[GME-commit] GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp NameSpecTbl.cpp,1.1,1.2 NameSpecTbl.h,1.1,1.2

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Mon Aug 9 12:11:40 CDT 2004


Update of /var/lib/gme/GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp
In directory braindrain:/tmp/cvs-serv14803/Asp

Modified Files:
	NameSpecTbl.cpp NameSpecTbl.h 
Log Message:
Improved name selector listctrl.


CVS User: zolmol

Index: NameSpecTbl.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp/NameSpecTbl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NameSpecTbl.cpp	30 Jul 2004 00:10:23 -0000	1.1
--- NameSpecTbl.cpp	9 Aug 2004 16:11:37 -0000	1.2
***************
*** 15,18 ****
--- 15,21 ----
  #endif
  
+ #define OFFSET_FIRST    2
+ #define OFFSET_OTHER    6
+ 
  /////////////////////////////////////////////////////////////////////////////
  // NameSpecTbl
***************
*** 40,43 ****
--- 43,53 ----
  // NameSpecTbl message handlers
  
+ BOOL NameSpecTbl::PreCreateWindow( CREATESTRUCT &cs)
+ {
+ 	cs.style |= WS_TABSTOP|LVS_REPORT|LVS_SINGLESEL|LVS_NOSORTHEADER|LVS_OWNERDRAWFIXED;
+ 
+ 	return CListCtrl::PreCreateWindow( cs);
+ }
+ 
  void NameSpecTbl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
  {
***************
*** 151,156 ****
  	}
  
! 	rect.left += offset+4;
! 	rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
  	int height = rect.bottom-rect.top;
  	rect.bottom += (lstItems.GetCount()+1)*height;
--- 161,166 ----
  	}
  
! 	rect.left += offset+ 1*OFFSET_FIRST;
! 	rect.right = rect.left + GetColumnWidth( nCol );
  	int height = rect.bottom-rect.top;
  	rect.bottom += (lstItems.GetCount()+1)*height;
***************
*** 161,166 ****
  	CComboBox *pList = new CInPlaceList(nItem, nCol, &lstItems, nSel);
  	pList->Create( dwStyle, rect, this, IDC_IPEDIT );
! 	pList->SetItemHeight( -1, height);
  	pList->SetHorizontalExtent( GetColumnWidth( nCol ));
  
  	
--- 171,177 ----
  	CComboBox *pList = new CInPlaceList(nItem, nCol, &lstItems, nSel);
  	pList->Create( dwStyle, rect, this, IDC_IPEDIT );
! 	pList->SetItemHeight( -1, height-1);
  	pList->SetHorizontalExtent( GetColumnWidth( nCol ));
+ 	pList->ShowDropDown();
  
  	
***************
*** 372,373 ****
--- 383,544 ----
  }
  
+ void NameSpecTbl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
+ {
+ 	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
+ 	CRect rcItem(lpDrawItemStruct->rcItem);
+ 	int nItem = lpDrawItemStruct->itemID;
+ 	BOOL bFocus = (GetFocus() == this);
+ 	COLORREF clrTextSave, clrBkSave;
+ 	static _TCHAR szBuff[MAX_PATH];
+ 	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
+ 	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;
+ 	GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
+ 
+ 	CRect rcLabel;
+ 	GetItemRect(nItem, rcLabel, LVIR_LABEL);
+ 
+ 	rcAllLabels.left = rcLabel.left;
+ 
+ 	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
+ 
+ 	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 scroll down button MZ
+ 	CRect rc = rcItem;
+ 
+ 	rc.left = rc.right - ::GetSystemMetrics(SM_CXHSCROLL);
+ 	//rc.top = rc.bottom - ::GetSystemMetrics(SM_CYVSCROLL);
+ 	//rc.DeflateRect(1,1);
+ 
+ 
+ 	if( rc.left > OFFSET_FIRST + 1)
+ 		pDC->DrawFrameControl(rc, DFC_SCROLL, DFCS_SCROLLDOWN);
+ 
+ // draw labels for extra columns
+ 
+ 	LV_COLUMN lvc;
+ 	lvc.mask = LVCF_FMT | LVCF_WIDTH;
+ 
+ 	for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
+ 	{
+ 		rcItem.left = rcItem.right;
+ 		rcItem.right += lvc.cx;
+ 
+ 		int nRetLen = 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 NameSpecTbl::MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset)
+ {
+ 	static const _TCHAR szEmpty[] = _T("");
+ 	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;
+ 
+ 	if( nOffset + nAddLen > nColumnLen) return szEmpty;
+ 
+ 
+ 	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);
+ }

Index: NameSpecTbl.h
===================================================================
RCS file: /var/lib/gme/GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp/NameSpecTbl.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NameSpecTbl.h	30 Jul 2004 00:10:23 -0000	1.1
--- NameSpecTbl.h	9 Aug 2004 16:11:37 -0000	1.2
***************
*** 36,43 ****
--- 36,49 ----
  	bool GetRow( int rowID, CString& name, CString& kind);
  	void AddRow( int rowID, CString& name, CString& kind);
+ 
  	virtual ~NameSpecTbl();
+ 	virtual BOOL PreCreateWindow( CREATESTRUCT &cs);
+ 	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  	int HitTestEx(CPoint &point, int *col) const;
  	CEdit* EditSubLabel( int nItem, int nCol );
  	CComboBox* ShowInPlaceList( int nItem, int nCol, CStringList &lstItems, int nSel );
+ 
+ 	static LPCTSTR MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset);
+ 
  
  	// Generated message map functions



More information about the GME-commit mailing list