From ba95dc72674b7b517a771b79df96fa50c77b590e Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 13 Dec 1999 17:36:12 +0000 Subject: Added an icon to indicate the sort order of the pieces list git-svn-id: http://svn.leocad.org/trunk@31 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- win/Piecelst.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'win/Piecelst.cpp') diff --git a/win/Piecelst.cpp b/win/Piecelst.cpp index 1506890..4b0f0fb 100644 --- a/win/Piecelst.cpp +++ b/win/Piecelst.cpp @@ -20,18 +20,29 @@ static char THIS_FILE[] = __FILE__; static int CALLBACK ListViewCompareProc(LPARAM lP1, LPARAM lP2, LPARAM lParamSort) { - if ((lP1 < 0) || (lP2 < 0)) return 0; + int ret; - if (lParamSort == 0) - return strcmpi(((PieceInfo*)lP1)->m_strDescription, ((PieceInfo*)lP2)->m_strDescription); + if ((lP1 < 0) || (lP2 < 0)) + return 0; - return strcmpi(((PieceInfo*)lP1)->m_strName, ((PieceInfo*)lP2)->m_strName); + if ((lParamSort & ~0xF0) == 0) + ret = strcmpi(((PieceInfo*)lP1)->m_strDescription, ((PieceInfo*)lP2)->m_strDescription); + else + ret = strcmpi(((PieceInfo*)lP1)->m_strName, ((PieceInfo*)lP2)->m_strName); + + if (lParamSort & 0xF0) + return ret; + else + return -ret; } CPiecesList::CPiecesList() { // TODO: Load from registry memset(m_nLastPieces, 0, sizeof(m_nLastPieces)); + + m_nSortedCol = 0; + m_bAscending = FALSE; } CPiecesList::~CPiecesList() @@ -56,7 +67,22 @@ END_MESSAGE_MAP() void CPiecesList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; - SortItems((PFNLVCOMPARE)ListViewCompareProc, pNMListView->iSubItem); + + // set the sort order. + if (pNMListView->iSubItem == m_nSortedCol) + m_bAscending = !m_bAscending; + else + m_bAscending = TRUE; + + // save the column index. + m_nSortedCol = pNMListView->iSubItem; + + if (m_bAscending) + SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol); + else + SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol|0xF0); + + m_HeaderCtrl.SetSortImage(m_nSortedCol, m_bAscending); *pResult = 0; } @@ -120,6 +146,12 @@ void CPiecesList::UpdateList() SetItemText(idx, 1, tmp2); } } + + if (m_bAscending) + SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol); + else + SortItems((PFNLVCOMPARE)ListViewCompareProc, m_nSortedCol|0xF0); + EnsureVisible(m_nLastPieces[pBar->m_nCurGroup], FALSE); SetItemState (m_nLastPieces[pBar->m_nCurGroup], LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED); SetRedraw (TRUE); @@ -208,9 +240,9 @@ int CPiecesList::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CListCtrl::OnCreate(lpCreateStruct) == -1) return -1; - + m_TitleTip.Create(this); - + return 0; } @@ -227,3 +259,14 @@ void CPiecesList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) else CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags); } + +void CPiecesList::SubclassHeader() +{ + // Get the window handle to the existing header control. + HWND hWnd = GetDlgItem(0)->GetSafeHwnd(); + ASSERT(hWnd); + + // subclass the header control. + m_HeaderCtrl.SubclassWindow(hWnd); + m_HeaderCtrl.SetSortImage(0, FALSE); +} -- cgit v1.2.3