[SDK] -rosctrls.h: Add GetItemPosition and SetItemPosition methods in CListView.
[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 BOOL GetItemPosition(int nItem, POINT* pPoint)
219 {
220 return (BOOL)SendMessage(LVM_GETITEMPOSITION, nItem, (LPARAM)pPoint);
221 }
222
223 BOOL SetItemPosition(int nItem, POINT* pPoint)
224 {
225 return (BOOL)SendMessage(LVM_SETITEMPOSITION, nItem, MAKELPARAM(pPoint->x, pPoint->y));
226 }
227 };
228
229 template<typename TItemData = DWORD_PTR>
230 class CToolbar :
231 public CWindow
232 {
233 public: // Configuration methods
234
235 HWND Create(HWND hWndParent, DWORD dwStyles = 0, DWORD dwExStyles = 0)
236 {
237 if (!dwStyles)
238 {
239 dwStyles = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
240 }
241
242 if (!dwExStyles)
243 {
244 dwExStyles = WS_EX_TOOLWINDOW;
245 }
246
247 m_hWnd = CreateWindowExW(dwExStyles,
248 TOOLBARCLASSNAME,
249 NULL,
250 dwStyles,
251 0, 0, 0, 0, hWndParent,
252 NULL,
253 _AtlBaseModule.GetModuleInstance(),
254 NULL);
255
256 if (!m_hWnd)
257 return NULL;
258
259 /* Identify the version we're using */
260 SetButtonStructSize();
261
262 return m_hWnd;
263 }
264
265 DWORD SetButtonStructSize()
266 {
267 return SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
268 }
269
270 HWND GetTooltip()
271 {
272 return (HWND)SendMessageW(TB_GETTOOLTIPS);
273 }
274
275 DWORD SetTooltip(HWND hWndTooltip)
276 {
277 return SendMessageW(TB_SETTOOLTIPS, hWndTooltip, 0);
278 }
279
280 INT GetHotItem()
281 {
282 return SendMessageW(TB_GETHOTITEM);
283 }
284
285 DWORD SetHotItem(INT item)
286 {
287 return SendMessageW(TB_SETHOTITEM, item);
288 }
289
290 public: // Button list management methods
291 int GetButtonCount()
292 {
293 return SendMessageW(TB_BUTTONCOUNT);
294 }
295
296 DWORD GetButton(int index, TBBUTTON * btn)
297 {
298 return SendMessageW(TB_GETBUTTON, index, reinterpret_cast<LPARAM>(btn));
299 }
300
301 DWORD AddButton(TBBUTTON * btn)
302 {
303 return SendMessageW(TB_ADDBUTTONS, 1, reinterpret_cast<LPARAM>(btn));
304 }
305
306 DWORD AddButtons(int count, TBBUTTON * buttons)
307 {
308 return SendMessageW(TB_ADDBUTTONS, count, reinterpret_cast<LPARAM>(buttons));
309 }
310
311 DWORD InsertButton(int insertAt, TBBUTTON * btn)
312 {
313 return SendMessageW(TB_INSERTBUTTON, insertAt, reinterpret_cast<LPARAM>(btn));
314 }
315
316 DWORD MoveButton(int oldIndex, int newIndex)
317 {
318 return SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
319 }
320
321 DWORD DeleteButton(int index)
322 {
323 return SendMessageW(TB_DELETEBUTTON, index, 0);
324 }
325
326 DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
327 {
328 return SendMessageW(TB_GETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
329 }
330
331 DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
332 {
333 return SendMessageW(TB_SETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
334 }
335
336 DWORD CheckButton(int cmdId, BOOL bCheck)
337 {
338 return SendMessageW(TB_CHECKBUTTON, cmdId, MAKELPARAM(bCheck, 0));
339 }
340
341 public: // Layout management methods
342 DWORD GetButtonSize()
343 {
344 return SendMessageW(TB_GETBUTTONSIZE);
345 }
346
347 DWORD SetButtonSize(int w, int h)
348 {
349 return SendMessageW(TB_SETBUTTONSIZE, 0, MAKELPARAM(w, h));
350 }
351
352 DWORD AutoSize()
353 {
354 return SendMessageW(TB_AUTOSIZE);
355 }
356
357 DWORD GetMaxSize(LPSIZE size)
358 {
359 return SendMessageW(TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(size));
360 }
361
362 DWORD GetIdealSize(BOOL useHeight, LPSIZE size)
363 {
364 return SendMessageW(TB_GETIDEALSIZE, useHeight, reinterpret_cast<LPARAM>(size));
365 }
366
367 DWORD GetMetrics(TBMETRICS * tbm)
368 {
369 return SendMessageW(TB_GETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
370 }
371
372 DWORD SetMetrics(TBMETRICS * tbm)
373 {
374 return SendMessageW(TB_SETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
375 }
376
377 DWORD GetItemRect(int index, LPRECT prcItem)
378 {
379 return SendMessageW(TB_GETITEMRECT, index, reinterpret_cast<LPARAM>(prcItem));
380 }
381
382 DWORD SetRedraw(BOOL bEnable)
383 {
384 return SendMessageW(WM_SETREDRAW, bEnable);
385 }
386
387 DWORD GetPadding()
388 {
389 return SendMessageW(TB_GETPADDING);
390 }
391
392 DWORD SetPadding(int x, int y)
393 {
394 return SendMessageW(TB_SETPADDING, 0, MAKELPARAM(x, y));
395 }
396
397 public: // Image list management methods
398 DWORD SetImageList(HIMAGELIST himl)
399 {
400 return SendMessageW(TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(himl));
401 }
402
403 public: // Other methods
404 INT HitTest(PPOINT ppt)
405 {
406 return (INT) SendMessageW(TB_HITTEST, 0, reinterpret_cast<LPARAM>(ppt));
407 }
408
409 public: // Utility methods
410 TItemData * GetItemData(int index)
411 {
412 TBBUTTON btn;
413 GetButton(index, &btn);
414 return (TItemData*) btn.dwData;
415 }
416
417 DWORD SetItemData(int index, TItemData * data)
418 {
419 TBBUTTONINFOW info = { 0 };
420 info.cbSize = sizeof(info);
421 info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
422 info.lParam = (DWORD_PTR) data;
423 return SetButtonInfo(index, &info);
424 }
425 };
426
427 class CStatusBar :
428 public CWindow
429 {
430 public:
431 VOID SetText(LPCWSTR lpszText)
432 {
433 SendMessage(SB_SETTEXT, SBT_NOBORDERS, (LPARAM) lpszText);
434 }
435
436 HWND Create(HWND hwndParent, HMENU hMenu)
437 {
438 m_hWnd = CreateWindowExW(0,
439 STATUSCLASSNAMEW,
440 NULL,
441 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
442 0, 0, 0, 0,
443 hwndParent,
444 hMenu,
445 _AtlBaseModule.GetModuleInstance(),
446 NULL);
447
448 return m_hWnd;
449 }
450
451 };
452
453 class CTreeView :
454 public CWindow
455 {
456 public:
457 HWND Create(HWND hwndParent)
458 {
459 m_hWnd = CreateWindowExW(WS_EX_CLIENTEDGE,
460 WC_TREEVIEWW,
461 L"",
462 WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_SHOWSELALWAYS,
463 0, 28, 200, 350,
464 hwndParent,
465 NULL,
466 _AtlBaseModule.GetModuleInstance(),
467 NULL);
468
469 return m_hWnd;
470 }
471
472 HTREEITEM AddItem(HTREEITEM hParent, LPWSTR lpText, INT Image, INT SelectedImage, LPARAM lParam)
473 {
474 TVINSERTSTRUCTW Insert;
475
476 ZeroMemory(&Insert, sizeof(TV_INSERTSTRUCT));
477
478 Insert.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
479 Insert.hInsertAfter = TVI_LAST;
480 Insert.hParent = hParent;
481 Insert.item.iSelectedImage = SelectedImage;
482 Insert.item.iImage = Image;
483 Insert.item.lParam = lParam;
484 Insert.item.pszText = lpText;
485
486 return InsertItem(&Insert);
487 }
488
489 void SetRedraw(BOOL redraw)
490 {
491 SendMessage(WM_SETREDRAW, redraw);
492 }
493
494 BOOL SetBkColor(COLORREF cr)
495 {
496 return (BOOL) SendMessage(TVM_SETBKCOLOR, 0, cr);
497 }
498
499 BOOL SetTextColor(COLORREF cr)
500 {
501 return (BOOL) SendMessage(TVM_SETTEXTCOLOR, 0, cr);
502 }
503
504 HIMAGELIST SetImageList(HIMAGELIST himl, int iImageList)
505 {
506 return (HIMAGELIST) SendMessage(TVM_SETIMAGELIST, iImageList, reinterpret_cast<LPARAM>(himl));
507 }
508
509 HTREEITEM InsertItem(const TVINSERTSTRUCTW * pitem)
510 {
511 return (HTREEITEM) SendMessage(TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(pitem));
512 }
513
514 BOOL DeleteItem(HTREEITEM i)
515 {
516 return (BOOL) SendMessage(TVM_DELETEITEM, 0, (LPARAM)i);
517 }
518
519 BOOL GetItem(TV_ITEM* pitem)
520 {
521 return (BOOL) SendMessage(TVM_GETITEM, 0, reinterpret_cast<LPARAM>(pitem));
522 }
523
524 BOOL SetItem(const TV_ITEM * pitem)
525 {
526 return (BOOL) SendMessage(TVM_SETITEM, 0, reinterpret_cast<LPARAM>(pitem));
527 }
528
529 int GetItemCount()
530 {
531 return SendMessage(TVM_GETCOUNT);
532 }
533
534 BOOL EnsureVisible(HTREEITEM i)
535 {
536 return (BOOL) SendMessage(TVM_ENSUREVISIBLE, 0, (LPARAM)i);
537 }
538
539 HWND EditLabel(HTREEITEM i)
540 {
541 return (HWND) SendMessage(TVM_EDITLABEL, 0, (LPARAM)i);
542 }
543
544 HTREEITEM GetNextItem(HTREEITEM i, WORD flags)
545 {
546 return (HTREEITEM)SendMessage(TVM_GETNEXTITEM, flags, (LPARAM)i);
547 }
548
549 UINT GetItemState(int i, UINT mask)
550 {
551 return SendMessage(TVM_GETITEMSTATE, i, (LPARAM) mask);
552 }
553
554 HTREEITEM HitTest(TVHITTESTINFO * phtInfo)
555 {
556 return (HTREEITEM) SendMessage(TVM_HITTEST, 0, reinterpret_cast<LPARAM>(phtInfo));
557 }
558
559 DWORD_PTR GetItemData(HTREEITEM item)
560 {
561 TVITEMW lvItem;
562 lvItem.hItem = item;
563 lvItem.mask = TVIF_PARAM;
564 BOOL ret = GetItem(&lvItem);
565 return (DWORD_PTR) (ret ? lvItem.lParam : NULL);
566 }
567
568 HTREEITEM GetSelection()
569 {
570 return GetNextItem(NULL, TVGN_CARET);
571 }
572
573 BOOL Expand(HTREEITEM item, DWORD action)
574 {
575 return SendMessage(TVM_EXPAND, action, (LPARAM)item);
576 }
577
578 BOOL SelectItem(HTREEITEM item, DWORD action = TVGN_CARET)
579 {
580 return SendMessage(TVM_SELECTITEM, action, (LPARAM) item);
581 }
582
583 };