]> git.saurik.com Git - wxWidgets.git/blob - include/wx/treectrl.h
Integrated recent API-change
[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 // TODO we could 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 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
170 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
171
172 // GetItem() returns the itme whose label is being edited, GetLabel() returns
173 // the current item label for BEGIN and the would be new one for END.
174 //
175 // Vetoing BEGIN event means that label editing won't happen at all,
176 // vetoing END means that the new value is discarded and the old one kept
177 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
178 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
179
180 // provide/update information about GetItem() item
181 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
182 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
183
184 // GetItem() is the item being expanded/collapsed, the "ING" versions can use
185 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
186 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
187 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
188 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
189
190 // GetOldItem() is the item which had the selection previously, GetItem() is
191 // the item which acquires selection
192 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
193 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
194
195 // GetCode() returns the key code
196 // NB: this is the only message for which GetItem() is invalid (you may get the
197 // item from GetSelection())
198 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
199
200 // GetItem() returns the item being deleted, the associated data (if any) will
201 // be deleted just after the return of this event handler (if any)
202 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
203
204 // GetItem() returns the item that was activated (double click, enter, space)
205 #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
206
207 // GetItem() returns the item that was clicked on
208 #define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
209 #define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
210
211 #endif
212 // _WX_TREECTRL_H_BASE_
213
214