1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/treectrl.cpp
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin to be less MSW-specific on 10.10.98
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "treectrl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/msw/private.h"
35 // Set this to 1 to be _absolutely_ sure that repainting will work for all
36 // comctl32.dll versions
37 #define wxUSE_COMCTL32_SAFELY 0
39 // Mingw32 is a bit mental even though this is done in winundef
48 #if defined(__WIN95__)
52 #include "wx/dynarray.h"
53 #include "wx/imaglist.h"
54 #include "wx/settings.h"
55 #include "wx/msw/treectrl.h"
56 #include "wx/msw/dragimag.h"
58 #ifdef __GNUWIN32_OLD__
59 #include "wx/msw/gnuwin32/extra.h"
62 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
66 // Bug in headers, sometimes
68 #define TVIS_FOCUSED 0x0001
72 #define TV_FIRST 0x1100
75 #ifndef TVS_CHECKBOXES
76 #define TVS_CHECKBOXES 0x0100
79 #ifndef TVS_FULLROWSELECT
80 #define TVS_FULLROWSELECT 0x1000
83 // old headers might miss these messages (comctl32.dll 4.71+ only)
84 #ifndef TVM_SETBKCOLOR
85 #define TVM_SETBKCOLOR (TV_FIRST + 29)
86 #define TVM_SETTEXTCOLOR (TV_FIRST + 30)
89 // a macro to hide the ugliness of nested casts
90 #define HITEM(item) (HTREEITEM)(WXHTREEITEM)(item)
92 // the native control doesn't support multiple selections under MSW and we
93 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
94 // checkboxes be the selection status (checked == selected) or by really
95 // emulating everything, i.e. intercepting mouse and key events &c. The first
96 // approach is much easier but doesn't work with comctl32.dll < 4.71 and also
98 #define wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE 0
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 // wrapper for TreeView_HitTest
105 static HTREEITEM
GetItemFromPoint(HWND hwndTV
, int x
, int y
)
111 return (HTREEITEM
)TreeView_HitTest(hwndTV
, &tvht
);
114 #if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
116 // wrappers for TreeView_GetItem/TreeView_SetItem
117 static bool IsItemSelected(HWND hwndTV
, HTREEITEM hItem
)
120 tvi
.mask
= TVIF_STATE
| TVIF_HANDLE
;
121 tvi
.stateMask
= TVIS_SELECTED
;
124 if ( !TreeView_GetItem(hwndTV
, &tvi
) )
126 wxLogLastError(wxT("TreeView_GetItem"));
129 return (tvi
.state
& TVIS_SELECTED
) != 0;
132 static void SelectItem(HWND hwndTV
, HTREEITEM hItem
, bool select
= TRUE
)
135 tvi
.mask
= TVIF_STATE
| TVIF_HANDLE
;
136 tvi
.stateMask
= TVIS_SELECTED
;
137 tvi
.state
= select
? TVIS_SELECTED
: 0;
140 if ( TreeView_SetItem(hwndTV
, &tvi
) == -1 )
142 wxLogLastError(wxT("TreeView_SetItem"));
146 static inline void UnselectItem(HWND hwndTV
, HTREEITEM htItem
)
148 SelectItem(hwndTV
, htItem
, FALSE
);
151 static inline void ToggleItemSelection(HWND hwndTV
, HTREEITEM htItem
)
153 SelectItem(hwndTV
, htItem
, !IsItemSelected(hwndTV
, htItem
));
156 // helper function which selects all items in a range and, optionally,
157 // unselects all others
158 static void SelectRange(HWND hwndTV
,
161 bool unselectOthers
= TRUE
)
163 // find the first (or last) item and select it
165 HTREEITEM htItem
= (HTREEITEM
)TreeView_GetRoot(hwndTV
);
166 while ( htItem
&& cont
)
168 if ( (htItem
== htFirst
) || (htItem
== htLast
) )
170 if ( !IsItemSelected(hwndTV
, htItem
) )
172 SelectItem(hwndTV
, htItem
);
179 if ( unselectOthers
&& IsItemSelected(hwndTV
, htItem
) )
181 UnselectItem(hwndTV
, htItem
);
185 htItem
= (HTREEITEM
)TreeView_GetNextVisible(hwndTV
, htItem
);
188 // select the items in range
189 cont
= htFirst
!= htLast
;
190 while ( htItem
&& cont
)
192 if ( !IsItemSelected(hwndTV
, htItem
) )
194 SelectItem(hwndTV
, htItem
);
197 cont
= (htItem
!= htFirst
) && (htItem
!= htLast
);
199 htItem
= (HTREEITEM
)TreeView_GetNextVisible(hwndTV
, htItem
);
203 if ( unselectOthers
)
207 if ( IsItemSelected(hwndTV
, htItem
) )
209 UnselectItem(hwndTV
, htItem
);
212 htItem
= (HTREEITEM
)TreeView_GetNextVisible(hwndTV
, htItem
);
216 // seems to be necessary - otherwise the just selected items don't always
217 // appear as selected
218 UpdateWindow(hwndTV
);
221 // helper function which tricks the standard control into changing the focused
222 // item without changing anything else (if someone knows why Microsoft doesn't
223 // allow to do it by just setting TVIS_FOCUSED flag, please tell me!)
224 static void SetFocus(HWND hwndTV
, HTREEITEM htItem
)
227 HTREEITEM htFocus
= (HTREEITEM
)TreeView_GetSelection(hwndTV
);
232 if ( htItem
!= htFocus
)
234 // remember the selection state of the item
235 bool wasSelected
= IsItemSelected(hwndTV
, htItem
);
237 if ( htFocus
&& IsItemSelected(hwndTV
, htFocus
) )
239 // prevent the tree from unselecting the old focus which it
240 // would do by default (TreeView_SelectItem unselects the
242 TreeView_SelectItem(hwndTV
, 0);
243 SelectItem(hwndTV
, htFocus
);
246 TreeView_SelectItem(hwndTV
, htItem
);
250 // need to clear the selection which TreeView_SelectItem() gave
252 UnselectItem(hwndTV
, htItem
);
254 //else: was selected, still selected - ok
256 //else: nothing to do, focus already there
262 bool wasFocusSelected
= IsItemSelected(hwndTV
, htFocus
);
264 // just clear the focus
265 TreeView_SelectItem(hwndTV
, 0);
267 if ( wasFocusSelected
)
269 // restore the selection state
270 SelectItem(hwndTV
, htFocus
);
273 //else: nothing to do, no focus already
277 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
279 // ----------------------------------------------------------------------------
281 // ----------------------------------------------------------------------------
283 // a convenient wrapper around TV_ITEM struct which adds a ctor
285 #pragma warning( disable : 4097 ) // inheriting from typedef
288 struct wxTreeViewItem
: public TV_ITEM
290 wxTreeViewItem(const wxTreeItemId
& item
, // the item handle
291 UINT mask_
, // fields which are valid
292 UINT stateMask_
= 0) // for TVIF_STATE only
294 // hItem member is always valid
295 mask
= mask_
| TVIF_HANDLE
;
296 stateMask
= stateMask_
;
302 #pragma warning( default : 4097 )
305 // a class which encapsulates the tree traversal logic: it vists all (unless
306 // OnVisit() returns FALSE) items under the given one
307 class wxTreeTraversal
310 wxTreeTraversal(const wxTreeCtrl
*tree
)
315 // do traverse the tree: visit all items (recursively by default) under the
316 // given one; return TRUE if all items were traversed or FALSE if the
317 // traversal was aborted because OnVisit returned FALSE
318 bool DoTraverse(const wxTreeItemId
& root
, bool recursively
= TRUE
);
320 // override this function to do whatever is needed for each item, return
321 // FALSE to stop traversing
322 virtual bool OnVisit(const wxTreeItemId
& item
) = 0;
325 const wxTreeCtrl
*GetTree() const { return m_tree
; }
328 bool Traverse(const wxTreeItemId
& root
, bool recursively
);
330 const wxTreeCtrl
*m_tree
;
333 // internal class for getting the selected items
334 class TraverseSelections
: public wxTreeTraversal
337 TraverseSelections(const wxTreeCtrl
*tree
,
338 wxArrayTreeItemIds
& selections
)
339 : wxTreeTraversal(tree
), m_selections(selections
)
341 m_selections
.Empty();
343 DoTraverse(tree
->GetRootItem());
346 virtual bool OnVisit(const wxTreeItemId
& item
)
348 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
349 if ( GetTree()->IsItemChecked(item
) )
351 if ( ::IsItemSelected(GetHwndOf(GetTree()), HITEM(item
)) )
354 m_selections
.Add(item
);
360 size_t GetCount() const { return m_selections
.GetCount(); }
363 wxArrayTreeItemIds
& m_selections
;
366 // internal class for counting tree items
367 class TraverseCounter
: public wxTreeTraversal
370 TraverseCounter(const wxTreeCtrl
*tree
,
371 const wxTreeItemId
& root
,
373 : wxTreeTraversal(tree
)
377 DoTraverse(root
, recursively
);
380 virtual bool OnVisit(const wxTreeItemId
& WXUNUSED(item
))
387 size_t GetCount() const { return m_count
; }
393 // ----------------------------------------------------------------------------
394 // This class is needed for support of different images: the Win32 common
395 // control natively supports only 2 images (the normal one and another for the
396 // selected state). We wish to provide support for 2 more of them for folder
397 // items (i.e. those which have children): for expanded state and for expanded
398 // selected state. For this we use this structure to store the additional items
401 // There is only one problem with this: when we retrieve the item's data, we
402 // don't know whether we get a pointer to wxTreeItemData or
403 // wxTreeItemIndirectData. So we always set the item id to an invalid value
404 // in this class and the code using the client data checks for it and retrieves
405 // the real client data in this case.
406 // ----------------------------------------------------------------------------
408 class wxTreeItemIndirectData
: public wxTreeItemData
411 // ctor associates this data with the item and the real item data becomes
412 // available through our GetData() method
413 wxTreeItemIndirectData(wxTreeCtrl
*tree
, const wxTreeItemId
& item
)
415 for ( size_t n
= 0; n
< WXSIZEOF(m_images
); n
++ )
421 m_data
= tree
->GetItemData(item
);
423 // and set ourselves as the new one
424 tree
->SetIndirectItemData(item
, this);
426 // we must have the invalid value for the item
430 // dtor deletes the associated data as well
431 virtual ~wxTreeItemIndirectData() { delete m_data
; }
434 // get the real data associated with the item
435 wxTreeItemData
*GetData() const { return m_data
; }
437 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
439 // do we have such image?
440 bool HasImage(wxTreeItemIcon which
) const { return m_images
[which
] != -1; }
442 int GetImage(wxTreeItemIcon which
) const { return m_images
[which
]; }
444 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
447 // all the images associated with the item
448 int m_images
[wxTreeItemIcon_Max
];
450 // the real client data
451 wxTreeItemData
*m_data
;
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
460 // ----------------------------------------------------------------------------
462 // ----------------------------------------------------------------------------
464 // indices in gs_expandEvents table below
479 // handy table for sending events - it has to be initialized during run-time
480 // now so can't be const any more
481 static /* const */ wxEventType gs_expandEvents
[IDX_WHAT_MAX
][IDX_HOW_MAX
];
484 but logically it's a const table with the following entries:
487 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxEVT_COMMAND_TREE_ITEM_COLLAPSING },
488 { wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxEVT_COMMAND_TREE_ITEM_EXPANDING }
492 // ============================================================================
494 // ============================================================================
496 // ----------------------------------------------------------------------------
498 // ----------------------------------------------------------------------------
500 bool wxTreeTraversal::DoTraverse(const wxTreeItemId
& root
, bool recursively
)
502 if ( !OnVisit(root
) )
505 return Traverse(root
, recursively
);
508 bool wxTreeTraversal::Traverse(const wxTreeItemId
& root
, bool recursively
)
511 wxTreeItemId child
= m_tree
->GetFirstChild(root
, cookie
);
512 while ( child
.IsOk() )
514 // depth first traversal
515 if ( recursively
&& !Traverse(child
, TRUE
) )
518 if ( !OnVisit(child
) )
521 child
= m_tree
->GetNextChild(root
, cookie
);
527 // ----------------------------------------------------------------------------
528 // construction and destruction
529 // ----------------------------------------------------------------------------
531 void wxTreeCtrl::Init()
533 m_imageListNormal
= NULL
;
534 m_imageListState
= NULL
;
535 m_ownsImageListNormal
= m_ownsImageListState
= FALSE
;
537 m_hasAnyAttr
= FALSE
;
541 // initialize the global array of events now as it can't be done statically
542 // with the wxEVT_XXX values being allocated during run-time only
543 gs_expandEvents
[IDX_COLLAPSE
][IDX_DONE
] = wxEVT_COMMAND_TREE_ITEM_COLLAPSED
;
544 gs_expandEvents
[IDX_COLLAPSE
][IDX_DOING
] = wxEVT_COMMAND_TREE_ITEM_COLLAPSING
;
545 gs_expandEvents
[IDX_EXPAND
][IDX_DONE
] = wxEVT_COMMAND_TREE_ITEM_EXPANDED
;
546 gs_expandEvents
[IDX_EXPAND
][IDX_DOING
] = wxEVT_COMMAND_TREE_ITEM_EXPANDING
;
549 bool wxTreeCtrl::Create(wxWindow
*parent
,
554 const wxValidator
& validator
,
555 const wxString
& name
)
559 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
562 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
565 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
566 wstyle
|= WS_CLIPSIBLINGS
;
568 if ((m_windowStyle
& wxTR_NO_LINES
) == 0)
569 wstyle
|= TVS_HASLINES
;
570 if ( m_windowStyle
& wxTR_HAS_BUTTONS
)
571 wstyle
|= TVS_HASBUTTONS
;
573 if ( m_windowStyle
& wxTR_EDIT_LABELS
)
574 wstyle
|= TVS_EDITLABELS
;
576 if ( m_windowStyle
& wxTR_LINES_AT_ROOT
)
577 wstyle
|= TVS_LINESATROOT
;
579 if ( m_windowStyle
& wxTR_FULL_ROW_HIGHLIGHT
)
581 if ( wxTheApp
->GetComCtl32Version() >= 471 )
582 wstyle
|= TVS_FULLROWSELECT
;
585 // using TVS_CHECKBOXES for emulation of a multiselection tree control
586 // doesn't work without the new enough headers
587 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE && \
588 !defined( __GNUWIN32_OLD__ ) && \
589 !defined( __BORLANDC__ ) && \
590 !defined( __WATCOMC__ ) && \
591 (!defined(__VISUALC__) || (__VISUALC__ > 1010))
593 // we emulate the multiple selection tree controls by using checkboxes: set
594 // up the image list we need for this if we do have multiple selections
595 if ( m_windowStyle
& wxTR_MULTIPLE
)
596 wstyle
|= TVS_CHECKBOXES
;
597 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
599 // Create the tree control.
600 if ( !MSWCreateControl(WC_TREEVIEW
, wstyle
) )
603 #if wxUSE_COMCTL32_SAFELY
604 wxWindow::SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
605 wxWindow::SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
607 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
608 SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
610 // This works around a bug in the Windows tree control whereby for some versions
611 // of comctrl32, setting any colour actually draws the background in black.
612 // This will initialise the background to the system colour.
613 // THIS FIX NOW REVERTED since it caused problems on _other_ systems.
614 // Assume the user has an updated comctl32.dll.
615 ::SendMessage(GetHwnd(), TVM_SETBKCOLOR
, 0,-1);
616 wxWindow::SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
617 SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
621 // VZ: this is some experimental code which may be used to get the
622 // TVS_CHECKBOXES style functionality for comctl32.dll < 4.71.
623 // AFAIK, the standard DLL does about the same thing anyhow.
625 if ( m_windowStyle
& wxTR_MULTIPLE
)
629 // create the DC compatible with the current screen
630 HDC hdcMem
= CreateCompatibleDC(NULL
);
632 // create a mono bitmap of the standard size
633 int x
= GetSystemMetrics(SM_CXMENUCHECK
);
634 int y
= GetSystemMetrics(SM_CYMENUCHECK
);
635 wxImageList
imagelistCheckboxes(x
, y
, FALSE
, 2);
636 HBITMAP hbmpCheck
= CreateBitmap(x
, y
, // bitmap size
637 1, // # of color planes
638 1, // # bits needed for one pixel
639 0); // array containing colour data
640 SelectObject(hdcMem
, hbmpCheck
);
642 // then draw a check mark into it
643 RECT rect
= { 0, 0, x
, y
};
644 if ( !::DrawFrameControl(hdcMem
, &rect
,
646 DFCS_BUTTONCHECK
| DFCS_CHECKED
) )
648 wxLogLastError(wxT("DrawFrameControl(check)"));
651 bmp
.SetHBITMAP((WXHBITMAP
)hbmpCheck
);
652 imagelistCheckboxes
.Add(bmp
);
654 if ( !::DrawFrameControl(hdcMem
, &rect
,
658 wxLogLastError(wxT("DrawFrameControl(uncheck)"));
661 bmp
.SetHBITMAP((WXHBITMAP
)hbmpCheck
);
662 imagelistCheckboxes
.Add(bmp
);
668 SetStateImageList(&imagelistCheckboxes
);
672 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
677 wxTreeCtrl::~wxTreeCtrl()
679 // delete any attributes
682 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
684 delete (wxTreeItemAttr
*)node
->Data();
687 // prevent TVN_DELETEITEM handler from deleting the attributes again!
688 m_hasAnyAttr
= FALSE
;
693 // delete user data to prevent memory leaks
696 if (m_ownsImageListNormal
) delete m_imageListNormal
;
697 if (m_ownsImageListState
) delete m_imageListState
;
700 // ----------------------------------------------------------------------------
702 // ----------------------------------------------------------------------------
704 // simple wrappers which add error checking in debug mode
706 bool wxTreeCtrl::DoGetItem(wxTreeViewItem
* tvItem
) const
708 if ( !TreeView_GetItem(GetHwnd(), tvItem
) )
710 wxLogLastError(wxT("TreeView_GetItem"));
718 void wxTreeCtrl::DoSetItem(wxTreeViewItem
* tvItem
)
720 if ( TreeView_SetItem(GetHwnd(), tvItem
) == -1 )
722 wxLogLastError(wxT("TreeView_SetItem"));
726 size_t wxTreeCtrl::GetCount() const
728 return (size_t)TreeView_GetCount(GetHwnd());
731 unsigned int wxTreeCtrl::GetIndent() const
733 return TreeView_GetIndent(GetHwnd());
736 void wxTreeCtrl::SetIndent(unsigned int indent
)
738 TreeView_SetIndent(GetHwnd(), indent
);
741 wxImageList
*wxTreeCtrl::GetImageList() const
743 return m_imageListNormal
;
746 wxImageList
*wxTreeCtrl::GetStateImageList() const
748 return m_imageListNormal
;
751 void wxTreeCtrl::SetAnyImageList(wxImageList
*imageList
, int which
)
754 TreeView_SetImageList(GetHwnd(),
755 imageList
? imageList
->GetHIMAGELIST() : 0,
759 void wxTreeCtrl::SetImageList(wxImageList
*imageList
)
761 if (m_ownsImageListNormal
) delete m_imageListNormal
;
762 SetAnyImageList(m_imageListNormal
= imageList
, TVSIL_NORMAL
);
763 m_ownsImageListNormal
= FALSE
;
766 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
)
768 if (m_ownsImageListState
) delete m_imageListState
;
769 SetAnyImageList(m_imageListState
= imageList
, TVSIL_STATE
);
770 m_ownsImageListState
= FALSE
;
773 void wxTreeCtrl::AssignImageList(wxImageList
*imageList
)
775 SetImageList(imageList
);
776 m_ownsImageListNormal
= TRUE
;
779 void wxTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
781 SetStateImageList(imageList
);
782 m_ownsImageListState
= TRUE
;
785 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
786 bool recursively
) const
788 TraverseCounter
counter(this, item
, recursively
);
790 return counter
.GetCount() - 1;
793 // ----------------------------------------------------------------------------
795 // ----------------------------------------------------------------------------
797 bool wxTreeCtrl::SetBackgroundColour(const wxColour
&colour
)
799 #if !wxUSE_COMCTL32_SAFELY
800 if ( !wxWindowBase::SetBackgroundColour(colour
) )
803 SendMessage(GetHwnd(), TVM_SETBKCOLOR
, 0, colour
.GetPixel());
809 bool wxTreeCtrl::SetForegroundColour(const wxColour
&colour
)
811 #if !wxUSE_COMCTL32_SAFELY
812 if ( !wxWindowBase::SetForegroundColour(colour
) )
815 SendMessage(GetHwnd(), TVM_SETTEXTCOLOR
, 0, colour
.GetPixel());
821 // ----------------------------------------------------------------------------
823 // ----------------------------------------------------------------------------
825 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
827 wxChar buf
[512]; // the size is arbitrary...
829 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
830 tvItem
.pszText
= buf
;
831 tvItem
.cchTextMax
= WXSIZEOF(buf
);
832 if ( !DoGetItem(&tvItem
) )
834 // don't return some garbage which was on stack, but an empty string
838 return wxString(buf
);
841 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
843 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
844 tvItem
.pszText
= (wxChar
*)text
.c_str(); // conversion is ok
848 int wxTreeCtrl::DoGetItemImageFromData(const wxTreeItemId
& item
,
849 wxTreeItemIcon which
) const
851 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
852 if ( !DoGetItem(&tvItem
) )
857 return ((wxTreeItemIndirectData
*)tvItem
.lParam
)->GetImage(which
);
860 void wxTreeCtrl::DoSetItemImageFromData(const wxTreeItemId
& item
,
862 wxTreeItemIcon which
) const
864 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
865 if ( !DoGetItem(&tvItem
) )
870 wxTreeItemIndirectData
*data
= ((wxTreeItemIndirectData
*)tvItem
.lParam
);
872 data
->SetImage(image
, which
);
874 // make sure that we have selected images as well
875 if ( which
== wxTreeItemIcon_Normal
&&
876 !data
->HasImage(wxTreeItemIcon_Selected
) )
878 data
->SetImage(image
, wxTreeItemIcon_Selected
);
881 if ( which
== wxTreeItemIcon_Expanded
&&
882 !data
->HasImage(wxTreeItemIcon_SelectedExpanded
) )
884 data
->SetImage(image
, wxTreeItemIcon_SelectedExpanded
);
888 void wxTreeCtrl::DoSetItemImages(const wxTreeItemId
& item
,
892 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
| TVIF_SELECTEDIMAGE
);
893 tvItem
.iSelectedImage
= imageSel
;
894 tvItem
.iImage
= image
;
898 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
899 wxTreeItemIcon which
) const
901 if ( HasIndirectData(item
) )
903 return DoGetItemImageFromData(item
, which
);
910 wxFAIL_MSG( wxT("unknown tree item image type") );
912 case wxTreeItemIcon_Normal
:
916 case wxTreeItemIcon_Selected
:
917 mask
= TVIF_SELECTEDIMAGE
;
920 case wxTreeItemIcon_Expanded
:
921 case wxTreeItemIcon_SelectedExpanded
:
925 wxTreeViewItem
tvItem(item
, mask
);
928 return mask
== TVIF_IMAGE
? tvItem
.iImage
: tvItem
.iSelectedImage
;
931 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
,
932 wxTreeItemIcon which
)
934 int imageNormal
, imageSel
;
938 wxFAIL_MSG( wxT("unknown tree item image type") );
940 case wxTreeItemIcon_Normal
:
942 imageSel
= GetItemSelectedImage(item
);
945 case wxTreeItemIcon_Selected
:
946 imageNormal
= GetItemImage(item
);
950 case wxTreeItemIcon_Expanded
:
951 case wxTreeItemIcon_SelectedExpanded
:
952 if ( !HasIndirectData(item
) )
954 // we need to get the old images first, because after we create
955 // the wxTreeItemIndirectData GetItemXXXImage() will use it to
957 imageNormal
= GetItemImage(item
);
958 imageSel
= GetItemSelectedImage(item
);
960 // if it doesn't have it yet, add it
961 wxTreeItemIndirectData
*data
= new
962 wxTreeItemIndirectData(this, item
);
964 // copy the data to the new location
965 data
->SetImage(imageNormal
, wxTreeItemIcon_Normal
);
966 data
->SetImage(imageSel
, wxTreeItemIcon_Selected
);
969 DoSetItemImageFromData(item
, image
, which
);
971 // reset the normal/selected images because we won't use them any
972 // more - now they're stored inside the indirect data
974 imageSel
= I_IMAGECALLBACK
;
978 // NB: at least in version 5.00.0518.9 of comctl32.dll we need to always
979 // change both normal and selected image - otherwise the change simply
980 // doesn't take place!
981 DoSetItemImages(item
, imageNormal
, imageSel
);
984 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
986 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
987 if ( !DoGetItem(&tvItem
) )
992 wxTreeItemData
*data
= (wxTreeItemData
*)tvItem
.lParam
;
993 if ( IsDataIndirect(data
) )
995 data
= ((wxTreeItemIndirectData
*)data
)->GetData();
1001 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
1003 // first, associate this piece of data with this item
1009 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
1011 if ( HasIndirectData(item
) )
1013 if ( DoGetItem(&tvItem
) )
1015 ((wxTreeItemIndirectData
*)tvItem
.lParam
)->SetData(data
);
1019 wxFAIL_MSG( wxT("failed to change tree items data") );
1024 tvItem
.lParam
= (LPARAM
)data
;
1029 void wxTreeCtrl::SetIndirectItemData(const wxTreeItemId
& item
,
1030 wxTreeItemIndirectData
*data
)
1032 // this should never happen because it's unnecessary and will probably lead
1033 // to crash too because the code elsewhere supposes that the pointer the
1034 // wxTreeItemIndirectData has is a real wxItemData and not
1035 // wxTreeItemIndirectData as well
1036 wxASSERT_MSG( !HasIndirectData(item
), wxT("setting indirect data twice?") );
1038 SetItemData(item
, data
);
1041 bool wxTreeCtrl::HasIndirectData(const wxTreeItemId
& item
) const
1043 // query the item itself
1044 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
1045 if ( !DoGetItem(&tvItem
) )
1050 wxTreeItemData
*data
= (wxTreeItemData
*)tvItem
.lParam
;
1052 return data
&& IsDataIndirect(data
);
1055 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
1057 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
1058 tvItem
.cChildren
= (int)has
;
1062 void wxTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
1064 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
1065 tvItem
.state
= bold
? TVIS_BOLD
: 0;
1069 void wxTreeCtrl::SetItemDropHighlight(const wxTreeItemId
& item
, bool highlight
)
1071 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_DROPHILITED
);
1072 tvItem
.state
= highlight
? TVIS_DROPHILITED
: 0;
1076 void wxTreeCtrl::RefreshItem(const wxTreeItemId
& item
)
1079 if ( GetBoundingRect(item
, rect
) )
1085 void wxTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
1086 const wxColour
& col
)
1088 m_hasAnyAttr
= TRUE
;
1090 long id
= (long)(WXHTREEITEM
)item
;
1091 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
1094 attr
= new wxTreeItemAttr
;
1095 m_attrs
.Put(id
, (wxObject
*)attr
);
1098 attr
->SetTextColour(col
);
1103 void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1104 const wxColour
& col
)
1106 m_hasAnyAttr
= TRUE
;
1108 long id
= (long)(WXHTREEITEM
)item
;
1109 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
1112 attr
= new wxTreeItemAttr
;
1113 m_attrs
.Put(id
, (wxObject
*)attr
);
1116 attr
->SetBackgroundColour(col
);
1121 void wxTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1123 m_hasAnyAttr
= TRUE
;
1125 long id
= (long)(WXHTREEITEM
)item
;
1126 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
1129 attr
= new wxTreeItemAttr
;
1130 m_attrs
.Put(id
, (wxObject
*)attr
);
1133 attr
->SetFont(font
);
1138 // ----------------------------------------------------------------------------
1140 // ----------------------------------------------------------------------------
1142 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1144 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
1147 // this ugliness comes directly from MSDN - it *is* the correct way to pass
1148 // the HTREEITEM with TVM_GETITEMRECT
1149 *(WXHTREEITEM
*)&rect
= (WXHTREEITEM
)item
;
1151 // FALSE means get item rect for the whole item, not only text
1152 return SendMessage(GetHwnd(), TVM_GETITEMRECT
, FALSE
, (LPARAM
)&rect
) != 0;
1155 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1157 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
1160 return tvItem
.cChildren
!= 0;
1163 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1165 // probably not a good idea to put it here
1166 //wxASSERT( ItemHasChildren(item) );
1168 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDED
);
1171 return (tvItem
.state
& TVIS_EXPANDED
) != 0;
1174 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1176 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_SELECTED
);
1179 return (tvItem
.state
& TVIS_SELECTED
) != 0;
1182 bool wxTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1184 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
1187 return (tvItem
.state
& TVIS_BOLD
) != 0;
1190 // ----------------------------------------------------------------------------
1192 // ----------------------------------------------------------------------------
1194 wxTreeItemId
wxTreeCtrl::GetRootItem() const
1196 return wxTreeItemId((WXHTREEITEM
) TreeView_GetRoot(GetHwnd()));
1199 wxTreeItemId
wxTreeCtrl::GetSelection() const
1201 wxCHECK_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), (long)(WXHTREEITEM
)0,
1202 wxT("this only works with single selection controls") );
1204 return wxTreeItemId((WXHTREEITEM
) TreeView_GetSelection(GetHwnd()));
1207 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const
1209 return wxTreeItemId((WXHTREEITEM
) TreeView_GetParent(GetHwnd(), HITEM(item
)));
1212 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1213 long& _cookie
) const
1215 // remember the last child returned in 'cookie'
1216 _cookie
= (long)TreeView_GetChild(GetHwnd(), HITEM(item
));
1218 return wxTreeItemId((WXHTREEITEM
)_cookie
);
1221 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
1222 long& _cookie
) const
1224 wxTreeItemId l
= wxTreeItemId((WXHTREEITEM
)TreeView_GetNextSibling(GetHwnd(),
1231 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1233 // can this be done more efficiently?
1236 wxTreeItemId childLast
,
1237 child
= GetFirstChild(item
, cookie
);
1238 while ( child
.IsOk() )
1241 child
= GetNextChild(item
, cookie
);
1247 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1249 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(GetHwnd(), HITEM(item
)));
1252 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1254 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevSibling(GetHwnd(), HITEM(item
)));
1257 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
1259 return wxTreeItemId((WXHTREEITEM
) TreeView_GetFirstVisible(GetHwnd()));
1262 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1264 wxASSERT_MSG( IsVisible(item
), wxT("The item you call GetNextVisible() for must be visible itself!"));
1266 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextVisible(GetHwnd(), HITEM(item
)));
1269 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1271 wxASSERT_MSG( IsVisible(item
), wxT("The item you call GetPrevVisible() for must be visible itself!"));
1273 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevVisible(GetHwnd(), HITEM(item
)));
1276 // ----------------------------------------------------------------------------
1277 // multiple selections emulation
1278 // ----------------------------------------------------------------------------
1280 bool wxTreeCtrl::IsItemChecked(const wxTreeItemId
& item
) const
1282 // receive the desired information.
1283 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_STATEIMAGEMASK
);
1286 // state image indices are 1 based
1287 return ((tvItem
.state
>> 12) - 1) == 1;
1290 void wxTreeCtrl::SetItemCheck(const wxTreeItemId
& item
, bool check
)
1292 // receive the desired information.
1293 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_STATEIMAGEMASK
);
1295 // state images are one-based
1296 tvItem
.state
= (check
? 2 : 1) << 12;
1301 size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds
& selections
) const
1303 TraverseSelections
selector(this, selections
);
1305 return selector
.GetCount();
1308 // ----------------------------------------------------------------------------
1310 // ----------------------------------------------------------------------------
1312 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
1313 wxTreeItemId hInsertAfter
,
1314 const wxString
& text
,
1315 int image
, int selectedImage
,
1316 wxTreeItemData
*data
)
1318 wxCHECK_MSG( parent
.IsOk() || !TreeView_GetRoot(GetHwnd()),
1320 _T("can't have more than one root in the tree") );
1322 TV_INSERTSTRUCT tvIns
;
1323 tvIns
.hParent
= HITEM(parent
);
1324 tvIns
.hInsertAfter
= HITEM(hInsertAfter
);
1326 // this is how we insert the item as the first child: supply a NULL
1328 if ( !tvIns
.hInsertAfter
)
1330 tvIns
.hInsertAfter
= TVI_FIRST
;
1334 if ( !text
.IsEmpty() )
1337 tvIns
.item
.pszText
= (wxChar
*)text
.c_str(); // cast is ok
1341 tvIns
.item
.pszText
= NULL
;
1342 tvIns
.item
.cchTextMax
= 0;
1348 tvIns
.item
.iImage
= image
;
1350 if ( selectedImage
== -1 )
1352 // take the same image for selected icon if not specified
1353 selectedImage
= image
;
1357 if ( selectedImage
!= -1 )
1359 mask
|= TVIF_SELECTEDIMAGE
;
1360 tvIns
.item
.iSelectedImage
= selectedImage
;
1366 tvIns
.item
.lParam
= (LPARAM
)data
;
1369 tvIns
.item
.mask
= mask
;
1371 HTREEITEM id
= (HTREEITEM
) TreeView_InsertItem(GetHwnd(), &tvIns
);
1374 wxLogLastError(wxT("TreeView_InsertItem"));
1379 // associate the application tree item with Win32 tree item handle
1380 data
->SetId((WXHTREEITEM
)id
);
1383 return wxTreeItemId((WXHTREEITEM
)id
);
1386 // for compatibility only
1387 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
1388 const wxString
& text
,
1389 int image
, int selImage
,
1392 return DoInsertItem(parent
, (WXHTREEITEM
)insertAfter
, text
,
1393 image
, selImage
, NULL
);
1396 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
1397 int image
, int selectedImage
,
1398 wxTreeItemData
*data
)
1400 return DoInsertItem(wxTreeItemId((long) (WXHTREEITEM
) 0), (long)(WXHTREEITEM
) 0,
1401 text
, image
, selectedImage
, data
);
1404 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1405 const wxString
& text
,
1406 int image
, int selectedImage
,
1407 wxTreeItemData
*data
)
1409 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_FIRST
,
1410 text
, image
, selectedImage
, data
);
1413 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
1414 const wxTreeItemId
& idPrevious
,
1415 const wxString
& text
,
1416 int image
, int selectedImage
,
1417 wxTreeItemData
*data
)
1419 return DoInsertItem(parent
, idPrevious
, text
, image
, selectedImage
, data
);
1422 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
1424 const wxString
& text
,
1425 int image
, int selectedImage
,
1426 wxTreeItemData
*data
)
1428 // find the item from index
1430 wxTreeItemId idPrev
, idCur
= GetFirstChild(parent
, cookie
);
1431 while ( index
!= 0 && idCur
.IsOk() )
1436 idCur
= GetNextChild(parent
, cookie
);
1439 // assert, not check: if the index is invalid, we will append the item
1441 wxASSERT_MSG( index
== 0, _T("bad index in wxTreeCtrl::InsertItem") );
1443 return DoInsertItem(parent
, idPrev
, text
, image
, selectedImage
, data
);
1446 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
1447 const wxString
& text
,
1448 int image
, int selectedImage
,
1449 wxTreeItemData
*data
)
1451 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_LAST
,
1452 text
, image
, selectedImage
, data
);
1455 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
1457 if ( !TreeView_DeleteItem(GetHwnd(), HITEM(item
)) )
1459 wxLogLastError(wxT("TreeView_DeleteItem"));
1463 // delete all children (but don't delete the item itself)
1464 void wxTreeCtrl::DeleteChildren(const wxTreeItemId
& item
)
1468 wxArrayLong children
;
1469 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1470 while ( child
.IsOk() )
1472 children
.Add((long)(WXHTREEITEM
)child
);
1474 child
= GetNextChild(item
, cookie
);
1477 size_t nCount
= children
.Count();
1478 for ( size_t n
= 0; n
< nCount
; n
++ )
1480 if ( !TreeView_DeleteItem(GetHwnd(), (HTREEITEM
)children
[n
]) )
1482 wxLogLastError(wxT("TreeView_DeleteItem"));
1487 void wxTreeCtrl::DeleteAllItems()
1489 if ( !TreeView_DeleteAllItems(GetHwnd()) )
1491 wxLogLastError(wxT("TreeView_DeleteAllItems"));
1495 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
1497 wxASSERT_MSG( flag
== TVE_COLLAPSE
||
1498 flag
== (TVE_COLLAPSE
| TVE_COLLAPSERESET
) ||
1499 flag
== TVE_EXPAND
||
1501 wxT("Unknown flag in wxTreeCtrl::DoExpand") );
1503 // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
1504 // emulate them. This behaviour has changed slightly with comctl32.dll
1505 // v 4.70 - now it does send them but only the first time. To maintain
1506 // compatible behaviour and also in order to not have surprises with the
1507 // future versions, don't rely on this and still do everything ourselves.
1508 // To avoid that the messages be sent twice when the item is expanded for
1509 // the first time we must clear TVIS_EXPANDEDONCE style manually.
1511 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDEDONCE
);
1515 if ( TreeView_Expand(GetHwnd(), HITEM(item
), flag
) != 0 )
1517 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
1518 event
.m_item
= item
;
1519 event
.SetEventObject(this);
1521 // note that the {EXPAND|COLLAPS}ING event is sent by TreeView_Expand()
1523 event
.SetEventType(gs_expandEvents
[IsExpanded(item
) ? IDX_EXPAND
1527 (void)GetEventHandler()->ProcessEvent(event
);
1529 //else: change didn't took place, so do nothing at all
1532 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
1534 DoExpand(item
, TVE_EXPAND
);
1537 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
1539 DoExpand(item
, TVE_COLLAPSE
);
1542 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1544 DoExpand(item
, TVE_COLLAPSE
| TVE_COLLAPSERESET
);
1547 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
1549 DoExpand(item
, TVE_TOGGLE
);
1552 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
)
1554 DoExpand(item
, action
);
1557 void wxTreeCtrl::Unselect()
1559 wxASSERT_MSG( !(m_windowStyle
& wxTR_MULTIPLE
),
1560 wxT("doesn't make sense, may be you want UnselectAll()?") );
1562 // just remove the selection
1563 SelectItem(wxTreeItemId((long) (WXHTREEITEM
) 0));
1566 void wxTreeCtrl::UnselectAll()
1568 if ( m_windowStyle
& wxTR_MULTIPLE
)
1570 wxArrayTreeItemIds selections
;
1571 size_t count
= GetSelections(selections
);
1572 for ( size_t n
= 0; n
< count
; n
++ )
1574 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1575 SetItemCheck(selections
[n
], FALSE
);
1576 #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1577 ::UnselectItem(GetHwnd(), HITEM(selections
[n
]));
1578 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1583 // just remove the selection
1588 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
)
1590 if ( m_windowStyle
& wxTR_MULTIPLE
)
1592 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1593 // selecting the item means checking it
1595 #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1596 ::SelectItem(GetHwnd(), HITEM(item
));
1597 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1601 // inspite of the docs (MSDN Jan 99 edition), we don't seem to receive
1602 // the notification from the control (i.e. TVN_SELCHANG{ED|ING}), so
1603 // send them ourselves
1605 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
1606 event
.m_item
= item
;
1607 event
.SetEventObject(this);
1609 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGING
);
1610 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
1612 if ( !TreeView_SelectItem(GetHwnd(), HITEM(item
)) )
1614 wxLogLastError(wxT("TreeView_SelectItem"));
1618 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1619 (void)GetEventHandler()->ProcessEvent(event
);
1622 //else: program vetoed the change
1626 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1629 TreeView_EnsureVisible(GetHwnd(), HITEM(item
));
1632 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
1634 if ( !TreeView_SelectSetFirstVisible(GetHwnd(), HITEM(item
)) )
1636 wxLogLastError(wxT("TreeView_SelectSetFirstVisible"));
1640 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
1642 // normally, we could try to do something like this to return something
1643 // even when the editing was started by the user and not by calling
1644 // EditLabel() - but as nobody has asked for this so far and there might be
1645 // problems in the code below, I leave it disabled for now (VZ)
1649 HWND hwndText
= TreeView_GetEditControl(GetHwnd());
1652 m_textCtrl
= new wxTextCtrl(this, -1);
1654 m_textCtrl
->SetHWND((WXHWND
)hwndText
);
1656 //else: not editing label right now
1663 void wxTreeCtrl::DeleteTextCtrl()
1667 // the HWND corresponding to this control is deleted by the tree
1668 // control itself and we don't know when exactly this happens, so check
1669 // if the window still exists before calling UnsubclassWin()
1670 if ( !::IsWindow(GetHwndOf(m_textCtrl
)) )
1672 m_textCtrl
->SetHWND(0);
1675 m_textCtrl
->UnsubclassWin();
1676 m_textCtrl
->SetHWND(0);
1682 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
1683 wxClassInfo
* textControlClass
)
1685 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
1689 HWND hWnd
= (HWND
) TreeView_EditLabel(GetHwnd(), HITEM(item
));
1691 // this is not an error - the TVN_BEGINLABELEDIT handler might have
1698 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
1699 m_textCtrl
->SetParent(this);
1700 m_textCtrl
->SetHWND((WXHWND
)hWnd
);
1701 m_textCtrl
->SubclassWin((WXHWND
)hWnd
);
1706 // End label editing, optionally cancelling the edit
1707 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& WXUNUSED(item
), bool discardChanges
)
1709 TreeView_EndEditLabelNow(GetHwnd(), discardChanges
);
1714 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
1716 TV_HITTESTINFO hitTestInfo
;
1717 hitTestInfo
.pt
.x
= (int)point
.x
;
1718 hitTestInfo
.pt
.y
= (int)point
.y
;
1720 TreeView_HitTest(GetHwnd(), &hitTestInfo
);
1725 #define TRANSLATE_FLAG(flag) if ( hitTestInfo.flags & TVHT_##flag ) \
1726 flags |= wxTREE_HITTEST_##flag
1728 TRANSLATE_FLAG(ABOVE
);
1729 TRANSLATE_FLAG(BELOW
);
1730 TRANSLATE_FLAG(NOWHERE
);
1731 TRANSLATE_FLAG(ONITEMBUTTON
);
1732 TRANSLATE_FLAG(ONITEMICON
);
1733 TRANSLATE_FLAG(ONITEMINDENT
);
1734 TRANSLATE_FLAG(ONITEMLABEL
);
1735 TRANSLATE_FLAG(ONITEMRIGHT
);
1736 TRANSLATE_FLAG(ONITEMSTATEICON
);
1737 TRANSLATE_FLAG(TOLEFT
);
1738 TRANSLATE_FLAG(TORIGHT
);
1740 #undef TRANSLATE_FLAG
1742 return wxTreeItemId((WXHTREEITEM
) hitTestInfo
.hItem
);
1745 bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
1747 bool textOnly
) const
1750 if ( TreeView_GetItemRect(GetHwnd(), HITEM(item
),
1753 rect
= wxRect(wxPoint(rc
.left
, rc
.top
), wxPoint(rc
.right
, rc
.bottom
));
1759 // couldn't retrieve rect: for example, item isn't visible
1764 // ----------------------------------------------------------------------------
1766 // ----------------------------------------------------------------------------
1768 // this is just a tiny namespace which is friend to wxTreeCtrl and so can use
1769 // functions such as IsDataIndirect()
1770 class wxTreeSortHelper
1773 static int CALLBACK
Compare(LPARAM data1
, LPARAM data2
, LPARAM tree
);
1776 static wxTreeItemId
GetIdFromData(wxTreeCtrl
*tree
, LPARAM item
)
1778 wxTreeItemData
*data
= (wxTreeItemData
*)item
;
1779 if ( tree
->IsDataIndirect(data
) )
1781 data
= ((wxTreeItemIndirectData
*)data
)->GetData();
1784 return data
->GetId();
1788 int CALLBACK
wxTreeSortHelper::Compare(LPARAM pItem1
,
1792 wxCHECK_MSG( pItem1
&& pItem2
, 0,
1793 wxT("sorting tree without data doesn't make sense") );
1795 wxTreeCtrl
*tree
= (wxTreeCtrl
*)htree
;
1797 return tree
->OnCompareItems(GetIdFromData(tree
, pItem1
),
1798 GetIdFromData(tree
, pItem2
));
1801 int wxTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1802 const wxTreeItemId
& item2
)
1804 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1807 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
)
1809 // rely on the fact that TreeView_SortChildren does the same thing as our
1810 // default behaviour, i.e. sorts items alphabetically and so call it
1811 // directly if we're not in derived class (much more efficient!)
1812 if ( GetClassInfo() == CLASSINFO(wxTreeCtrl
) )
1814 TreeView_SortChildren(GetHwnd(), HITEM(item
), 0);
1819 tvSort
.hParent
= HITEM(item
);
1820 tvSort
.lpfnCompare
= wxTreeSortHelper::Compare
;
1821 tvSort
.lParam
= (LPARAM
)this;
1822 TreeView_SortChildrenCB(GetHwnd(), &tvSort
, 0 /* reserved */);
1826 // ----------------------------------------------------------------------------
1828 // ----------------------------------------------------------------------------
1830 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1832 if ( cmd
== EN_UPDATE
)
1834 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1835 event
.SetEventObject( this );
1836 ProcessCommand(event
);
1838 else if ( cmd
== EN_KILLFOCUS
)
1840 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1841 event
.SetEventObject( this );
1842 ProcessCommand(event
);
1850 // command processed
1854 // we hook into WndProc to process WM_MOUSEMOVE/WM_BUTTONUP messages - as we
1855 // only do it during dragging, minimize wxWin overhead (this is important for
1856 // WM_MOUSEMOVE as they're a lot of them) by catching Windows messages directly
1857 // instead of passing by wxWin events
1858 long wxTreeCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1860 bool processed
= FALSE
;
1862 bool isMultiple
= (GetWindowStyle() & wxTR_MULTIPLE
) != 0;
1864 if ( (nMsg
>= WM_MOUSEFIRST
) && (nMsg
<= WM_MOUSELAST
) )
1866 // we only process mouse messages here and these parameters have the same
1867 // meaning for all of them
1868 int x
= GET_X_LPARAM(lParam
),
1869 y
= GET_Y_LPARAM(lParam
);
1870 HTREEITEM htItem
= GetItemFromPoint(GetHwnd(), x
, y
);
1874 #if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1875 case WM_LBUTTONDOWN
:
1876 if ( htItem
&& isMultiple
)
1878 if ( wParam
& MK_CONTROL
)
1882 // toggle selected state
1883 ToggleItemSelection(GetHwnd(), htItem
);
1885 ::SetFocus(GetHwnd(), htItem
);
1887 // reset on any click without Shift
1892 else if ( wParam
& MK_SHIFT
)
1894 // this selects all items between the starting one and
1897 if ( !m_htSelStart
)
1899 // take the focused item
1900 m_htSelStart
= (WXHTREEITEM
)
1901 TreeView_GetSelection(GetHwnd());
1904 SelectRange(GetHwnd(), HITEM(m_htSelStart
), htItem
,
1905 !(wParam
& MK_CONTROL
));
1907 ::SetFocus(GetHwnd(), htItem
);
1911 else // normal click
1913 // clear the selection and then let the default handler
1917 // prevent the click from starting in-place editing
1918 // when there was no selection in the control
1919 TreeView_SelectItem(GetHwnd(), 0);
1921 // reset on any click without Shift
1926 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1931 m_dragImage
->Move(wxPoint(x
, y
));
1934 // highlight the item as target (hiding drag image is
1935 // necessary - otherwise the display will be corrupted)
1936 m_dragImage
->Hide();
1937 TreeView_SelectDropTarget(GetHwnd(), htItem
);
1938 m_dragImage
->Show();
1947 m_dragImage
->EndDrag();
1951 // generate the drag end event
1952 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, m_windowId
);
1954 event
.m_item
= (WXHTREEITEM
)htItem
;
1955 event
.m_pointDrag
= wxPoint(x
, y
);
1956 event
.SetEventObject(this);
1958 (void)GetEventHandler()->ProcessEvent(event
);
1960 // if we don't do it, the tree seems to think that 2 items
1961 // are selected simultaneously which is quite weird
1962 TreeView_SelectDropTarget(GetHwnd(), 0);
1967 #if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
1968 else if ( (nMsg
== WM_SETFOCUS
|| nMsg
== WM_KILLFOCUS
) && isMultiple
)
1970 // the tree control greys out the selected item when it loses focus and
1971 // paints it as selected again when it regains it, but it won't do it
1972 // for the other items itself - help it
1973 wxArrayTreeItemIds selections
;
1974 size_t count
= GetSelections(selections
);
1976 for ( size_t n
= 0; n
< count
; n
++ )
1978 // TreeView_GetItemRect() will return FALSE if item is not visible,
1979 // which may happen perfectly well
1980 if ( TreeView_GetItemRect(GetHwnd(), HITEM(selections
[n
]),
1983 ::InvalidateRect(GetHwnd(), &rect
, FALSE
);
1987 else if ( nMsg
== WM_KEYDOWN
&& isMultiple
)
1989 bool bCtrl
= wxIsCtrlDown(),
1990 bShift
= wxIsShiftDown();
1992 // we handle.arrows and space, but not page up/down and home/end: the
1993 // latter should be easy, but not the former
1995 HTREEITEM htSel
= (HTREEITEM
)TreeView_GetSelection(GetHwnd());
1996 if ( !m_htSelStart
)
1998 m_htSelStart
= (WXHTREEITEM
)htSel
;
2001 if ( wParam
== VK_SPACE
)
2005 ToggleItemSelection(GetHwnd(), htSel
);
2011 ::SelectItem(GetHwnd(), htSel
);
2016 else if ( wParam
== VK_UP
|| wParam
== VK_DOWN
)
2018 if ( !bCtrl
&& !bShift
)
2020 // no modifiers, just clear selection and then let the default
2021 // processing to take place
2026 (void)wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
2028 HTREEITEM htNext
= (HTREEITEM
)(wParam
== VK_UP
2029 ? TreeView_GetPrevVisible(GetHwnd(), htSel
)
2030 : TreeView_GetNextVisible(GetHwnd(), htSel
));
2034 // at the top/bottom
2040 SelectRange(GetHwnd(), HITEM(m_htSelStart
), htNext
);
2044 // without changing selection
2045 ::SetFocus(GetHwnd(), htNext
);
2052 #endif // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
2054 rc
= wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
2059 // process WM_NOTIFY Windows message
2060 bool wxTreeCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
2062 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
2063 wxEventType eventType
= wxEVT_NULL
;
2064 NMHDR
*hdr
= (NMHDR
*)lParam
;
2066 switch ( hdr
->code
)
2069 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
2072 case TVN_BEGINRDRAG
:
2074 if ( eventType
== wxEVT_NULL
)
2075 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
2076 //else: left drag, already set above
2078 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
2080 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
2081 event
.m_pointDrag
= wxPoint(tv
->ptDrag
.x
, tv
->ptDrag
.y
);
2083 // don't allow dragging by default: the user code must
2084 // explicitly say that it wants to allow it to avoid breaking
2090 case TVN_BEGINLABELEDIT
:
2092 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
2093 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
2095 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
2096 event
.m_label
= info
->item
.pszText
;
2100 case TVN_DELETEITEM
:
2102 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
2103 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
2105 event
.m_item
= (WXHTREEITEM
)tv
->itemOld
.hItem
;
2109 delete (wxTreeItemAttr
*)m_attrs
.
2110 Delete((long)tv
->itemOld
.hItem
);
2115 case TVN_ENDLABELEDIT
:
2117 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
2118 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
2120 event
.m_item
= (WXHTREEITEM
)info
->item
.hItem
;
2121 event
.m_label
= info
->item
.pszText
;
2122 if (info
->item
.pszText
== NULL
)
2127 case TVN_GETDISPINFO
:
2128 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
2131 case TVN_SETDISPINFO
:
2133 if ( eventType
== wxEVT_NULL
)
2134 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
2135 //else: get, already set above
2137 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
2139 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
2143 case TVN_ITEMEXPANDING
:
2144 case TVN_ITEMEXPANDED
:
2146 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
2149 switch ( tv
->action
)
2152 wxLogDebug(wxT("unexpected code %d in TVN_ITEMEXPAND message"), tv
->action
);
2160 what
= IDX_COLLAPSE
;
2164 int how
= (int)hdr
->code
== TVN_ITEMEXPANDING
? IDX_DOING
2167 eventType
= gs_expandEvents
[what
][how
];
2169 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
2175 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
2176 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
2178 // we pass 0 as last CreateKeyEvent() parameter because we
2179 // don't have access to the real key press flags here - but as
2180 // it is only used to determin wxKeyEvent::m_altDown flag it's
2182 event
.m_evtKey
= CreateKeyEvent(wxEVT_KEY_DOWN
,
2183 wxCharCodeMSWToWX(info
->wVKey
),
2186 // a separate event for Space/Return
2187 if ( !wxIsCtrlDown() && !wxIsShiftDown() &&
2188 ((info
->wVKey
== VK_SPACE
) || (info
->wVKey
== VK_RETURN
)) )
2190 wxTreeEvent
event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
2192 event2
.SetEventObject(this);
2193 if ( !(GetWindowStyle() & wxTR_MULTIPLE
) )
2195 event2
.m_item
= GetSelection();
2197 //else: don't know how to get it
2199 (void)GetEventHandler()->ProcessEvent(event2
);
2204 case TVN_SELCHANGED
:
2205 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
2208 case TVN_SELCHANGING
:
2210 if ( eventType
== wxEVT_NULL
)
2211 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
2212 //else: already set above
2214 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
2216 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
2217 event
.m_itemOld
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
2221 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 && !wxUSE_COMCTL32_SAFELY && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
2224 LPNMTVCUSTOMDRAW lptvcd
= (LPNMTVCUSTOMDRAW
)lParam
;
2225 NMCUSTOMDRAW
& nmcd
= lptvcd
->nmcd
;
2226 switch ( nmcd
.dwDrawStage
)
2229 // if we've got any items with non standard attributes,
2230 // notify us before painting each item
2231 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2235 case CDDS_ITEMPREPAINT
:
2237 wxTreeItemAttr
*attr
=
2238 (wxTreeItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
2242 // nothing to do for this item
2243 *result
= CDRF_DODEFAULT
;
2248 wxColour colText
, colBack
;
2249 if ( attr
->HasFont() )
2251 wxFont font
= attr
->GetFont();
2252 hFont
= (HFONT
)font
.GetResourceHandle();
2259 if ( attr
->HasTextColour() )
2261 colText
= attr
->GetTextColour();
2265 colText
= GetForegroundColour();
2268 // selection colours should override ours
2269 if ( nmcd
.uItemState
& CDIS_SELECTED
)
2271 DWORD clrBk
= ::GetSysColor(COLOR_HIGHLIGHT
);
2272 lptvcd
->clrTextBk
= clrBk
;
2274 // try to make the text visible
2275 lptvcd
->clrText
= wxColourToRGB(colText
);
2276 lptvcd
->clrText
|= ~clrBk
;
2277 lptvcd
->clrText
&= 0x00ffffff;
2281 if ( attr
->HasBackgroundColour() )
2283 colBack
= attr
->GetBackgroundColour();
2287 colBack
= GetBackgroundColour();
2290 lptvcd
->clrText
= wxColourToRGB(colText
);
2291 lptvcd
->clrTextBk
= wxColourToRGB(colBack
);
2294 // note that if we wanted to set colours for
2295 // individual columns (subitems), we would have
2296 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2299 ::SelectObject(nmcd
.hdc
, hFont
);
2301 *result
= CDRF_NEWFONT
;
2305 *result
= CDRF_DODEFAULT
;
2311 *result
= CDRF_DODEFAULT
;
2315 // we always process it
2317 #endif // _WIN32_IE >= 0x300
2322 TV_HITTESTINFO tvhti
;
2323 ::GetCursorPos(&tvhti
.pt
);
2324 ::ScreenToClient(GetHwnd(), &tvhti
.pt
);
2325 if ( TreeView_HitTest(GetHwnd(), &tvhti
) )
2327 if ( tvhti
.flags
& TVHT_ONITEM
)
2329 event
.m_item
= (WXHTREEITEM
) tvhti
.hItem
;
2330 eventType
= (int)hdr
->code
== NM_DBLCLK
2331 ? wxEVT_COMMAND_TREE_ITEM_ACTIVATED
2332 : wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
;
2334 event
.m_pointDrag
.x
= tvhti
.pt
.x
;
2335 event
.m_pointDrag
.y
= tvhti
.pt
.y
;
2344 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2347 event
.SetEventObject(this);
2348 event
.SetEventType(eventType
);
2350 bool processed
= GetEventHandler()->ProcessEvent(event
);
2353 switch ( hdr
->code
)
2356 // we translate NM_DBLCLK into ACTIVATED event, so don't interpret
2357 // the return code of this event handler as the return value for
2358 // NM_DBLCLK - otherwise, double clicking the item to toggle its
2359 // expanded status would never work
2364 case TVN_BEGINRDRAG
:
2365 if ( event
.IsAllowed() )
2367 // normally this is impossible because the m_dragImage is
2368 // deleted once the drag operation is over
2369 wxASSERT_MSG( !m_dragImage
, _T("starting to drag once again?") );
2371 m_dragImage
= new wxDragImage(*this, event
.m_item
);
2372 m_dragImage
->BeginDrag(wxPoint(0, 0), this);
2373 m_dragImage
->Show();
2377 case TVN_DELETEITEM
:
2379 // NB: we might process this message using wxWindows event
2380 // tables, but due to overhead of wxWin event system we
2381 // prefer to do it here ourself (otherwise deleting a tree
2382 // with many items is just too slow)
2383 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
2385 wxTreeItemId item
= event
.m_item
;
2386 if ( HasIndirectData(item
) )
2388 wxTreeItemIndirectData
*data
= (wxTreeItemIndirectData
*)
2390 delete data
; // can't be NULL here
2394 wxTreeItemData
*data
= (wxTreeItemData
*)tv
->itemOld
.lParam
;
2395 delete data
; // may be NULL, ok
2398 processed
= TRUE
; // Make sure we don't get called twice
2402 case TVN_BEGINLABELEDIT
:
2403 // return TRUE to cancel label editing
2404 *result
= !event
.IsAllowed();
2407 case TVN_ENDLABELEDIT
:
2408 // return TRUE to set the label to the new string: note that we
2409 // also must pretend that we did process the message or it is going
2410 // to be passed to DefWindowProc() which will happily return FALSE
2411 // cancelling the label change
2412 *result
= event
.IsAllowed();
2415 // ensure that we don't have the text ctrl which is going to be
2420 case TVN_SELCHANGING
:
2421 case TVN_ITEMEXPANDING
:
2422 // return TRUE to prevent the action from happening
2423 *result
= !event
.IsAllowed();
2426 case TVN_ITEMEXPANDED
:
2427 // the item is not refreshed properly after expansion when it has
2428 // an image depending on the expanded/collapsed state - bug in
2429 // comctl32.dll or our code?
2431 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
2432 if ( tv
->action
== TVE_EXPAND
)
2434 wxTreeItemId id
= (WXHTREEITEM
)tv
->itemNew
.hItem
;
2436 int image
= GetItemImage(id
, wxTreeItemIcon_Expanded
);
2445 case TVN_GETDISPINFO
:
2446 // NB: so far the user can't set the image himself anyhow, so do it
2447 // anyway - but this may change later
2448 // if ( /* !processed && */ 1 )
2450 wxTreeItemId item
= event
.m_item
;
2451 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
2452 if ( info
->item
.mask
& TVIF_IMAGE
)
2455 DoGetItemImageFromData
2458 IsExpanded(item
) ? wxTreeItemIcon_Expanded
2459 : wxTreeItemIcon_Normal
2462 if ( info
->item
.mask
& TVIF_SELECTEDIMAGE
)
2464 info
->item
.iSelectedImage
=
2465 DoGetItemImageFromData
2468 IsExpanded(item
) ? wxTreeItemIcon_SelectedExpanded
2469 : wxTreeItemIcon_Selected
2476 // for the other messages the return value is ignored and there is
2477 // nothing special to do
2484 #endif // wxUSE_TREECTRL