1 /////////////////////////////////////////////////////////////////////////////
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 // ----------------------------------------------------------------------------
20 #pragma implementation "treectrl.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
30 #include "wx/window.h"
31 #include "wx/msw/private.h"
33 // Mingw32 is a bit mental even though this is done in winundef
42 #if defined(__WIN95__)
45 #include "wx/dynarray.h"
46 #include "wx/imaglist.h"
47 #include "wx/treectrl.h"
48 #include "wx/settings.h"
51 #ifndef wxUSE_NORLANDER_HEADERS
52 #include "wx/msw/gnuwin32/extra.h"
56 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
60 // Bug in headers, sometimes
62 #define TVIS_FOCUSED 0x0001
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // a convenient wrapper around TV_ITEM struct which adds a ctor
71 #pragma warning( disable : 4097 )
74 struct wxTreeViewItem
: public TV_ITEM
76 wxTreeViewItem(const wxTreeItemId
& item
, // the item handle
77 UINT mask_
, // fields which are valid
78 UINT stateMask_
= 0) // for TVIF_STATE only
80 // hItem member is always valid
81 mask
= mask_
| TVIF_HANDLE
;
82 stateMask
= stateMask_
;
83 hItem
= (HTREEITEM
) (WXHTREEITEM
) item
;
88 #pragma warning( default : 4097 )
91 // a class which encapsulates the tree traversal logic: it vists all (unless
92 // OnVisit() returns FALSE) items under the given one
96 wxTreeTraversal(const wxTreeCtrl
*tree
)
101 // do traverse the tree: visit all items (recursively by default) under the
102 // given one; return TRUE if all items were traversed or FALSE if the
103 // traversal was aborted because OnVisit returned FALSE
104 bool DoTraverse(const wxTreeItemId
& root
, bool recursively
= TRUE
);
106 // override this function to do whatever is needed for each item, return
107 // FALSE to stop traversing
108 virtual bool OnVisit(const wxTreeItemId
& item
) = 0;
111 const wxTreeCtrl
*GetTree() const { return m_tree
; }
114 bool Traverse(const wxTreeItemId
& root
, bool recursively
);
116 const wxTreeCtrl
*m_tree
;
119 // internal class for getting the selected items
120 class TraverseSelections
: public wxTreeTraversal
123 TraverseSelections(const wxTreeCtrl
*tree
,
124 wxArrayTreeItemIds
& selections
)
125 : wxTreeTraversal(tree
), m_selections(selections
)
127 m_selections
.Empty();
129 DoTraverse(tree
->GetRootItem());
132 virtual bool OnVisit(const wxTreeItemId
& item
)
134 if ( GetTree()->IsItemChecked(item
) )
136 m_selections
.Add(item
);
143 wxArrayTreeItemIds
& m_selections
;
146 // internal class for counting tree items
147 class TraverseCounter
: public wxTreeTraversal
150 TraverseCounter(const wxTreeCtrl
*tree
,
151 const wxTreeItemId
& root
,
153 : wxTreeTraversal(tree
)
157 DoTraverse(root
, recursively
);
160 virtual bool OnVisit(const wxTreeItemId
& item
)
167 size_t GetCount() const { return m_count
; }
173 // ----------------------------------------------------------------------------
174 // This class is needed for support of different images: the Win32 common
175 // control natively supports only 2 images (the normal one and another for the
176 // selected state). We wish to provide support for 2 more of them for folder
177 // items (i.e. those which have children): for expanded state and for expanded
178 // selected state. For this we use this structure to store the additional items
181 // There is only one problem with this: when we retrieve the item's data, we
182 // don't know whether we get a pointer to wxTreeItemData or
183 // wxTreeItemIndirectData. So we have to maintain a list of all items which
184 // have indirect data inside the listctrl itself.
185 // ----------------------------------------------------------------------------
187 class wxTreeItemIndirectData
190 // ctor associates this data with the item and the real item data becomes
191 // available through our GetData() method
192 wxTreeItemIndirectData(wxTreeCtrl
*tree
, const wxTreeItemId
& item
)
194 for ( size_t n
= 0; n
< WXSIZEOF(m_images
); n
++ )
200 m_data
= tree
->GetItemData(item
);
202 // and set ourselves as the new one
203 tree
->SetIndirectItemData(item
, this);
206 // dtor deletes the associated data as well
207 ~wxTreeItemIndirectData() { delete m_data
; }
210 // get the real data associated with the item
211 wxTreeItemData
*GetData() const { return m_data
; }
213 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
215 // do we have such image?
216 bool HasImage(wxTreeItemIcon which
) const { return m_images
[which
] != -1; }
218 int GetImage(wxTreeItemIcon which
) const { return m_images
[which
]; }
220 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
223 // all the images associated with the item
224 int m_images
[wxTreeItemIcon_Max
];
226 wxTreeItemData
*m_data
;
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
233 #if !USE_SHARED_LIBRARY
234 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
237 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
241 // handy table for sending events
242 static const wxEventType g_events
[2][2] =
244 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, wxEVT_COMMAND_TREE_ITEM_COLLAPSING
},
245 { wxEVT_COMMAND_TREE_ITEM_EXPANDED
, wxEVT_COMMAND_TREE_ITEM_EXPANDING
}
248 // ============================================================================
250 // ============================================================================
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
256 bool wxTreeTraversal::DoTraverse(const wxTreeItemId
& root
, bool recursively
)
258 if ( !OnVisit(root
) )
261 return Traverse(root
, recursively
);
264 bool wxTreeTraversal::Traverse(const wxTreeItemId
& root
, bool recursively
)
267 wxTreeItemId child
= m_tree
->GetFirstChild(root
, cookie
);
268 while ( child
.IsOk() )
270 // depth first traversal
271 if ( recursively
&& !Traverse(child
, TRUE
) )
274 if ( !OnVisit(child
) )
277 child
= m_tree
->GetNextChild(root
, cookie
);
283 // ----------------------------------------------------------------------------
284 // construction and destruction
285 // ----------------------------------------------------------------------------
287 void wxTreeCtrl::Init()
289 m_imageListNormal
= NULL
;
290 m_imageListState
= NULL
;
292 m_hasAnyAttr
= FALSE
;
295 bool wxTreeCtrl::Create(wxWindow
*parent
,
300 const wxValidator
& validator
,
301 const wxString
& name
)
305 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
308 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
309 TVS_HASLINES
| TVS_SHOWSELALWAYS
;
311 if ( m_windowStyle
& wxTR_HAS_BUTTONS
)
312 wstyle
|= TVS_HASBUTTONS
;
314 if ( m_windowStyle
& wxTR_EDIT_LABELS
)
315 wstyle
|= TVS_EDITLABELS
;
317 if ( m_windowStyle
& wxTR_LINES_AT_ROOT
)
318 wstyle
|= TVS_LINESATROOT
;
320 #if !defined( __GNUWIN32__ ) && !defined( __BORLANDC__ ) && !defined( __WATCOMC__ ) && !defined(wxUSE_NORLANDER_HEADERS)
321 // we emulate the multiple selection tree controls by using checkboxes: set
322 // up the image list we need for this if we do have multiple selections
323 #if !defined(__VISUALC__) || (__VISUALC__ > 1010)
324 if ( m_windowStyle
& wxTR_MULTIPLE
)
325 wstyle
|= TVS_CHECKBOXES
;
329 // Create the tree control.
330 if ( !MSWCreateControl(WC_TREEVIEW
, wstyle
) )
333 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
334 SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
336 // VZ: this is some experimental code which may be used to get the
337 // TVS_CHECKBOXES style functionality for comctl32.dll < 4.71.
338 // AFAIK, the standard DLL does about the same thing anyhow.
340 if ( m_windowStyle
& wxTR_MULTIPLE
)
344 // create the DC compatible with the current screen
345 HDC hdcMem
= CreateCompatibleDC(NULL
);
347 // create a mono bitmap of the standard size
348 int x
= GetSystemMetrics(SM_CXMENUCHECK
);
349 int y
= GetSystemMetrics(SM_CYMENUCHECK
);
350 wxImageList
imagelistCheckboxes(x
, y
, FALSE
, 2);
351 HBITMAP hbmpCheck
= CreateBitmap(x
, y
, // bitmap size
352 1, // # of color planes
353 1, // # bits needed for one pixel
354 0); // array containing colour data
355 SelectObject(hdcMem
, hbmpCheck
);
357 // then draw a check mark into it
358 RECT rect
= { 0, 0, x
, y
};
359 if ( !::DrawFrameControl(hdcMem
, &rect
,
361 DFCS_BUTTONCHECK
| DFCS_CHECKED
) )
363 wxLogLastError(wxT("DrawFrameControl(check)"));
366 bmp
.SetHBITMAP((WXHBITMAP
)hbmpCheck
);
367 imagelistCheckboxes
.Add(bmp
);
369 if ( !::DrawFrameControl(hdcMem
, &rect
,
373 wxLogLastError(wxT("DrawFrameControl(uncheck)"));
376 bmp
.SetHBITMAP((WXHBITMAP
)hbmpCheck
);
377 imagelistCheckboxes
.Add(bmp
);
383 SetStateImageList(&imagelistCheckboxes
);
387 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
392 wxTreeCtrl::~wxTreeCtrl()
394 // delete any attributes
397 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
399 delete (wxTreeItemAttr
*)node
->Data();
402 // prevent TVN_DELETEITEM handler from deleting the attributes again!
403 m_hasAnyAttr
= FALSE
;
408 // delete user data to prevent memory leaks
412 // ----------------------------------------------------------------------------
414 // ----------------------------------------------------------------------------
416 // simple wrappers which add error checking in debug mode
418 bool wxTreeCtrl::DoGetItem(wxTreeViewItem
* tvItem
) const
420 if ( !TreeView_GetItem(GetHwnd(), tvItem
) )
422 wxLogLastError("TreeView_GetItem");
430 void wxTreeCtrl::DoSetItem(wxTreeViewItem
* tvItem
)
432 if ( TreeView_SetItem(GetHwnd(), tvItem
) == -1 )
434 wxLogLastError("TreeView_SetItem");
438 size_t wxTreeCtrl::GetCount() const
440 return (size_t)TreeView_GetCount(GetHwnd());
443 unsigned int wxTreeCtrl::GetIndent() const
445 return TreeView_GetIndent(GetHwnd());
448 void wxTreeCtrl::SetIndent(unsigned int indent
)
450 TreeView_SetIndent(GetHwnd(), indent
);
453 wxImageList
*wxTreeCtrl::GetImageList() const
455 return m_imageListNormal
;
458 wxImageList
*wxTreeCtrl::GetStateImageList() const
460 return m_imageListNormal
;
463 void wxTreeCtrl::SetAnyImageList(wxImageList
*imageList
, int which
)
466 TreeView_SetImageList(GetHwnd(),
467 imageList
? imageList
->GetHIMAGELIST() : 0,
471 void wxTreeCtrl::SetImageList(wxImageList
*imageList
)
473 SetAnyImageList(m_imageListNormal
= imageList
, TVSIL_NORMAL
);
476 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
)
478 SetAnyImageList(m_imageListState
= imageList
, TVSIL_STATE
);
481 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
482 bool recursively
) const
484 TraverseCounter
counter(this, item
, recursively
);
486 return counter
.GetCount() - 1;
489 // ----------------------------------------------------------------------------
491 // ----------------------------------------------------------------------------
493 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
495 wxChar buf
[512]; // the size is arbitrary...
497 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
498 tvItem
.pszText
= buf
;
499 tvItem
.cchTextMax
= WXSIZEOF(buf
);
500 if ( !DoGetItem(&tvItem
) )
502 // don't return some garbage which was on stack, but an empty string
506 return wxString(buf
);
509 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
511 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
512 tvItem
.pszText
= (wxChar
*)text
.c_str(); // conversion is ok
516 int wxTreeCtrl::DoGetItemImageFromData(const wxTreeItemId
& item
,
517 wxTreeItemIcon which
) const
519 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
520 if ( !DoGetItem(&tvItem
) )
525 return ((wxTreeItemIndirectData
*)tvItem
.lParam
)->GetImage(which
);
528 void wxTreeCtrl::DoSetItemImageFromData(const wxTreeItemId
& item
,
530 wxTreeItemIcon which
) const
532 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
533 if ( !DoGetItem(&tvItem
) )
538 wxTreeItemIndirectData
*data
= ((wxTreeItemIndirectData
*)tvItem
.lParam
);
540 data
->SetImage(image
, which
);
542 // make sure that we have selected images as well
543 if ( which
== wxTreeItemIcon_Normal
&&
544 !data
->HasImage(wxTreeItemIcon_Selected
) )
546 data
->SetImage(image
, wxTreeItemIcon_Selected
);
549 if ( which
== wxTreeItemIcon_Expanded
&&
550 !data
->HasImage(wxTreeItemIcon_SelectedExpanded
) )
552 data
->SetImage(image
, wxTreeItemIcon_SelectedExpanded
);
556 void wxTreeCtrl::DoSetItemImages(const wxTreeItemId
& item
,
560 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
| TVIF_SELECTEDIMAGE
);
561 tvItem
.iSelectedImage
= imageSel
;
562 tvItem
.iImage
= image
;
566 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
567 wxTreeItemIcon which
) const
569 if ( HasIndirectData(item
) )
571 return DoGetItemImageFromData(item
, which
);
578 wxFAIL_MSG( wxT("unknown tree item image type") );
580 case wxTreeItemIcon_Normal
:
584 case wxTreeItemIcon_Selected
:
585 mask
= TVIF_SELECTEDIMAGE
;
588 case wxTreeItemIcon_Expanded
:
589 case wxTreeItemIcon_SelectedExpanded
:
593 wxTreeViewItem
tvItem(item
, mask
);
596 return mask
== TVIF_IMAGE
? tvItem
.iImage
: tvItem
.iSelectedImage
;
599 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
,
600 wxTreeItemIcon which
)
602 int imageNormal
, imageSel
;
606 wxFAIL_MSG( wxT("unknown tree item image type") );
608 case wxTreeItemIcon_Normal
:
610 imageSel
= GetItemSelectedImage(item
);
613 case wxTreeItemIcon_Selected
:
614 imageNormal
= GetItemImage(item
);
618 case wxTreeItemIcon_Expanded
:
619 case wxTreeItemIcon_SelectedExpanded
:
620 if ( !HasIndirectData(item
) )
622 // we need to get the old images first, because after we create
623 // the wxTreeItemIndirectData GetItemXXXImage() will use it to
625 imageNormal
= GetItemImage(item
);
626 imageSel
= GetItemSelectedImage(item
);
628 // if it doesn't have it yet, add it
629 wxTreeItemIndirectData
*data
= new
630 wxTreeItemIndirectData(this, item
);
632 // copy the data to the new location
633 data
->SetImage(imageNormal
, wxTreeItemIcon_Normal
);
634 data
->SetImage(imageSel
, wxTreeItemIcon_Selected
);
637 DoSetItemImageFromData(item
, image
, which
);
639 // reset the normal/selected images because we won't use them any
640 // more - now they're stored inside the indirect data
642 imageSel
= I_IMAGECALLBACK
;
646 // NB: at least in version 5.00.0518.9 of comctl32.dll we need to always
647 // change both normal and selected image - otherwise the change simply
648 // doesn't take place!
649 DoSetItemImages(item
, imageNormal
, imageSel
);
652 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
654 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
655 if ( !DoGetItem(&tvItem
) )
660 if ( HasIndirectData(item
) )
662 return ((wxTreeItemIndirectData
*)tvItem
.lParam
)->GetData();
666 return (wxTreeItemData
*)tvItem
.lParam
;
670 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
672 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
674 if ( HasIndirectData(item
) )
676 if ( DoGetItem(&tvItem
) )
678 ((wxTreeItemIndirectData
*)tvItem
.lParam
)->SetData(data
);
682 wxFAIL_MSG( wxT("failed to change tree items data") );
687 tvItem
.lParam
= (LPARAM
)data
;
692 void wxTreeCtrl::SetIndirectItemData(const wxTreeItemId
& item
,
693 wxTreeItemIndirectData
*data
)
695 // this should never happen because it's unnecessary and will probably lead
696 // to crash too because the code elsewhere supposes that the pointer the
697 // wxTreeItemIndirectData has is a real wxItemData and not
698 // wxTreeItemIndirectData as well
699 wxASSERT_MSG( !HasIndirectData(item
), wxT("setting indirect data twice?") );
701 SetItemData(item
, (wxTreeItemData
*)data
);
703 m_itemsWithIndirectData
.Add(item
);
706 bool wxTreeCtrl::HasIndirectData(const wxTreeItemId
& item
) const
708 return m_itemsWithIndirectData
.Index(item
) != wxNOT_FOUND
;
711 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
713 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
714 tvItem
.cChildren
= (int)has
;
718 void wxTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
720 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
721 tvItem
.state
= bold
? TVIS_BOLD
: 0;
725 void wxTreeCtrl::SetItemDropHighlight(const wxTreeItemId
& item
, bool highlight
)
727 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_DROPHILITED
);
728 tvItem
.state
= highlight
? TVIS_DROPHILITED
: 0;
732 void wxTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
737 long id
= (long)(WXHTREEITEM
)item
;
738 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
741 attr
= new wxTreeItemAttr
;
742 m_attrs
.Put(id
, (wxObject
*)attr
);
745 attr
->SetTextColour(col
);
748 void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
753 long id
= (long)(WXHTREEITEM
)item
;
754 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
757 attr
= new wxTreeItemAttr
;
758 m_attrs
.Put(id
, (wxObject
*)attr
);
761 attr
->SetBackgroundColour(col
);
764 void wxTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
768 long id
= (long)(WXHTREEITEM
)item
;
769 wxTreeItemAttr
*attr
= (wxTreeItemAttr
*)m_attrs
.Get(id
);
772 attr
= new wxTreeItemAttr
;
773 m_attrs
.Put(id
, (wxObject
*)attr
);
779 // ----------------------------------------------------------------------------
781 // ----------------------------------------------------------------------------
783 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
785 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
788 // this ugliness comes directly from MSDN - it *is* the correct way to pass
789 // the HTREEITEM with TVM_GETITEMRECT
790 *(WXHTREEITEM
*)&rect
= (WXHTREEITEM
)item
;
792 // FALSE means get item rect for the whole item, not only text
793 return SendMessage(GetHwnd(), TVM_GETITEMRECT
, FALSE
, (LPARAM
)&rect
) != 0;
797 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
799 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
802 return tvItem
.cChildren
!= 0;
805 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
807 // probably not a good idea to put it here
808 //wxASSERT( ItemHasChildren(item) );
810 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDED
);
813 return (tvItem
.state
& TVIS_EXPANDED
) != 0;
816 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
818 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_SELECTED
);
821 return (tvItem
.state
& TVIS_SELECTED
) != 0;
824 bool wxTreeCtrl::IsBold(const wxTreeItemId
& item
) const
826 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
829 return (tvItem
.state
& TVIS_BOLD
) != 0;
832 // ----------------------------------------------------------------------------
834 // ----------------------------------------------------------------------------
836 wxTreeItemId
wxTreeCtrl::GetRootItem() const
838 return wxTreeItemId((WXHTREEITEM
) TreeView_GetRoot(GetHwnd()));
841 wxTreeItemId
wxTreeCtrl::GetSelection() const
843 wxCHECK_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), (WXHTREEITEM
)0,
844 wxT("this only works with single selection controls") );
846 return wxTreeItemId((WXHTREEITEM
) TreeView_GetSelection(GetHwnd()));
849 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const
851 return wxTreeItemId((WXHTREEITEM
) TreeView_GetParent(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
));
854 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
857 // remember the last child returned in 'cookie'
858 _cookie
= (long)TreeView_GetChild(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
)item
);
860 return wxTreeItemId((WXHTREEITEM
)_cookie
);
863 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
866 wxTreeItemId l
= wxTreeItemId((WXHTREEITEM
)TreeView_GetNextSibling(GetHwnd(),
867 (HTREEITEM
)(WXHTREEITEM
)_cookie
));
873 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
875 // can this be done more efficiently?
878 wxTreeItemId childLast
,
879 child
= GetFirstChild(item
, cookie
);
880 while ( child
.IsOk() )
883 child
= GetNextChild(item
, cookie
);
889 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
891 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
));
894 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
896 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevSibling(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
));
899 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
901 return wxTreeItemId((WXHTREEITEM
) TreeView_GetFirstVisible(GetHwnd()));
904 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
906 wxASSERT_MSG( IsVisible(item
), wxT("The item you call GetNextVisible() "
907 "for must be visible itself!"));
909 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextVisible(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
));
912 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
914 wxASSERT_MSG( IsVisible(item
), wxT("The item you call GetPrevVisible() "
915 "for must be visible itself!"));
917 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevVisible(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
));
920 // ----------------------------------------------------------------------------
921 // multiple selections emulation
922 // ----------------------------------------------------------------------------
924 bool wxTreeCtrl::IsItemChecked(const wxTreeItemId
& item
) const
926 // receive the desired information.
927 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_STATEIMAGEMASK
);
930 // state image indices are 1 based
931 return ((tvItem
.state
>> 12) - 1) == 1;
934 void wxTreeCtrl::SetItemCheck(const wxTreeItemId
& item
, bool check
)
936 // receive the desired information.
937 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_STATEIMAGEMASK
);
939 // state images are one-based
940 tvItem
.state
= (check
? 2 : 1) << 12;
945 size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds
& selections
) const
947 TraverseSelections
selector(this, selections
);
949 return selections
.GetCount();
952 // ----------------------------------------------------------------------------
954 // ----------------------------------------------------------------------------
956 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
957 wxTreeItemId hInsertAfter
,
958 const wxString
& text
,
959 int image
, int selectedImage
,
960 wxTreeItemData
*data
)
962 TV_INSERTSTRUCT tvIns
;
963 tvIns
.hParent
= (HTREEITEM
) (WXHTREEITEM
)parent
;
964 tvIns
.hInsertAfter
= (HTREEITEM
) (WXHTREEITEM
) hInsertAfter
;
966 // this is how we insert the item as the first child: supply a NULL
968 if ( !tvIns
.hInsertAfter
)
970 tvIns
.hInsertAfter
= TVI_FIRST
;
974 if ( !text
.IsEmpty() )
977 tvIns
.item
.pszText
= (wxChar
*)text
.c_str(); // cast is ok
983 tvIns
.item
.iImage
= image
;
985 if ( selectedImage
== -1 )
987 // take the same image for selected icon if not specified
988 selectedImage
= image
;
992 if ( selectedImage
!= -1 )
994 mask
|= TVIF_SELECTEDIMAGE
;
995 tvIns
.item
.iSelectedImage
= selectedImage
;
1001 tvIns
.item
.lParam
= (LPARAM
)data
;
1004 tvIns
.item
.mask
= mask
;
1006 HTREEITEM id
= (HTREEITEM
) TreeView_InsertItem(GetHwnd(), &tvIns
);
1009 wxLogLastError("TreeView_InsertItem");
1014 // associate the application tree item with Win32 tree item handle
1015 data
->SetId((WXHTREEITEM
)id
);
1018 return wxTreeItemId((WXHTREEITEM
)id
);
1021 // for compatibility only
1022 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
1023 const wxString
& text
,
1024 int image
, int selImage
,
1027 return DoInsertItem(parent
, (WXHTREEITEM
)insertAfter
, text
,
1028 image
, selImage
, NULL
);
1031 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
1032 int image
, int selectedImage
,
1033 wxTreeItemData
*data
)
1035 return DoInsertItem(wxTreeItemId((WXHTREEITEM
) 0), (WXHTREEITEM
) 0,
1036 text
, image
, selectedImage
, data
);
1039 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1040 const wxString
& text
,
1041 int image
, int selectedImage
,
1042 wxTreeItemData
*data
)
1044 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_FIRST
,
1045 text
, image
, selectedImage
, data
);
1048 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
1049 const wxTreeItemId
& idPrevious
,
1050 const wxString
& text
,
1051 int image
, int selectedImage
,
1052 wxTreeItemData
*data
)
1054 return DoInsertItem(parent
, idPrevious
, text
, image
, selectedImage
, data
);
1057 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
1058 const wxString
& text
,
1059 int image
, int selectedImage
,
1060 wxTreeItemData
*data
)
1062 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_LAST
,
1063 text
, image
, selectedImage
, data
);
1066 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
1068 if ( !TreeView_DeleteItem(GetHwnd(), (HTREEITEM
)(WXHTREEITEM
)item
) )
1070 wxLogLastError("TreeView_DeleteItem");
1074 // delete all children (but don't delete the item itself)
1075 void wxTreeCtrl::DeleteChildren(const wxTreeItemId
& item
)
1079 wxArrayLong children
;
1080 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1081 while ( child
.IsOk() )
1083 children
.Add((long)(WXHTREEITEM
)child
);
1085 child
= GetNextChild(item
, cookie
);
1088 size_t nCount
= children
.Count();
1089 for ( size_t n
= 0; n
< nCount
; n
++ )
1091 if ( !TreeView_DeleteItem(GetHwnd(), (HTREEITEM
)children
[n
]) )
1093 wxLogLastError("TreeView_DeleteItem");
1098 void wxTreeCtrl::DeleteAllItems()
1100 if ( !TreeView_DeleteAllItems(GetHwnd()) )
1102 wxLogLastError("TreeView_DeleteAllItems");
1106 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
1108 wxASSERT_MSG( flag
== TVE_COLLAPSE
||
1109 flag
== (TVE_COLLAPSE
| TVE_COLLAPSERESET
) ||
1110 flag
== TVE_EXPAND
||
1112 wxT("Unknown flag in wxTreeCtrl::DoExpand") );
1114 // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
1115 // emulate them. This behaviour has changed slightly with comctl32.dll
1116 // v 4.70 - now it does send them but only the first time. To maintain
1117 // compatible behaviour and also in order to not have surprises with the
1118 // future versions, don't rely on this and still do everything ourselves.
1119 // To avoid that the messages be sent twice when the item is expanded for
1120 // the first time we must clear TVIS_EXPANDEDONCE style manually.
1122 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDEDONCE
);
1126 if ( TreeView_Expand(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
, flag
) != 0 )
1128 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
1129 event
.m_item
= item
;
1131 bool isExpanded
= IsExpanded(item
);
1133 event
.SetEventObject(this);
1135 // FIXME return value of {EXPAND|COLLAPS}ING event handler is discarded
1136 event
.SetEventType(g_events
[isExpanded
][TRUE
]);
1137 GetEventHandler()->ProcessEvent(event
);
1139 event
.SetEventType(g_events
[isExpanded
][FALSE
]);
1140 GetEventHandler()->ProcessEvent(event
);
1142 //else: change didn't took place, so do nothing at all
1145 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
1147 DoExpand(item
, TVE_EXPAND
);
1150 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
1152 DoExpand(item
, TVE_COLLAPSE
);
1155 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1157 DoExpand(item
, TVE_COLLAPSE
| TVE_COLLAPSERESET
);
1160 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
1162 DoExpand(item
, TVE_TOGGLE
);
1165 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
)
1167 DoExpand(item
, action
);
1170 void wxTreeCtrl::Unselect()
1172 wxASSERT_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), wxT("doesn't make sense") );
1174 // just remove the selection
1175 SelectItem(wxTreeItemId((WXHTREEITEM
) 0));
1178 void wxTreeCtrl::UnselectAll()
1180 if ( m_windowStyle
& wxTR_MULTIPLE
)
1182 wxArrayTreeItemIds selections
;
1183 size_t count
= GetSelections(selections
);
1184 for ( size_t n
= 0; n
< count
; n
++ )
1186 SetItemCheck(selections
[n
], FALSE
);
1191 // just remove the selection
1196 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
)
1198 if ( m_windowStyle
& wxTR_MULTIPLE
)
1200 // selecting the item means checking it
1205 // inspite of the docs (MSDN Jan 99 edition), we don't seem to receive
1206 // the notification from the control (i.e. TVN_SELCHANG{ED|ING}), so
1207 // send them ourselves
1209 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
1210 event
.m_item
= item
;
1211 event
.SetEventObject(this);
1213 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGING
);
1214 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
1216 if ( !TreeView_SelectItem(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
) )
1218 wxLogLastError("TreeView_SelectItem");
1222 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1223 (void)GetEventHandler()->ProcessEvent(event
);
1226 //else: program vetoed the change
1230 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1233 TreeView_EnsureVisible(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
);
1236 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
1238 if ( !TreeView_SelectSetFirstVisible(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
) )
1240 wxLogLastError("TreeView_SelectSetFirstVisible");
1244 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
1249 void wxTreeCtrl::DeleteTextCtrl()
1253 m_textCtrl
->UnsubclassWin();
1254 m_textCtrl
->SetHWND(0);
1260 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
1261 wxClassInfo
* textControlClass
)
1263 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
1265 HWND hWnd
= (HWND
) TreeView_EditLabel(GetHwnd(), (HTREEITEM
) (WXHTREEITEM
) item
);
1267 // this is not an error - the TVN_BEGINLABELEDIT handler might have
1276 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
1277 m_textCtrl
->SetHWND((WXHWND
)hWnd
);
1278 m_textCtrl
->SubclassWin((WXHWND
)hWnd
);
1283 // End label editing, optionally cancelling the edit
1284 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
)
1286 TreeView_EndEditLabelNow(GetHwnd(), discardChanges
);
1291 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
1293 TV_HITTESTINFO hitTestInfo
;
1294 hitTestInfo
.pt
.x
= (int)point
.x
;
1295 hitTestInfo
.pt
.y
= (int)point
.y
;
1297 TreeView_HitTest(GetHwnd(), &hitTestInfo
);
1302 #define TRANSLATE_FLAG(flag) if ( hitTestInfo.flags & TVHT_##flag ) \
1303 flags |= wxTREE_HITTEST_##flag
1305 TRANSLATE_FLAG(ABOVE
);
1306 TRANSLATE_FLAG(BELOW
);
1307 TRANSLATE_FLAG(NOWHERE
);
1308 TRANSLATE_FLAG(ONITEMBUTTON
);
1309 TRANSLATE_FLAG(ONITEMICON
);
1310 TRANSLATE_FLAG(ONITEMINDENT
);
1311 TRANSLATE_FLAG(ONITEMLABEL
);
1312 TRANSLATE_FLAG(ONITEMRIGHT
);
1313 TRANSLATE_FLAG(ONITEMSTATEICON
);
1314 TRANSLATE_FLAG(TOLEFT
);
1315 TRANSLATE_FLAG(TORIGHT
);
1317 #undef TRANSLATE_FLAG
1319 return wxTreeItemId((WXHTREEITEM
) hitTestInfo
.hItem
);
1322 bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
1324 bool textOnly
) const
1327 if ( TreeView_GetItemRect(GetHwnd(), (HTREEITEM
)(WXHTREEITEM
)item
,
1330 rect
= wxRect(wxPoint(rc
.left
, rc
.top
), wxPoint(rc
.right
, rc
.bottom
));
1336 // couldn't retrieve rect: for example, item isn't visible
1341 // ----------------------------------------------------------------------------
1343 // ----------------------------------------------------------------------------
1345 static int CALLBACK
TreeView_CompareCallback(wxTreeItemData
*pItem1
,
1346 wxTreeItemData
*pItem2
,
1349 wxCHECK_MSG( pItem1
&& pItem2
, 0,
1350 wxT("sorting tree without data doesn't make sense") );
1352 return tree
->OnCompareItems(pItem1
->GetId(), pItem2
->GetId());
1355 int wxTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1356 const wxTreeItemId
& item2
)
1358 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1361 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
)
1363 // rely on the fact that TreeView_SortChildren does the same thing as our
1364 // default behaviour, i.e. sorts items alphabetically and so call it
1365 // directly if we're not in derived class (much more efficient!)
1366 if ( GetClassInfo() == CLASSINFO(wxTreeCtrl
) )
1368 TreeView_SortChildren(GetHwnd(), (HTREEITEM
)(WXHTREEITEM
)item
, 0);
1373 tvSort
.hParent
= (HTREEITEM
)(WXHTREEITEM
)item
;
1374 tvSort
.lpfnCompare
= (PFNTVCOMPARE
)TreeView_CompareCallback
;
1375 tvSort
.lParam
= (LPARAM
)this;
1376 TreeView_SortChildrenCB(GetHwnd(), &tvSort
, 0 /* reserved */);
1380 // ----------------------------------------------------------------------------
1382 // ----------------------------------------------------------------------------
1384 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1386 if ( cmd
== EN_UPDATE
)
1388 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1389 event
.SetEventObject( this );
1390 ProcessCommand(event
);
1392 else if ( cmd
== EN_KILLFOCUS
)
1394 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1395 event
.SetEventObject( this );
1396 ProcessCommand(event
);
1404 // command processed
1408 // process WM_NOTIFY Windows message
1409 bool wxTreeCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1411 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
1412 wxEventType eventType
= wxEVT_NULL
;
1413 NMHDR
*hdr
= (NMHDR
*)lParam
;
1415 switch ( hdr
->code
)
1419 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1422 TV_HITTESTINFO tvhti
;
1423 ::GetCursorPos(&(tvhti
.pt
));
1424 ::ScreenToClient(GetHwnd(),&(tvhti
.pt
));
1425 if ( TreeView_HitTest(GetHwnd(),&tvhti
) )
1427 if( tvhti
.flags
& TVHT_ONITEM
)
1429 event
.m_item
= (WXHTREEITEM
) tvhti
.hItem
;
1430 eventType
= wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
;
1437 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
1440 case TVN_BEGINRDRAG
:
1442 if ( eventType
== wxEVT_NULL
)
1443 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
1444 //else: left drag, already set above
1446 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
1448 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
1449 event
.m_pointDrag
= wxPoint(tv
->ptDrag
.x
, tv
->ptDrag
.y
);
1453 case TVN_BEGINLABELEDIT
:
1455 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
1456 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
1458 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
1459 event
.m_label
= info
->item
.pszText
;
1463 case TVN_DELETEITEM
:
1465 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
1466 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
1468 event
.m_item
= (WXHTREEITEM
)tv
->itemOld
.hItem
;
1472 delete (wxTreeItemAttr
*)m_attrs
.
1473 Delete((long)tv
->itemOld
.hItem
);
1478 case TVN_ENDLABELEDIT
:
1480 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
1481 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
1483 event
.m_item
= (WXHTREEITEM
)info
->item
.hItem
;
1484 event
.m_label
= info
->item
.pszText
;
1485 if (info
->item
.pszText
== NULL
)
1490 case TVN_GETDISPINFO
:
1491 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
1494 case TVN_SETDISPINFO
:
1496 if ( eventType
== wxEVT_NULL
)
1497 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
1498 //else: get, already set above
1500 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
1502 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
1506 case TVN_ITEMEXPANDING
:
1507 event
.m_code
= FALSE
;
1510 case TVN_ITEMEXPANDED
:
1512 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
1514 bool expand
= FALSE
;
1515 switch ( tv
->action
)
1526 wxLogDebug(wxT("unexpected code %d in TVN_ITEMEXPAND "
1527 "message"), tv
->action
);
1530 bool ing
= ((int)hdr
->code
== TVN_ITEMEXPANDING
);
1531 eventType
= g_events
[expand
][ing
];
1533 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
1539 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
1540 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
1542 event
.m_code
= wxCharCodeMSWToWX(info
->wVKey
);
1544 // a separate event for this case
1545 if ( info
->wVKey
== VK_SPACE
|| info
->wVKey
== VK_RETURN
)
1547 wxTreeEvent
event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
1549 event2
.SetEventObject(this);
1551 GetEventHandler()->ProcessEvent(event2
);
1556 case TVN_SELCHANGED
:
1557 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
1560 case TVN_SELCHANGING
:
1562 if ( eventType
== wxEVT_NULL
)
1563 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
1564 //else: already set above
1566 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
1568 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
1569 event
.m_itemOld
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
1573 #ifdef NM_CUSTOMDRAW
1576 LPNMTVCUSTOMDRAW lptvcd
= (LPNMTVCUSTOMDRAW
)lParam
;
1577 NMCUSTOMDRAW
& nmcd
= lptvcd
->nmcd
;
1578 switch( nmcd
.dwDrawStage
)
1581 // if we've got any items with non standard attributes,
1582 // notify us before painting each item
1583 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1587 case CDDS_ITEMPREPAINT
:
1589 wxTreeItemAttr
*attr
=
1590 (wxTreeItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1594 // nothing to do for this item
1595 return CDRF_DODEFAULT
;
1599 wxColour colText
, colBack
;
1600 if ( attr
->HasFont() )
1602 wxFont font
= attr
->GetFont();
1603 hFont
= (HFONT
)font
.GetResourceHandle();
1610 if ( attr
->HasTextColour() )
1612 colText
= attr
->GetTextColour();
1616 colText
= GetForegroundColour();
1619 // selection colours should override ours
1620 if ( nmcd
.uItemState
& CDIS_SELECTED
)
1622 DWORD clrBk
= ::GetSysColor(COLOR_HIGHLIGHT
);
1623 lptvcd
->clrTextBk
= clrBk
;
1625 // try to make the text visible
1626 lptvcd
->clrText
= wxColourToRGB(colText
);
1627 lptvcd
->clrText
|= ~clrBk
;
1628 lptvcd
->clrText
&= 0x00ffffff;
1632 if ( attr
->HasBackgroundColour() )
1634 colBack
= attr
->GetBackgroundColour();
1638 colBack
= GetBackgroundColour();
1641 lptvcd
->clrText
= wxColourToRGB(colText
);
1642 lptvcd
->clrTextBk
= wxColourToRGB(colBack
);
1645 // note that if we wanted to set colours for
1646 // individual columns (subitems), we would have
1647 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1650 ::SelectObject(nmcd
.hdc
, hFont
);
1652 *result
= CDRF_NEWFONT
;
1656 *result
= CDRF_DODEFAULT
;
1663 *result
= CDRF_DODEFAULT
;
1668 #endif // NM_CUSTOMDRAW
1671 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1674 event
.SetEventObject(this);
1675 event
.SetEventType(eventType
);
1677 bool processed
= GetEventHandler()->ProcessEvent(event
);
1680 switch ( hdr
->code
)
1682 case TVN_DELETEITEM
:
1684 // NB: we might process this message using wxWindows event
1685 // tables, but due to overhead of wxWin event system we
1686 // prefer to do it here ourself (otherwise deleting a tree
1687 // with many items is just too slow)
1688 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
1690 wxTreeItemId item
= event
.m_item
;
1691 if ( HasIndirectData(item
) )
1693 wxTreeItemIndirectData
*data
= (wxTreeItemIndirectData
*)
1695 delete data
; // can't be NULL here
1697 m_itemsWithIndirectData
.Remove(item
);
1701 wxTreeItemData
*data
= (wxTreeItemData
*)tv
->itemOld
.lParam
;
1702 delete data
; // may be NULL, ok
1705 processed
= TRUE
; // Make sure we don't get called twice
1709 case TVN_BEGINLABELEDIT
:
1710 // return TRUE to cancel label editing
1711 *result
= !event
.IsAllowed();
1714 case TVN_ENDLABELEDIT
:
1715 // return TRUE to set the label to the new string
1716 *result
= event
.IsAllowed();
1718 // ensure that we don't have the text ctrl which is going to be
1723 case TVN_SELCHANGING
:
1724 case TVN_ITEMEXPANDING
:
1725 // return TRUE to prevent the action from happening
1726 *result
= !event
.IsAllowed();
1729 case TVN_GETDISPINFO
:
1730 // NB: so far the user can't set the image himself anyhow, so do it
1731 // anyway - but this may change later
1732 if ( /* !processed && */ 1 )
1734 wxTreeItemId item
= event
.m_item
;
1735 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
1736 if ( info
->item
.mask
& TVIF_IMAGE
)
1739 DoGetItemImageFromData
1742 IsExpanded(item
) ? wxTreeItemIcon_Expanded
1743 : wxTreeItemIcon_Normal
1746 if ( info
->item
.mask
& TVIF_SELECTEDIMAGE
)
1748 info
->item
.iSelectedImage
=
1749 DoGetItemImageFromData
1752 IsExpanded(item
) ? wxTreeItemIcon_SelectedExpanded
1753 : wxTreeItemIcon_Selected
1760 // for the other messages the return value is ignored and there is
1761 // nothing special to do
1767 // ----------------------------------------------------------------------------
1769 // ----------------------------------------------------------------------------
1771 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxNotifyEvent
)
1773 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
)
1774 : wxNotifyEvent(commandType
, id
)