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"
34 #if defined(__WIN95__)
37 #include "wx/imaglist.h"
39 #include "wx/msw/private.h"
57 #include "wx/treectrl.h"
59 // Bug in headers, sometimes
61 #define TVIS_FOCUSED 0x0001
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // a convenient wrapper around TV_ITEM struct which adds a ctor
69 struct wxTreeViewItem
: public TV_ITEM
71 wxTreeViewItem(const wxTreeItemId
& item
,
72 UINT mask_
, UINT stateMask_
= 0)
75 stateMask
= stateMask_
;
76 hItem
= (HTREEITEM
) (WXHTREEITEM
) item
;
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 #if !USE_SHARED_LIBRARY
85 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
88 // hide the ugly cast (of course, the macro is _quite_ ugly too...)
89 #define wxhWnd ((HWND)m_hWnd)
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 // handy table for sending events
96 static const wxEventType g_events
[2][2] =
98 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, wxEVT_COMMAND_TREE_ITEM_COLLAPSING
},
99 { wxEVT_COMMAND_TREE_ITEM_EXPANDED
, wxEVT_COMMAND_TREE_ITEM_EXPANDING
}
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
107 // construction and destruction
108 // ----------------------------------------------------------------------------
110 void wxTreeCtrl::Init()
112 m_imageListNormal
= NULL
;
113 m_imageListState
= NULL
;
117 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
118 const wxPoint
& pos
, const wxSize
& size
,
119 long style
, const wxValidator
& validator
,
120 const wxString
& name
)
124 wxSystemSettings settings
;
127 SetValidator(validator
);
129 m_windowStyle
= style
;
133 m_windowId
= (id
== -1) ? NewControlId() : id
;
135 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| TVS_HASLINES
;
138 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
140 // Even with extended styles, need to combine with WS_BORDER
141 // for them to look right.
142 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
147 if ( m_windowStyle
& wxTR_HAS_BUTTONS
)
148 wstyle
|= TVS_HASBUTTONS
;
150 if ( m_windowStyle
& wxTR_EDIT_LABELS
)
151 wstyle
|= TVS_EDITLABELS
;
153 if ( m_windowStyle
& wxTR_LINES_AT_ROOT
)
154 wstyle
|= TVS_LINESATROOT
;
156 // Create the tree control.
157 m_hWnd
= (WXHWND
)::CreateWindowEx
163 pos
.x
, pos
.y
, size
.x
, size
.y
,
164 (HWND
)parent
->GetHWND(),
170 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create tree ctrl" );
173 parent
->AddChild(this);
180 wxTreeCtrl::~wxTreeCtrl()
184 // delete user data to prevent memory leaks
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
192 // simple wrappers which add error checking in debug mode
194 bool wxTreeCtrl::DoGetItem(wxTreeViewItem
* tvItem
) const
196 if ( !TreeView_GetItem(wxhWnd
, tvItem
) )
198 wxLogLastError("TreeView_GetItem");
206 void wxTreeCtrl::DoSetItem(wxTreeViewItem
* tvItem
)
208 if ( TreeView_SetItem(wxhWnd
, tvItem
) == -1 )
210 wxLogLastError("TreeView_SetItem");
214 size_t wxTreeCtrl::GetCount() const
216 return (size_t)TreeView_GetCount(wxhWnd
);
219 unsigned int wxTreeCtrl::GetIndent() const
221 return TreeView_GetIndent(wxhWnd
);
224 void wxTreeCtrl::SetIndent(unsigned int indent
)
226 TreeView_SetIndent(wxhWnd
, indent
);
229 wxImageList
*wxTreeCtrl::GetImageList() const
231 return m_imageListNormal
;
234 wxImageList
*wxTreeCtrl::GetStateImageList() const
236 return m_imageListNormal
;
239 void wxTreeCtrl::SetAnyImageList(wxImageList
*imageList
, int which
)
242 TreeView_SetImageList(wxhWnd
,
243 imageList
? imageList
->GetHIMAGELIST() : 0,
247 void wxTreeCtrl::SetImageList(wxImageList
*imageList
)
249 SetAnyImageList(m_imageListNormal
= imageList
, TVSIL_NORMAL
);
252 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
)
254 SetAnyImageList(m_imageListState
= imageList
, TVSIL_STATE
);
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
263 char buf
[512]; // the size is arbitrary...
265 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
266 tvItem
.pszText
= buf
;
267 tvItem
.cchTextMax
= WXSIZEOF(buf
);
268 if ( !DoGetItem(&tvItem
) )
270 // don't return some garbage which was on stack, but an empty string
274 return wxString(buf
);
277 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
279 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
280 tvItem
.pszText
= (char *)text
.c_str(); // conversion is ok
284 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const
286 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
289 return tvItem
.iImage
;
292 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
)
294 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
295 tvItem
.iImage
= image
;
299 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const
301 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
304 return tvItem
.iSelectedImage
;
307 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
309 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
310 tvItem
.iSelectedImage
= image
;
314 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
316 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
317 if ( !DoGetItem(&tvItem
) )
322 return (wxTreeItemData
*)tvItem
.lParam
;
325 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
327 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
328 tvItem
.lParam
= (LPARAM
)data
;
332 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
334 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
335 tvItem
.cChildren
= (int)has
;
339 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
343 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
346 // return (TreeView_GetItemRect(wxhWnd, (HTREEITEM) (WXHTREEITEM)item, &rect, FALSE) != 0);
347 // Bug in Gnu-Win32 headers, so don't use the macro.
348 return (SendMessage((wxhWnd
), TVM_GETITEMRECT
, (WPARAM
) FALSE
, (LPARAM
) & rect
) != 0);
352 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
354 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
357 return tvItem
.cChildren
!= 0;
360 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
362 // probably not a good idea to put it here
363 //wxASSERT( ItemHasChildren(item) );
365 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDED
);
368 return (tvItem
.state
& TVIS_EXPANDED
) != 0;
371 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
373 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_SELECTED
);
376 return (tvItem
.state
& TVIS_SELECTED
) != 0;
379 // ----------------------------------------------------------------------------
381 // ----------------------------------------------------------------------------
383 wxTreeItemId
wxTreeCtrl::GetRootItem() const
385 return wxTreeItemId((WXHTREEITEM
) TreeView_GetRoot(wxhWnd
));
388 wxTreeItemId
wxTreeCtrl::GetSelection() const
390 return wxTreeItemId((WXHTREEITEM
) TreeView_GetSelection(wxhWnd
));
393 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const
395 return wxTreeItemId((WXHTREEITEM
) TreeView_GetParent(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
398 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
401 // remember the last child returned in 'cookie'
402 _cookie
= (long)TreeView_GetChild(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
)item
);
404 return wxTreeItemId((WXHTREEITEM
)_cookie
);
407 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
410 wxTreeItemId l
=wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(wxhWnd
,
411 (HTREEITEM
) (WXHTREEITEM
)_cookie
));
416 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
418 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
421 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
423 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
426 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
428 return wxTreeItemId((WXHTREEITEM
) TreeView_GetFirstVisible(wxhWnd
));
431 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
433 wxASSERT_MSG( IsVisible(item
), "The item you call GetNextVisible() "
434 "for must be visible itself!");
436 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
439 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
441 wxASSERT_MSG( IsVisible(item
), "The item you call GetPrevVisible() "
442 "for must be visible itself!");
444 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
447 // ----------------------------------------------------------------------------
449 // ----------------------------------------------------------------------------
451 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
452 wxTreeItemId hInsertAfter
,
453 const wxString
& text
,
454 int image
, int selectedImage
,
455 wxTreeItemData
*data
)
457 TV_INSERTSTRUCT tvIns
;
458 tvIns
.hParent
= (HTREEITEM
) (WXHTREEITEM
)parent
;
459 tvIns
.hInsertAfter
= (HTREEITEM
) (WXHTREEITEM
) hInsertAfter
;
461 if ( !text
.IsEmpty() )
464 tvIns
.item
.pszText
= (char *)text
.c_str(); // cast is ok
470 tvIns
.item
.iImage
= image
;
472 if ( selectedImage
== -1 )
474 // take the same image for selected icon if not specified
475 selectedImage
= image
;
479 if ( selectedImage
!= -1 )
481 mask
|= TVIF_SELECTEDIMAGE
;
482 tvIns
.item
.iSelectedImage
= selectedImage
;
488 tvIns
.item
.lParam
= (LPARAM
)data
;
491 tvIns
.item
.mask
= mask
;
493 HTREEITEM id
= (HTREEITEM
) TreeView_InsertItem(wxhWnd
, &tvIns
);
496 wxLogLastError("TreeView_InsertItem");
499 return wxTreeItemId((WXHTREEITEM
)id
);
502 // for compatibility only
503 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
504 const wxString
& text
,
505 int image
, int selImage
,
508 return DoInsertItem(parent
, (WXHTREEITEM
)insertAfter
, text
,
509 image
, selImage
, NULL
);
512 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
513 int image
, int selectedImage
,
514 wxTreeItemData
*data
)
516 return DoInsertItem(wxTreeItemId((WXHTREEITEM
) 0), (WXHTREEITEM
) 0,
517 text
, image
, selectedImage
, data
);
520 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
521 const wxString
& text
,
522 int image
, int selectedImage
,
523 wxTreeItemData
*data
)
525 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_FIRST
,
526 text
, image
, selectedImage
, data
);
529 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
530 const wxTreeItemId
& idPrevious
,
531 const wxString
& text
,
532 int image
, int selectedImage
,
533 wxTreeItemData
*data
)
535 return DoInsertItem(parent
, idPrevious
, text
, image
, selectedImage
, data
);
538 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
539 const wxString
& text
,
540 int image
, int selectedImage
,
541 wxTreeItemData
*data
)
543 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_LAST
,
544 text
, image
, selectedImage
, data
);
547 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
549 wxTreeItemData
*data
= GetItemData(item
);
551 delete data
; // may be NULL, ok
553 if ( !TreeView_DeleteItem(wxhWnd
, (HTREEITEM
)(WXHTREEITEM
)item
) )
555 wxLogLastError("TreeView_DeleteItem");
559 void wxTreeCtrl::DeleteAllItems()
561 if ( !TreeView_DeleteAllItems(wxhWnd
) )
563 wxLogLastError("TreeView_DeleteAllItems");
567 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
569 wxASSERT_MSG( flag
== TVE_COLLAPSE
|| flag
== TVE_COLLAPSERESET
||
570 flag
== TVE_EXPAND
|| flag
== TVE_TOGGLE
,
571 "Unknown flag in wxTreeCtrl::DoExpand" );
573 // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
575 if ( TreeView_Expand(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
, flag
) != 0 )
577 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
580 bool isExpanded
= IsExpanded(item
);
582 event
.SetEventObject(this);
584 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
585 event
.SetEventType(g_events
[isExpanded
][TRUE
]);
586 GetEventHandler()->ProcessEvent(event
);
588 event
.SetEventType(g_events
[isExpanded
][FALSE
]);
589 GetEventHandler()->ProcessEvent(event
);
593 // I wonder if it really ever happens...
594 wxLogDebug("TreeView_Expand: change didn't took place.");
598 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
600 DoExpand(item
, TVE_EXPAND
);
603 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
605 DoExpand(item
, TVE_COLLAPSE
);
608 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
610 DoExpand(item
, TVE_COLLAPSERESET
);
613 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
615 DoExpand(item
, TVE_TOGGLE
);
618 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
)
620 DoExpand(item
, action
);
623 void wxTreeCtrl::Unselect()
625 SelectItem(wxTreeItemId((WXHTREEITEM
) 0));
628 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
)
630 if ( !TreeView_SelectItem(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
632 wxLogLastError("TreeView_SelectItem");
636 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
639 TreeView_EnsureVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
642 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
644 if ( !TreeView_SelectSetFirstVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
646 wxLogLastError("TreeView_SelectSetFirstVisible");
650 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
655 void wxTreeCtrl::DeleteTextCtrl()
659 m_textCtrl
->UnsubclassWin();
660 m_textCtrl
->SetHWND(0);
666 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
667 wxClassInfo
* textControlClass
)
669 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
671 HWND hWnd
= (HWND
) TreeView_EditLabel(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
673 wxCHECK_MSG( hWnd
, NULL
, "Can't edit tree ctrl label" );
677 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
678 m_textCtrl
->SetHWND((WXHWND
)hWnd
);
679 m_textCtrl
->SubclassWin((WXHWND
)hWnd
);
684 // End label editing, optionally cancelling the edit
685 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
)
687 TreeView_EndEditLabelNow(wxhWnd
, discardChanges
);
692 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
694 TV_HITTESTINFO hitTestInfo
;
695 hitTestInfo
.pt
.x
= (int)point
.x
;
696 hitTestInfo
.pt
.y
= (int)point
.y
;
698 TreeView_HitTest(wxhWnd
, &hitTestInfo
);
703 #define TRANSLATE_FLAG(flag) if ( hitTestInfo.flags & TVHT_##flag ) \
704 flags |= wxTREE_HITTEST_##flag
706 TRANSLATE_FLAG(ABOVE
);
707 TRANSLATE_FLAG(BELOW
);
708 TRANSLATE_FLAG(NOWHERE
);
709 TRANSLATE_FLAG(ONITEMBUTTON
);
710 TRANSLATE_FLAG(ONITEMICON
);
711 TRANSLATE_FLAG(ONITEMINDENT
);
712 TRANSLATE_FLAG(ONITEMLABEL
);
713 TRANSLATE_FLAG(ONITEMRIGHT
);
714 TRANSLATE_FLAG(ONITEMSTATEICON
);
715 TRANSLATE_FLAG(TOLEFT
);
716 TRANSLATE_FLAG(TORIGHT
);
718 #undef TRANSLATE_FLAG
720 return wxTreeItemId((WXHTREEITEM
) hitTestInfo
.hItem
);
723 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
,
724 wxTreeItemCmpFunc
*cmpFunction
)
726 if ( cmpFunction
== NULL
)
728 TreeView_SortChildren(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
, 0);
732 // TODO: use TreeView_SortChildrenCB
733 wxFAIL_MSG("wxTreeCtrl::SortChildren not implemented");
737 // ----------------------------------------------------------------------------
739 // ----------------------------------------------------------------------------
741 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
743 if ( cmd
== EN_UPDATE
)
745 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
746 event
.SetEventObject( this );
747 ProcessCommand(event
);
749 else if ( cmd
== EN_KILLFOCUS
)
751 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
752 event
.SetEventObject( this );
753 ProcessCommand(event
);
765 // process WM_NOTIFY Windows message
766 bool wxTreeCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
768 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
769 wxEventType eventType
= wxEVT_NULL
;
770 NMHDR
*hdr
= (NMHDR
*)lParam
;
775 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
780 if ( eventType
== wxEVT_NULL
)
781 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
782 //else: left drag, already set above
784 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
786 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
787 event
.m_pointDrag
= wxPoint(tv
->ptDrag
.x
, tv
->ptDrag
.y
);
791 case TVN_BEGINLABELEDIT
:
793 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
794 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
796 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
802 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
803 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
805 event
.m_item
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
809 case TVN_ENDLABELEDIT
:
811 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
812 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
814 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
818 case TVN_GETDISPINFO
:
819 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
822 case TVN_SETDISPINFO
:
824 if ( eventType
== wxEVT_NULL
)
825 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
826 //else: get, already set above
828 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
830 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
834 case TVN_ITEMEXPANDING
:
835 event
.m_code
= FALSE
;
838 case TVN_ITEMEXPANDED
:
840 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
843 switch ( tv
->action
)
854 wxLogDebug("unexpected code %d in TVN_ITEMEXPAND "
855 "message", tv
->action
);
858 bool ing
= (hdr
->code
== TVN_ITEMEXPANDING
);
859 eventType
= g_events
[expand
][ing
];
861 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
867 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
868 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
870 event
.m_code
= wxCharCodeMSWToWX(info
->wVKey
);
875 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
878 case TVN_SELCHANGING
:
880 if ( eventType
== wxEVT_NULL
)
881 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
882 //else: already set above
884 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
886 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
887 event
.m_itemOld
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
892 return wxControl::MSWNotify(wParam
, lParam
);
895 event
.SetEventObject(this);
896 event
.SetEventType(eventType
);
898 bool rc
= GetEventHandler()->ProcessEvent(event
);
903 // NB: we might process this message using wxWindows event tables, but
904 // due to overhead of wxWin event system we prefer to do it here
905 // (otherwise deleting a tree with many items is just too slow)
908 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
909 wxTreeItemData
*data
= (wxTreeItemData
*)tv
->itemOld
.lParam
;
910 delete data
; // may be NULL, ok
914 case TVN_ITEMEXPANDING
:
915 // if user called Veto(), don't allow expansion/collapse by
916 // returning TRUE from here
917 rc
= event
.m_code
!= 0;
924 // ----------------------------------------------------------------------------
926 // ----------------------------------------------------------------------------
928 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
930 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
)
931 : wxCommandEvent(commandType
, id
)