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. It's opaque for the
33 // ----------------------------------------------------------------------------
35 // Using this typedef removes an ambiguity when calling Remove()
36 typedef unsigned long wxTreeItemIdValue
;
38 class WXDLLEXPORT wxTreeItemId
40 friend class WXDLLEXPORT wxTreeCtrl
;
41 friend class WXDLLEXPORT wxGenericTreeCtrl
;
42 friend class WXDLLEXPORT wxTreeEvent
;
45 // 0 is invalid value for HTREEITEM
46 wxTreeItemId() { m_pItem
= 0; }
48 // default copy ctor/assignment operator are ok for us
51 // is this a valid tree item?
52 bool IsOk() const { return m_pItem
!= 0; }
54 // deprecated: only for compatibility
55 wxTreeItemId(long itemId
) { m_pItem
= itemId
; }
56 //operator long() const { return m_pItem; }
57 operator wxTreeItemIdValue() const { return m_pItem
; }
59 void operator=(long item
) { m_pItem
= item
; }
61 wxTreeItemId(void *pItem
) { m_pItem
= (long) pItem
; }
63 wxTreeItemIdValue m_pItem
;
66 // ----------------------------------------------------------------------------
67 // wxTreeItemData is some (arbitrary) user class associated with some item. The
68 // main advantage of having this class (compared to old untyped interface) is
69 // that wxTreeItemData's are destroyed automatically by the tree and, as this
70 // class has virtual dtor, it means that the memory will be automatically
71 // freed. OTOH, we don't just use wxObject instead of wxTreeItemData because
72 // the size of this class is critical: in any real application, each tree leaf
73 // will have wxTreeItemData associated with it and number of leaves may be
76 // Because the objects of this class are deleted by the tree, they should
77 // always be allocated on the heap!
78 // ----------------------------------------------------------------------------
80 class WXDLLEXPORT wxTreeItemData
: public wxClientData
82 friend class WXDLLEXPORT wxTreeCtrl
;
83 friend class WXDLLEXPORT wxGenericTreeCtrl
;
85 // creation/destruction
86 // --------------------
90 // default copy ctor/assignment operator are ok
92 // accessor: get the item associated with us
93 const wxTreeItemId
& GetId() const { return m_pItem
; }
94 void SetId(const wxTreeItemId
& id
) { m_pItem
= id
; }
100 WX_DEFINE_EXPORTED_ARRAY(wxTreeItemId
, wxArrayTreeItemIds
);
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 // enum for different images associated with a treectrl item
109 wxTreeItemIcon_Normal
, // not selected, not expanded
110 wxTreeItemIcon_Selected
, // selected, not expanded
111 wxTreeItemIcon_Expanded
, // not selected, expanded
112 wxTreeItemIcon_SelectedExpanded
, // selected, expanded
117 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
118 // where exactly the specified point is situated:
120 static const int wxTREE_HITTEST_ABOVE
= 0x0001;
121 static const int wxTREE_HITTEST_BELOW
= 0x0002;
122 static const int wxTREE_HITTEST_NOWHERE
= 0x0004;
123 // on the button associated with an item.
124 static const int wxTREE_HITTEST_ONITEMBUTTON
= 0x0008;
125 // on the bitmap associated with an item.
126 static const int wxTREE_HITTEST_ONITEMICON
= 0x0010;
127 // on the indent associated with an item.
128 static const int wxTREE_HITTEST_ONITEMINDENT
= 0x0020;
129 // on the label (string) associated with an item.
130 static const int wxTREE_HITTEST_ONITEMLABEL
= 0x0040;
131 // on the right of the label associated with an item.
132 static const int wxTREE_HITTEST_ONITEMRIGHT
= 0x0080;
133 // on the label (string) associated with an item.
134 static const int wxTREE_HITTEST_ONITEMSTATEICON
= 0x0100;
135 // on the left of the wxTreeCtrl.
136 static const int wxTREE_HITTEST_TOLEFT
= 0x0200;
137 // on the right of the wxTreeCtrl.
138 static const int wxTREE_HITTEST_TORIGHT
= 0x0400;
139 // on the upper part (first half) of the item.
140 static const int wxTREE_HITTEST_ONITEMUPPERPART
= 0x0800;
141 // on the lower part (second half) of the item.
142 static const int wxTREE_HITTEST_ONITEMLOWERPART
= 0x1000;
144 // anywhere on the item
145 static const int wxTREE_HITTEST_ONITEM
= wxTREE_HITTEST_ONITEMICON
|
146 wxTREE_HITTEST_ONITEMLABEL
;
148 // tree ctrl default name
149 WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr
;
151 // ----------------------------------------------------------------------------
152 // wxTreeItemAttr: a structure containing the visual attributes of an item
153 // ----------------------------------------------------------------------------
155 class WXDLLEXPORT wxTreeItemAttr
160 wxTreeItemAttr(const wxColour
& colText
,
161 const wxColour
& colBack
,
163 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
166 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
167 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
168 void SetFont(const wxFont
& font
) { m_font
= font
; }
171 bool HasTextColour() const { return m_colText
.Ok(); }
172 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
173 bool HasFont() const { return m_font
.Ok(); }
175 const wxColour
& GetTextColour() const { return m_colText
; }
176 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
177 const wxFont
& GetFont() const { return m_font
; }
185 // ----------------------------------------------------------------------------
186 // wxTreeEvent is a special class for all events associated with tree controls
188 // NB: note that not all accessors make sense for all events, see the event
189 // descriptions below
190 // ----------------------------------------------------------------------------
192 class WXDLLEXPORT wxTreeEvent
: public wxNotifyEvent
194 friend class WXDLLEXPORT wxTreeCtrl
;
195 friend class WXDLLEXPORT wxGenericTreeCtrl
;
198 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
201 // get the item on which the operation was performed or the newly
202 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
203 wxTreeItemId
GetItem() const { return m_item
; }
205 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
207 wxTreeItemId
GetOldItem() const { return m_itemOld
; }
209 // the point where the mouse was when the drag operation started (for
210 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
211 wxPoint
GetPoint() const { return m_pointDrag
; }
213 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
214 int GetCode() const { return m_code
; }
216 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
217 const wxString
& GetLabel() const { return m_label
; }
220 // we could probably save some space by using union here
227 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
230 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
232 // ----------------------------------------------------------------------------
233 // macros for handling tree control events
234 // ----------------------------------------------------------------------------
236 // GetItem() returns the item being dragged, GetPoint() the mouse coords
238 // if you call event.Allow(), the drag operation will start and a
239 // EVT_TREE_END_DRAG event will be sent when the drag is over.
240 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
241 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
243 // GetItem() is the item on which the drop occured (if any) and GetPoint() the
244 // current mouse coords
245 #define EVT_TREE_END_DRAG(id, fn) { wxEVT_COMMAND_TREE_END_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
247 // GetItem() returns the itme whose label is being edited, GetLabel() returns
248 // the current item label for BEGIN and the would be new one for END.
250 // Vetoing BEGIN event means that label editing won't happen at all,
251 // vetoing END means that the new value is discarded and the old one kept
252 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
253 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
255 // provide/update information about GetItem() item
256 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
257 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
259 // GetItem() is the item being expanded/collapsed, the "ING" versions can use
260 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
261 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
262 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
263 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
265 // GetOldItem() is the item which had the selection previously, GetItem() is
266 // the item which acquires selection
267 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
268 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
270 // GetCode() returns the key code
271 // NB: this is the only message for which GetItem() is invalid (you may get the
272 // item from GetSelection())
273 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
275 // GetItem() returns the item being deleted, the associated data (if any) will
276 // be deleted just after the return of this event handler (if any)
277 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
279 // GetItem() returns the item that was activated (double click, enter, space)
280 #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
282 // GetItem() returns the item that was clicked on
283 #define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
284 #define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
286 // #endif // wxUSE_TREECTRL