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/msw/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 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool recursively
)
263 wxArrayLong children
;
264 wxTreeItemId child
= GetFirstChild(item
, cookie
);
265 while ( child
.IsOk() )
270 result
+= GetChildrenCount(child
, TRUE
);
273 // add the child to the result in any case
276 child
= GetNextChild(item
, cookie
);
282 // ----------------------------------------------------------------------------
284 // ----------------------------------------------------------------------------
286 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
288 char buf
[512]; // the size is arbitrary...
290 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
291 tvItem
.pszText
= buf
;
292 tvItem
.cchTextMax
= WXSIZEOF(buf
);
293 if ( !DoGetItem(&tvItem
) )
295 // don't return some garbage which was on stack, but an empty string
299 return wxString(buf
);
302 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
304 wxTreeViewItem
tvItem(item
, TVIF_TEXT
);
305 tvItem
.pszText
= (char *)text
.c_str(); // conversion is ok
309 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const
311 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
314 return tvItem
.iImage
;
317 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
)
319 wxTreeViewItem
tvItem(item
, TVIF_IMAGE
);
320 tvItem
.iImage
= image
;
324 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const
326 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
329 return tvItem
.iSelectedImage
;
332 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
334 wxTreeViewItem
tvItem(item
, TVIF_SELECTEDIMAGE
);
335 tvItem
.iSelectedImage
= image
;
339 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
341 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
342 if ( !DoGetItem(&tvItem
) )
347 return (wxTreeItemData
*)tvItem
.lParam
;
350 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
352 wxTreeViewItem
tvItem(item
, TVIF_PARAM
);
353 tvItem
.lParam
= (LPARAM
)data
;
357 void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
359 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
360 tvItem
.cChildren
= (int)has
;
364 void wxTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
366 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
367 tvItem
.state
= bold
? TVIS_BOLD
: 0;
371 // ----------------------------------------------------------------------------
373 // ----------------------------------------------------------------------------
375 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
377 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
379 return SendMessage(wxhWnd
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)&rect
) != 0;
383 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
385 wxTreeViewItem
tvItem(item
, TVIF_CHILDREN
);
388 return tvItem
.cChildren
!= 0;
391 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
393 // probably not a good idea to put it here
394 //wxASSERT( ItemHasChildren(item) );
396 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_EXPANDED
);
399 return (tvItem
.state
& TVIS_EXPANDED
) != 0;
402 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
404 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_SELECTED
);
407 return (tvItem
.state
& TVIS_SELECTED
) != 0;
410 bool wxTreeCtrl::IsBold(const wxTreeItemId
& item
) const
412 wxTreeViewItem
tvItem(item
, TVIF_STATE
, TVIS_BOLD
);
415 return (tvItem
.state
& TVIS_BOLD
) != 0;
418 // ----------------------------------------------------------------------------
420 // ----------------------------------------------------------------------------
422 wxTreeItemId
wxTreeCtrl::GetRootItem() const
424 return wxTreeItemId((WXHTREEITEM
) TreeView_GetRoot(wxhWnd
));
427 wxTreeItemId
wxTreeCtrl::GetSelection() const
429 return wxTreeItemId((WXHTREEITEM
) TreeView_GetSelection(wxhWnd
));
432 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const
434 return wxTreeItemId((WXHTREEITEM
) TreeView_GetParent(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
437 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
440 // remember the last child returned in 'cookie'
441 _cookie
= (long)TreeView_GetChild(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
)item
);
443 return wxTreeItemId((WXHTREEITEM
)_cookie
);
446 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& WXUNUSED(item
),
449 wxTreeItemId l
= wxTreeItemId((WXHTREEITEM
)TreeView_GetNextSibling(wxhWnd
,
450 (HTREEITEM
)(WXHTREEITEM
)_cookie
));
456 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
458 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
461 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
463 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevSibling(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
466 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const
468 return wxTreeItemId((WXHTREEITEM
) TreeView_GetFirstVisible(wxhWnd
));
471 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
473 wxASSERT_MSG( IsVisible(item
), "The item you call GetNextVisible() "
474 "for must be visible itself!");
476 return wxTreeItemId((WXHTREEITEM
) TreeView_GetNextVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
479 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
481 wxASSERT_MSG( IsVisible(item
), "The item you call GetPrevVisible() "
482 "for must be visible itself!");
484 return wxTreeItemId((WXHTREEITEM
) TreeView_GetPrevVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
));
487 // ----------------------------------------------------------------------------
489 // ----------------------------------------------------------------------------
491 wxTreeItemId
wxTreeCtrl::DoInsertItem(const wxTreeItemId
& parent
,
492 wxTreeItemId hInsertAfter
,
493 const wxString
& text
,
494 int image
, int selectedImage
,
495 wxTreeItemData
*data
)
497 TV_INSERTSTRUCT tvIns
;
498 tvIns
.hParent
= (HTREEITEM
) (WXHTREEITEM
)parent
;
499 tvIns
.hInsertAfter
= (HTREEITEM
) (WXHTREEITEM
) hInsertAfter
;
501 if ( !text
.IsEmpty() )
504 tvIns
.item
.pszText
= (char *)text
.c_str(); // cast is ok
510 tvIns
.item
.iImage
= image
;
512 if ( selectedImage
== -1 )
514 // take the same image for selected icon if not specified
515 selectedImage
= image
;
519 if ( selectedImage
!= -1 )
521 mask
|= TVIF_SELECTEDIMAGE
;
522 tvIns
.item
.iSelectedImage
= selectedImage
;
528 tvIns
.item
.lParam
= (LPARAM
)data
;
531 tvIns
.item
.mask
= mask
;
533 HTREEITEM id
= (HTREEITEM
) TreeView_InsertItem(wxhWnd
, &tvIns
);
536 wxLogLastError("TreeView_InsertItem");
541 // associate the application tree item with Win32 tree item handle
542 data
->SetId((WXHTREEITEM
)id
);
545 return wxTreeItemId((WXHTREEITEM
)id
);
548 // for compatibility only
549 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
550 const wxString
& text
,
551 int image
, int selImage
,
554 return DoInsertItem(parent
, (WXHTREEITEM
)insertAfter
, text
,
555 image
, selImage
, NULL
);
558 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
,
559 int image
, int selectedImage
,
560 wxTreeItemData
*data
)
562 return DoInsertItem(wxTreeItemId((WXHTREEITEM
) 0), (WXHTREEITEM
) 0,
563 text
, image
, selectedImage
, data
);
566 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
567 const wxString
& text
,
568 int image
, int selectedImage
,
569 wxTreeItemData
*data
)
571 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_FIRST
,
572 text
, image
, selectedImage
, data
);
575 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
576 const wxTreeItemId
& idPrevious
,
577 const wxString
& text
,
578 int image
, int selectedImage
,
579 wxTreeItemData
*data
)
581 return DoInsertItem(parent
, idPrevious
, text
, image
, selectedImage
, data
);
584 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
585 const wxString
& text
,
586 int image
, int selectedImage
,
587 wxTreeItemData
*data
)
589 return DoInsertItem(parent
, (WXHTREEITEM
) TVI_LAST
,
590 text
, image
, selectedImage
, data
);
593 void wxTreeCtrl::Delete(const wxTreeItemId
& item
)
595 if ( !TreeView_DeleteItem(wxhWnd
, (HTREEITEM
)(WXHTREEITEM
)item
) )
597 wxLogLastError("TreeView_DeleteItem");
601 // delete all children (but don't delete the item itself)
602 void wxTreeCtrl::DeleteChildren(const wxTreeItemId
& item
)
606 wxArrayLong children
;
607 wxTreeItemId child
= GetFirstChild(item
, cookie
);
608 while ( child
.IsOk() )
610 children
.Add((long)(WXHTREEITEM
)child
);
612 child
= GetNextChild(item
, cookie
);
615 size_t nCount
= children
.Count();
616 for ( size_t n
= 0; n
< nCount
; n
++ )
618 if ( !TreeView_DeleteItem(wxhWnd
, (HTREEITEM
)children
[n
]) )
620 wxLogLastError("TreeView_DeleteItem");
625 void wxTreeCtrl::DeleteAllItems()
627 if ( !TreeView_DeleteAllItems(wxhWnd
) )
629 wxLogLastError("TreeView_DeleteAllItems");
633 void wxTreeCtrl::DoExpand(const wxTreeItemId
& item
, int flag
)
635 wxASSERT_MSG( flag
== TVE_COLLAPSE
|| flag
== TVE_COLLAPSERESET
||
636 flag
== TVE_EXPAND
|| flag
== TVE_TOGGLE
,
637 "Unknown flag in wxTreeCtrl::DoExpand" );
639 // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must
641 if ( TreeView_Expand(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
, flag
) != 0 )
643 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
646 bool isExpanded
= IsExpanded(item
);
648 event
.SetEventObject(this);
650 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
651 event
.SetEventType(g_events
[isExpanded
][TRUE
]);
652 GetEventHandler()->ProcessEvent(event
);
654 event
.SetEventType(g_events
[isExpanded
][FALSE
]);
655 GetEventHandler()->ProcessEvent(event
);
659 // I wonder if it really ever happens...
660 wxLogDebug("TreeView_Expand: change didn't took place.");
664 void wxTreeCtrl::Expand(const wxTreeItemId
& item
)
666 DoExpand(item
, TVE_EXPAND
);
669 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
)
671 DoExpand(item
, TVE_COLLAPSE
);
674 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
676 DoExpand(item
, TVE_COLLAPSERESET
);
679 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
)
681 DoExpand(item
, TVE_TOGGLE
);
684 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
)
686 DoExpand(item
, action
);
689 void wxTreeCtrl::Unselect()
691 SelectItem(wxTreeItemId((WXHTREEITEM
) 0));
694 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
)
696 if ( !TreeView_SelectItem(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
698 wxLogLastError("TreeView_SelectItem");
702 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
705 TreeView_EnsureVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
708 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
)
710 if ( !TreeView_SelectSetFirstVisible(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
) )
712 wxLogLastError("TreeView_SelectSetFirstVisible");
716 wxTextCtrl
* wxTreeCtrl::GetEditControl() const
721 void wxTreeCtrl::DeleteTextCtrl()
725 m_textCtrl
->UnsubclassWin();
726 m_textCtrl
->SetHWND(0);
732 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
733 wxClassInfo
* textControlClass
)
735 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
737 HWND hWnd
= (HWND
) TreeView_EditLabel(wxhWnd
, (HTREEITEM
) (WXHTREEITEM
) item
);
739 wxCHECK_MSG( hWnd
, NULL
, "Can't edit tree ctrl label" );
743 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
744 m_textCtrl
->SetHWND((WXHWND
)hWnd
);
745 m_textCtrl
->SubclassWin((WXHWND
)hWnd
);
750 // End label editing, optionally cancelling the edit
751 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
)
753 TreeView_EndEditLabelNow(wxhWnd
, discardChanges
);
758 wxTreeItemId
wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
760 TV_HITTESTINFO hitTestInfo
;
761 hitTestInfo
.pt
.x
= (int)point
.x
;
762 hitTestInfo
.pt
.y
= (int)point
.y
;
764 TreeView_HitTest(wxhWnd
, &hitTestInfo
);
769 #define TRANSLATE_FLAG(flag) if ( hitTestInfo.flags & TVHT_##flag ) \
770 flags |= wxTREE_HITTEST_##flag
772 TRANSLATE_FLAG(ABOVE
);
773 TRANSLATE_FLAG(BELOW
);
774 TRANSLATE_FLAG(NOWHERE
);
775 TRANSLATE_FLAG(ONITEMBUTTON
);
776 TRANSLATE_FLAG(ONITEMICON
);
777 TRANSLATE_FLAG(ONITEMINDENT
);
778 TRANSLATE_FLAG(ONITEMLABEL
);
779 TRANSLATE_FLAG(ONITEMRIGHT
);
780 TRANSLATE_FLAG(ONITEMSTATEICON
);
781 TRANSLATE_FLAG(TOLEFT
);
782 TRANSLATE_FLAG(TORIGHT
);
784 #undef TRANSLATE_FLAG
786 return wxTreeItemId((WXHTREEITEM
) hitTestInfo
.hItem
);
789 // ----------------------------------------------------------------------------
791 // ----------------------------------------------------------------------------
792 static int CALLBACK
TreeView_CompareCallback(wxTreeItemData
*pItem1
,
793 wxTreeItemData
*pItem2
,
796 return tree
->OnCompareItems(pItem1
->GetId(), pItem2
->GetId());
799 int wxTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
800 const wxTreeItemId
& item2
)
802 return strcmp(GetItemText(item1
), GetItemText(item2
));
805 void wxTreeCtrl::SortChildren(const wxTreeItemId
& item
)
807 // rely on the fact that TreeView_SortChildren does the same thing as our
808 // default behaviour, i.e. sorts items alphabetically and so call it
809 // directly if we're not in derived class (much more efficient!)
810 if ( GetClassInfo() == CLASSINFO(wxTreeCtrl
) )
812 TreeView_SortChildren(wxhWnd
, (HTREEITEM
)(WXHTREEITEM
)item
, 0);
817 tvSort
.hParent
= (HTREEITEM
)(WXHTREEITEM
)item
;
818 tvSort
.lpfnCompare
= (PFNTVCOMPARE
)TreeView_CompareCallback
;
819 tvSort
.lParam
= (LPARAM
)this;
820 TreeView_SortChildrenCB(wxhWnd
, &tvSort
, 0 /* reserved */);
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
828 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
830 if ( cmd
== EN_UPDATE
)
832 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
833 event
.SetEventObject( this );
834 ProcessCommand(event
);
836 else if ( cmd
== EN_KILLFOCUS
)
838 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
839 event
.SetEventObject( this );
840 ProcessCommand(event
);
852 // process WM_NOTIFY Windows message
853 bool wxTreeCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
*result
)
855 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
856 wxEventType eventType
= wxEVT_NULL
;
857 NMHDR
*hdr
= (NMHDR
*)lParam
;
862 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
867 if ( eventType
== wxEVT_NULL
)
868 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
869 //else: left drag, already set above
871 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
873 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
874 event
.m_pointDrag
= wxPoint(tv
->ptDrag
.x
, tv
->ptDrag
.y
);
878 case TVN_BEGINLABELEDIT
:
880 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
881 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
883 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
889 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
890 NM_TREEVIEW
*tv
= (NM_TREEVIEW
*)lParam
;
892 event
.m_item
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
896 case TVN_ENDLABELEDIT
:
898 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
899 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
901 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
905 case TVN_GETDISPINFO
:
906 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
909 case TVN_SETDISPINFO
:
911 if ( eventType
== wxEVT_NULL
)
912 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
913 //else: get, already set above
915 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
917 event
.m_item
= (WXHTREEITEM
) info
->item
.hItem
;
921 case TVN_ITEMEXPANDING
:
922 event
.m_code
= FALSE
;
925 case TVN_ITEMEXPANDED
:
927 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
930 switch ( tv
->action
)
941 wxLogDebug("unexpected code %d in TVN_ITEMEXPAND "
942 "message", tv
->action
);
945 bool ing
= (hdr
->code
== TVN_ITEMEXPANDING
);
946 eventType
= g_events
[expand
][ing
];
948 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
954 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
955 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
957 event
.m_code
= wxCharCodeMSWToWX(info
->wVKey
);
959 // a separate event for this case
960 if ( info
->wVKey
== VK_SPACE
|| info
->wVKey
== VK_RETURN
)
962 wxTreeEvent
event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
964 event2
.SetEventObject(this);
966 GetEventHandler()->ProcessEvent(event2
);
972 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
975 case TVN_SELCHANGING
:
977 if ( eventType
== wxEVT_NULL
)
978 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
979 //else: already set above
981 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
983 event
.m_item
= (WXHTREEITEM
) tv
->itemNew
.hItem
;
984 event
.m_itemOld
= (WXHTREEITEM
) tv
->itemOld
.hItem
;
989 return wxControl::MSWNotify(wParam
, lParam
, result
);
992 event
.SetEventObject(this);
993 event
.SetEventType(eventType
);
995 bool processed
= GetEventHandler()->ProcessEvent(event
);
998 if ( hdr
->code
== TVN_DELETEITEM
)
1000 // NB: we might process this message using wxWindows event tables, but
1001 // due to overhead of wxWin event system we prefer to do it here
1002 // (otherwise deleting a tree with many items is just too slow)
1003 NM_TREEVIEW
* tv
= (NM_TREEVIEW
*)lParam
;
1004 wxTreeItemData
*data
= (wxTreeItemData
*)tv
->itemOld
.lParam
;
1005 delete data
; // may be NULL, ok
1008 *result
= !event
.IsAllowed();
1013 // ----------------------------------------------------------------------------
1015 // ----------------------------------------------------------------------------
1017 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxNotifyEvent
)
1019 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
)
1020 : wxNotifyEvent(commandType
, id
)