]> git.saurik.com Git - wxWidgets.git/blame - include/wx/treebase.h
define this, wxSIZE_T_IS_UINT, for OS/2.
[wxWidgets.git] / include / wx / treebase.h
CommitLineData
484523cf 1/////////////////////////////////////////////////////////////////////////////
5e0e6ceb 2// Name: treebase.h
484523cf
JS
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
75212e68
JS
23// Not defined in setup.h so removing for now
24// #if wxUSE_TREECTRL
33737618 25
484523cf
JS
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
2f3dcbbf
VZ
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().
484523cf
JS
34// ----------------------------------------------------------------------------
35
36// Using this typedef removes an ambiguity when calling Remove()
37typedef unsigned long wxTreeItemIdValue;
38
39class WXDLLEXPORT wxTreeItemId
40{
484523cf
JS
41public:
42 // ctors
43 // 0 is invalid value for HTREEITEM
44 wxTreeItemId() { m_pItem = 0; }
45
2f3dcbbf
VZ
46 // this one is used in the generic version
47 wxTreeItemId(void *pItem) { m_pItem = (long) pItem; }
48
49 // and this one under MSW
50 wxTreeItemId(long lItem) { m_pItem = lItem; }
51
484523cf
JS
52 // default copy ctor/assignment operator are ok for us
53
54 // accessors
55 // is this a valid tree item?
56 bool IsOk() const { return m_pItem != 0; }
57
58 // deprecated: only for compatibility
484523cf
JS
59 operator wxTreeItemIdValue() const { return m_pItem; }
60
484523cf
JS
61 wxTreeItemIdValue m_pItem;
62};
63
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
72// quite big.
73//
74// Because the objects of this class are deleted by the tree, they should
75// always be allocated on the heap!
76// ----------------------------------------------------------------------------
77
78class WXDLLEXPORT wxTreeItemData: public wxClientData
79{
80friend class WXDLLEXPORT wxTreeCtrl;
81friend class WXDLLEXPORT wxGenericTreeCtrl;
82public:
83 // creation/destruction
84 // --------------------
85 // default ctor
86 wxTreeItemData() { }
87
88 // default copy ctor/assignment operator are ok
89
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; }
93
94protected:
95 wxTreeItemId m_pItem;
96};
97
98WX_DEFINE_EXPORTED_ARRAY(wxTreeItemId, wxArrayTreeItemIds);
99
100// ----------------------------------------------------------------------------
101// constants
102// ----------------------------------------------------------------------------
103
104// enum for different images associated with a treectrl item
105enum wxTreeItemIcon
106{
107 wxTreeItemIcon_Normal, // not selected, not expanded
108 wxTreeItemIcon_Selected, // selected, not expanded
109 wxTreeItemIcon_Expanded, // not selected, expanded
110 wxTreeItemIcon_SelectedExpanded, // selected, expanded
111 wxTreeItemIcon_Max
112};
113
114
115// values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
116// where exactly the specified point is situated:
117
118static const int wxTREE_HITTEST_ABOVE = 0x0001;
119static const int wxTREE_HITTEST_BELOW = 0x0002;
120static const int wxTREE_HITTEST_NOWHERE = 0x0004;
121 // on the button associated with an item.
122static const int wxTREE_HITTEST_ONITEMBUTTON = 0x0008;
123 // on the bitmap associated with an item.
124static const int wxTREE_HITTEST_ONITEMICON = 0x0010;
125 // on the indent associated with an item.
126static const int wxTREE_HITTEST_ONITEMINDENT = 0x0020;
127 // on the label (string) associated with an item.
128static const int wxTREE_HITTEST_ONITEMLABEL = 0x0040;
129 // on the right of the label associated with an item.
130static const int wxTREE_HITTEST_ONITEMRIGHT = 0x0080;
131 // on the label (string) associated with an item.
132static const int wxTREE_HITTEST_ONITEMSTATEICON = 0x0100;
133 // on the left of the wxTreeCtrl.
134static const int wxTREE_HITTEST_TOLEFT = 0x0200;
135 // on the right of the wxTreeCtrl.
136static const int wxTREE_HITTEST_TORIGHT = 0x0400;
137 // on the upper part (first half) of the item.
138static const int wxTREE_HITTEST_ONITEMUPPERPART = 0x0800;
139 // on the lower part (second half) of the item.
140static const int wxTREE_HITTEST_ONITEMLOWERPART = 0x1000;
141
142 // anywhere on the item
143static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON |
144 wxTREE_HITTEST_ONITEMLABEL;
145
146// tree ctrl default name
161f4f73 147WXDLLEXPORT_DATA(extern const wxChar*) wxTreeCtrlNameStr;
484523cf
JS
148
149// ----------------------------------------------------------------------------
150// wxTreeItemAttr: a structure containing the visual attributes of an item
151// ----------------------------------------------------------------------------
152
153class WXDLLEXPORT wxTreeItemAttr
154{
155public:
156 // ctors
157 wxTreeItemAttr() { }
158 wxTreeItemAttr(const wxColour& colText,
159 const wxColour& colBack,
160 const wxFont& font)
161 : m_colText(colText), m_colBack(colBack), m_font(font) { }
162
163 // setters
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; }
167
168 // accessors
169 bool HasTextColour() const { return m_colText.Ok(); }
170 bool HasBackgroundColour() const { return m_colBack.Ok(); }
171 bool HasFont() const { return m_font.Ok(); }
172
173 const wxColour& GetTextColour() const { return m_colText; }
174 const wxColour& GetBackgroundColour() const { return m_colBack; }
175 const wxFont& GetFont() const { return m_font; }
176
177private:
178 wxColour m_colText,
179 m_colBack;
180 wxFont m_font;
181};
182
183// ----------------------------------------------------------------------------
184// wxTreeEvent is a special class for all events associated with tree controls
185//
186// NB: note that not all accessors make sense for all events, see the event
187// descriptions below
188// ----------------------------------------------------------------------------
189
190class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent
191{
192 friend class WXDLLEXPORT wxTreeCtrl;
193 friend class WXDLLEXPORT wxGenericTreeCtrl;
194
195public:
196 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
197
198 // accessors
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; }
202
203 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
204 // selected item
205 wxTreeItemId GetOldItem() const { return m_itemOld; }
206
207 // the point where the mouse was when the drag operation started (for
33737618 208 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
484523cf
JS
209 wxPoint GetPoint() const { return m_pointDrag; }
210
211 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
212 int GetCode() const { return m_code; }
213
214 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
215 const wxString& GetLabel() const { return m_label; }
216
217private:
218 // we could probably save some space by using union here
219 int m_code;
220 wxTreeItemId m_item,
221 m_itemOld;
222 wxPoint m_pointDrag;
223 wxString m_label;
224
225 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
226};
227
228typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
229
230// ----------------------------------------------------------------------------
2e4df4bf 231// tree control events and macros for handling them
484523cf
JS
232// ----------------------------------------------------------------------------
233
2e4df4bf
VZ
234BEGIN_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)
253END_DECLARE_EVENT_TYPES()
254
484523cf
JS
255// GetItem() returns the item being dragged, GetPoint() the mouse coords
256//
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.
2e4df4bf
VZ
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 ),
484523cf
JS
261
262// GetItem() is the item on which the drop occured (if any) and GetPoint() the
263// current mouse coords
2e4df4bf 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 ),
484523cf
JS
265
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.
268//
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
2e4df4bf
VZ
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 ),
484523cf
JS
273
274// provide/update information about GetItem() item
2e4df4bf
VZ
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 ),
484523cf
JS
277
278// GetItem() is the item being expanded/collapsed, the "ING" versions can use
2e4df4bf
VZ
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 ),
484523cf
JS
283
284// GetOldItem() is the item which had the selection previously, GetItem() is
285// the item which acquires selection
2e4df4bf
VZ
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 ),
484523cf
JS
288
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())
2e4df4bf 292#define EVT_TREE_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
484523cf
JS
293
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)
2e4df4bf 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 ),
484523cf
JS
297
298// GetItem() returns the item that was activated (double click, enter, space)
2e4df4bf 299#define EVT_TREE_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
484523cf
JS
300
301// GetItem() returns the item that was clicked on
2e4df4bf
VZ
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 ),
484523cf 304
75212e68 305// #endif // wxUSE_TREECTRL
33737618 306
484523cf
JS
307#endif
308 // _WX_TREEBASE_H_
309
310