soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
STreeCtrl.h
Go to the documentation of this file.
1/**
2 * @file STreeCtrl.h
3 * @brief Definition of the STreeCtrl class.
4 * @version 2012.12.16 - 1.1
5 * @author soui
6 * @date 2012-12-16
7 *
8 * @copyright Copyright (C) 2012-2050 SOUI团队
9 * All rights reserved.
10 */
11
12#ifndef __STREECTRL__H__
13#define __STREECTRL__H__
14
15#include "core/SPanel.h"
16#include "STree.h"
17
18SNSBEGIN
19
20/**
21 * @enum STVIMask
22 * @brief Masks for TVITEM structure.
23 */
25{
26 STVIMask_Toggle = 0x00000001UL, /**< Mask for toggle state. */
27 STVIMask_CheckBox = 0x00000002UL, /**< Mask for checkbox state. */
28 STVIMask_Icon = 0x00000004UL /**< Mask for icon state. */
29};
30
31/**
32 * @enum STVICheckBox
33 * @brief States for checkboxes in the tree view.
34 */
36{
37 STVICheckBox_UnChecked = 0, /**< Checkbox is unchecked. */
38 STVICheckBox_Checked, /**< Checkbox is checked. */
39 STVICheckBox_PartChecked /**< Checkbox is partially checked. */
40};
41
42/**
43 * @enum STVIBtn
44 * @brief Types of buttons in the tree view.
45 */
47{
48 STVIBtn_None, /**< No button. */
49 STVIBtn_Toggle, /**< Toggle button. */
50 STVIBtn_CheckBox /**< Checkbox button. */
51};
52
53/**
54 * @struct TVITEM
55 * @brief Structure representing a tree view item.
56 */
57typedef struct tagTVITEM
58{
59 SStringT strText; /**< Text of the item. */
60 int nImage; /**< Index of the normal image. */
61 int nSelectedImage; /**< Index of the selected image. */
62 LPARAM lParam; /**< Application-defined data. */
63
64 HSTREEITEM hItem; /**< Handle to the item. */
65 BOOL bCollapsed; /**< TRUE if the item is collapsed. */
66 BOOL bVisible; /**< TRUE if the item is visible. */
67 BOOL bHasChildren; /**< TRUE if the item has children. */
68 int nLevel; /**< Level of the item in the tree. */
69 int nCheckBoxValue; /**< State of the checkbox. */
70 int nContentWidth; /**< Content width of the item. */
71 DWORD dwToggleState; /**< Toggle state of the item. */
72 DWORD dwCheckBoxState; /**< Checkbox state of the item. */
73
74 /**
75 * @brief Constructor for TVITEM.
76 */
77 tagTVITEM()
78 {
79 nImage = -1;
80 nSelectedImage = -1;
81 lParam = 0;
82
83 hItem = 0;
84 bCollapsed = FALSE;
85 bVisible = TRUE;
86 bHasChildren = FALSE;
87 nLevel = 0;
88 nCheckBoxValue = STVICheckBox_UnChecked;
89 nContentWidth = 0;
90 dwToggleState = WndState_Normal;
91 dwCheckBoxState = WndState_Normal;
92 }
93
94} TVITEM, *LPTVITEM;
95
96/**
97 * @class STreeCtrl
98 * @brief A tree control for displaying hierarchical data.
99 *
100 * This class represents a tree control that can display hierarchical data with various customization options.
101 */
102class SOUI_EXP STreeCtrl
103 : public TPanelProxy<ITreeCtrl>
104 , protected CSTree<LPTVITEM> {
105 DEF_SOBJECT(SPanel, L"treectrl")
106
107 public:
108 /**
109 * @class IListener
110 * @brief Listener interface for tree view events.
111 */
113 {
114 /**
115 * @brief Called when an item is inserted.
116 * @param pTreeCtrl Pointer to the tree control.
117 * @param hItem Handle to the inserted item.
118 */
119 virtual void OnInsertItem(STreeCtrl *pTreeCtrl, HSTREEITEM hItem) = 0;
120
121 /**
122 * @brief Called when an item is deleted.
123 * @param pTreeCtrl Pointer to the tree control.
124 * @param hItem Handle to the deleted item.
125 * @param lParam Application-defined data.
126 */
127 virtual void OnDeleteItem(STreeCtrl *pTreeCtrl, HSTREEITEM hItem, LPARAM lParam) = 0;
128 };
129
130 /**
131 * @brief Constructor for STreeCtrl.
132 */
133 STreeCtrl();
134
135 /**
136 * @brief Destructor for STreeCtrl.
137 */
138 virtual ~STreeCtrl();
139
140 public:
141 /**
142 * @brief Inserts a new item into the tree.
143 * @param lpszItem Text of the item.
144 * @param nImage Index of the normal image.
145 * @param nSelectedImage Index of the selected image.
146 * @param lParam Application-defined data.
147 * @param hParent Handle to the parent item.
148 * @param hInsertAfter Handle to the item after which to insert.
149 * @return Handle to the inserted item.
150 */
151 STDMETHOD_(HSTREEITEM, InsertItem)
152 (THIS_ LPCTSTR lpszItem, int nImage, int nSelectedImage, LPARAM lParam, HSTREEITEM hParent = STVI_ROOT, HSTREEITEM hInsertAfter = STVI_LAST) OVERRIDE;
153
154 /**
155 * @brief Inserts a new item into the tree (ANSI version).
156 * @param lpszItem Text of the item.
157 * @param nImage Index of the normal image.
158 * @param nSelectedImage Index of the selected image.
159 * @param lParam Application-defined data.
160 * @param hParent Handle to the parent item.
161 * @param hInsertAfter Handle to the item after which to insert.
162 * @return Handle to the inserted item.
163 */
164 STDMETHOD_(HSTREEITEM, InsertItemA)
165 (THIS_ LPCSTR lpszItem, int nImage, int nSelectedImage, LPARAM lParam, HSTREEITEM hParent = STVI_ROOT, HSTREEITEM hInsertAfter = STVI_LAST) OVERRIDE
166 {
167 SStringT str = S_CA2T(lpszItem, CP_UTF8);
168 return InsertItem(str, nImage, nSelectedImage, lParam, hParent, hInsertAfter);
169 }
170
171 /**
172 * @brief Removes an item from the tree.
173 * @param hItem Handle to the item to remove.
174 * @return TRUE if successful, otherwise FALSE.
175 */
176 STDMETHOD_(BOOL, RemoveItem)(THIS_ HSTREEITEM hItem) OVERRIDE;
177
178 /**
179 * @brief Removes all items from the tree.
180 */
181 STDMETHOD_(void, RemoveAllItems)(THIS) OVERRIDE;
182
183 /**
184 * @brief Gets the root item of the tree.
185 * @return Handle to the root item.
186 */
187 STDMETHOD_(HSTREEITEM, GetRootItem)(THIS) SCONST OVERRIDE;
188
189 /**
190 * @brief Gets the next sibling item.
191 * @param hItem Handle to the item.
192 * @return Handle to the next sibling item.
193 */
194 STDMETHOD_(HSTREEITEM, GetNextSiblingItem)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
195
196 /**
197 * @brief Gets the previous sibling item.
198 * @param hItem Handle to the item.
199 * @return Handle to the previous sibling item.
200 */
201 STDMETHOD_(HSTREEITEM, GetPrevSiblingItem)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
202
203 /**
204 * @brief Gets a child item.
205 * @param hItem Handle to the item.
206 * @param bFirst TRUE to get the first child, FALSE to get the next child.
207 * @return Handle to the child item.
208 */
209 STDMETHOD_(HSTREEITEM, GetChildItem)
210 (THIS_ HSTREEITEM hItem, BOOL bFirst = TRUE) SCONST OVERRIDE;
211
212 /**
213 * @brief Gets the parent item.
214 * @param hItem Handle to the item.
215 * @return Handle to the parent item.
216 */
217 STDMETHOD_(HSTREEITEM, GetParentItem)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
218
219 /**
220 * @brief Gets the selected item.
221 * @return Handle to the selected item.
222 */
223 STDMETHOD_(HSTREEITEM, GetSelectedItem)(THIS) SCONST OVERRIDE;
224
225 /**
226 * @brief Gets the next item.
227 * @param hItem Handle to the item.
228 * @return Handle to the next item.
229 */
230 STDMETHOD_(HSTREEITEM, GetNextItem)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
231
232 /**
233 * @brief Sorts the children of an item.
234 * @param hItem Handle to the item.
235 * @param sortFunc Sorting callback function.
236 * @param pCtx Context for the sorting function.
237 */
238 STDMETHOD_(void, SortChildren)
239 (THIS_ HSTREEITEM hItem, FunTreeSortCallback sortFunc, void *pCtx) OVERRIDE;
240
241 /**
242 * @brief Selects an item.
243 * @param hItem Handle to the item to select.
244 * @param bEnsureVisible TRUE to ensure the item is visible.
245 * @return TRUE if successful, otherwise FALSE.
246 */
247 STDMETHOD_(BOOL, SelectItem)(THIS_ HSTREEITEM hItem, BOOL bEnsureVisible = TRUE) OVERRIDE;
248
249 /**
250 * @brief Gets the text of an item.
251 * @param hItem Handle to the item.
252 * @param strText String to receive the item text.
253 * @return TRUE if successful, otherwise FALSE.
254 */
255 STDMETHOD_(BOOL, GetItemText)(THIS_ HSTREEITEM hItem, IStringT *strText) SCONST OVERRIDE;
256
257 /**
258 * @brief Gets the text of an item (ANSI version).
259 * @param hItem Handle to the item.
260 * @param strText String to receive the item text.
261 * @return TRUE if successful, otherwise FALSE.
262 */
263 STDMETHOD_(BOOL, GetItemTextA)(THIS_ HSTREEITEM hItem, IStringA *strText) SCONST OVERRIDE
264 {
265 SStringT strBuf;
266 BOOL bRet = GetItemText(hItem, &strBuf);
267 SStringA strBufA = S_CT2A(strBuf, CP_UTF8);
268 strText->Copy(&strBufA);
269 return bRet;
270 }
271
272 /**
273 * @brief Sets the text of an item.
274 * @param hItem Handle to the item.
275 * @param lpszItem New text for the item.
276 * @return TRUE if successful, otherwise FALSE.
277 */
278 STDMETHOD_(BOOL, SetItemText)(THIS_ HSTREEITEM hItem, LPCTSTR lpszItem) OVERRIDE;
279
280 /**
281 * @brief Sets the text of an item (ANSI version).
282 * @param hItem Handle to the item.
283 * @param lpszItem New text for the item.
284 * @return TRUE if successful, otherwise FALSE.
285 */
286 STDMETHOD_(BOOL, SetItemTextA)(THIS_ HSTREEITEM hItem, LPCSTR lpszItem) OVERRIDE
287 {
288 SStringT str = S_CA2T(lpszItem, CP_UTF8);
289 return SetItemText(hItem, str);
290 }
291
292 /**
293 * @brief Gets the images of an item.
294 * @param hItem Handle to the item.
295 * @param nImage Pointer to receive the index of the normal image.
296 * @param nSelectedImage Pointer to receive the index of the selected image.
297 * @return TRUE if successful, otherwise FALSE.
298 */
299 STDMETHOD_(BOOL, GetItemImage)
300 (THIS_ HSTREEITEM hItem, int *nImage, int *nSelectedImage) SCONST OVERRIDE;
301
302 /**
303 * @brief Sets the images of an item.
304 * @param hItem Handle to the item.
305 * @param nImage Index of the normal image.
306 * @param nSelectedImage Index of the selected image.
307 * @return TRUE if successful, otherwise FALSE.
308 */
309 STDMETHOD_(BOOL, SetItemImage)(THIS_ HSTREEITEM hItem, int nImage, int nSelectedImage) OVERRIDE;
310
311 /**
312 * @brief Gets the application-defined data of an item.
313 * @param hItem Handle to the item.
314 * @return Application-defined data.
315 */
316 STDMETHOD_(LPARAM, GetItemData)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
317
318 /**
319 * @brief Sets the application-defined data of an item.
320 * @param hItem Handle to the item.
321 * @param lParam Application-defined data.
322 * @return TRUE if successful, otherwise FALSE.
323 */
324 STDMETHOD_(BOOL, SetItemData)(THIS_ HSTREEITEM hItem, LPARAM lParam) OVERRIDE;
325
326 /**
327 * @brief Checks if an item has children.
328 * @param hItem Handle to the item.
329 * @return TRUE if the item has children, otherwise FALSE.
330 */
331 STDMETHOD_(BOOL, ItemHasChildren)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
332
333 /**
334 * @brief Gets the check state of an item.
335 * @param hItem Handle to the item.
336 * @return Check state of the item.
337 */
338 STDMETHOD_(int, GetCheckState)(THIS_ HSTREEITEM hItem) SCONST OVERRIDE;
339
340 /**
341 * @brief Sets the check state of an item.
342 * @param hItem Handle to the item.
343 * @param bCheck TRUE to check the item, FALSE to uncheck.
344 * @return TRUE if successful, otherwise FALSE.
345 */
346 STDMETHOD_(BOOL, SetCheckState)(THIS_ HSTREEITEM hItem, BOOL bCheck) OVERRIDE;
347
348 /**
349 * @brief Expands or collapses an item.
350 * @param hItem Handle to the item.
351 * @param nCode Code specifying the action (e.g., TVE_EXPAND).
352 * @return TRUE if successful, otherwise FALSE.
353 */
354 STDMETHOD_(BOOL, Expand)(THIS_ HSTREEITEM hItem, UINT nCode = TVE_EXPAND) OVERRIDE;
355
356 /**
357 * @brief Ensures an item is visible.
358 * @param hItem Handle to the item.
359 * @return TRUE if successful, otherwise FALSE.
360 */
361 STDMETHOD_(BOOL, EnsureVisible)(THIS_ HSTREEITEM hItem) OVERRIDE;
362
363 public:
364 /**
365 * @brief Sets the listener for tree view events.
366 * @param pListener Pointer to the listener.
367 */
368 void SetListener(IListener *pListener);
369
370 /**
371 * @brief Inserts a new item into the tree.
372 * @param lpszItem Text of the item.
373 * @param hParent Handle to the parent item.
374 * @param hInsertAfter Handle to the item after which to insert.
375 * @return Handle to the inserted item.
376 */
377 HSTREEITEM InsertItem(LPCTSTR lpszItem, HSTREEITEM hParent = STVI_ROOT, HSTREEITEM hInsertAfter = STVI_LAST);
378
379 /**
380 * @brief Inserts a new item into the tree.
381 * @param lpszItem Text of the item.
382 * @param nImage Index of the normal image.
383 * @param nSelectedImage Index of the selected image.
384 * @param hParent Handle to the parent item.
385 * @param hInsertAfter Handle to the item after which to insert.
386 * @return Handle to the inserted item.
387 */
388 HSTREEITEM InsertItem(LPCTSTR lpszItem, int nImage, int nSelectedImage, HSTREEITEM hParent = STVI_ROOT, HSTREEITEM hInsertAfter = STVI_LAST);
389
390 /**
391 * @brief Performs a hit test on the tree view.
392 * @param pt Mouse position.
393 * @return Handle to the item at the specified position.
394 */
395 HSTREEITEM HitTest(CPoint &pt);
396
397 /**
398 * @brief Gets the text of an item.
399 * @param hItem Handle to the item.
400 * @param strText String to receive the item text.
401 * @return TRUE if successful, otherwise FALSE.
402 */
403 BOOL GetItemText(HSTREEITEM hItem, SStringT &strText) const
404 {
405 return GetItemText(hItem, &strText);
406 }
407
408 protected:
409 /**
410 * @brief Handles the page up action.
411 */
412 void PageUp();
413
414 /**
415 * @brief Handles the page down action.
416 */
417 void PageDown();
418
419 /**
420 * @brief Updates the scroll bars.
421 */
422 void UpdateScrollBar();
423
424 /**
425 * @brief Creates child windows from an XML node.
426 * @param xmlNode XML node containing the child window definitions.
427 * @return TRUE if successful, otherwise FALSE.
428 */
429 virtual BOOL CreateChildren(SXmlNode xmlNode);
430
431 /**
432 * @brief Loads a branch of items from an XML node.
433 * @param hParent Handle to the parent item.
434 * @param xmlNode XML node containing the branch definitions.
435 */
436 virtual void LoadBranch(HSTREEITEM hParent, SXmlNode xmlNode);
437
438 /**
439 * @brief Loads attributes for an item from an XML node.
440 * @param xmlNode XML node containing the item attributes.
441 * @param pItem Pointer to the item.
442 */
443 virtual void LoadItemAttribute(SXmlNode xmlNode, LPTVITEM pItem);
444
445 /**
446 * @brief Inserts a new item into the tree.
447 * @param pItemObj Pointer to the item data.
448 * @param hParent Handle to the parent item.
449 * @param hInsertAfter Handle to the item after which to insert.
450 * @return Handle to the inserted item.
451 */
452 HSTREEITEM InsertItem(LPTVITEM pItemObj, HSTREEITEM hParent, HSTREEITEM hInsertAfter);
453
454 /**
455 * @brief Inserts a new item into the tree from an XML node.
456 * @param xmlNode XML node containing the item definition.
457 * @param hParent Handle to the parent item.
458 * @param hInsertAfter Handle to the item after which to insert.
459 * @return Handle to the inserted item.
460 */
461 HSTREEITEM InsertItem(SXmlNode xmlNode, HSTREEITEM hParent = STVI_ROOT, HSTREEITEM hInsertAfter = STVI_LAST);
462
463 /**
464 * @brief Checks if one item is an ancestor of another.
465 * @param hItem1 Handle to the potential ancestor item.
466 * @param hItem2 Handle to the potential descendant item.
467 * @return TRUE if hItem1 is an ancestor of hItem2, otherwise FALSE.
468 */
469 BOOL IsAncestor(HSTREEITEM hItem1, HSTREEITEM hItem2);
470
471 /**
472 * @brief Verifies if an item is valid.
473 * @param hItem Handle to the item to verify.
474 * @return TRUE if the item is valid, otherwise FALSE.
475 */
476 BOOL VerifyItem(HSTREEITEM hItem) const;
477
478 /**
479 * @brief Sets the visibility of an item's children.
480 * @param hItem Handle to the item.
481 * @param bVisible TRUE to make the children visible, FALSE to hide them.
482 */
483 void SetChildrenVisible(HSTREEITEM hItem, BOOL bVisible);
484
485 /**
486 * @brief Sets the check state of an item's children.
487 * @param hItem Handle to the item.
488 * @param nCheckValue New check state value.
489 */
490 void SetChildrenState(HSTREEITEM hItem, int nCheckValue);
491
492 /**
493 * @brief Checks the state of an item's children.
494 * @param hItem Handle to the item.
495 * @param bCheck TRUE to check the children, FALSE to uncheck them.
496 * @return TRUE if the state was successfully updated, otherwise FALSE.
497 */
498 BOOL CheckChildrenState(HSTREEITEM hItem, BOOL bCheck);
499
500 /**
501 * @brief Updates the check state of an item.
502 * @param hItem Handle to the item.
503 */
504 void CheckState(HSTREEITEM hItem);
505
506 /**
507 * @brief Performs layout calculations for items.
508 */
509 virtual void ItemLayout();
510
511 /**
512 * @brief Calculates the content width of an item.
513 * @param pItem Pointer to the item data.
514 */
515 virtual void CalcItemContentWidth(LPTVITEM pItem);
516
517 /**
518 * @brief Calculates the width of an item.
519 * @param pItem Pointer to the item data.
520 * @return Calculated width of the item.
521 */
522 virtual int CalcItemWidth(const LPTVITEM pItem);
523
524 /**
525 * @brief Calculates the maximum width of an item and its children.
526 * @param hItem Handle to the item.
527 * @return Maximum width of the item and its children.
528 */
529 virtual int CalcMaxItemWidth(HSTREEITEM hItem);
530
531 /**
532 * @brief Updates the content width of the tree.
533 */
534 virtual void UpdateContentWidth();
535
536 /**
537 * @brief Gets the index of an item in the visible list.
538 * @param hItemObj Handle to the item.
539 * @return Index of the item in the visible list.
540 */
541 int GetItemShowIndex(HSTREEITEM hItemObj);
542
543 /**
544 * @brief Gets the rectangle of an item.
545 * @param pItem Pointer to the item data.
546 * @param rcItem Rectangle to receive the item position.
547 * @return TRUE if successful, otherwise FALSE.
548 */
549 BOOL GetItemRect(LPTVITEM pItem, CRect &rcItem);
550
551 /**
552 * @brief Redraws an item.
553 * @param hItem Handle to the item.
554 */
555 void RedrawItem(HSTREEITEM hItem);
556
557 /**
558 * @brief Draws an item.
559 * @param pRT Pointer to the rendering target.
560 * @param rc Rectangle to draw the item.
561 * @param hItem Handle to the item.
562 */
563 virtual void DrawItem(IRenderTarget *pRT, const CRect &rc, HSTREEITEM hItem);
564
565 /**
566 * @brief Draws lines for an item.
567 * @param pRT Pointer to the rendering target.
568 * @param rc Rectangle to draw the lines.
569 * @param hItem Handle to the item.
570 */
571 virtual void DrawLines(IRenderTarget *pRT, const CRect &rc, HSTREEITEM hItem);
572
573 /**
574 * @brief Performs a hit test on an item.
575 * @param hItem Handle to the item.
576 * @param pt Mouse position.
577 * @return Index of the hit test result.
578 */
579 int ItemHitTest(HSTREEITEM hItem, CPoint &pt) const;
580
581 /**
582 * @brief Modifies the toggle state of an item.
583 * @param hItem Handle to the item.
584 * @param dwStateAdd State to add.
585 * @param dwStateRemove State to remove.
586 */
587 void ModifyToggleState(HSTREEITEM hItem, DWORD dwStateAdd, DWORD dwStateRemove);
588
589 /**
590 * @brief Modifies the checkbox state of an item.
591 * @param hItem Handle to the item.
592 * @param dwStateAdd State to add.
593 * @param dwStateRemove State to remove.
594 */
595 void ModifyChekcBoxState(HSTREEITEM hItem, DWORD dwStateAdd, DWORD dwStateRemove);
596
597 /**
598 * @brief Handles the left mouse button down event for an item.
599 * @param hItem Handle to the item.
600 * @param nFlags Flags associated with the mouse event.
601 * @param pt Mouse position.
602 */
603 void ItemLButtonDown(HSTREEITEM hItem, UINT nFlags, CPoint pt);
604
605 /**
606 * @brief Handles the left mouse button up event for an item.
607 * @param hItem Handle to the item.
608 * @param nFlags Flags associated with the mouse event.
609 * @param pt Mouse position.
610 */
611 void ItemLButtonUp(HSTREEITEM hItem, UINT nFlags, CPoint pt);
612
613 /**
614 * @brief Handles the left mouse button double-click event for an item.
615 * @param hItem Handle to the item.
616 * @param nFlags Flags associated with the mouse event.
617 * @param pt Mouse position.
618 */
619 void ItemLButtonDbClick(HSTREEITEM hItem, UINT nFlags, CPoint pt);
620
621 /**
622 * @brief Handles the mouse move event for an item.
623 * @param hItem Handle to the item.
624 * @param nFlags Flags associated with the mouse event.
625 * @param pt Mouse position.
626 */
627 void ItemMouseMove(HSTREEITEM hItem, UINT nFlags, CPoint pt);
628
629 /**
630 * @brief Handles the mouse leave event for an item.
631 * @param hItem Handle to the item.
632 */
633 void ItemMouseLeave(HSTREEITEM hItem);
634
635 protected:
636 /**
637 * @brief Frees the memory associated with an item.
638 * @param pItemData Pointer to the item data.
639 */
640 virtual void OnNodeFree(LPTVITEM &pItemData);
641
642 /**
643 * @brief Handles the insertion of an item.
644 * @param pItemData Pointer to the item data.
645 */
646 virtual void OnInsertItem(LPTVITEM &pItemData);
647
648 protected:
649 /**
650 * @brief Handle to the selected item.
651 */
652 HSTREEITEM m_hSelItem;
653
654 /**
655 * @brief Handle to the item under the hover state.
656 */
657 HSTREEITEM m_hHoverItem;
658
659 /**
660 * @brief Handle to the item that has capture.
661 */
662 HSTREEITEM m_hCaptureItem;
663
664 /**
665 * @brief Number of visible items.
666 */
668
669 /**
670 * @brief Total content width of the tree.
671 */
673
674 /**
675 * @brief Mask for item attributes.
676 */
678
679 /**
680 * @brief Offset for item positioning.
681 */
683
684 /**
685 * @brief Rectangle for the toggle button.
686 */
688
689 /**
690 * @brief Rectangle for the checkbox.
691 */
693
694 /**
695 * @brief Rectangle for the icon.
696 */
697 CRect m_rcIcon;
698
699 /**
700 * @brief Button currently hovered.
701 */
703
704 /**
705 * @brief Button currently pushed down.
706 */
708
709 /**
710 * @brief Height of each item.
711 */
713
714 /**
715 * @brief Indentation between levels.
716 */
718
719 /**
720 * @brief Margin around each item.
721 */
723
724 /**
725 * @brief Flag indicating if checkboxes are enabled.
726 */
728
729 /**
730 * @brief Flag indicating if right-click selection is enabled.
731 */
733
734 /**
735 * @brief Listener for tree view events.
736 */
738
739 /**
740 * @brief Skin for the background of items.
741 */
743
744 /**
745 * @brief Skin for the selected background of items.
746 */
748
749 /**
750 * @brief Skin for the icons.
751 */
753
754 /**
755 * @brief Skin for the toggle buttons.
756 */
758
759 /**
760 * @brief Skin for the checkboxes.
761 */
763
764 /**
765 * @brief Skin for the lines.
766 */
768
769 /**
770 * @brief Background color of items.
771 */
772 COLORREF m_crItemBg;
773
774 /**
775 * @brief Background color of selected items.
776 */
778
779 /**
780 * @brief Text color of items.
781 */
782 COLORREF m_crItemText;
783
784 /**
785 * @brief Text color of selected items.
786 */
788
789 /**
790 * @brief Flag indicating if lines are drawn between items.
791 */
792 BOOL m_bHasLines; /**< has lines*/
793
794 SOUI_ATTRS_BEGIN()
795 ATTR_INT(L"indent", m_nIndent, TRUE)
796 ATTR_INT(L"itemHeight", m_nItemHei, TRUE)
797 ATTR_INT(L"itemMargin", m_nItemMargin, TRUE)
798 ATTR_BOOL(L"checkBox", m_bCheckBox, TRUE)
799 ATTR_BOOL(L"rightClickSel", m_bRightClickSel, TRUE)
800 ATTR_SKIN(L"itemBkgndSkin", m_pItemBgSkin, TRUE)
801 ATTR_SKIN(L"itemSelSkin", m_pItemSelSkin, TRUE)
802 ATTR_SKIN(L"lineSkin", m_pLineSkin, TRUE)
803 ATTR_SKIN(L"toggleSkin", m_pToggleSkin, TRUE)
804 ATTR_SKIN(L"iconSkin", m_pIconSkin, TRUE)
805 ATTR_SKIN(L"checkSkin", m_pCheckSkin, TRUE)
806 ATTR_COLOR(L"colorItemBkgnd", m_crItemBg, FALSE)
807 ATTR_COLOR(L"colorItemSelBkgnd", m_crItemSelBg, FALSE)
808 ATTR_COLOR(L"colorItemText", m_crItemText, FALSE)
809 ATTR_COLOR(L"colorItemSelText", m_crItemSelText, FALSE)
810 ATTR_BOOL(L"hasLines", m_bHasLines, TRUE)
811 SOUI_ATTRS_END()
812
813 protected:
814 /**
815 * @brief Handles the destruction of the tree control.
816 */
817 void OnDestroy();
818
819 /**
820 * @brief Handles the paint event.
821 * @param pRT Pointer to the rendering target.
822 */
823 void OnPaint(IRenderTarget *pRT);
824
825 /**
826 * @brief Handles the left mouse button down event.
827 * @param nFlags Flags associated with the mouse event.
828 * @param pt Mouse position.
829 */
830 void OnLButtonDown(UINT nFlags, CPoint pt);
831
832 /**
833 * @brief Handles the left mouse button up event.
834 * @param nFlags Flags associated with the mouse event.
835 * @param pt Mouse position.
836 */
837 void OnLButtonUp(UINT nFlags, CPoint pt);
838
839 /**
840 * @brief Handles the left mouse button double-click event.
841 * @param nFlags Flags associated with the mouse event.
842 * @param pt Mouse position.
843 */
844 void OnLButtonDbClick(UINT nFlags, CPoint pt);
845
846 /**
847 * @brief Handles the right mouse button down event.
848 * @param nFlags Flags associated with the mouse event.
849 * @param pt Mouse position.
850 */
851 void OnRButtonDown(UINT nFlags, CPoint pt);
852
853 /**
854 * @brief Handles the mouse move event.
855 * @param nFlags Flags associated with the mouse event.
856 * @param pt Mouse position.
857 */
858 void OnMouseMove(UINT nFlags, CPoint pt);
859
860 /**
861 * @brief Handles the mouse leave event.
862 */
863 void OnMouseLeave();
864
865 /**
866 * @brief Handles the size event.
867 * @param nType Type of size change.
868 * @param size New size.
869 */
870 void OnSize(UINT nType, CSize size);
871
872 SOUI_MSG_MAP_BEGIN()
873 MSG_WM_PAINT_EX(OnPaint)
874 MSG_WM_DESTROY(OnDestroy)
875 MSG_WM_LBUTTONDOWN(OnLButtonDown)
876 MSG_WM_LBUTTONDBLCLK(OnLButtonDbClick)
877 MSG_WM_LBUTTONUP(OnLButtonUp)
878 MSG_WM_RBUTTONDOWN(OnRButtonDown);
879 MSG_WM_MOUSEMOVE(OnMouseMove)
880 MSG_WM_MOUSELEAVE(OnMouseLeave)
881 MSG_WM_SIZE(OnSize)
882 SOUI_MSG_MAP_END()
883};
884
885SNSEND
886
887#endif // __STREECTRL__H__
SOUI Panel with Scrollbar Support.
Tree template for general data types.
#define STVI_ROOT
Definition STree.h:43
#define STVI_LAST
Definition STree.h:45
STVICheckBox
States for checkboxes in the tree view.
Definition STreeCtrl.h:36
@ STVICheckBox_PartChecked
Definition STreeCtrl.h:39
@ STVICheckBox_Checked
Definition STreeCtrl.h:38
@ STVICheckBox_UnChecked
Definition STreeCtrl.h:37
STVIBtn
Types of buttons in the tree view.
Definition STreeCtrl.h:47
@ STVIBtn_None
Definition STreeCtrl.h:48
@ STVIBtn_Toggle
Definition STreeCtrl.h:49
@ STVIBtn_CheckBox
Definition STreeCtrl.h:50
STVIMask
Masks for TVITEM structure.
Definition STreeCtrl.h:25
@ STVIMask_Icon
Definition STreeCtrl.h:28
@ STVIMask_Toggle
Definition STreeCtrl.h:26
@ STVIMask_CheckBox
Definition STreeCtrl.h:27
@ WndState_Normal
Definition SWnd.h:75
virtual void OnNodeFree(T &data)
Virtual function to handle the freeing of node data.
Definition STree.h:710
HSTREEITEM InsertItem(const T &data, HSTREEITEM hParent=((HSTREEITEM) 0xFFFF0000), HSTREEITEM hInsertAfter=((HSTREEITEM) 0xFFFF0002))
Insert a new item.
Definition STree.h:348
Smart pointer class for managing COM-style reference-counted objects.
SPanel()
Constructor for SPanel.
Definition SPanel.cpp:165
A class representing an ASCII string.
Definition sstringa.h:96
COLORREF m_crItemSelBg
Background color of selected items.
Definition STreeCtrl.h:777
SAutoRefPtr< ISkinObj > m_pToggleSkin
Skin for the toggle buttons.
Definition STreeCtrl.h:757
BOOL m_bRightClickSel
Flag indicating if right-click selection is enabled.
Definition STreeCtrl.h:732
int m_nVisibleItems
Number of visible items.
Definition STreeCtrl.h:667
IListener * m_pListener
Listener for tree view events.
Definition STreeCtrl.h:737
SAutoRefPtr< ISkinObj > m_pItemBgSkin
Skin for the background of items.
Definition STreeCtrl.h:742
COLORREF m_crItemBg
Background color of items.
Definition STreeCtrl.h:772
STreeCtrl()
Constructor for STreeCtrl.
Definition STreeCtrl.cpp:12
int m_nItemOffset
Offset for item positioning.
Definition STreeCtrl.h:682
BOOL SetItemText(HSTREEITEM hItem, LPCTSTR lpszItem) OVERRIDE
Sets the text of an item.
int m_nItemHoverBtn
Button currently hovered.
Definition STreeCtrl.h:702
CRect m_rcToggle
Rectangle for the toggle button.
Definition STreeCtrl.h:687
CRect m_rcCheckBox
Rectangle for the checkbox.
Definition STreeCtrl.h:692
int m_nItemHei
Height of each item.
Definition STreeCtrl.h:712
BOOL SetItemTextA(HSTREEITEM hItem, LPCSTR lpszItem) OVERRIDE
Sets the text of an item (ANSI version).
Definition STreeCtrl.h:286
int m_nItemMargin
Margin around each item.
Definition STreeCtrl.h:722
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
BOOL GetItemText(HSTREEITEM hItem, IStringT *strText) SCONST OVERRIDE
Gets the text of an item.
CRect m_rcIcon
Rectangle for the icon.
Definition STreeCtrl.h:697
BOOL m_bCheckBox
Flag indicating if checkboxes are enabled.
Definition STreeCtrl.h:727
void OnMouseMove(UINT nFlags, CPoint pt)
Handles the mouse move event.
void OnLButtonDbClick(UINT nFlags, CPoint pt)
Handles the left mouse button double-click event.
HSTREEITEM m_hCaptureItem
Handle to the item that has capture.
Definition STreeCtrl.h:662
int m_nContentWidth
Total content width of the tree.
Definition STreeCtrl.h:672
SAutoRefPtr< ISkinObj > m_pItemSelSkin
Skin for the selected background of items.
Definition STreeCtrl.h:747
void OnPaint(IRenderTarget *pRT)
Handles the paint event.
void OnDestroy()
Handles the destruction of the tree control.
HSTREEITEM m_hHoverItem
Handle to the item under the hover state.
Definition STreeCtrl.h:657
int m_nItemPushDownBtn
Button currently pushed down.
Definition STreeCtrl.h:707
UINT m_uItemMask
Mask for item attributes.
Definition STreeCtrl.h:677
void OnMouseLeave()
Handles the mouse leave event.
HSTREEITEM m_hSelItem
Handle to the selected item.
Definition STreeCtrl.h:652
COLORREF m_crItemText
Text color of items.
Definition STreeCtrl.h:782
BOOL GetItemText(HSTREEITEM hItem, SStringT &strText) const
Gets the text of an item.
Definition STreeCtrl.h:403
SAutoRefPtr< ISkinObj > m_pCheckSkin
Skin for the checkboxes.
Definition STreeCtrl.h:762
HSTREEITEM InsertItemA(LPCSTR lpszItem, int nImage, int nSelectedImage, LPARAM lParam, HSTREEITEM hParent=STVI_ROOT, HSTREEITEM hInsertAfter=STVI_LAST) OVERRIDE
Inserts a new item into the tree (ANSI version).
Definition STreeCtrl.h:165
BOOL m_bHasLines
Flag indicating if lines are drawn between items.
Definition STreeCtrl.h:792
SAutoRefPtr< ISkinObj > m_pLineSkin
Skin for the lines.
Definition STreeCtrl.h:767
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles the left mouse button up event.
BOOL GetItemTextA(HSTREEITEM hItem, IStringA *strText) SCONST OVERRIDE
Gets the text of an item (ANSI version).
Definition STreeCtrl.h:263
HSTREEITEM InsertItem(LPCTSTR lpszItem, int nImage, int nSelectedImage, LPARAM lParam, HSTREEITEM hParent=STVI_ROOT, HSTREEITEM hInsertAfter=STVI_LAST) OVERRIDE
Inserts a new item into the tree.
Definition STreeCtrl.cpp:65
int m_nIndent
Indentation between levels.
Definition STreeCtrl.h:717
void OnRButtonDown(UINT nFlags, CPoint pt)
Handles the right mouse button down event.
void OnSize(UINT nType, CSize size)
Handles the size event.
SAutoRefPtr< ISkinObj > m_pIconSkin
Skin for the icons.
Definition STreeCtrl.h:752
COLORREF m_crItemSelText
Text color of selected items.
Definition STreeCtrl.h:787
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Listener interface for tree view events.
Definition STreeCtrl.h:113
virtual void OnInsertItem(STreeCtrl *pTreeCtrl, HSTREEITEM hItem)=0
Called when an item is inserted.
virtual void OnDeleteItem(STreeCtrl *pTreeCtrl, HSTREEITEM hItem, LPARAM lParam)=0
Called when an item is deleted.
Structure representing a tree view item.