1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl base classes and types
4 // Author: Julian Smart et al
8 // Copyright: (c) 1997,1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TREEBASE_H_
13 #define _WX_TREEBASE_H_
16 #pragma interface "treebase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 // Not defined in setup.h so removing for now
26 #include "wx/control.h"
29 // ----------------------------------------------------------------------------
30 // wxTreeItemId identifies an element of the tree. In this implementation, it's
31 // just a trivial wrapper around Win32 HTREEITEM or a pointer to some private
32 // data structure in the generic version. It's opaque for the application and
33 // the only method which can be used by user code is IsOk().
34 // ----------------------------------------------------------------------------
36 // Using this typedef removes an ambiguity when calling Remove()
37 typedef unsigned long wxTreeItemIdValue
;
39 class WXDLLEXPORT wxTreeItemId
43 // 0 is invalid value for HTREEITEM
44 wxTreeItemId() { m_pItem
= 0; }
46 // this one is used in the generic version
47 wxTreeItemId(void *pItem
) { m_pItem
= (long) pItem
; }
49 // and this one under MSW
50 wxTreeItemId(long lItem
) { m_pItem
= lItem
; }
52 // default copy ctor/assignment operator are ok for us
55 // is this a valid tree item?
56 bool IsOk() const { return m_pItem
!= 0; }
58 // deprecated: only for compatibility
59 operator wxTreeItemIdValue() const { return m_pItem
; }
61 wxTreeItemIdValue m_pItem
;
64 // ----------------------------------------------------------------------------
65 // wxTreeItemData is some (arbitrary) user class associated with some item. The
66 // main advantage of having this class (compared to old untyped interface) is
67 // that wxTreeItemData's are destroyed automatically by the tree and, as this
68 // class has virtual dtor, it means that the memory will be automatically
69 // freed. OTOH, we don't just use wxObject instead of wxTreeItemData because
70 // the size of this class is critical: in any real application, each tree leaf
71 // will have wxTreeItemData associated with it and number of leaves may be
74 // Because the objects of this class are deleted by the tree, they should
75 // always be allocated on the heap!
76 // ----------------------------------------------------------------------------
78 class WXDLLEXPORT wxTreeItemData
: public wxClientData
80 friend class WXDLLEXPORT wxTreeCtrl
;
81 friend class WXDLLEXPORT wxGenericTreeCtrl
;
83 // creation/destruction
84 // --------------------
88 // default copy ctor/assignment operator are ok
90 // accessor: get the item associated with us
91 const wxTreeItemId
& GetId() const { return m_pItem
; }
92 void SetId(const wxTreeItemId
& id
) { m_pItem
= id
; }
98 WX_DEFINE_EXPORTED_ARRAY(wxTreeItemId
, wxArrayTreeItemIds
);
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 // enum for different images associated with a treectrl item
107 wxTreeItemIcon_Normal
, // not selected, not expanded
108 wxTreeItemIcon_Selected
, // selected, not expanded
109 wxTreeItemIcon_Expanded
, // not selected, expanded
110 wxTreeItemIcon_SelectedExpanded
, // selected, expanded
115 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
116 // where exactly the specified point is situated:
118 static const int wxTREE_HITTEST_ABOVE
= 0x0001;
119 static const int wxTREE_HITTEST_BELOW
= 0x0002;
120 static const int wxTREE_HITTEST_NOWHERE
= 0x0004;
121 // on the button associated with an item.
122 static const int wxTREE_HITTEST_ONITEMBUTTON
= 0x0008;
123 // on the bitmap associated with an item.
124 static const int wxTREE_HITTEST_ONITEMICON
= 0x0010;
125 // on the indent associated with an item.
126 static const int wxTREE_HITTEST_ONITEMINDENT
= 0x0020;
127 // on the label (string) associated with an item.
128 static const int wxTREE_HITTEST_ONITEMLABEL
= 0x0040;
129 // on the right of the label associated with an item.
130 static const int wxTREE_HITTEST_ONITEMRIGHT
= 0x0080;
131 // on the label (string) associated with an item.
132 static const int wxTREE_HITTEST_ONITEMSTATEICON
= 0x0100;
133 // on the left of the wxTreeCtrl.
134 static const int wxTREE_HITTEST_TOLEFT
= 0x0200;
135 // on the right of the wxTreeCtrl.
136 static const int wxTREE_HITTEST_TORIGHT
= 0x0400;
137 // on the upper part (first half) of the item.
138 static const int wxTREE_HITTEST_ONITEMUPPERPART
= 0x0800;
139 // on the lower part (second half) of the item.
140 static const int wxTREE_HITTEST_ONITEMLOWERPART
= 0x1000;
142 // anywhere on the item
143 static const int wxTREE_HITTEST_ONITEM
= wxTREE_HITTEST_ONITEMICON
|
144 wxTREE_HITTEST_ONITEMLABEL
;
146 // tree ctrl default name
147 WXDLLEXPORT_DATA(extern const wxChar
*) wxTreeCtrlNameStr
;
149 // ----------------------------------------------------------------------------
150 // wxTreeItemAttr: a structure containing the visual attributes of an item
151 // ----------------------------------------------------------------------------
153 class WXDLLEXPORT wxTreeItemAttr
158 wxTreeItemAttr(const wxColour
& colText
,
159 const wxColour
& colBack
,
161 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
164 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
165 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
166 void SetFont(const wxFont
& font
) { m_font
= font
; }
169 bool HasTextColour() const { return m_colText
.Ok(); }
170 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
171 bool HasFont() const { return m_font
.Ok(); }
173 const wxColour
& GetTextColour() const { return m_colText
; }
174 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
175 const wxFont
& GetFont() const { return m_font
; }
183 // ----------------------------------------------------------------------------
184 // wxTreeEvent is a special class for all events associated with tree controls
186 // NB: note that not all accessors make sense for all events, see the event
187 // descriptions below
188 // ----------------------------------------------------------------------------
190 class WXDLLEXPORT wxTreeEvent
: public wxNotifyEvent
192 friend class WXDLLEXPORT wxTreeCtrl
;
193 friend class WXDLLEXPORT wxGenericTreeCtrl
;
196 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
199 // get the item on which the operation was performed or the newly
200 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
201 wxTreeItemId
GetItem() const { return m_item
; }
203 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
205 wxTreeItemId
GetOldItem() const { return m_itemOld
; }
207 // the point where the mouse was when the drag operation started (for
208 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
209 wxPoint
GetPoint() const { return m_pointDrag
; }
211 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
212 int GetCode() const { return m_code
; }
214 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
215 const wxString
& GetLabel() const { return m_label
; }
218 // we could probably save some space by using union here
225 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
228 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
230 // ----------------------------------------------------------------------------
231 // tree control events and macros for handling them
232 // ----------------------------------------------------------------------------
234 BEGIN_DECLARE_EVENT_TYPES()
235 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_DRAG
, 600)
236 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_RDRAG
, 601)
237 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, 602)
238 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_LABEL_EDIT
, 603)
239 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_DELETE_ITEM
, 604)
240 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_GET_INFO
, 605)
241 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_SET_INFO
, 606)
242 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, 607)
243 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, 608)
244 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, 609)
245 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, 610)
246 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGED
, 611)
247 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGING
, 612)
248 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_KEY_DOWN
, 613)
249 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, 614)
250 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, 615)
251 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
, 616)
252 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG
, 617)
253 END_DECLARE_EVENT_TYPES()
255 // GetItem() returns the item being dragged, GetPoint() the mouse coords
257 // if you call event.Allow(), the drag operation will start and a
258 // EVT_TREE_END_DRAG event will be sent when the drag is over.
259 #define EVT_TREE_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
260 #define EVT_TREE_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
262 // GetItem() is the item on which the drop occured (if any) and GetPoint() the
263 // current mouse coords
264 #define EVT_TREE_END_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_END_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
266 // GetItem() returns the itme whose label is being edited, GetLabel() returns
267 // the current item label for BEGIN and the would be new one for END.
269 // Vetoing BEGIN event means that label editing won't happen at all,
270 // vetoing END means that the new value is discarded and the old one kept
271 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
272 #define EVT_TREE_END_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
274 // provide/update information about GetItem() item
275 #define EVT_TREE_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
276 #define EVT_TREE_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
278 // GetItem() is the item being expanded/collapsed, the "ING" versions can use
279 #define EVT_TREE_ITEM_EXPANDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
280 #define EVT_TREE_ITEM_EXPANDING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
281 #define EVT_TREE_ITEM_COLLAPSED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
282 #define EVT_TREE_ITEM_COLLAPSING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
284 // GetOldItem() is the item which had the selection previously, GetItem() is
285 // the item which acquires selection
286 #define EVT_TREE_SEL_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
287 #define EVT_TREE_SEL_CHANGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
289 // GetCode() returns the key code
290 // NB: this is the only message for which GetItem() is invalid (you may get the
291 // item from GetSelection())
292 #define EVT_TREE_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
294 // GetItem() returns the item being deleted, the associated data (if any) will
295 // be deleted just after the return of this event handler (if any)
296 #define EVT_TREE_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL ),
298 // GetItem() returns the item that was activated (double click, enter, space)
299 #define EVT_TREE_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
301 // GetItem() returns the item that was clicked on
302 #define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
303 #define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
305 // #endif // wxUSE_TREECTRL