]> git.saurik.com Git - wxWidgets.git/blob - include/wx/treectrl.h
Ops, stupid me.
[wxWidgets.git] / include / wx / treectrl.h
1 #ifndef _WX_TREECTRL_H_BASE_
2 #define _WX_TREECTRL_H_BASE_
3
4 // ----------------------------------------------------------------------------
5 // headers
6 // ----------------------------------------------------------------------------
7
8 #include "wx/control.h"
9 #include "wx/event.h"
10
11 // ----------------------------------------------------------------------------
12 // constants
13 // ----------------------------------------------------------------------------
14
15 // enum for different images associated with a treectrl item
16 enum wxTreeItemIcon
17 {
18 wxTreeItemIcon_Normal, // not selected, not expanded
19 wxTreeItemIcon_Selected, // selected, not expanded
20 wxTreeItemIcon_Expanded, // not selected, expanded
21 wxTreeItemIcon_SelectedExpanded, // selected, expanded
22 wxTreeItemIcon_Max
23 };
24
25
26 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
27 // where exactly the specified point is situated:
28
29 static const int wxTREE_HITTEST_ABOVE = 0x0001;
30 static const int wxTREE_HITTEST_BELOW = 0x0002;
31 static const int wxTREE_HITTEST_NOWHERE = 0x0004;
32 // on the button associated with an item.
33 static const int wxTREE_HITTEST_ONITEMBUTTON = 0x0008;
34 // on the bitmap associated with an item.
35 static const int wxTREE_HITTEST_ONITEMICON = 0x0010;
36 // on the indent associated with an item.
37 static const int wxTREE_HITTEST_ONITEMINDENT = 0x0020;
38 // on the label (string) associated with an item.
39 static const int wxTREE_HITTEST_ONITEMLABEL = 0x0040;
40 // on the right of the label associated with an item.
41 static const int wxTREE_HITTEST_ONITEMRIGHT = 0x0080;
42 // on the label (string) associated with an item.
43 static const int wxTREE_HITTEST_ONITEMSTATEICON = 0x0100;
44 // on the left of the wxTreeCtrl.
45 static const int wxTREE_HITTEST_TOLEFT = 0x0200;
46 // on the right of the wxTreeCtrl.
47 static const int wxTREE_HITTEST_TORIGHT = 0x0400;
48 // on the upper part (first half) of the item.
49 static const int wxTREE_HITTEST_ONITEMUPPERPART = 0x0800;
50 // on the lower part (second half) of the item.
51 static const int wxTREE_HITTEST_ONITEMLOWERPART = 0x1000;
52
53 // anywhere on the item
54 static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON |
55 wxTREE_HITTEST_ONITEMLABEL;
56
57 // tree ctrl default name
58 WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr;
59
60 // ----------------------------------------------------------------------------
61 // wxTreeItemAttr: a structure containing the visual attributes of an item
62 // ----------------------------------------------------------------------------
63
64 class WXDLLEXPORT wxTreeItemAttr
65 {
66 public:
67 // ctors
68 wxTreeItemAttr() { }
69 wxTreeItemAttr(const wxColour& colText,
70 const wxColour& colBack,
71 const wxFont& font)
72 : m_colText(colText), m_colBack(colBack), m_font(font) { }
73
74 // setters
75 void SetTextColour(const wxColour& colText) { m_colText = colText; }
76 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
77 void SetFont(const wxFont& font) { m_font = font; }
78
79 // accessors
80 bool HasTextColour() const { return m_colText.Ok(); }
81 bool HasBackgroundColour() const { return m_colBack.Ok(); }
82 bool HasFont() const { return m_font.Ok(); }
83
84 const wxColour& GetTextColour() const { return m_colText; }
85 const wxColour& GetBackgroundColour() const { return m_colBack; }
86 const wxFont& GetFont() const { return m_font; }
87
88 private:
89 wxColour m_colText,
90 m_colBack;
91 wxFont m_font;
92 };
93
94 // ----------------------------------------------------------------------------
95 // include the platform-dependent wxTreeCtrl class
96 // ----------------------------------------------------------------------------
97
98 #if defined(__WXMSW__)
99 #ifdef __WIN16__
100 #include "wx/generic/treectrl.h"
101 #else
102 #include "wx/msw/treectrl.h"
103 #endif
104 #elif defined(__WXMOTIF__)
105 #include "wx/generic/treectrl.h"
106 #elif defined(__WXGTK__)
107 #include "wx/generic/treectrl.h"
108 #elif defined(__WXQT__)
109 #include "wx/qt/treectrl.h"
110 #elif defined(__WXMAC__)
111 #include "wx/generic/treectrl.h"
112 #elif defined(__WXPM__)
113 #include "wx/generic/treectrl.h"
114 #elif defined(__WXSTUBS__)
115 #include "wx/generic/treectrl.h"
116 #endif
117
118 // ----------------------------------------------------------------------------
119 // wxTreeEvent is a special class for all events associated with tree controls
120 //
121 // NB: note that not all accessors make sense for all events, see the event
122 // descriptions below
123 // ----------------------------------------------------------------------------
124
125 class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent
126 {
127 friend class WXDLLEXPORT wxTreeCtrl;
128
129 public:
130 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
131
132 // accessors
133 // get the item on which the operation was performed or the newly
134 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
135 wxTreeItemId GetItem() const { return m_item; }
136
137 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
138 // selected item
139 wxTreeItemId GetOldItem() const { return m_itemOld; }
140
141 // the point where the mouse was when the drag operation started (for
142 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only)
143 wxPoint GetPoint() const { return m_pointDrag; }
144
145 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
146 int GetCode() const { return m_code; }
147
148 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
149 const wxString& GetLabel() const { return m_label; }
150
151 private:
152 // we could probably save some space by using union here
153 int m_code;
154 wxTreeItemId m_item,
155 m_itemOld;
156 wxPoint m_pointDrag;
157 wxString m_label;
158
159 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
160 };
161
162 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
163
164 // ----------------------------------------------------------------------------
165 // macros for handling tree control events
166 // ----------------------------------------------------------------------------
167
168 // GetItem() returns the item being dragged, GetPoint() the mouse coords
169 //
170 // if you call event.Allow(), the drag operation will start and a
171 // EVT_TREE_END_DRAG event will be sent when the drag is over.
172 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
173 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
174
175 // GetItem() is the item on which the drop occured (if any) and GetPoint() the
176 // current mouse coords
177 #define EVT_TREE_END_DRAG(id, fn) { wxEVT_COMMAND_TREE_END_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
178
179 // GetItem() returns the itme whose label is being edited, GetLabel() returns
180 // the current item label for BEGIN and the would be new one for END.
181 //
182 // Vetoing BEGIN event means that label editing won't happen at all,
183 // vetoing END means that the new value is discarded and the old one kept
184 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
185 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
186
187 // provide/update information about GetItem() item
188 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
189 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
190
191 // GetItem() is the item being expanded/collapsed, the "ING" versions can use
192 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
193 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
194 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
195 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
196
197 // GetOldItem() is the item which had the selection previously, GetItem() is
198 // the item which acquires selection
199 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
200 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
201
202 // GetCode() returns the key code
203 // NB: this is the only message for which GetItem() is invalid (you may get the
204 // item from GetSelection())
205 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
206
207 // GetItem() returns the item being deleted, the associated data (if any) will
208 // be deleted just after the return of this event handler (if any)
209 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
210
211 // GetItem() returns the item that was activated (double click, enter, space)
212 #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
213
214 // GetItem() returns the item that was clicked on
215 #define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
216 #define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
217
218 #endif
219 // _WX_TREECTRL_H_BASE_
220
221