666bf0e12504b1f498b19f9b9f5aa11be8865fc7
[reactos.git] / reactos / sdk / 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 BOOL FindItem(int iStart, const LV_FINDINFO * plvfi)
117 {
118 return (BOOL)SendMessage(LVM_FINDITEM, iStart, (LPARAM) plvfi);
119 }
120
121 int GetItemCount()
122 {
123 return SendMessage(LVM_GETITEMCOUNT);
124 }
125
126 BOOL DeleteAllItems()
127 {
128 return (BOOL)SendMessage(LVM_DELETEALLITEMS);
129 }
130
131 BOOL Update(int i)
132 {
133 return (BOOL)SendMessage(LVM_UPDATE, i, 0);
134 }
135
136 UINT GetSelectedCount()
137 {
138 return (UINT)SendMessage(LVM_GETSELECTEDCOUNT);
139 }
140
141 BOOL SortItems(PFNLVCOMPARE pfnCompare, PVOID lParam)
142 {
143 return (BOOL)SendMessage(LVM_SORTITEMS, (WPARAM)lParam, (LPARAM) pfnCompare);
144 }
145
146 BOOL EnsureVisible(int i, BOOL fPartialOK)
147 {
148 return (BOOL)SendMessage(LVM_ENSUREVISIBLE, i, MAKELPARAM((fPartialOK),0));
149 }
150
151 HWND EditLabel(int i)
152 {
153 return (HWND)SendMessage(LVM_EDITLABEL, i, 0);
154 }
155
156 int GetSelectionMark()
157 {
158 return (int)SendMessage(LVM_GETSELECTIONMARK);
159 }
160
161 int GetNextItem(int i, WORD flags)
162 {
163 return (int)SendMessage(LVM_GETNEXTITEM, i, MAKELPARAM((flags),0));
164 }
165
166 void GetItemSpacing(SIZE& spacing, BOOL bSmallIconView = FALSE)
167 {
168 DWORD ret = SendMessage(LVM_GETITEMSPACING, bSmallIconView);
169 spacing.cx = LOWORD(ret);
170 spacing.cy = HIWORD(ret);
171 }
172
173 UINT GetItemState(int i, UINT mask)
174 {
175 return SendMessage(LVM_GETITEMSTATE, i, (LPARAM)mask);
176 }
177
178 void SetItemState(int i, UINT state, UINT mask)
179 {
180 LV_ITEM item;
181 item.stateMask = mask;
182 item.state = state;
183 SendMessage(LVM_SETITEMSTATE, i, reinterpret_cast<LPARAM>(&item));
184 }
185
186 int HitTest(LV_HITTESTINFO * phtInfo)
187 {
188 return (int)SendMessage(LVM_HITTEST, 0, reinterpret_cast<LPARAM>(phtInfo));
189 }
190
191 DWORD_PTR GetItemData(int i)
192 {
193 LVITEMW lvItem = { 0 };
194 lvItem.mask = LVIF_PARAM;
195 lvItem.iItem = i;
196 BOOL ret = GetItem(&lvItem);
197 return (DWORD_PTR)(ret ? lvItem.lParam : NULL);
198 }
199
200 BOOL GetSelectedItem(LV_ITEM* pItem)
201 {
202 pItem->iItem = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
203 if (pItem->iItem == -1)
204 return FALSE;
205 return GetItem(pItem);
206 }
207
208 void GetItemText(int iItem, int iSubItem, LPTSTR pszText, int cchTextMax)
209 {
210 LV_ITEM itemInfo;
211 itemInfo.iSubItem = iSubItem;
212 itemInfo.pszText = pszText;
213 itemInfo.cchTextMax = cchTextMax;
214
215 SendMessage(LVM_GETITEMTEXT, iItem, (LPARAM) &itemInfo);
216 }
217 };
218
219 template<typename TItemData = DWORD_PTR>
220 class CToolbar :
221 public CWindow
222 {
223 public: // Configuration methods
224
225 HWND Create(HWND hWndParent, DWORD dwStyles = 0, DWORD dwExStyles = 0)
226 {
227 if (!dwStyles)
228 {
229 dwStyles = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
230 }
231
232 if (!dwExStyles)
233 {
234 dwExStyles = WS_EX_TOOLWINDOW;
235 }
236
237 m_hWnd = CreateWindowExW(dwExStyles,
238 TOOLBARCLASSNAME,
239 NULL,
240 dwStyles,
241 0, 0, 0, 0, hWndParent,
242 NULL,
243 _AtlBaseModule.GetModuleInstance(),
244 NULL);
245
246 if (!m_hWnd)
247 return NULL;
248
249 /* Identify the version we're using */
250 SetButtonStructSize();
251
252 return m_hWnd;
253 }
254
255 DWORD SetButtonStructSize()
256 {
257 return SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
258 }
259
260 HWND GetTooltip()
261 {
262 return (HWND)SendMessageW(TB_GETTOOLTIPS);
263 }
264
265 DWORD SetTooltip(HWND hWndTooltip)
266 {
267 return SendMessageW(TB_SETTOOLTIPS, hWndTooltip, 0);
268 }
269
270 INT GetHotItem()
271 {
272 return SendMessageW(TB_GETHOTITEM);
273 }
274
275 DWORD SetHotItem(INT item)
276 {
277 return SendMessageW(TB_SETHOTITEM, item);
278 }
279
280 public: // Button list management methods
281 int GetButtonCount()
282 {
283 return SendMessageW(TB_BUTTONCOUNT);
284 }
285
286 DWORD GetButton(int index, TBBUTTON * btn)
287 {
288 return SendMessageW(TB_GETBUTTON, index, reinterpret_cast<LPARAM>(btn));
289 }
290
291 DWORD AddButton(TBBUTTON * btn)
292 {
293 return SendMessageW(TB_ADDBUTTONS, 1, reinterpret_cast<LPARAM>(btn));
294 }
295
296 DWORD AddButtons(int count, TBBUTTON * buttons)
297 {
298 return SendMessageW(TB_ADDBUTTONS, count, reinterpret_cast<LPARAM>(buttons));
299 }
300
301 DWORD InsertButton(int insertAt, TBBUTTON * btn)
302 {
303 return SendMessageW(TB_INSERTBUTTON, insertAt, reinterpret_cast<LPARAM>(btn));
304 }
305
306 DWORD MoveButton(int oldIndex, int newIndex)
307 {
308 return SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
309 }
310
311 DWORD DeleteButton(int index)
312 {
313 return SendMessageW(TB_DELETEBUTTON, index, 0);
314 }
315
316 DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
317 {
318 return SendMessageW(TB_GETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
319 }
320
321 DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
322 {
323 return SendMessageW(TB_SETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
324 }
325
326 DWORD CheckButton(int cmdId, BOOL bCheck)
327 {
328 return SendMessageW(TB_CHECKBUTTON, cmdId, MAKELPARAM(bCheck, 0));
329 }
330
331 public: // Layout management methods
332 DWORD GetButtonSize()
333 {
334 return SendMessageW(TB_GETBUTTONSIZE);
335 }
336
337 DWORD SetButtonSize(int w, int h)
338 {
339 return SendMessageW(TB_SETBUTTONSIZE, 0, MAKELPARAM(w, h));
340 }
341
342 DWORD AutoSize()
343 {
344 return SendMessageW(TB_AUTOSIZE);
345 }
346
347 DWORD GetMaxSize(LPSIZE size)
348 {
349 return SendMessageW(TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(size));
350 }
351
352 DWORD GetIdealSize(BOOL useHeight, LPSIZE size)
353 {
354 return SendMessageW(TB_GETIDEALSIZE, useHeight, reinterpret_cast<LPARAM>(size));
355 }
356
357 DWORD GetMetrics(TBMETRICS * tbm)
358 {
359 return SendMessageW(TB_GETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
360 }
361
362 DWORD SetMetrics(TBMETRICS * tbm)
363 {
364 return SendMessageW(TB_SETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
365 }
366
367 DWORD GetItemRect(int index, LPRECT prcItem)
368 {
369 return SendMessageW(TB_GETITEMRECT, index, reinterpret_cast<LPARAM>(prcItem));
370 }
371
372 DWORD SetRedraw(BOOL bEnable)
373 {
374 return SendMessageW(WM_SETREDRAW, bEnable);
375 }
376
377 DWORD GetPadding()
378 {
379 return SendMessageW(TB_GETPADDING);
380 }
381
382 DWORD SetPadding(int x, int y)
383 {
384 return SendMessageW(TB_SETPADDING, 0, MAKELPARAM(x, y));
385 }
386
387 public: // Image list management methods
388 DWORD SetImageList(HIMAGELIST himl)
389 {
390 return SendMessageW(TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(himl));
391 }
392
393 public: // Other methods
394 INT HitTest(PPOINT ppt)
395 {
396 return (INT) SendMessageW(TB_HITTEST, 0, reinterpret_cast<LPARAM>(ppt));
397 }
398
399 public: // Utility methods
400 TItemData * GetItemData(int index)
401 {
402 TBBUTTON btn;
403 GetButton(index, &btn);
404 return (TItemData*) btn.dwData;
405 }
406
407 DWORD SetItemData(int index, TItemData * data)
408 {
409 TBBUTTONINFOW info = { 0 };
410 info.cbSize = sizeof(info);
411 info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
412 info.lParam = (DWORD_PTR) data;
413 return SetButtonInfo(index, &info);
414 }
415 };
416
417 class CStatusBar :
418 public CWindow
419 {
420 public:
421 VOID SetText(LPCWSTR lpszText)
422 {
423 SendMessage(SB_SETTEXT, SBT_NOBORDERS, (LPARAM) lpszText);
424 }
425
426 HWND Create(HWND hwndParent, HMENU hMenu)
427 {
428 m_hWnd = CreateWindowExW(0,
429 STATUSCLASSNAMEW,
430 NULL,
431 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
432 0, 0, 0, 0,
433 hwndParent,
434 hMenu,
435 _AtlBaseModule.GetModuleInstance(),
436 NULL);
437
438 return m_hWnd;
439 }
440
441 };
442
443 class CTreeView :
444 public CWindow
445 {
446 public:
447 HWND Create(HWND hwndParent)
448 {
449 m_hWnd = CreateWindowExW(WS_EX_CLIENTEDGE,
450 WC_TREEVIEWW,
451 L"",
452 WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_SHOWSELALWAYS,
453 0, 28, 200, 350,
454 hwndParent,
455 NULL,
456 _AtlBaseModule.GetModuleInstance(),
457 NULL);
458
459 return m_hWnd;
460 }
461
462 HTREEITEM AddItem(HTREEITEM hParent, LPWSTR lpText, INT Image, INT SelectedImage, LPARAM lParam)
463 {
464 TVINSERTSTRUCTW Insert;
465
466 ZeroMemory(&Insert, sizeof(TV_INSERTSTRUCT));
467
468 Insert.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
469 Insert.hInsertAfter = TVI_LAST;
470 Insert.hParent = hParent;
471 Insert.item.iSelectedImage = SelectedImage;
472 Insert.item.iImage = Image;
473 Insert.item.lParam = lParam;
474 Insert.item.pszText = lpText;
475
476 return InsertItem(&Insert);
477 }
478
479 void SetRedraw(BOOL redraw)
480 {
481 SendMessage(WM_SETREDRAW, redraw);
482 }
483
484 BOOL SetBkColor(COLORREF cr)
485 {
486 return (BOOL) SendMessage(TVM_SETBKCOLOR, 0, cr);
487 }
488
489 BOOL SetTextColor(COLORREF cr)
490 {
491 return (BOOL) SendMessage(TVM_SETTEXTCOLOR, 0, cr);
492 }
493
494 HIMAGELIST SetImageList(HIMAGELIST himl, int iImageList)
495 {
496 return (HIMAGELIST) SendMessage(TVM_SETIMAGELIST, iImageList, reinterpret_cast<LPARAM>(himl));
497 }
498
499 HTREEITEM InsertItem(const TVINSERTSTRUCTW * pitem)
500 {
501 return (HTREEITEM) SendMessage(TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(pitem));
502 }
503
504 BOOL DeleteItem(HTREEITEM i)
505 {
506 return (BOOL) SendMessage(TVM_DELETEITEM, 0, (LPARAM)i);
507 }
508
509 BOOL GetItem(TV_ITEM* pitem)
510 {
511 return (BOOL) SendMessage(TVM_GETITEM, 0, reinterpret_cast<LPARAM>(pitem));
512 }
513
514 BOOL SetItem(const TV_ITEM * pitem)
515 {
516 return (BOOL) SendMessage(TVM_SETITEM, 0, reinterpret_cast<LPARAM>(pitem));
517 }
518
519 int GetItemCount()
520 {
521 return SendMessage(TVM_GETCOUNT);
522 }
523
524 BOOL EnsureVisible(HTREEITEM i)
525 {
526 return (BOOL) SendMessage(TVM_ENSUREVISIBLE, 0, (LPARAM)i);
527 }
528
529 HWND EditLabel(HTREEITEM i)
530 {
531 return (HWND) SendMessage(TVM_EDITLABEL, 0, (LPARAM)i);
532 }
533
534 HTREEITEM GetNextItem(HTREEITEM i, WORD flags)
535 {
536 return (HTREEITEM)SendMessage(TVM_GETNEXTITEM, flags, (LPARAM)i);
537 }
538
539 UINT GetItemState(int i, UINT mask)
540 {
541 return SendMessage(TVM_GETITEMSTATE, i, (LPARAM) mask);
542 }
543
544 HTREEITEM HitTest(TVHITTESTINFO * phtInfo)
545 {
546 return (HTREEITEM) SendMessage(TVM_HITTEST, 0, reinterpret_cast<LPARAM>(phtInfo));
547 }
548
549 DWORD_PTR GetItemData(HTREEITEM item)
550 {
551 TVITEMW lvItem;
552 lvItem.hItem = item;
553 lvItem.mask = TVIF_PARAM;
554 BOOL ret = GetItem(&lvItem);
555 return (DWORD_PTR) (ret ? lvItem.lParam : NULL);
556 }
557
558 HTREEITEM GetSelection()
559 {
560 return GetNextItem(NULL, TVGN_CARET);
561 }
562
563 BOOL Expand(HTREEITEM item, DWORD action)
564 {
565 return SendMessage(TVM_EXPAND, action, (LPARAM)item);
566 }
567
568 BOOL SelectItem(HTREEITEM item, DWORD action = TVGN_CARET)
569 {
570 return SendMessage(TVM_SELECTITEM, action, (LPARAM) item);
571 }
572
573 };