[GME-commit] GMESRC/Paradigms/MetaGME/BonExtension/Gui SelConf.cpp,1.5,1.6 SelConf.h,1.1,1.2 Table.cpp,1.5,1.6 Table.h,1.1,1.2

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Mon Sep 26 21:26:25 CDT 2005


Update of /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension/Gui
In directory escher:/tmp/cvs-serv5209/Gui

Modified Files:
	SelConf.cpp SelConf.h Table.cpp Table.h 
Log Message:
More flexibility in BonX. Captured as option added.


CVS User: Zoltan Molnar, ISIS (zolmol)

Index: SelConf.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension/Gui/SelConf.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** SelConf.cpp	16 Jun 2004 18:35:02 -0000	1.5
--- SelConf.cpp	26 Sep 2005 20:26:23 -0000	1.6
***************
*** 16,20 ****
  // SelConf dialog
  /*static*/ int SelConf::m_lastId = 0;
! 
  
  SelConf::SelConf( unsigned int no_of_configs, CWnd* pParent /*=NULL*/)
--- 16,20 ----
  // SelConf dialog
  /*static*/ int SelConf::m_lastId = 0;
! /*static*/ int SelConf::m_sortOrder = 1;
  
  SelConf::SelConf( unsigned int no_of_configs, CWnd* pParent /*=NULL*/)
***************
*** 72,90 ****
  
  
! int SelConf::addEntry( CString& role, int clique, bool in, const void * ptr)
  {
  	entry *f = new entry;
  	f->id = m_lastId;
  	f->s = role;
  	f->cliqueId = clique;
  	f->val = in;
  	f->ptr = ptr;
  
  	m_entries.AddTail( f);
- 
  	return m_lastId++;
  }
  
! bool SelConf::getEntry( int row, CString& role, bool & in, const void * &ptr)
  {
  	bool retval = false;
--- 72,91 ----
  
  
! int SelConf::addEntry( const CString& role, char kind, int clique, bool in, const CString& repr, const void * ptr)
  {
  	entry *f = new entry;
  	f->id = m_lastId;
  	f->s = role;
+ 	f->kind = kind;
  	f->cliqueId = clique;
  	f->val = in;
+ 	f->resp = repr;
  	f->ptr = ptr;
  
  	m_entries.AddTail( f);
  	return m_lastId++;
  }
  
! bool SelConf::getEntry( int row, CString& role, bool & in, CString& repr, const void * &ptr)
  {
  	bool retval = false;
***************
*** 97,100 ****
--- 98,102 ----
  			in = e->val;
  			ptr = e->ptr;
+ 			repr = e->resp;
  			retval = true;
  		}
***************
*** 111,115 ****
  	this->GetClientRect(&loc);
  	loc.DeflateRect(15, 50, 15, 50);
! 	
  	m_table.Create(WS_CHILD|WS_VISIBLE|WS_BORDER/*|LVS_EDITLABELS*/|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
  	m_table.m_parent = this;
--- 113,117 ----
  	this->GetClientRect(&loc);
  	loc.DeflateRect(15, 50, 15, 50);
! 
  	m_table.Create(WS_CHILD|WS_VISIBLE|WS_BORDER/*|LVS_EDITLABELS*/|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
  	m_table.m_parent = this;
***************
*** 234,240 ****
--- 236,251 ----
  		{
  			if ( !check) // if called from OnOk
+ 			{
  				any_ptr->toBeEx( e->val);
+ 				FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
+ 				if( any_ptr->isFCO() && fco_ptr)
+ 				{
+ 					// stores into the ExtedAnc var the selected responsible
+ 					fco_ptr->setExtedAnc( fco_ptr->findRspPtr( (LPCTSTR) e->resp));
+ 				}
+ 			}
  			if (e->val)	regVal = "true"; else regVal = "false";
  			any_ptr->getMyRegistry()->setValueByPath( regPath, regVal);
+ 			any_ptr->getMyRegistry()->setValueByPath( regPath + "/Resp", (LPCTSTR) e->resp);
  		}
  	}
***************
*** 246,250 ****
  	while (pos) {
  		entry	*e = m_entries.GetNext(pos);
! 		m_table.addRow(e->id, e->s, e->cliqueId, e->val);
  	}
  }
--- 257,261 ----
  	while (pos) {
  		entry	*e = m_entries.GetNext(pos);
! 		m_table.addRow(e->id, e->s, e->kind, e->cliqueId, e->val, e->resp);
  	}
  }
***************
*** 255,262 ****
  	while (pos) {
  		entry	*e = m_entries.GetNext(pos);
! 		m_table.getRow( e->id, e->s, e->val);
  	}
  }
  
  
  // which: true if the user selected NO, false if the user selected YES
--- 266,328 ----
  	while (pos) {
  		entry	*e = m_entries.GetNext(pos);
! 		m_table.getRow( e->id, e->s, e->val, e->resp);
  	}
  }
  
+ // appends those class names to list which are samekind extended ancestors
+ // of the fco identified by 'changed'
+ bool SelConf::addPossibleAncestors( CStringList& list, int changed)
+ {
+ 	POSITION pos = m_entries.GetHeadPosition();
+ 	entry	*e = 0;
+ 	while (pos) {
+ 		e = m_entries.GetNext(pos);
+ 		if ( e->id == changed)
+ 			break;
+ 	}
+ 
+ 	if ( e && e->id == changed)
+ 	{
+ 		Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
+ 		if ( any_ptr && any_ptr->isFCO())
+ 		{
+ 			FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
+ 			if( fco_ptr)
+ 			{
+ 				std::vector<FCO *> ancestor;
+ 				bool found_same_kind_extd_anc = false; // notifies that extended ancestors of the same kind have been found
+ 				fco_ptr->getIntAncestors( ancestor);
+ 				
+ 				for( unsigned int i = 0; i < ancestor.size(); ++i)
+ 				{
+ 					// check whether ancestor[i] is to be extended
+ 					POSITION pos_d = m_entries.GetHeadPosition();
+ 					entry	*e_d = 0;
+ 					while (pos_d) {
+ 						e_d = m_entries.GetNext(pos_d);
+ 						if ( e_d->ptr == ancestor[i])
+ 						{
+ 							CString role, repr; bool extended = false;
+ 							if( m_table.getRow( e_d->id, role, extended, repr))
+ 							{
+ 								if( extended                                          // it is extended
+ 								  && fco_ptr->getMyKind() == ancestor[i]->getMyKind() // it is the same kind that fco_ptr
+ 								  )
+ 								{
+ 									list.AddTail( ancestor[i]->getName().c_str());    // put into the option
+ 									found_same_kind_extd_anc = true;
+ 								}
+ 							}
+ 							break; // end the cycle
+ 						}
+ 					}
+ 				}
+ 				
+ 				return found_same_kind_extd_anc; // will notify the user if additional options have been added at all
+ 			}
+ 		}
+ 	}
+ 	return false;
+ }
  
  // which: true if the user selected NO, false if the user selected YES
***************
*** 270,274 ****
  			break;
  	}
! 	//m_table.getRow( e->id, e->s, e->val);
  	if ( e && e->id == changed)
  	{
--- 336,340 ----
  			break;
  	}
! 
  	if ( e && e->id == changed)
  	{
***************
*** 282,288 ****
  				if ( which) // means 'no' is selected
  				{
! 					if ( fco_ptr->getMyKind() == Any::FCO_REP || !fco_ptr->hasParentOfSameKind()) //if fco_rep is selected for 'no' means no other elements in the hierarchy needed to be extended or if has _not_ the same kind of ancestor means doesn't inherit from a same kind object (inherits from FCO)
  						fco_ptr->getAllInMyHierarchy( family);
! 					else
  						family = fco_ptr->getAllDescendants();
  				}
--- 348,354 ----
  				if ( which) // means 'no' is selected
  				{
! 					/*if ( fco_ptr->getMyKind() == Any::FCO_REP || !fco_ptr->hasParentOfSameKind()) //if fco_rep is selected for 'no' means no other elements in the hierarchy needed to be extended or if has _not_ the same kind of ancestor means doesn't inherit from a same kind object (inherits from FCO)
  						fco_ptr->getAllInMyHierarchy( family);
! 					else*/
  						family = fco_ptr->getAllDescendants();
  				}
***************
*** 290,294 ****
  				{
  					family = fco_ptr->getAllAncestors(); // since fco_rep may exist among the ancestors and that will become yes, we have to make yes all fcoreps and the first nonfcorep leaves
! 					fco_ptr->getRootDescsUntilNonFcoRep( family); // get more dependants
  				}
  
--- 356,360 ----
  				{
  					family = fco_ptr->getAllAncestors(); // since fco_rep may exist among the ancestors and that will become yes, we have to make yes all fcoreps and the first nonfcorep leaves
! 					//fco_ptr->getRootDescsUntilNonFcoRep( family); // get more dependants
  				}
  
***************
*** 311,312 ****
--- 377,427 ----
  	}
  }
+ 
+ /*static*/ bool SelConf::getEntries( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort, entry& e, entry& f)
+ {
+ 	SelConf * myDlg = reinterpret_cast<SelConf *>((void*)lParamSort);
+ 	bool b1 = myDlg->getEntry( lParam1, e.s, e.val, e.resp, e.ptr); 
+ 	bool b2 = myDlg->getEntry( lParam2, f.s, f.val, f.resp, f.ptr); 
+ 	
+ 	return b1 && b2;
+ }
+ 
+ /*static*/ int CALLBACK SelConf::MyNameCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+ {
+ 	entry e, f;
+ 	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
+ 
+ 	return m_sortOrder * e.s.Compare( f.s);
+ }
+ 
+ /*static*/ int CALLBACK SelConf::MyKindCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+ {
+ 	entry e, f;
+ 	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
+ 
+ 	Any * any_ptr1 = reinterpret_cast<Any *>((void*)e.ptr);
+ 	Any * any_ptr2 = reinterpret_cast<Any *>((void*)f.ptr);
+ 
+ 	std::string ks1 = any_ptr1->getMyKindStr();
+ 	std::string ks2 = any_ptr2->getMyKindStr();
+ 
+ 	return m_sortOrder * ks1.compare( ks2);
+ }
+ 
+ /*static*/ int CALLBACK SelConf::MyExtdCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+ {
+ 	entry e, f;
+ 	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
+ 
+ 	if( e.val == f.val) return 0;
+ 	else return m_sortOrder * (int)e.val < m_sortOrder * (int)f.val;
+ }
+ 
+ /*static*/ int CALLBACK SelConf::MyReprCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+ {
+ 	entry e, f;
+ 	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;
+ 
+ 	return m_sortOrder * e.resp.Compare( f.resp);
+ }
+ 

Index: Table.h
===================================================================
RCS file: /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension/Gui/Table.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Table.h	26 Feb 2004 17:12:46 -0000	1.1
--- Table.h	26 Sep 2005 20:26:23 -0000	1.2
***************
*** 32,35 ****
--- 32,37 ----
  	//{{AFX_VIRTUAL(CTable)
  	//}}AFX_VIRTUAL
+ 	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
+ 	virtual BOOL PreCreateWindow(CREATESTRUCT &cs);
  
  // Implementation
***************
*** 37,43 ****
  	SelConf * m_parent;
  
! 	CImageList m_checkImages;
! 	void addRow(int rowID, CString& role, int clique, bool isPrimary);
! 	bool getRow(int rowID, CString& role, bool& isPrimary);
  	virtual ~CTable();
  	int HitTestEx(CPoint &point, int *col) const;
--- 39,44 ----
  	SelConf * m_parent;
  
! 	void addRow(int rowID, CString& role, char kind, int clique, bool isPrimary, CString& repr);
! 	bool getRow(int rowID, CString& role, bool& extend, CString& repr);
  	virtual ~CTable();
  	int HitTestEx(CPoint &point, int *col) const;
***************
*** 45,48 ****
--- 46,53 ----
  	CComboBox* ShowInPlaceList( int nItem, int nCol, CStringList &lstItems, int nSel );
  
+ protected:
+ 	static LPCTSTR MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset);
+ 	int m_cxClient;
+ 
  	// Generated message map functions
  protected:
***************
*** 53,56 ****
--- 58,64 ----
  	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ 	afx_msg void OnSize(UINT nType, int cx, int cy);
+ 	afx_msg void OnPaint();
+ 	afx_msg void OnSort(NMHDR* pNMHDR, LRESULT* pResult);
  	//}}AFX_MSG
  

Index: Table.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension/Gui/Table.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Table.cpp	6 May 2004 22:30:26 -0000	1.5
--- Table.cpp	26 Sep 2005 20:26:23 -0000	1.6
***************
*** 14,17 ****
--- 14,23 ----
  #endif
  
+ #define OFFSET_FIRST        2       // offsets for first and other columns in owner draw methods 
+ #define OFFSET_OTHER        6
+ 
+ #define EXT_COLNUM          2       // column of 'Extended?'
+ #define RSP_COLNUM          3       // column of 'Capture as' or 'Responsible'
+ 
  /////////////////////////////////////////////////////////////////////////////
  // CTable
***************
*** 19,22 ****
--- 25,29 ----
  CTable::CTable()
  	: m_parent(0)
+ 	, m_cxClient(0)
  {
  }
***************
*** 26,29 ****
--- 33,42 ----
  }
  
+ BOOL CTable::PreCreateWindow(CREATESTRUCT &cs)
+ {
+ 	cs.style |= LVS_OWNERDRAWFIXED;
+ 	return CListCtrl::PreCreateWindow( cs);
+ }
+ 
  
  BEGIN_MESSAGE_MAP(CTable, CListCtrl)
***************
*** 34,37 ****
--- 47,53 ----
  	ON_WM_LBUTTONDOWN()
  	ON_WM_CREATE()
+ 	ON_WM_SIZE()
+ 	ON_WM_PAINT()
+ 	ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnSort)
  	//}}AFX_MSG_MAP
  END_MESSAGE_MAP()
***************
*** 49,70 ****
  	if (plvItem->pszText != NULL)
  	{
! 		if ( SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText))// mod on 3/16/2004 plvItem->iItem >= 0)
  		{
! 			std::string val( plvItem->pszText);
! 			int rid = this->GetItemData( plvItem->iItem);
! 			if ( m_parent)
! 			{
! 				std::vector< int > res;
! 				m_parent->getDescsAncs( val == "no", rid, res); // get Descendants if val == "no", otherwise Ancestors
  
! 				for( unsigned int desc_i = 0; desc_i < res.size(); ++desc_i)
  				{
! 					unsigned int desc_r_id = res[desc_i];
! 					for (int i=0;i < GetItemCount();i++)
  					{
! 						if ( GetItemData(i) == desc_r_id)
! 						{
! 							SetItemText( i, plvItem->iSubItem, plvItem->pszText);
! 						}
  					}
  				}
--- 65,115 ----
  	if (plvItem->pszText != NULL)
  	{
! 		// get old value
! 		LV_ITEM old_lvItem;
! 		old_lvItem.mask = LVIF_TEXT;
! 		old_lvItem.iItem = plvItem->iItem;
! 		
! 		CString prev_str;
! 		old_lvItem.iSubItem = plvItem->iSubItem;
! 		old_lvItem.pszText = prev_str.GetBuffer(255);
! 		old_lvItem.cchTextMax = 255;
! 		GetItem(&old_lvItem);
! 
! 		// if not changed, return
! 		if( prev_str == plvItem->pszText) { *pResult = TRUE; return; }
! 
! 		// change the value
! 		BOOL res = SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
! 		
! 		// if 'Extend?' value changed
! 		if( res && plvItem->iSubItem == EXT_COLNUM)// mod on 3/16/2004 plvItem->iItem >= 0)
  		{
! 			bool bYes = strcmp( plvItem->pszText, "yes") == 0;
! 			const char* repValArray[] = { "self", "none"};
! 			const char* repVal = repValArray[bYes?0:1];
  
! 			// update the responsible column accordingly
! 			SetItemText(plvItem->iItem, RSP_COLNUM, repVal);
! 
! 			// change the extended and responsible column of the relatives
! 			std::vector< int > res;
! 			m_parent->getDescsAncs( !bYes, GetItemData( plvItem->iItem), res); // get Descendants if ext == "no", otherwise Ancestors
! 
! 			// for each relative
! 			for( unsigned int desc_i = 0; desc_i < res.size(); ++desc_i)
! 			{
! 				unsigned int desc_r_id = res[desc_i];
! 				for (int i=0;i < GetItemCount();i++)
  				{
! 					// if element found
! 					if ( GetItemData(i) == desc_r_id)
  					{
! 						// change the extended value as for the current one
! 						// in case of 'yes' all ancestors need 'yes'
! 						// in case of 'no'  all descendants need 'no'
! 						SetItemText( i, EXT_COLNUM, plvItem->pszText);
! 
! 						// update the responsible column accordingly
! 						SetItemText( i, RSP_COLNUM, repVal);
  					}
  				}
***************
*** 297,301 ****
  				}
  			}*/
! 			if(colnum==1)
  			{
  				CStringList lstItems;
--- 342,346 ----
  				}
  			}*/
! 			if(colnum==EXT_COLNUM)
  			{
  				CStringList lstItems;
***************
*** 304,307 ****
--- 349,366 ----
  				ShowInPlaceList( index, colnum, lstItems, 0 );
  			}
+ 			else if(colnum==RSP_COLNUM)
+ 			{
+ 				int rowID = GetItemData( index);
+ 				CString role, repr; bool ext;
+ 				if( getRow( rowID, role, ext, repr) && ext == false) // if not intended for extension
+ 				{
+ 					CStringList lstItems;
+ 					lstItems.AddTail("none");
+ 					if( m_parent->addPossibleAncestors( lstItems, rowID)) // some choices added
+ 						ShowInPlaceList( index, colnum, lstItems, 0 );
+ 					else
+ 						AfxMessageBox("This class does not have a base of the same kind. For BON2 reasons can't be captured by its superclass.");
+ 				}
+ 			}
  
  		}
***************
*** 317,332 ****
  		return -1;
  
! 	int col1size = 9*GetStringWidth("TipicalLongRolenName")/4;
! 	//int col2size = 5*GetStringWidth("12345")/2;
! 	int col3size = 13*GetStringWidth("Extend")/9;
  
! 	InsertColumn(0, _T("Classes"), LVCFMT_LEFT,  col1size, -1);
! 	//InsertColumn(1, _T("CliqueId"), LVCFMT_LEFT, col2size, -1);
! 	InsertColumn(1, _T("Extend"), LVCFMT_LEFT, col3size, -1);
  
  	return 0;
  }
  
! void CTable::addRow(int rowID, CString& role, int clique, bool generate)
  {
  	LV_ITEM lvItem;
--- 376,393 ----
  		return -1;
  
! 	int col0size = 9*GetStringWidth("TipicalLongRolenName")/4;
! 	int col1size = 4*GetStringWidth("R");
! 	int col2size = 13*GetStringWidth("Extend")/9;
! 	int col3size = 3*GetStringWidth("TypicalLongRoleName")/2;
  
! 	InsertColumn(0, _T("Class"), LVCFMT_LEFT,  col0size, -1);
! 	InsertColumn(1, _T("Stereotype"), LVCFMT_LEFT, col1size, -1);
! 	InsertColumn(EXT_COLNUM, _T("Extend"), LVCFMT_LEFT, col2size, -1);
! 	InsertColumn(RSP_COLNUM, _T("Capture as"), LVCFMT_LEFT, col3size, -1);
  
  	return 0;
  }
  
! void CTable::addRow(int rowID, CString& role, char kind, int clique, bool generate, CString& repr)
  {
  	LV_ITEM lvItem;
***************
*** 337,358 ****
  	int index = InsertItem(&lvItem);
  	
! 
! 	/*char clique_str[12]; sprintf( clique_str, "%d", clique);
  	lvItem.iSubItem = 1;
! 	lvItem.pszText = clique_str;
! 	SetItem(&lvItem);*/
  
! 	lvItem.iSubItem = 1;
  	lvItem.pszText = generate ? _T("yes"): _T("no");
  
  	SetItem(&lvItem);
  
  	SetItemData(index, rowID);
  	
  }
  
! bool CTable::getRow(int rowID, CString &role, bool &generate)
  {
- 
  	LVFINDINFO lvFind;
  	lvFind.flags = LVFI_PARAM;
--- 398,421 ----
  	int index = InsertItem(&lvItem);
  	
! 	char b[2] = { kind, 0 };
  	lvItem.iSubItem = 1;
! 	lvItem.pszText = b;
! 	SetItem(&lvItem);
  
! 	lvItem.iSubItem = EXT_COLNUM;
  	lvItem.pszText = generate ? _T("yes"): _T("no");
+ 	SetItem(&lvItem);
  
+ 	lvItem.iSubItem = RSP_COLNUM;
+ 	lvItem.pszText = generate ?_T("self"): repr.IsEmpty() ? _T("none") : repr;
  	SetItem(&lvItem);
  
+ 
  	SetItemData(index, rowID);
  	
  }
  
! bool CTable::getRow(int rowID, CString &role, bool &generate, CString &repr)
  {
  	LVFINDINFO lvFind;
  	lvFind.flags = LVFI_PARAM;
***************
*** 372,390 ****
  	GetItem(&lvItem);
  	
- 	
- 
- 	/*lvItem.iSubItem = 1;
- 	lvItem.pszText = kindAspect.GetBuffer(255);
- 	lvItem.cchTextMax = 255;
- 	GetItem(&lvItem);*/
- 
- 
  	CString tmpStr;
  	lvItem.pszText = tmpStr.GetBuffer(10);
  	lvItem.cchTextMax = 10;
! 	lvItem.iSubItem = 1;
  	GetItem(&lvItem);
  	generate = (tmpStr == "yes");
! 	
  	return true;
  }
--- 435,662 ----
  	GetItem(&lvItem);
  	
  	CString tmpStr;
  	lvItem.pszText = tmpStr.GetBuffer(10);
  	lvItem.cchTextMax = 10;
! 	lvItem.iSubItem = EXT_COLNUM;
  	GetItem(&lvItem);
  	generate = (tmpStr == "yes");
! 
! 	lvItem.pszText = repr.GetBuffer(255);
! 	lvItem.cchTextMax = 255;
! 	lvItem.iSubItem = RSP_COLNUM;
! 	GetItem(&lvItem);
! 
  	return true;
+ }
+ 
+ void CTable::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
+ {
+ 	CListCtrl& ListCtrl = *this;
+ 	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
+ 	CRect rcItem(lpDrawItemStruct->rcItem);
+ 	UINT uiFlags = ILD_TRANSPARENT;
+ 	int nItem = lpDrawItemStruct->itemID;
+ 	BOOL bFocus = (GetFocus() == this);
+ 	COLORREF clrTextSave, clrBkSave;
+ 	static _TCHAR szBuff[MAX_PATH];
+ 	static _TCHAR szBuff2[MAX_PATH] = _T("c");
+ 	LPCTSTR pszText;
+ 
+ // get item data
+ 
+ 	LV_ITEM lvi;
+ 	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
+ 	lvi.iItem = nItem;
+ 	lvi.iSubItem = 0;
+ 	lvi.pszText = szBuff;
+ 	lvi.cchTextMax = sizeof(szBuff);
+ 	lvi.stateMask = 0xFFFF;     // get all state flags
+ 	ListCtrl.GetItem(&lvi);
+ 
+ 	BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
+ 	bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);
+ 
+ // set colors if item is selected
+ 
+ 	CRect rcAllLabels;
+ 	ListCtrl.GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
+ 
+ 	CRect rcLabel;
+ 	ListCtrl.GetItemRect(nItem, rcLabel, LVIR_LABEL);
+ 
+ 	rcAllLabels.left = rcLabel.left;
+ 	if (rcAllLabels.right<m_cxClient)
+ 		rcAllLabels.right = m_cxClient;
+ 
+ 	if (bSelected)
+ 	{
+ 		// the return value is the previous color, so save it
+ 		clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
+ 		clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
+ 
+ 		pDC->FillRect(rcAllLabels, &CBrush( ::GetSysColor(COLOR_HIGHLIGHT)));
+ 	}
+ 	else
+ 		pDC->FillRect(rcAllLabels, &CBrush( ::GetSysColor(COLOR_WINDOW)));
+ 
+ // draw item label
+ 
+ 	ListCtrl.GetItemRect(nItem, rcItem, LVIR_LABEL);
+ 
+ 	pszText = MakeShortString(pDC, szBuff, rcItem.right-rcItem.left, 2*OFFSET_FIRST);
+ 
+ 	rcLabel = rcItem;
+ 	rcLabel.left += OFFSET_FIRST;
+ 	rcLabel.right -= OFFSET_FIRST;
+ 
+ 	pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
+ 
+ 
+ // draw labels for extra columns
+ 
+ 	LV_COLUMN lvc;
+ 	lvc.mask = LVCF_FMT | LVCF_WIDTH;
+ 
+ 	for(int nColumn = 1; ListCtrl.GetColumn(nColumn, &lvc); nColumn++)
+ 	{
+ 		rcItem.left = rcItem.right;
+ 		rcItem.right += lvc.cx;
+ 
+ 		int nRetLen = ListCtrl.GetItemText(nItem, nColumn,
+ 						szBuff, sizeof(szBuff));
+ 		if (nRetLen == 0)
+ 			continue;
+ 
+ 		pszText = MakeShortString(pDC, szBuff,
+ 			rcItem.right - rcItem.left, 2*OFFSET_OTHER);
+ 
+ 		UINT nJustify = DT_LEFT;
+ 
+ 		if(pszText == szBuff)
+ 		{
+ 			switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
+ 			{
+ 			case LVCFMT_RIGHT:
+ 				nJustify = DT_RIGHT;
+ 				break;
+ 			case LVCFMT_CENTER:
+ 				nJustify = DT_CENTER;
+ 				break;
+ 			default:
+ 				break;
+ 			}
+ 		}
+ 
+ 		rcLabel = rcItem;
+ 		rcLabel.left += OFFSET_OTHER;
+ 		rcLabel.right -= OFFSET_OTHER;
+ 
+ 		pDC->DrawText(pszText, -1, rcLabel,
+ 			nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
+ 	}
+ 
+ 	// draw focus rectangle if item has focus
+ 	//if (lvi.state & LVIS_FOCUSED && bFocus) pDC->DrawFocusRect(rcAllLabels);
+ 
+ 	
+ // set original colors if item was selected
+ 
+ 	if (bSelected)
+ 	{
+ 		pDC->SetTextColor(clrTextSave);
+ 		pDC->SetBkColor(clrBkSave);
+ 	}
+ }
+ 
+ LPCTSTR CTable::MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset)
+ {
+ 	static const _TCHAR szThreeDots[] = _T("...");
+ 
+ 	int nStringLen = lstrlen(lpszLong);
+ 
+ 	if(nStringLen == 0 ||
+ 		(pDC->GetTextExtent(lpszLong, nStringLen).cx + nOffset) <= nColumnLen)
+ 	{
+ 		return(lpszLong);
+ 	}
+ 
+ 	static _TCHAR szShort[MAX_PATH];
+ 
+ 	lstrcpy(szShort,lpszLong);
+ 	int nAddLen = pDC->GetTextExtent(szThreeDots,sizeof(szThreeDots)).cx;
+ 
+ 	for(int i = nStringLen-1; i > 0; i--)
+ 	{
+ 		szShort[i] = 0;
+ 		if((pDC->GetTextExtent(szShort, i).cx + nOffset + nAddLen)
+ 			<= nColumnLen)
+ 		{
+ 			break;
+ 		}
+ 	}
+ 
+ 	lstrcat(szShort, szThreeDots);
+ 	return(szShort);
+ }
+ 
+ void CTable::OnSize(UINT nType, int cx, int cy)
+ {
+ 	m_cxClient = cx;
+ 	CListCtrl::OnSize(nType, cx, cy);
+ }
+ 
+ void CTable::OnPaint()
+ {
+ 	// full row select mode: need to extend the clipping region
+ 	// so we can paint a selection all the way to the right
+ 	if ((GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
+ 	{
+ 		CRect rcAllLabels;
+ 		GetItemRect(0, rcAllLabels, LVIR_BOUNDS);
+ 
+ 		if(rcAllLabels.right < m_cxClient)
+ 		{
+ 			// need to call BeginPaint (in CPaintDC c-tor)
+ 			// to get correct clipping rect
+ 			CPaintDC dc(this);
+ 
+ 			CRect rcClip;
+ 			dc.GetClipBox(rcClip);
+ 
+ 			rcClip.left = min(rcAllLabels.right-1, rcClip.left);
+ 			rcClip.right = m_cxClient;
+ 
+ 			InvalidateRect(rcClip, FALSE);
+ 			// EndPaint will be called in CPaintDC d-tor
+ 		}
+ 	}
+ 
+ 	CListCtrl::OnPaint();
+ }
+ 
+ void CTable::OnSort(NMHDR* pNMHDR, LRESULT* pResult)
+ {
+ 	NMLISTVIEW* pNMLV = (NMLISTVIEW*) pNMHDR;
+ 	ASSERT( pNMLV->iItem == -1);
+ 	ASSERT( pNMLV->iSubItem >= 0);
+ 
+ 	switch( pNMLV->iSubItem) {
+ 		case 0:
+ 			this->SortItems( SelConf::MyNameCompare, (LPARAM) m_parent);
+ 			break;
+ 		case 1:
+ 			this->SortItems( SelConf::MyKindCompare, (LPARAM) m_parent);
+ 			break;
+ 		case 2:
+ 			this->SortItems( SelConf::MyExtdCompare, (LPARAM) m_parent);
+ 			break;
+ 		case 3:
+ 			this->SortItems( SelConf::MyReprCompare, (LPARAM) m_parent);
+ 			break;
+ 		default:
+ 			ASSERT(0);
+ 	};
+ 	
+ 	// after sort is done we revert the direction of the next sort with:
+ 	SelConf::m_sortOrder *= -1;
  }

Index: SelConf.h
===================================================================
RCS file: /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension/Gui/SelConf.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SelConf.h	26 Feb 2004 17:12:46 -0000	1.1
--- SelConf.h	26 Sep 2005 20:26:23 -0000	1.2
***************
*** 19,24 ****
--- 19,26 ----
  	int id;
  	CString s;
+ 	char kind;
  	int cliqueId;
  	bool val;
+ 	CString resp;
  	const void * ptr;
  } entry;
***************
*** 51,56 ****
  // Implementation
  public:
! 	int addEntry( CString& role, int clique, bool in, const void * ptr);
! 	bool getEntry( int row, CString& role, bool& in, const void * &ptr);
  
  	void addConfigs( std::vector< std::string >& configs);
--- 53,58 ----
  // Implementation
  public:
! 	int addEntry( const CString& role, char kind, int clique, bool in, const CString& repr, const void * ptr);
! 	bool getEntry( int row, CString& role, bool& in, CString& repr, const void * &ptr);
  
  	void addConfigs( std::vector< std::string >& configs);
***************
*** 60,63 ****
--- 62,73 ----
  
  	void getDescsAncs( bool which, int changed, std::vector< int > & res);
+ 	bool addPossibleAncestors( CStringList& list, int changed);
+ 	
+ 	static int m_sortOrder;
+ 	static bool getEntries( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort, entry& e, entry& f);
+ 	static int CALLBACK MyNameCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
+ 	static int CALLBACK MyKindCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
+ 	static int CALLBACK MyExtdCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
+ 	static int CALLBACK MyReprCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
  
  protected:



More information about the GME-commit mailing list