1 //*******************************************************************************
4 // You may use this source code, compile or redistribute it as part of your application
5 // for free. You cannot redistribute it as a part of a software development
6 // library without the agreement of the author. If the sources are
7 // distributed along with the application, you should leave the original
8 // copyright notes in the source code without any changes.
9 // This code can be used WITHOUT ANY WARRANTIES at your own risk.
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
18 #ifndef __LISTCTRLDATA_H__
19 #define __LISTCTRLDATA_H__
21 ////////////////////////////////////////////////
23 // Interface for an owner draw control in a list control column
24 ////////////////////////////////////////////////
25 class CUIODColumnCtrl : public CObject
27 DECLARE_DYNAMIC(CUIODColumnCtrl);
30 virtual ~CUIODColumnCtrl();
32 virtual void DoPaint(CDC *PaintDC,CRect rcClient,bool bSelected)=0;
37 inline CUIODColumnCtrl::CUIODColumnCtrl()
41 inline CUIODColumnCtrl::~CUIODColumnCtrl()
45 // Internal extension data for each row in the list control
46 // if you wish to override the default behaviour
47 // a class should be derived from this one and the GetListCtrlData method
48 // should be overridden in the list control class
49 class CTRL_EXT_CLASS CUIListCtrlData : public CObject
52 DECLARE_DYNAMIC(CUIListCtrlData)
53 CUIListCtrlData(int nCols=1);
56 // functions to change the color of each row
57 COLORREF GetTextColor(int nCol=0) const;
58 COLORREF GetBkColor(int nCol=0) const;
59 const CFont *GetFont(int nCol=0) const;
60 void SetBkColor(COLORREF BkColor,int nCol=-1);
61 void SetTextColor(COLORREF TextColor,int nCol=-1);
62 void SetDefaultBkColor(int nCol=-1);
63 void SetDefaultTextColor(int nCol=-1);
64 void SetFont(CFont *pFont,int nCol=-1);
65 void SetCtrl(CUIODColumnCtrl *pCtrl,int nCol);
66 void DestroyCtrl(int nCol);
67 // emulate the CListCtrl class by allowing user defined extension data
68 DWORD GetExtData() const;
69 void SetExtData(DWORD dwExtData);
70 BOOL IsFontSet(int nCol=-1) const;
74 void CreateNewFont(int nCol,LOGFONT &lf);
77 void SetAutoDelete(bool bAutoDelete);
78 bool GetAutoDelete() const;
79 int GetCtrlCount() const;
80 CUIODColumnCtrl *GetCtrl(int nCol) const;
81 void SetDeleted(bool bDeleted);
82 bool IsDeleted() const;
84 CDWordArray m_arBkColors;
85 CDWordArray m_arTextColors;
93 inline int CUIListCtrlData::GetCtrlCount() const
96 for(int i=0;i < m_arCtrl.GetSize();i++)
98 if (m_arCtrl.GetAt(i) != NULL)
106 inline CUIODColumnCtrl *CUIListCtrlData::GetCtrl(int nCol) const
108 CUIODColumnCtrl *pCtrl = (CUIODColumnCtrl*)m_arCtrl.GetAt(nCol);
112 inline void CUIListCtrlData::DestroyCtrl(int nCol)
114 CUIODColumnCtrl *pOldCtrl = (CUIODColumnCtrl*)m_arCtrl[nCol];
116 m_arCtrl[nCol] = NULL;
119 inline void CUIListCtrlData::SetCtrl(CUIODColumnCtrl *pCtrl,int nCol)
122 ASSERT_KINDOF(CUIODColumnCtrl,pCtrl);
123 m_arCtrl[nCol] = pCtrl;
126 inline void CUIListCtrlData::SetAutoDelete(bool bAutoDelete)
128 m_bAutoDelete = bAutoDelete;
131 inline bool CUIListCtrlData::GetAutoDelete() const
133 return m_bAutoDelete;
136 inline void CUIListCtrlData::SetDeleted(bool bDeleted)
138 m_bDeleted = bDeleted;
141 inline bool CUIListCtrlData::IsDeleted() const
146 inline const CFont *CUIListCtrlData::GetFont(int nCol) const
148 return (const CFont*)m_arFonts[nCol];
151 inline COLORREF CUIListCtrlData::GetTextColor(int nCol) const
153 return m_arTextColors[nCol];
156 inline COLORREF CUIListCtrlData::GetBkColor(int nCol) const
158 return m_arBkColors[nCol];
161 inline DWORD CUIListCtrlData::GetExtData() const
166 inline void CUIListCtrlData::SetBkColor(COLORREF BkColor,int nCol)
170 for(int i=0;i < m_arBkColors.GetSize();i++)
172 m_arBkColors[i] = BkColor;
176 m_arBkColors[nCol] = BkColor;
179 inline void CUIListCtrlData::SetTextColor(COLORREF TextColor,int nCol)
183 for(int i=0;i < m_arTextColors.GetSize();i++)
185 m_arTextColors[i] = TextColor;
189 m_arTextColors[nCol] = TextColor;
192 inline void CUIListCtrlData::SetDefaultTextColor(int nCol)
194 SetTextColor(::GetSysColor(COLOR_WINDOWTEXT),nCol);
197 inline void CUIListCtrlData::SetDefaultBkColor(int nCol)
199 SetBkColor(::GetSysColor(COLOR_WINDOW),nCol);
202 inline void CUIListCtrlData::SetExtData(DWORD dwExtData)
204 m_dwExtData = dwExtData;
207 // for ODBC databases
208 class CTRL_EXT_CLASS CUIDBListCtrlData : public CUIListCtrlData
211 CUIDBListCtrlData(int nCols) : CUIListCtrlData(nCols) { }
212 DECLARE_DYNAMIC(CUIDBListCtrlData)
213 const GetRecNum() { return m_nRecNum; }
214 void SetRecNum(long nRecNum) { m_nRecNum = nRecNum; }
216 long m_nRecNum; // for ODBC connection to record sets
219 // used by the Ownerdraw combo box
220 class CTRL_EXT_CLASS CUIComboBoxData : public CUIListCtrlData
222 DECLARE_DYNAMIC(CUIComboBoxData)
224 CUIComboBoxData(int nCols) : CUIListCtrlData(nCols), m_nImageIndex(-1) {}
225 CString GetText(int nCol = -1) const;
226 int GetImageIndex() const { return m_nImageIndex; }
227 void SetText(LPCTSTR szText) { m_strText = szText; }
228 void SetImageIndex(int nImageIndex) { m_nImageIndex = nImageIndex; }
230 CString m_strText; // for displaying text in OD combo boxes with columns
234 // keep our own copy of strings in the list control to ease sorting
235 class CTRL_EXT_CLASS CUIStrListCtrlData : public CUIListCtrlData
238 DECLARE_DYNAMIC(CUIStrListCtrlData)
239 CUIStrListCtrlData(int nColumns);
240 CUIStrListCtrlData();
241 LPTSTR GetString(int nCol);
242 const CString &GetExtraString() const;
243 void AddExtraString(LPCTSTR pszExtraText);
244 int GetStringLen(int nCol) const;
245 BOOL AddString(int nCol,LPCTSTR szText);
247 CStringArray m_StringArray;
248 CString m_strExtraText;
251 inline int CUIStrListCtrlData::GetStringLen(int nCol) const
253 return m_StringArray[nCol].GetLength();
256 inline void CUIStrListCtrlData::AddExtraString(LPCTSTR pszExtraText)
258 m_strExtraText = pszExtraText;
261 inline const CString &CUIStrListCtrlData::GetExtraString() const
263 return m_strExtraText;
266 // Used internally to help sorting
267 class CUIODListCtrlSortInfo : public CObject
270 CUIODListCtrlSortInfo(int nSubItem,int ColType,BOOL bSortAscending);
271 BOOL Ascending() const;
272 int GetColumn() const;
273 int GetColType() const;
275 BOOL m_bSortAscending;
280 inline CUIODListCtrlSortInfo::CUIODListCtrlSortInfo(int nSubItem,int ColType,BOOL bSortAscending)
281 : m_nSubItem(nSubItem),m_ColType(ColType),m_bSortAscending(bSortAscending)
285 inline BOOL CUIODListCtrlSortInfo::Ascending() const
287 return m_bSortAscending;
290 inline int CUIODListCtrlSortInfo::GetColumn() const
295 inline int CUIODListCtrlSortInfo::GetColType() const
300 #endif // __LISTCTRLDATA_H__