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"
61 #include "wx/msw/treectrl.h"
63 // Bug in headers, sometimes
65 #define TVIS_FOCUSED 0x0001
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 // a convenient wrapper around TV_ITEM struct which adds a ctor
73 struct wxTreeViewItem
: public TV_ITEM
75 wxTreeViewItem(const wxTreeItemId
& item
,
76 UINT mask_
, UINT stateMask_
= 0)
79 stateMask
= stateMask_
;
80 hItem
= (HTREEITEM
) (WXHTREEITEM
) item
;
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 #if !USE_SHARED_LIBRARY
89 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
92 // hide the ugly cast (of course, the macro is _quite_ ugly too...)
93 #define wxhWnd ((HWND)m_hWnd)
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // handy table for sending events
100 static const wxEventType g_events
[2][2] =
102 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, wxEVT_COMMAND_TREE_ITEM_COLLAPSING
},
103 { wxEVT_COMMAND_TREE_ITEM_EXPANDED
, wxEVT_COMMAND_TREE_ITEM_EXPANDING
}
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
111 // construction and destruction
112 // ----------------------------------------------------------------------------
114 void wxTreeCtrl::Init()
116 m_imageListNormal
= NULL
;
117 m_imageListState
= NULL
;
121 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
122 const wxPoint
& pos
, const wxSize
& size
,
123 long style
, const wxValidator
& validator
,
124 const wxString
& name
)
128 wxSystemSettings settings
;
131 SetValidator(validator
);
133 m_windowStyle
= style
;
137 m_windowId
= (id
== -1) ? NewControlId() : id
;
139 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| TVS_HASLINES
;
142 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
144 // Even with extended styles, need to combine with WS_BORDER
145 // for them to look right.
146 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
151 if ( m_windowStyle
& wxTR_HAS_BUTTONS
)
152 wstyle
|= TVS_HASBUTTONS
;
154 if ( m_windowStyle
& wxTR_EDIT_LABELS
)
155 wstyle
|= TVS_EDITLABELS
;
157 if ( m_windowStyle
& wxTR_LINES_AT_ROOT
)
158 wstyle
|= TVS_LINESATROOT
;
160 // Create the tree control.
161 m_hWnd
= (WXHWND
)::CreateWindowEx
167 pos
.x
, pos
.y
, size
.x
, size
.y
,
168 (HWND
)parent
->GetHWND(),
174 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create tree ctrl" );
177 parent
->AddChild(this);
184 wxTreeCtrl::~wxTreeCtrl()
188 // delete user data to prevent memory leaks
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 // simple wrappers which add error checking in debug mode
198 bool wxTreeCtrl::DoGetItem(wxTreeViewItem
* tvItem
) const
200 if ( !TreeView_GetItem(wxhWnd
, tvItem
) )
202 wxLogLastError("TreeView_GetItem");
210 void wxTreeCtrl::DoSetItem(wxTreeViewItem
* tvItem
)
212 if ( TreeView_SetItem(wxhWnd
, tvItem
) == -1 )
214 wxLogLastError("TreeView_SetItem");
218 size_t wxTreeCtrl::GetCount() const
220 return (size_t)TreeView_GetCount(wxhWnd
);
223 unsigned int wxTreeCtrl::GetIndent() const
225 return TreeView_GetIndent(wxhWnd
);
228 void wxTreeCtrl::SetIndent(unsigned int indent
)
230 TreeView_SetIndent(wxhWnd
, indent
);
233 wxImageList
*wxTreeCtrl::GetImageList() const
235 return m_imageListNormal
;
238 wxImageList
*wxTreeCtrl::GetStateImageList() const
240 return m_imageListNormal
;
243 void wxTreeCtrl::SetAnyImageList(wxImageList
*imageList
, int which
)
246 TreeView_SetImageList(wxhWnd
,
247 imageList
? imageList
->GetHIMAGELIST() : 0,
251 void wxTreeCtrl::SetImageList(wxImageList
*imageList
)
253 SetAnyImageList(m_imageListNormal
= imageList
, TVSIL_NORMAL
);
256 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
)
258 SetAnyImageList(m_imageListState
= imageList
, TVSIL_STATE
);
261 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool recursively
)
267 wxArrayLong children
;
268 wxTreeItemId child
= GetFirstChild(item
, cookie
);
269 while ( child
.IsOk() )
274 result
+= GetChildrenCount(child
, TRUE
);
277 // add the child to the result in any case
280 child
= GetNextChild(item
, cookie
);
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
290 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
292 char buf
[512]; // the size is arbitrary...
294 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
295 tvItem
.pszText
= buf
;
296 tvItem
.cchTextMax
= WXSIZEOF(buf
);
297 if ( !DoGetItem(&tvItem
) )
299 // don't return some garbage which was on stack, but an empty string
303 return wxString(buf
);
306 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
308 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
309 tvItem
.pszText
= (char *)text
.c_str(); // conversion is ok
313 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const
315 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
318 return tvItem
.iImage
;
321 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
)
323 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
324 tvItem
.iImage
= image
;
328 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const
330 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
333 return tvItem
.iSelectedImage
;
336 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
338 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
339 tvItem
.iSelectedImage
= image
;
343 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
345 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
346 if ( !DoGetItem(&tvItem
) )
351 return (wxTreeItemData
*)tvItem
.lParam
;
354 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
356 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
357 tvItem
.lParam
= (LPARAM
)data
;
361 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
363 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
364 tvItem
.cChildren
= (int)has
;
368 void wxTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
370 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
371 tvItem
.state
= bold
? TVIS_BOLD
: 0;
375 // ----------------------------------------------------------------------------
377 // ----------------------------------------------------------------------------
379 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
381 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
383 return SendMessage(wxhWnd
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)&rect
) != 0;
387 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
389 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
392 return tvItem
.cChildren
!= 0;
395 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
397 // probably not a good idea to put it here
398 //wxASSERT( ItemHasChildren(item) );
400 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDED
);
403 return (tvItem
.state
& TVIS_EXPANDED
) != 0;
406 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
408 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_SELECTED
);
411 return (tvItem
.state
& TVIS_SELECTED
) != 0;
414 bool wxTreeCtrl::IsBold(const wxTreeItemId
& item
) const
416 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
419 return (tvItem
.state
& TVIS_BOLD
) != 0;
422 // ----------------------------------------------------------------------------
424 // ----------------------------------------------------------------------------
426 wxTreeItemId
wxTreeCtrl::GetRootItem() const
428 return wxTreeItemId((WXHTREEITEM
) TreeView_GetRoot(wxhWnd
));
431 wxTreeItemId
wxTreeCtrl::GetSelection() const
433 return wxTreeItemId((WXHTREEITEM
) TreeView_GetSelection(wxhWnd
));
436 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const
438 return wxTreeItemId((WXHTREEITEM
) TreeView_GetParent(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
441 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
444 // remember the last child returned in 'cookie'
445 _cookie
= (long)TreeView_GetChild(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
)item
);
447 return wxTreeItemId((WXHTREEITEM
)_cookie
);
450 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
453 wxTreeItemId l
= wxTreeItemId((WXHTREEITEM
)TreeView_GetNextSibling(wxhWnd
,
454 (HTREEITEM
)(WXHTREEITEM
)_cookie
));
460 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
462 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
465 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
467 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
470 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
472 return wxTreeItemId((WXHTREEITEM
) TreeView_GetFirstVisible(wxhWnd
));
475 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
477 wxASSERT_MSG( IsVisible(item
), "The item you call GetNextVisible() "
478 "for must be visible itself!");
480 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
483 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
485 wxASSERT_MSG( IsVisible(item
), "The item you call GetPrevVisible() "
486 "for must be visible itself!");
488 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
491 // ----------------------------------------------------------------------------
493 // ----------------------------------------------------------------------------
495 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
496 wxTreeItemId hInsertAfter
,
497 const wxString
& text
,
498 int image
, int selectedImage
,
499 wxTreeItemData
*data
)
501 TV_INSERTSTRUCT tvIns
;
502 tvIns
.hParent
= (HTREEITEM
) (WXHTREEITEM
)parent
;
503 tvIns
.hInsertAfter
= (HTREEITEM
) (WXHTREEITEM
) hInsertAfter
;
505 if ( !text
.IsEmpty() )
508 tvIns
.item
.pszText
= (char *)text
.c_str(); // cast is ok
514 tvIns
.item
.iImage
= image
;
516 if ( selectedImage
== -1 )
518 // take the same image for selected icon if not specified
519 selectedImage
= image
;
523 if ( selectedImage
!= -1 )
525 mask
|= TVIF_SELECTEDIMAGE
;
526 tvIns
.item
.iSelectedImage
= selectedImage
;
532 tvIns
.item
.lParam
= (LPARAM
)data
;
535 tvIns
.item
.mask
= mask
;
537 HTREEITEM id
= (HTREEITEM
) TreeView_InsertItem(wxhWnd
, &tvIns
);
540 wxLogLastError("TreeView_InsertItem");
545 // associate the application tree item with Win32 tree item handle
546 data
->SetId((WXHTREEITEM
)id
);
549 return wxTreeItemId((WXHTREEITEM
)id
);
552 // for compatibility only
553 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
554 const wxString
& text
,
555 int image
, int selImage
,
558 return DoInsertItem(parent
, (WXHTREEITEM
)insertAfter
, text
,
559 image
, selImage
, NULL
);
562 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
563 int image
, int selectedImage
,
564 wxTreeItemData
*data
)
566 return DoInsertItem(wxTreeItemId((WXHTREEITEM
) 0), (WXHTREEITEM
) 0,
567 text
, image
, selectedImage
, data
);
570 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
571 const wxString
& text
,
572 int image
, int selectedImage
,
573 wxTreeItemData
*data
)
575 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_FIRST
,
576 text
, image
, selectedImage
, data
);
579 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
580 const wxTreeItemId
& idPrevious
,
581 const wxString
& text
,
582 int image
, int selectedImage
,
583 wxTreeItemData
*data
)
585 return DoInsertItem(parent
, idPrevious
, text
, image
, selectedImage
, data
);
588 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
589 const wxString
& text
,
590 int image
, int selectedImage
,
591 wxTreeItemData
*data
)
593 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_LAST
,
594 text
, image
, selectedImage
, data
);
597 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
599 if ( !TreeView_DeleteItem(wxhWnd
, (HTREEITEM
)(WXHTREEITEM
)item
) )
601 wxLogLastError("TreeView_DeleteItem");
605 // delete all children (but don't delete the item itself)
606 void wxTreeCtrl::DeleteChildren(const wxTreeItemId
& item
)
610 wxArrayLong children
;
611 wxTreeItemId child
= GetFirstChild(item
, cookie
);
612 while ( child
.IsOk() )
614 children
.Add((long)(WXHTREEITEM
)child
);
616 child
= GetNextChild(item
, cookie
);
619 size_t nCount
= children
.Count();
620 for ( size_t n
= 0; n
< nCount
; n
++ )
622 if ( !TreeView_DeleteItem(wxhWnd
, (HTREEITEM
)children
[n
]) )
624 wxLogLastError("TreeView_DeleteItem");
629 void wxTreeCtrl::DeleteAllItems()
631 if ( !TreeView_DeleteAllItems(wxhWnd
) )
633 wxLogLastError("TreeView_DeleteAllItems");
637 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
639 wxASSERT_MSG( flag
== TVE_COLLAPSE
|| flag
== TVE_COLLAPSERESET
||
640 flag
== TVE_EXPAND
|| flag
== TVE_TOGGLE
,
641 "Unknown flag in wxTreeCtrl::DoExpand" );
643 // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
645 if ( TreeView_Expand(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
, flag
) != 0 )
647 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
650 bool isExpanded
= IsExpanded(item
);
652 event
.SetEventObject(this);
654 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
655 event
.SetEventType(g_events
[isExpanded
][TRUE
]);
656 GetEventHandler()->ProcessEvent(event
);
658 event
.SetEventType(g_events
[isExpanded
][FALSE
]);
659 GetEventHandler()->ProcessEvent(event
);
663 // I wonder if it really ever happens...
664 wxLogDebug("TreeView_Expand: change didn't took place.");
668 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
670 DoExpand(item
, TVE_EXPAND
);
673 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
675 DoExpand(item
, TVE_COLLAPSE
);
678 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
680 DoExpand(item
, TVE_COLLAPSERESET
);
683 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
685 DoExpand(item
, TVE_TOGGLE
);
688 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
)
690 DoExpand(item
, action
);
693 void wxTreeCtrl::Unselect()
695 SelectItem(wxTreeItemId((WXHTREEITEM
) 0));
698 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
)
700 if ( !TreeView_SelectItem(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
702 wxLogLastError("TreeView_SelectItem");
706 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
709 TreeView_EnsureVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
712 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
714 if ( !TreeView_SelectSetFirstVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
716 wxLogLastError("TreeView_SelectSetFirstVisible");
720 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
725 void wxTreeCtrl::DeleteTextCtrl()
729 m_textCtrl
->UnsubclassWin();
730 m_textCtrl
->SetHWND(0);
736 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
737 wxClassInfo
* textControlClass
)
739 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
741 HWND hWnd
= (HWND
) TreeView_EditLabel(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
743 wxCHECK_MSG( hWnd
, NULL
, "Can't edit tree ctrl label" );
747 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
748 m_textCtrl
->SetHWND((WXHWND
)hWnd
);
749 m_textCtrl
->SubclassWin((WXHWND
)hWnd
);
754 // End label editing, optionally cancelling the edit
755 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
)
757 TreeView_EndEditLabelNow(wxhWnd
, discardChanges
);
762 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
764 TV_HITTESTINFO hitTestInfo
;
765 hitTestInfo
.pt
.x
= (int)point
.x
;
766 hitTestInfo
.pt
.y
= (int)point
.y
;
768 TreeView_HitTest(wxhWnd
, &hitTestInfo
);
773 #define TRANSLATE_FLAG(flag) if ( hitTestInfo.flags & TVHT_##flag ) \
774 flags |= wxTREE_HITTEST_##flag
776 TRANSLATE_FLAG(ABOVE
);
777 TRANSLATE_FLAG(BELOW
);
778 TRANSLATE_FLAG(NOWHERE
);
779 TRANSLATE_FLAG(ONITEMBUTTON
);
780 TRANSLATE_FLAG(ONITEMICON
);
781 TRANSLATE_FLAG(ONITEMINDENT
);
782 TRANSLATE_FLAG(ONITEMLABEL
);
783 TRANSLATE_FLAG(ONITEMRIGHT
);
784 TRANSLATE_FLAG(ONITEMSTATEICON
);
785 TRANSLATE_FLAG(TOLEFT
);
786 TRANSLATE_FLAG(TORIGHT
);
788 #undef TRANSLATE_FLAG
790 return wxTreeItemId((WXHTREEITEM
) hitTestInfo
.hItem
);
793 // ----------------------------------------------------------------------------
795 // ----------------------------------------------------------------------------
796 static int CALLBACK
TreeView_CompareCallback(wxTreeItemData
*pItem1
,
797 wxTreeItemData
*pItem2
,
800 return tree
->OnCompareItems(pItem1
->GetId(), pItem2
->GetId());
803 int wxTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
804 const wxTreeItemId
& item2
)
806 return strcmp(GetItemText(item1
), GetItemText(item2
));
809 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
)
811 // rely on the fact that TreeView_SortChildren does the same thing as our
812 // default behaviour, i.e. sorts items alphabetically and so call it
813 // directly if we're not in derived class (much more efficient!)
814 if ( GetClassInfo() == CLASSINFO(wxTreeCtrl
) )
816 TreeView_SortChildren(wxhWnd
, (HTREEITEM
)(WXHTREEITEM
)item
, 0);
821 tvSort
.hParent
= (HTREEITEM
)(WXHTREEITEM
)item
;
822 tvSort
.lpfnCompare
= (PFNTVCOMPARE
)TreeView_CompareCallback
;
823 tvSort
.lParam
= (LPARAM
)this;
824 TreeView_SortChildrenCB(wxhWnd
, &tvSort
, 0 /* reserved */);
828 // ----------------------------------------------------------------------------
830 // ----------------------------------------------------------------------------
832 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
834 if ( cmd
== EN_UPDATE
)
836 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
837 event
.SetEventObject( this );
838 ProcessCommand(event
);
840 else if ( cmd
== EN_KILLFOCUS
)
842 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
843 event
.SetEventObject( this );
844 ProcessCommand(event
);
856 // process WM_NOTIFY Windows message
857 bool wxTreeCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
*result
)
859 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
860 wxEventType eventType
= wxEVT_NULL
;
861 NMHDR
*hdr
= (NMHDR
*)lParam
;
866 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
871 if ( eventType
== wxEVT_NULL
)
872 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
873 //else: left drag, already set above
875 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
877 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
878 event
.m_pointDrag
= wxPoint(tv
->ptDrag
.x
, tv
->ptDrag
.y
);
882 case TVN_BEGINLABELEDIT
:
884 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
885 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
887 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
893 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
894 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
896 event
.m_item
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
900 case TVN_ENDLABELEDIT
:
902 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
903 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
905 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
909 case TVN_GETDISPINFO
:
910 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
913 case TVN_SETDISPINFO
:
915 if ( eventType
== wxEVT_NULL
)
916 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
917 //else: get, already set above
919 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
921 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
925 case TVN_ITEMEXPANDING
:
926 event
.m_code
= FALSE
;
929 case TVN_ITEMEXPANDED
:
931 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
934 switch ( tv
->action
)
945 wxLogDebug("unexpected code %d in TVN_ITEMEXPAND "
946 "message", tv
->action
);
949 bool ing
= (hdr
->code
== TVN_ITEMEXPANDING
);
950 eventType
= g_events
[expand
][ing
];
952 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
958 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
959 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
961 event
.m_code
= wxCharCodeMSWToWX(info
->wVKey
);
963 // a separate event for this case
964 if ( info
->wVKey
== VK_SPACE
|| info
->wVKey
== VK_RETURN
)
966 wxTreeEvent
event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
968 event2
.SetEventObject(this);
970 GetEventHandler()->ProcessEvent(event2
);
976 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
979 case TVN_SELCHANGING
:
981 if ( eventType
== wxEVT_NULL
)
982 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
983 //else: already set above
985 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
987 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
988 event
.m_itemOld
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
993 return wxControl::MSWNotify(wParam
, lParam
, result
);
996 event
.SetEventObject(this);
997 event
.SetEventType(eventType
);
999 bool processed
= GetEventHandler()->ProcessEvent(event
);
1002 if ( hdr
->code
== TVN_DELETEITEM
)
1004 // NB: we might process this message using wxWindows event tables, but
1005 // due to overhead of wxWin event system we prefer to do it here
1006 // (otherwise deleting a tree with many items is just too slow)
1007 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
1008 wxTreeItemData
*data
= (wxTreeItemData
*)tv
->itemOld
.lParam
;
1009 delete data
; // may be NULL, ok
1012 *result
= !event
.IsAllowed();
1017 // ----------------------------------------------------------------------------
1019 // ----------------------------------------------------------------------------
1021 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxNotifyEvent
)
1023 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
)
1024 : wxNotifyEvent(commandType
, id
)