7d7735816a270cb94b28974f71ec060cba02f965
[reactos.git] / include / reactos / rosctrls.h
1
2 #pragma once
3
4 class CListView: public CWindow
5 {
6 public:
7
8 HWND Create(HWND hWndParent, _U_RECT rect, LPCTSTR szWindowName = NULL, DWORD dwStyle = 0,
9 DWORD dwExStyle = 0, _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
10 {
11 m_hWnd = ::CreateWindowEx(dwExStyle,
12 WC_LISTVIEW,
13 szWindowName,
14 dwStyle,
15 rect.m_lpRect->left,
16 rect.m_lpRect->top,
17 rect.m_lpRect->right - rect.m_lpRect->left,
18 rect.m_lpRect->bottom - rect.m_lpRect->top,
19 hWndParent,
20 MenuOrID.m_hMenu,
21 _AtlBaseModule.GetModuleInstance(),
22 lpCreateParam);
23
24 return m_hWnd;
25 }
26
27 void SetRedraw(BOOL redraw)
28 {
29 SendMessage(WM_SETREDRAW, redraw);
30 }
31
32 BOOL SetTextBkColor(COLORREF cr)
33 {
34 return (BOOL)SendMessage(LVM_SETTEXTBKCOLOR, 0, cr);
35 }
36
37 BOOL SetBkColor(COLORREF cr)
38 {
39 return (BOOL)SendMessage(LVM_SETBKCOLOR, 0, cr);
40 }
41
42 BOOL SetTextColor(COLORREF cr)
43 {
44 return (BOOL)SendMessage(LVM_SETTEXTCOLOR, 0, cr);
45 }
46
47 DWORD SetExtendedListViewStyle(DWORD dw, DWORD dwMask = 0)
48 {
49 return (DWORD)SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, dwMask, dw);
50 }
51
52 int InsertColumn(int iCol, LV_COLUMN* pcol)
53 {
54 return (int)SendMessage(LVM_INSERTCOLUMN, iCol, reinterpret_cast<LPARAM>(pcol));
55 }
56
57 int InsertColumn(int iCol, LPWSTR pszText, int fmt, int width = -1, int iSubItem = -1, int iImage = -1, int iOrder = -1)
58 {
59 LV_COLUMN column = {0};
60 column.mask = LVCF_TEXT|LVCF_FMT;
61 column.pszText = pszText;
62 column.fmt = fmt;
63 if(width != -1)
64 {
65 column.mask |= LVCF_WIDTH;
66 column.cx = width;
67 }
68 if(iSubItem != -1)
69 {
70 column.mask |= LVCF_SUBITEM;
71 column.iSubItem = iSubItem;
72 }
73 if(iImage != -1)
74 {
75 column.mask |= LVCF_IMAGE;
76 column.iImage = iImage;
77 }
78 if(iOrder != -1)
79 {
80 column.mask |= LVCF_ORDER;
81 column.iOrder = iOrder;
82 }
83 return InsertColumn(iCol, &column);
84 }
85
86 int GetColumnWidth(int iCol)
87 {
88 return (int)SendMessage(LVM_GETCOLUMNWIDTH, iCol);
89 }
90
91 HIMAGELIST SetImageList(HIMAGELIST himl, int iImageList)
92 {
93 return (HIMAGELIST)SendMessage(LVM_SETIMAGELIST, iImageList, reinterpret_cast<LPARAM>(himl));
94 }
95
96 int InsertItem(const LV_ITEM * pitem)
97 {
98 return (int)SendMessage(LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(pitem));
99 }
100
101 BOOL DeleteItem(int i)
102 {
103 return (BOOL)SendMessage(LVM_DELETEITEM, i, 0);
104 }
105
106 BOOL GetItem(LV_ITEM* pitem)
107 {
108 return (BOOL)SendMessage(LVM_GETITEM, 0, reinterpret_cast<LPARAM>(pitem));
109 }
110
111 BOOL SetItem(const LV_ITEM * pitem)
112 {
113 return (BOOL)SendMessage(LVM_SETITEM, 0, reinterpret_cast<LPARAM>(pitem));
114 }
115
116 int GetItemCount()
117 {
118 return SendMessage(LVM_GETITEMCOUNT);
119 }
120
121 BOOL DeleteAllItems()
122 {
123 return (BOOL)SendMessage(LVM_DELETEALLITEMS);
124 }
125
126 BOOL Update(int i)
127 {
128 return (BOOL)SendMessage(LVM_UPDATE, i, 0);
129 }
130
131 UINT GetSelectedCount()
132 {
133 return (UINT)SendMessage(LVM_GETSELECTEDCOUNT);
134 }
135
136 BOOL SortItems(PFNLVCOMPARE pfnCompare, PVOID lParam)
137 {
138 return (BOOL)SendMessage(LVM_SORTITEMS, (WPARAM)lParam, (LPARAM) pfnCompare);
139 }
140
141 BOOL EnsureVisible(int i, BOOL fPartialOK)
142 {
143 return (BOOL)SendMessage(LVM_ENSUREVISIBLE, i, MAKELPARAM((fPartialOK),0));
144 }
145
146 HWND EditLabel(int i)
147 {
148 return (HWND)SendMessage(LVM_EDITLABEL, i, 0);
149 }
150
151 int GetSelectionMark()
152 {
153 return (int)SendMessage(LVM_GETSELECTIONMARK);
154 }
155
156 int GetNextItem(int i, WORD flags)
157 {
158 return (int)SendMessage(LVM_GETNEXTITEM, i, MAKELPARAM((flags),0));
159 }
160
161 void GetItemSpacing(SIZE& spacing, BOOL bSmallIconView = FALSE)
162 {
163 DWORD ret = SendMessage(LVM_GETITEMSPACING, bSmallIconView);
164 spacing.cx = LOWORD(ret);
165 spacing.cy = HIWORD(ret);
166 }
167
168 void SetItemState(int i, UINT state, UINT mask)
169 {
170 LV_ITEM item;
171 item.stateMask = mask;
172 item.state = state;
173 SendMessage(LVM_SETITEMSTATE, i, reinterpret_cast<LPARAM>(&item));
174 }
175
176 int HitTest(LV_HITTESTINFO * phtInfo)
177 {
178 return (int)SendMessage(LVM_HITTEST, 0, reinterpret_cast<LPARAM>(&phtInfo));
179 }
180
181 DWORD_PTR GetItemData(int i)
182 {
183 LVITEMW lvItem;
184 lvItem.iItem = i;
185 lvItem.mask = LVIF_PARAM;
186 BOOL ret = GetItem(&lvItem);
187 return (DWORD_PTR)(ret ? lvItem.lParam : NULL);
188 }
189
190 BOOL GetSelectedItem(LV_ITEM* pItem)
191 {
192 pItem->iItem = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
193 if (pItem->iItem == -1)
194 return FALSE;
195 return GetItem(pItem);
196 }
197
198 };
199
200 template<typename TItemData = DWORD_PTR>
201 class CToolbar :
202 public CWindowImplBaseT<CWindow>
203 {
204 public: // Configuration methods
205
206 HWND Create(HWND hWndParent, DWORD dwStyles = 0, DWORD dwExStyles = 0)
207 {
208 if (!dwStyles)
209 {
210 dwStyles = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
211 }
212
213 if (!dwExStyles)
214 {
215 dwExStyles = WS_EX_TOOLWINDOW;
216 }
217
218 m_hWnd = CreateWindowExW(dwExStyles,
219 TOOLBARCLASSNAME,
220 NULL,
221 dwStyles,
222 0, 0, 0, 0, hWndParent,
223 NULL,
224 _AtlBaseModule.GetModuleInstance(),
225 NULL);
226
227 if (!m_hWnd)
228 return NULL;
229
230 /* Identify the version we're using */
231 SetButtonStructSize();
232
233 return m_hWnd;
234 }
235
236 DWORD SetButtonStructSize()
237 {
238 return SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
239 }
240
241 HWND GetTooltip()
242 {
243 return (HWND)SendMessageW(TB_GETTOOLTIPS);
244 }
245
246 DWORD SetTooltip(HWND hWndTooltip)
247 {
248 return SendMessageW(TB_SETTOOLTIPS, hWndTooltip, 0);
249 }
250
251 INT GetHotItem()
252 {
253 return SendMessageW(TB_GETHOTITEM);
254 }
255
256 public: // Button list management methods
257 int GetButtonCount()
258 {
259 return SendMessageW(TB_BUTTONCOUNT);
260 }
261
262 DWORD GetButton(int index, TBBUTTON * btn)
263 {
264 return SendMessageW(TB_GETBUTTON, index, (LPARAM) btn);
265 }
266
267 DWORD AddButton(TBBUTTON * btn)
268 {
269 return SendMessageW(TB_ADDBUTTONS, 1, (LPARAM) btn);
270 }
271
272 DWORD AddButtons(int count, TBBUTTON * buttons)
273 {
274 return SendMessageW(TB_ADDBUTTONS, count, (LPARAM) buttons);
275 }
276
277 DWORD InsertButton(int insertAt, TBBUTTON * btn)
278 {
279 return SendMessageW(TB_INSERTBUTTON, insertAt, (LPARAM) btn);
280 }
281
282 DWORD MoveButton(int oldIndex, int newIndex)
283 {
284 return SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
285 }
286
287 DWORD DeleteButton(int index)
288 {
289 return SendMessageW(TB_DELETEBUTTON, index, 0);
290 }
291
292 DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
293 {
294 return SendMessageW(TB_GETBUTTONINFO, cmdId, (LPARAM) info);
295 }
296
297 DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
298 {
299 return SendMessageW(TB_SETBUTTONINFO, cmdId, (LPARAM) info);
300 }
301
302 public: // Layout management methods
303 DWORD SetButtonSize(int w, int h)
304 {
305 return SendMessageW(TB_SETBUTTONSIZE, 0, MAKELONG(w, h));
306 }
307
308 DWORD AutoSize()
309 {
310 return SendMessageW(TB_AUTOSIZE);
311 }
312
313 DWORD GetMetrics(TBMETRICS * tbm)
314 {
315 return SendMessageW(TB_GETMETRICS, 0, (LPARAM) tbm);
316 }
317
318 DWORD SetMetrics(TBMETRICS * tbm)
319 {
320 return SendMessageW(TB_SETMETRICS, 0, (LPARAM) tbm);
321 }
322
323 DWORD GetItemRect(int index, LPRECT prcItem)
324 {
325 return SendMessageW(TB_GETITEMRECT, index, (LPARAM) prcItem);
326 }
327
328 DWORD SetRedraw(BOOL bEnable)
329 {
330 return SendMessageW(WM_SETREDRAW, bEnable);
331 }
332
333 public: // Image list management methods
334 DWORD SetImageList(HIMAGELIST himl)
335 {
336 return SendMessageW(TB_SETIMAGELIST, 0, (LPARAM) himl);
337 }
338
339 public: // Other methods
340 INT HitTest(PPOINT ppt)
341 {
342 return (INT) SendMessageW(TB_HITTEST, 0, (LPARAM) ppt);
343 }
344
345 public: // Utility methods
346 TItemData * GetItemData(int index)
347 {
348 TBBUTTON btn;
349 GetButton(index, &btn);
350 return (TItemData*) btn.dwData;
351 }
352
353 DWORD SetItemData(int index, TItemData * data)
354 {
355 TBBUTTONINFOW info = { 0 };
356 info.cbSize = sizeof(info);
357 info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
358 info.lParam = (DWORD_PTR) data;
359 return SetButtonInfo(index, &info);
360 }
361 };