Removed #if wxUSE_TREECTRL (not in setup0.h, and not applied consistently)
[wxWidgets.git] / include / wx / treebase.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treectrl.h
3 // Purpose: wxTreeCtrl base classes and types
4 // Author: Julian Smart et al
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997,1998 Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TREEBASE_H_
13 #define _WX_TREEBASE_H_
14
15 #ifdef __GNUG__
16 #pragma interface "treebase.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22
23 // Not defined in setup.h so removing for now
24 // #if wxUSE_TREECTRL
25
26 #include "wx/control.h"
27 #include "wx/event.h"
28
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
32 // application.
33 // ----------------------------------------------------------------------------
34
35 // Using this typedef removes an ambiguity when calling Remove()
36 typedef unsigned long wxTreeItemIdValue;
37
38 class WXDLLEXPORT wxTreeItemId
39 {
40 friend class WXDLLEXPORT wxTreeCtrl;
41 friend class WXDLLEXPORT wxGenericTreeCtrl;
42 friend class WXDLLEXPORT wxTreeEvent;
43 public:
44 // ctors
45 // 0 is invalid value for HTREEITEM
46 wxTreeItemId() { m_pItem = 0; }
47
48 // default copy ctor/assignment operator are ok for us
49
50 // accessors
51 // is this a valid tree item?
52 bool IsOk() const { return m_pItem != 0; }
53
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; }
58
59 void operator=(long item) { m_pItem = item; }
60
61 wxTreeItemId(void *pItem) { m_pItem = (long) pItem; }
62
63 wxTreeItemIdValue m_pItem;
64 };
65
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
74 // quite big.
75 //
76 // Because the objects of this class are deleted by the tree, they should
77 // always be allocated on the heap!
78 // ----------------------------------------------------------------------------
79
80 class WXDLLEXPORT wxTreeItemData: public wxClientData
81 {
82 friend class WXDLLEXPORT wxTreeCtrl;
83 friend class WXDLLEXPORT wxGenericTreeCtrl;
84 public:
85 // creation/destruction
86 // --------------------
87 // default ctor
88 wxTreeItemData() { }
89
90 // default copy ctor/assignment operator are ok
91
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; }
95
96 protected:
97 wxTreeItemId m_pItem;
98 };
99
100 WX_DEFINE_EXPORTED_ARRAY(wxTreeItemId, wxArrayTreeItemIds);
101
102 // ----------------------------------------------------------------------------
103 // constants
104 // ----------------------------------------------------------------------------
105
106 // enum for different images associated with a treectrl item
107 enum wxTreeItemIcon
108 {
109 wxTreeItemIcon_Normal, // not selected, not expanded
110 wxTreeItemIcon_Selected, // selected, not expanded
111 wxTreeItemIcon_Expanded, // not selected, expanded
112 wxTreeItemIcon_SelectedExpanded, // selected, expanded
113 wxTreeItemIcon_Max
114 };
115
116
117 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
118 // where exactly the specified point is situated:
119
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;
143
144 // anywhere on the item
145 static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON |
146 wxTREE_HITTEST_ONITEMLABEL;
147
148 // tree ctrl default name
149 WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr;
150
151 // ----------------------------------------------------------------------------
152 // wxTreeItemAttr: a structure containing the visual attributes of an item
153 // ----------------------------------------------------------------------------
154
155 class WXDLLEXPORT wxTreeItemAttr
156 {
157 public:
158 // ctors
159 wxTreeItemAttr() { }
160 wxTreeItemAttr(const wxColour& colText,
161 const wxColour& colBack,
162 const wxFont& font)
163 : m_colText(colText), m_colBack(colBack), m_font(font) { }
164
165 // setters
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; }
169
170 // accessors
171 bool HasTextColour() const { return m_colText.Ok(); }
172 bool HasBackgroundColour() const { return m_colBack.Ok(); }
173 bool HasFont() const { return m_font.Ok(); }
174
175 const wxColour& GetTextColour() const { return m_colText; }
176 const wxColour& GetBackgroundColour() const { return m_colBack; }
177 const wxFont& GetFont() const { return m_font; }
178
179 private:
180 wxColour m_colText,
181 m_colBack;
182 wxFont m_font;
183 };
184
185 // ----------------------------------------------------------------------------
186 // wxTreeEvent is a special class for all events associated with tree controls
187 //
188 // NB: note that not all accessors make sense for all events, see the event
189 // descriptions below
190 // ----------------------------------------------------------------------------
191
192 class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent
193 {
194 friend class WXDLLEXPORT wxTreeCtrl;
195 friend class WXDLLEXPORT wxGenericTreeCtrl;
196
197 public:
198 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
199
200 // accessors
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; }
204
205 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
206 // selected item
207 wxTreeItemId GetOldItem() const { return m_itemOld; }
208
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; }
212
213 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
214 int GetCode() const { return m_code; }
215
216 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
217 const wxString& GetLabel() const { return m_label; }
218
219 private:
220 // we could probably save some space by using union here
221 int m_code;
222 wxTreeItemId m_item,
223 m_itemOld;
224 wxPoint m_pointDrag;
225 wxString m_label;
226
227 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
228 };
229
230 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
231
232 // ----------------------------------------------------------------------------
233 // macros for handling tree control events
234 // ----------------------------------------------------------------------------
235
236 // GetItem() returns the item being dragged, GetPoint() the mouse coords
237 //
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 },
242
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 },
246
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.
249 //
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 },
254
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 },
258
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 },
264
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 },
269
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 },
274
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 },
278
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 },
281
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 },
285
286 // #endif // wxUSE_TREECTRL
287
288 #endif
289 // _WX_TREEBASE_H_
290
291