1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base wxTreeCtrl classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Robert Roebling, Julian Smart et al
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // =============================================================================
14 // =============================================================================
16 // -----------------------------------------------------------------------------
18 // -----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/treectrl.h"
30 #include "wx/imaglist.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_DRAG
)
37 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_RDRAG
)
38 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
)
39 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_LABEL_EDIT
)
40 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_DELETE_ITEM
)
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_GET_INFO
)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SET_INFO
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDED
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDING
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGED
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGING
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_KEY_DOWN
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MENU
)
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxNotifyEvent
)
65 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
)
66 : wxNotifyEvent(commandType
, id
)
69 m_editCancelled
= false;
72 wxTreeEvent::wxTreeEvent(const wxTreeEvent
& event
)
73 : wxNotifyEvent(event
)
75 m_evtKey
= event
.m_evtKey
;
76 m_item
= event
.m_item
;
77 m_itemOld
= event
.m_itemOld
;
78 m_pointDrag
= event
.m_pointDrag
;
79 m_label
= event
.m_label
;
80 m_editCancelled
= event
.m_editCancelled
;
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 wxTreeCtrlBase::~wxTreeCtrlBase()
89 if (m_ownsImageListNormal
)
90 delete m_imageListNormal
;
91 if (m_ownsImageListState
)
92 delete m_imageListState
;
95 static void wxGetBestTreeSize(const wxTreeCtrlBase
* treeCtrl
, const wxTreeItemId
& id
, wxSize
& size
)
99 if ( treeCtrl
->GetBoundingRect(id
, rect
, true) )
101 if ( size
.x
< rect
.x
+ rect
.width
)
102 size
.x
= rect
.x
+ rect
.width
;
103 if ( size
.y
< rect
.y
+ rect
.height
)
104 size
.y
= rect
.y
+ rect
.height
;
107 wxTreeItemIdValue cookie
;
108 for ( wxTreeItemId item
= treeCtrl
->GetFirstChild(id
, cookie
);
110 item
= treeCtrl
->GetNextChild(item
, cookie
) )
112 wxGetBestTreeSize(treeCtrl
, item
, size
);
116 wxSize
wxTreeCtrlBase::DoGetBestSize() const
120 // this doesn't really compute the total bounding rectangle of all items
121 // but a not too bad guess of it which has the advantage of not having to
122 // examine all (potentially hundreds or thousands) items in the control
124 if (GetQuickBestSize())
126 for ( wxTreeItemId item
= GetRootItem();
128 item
= GetLastChild(item
) )
132 // last parameter is "true" to get only the dimensions of the text
133 // label, we don't want to get the entire item width as it's determined
134 // by the current size
135 if ( GetBoundingRect(item
, rect
, true) )
137 if ( size
.x
< rect
.x
+ rect
.width
)
138 size
.x
= rect
.x
+ rect
.width
;
139 if ( size
.y
< rect
.y
+ rect
.height
)
140 size
.y
= rect
.y
+ rect
.height
;
145 wxGetBestTreeSize(this, GetRootItem(), size
);
147 // need some minimal size even for empty tree
148 if ( !size
.x
|| !size
.y
)
149 size
= wxControl::DoGetBestSize();
156 #endif // wxUSE_TREECTRL