summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo1999-12-13 17:36:12 +0000
committerleo1999-12-13 17:36:12 +0000
commitba95dc72674b7b517a771b79df96fa50c77b590e (patch)
tree8c0cb0fa5fb50bd508be2bdaee499e2134ebf6d1
parentd74841ebfc386e35c57d474742cc8fcbe543f6ff (diff)
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
-rw-r--r--win/LeoCAD.dsp15
-rw-r--r--win/Leocad.clw75
-rw-r--r--win/Piecebar.cpp1
-rw-r--r--win/Piecelst.cpp57
-rw-r--r--win/Piecelst.h7
-rwxr-xr-xwin/SortHead.cpp163
-rwxr-xr-xwin/SortHead.h52
7 files changed, 318 insertions, 52 deletions
diff --git a/win/LeoCAD.dsp b/win/LeoCAD.dsp
index 7d15c4c..460bcbd 100644
--- a/win/LeoCAD.dsp
+++ b/win/LeoCAD.dsp
@@ -207,13 +207,6 @@ InputPath=.\hlp\LeoCAD.hpj
# Begin Source File
SOURCE=.\Leocad.rc
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-!ENDIF
-
# End Source File
# Begin Source File
@@ -289,6 +282,10 @@ SOURCE=.\Seldlg.cpp
# End Source File
# Begin Source File
+SOURCE=.\SortHead.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\Splitter.cpp
# End Source File
# Begin Source File
@@ -510,6 +507,10 @@ SOURCE=.\SelDlg.h
# End Source File
# Begin Source File
+SOURCE=.\SortHead.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Splitter.h
# End Source File
# Begin Source File
diff --git a/win/Leocad.clw b/win/Leocad.clw
index 9122449..461d847 100644
--- a/win/Leocad.clw
+++ b/win/Leocad.clw
@@ -2,7 +2,7 @@
[General Info]
Version=1
-LastClass=CPropertiesPieces
+LastClass=CPiecesList
LastTemplate=CHeaderCtrl
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "leocad.h"
@@ -60,44 +60,44 @@ Class48=CTransToolBar
Class49=CWheelWnd
ResourceCount=36
-Resource1=IDR_LIBRARY
-Resource2=IDR_PREVIEW
-Resource3=IDD_PREFDRAWING
-Resource4=IDR_ANIMATORBAR
-Resource5=IDR_TERRAIN
-Resource6=IDR_FULLSCREEN
-Resource7=IDR_MAINFRAME
-Resource8=IDR_PIECEEDITOR
-Resource9=IDD_TERRAIN_OPTIONS
-Resource10=IDD_ABOUTBOX
-Resource11=IDD_MODIFY
-Resource12=IDD_PROPGENERAL
-Resource13=IDD_PROPSUMMARY
-Resource14=IDD_PROPPIECES
-Resource15=IDD_SELECT_OBJECTS
-Resource16=IDD_ARRAY
-Resource17=IDD_STEP
-Resource18=IDD_MINIFIG
-Resource19=IDD_HTML
-Resource20=IDD_PROGRESS
-Resource21=IDD_GROUP
-Resource22=IDD_PREFGENERAL
-Resource23=IDR_POPUPS
-Resource24=IDD_PREFDETAIL
-Resource25=IDD_PREFSCENE
-Resource26=IDD_PREFPRINT
-Resource27=IDD_OPENDLG_TEMPLATE
-Resource28=IDD_EDIT_GROUPS
-Resource29=IDR_TOOLSBAR
-Resource30=IDD_SAVEDLG_TEMPLATE
-Resource31=IDD_EXPORTPOV
-Resource32=IDD_SAVEPICTUREDLG_TEMPLATE
-Resource33=IDD_PIECEEDITOR
-Resource34=IDD_LIBRARY
-Resource35=IDD_TERRAIN
+Resource1=IDR_TERRAIN
+Resource2=IDR_POPUPS
+Resource3=IDD_GROUP
+Resource4=IDR_PREVIEW
+Resource5=IDR_FULLSCREEN
+Resource6=IDR_TOOLSBAR
+Resource7=IDD_OPENDLG_TEMPLATE
+Resource8=IDR_ANIMATORBAR
+Resource9=IDD_LIBRARY
+Resource10=IDD_TERRAIN_OPTIONS
+Resource11=IDD_PREFPRINT
+Resource12=IDR_MAINFRAME
+Resource13=IDD_ABOUTBOX
+Resource14=IDD_PROPGENERAL
+Resource15=IDD_PROPSUMMARY
+Resource16=IDD_PROPPIECES
+Resource17=IDD_SELECT_OBJECTS
+Resource18=IDD_ARRAY
+Resource19=IDD_STEP
+Resource20=IDD_MINIFIG
+Resource21=IDD_HTML
+Resource22=IDD_PROGRESS
+Resource23=IDR_PIECEEDITOR
+Resource24=IDD_PREFGENERAL
+Resource25=IDD_PREFDRAWING
+Resource26=IDD_PREFDETAIL
+Resource27=IDD_PREFSCENE
+Resource28=IDD_TERRAIN
+Resource29=IDR_LIBRARY
+Resource30=IDD_MODIFY
+Resource31=IDD_IMAGE
+Resource32=IDD_SAVEDLG_TEMPLATE
+Resource33=IDD_EXPORTPOV
+Resource34=IDD_SAVEPICTUREDLG_TEMPLATE
+Resource35=IDD_PIECEEDITOR
Class50=CGroupEditTree
+Resource36=IDD_EDIT_GROUPS
Class51=CSortHeaderCtrl
-Resource36=IDD_IMAGE
[CLS:CAboutDlg]
Type=0
@@ -1298,5 +1298,4 @@ ImplementationFile=SortHead.cpp
BaseClass=CHeaderCtrl
Filter=W
LastObject=CSortHeaderCtrl
-VirtualFilter=JWC
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index 90410b0..d54f52b 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -683,6 +683,7 @@ int CPiecesBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
CRect(0,0,0,0), this, IDW_PIECESLIST);
m_wndPiecesList.InsertColumn(0, "Description", LVCFMT_LEFT, 129, 0);
+ m_wndPiecesList.SubclassHeader();
if (m_bNumbers)
m_wndPiecesList.InsertColumn(1, "Number", LVCFMT_LEFT, 60, 1);
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);
+}
diff --git a/win/Piecelst.h b/win/Piecelst.h
index 8def787..e756dcc 100644
--- a/win/Piecelst.h
+++ b/win/Piecelst.h
@@ -8,6 +8,7 @@
//
#include "TitleTip.h"
+#include "SortHead.h"
/////////////////////////////////////////////////////////////////////////////
// CPiecesList window
@@ -23,6 +24,7 @@ public:
// Operations
public:
+ void SubclassHeader();
// Overrides
// ClassWizard generated virtual function overrides
@@ -38,7 +40,12 @@ public:
protected:
UINT m_nLastPieces[32];
int CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) const;
+
+ BOOL m_bAscending;
+ int m_nSortedCol;
+
CTitleTip m_TitleTip;
+ CSortHeaderCtrl m_HeaderCtrl;
//{{AFX_MSG(CPiecesList)
afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);
diff --git a/win/SortHead.cpp b/win/SortHead.cpp
new file mode 100755
index 0000000..f3e65d2
--- /dev/null
+++ b/win/SortHead.cpp
@@ -0,0 +1,163 @@
+// SortHead.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "leocad.h"
+#include "SortHead.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CSortHeaderCtrl
+
+CSortHeaderCtrl::CSortHeaderCtrl()
+{
+ m_nSortCol = -1;
+}
+
+CSortHeaderCtrl::~CSortHeaderCtrl()
+{
+}
+
+
+BEGIN_MESSAGE_MAP(CSortHeaderCtrl, CHeaderCtrl)
+ //{{AFX_MSG_MAP(CSortHeaderCtrl)
+ // NOTE - the ClassWizard will add and remove mapping macros here.
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CSortHeaderCtrl message handlers
+
+int CSortHeaderCtrl::SetSortImage(int nCol, BOOL bAsc)
+{
+ int nPrevCol = m_nSortCol;
+
+ m_nSortCol = nCol;
+ m_bSortAsc = bAsc;
+
+ // Change the item to ownder drawn
+ HD_ITEM hditem;
+
+ hditem.mask = HDI_FORMAT;
+ GetItem(nCol, &hditem);
+ hditem.fmt |= HDF_OWNERDRAW;
+ SetItem(nCol, &hditem);
+
+ // Invalidate header control so that it gets redrawn
+ Invalidate();
+
+ return nPrevCol;
+}
+
+void CSortHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
+{
+ CDC dc;
+ dc.Attach(lpDrawItemStruct->hDC);
+
+ // Get the column rect
+ CRect rcLabel(lpDrawItemStruct->rcItem);
+
+ // Save DC
+ int nSavedDC = dc.SaveDC();
+
+ // Set clipping region to limit drawing within column
+ CRgn rgn;
+ rgn.CreateRectRgnIndirect(&rcLabel);
+ dc.SelectObject(&rgn);
+ rgn.DeleteObject();
+
+ // Draw the background
+ dc.FillRect(rcLabel, &CBrush(::GetSysColor(COLOR_3DFACE)));
+
+ // Labels are offset by a certain amount
+ // This offset is related to the width of a space character
+ int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;
+
+ // Get the column text and format
+ TCHAR buf[256];
+ HD_ITEM hditem;
+ hditem.mask = HDI_TEXT | HDI_FORMAT;
+ hditem.pszText = buf;
+ hditem.cchTextMax = 255;
+
+ GetItem(lpDrawItemStruct->itemID, &hditem);
+
+ // Determine format for drawing column label
+ UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP
+ | DT_VCENTER | DT_END_ELLIPSIS ;
+
+ if (hditem.fmt & HDF_CENTER)
+ uFormat |= DT_CENTER;
+ else if (hditem.fmt & HDF_RIGHT)
+ uFormat |= DT_RIGHT;
+ else
+ uFormat |= DT_LEFT;
+
+ // Adjust the rect if the mouse button is pressed on it
+ if (lpDrawItemStruct->itemState == ODS_SELECTED)
+ {
+ rcLabel.left++;
+ rcLabel.top += 2;
+ rcLabel.right++;
+ }
+
+ // Adjust the rect further if Sort arrow is to be displayed
+ if (lpDrawItemStruct->itemID == (UINT)m_nSortCol)
+ rcLabel.right -= 3 * offset;
+
+ rcLabel.left += offset;
+ rcLabel.right -= offset;
+
+ // Draw column label
+ if (rcLabel.left < rcLabel.right)
+ dc.DrawText(buf,-1,rcLabel, uFormat);
+
+ // Draw the Sort arrow
+ if (lpDrawItemStruct->itemID == (UINT)m_nSortCol)
+ {
+ CRect rcIcon(lpDrawItemStruct->rcItem);
+
+ // Set up pens to use for drawing the triangle
+ CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
+ CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
+ CPen *pOldPen = dc.SelectObject(&penLight);
+
+ if (m_bSortAsc)
+ {
+ // Draw triangle pointing upwards
+ dc.MoveTo(rcIcon.right - 2*offset, offset-1);
+ dc.LineTo(rcIcon.right - 3*offset/2, rcIcon.bottom - offset);
+ dc.LineTo(rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset);
+ dc.MoveTo(rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1);
+
+ dc.SelectObject(&penShadow);
+ dc.LineTo(rcIcon.right - 2*offset, offset-2);
+ }
+ else
+ {
+ // Draw triangle pointing downwords
+ dc.MoveTo(rcIcon.right - 3*offset/2, offset-1);
+ dc.LineTo(rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1);
+ dc.MoveTo(rcIcon.right - 2*offset-1, rcIcon.bottom - offset);
+
+ dc.SelectObject(&penShadow);
+ dc.LineTo(rcIcon.right - 5*offset/2-1, offset -1);
+ dc.LineTo(rcIcon.right - 3*offset/2, offset -1);
+ }
+
+ // Restore the pen
+ dc.SelectObject(pOldPen);
+ }
+
+ // Restore dc
+ dc.RestoreDC(nSavedDC);
+
+ // Detach the dc before returning
+ dc.Detach();
+}
+
diff --git a/win/SortHead.h b/win/SortHead.h
new file mode 100755
index 0000000..3d2bc5b
--- /dev/null
+++ b/win/SortHead.h
@@ -0,0 +1,52 @@
+#if !defined(AFX_SORTHEAD_H__56F42684_B169_11D3_A5D1_AA1A6BED9842__INCLUDED_)
+#define AFX_SORTHEAD_H__56F42684_B169_11D3_A5D1_AA1A6BED9842__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+// SortHead.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CSortHeaderCtrl window
+
+class CSortHeaderCtrl : public CHeaderCtrl
+{
+// Construction
+public:
+ CSortHeaderCtrl();
+
+// Attributes
+protected:
+ int m_nSortCol;
+ BOOL m_bSortAsc;
+
+// Operations
+public:
+ int SetSortImage(int nCol, BOOL bAsc);
+
+// Overrides
+ // ClassWizard generated virtual function overrides
+ //{{AFX_VIRTUAL(CSortHeaderCtrl)
+ virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
+ //}}AFX_VIRTUAL
+
+// Implementation
+public:
+ virtual ~CSortHeaderCtrl();
+
+ // Generated message map functions
+protected:
+ //{{AFX_MSG(CSortHeaderCtrl)
+ // NOTE - the ClassWizard will add and remove member functions here.
+ //}}AFX_MSG
+
+ DECLARE_MESSAGE_MAP()
+};
+
+/////////////////////////////////////////////////////////////////////////////
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_SORTHEAD_H__56F42684_B169_11D3_A5D1_AA1A6BED9842__INCLUDED_)