update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / UIDATA.H
1 //*******************************************************************************
2 // COPYRIGHT NOTES
3 // ---------------
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.
10 // 
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com 
13 // after Sept 2000
14 // 
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
17
18 #ifndef __LISTCTRLDATA_H__
19 #define __LISTCTRLDATA_H__ 
20
21 ////////////////////////////////////////////////
22 // CUIODColumnCtrl
23 // Interface for an owner draw control in a list control column
24 ////////////////////////////////////////////////
25 class CUIODColumnCtrl : public CObject
26 {
27         DECLARE_DYNAMIC(CUIODColumnCtrl);
28 public:
29         CUIODColumnCtrl();
30         virtual ~CUIODColumnCtrl();
31 public:
32         virtual void DoPaint(CDC *PaintDC,CRect rcClient,bool bSelected)=0;
33 protected:
34 private:
35 };
36
37 inline CUIODColumnCtrl::CUIODColumnCtrl()
38 {
39 }
40
41 inline CUIODColumnCtrl::~CUIODColumnCtrl()
42 {
43 }
44
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 
50 {
51 public:
52     DECLARE_DYNAMIC(CUIListCtrlData)
53     CUIListCtrlData(int nCols=1);
54     ~CUIListCtrlData();
55         void Init(int nCols);
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;
71 protected:
72         void DestroyFonts();
73         void DestroyCtrls();
74         void CreateNewFont(int nCol,LOGFONT &lf);
75 // Get/Set Methods
76 public:
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;
83 private:
84     CDWordArray m_arBkColors;
85     CDWordArray m_arTextColors;
86         CObArray m_arFonts;
87         DWORD m_dwExtData;
88         CObArray m_arCtrl;      
89         bool m_bAutoDelete;
90         bool m_bDeleted;
91 };
92
93 inline int CUIListCtrlData::GetCtrlCount() const
94 {
95         int nCount=0;
96         for(int i=0;i < m_arCtrl.GetSize();i++)
97         {
98                 if (m_arCtrl.GetAt(i) != NULL)
99                 {
100                         nCount++;
101                 }
102         }
103         return nCount;
104 }
105
106 inline CUIODColumnCtrl *CUIListCtrlData::GetCtrl(int nCol) const
107 {
108         CUIODColumnCtrl *pCtrl = (CUIODColumnCtrl*)m_arCtrl.GetAt(nCol);
109         return pCtrl;
110 }
111
112 inline void CUIListCtrlData::DestroyCtrl(int nCol)
113 {
114         CUIODColumnCtrl *pOldCtrl = (CUIODColumnCtrl*)m_arCtrl[nCol];
115         delete pOldCtrl;
116         m_arCtrl[nCol] = NULL;
117 }
118
119 inline void CUIListCtrlData::SetCtrl(CUIODColumnCtrl *pCtrl,int nCol) 
120 {
121         DestroyCtrl(nCol);
122         ASSERT_KINDOF(CUIODColumnCtrl,pCtrl);
123         m_arCtrl[nCol] = pCtrl;
124 }
125
126 inline void CUIListCtrlData::SetAutoDelete(bool bAutoDelete)
127 {
128         m_bAutoDelete = bAutoDelete;
129 }
130
131 inline bool CUIListCtrlData::GetAutoDelete() const
132 {
133         return m_bAutoDelete;
134 }
135
136 inline void CUIListCtrlData::SetDeleted(bool bDeleted)
137 {
138         m_bDeleted = bDeleted;
139 }
140
141 inline bool CUIListCtrlData::IsDeleted() const
142 {
143         return m_bDeleted;
144 }
145
146 inline const CFont *CUIListCtrlData::GetFont(int nCol) const
147
148         return (const CFont*)m_arFonts[nCol]; 
149 }
150
151 inline COLORREF CUIListCtrlData::GetTextColor(int nCol) const
152
153         return m_arTextColors[nCol]; 
154 }
155
156 inline COLORREF CUIListCtrlData::GetBkColor(int nCol) const 
157
158         return m_arBkColors[nCol]; 
159 }
160
161 inline DWORD CUIListCtrlData::GetExtData() const 
162
163         return m_dwExtData; 
164 }
165
166 inline void CUIListCtrlData::SetBkColor(COLORREF BkColor,int nCol) 
167
168         if (nCol == -1)
169         {
170                 for(int i=0;i < m_arBkColors.GetSize();i++)
171                 {
172                         m_arBkColors[i] = BkColor;
173                 }
174         }
175         else
176                 m_arBkColors[nCol] = BkColor; 
177 }
178
179 inline void CUIListCtrlData::SetTextColor(COLORREF TextColor,int nCol) 
180
181         if (nCol == -1)
182         {
183                 for(int i=0;i < m_arTextColors.GetSize();i++)
184                 {
185                         m_arTextColors[i] = TextColor;
186                 }
187         }
188         else
189                 m_arTextColors[nCol] = TextColor; 
190 }
191
192 inline void CUIListCtrlData::SetDefaultTextColor(int nCol) 
193
194         SetTextColor(::GetSysColor(COLOR_WINDOWTEXT),nCol); 
195 }
196
197 inline void CUIListCtrlData::SetDefaultBkColor(int nCol) 
198
199         SetBkColor(::GetSysColor(COLOR_WINDOW),nCol); 
200 }
201
202 inline void CUIListCtrlData::SetExtData(DWORD dwExtData) 
203
204         m_dwExtData = dwExtData; 
205 }
206
207 // for ODBC databases
208 class CTRL_EXT_CLASS CUIDBListCtrlData : public CUIListCtrlData 
209 {
210 public:
211         CUIDBListCtrlData(int nCols) : CUIListCtrlData(nCols) { }
212     DECLARE_DYNAMIC(CUIDBListCtrlData)
213         const GetRecNum() { return m_nRecNum; }
214         void SetRecNum(long nRecNum) { m_nRecNum = nRecNum; }
215 private:
216         long m_nRecNum;                 // for ODBC connection to record sets
217 };
218
219 // used by the Ownerdraw combo box
220 class CTRL_EXT_CLASS CUIComboBoxData : public CUIListCtrlData 
221 {
222     DECLARE_DYNAMIC(CUIComboBoxData)
223 public:
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; }
229 private:
230         CString m_strText;                      // for displaying text in OD combo boxes with columns
231         int m_nImageIndex;
232 };
233
234 // keep our own copy of strings in the list control to ease sorting
235 class CTRL_EXT_CLASS CUIStrListCtrlData : public CUIListCtrlData 
236 {
237 public:
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);
246 private:
247         CStringArray m_StringArray;
248         CString m_strExtraText;
249 };
250
251 inline int CUIStrListCtrlData::GetStringLen(int nCol) const
252
253         return m_StringArray[nCol].GetLength();
254 }
255
256 inline void CUIStrListCtrlData::AddExtraString(LPCTSTR pszExtraText) 
257
258         m_strExtraText = pszExtraText;
259 }
260
261 inline const CString &CUIStrListCtrlData::GetExtraString() const
262
263         return m_strExtraText;
264 }
265
266 // Used internally to help sorting
267 class CUIODListCtrlSortInfo : public CObject
268 {
269 public:
270         CUIODListCtrlSortInfo(int nSubItem,int ColType,BOOL bSortAscending);
271         BOOL Ascending() const;
272         int GetColumn() const;
273         int GetColType() const;
274 private:
275         BOOL m_bSortAscending;
276         int m_nSubItem;
277         int m_ColType;
278 };
279
280 inline CUIODListCtrlSortInfo::CUIODListCtrlSortInfo(int nSubItem,int ColType,BOOL bSortAscending) 
281         : m_nSubItem(nSubItem),m_ColType(ColType),m_bSortAscending(bSortAscending)
282 {
283 }
284
285 inline BOOL CUIODListCtrlSortInfo::Ascending() const
286 {
287         return m_bSortAscending;
288 }
289
290 inline int CUIODListCtrlSortInfo::GetColumn() const
291 {
292         return m_nSubItem;
293 }
294
295 inline int CUIODListCtrlSortInfo::GetColType() const
296 {
297         return m_ColType;
298 }
299
300 #endif // __LISTCTRLDATA_H__