soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SListCtrl.h
1#ifndef __SLISTCTRL__H__
2#define __SLISTCTRL__H__
3
4#include "core/SPanel.h"
5#include "SHeaderCtrl.h"
6
7SNSBEGIN
8
9/**
10 * @enum SListCtrlFlags
11 * @brief Flags for list control items
12 * @details Flags used to specify which attributes of a list item are valid.
13 */
14enum SListCtrlFlags
15{
16 S_LVIF_TEXT = 0x01, /**< Text attribute is valid */
17 S_LVIF_IMAGE = 0x02, /**< Image attribute is valid */
18 S_LVIF_INDENT = 0x04, /**< Indent attribute is valid */
19};
20
21/**
22 * @typedef PFNLVCOMPAREEX
23 * @brief Comparison function type for sorting
24 * @details Function pointer type for the comparison function used in sorting.
25 */
26typedef int(__cdecl *PFNLVCOMPAREEX)(void *, const void *, const void *);
27
28/**
29 * @struct DXLVSUBITEM
30 * @brief Subitem structure
31 * @details Structure representing a subitem in the list control.
32 */
33typedef struct DXLVSUBITEM
34{
35 /**
36 * @brief Constructor
37 */
39 {
40 mask = 0;
41 nImage = 0;
42 strText = NULL;
43 cchTextMax = 0;
44 nIndent = 0;
45 }
46
47 UINT mask; /**< Mask indicating which attributes are valid */
48 LPTSTR strText; /**< Text of the subitem */
49 int cchTextMax; /**< Maximum length of the text */
50 UINT nImage; /**< Icon index */
51 int nIndent; /**< Indent level */
53
54typedef SArray<DXLVSUBITEM> ArrSubItem; /**< Array of subitems */
55
56/**
57 * @struct DXLVITEM
58 * @brief Item structure
59 * @details Structure representing an item in the list control.
60 */
61typedef struct DXLVITEM
62{
63 /**
64 * @brief Constructor
65 */
67 {
68 dwData = 0;
69 arSubItems = NULL;
70 checked = FALSE;
71 }
72
73 ArrSubItem *arSubItems; /**< Array of subitems */
74 LPARAM dwData; /**< Additional data */
75 BOOL checked; /**< Check state */
76} DXLVITEM;
77
78/**
79 * @class SListCtrl
80 * @brief List Control
81 * @details A control that displays a list of items with multiple columns and subitems.
82 */
83class SOUI_EXP SListCtrl : public SPanel {
84 DEF_SOBJECT(SPanel, L"listctrl")
85
86 public:
87 /**
88 * @brief Constructor
89 */
90 SListCtrl();
91
92 /**
93 * @brief Destructor
94 */
95 virtual ~SListCtrl();
96
97 /**
98 * @brief Insert a column
99 * @param nIndex Index at which to insert the column
100 * @param pszText Column title
101 * @param nWidth Column width
102 * @param fmt Format flags
103 * @param lParam Additional parameter
104 * @return Index of the inserted column
105 */
106 int InsertColumn(int nIndex, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam = 0);
107
108 /**
109 * @brief Insert an item
110 * @param nItem Index at which to insert the item
111 * @param pszText Text of the item
112 * @param nImage Icon index
113 * @return Index of the inserted item
114 */
115 int InsertItem(int nItem, LPCTSTR pszText, int nImage = -1);
116
117 /**
118 * @brief Set the data associated with an item
119 * @param nItem Index of the item
120 * @param dwData Additional data
121 * @return TRUE if successful, FALSE otherwise
122 */
123 BOOL SetItemData(int nItem, LPARAM dwData);
124
125 /**
126 * @brief Get the data associated with an item
127 * @param nItem Index of the item
128 * @return Additional data
129 */
130 LPARAM GetItemData(int nItem);
131
132 /**
133 * @brief Set a subitem
134 * @param nItem Index of the item
135 * @param nSubItem Index of the subitem
136 * @param plv Pointer to the subitem structure
137 * @return TRUE if successful, FALSE otherwise
138 */
139 BOOL SetSubItem(int nItem, int nSubItem, const DXLVSUBITEM *plv);
140
141 /**
142 * @brief Get a subitem
143 * @param nItem Index of the item
144 * @param nSubItem Index of the subitem
145 * @param plv Pointer to the subitem structure
146 * @return TRUE if successful, FALSE otherwise
147 */
148 BOOL GetSubItem(int nItem, int nSubItem, DXLVSUBITEM *plv) const;
149
150 /**
151 * @brief Set the text of a subitem
152 * @param nItem Index of the item
153 * @param nSubItem Index of the subitem
154 * @param pszText Text to set
155 * @return TRUE if successful, FALSE otherwise
156 */
157 BOOL SetSubItemText(int nItem, int nSubItem, LPCTSTR pszText);
158
159 /**
160 * @brief Get the text of a subitem
161 * @param nItem Index of the item
162 * @param nSubItem Index of the subitem
163 * @return Text of the subitem
164 */
165 SStringT GetSubItemText(int nItem, int nSubItem) const;
166
167 /**
168 * @brief Get the selected item
169 * @return Index of the selected item
170 */
171 int GetSelectedItem();
172
173 /**
174 * @brief Set the selected item
175 * @param nItem Index of the item to select
176 */
177 void SetSelectedItem(int nItem);
178
179 /**
180 * @brief Get the total number of items
181 * @return Number of items
182 */
183 int GetItemCount() const;
184
185 /**
186 * @brief Set the total number of items
187 * @param nItems Number of items
188 * @param nGrowBy Growth increment
189 * @return TRUE if successful, FALSE otherwise
190 */
191 BOOL SetItemCount(int nItems, int nGrowBy);
192
193 /**
194 * @brief Get the total number of columns
195 * @return Number of columns
196 */
197 int GetColumnCount() const;
198
199 /**
200 * @brief Get the number of items per page
201 * @param bPartial Whether to include partial items
202 * @return Number of items per page
203 */
204 int GetCountPerPage(BOOL bPartial);
205
206 /**
207 * @brief Delete a specific item
208 * @param nItem Index of the item to delete
209 */
210 void DeleteItem(int nItem);
211
212 /**
213 * @brief Delete a specific column
214 * @param iCol Index of the column to delete
215 */
216 void DeleteColumn(int iCol);
217
218 /**
219 * @brief Delete all items
220 */
221 void DeleteAllItems();
222
223 /**
224 * @brief Sort items using a comparison function
225 * @param pfnCompare Comparison function
226 * @param pContext Context for the comparison function
227 * @return TRUE if successful, FALSE otherwise
228 */
229 BOOL SortItems(PFNLVCOMPAREEX pfnCompare, void *pContext);
230
231 /**
232 * @brief Get the check state of an item
233 * @param nItem Index of the item
234 * @return Check state of the item
235 */
236 BOOL GetCheckState(int nItem);
237
238 /**
239 * @brief Set the check state of an item
240 * @param nItem Index of the item
241 * @param bCheck Check state to set
242 * @return TRUE if successful, FALSE otherwise
243 */
244 BOOL SetCheckState(int nItem, BOOL bCheck);
245
246 /**
247 * @brief Get the number of checked items
248 * @return Number of checked items
249 */
251
252 /**
253 * @brief Get the header control
254 * @return Pointer to the header control
255 */
256 SHeaderCtrl *GetHeaderCtrl() const;
257
258 /**
259 * @brief Get the first checked item
260 * @return Index of the first checked item
261 */
263
264 /**
265 * @brief Get the last checked item
266 * @return Index of the last checked item
267 */
268 int GetLastCheckedItem();
269
270 /**
271 * @brief Enable or disable multiple selection
272 * @param enable Enable flag
273 */
274 VOID EnableMultiSelection(BOOL enable)
275 {
276 m_bMultiSelection = enable;
277 }
278
279 /**
280 * @brief Enable or disable checkboxes
281 * @param enable Enable flag
282 */
283 VOID EnableCheckBox(BOOL enable)
284 {
285 m_bCheckBox = enable;
286 }
287
288 /**
289 * @brief Enable or disable hot tracking
290 * @param enable Enable flag
291 */
292 VOID EnableHotTrack(BOOL enable)
293 {
294 m_bHotTrack = enable;
295 }
296
297 protected:
298 /**
299 * @brief Create child items from XML configuration
300 * @param xmlNode XML node for the child items
301 * @return TRUE if successful, FALSE otherwise
302 */
303 virtual BOOL CreateChildren(SXmlNode xmlNode);
304
305 /**
306 * @brief Hit test to determine the item under the mouse
307 * @param pt Mouse coordinates
308 * @return Index of the item or -1 if no item
309 */
310 int HitTest(const CPoint &pt);
311
312 /**
313 * @brief Get the index of the top visible item
314 * @return Index of the top visible item
315 */
316 int GetTopIndex() const;
317
318 /**
319 * @brief Get the rectangle of an item
320 * @param nItem Index of the item
321 * @param nSubItem Index of the subitem
322 * @return Rectangle of the item
323 */
324 CRect GetItemRect(int nItem, int nSubItem = 0);
325
326 /**
327 * @brief Draw an item
328 * @param pRT Rendering target handle
329 * @param rcItem Rectangle for the item
330 * @param nItem Index of the item
331 */
332 virtual void DrawItem(IRenderTarget *pRT, CRect rcItem, int nItem);
333
334 /**
335 * @brief Redraw a specific item
336 * @param nItem Index of the item to redraw
337 */
338 void RedrawItem(int nItem);
339
340 /**
341 * @brief Notify of selection change
342 * @param nOldSel Old selected index
343 * @param nNewSel New selected index
344 * @param checkBox Whether the change is due to a checkbox
345 */
346 void NotifySelChange(int nOldSel, int nNewSel, BOOL checkBox = FALSE);
347
348 /**
349 * @brief Paint the control
350 * @param pRT Rendering target handle
351 */
352 void OnPaint(IRenderTarget *pRT);
353
354 /**
355 * @brief Handle destroy event
356 */
357 void OnDestroy();
358
359 /**
360 * @brief Handle header click event
361 * @param pEvt Event arguments
362 * @return TRUE if handled, FALSE otherwise
363 */
364 BOOL OnHeaderClick(IEvtArgs *pEvt);
365
366 /**
367 * @brief Handle header size changing event
368 * @param pEvt Event arguments
369 * @return TRUE if handled, FALSE otherwise
370 */
371 BOOL OnHeaderSizeChanging(IEvtArgs *pEvt);
372
373 /**
374 * @brief Handle header swap event
375 * @param pEvt Event arguments
376 * @return TRUE if handled, FALSE otherwise
377 */
378 BOOL OnHeaderSwap(IEvtArgs *pEvt);
379
380 /**
381 * @brief Handle scroll event
382 * @param bVertical Whether the scroll is vertical
383 * @param uCode Scroll type
384 * @param nPos Scroll position
385 * @return TRUE if handled, FALSE otherwise
386 */
387 virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos);
388
389 /**
390 * @brief Handle left mouse button down event
391 * @param nFlags Flags
392 * @param pt Mouse coordinates
393 */
394 void OnLButtonDown(UINT nFlags, CPoint pt);
395
396 /**
397 * @brief Handle left mouse button double-click event
398 * @param nFlags Flags
399 * @param pt Mouse coordinates
400 */
401 void OnLButtonDbClick(UINT nFlags, CPoint pt);
402
403 /**
404 * @brief Handle left mouse button up event
405 * @param nFlags Flags
406 * @param pt Mouse coordinates
407 */
408 void OnLButtonUp(UINT nFlags, CPoint pt);
409
410 /**
411 * @brief Handle mouse move event
412 * @param nFlags Flags
413 * @param pt Mouse coordinates
414 */
415 void OnMouseMove(UINT nFlags, CPoint pt);
416
417 /**
418 * @brief Handle mouse leave event
419 */
420 void OnMouseLeave();
421
422 /**
423 * @brief Handle size change event
424 * @param nType Size change type
425 * @param size New size
426 */
427 void OnSize(UINT nType, CSize size);
428
429 /**
430 * @brief Update the position of child items
431 */
432 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
433
434 /**
435 * @brief Get the rectangle of the list
436 * @return Rectangle of the list
437 */
438 CRect GetListRect();
439
440 /**
441 * @brief Update the scroll bar
442 */
443 void UpdateScrollBar();
444
445 /**
446 * @brief Update the header control
447 */
448 void UpdateHeaderCtrl();
449
450 /**
451 * @brief Hit test to determine if the point is on a checkbox
452 * @param pt Mouse coordinates
453 * @return TRUE if on a checkbox, FALSE otherwise
454 */
455 BOOL HitCheckBox(const CPoint &pt);
456
457 protected:
458 int m_nHeaderHeight; /**< Height of the header */
459 int m_nItemHeight; /**< Height of the items */
460
461 int m_nSelectItem; /**< Index of the selected item */
462 int m_nHoverItem; /**< Index of the item under the mouse */
463 BOOL m_bHotTrack; /**< Hot tracking flag */
464
465 CPoint m_ptIcon; /**< Icon position */
466 CPoint m_ptText; /**< Text position */
467
468 COLORREF m_crItemBg; /**< Background color */
469 COLORREF m_crItemBg2; /**< Background color for even rows */
470 COLORREF m_crItemSelBg; /**< Selected item background color */
471 COLORREF m_crItemHotBg; /**< Hot item background color */
472 COLORREF m_crText; /**< Text color */
473 COLORREF m_crSelText; /**< Selected text color */
474
475 SAutoRefPtr<ISkinObj> m_pItemSkin; /**< Skin for items */
476 SAutoRefPtr<ISkinObj> m_pIconSkin; /**< Skin for icons */
477 SAutoRefPtr<ISkinObj> m_pCheckSkin; /**< Skin for checkboxes */
478 BOOL m_bCheckBox; /**< Checkbox enable flag */
479 BOOL m_bMultiSelection; /**< Multiple selection enable flag */
480
481 protected:
482 typedef SArray<DXLVITEM> ArrLvItem; /**< Array of items */
483
484 SHeaderCtrl *m_pHeader; /**< Header control */
485 ArrLvItem m_arrItems; /**< Array of items */
486 CPoint m_ptOrigin; /**< Origin point */
487
488 protected:
489 SOUI_ATTRS_BEGIN()
490 ATTR_INT(L"headerHeight", m_nHeaderHeight, FALSE)
491 ATTR_INT(L"itemHeight", m_nItemHeight, FALSE)
492 ATTR_BOOL(L"checkBox", m_bCheckBox, TRUE)
493 ATTR_BOOL(L"multiSelection", m_bMultiSelection, TRUE)
494 ATTR_SKIN(L"itemSkin", m_pItemSkin, TRUE)
495 ATTR_SKIN(L"iconSkin", m_pIconSkin, TRUE)
496 ATTR_SKIN(L"checkSkin", m_pCheckSkin, TRUE)
497 ATTR_COLOR(L"colorItemBkgnd", m_crItemBg, FALSE)
498 ATTR_COLOR(L"colorItemBkgnd2", m_crItemBg2, FALSE)
499 ATTR_COLOR(L"colorItemHotBkgnd", m_crItemHotBg, FALSE)
500 ATTR_COLOR(L"colorItemSelBkgnd", m_crItemSelBg, FALSE)
501 ATTR_COLOR(L"colorText", m_crText, FALSE)
502 ATTR_COLOR(L"colorSelText", m_crSelText, FALSE)
503 ATTR_INT(L"icon-x", m_ptIcon.x, FALSE)
504 ATTR_INT(L"icon-y", m_ptIcon.y, FALSE)
505 ATTR_INT(L"text-x", m_ptText.x, FALSE)
506 ATTR_INT(L"text-y", m_ptText.y, FALSE)
507 ATTR_INT(L"hotTrack", m_bHotTrack, FALSE)
508 SOUI_ATTRS_END()
509
510 SOUI_MSG_MAP_BEGIN()
511 MSG_WM_PAINT_EX(OnPaint)
512 MSG_WM_DESTROY(OnDestroy)
513 MSG_WM_SIZE(OnSize)
514 MSG_WM_LBUTTONDBLCLK(OnLButtonDbClick)
515 MSG_WM_LBUTTONDOWN(OnLButtonDown)
516 MSG_WM_LBUTTONUP(OnLButtonUp)
517 MSG_WM_MOUSEMOVE(OnMouseMove)
518 MSG_WM_MOUSELEAVE(OnMouseLeave)
519 SOUI_MSG_MAP_END()
520};
521
522SNSEND
523
524#endif // __SLISTCTRL__H__
SOUI Panel with Scrollbar Support.
Smart pointer class for managing COM-style reference-counted objects.
Header Control.
Definition SHeaderCtrl.h:18
void OnLButtonUp(UINT nFlags, CPoint pt)
Handle left mouse button up event.
void SetSelectedItem(int nItem)
Set the selected item.
BOOL SetSubItemText(int nItem, int nSubItem, LPCTSTR pszText)
Set the text of a subitem.
VOID EnableHotTrack(BOOL enable)
Enable or disable hot tracking.
Definition SListCtrl.h:292
int GetLastCheckedItem()
Get the last checked item.
BOOL SetSubItem(int nItem, int nSubItem, const DXLVSUBITEM *plv)
Set a subitem.
int GetSelectedItem()
Get the selected item.
int m_nSelectItem
Definition SListCtrl.h:461
void OnLButtonDown(UINT nFlags, CPoint pt)
Handle left mouse button down event.
BOOL SetItemCount(int nItems, int nGrowBy)
Set the total number of items.
SListCtrl()
Constructor.
Definition SListCtrl.cpp:11
int m_nHoverItem
Definition SListCtrl.h:462
SStringT GetSubItemText(int nItem, int nSubItem) const
Get the text of a subitem.
int InsertItem(int nItem, LPCTSTR pszText, int nImage=-1)
Insert an item.
Definition SListCtrl.cpp:75
COLORREF m_crItemHotBg
Definition SListCtrl.h:471
CPoint m_ptIcon
Definition SListCtrl.h:465
SArray< DXLVITEM > ArrLvItem
Definition SListCtrl.h:482
BOOL SortItems(PFNLVCOMPAREEX pfnCompare, void *pContext)
Sort items using a comparison function.
ArrLvItem m_arrItems
Definition SListCtrl.h:485
void OnMouseLeave()
Handle mouse leave event.
int GetFirstCheckedItem()
Get the first checked item.
SAutoRefPtr< ISkinObj > m_pItemSkin
Definition SListCtrl.h:475
CPoint m_ptOrigin
Definition SListCtrl.h:486
int InsertColumn(int nIndex, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam=0)
Insert a column.
Definition SListCtrl.cpp:43
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
BOOL GetCheckState(int nItem)
Get the check state of an item.
void OnPaint(IRenderTarget *pRT)
Paint the control.
VOID EnableMultiSelection(BOOL enable)
Enable or disable multiple selection.
Definition SListCtrl.h:274
VOID EnableCheckBox(BOOL enable)
Enable or disable checkboxes.
Definition SListCtrl.h:283
COLORREF m_crItemSelBg
Definition SListCtrl.h:470
void DeleteAllItems()
Delete all items.
LPARAM GetItemData(int nItem)
Get the data associated with an item.
void OnSize(UINT nType, CSize size)
Handle size change event.
void OnDestroy()
Handle destroy event.
COLORREF m_crText
Definition SListCtrl.h:472
SHeaderCtrl * GetHeaderCtrl() const
Get the header control.
SAutoRefPtr< ISkinObj > m_pCheckSkin
Definition SListCtrl.h:477
CPoint m_ptText
Definition SListCtrl.h:466
int m_nHeaderHeight
Definition SListCtrl.h:458
SAutoRefPtr< ISkinObj > m_pIconSkin
Definition SListCtrl.h:476
COLORREF m_crItemBg
Definition SListCtrl.h:468
int GetItemCount() const
Get the total number of items.
BOOL m_bCheckBox
Definition SListCtrl.h:478
SHeaderCtrl * m_pHeader
Definition SListCtrl.h:484
COLORREF m_crSelText
Definition SListCtrl.h:473
BOOL m_bHotTrack
Definition SListCtrl.h:463
void DeleteItem(int nItem)
Delete a specific item.
COLORREF m_crItemBg2
Definition SListCtrl.h:469
BOOL SetCheckState(int nItem, BOOL bCheck)
Set the check state of an item.
BOOL m_bMultiSelection
Definition SListCtrl.h:479
int m_nItemHeight
Definition SListCtrl.h:459
void OnLButtonDbClick(UINT nFlags, CPoint pt)
Handle left mouse button double-click event.
int GetColumnCount() const
Get the total number of columns.
BOOL GetSubItem(int nItem, int nSubItem, DXLVSUBITEM *plv) const
Get a subitem.
int GetCheckedItemCount()
Get the number of checked items.
BOOL SetItemData(int nItem, LPARAM dwData)
Set the data associated with an item.
Definition SListCtrl.cpp:99
void DeleteColumn(int iCol)
Delete a specific column.
int GetCountPerPage(BOOL bPartial)
Get the number of items per page.
SPanel()
Constructor for SPanel.
Definition SPanel.cpp:165
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
Definition SPanel.cpp:517
void OnDestroy()
Handles the WM_DESTROY message.
Definition SPanel.cpp:326
void OnMouseMove(UINT nFlags, CPoint pt)
Handles the mouse move event.
Definition Swnd.cpp:2131
void OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
void OnLButtonDbClick(UINT nFlags, CPoint point)
Handles the left mouse button double-click event.
Definition Swnd.cpp:2100
void OnMouseLeave()
Handles the mouse leave event.
Definition Swnd.cpp:2147
void OnSize(UINT nType, CSize size)
Handles the resizing of the window.
Definition Swnd.cpp:2844
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles the left mouse button up event.
Definition Swnd.cpp:2105
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
Class representing an XML node.
Definition SXml.h:352
Item structure.
Definition SListCtrl.h:62
DXLVITEM()
Constructor.
Definition SListCtrl.h:66
ArrSubItem * arSubItems
Definition SListCtrl.h:73
LPARAM dwData
Definition SListCtrl.h:74
BOOL checked
Definition SListCtrl.h:75
Subitem structure.
Definition SListCtrl.h:34
UINT nImage
Definition SListCtrl.h:50
int cchTextMax
Definition SListCtrl.h:49
DXLVSUBITEM()
Constructor.
Definition SListCtrl.h:38
LPTSTR strText
Definition SListCtrl.h:48
Interface for rendering target objects.
Definition SRender-i.h:1440