]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: treectrl.h | |
3 | // Purpose: wxTreeCtrl class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_TREECTRL_H_ |
13 | #define _WX_TREECTRL_H_ | |
2bda0e17 KB |
14 | |
15 | #ifdef __GNUG__ | |
16 | #pragma interface "treectrl.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/control.h" | |
20 | #include "wx/event.h" | |
21 | #include "wx/imaglist.h" | |
22 | ||
23 | // WXDLLEXPORT_DATA(extern const char*) wxTreeNameStr; | |
24 | ||
25 | #define wxTREE_MASK_HANDLE 0x0001 | |
26 | #define wxTREE_MASK_STATE 0x0002 | |
27 | #define wxTREE_MASK_TEXT 0x0004 | |
28 | #define wxTREE_MASK_IMAGE 0x0008 | |
29 | #define wxTREE_MASK_SELECTED_IMAGE 0x0010 | |
30 | #define wxTREE_MASK_CHILDREN 0x0020 | |
31 | #define wxTREE_MASK_DATA 0x0040 | |
32 | ||
33 | #define wxTREE_STATE_BOLD 0x0001 | |
34 | #define wxTREE_STATE_DROPHILITED 0x0002 | |
35 | #define wxTREE_STATE_EXPANDED 0x0004 | |
36 | #define wxTREE_STATE_EXPANDEDONCE 0x0008 | |
37 | #define wxTREE_STATE_FOCUSED 0x0010 | |
38 | #define wxTREE_STATE_SELECTED 0x0020 | |
39 | #define wxTREE_STATE_CUT 0x0040 | |
40 | ||
41 | #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area. | |
42 | #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area. | |
43 | #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item. | |
44 | #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item. | |
45 | #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item. | |
46 | #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item. | |
47 | #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item. | |
48 | #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item. | |
49 | #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state. | |
50 | #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area. | |
51 | #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area. | |
52 | ||
4efd7443 | 53 | #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON) |
2bda0e17 KB |
54 | |
55 | // Flags for GetNextItem | |
56 | enum { | |
57 | wxTREE_NEXT_CARET, // Retrieves the currently selected item. | |
58 | wxTREE_NEXT_CHILD, // Retrieves the first child item. The hItem parameter must be NULL. | |
59 | wxTREE_NEXT_DROPHILITE, // Retrieves the item that is the target of a drag-and-drop operation. | |
60 | wxTREE_NEXT_FIRSTVISIBLE, // Retrieves the first visible item. | |
61 | wxTREE_NEXT_NEXT, // Retrieves the next sibling item. | |
62 | wxTREE_NEXT_NEXTVISIBLE, // Retrieves the next visible item that follows the specified item. | |
63 | wxTREE_NEXT_PARENT, // Retrieves the parent of the specified item. | |
64 | wxTREE_NEXT_PREVIOUS, // Retrieves the previous sibling item. | |
65 | wxTREE_NEXT_PREVIOUSVISIBLE, // Retrieves the first visible item that precedes the specified item. | |
66 | wxTREE_NEXT_ROOT // Retrieves the first child item of the root item of which the specified item is a part. | |
67 | }; | |
68 | ||
69 | // Flags for ExpandItem | |
70 | enum { | |
71 | wxTREE_EXPAND_EXPAND, | |
72 | wxTREE_EXPAND_COLLAPSE, | |
73 | wxTREE_EXPAND_COLLAPSE_RESET, | |
74 | wxTREE_EXPAND_TOGGLE | |
75 | }; | |
76 | ||
77 | // Flags for InsertItem | |
3197ed26 VZ |
78 | #define wxTREE_INSERT_FIRST 0xFFFF0001 |
79 | #define wxTREE_INSERT_LAST 0xFFFF0002 | |
80 | #define wxTREE_INSERT_SORT 0xFFFF0003 | |
2bda0e17 KB |
81 | |
82 | class WXDLLEXPORT wxTreeItem: public wxObject | |
83 | { | |
84 | DECLARE_DYNAMIC_CLASS(wxTreeItem) | |
85 | public: | |
86 | long m_mask; | |
87 | long m_itemId; | |
88 | long m_state; | |
89 | long m_stateMask; | |
90 | wxString m_text; | |
91 | int m_image; | |
92 | int m_selectedImage; | |
93 | int m_children; | |
94 | long m_data; | |
95 | ||
092bddef | 96 | wxTreeItem(); |
64693098 JS |
97 | |
98 | // Accessors | |
99 | inline long GetMask() const { return m_mask; } | |
100 | inline long GetItemId() const { return m_itemId; } | |
101 | inline long GetState() const { return m_state; } | |
102 | inline long GetStateMask() const { return m_stateMask; } | |
103 | inline wxString GetText() const { return m_text; } | |
104 | inline int GetImage() const { return m_image; } | |
105 | inline int GetSelectedImage() const { return m_selectedImage; } | |
106 | inline int GetChildren() const { return m_children; } | |
107 | inline long GetData() const { return m_data; } | |
108 | ||
109 | inline void SetMask(long mask) { m_mask = mask; } | |
110 | inline void SetItemId(long id) { m_itemId = m_itemId = id; } | |
092bddef | 111 | inline void SetState(long state) { m_state = state; } |
64693098 JS |
112 | inline void SetStateMask(long stateMask) { m_stateMask = stateMask; } |
113 | inline void GetText(const wxString& text) { m_text = text; } | |
114 | inline void SetImage(int image) { m_image = image; } | |
115 | inline void GetSelectedImage(int selImage) { m_selectedImage = selImage; } | |
116 | inline void SetChildren(int children) { m_children = children; } | |
117 | inline void SetData(long data) { m_data = data; } | |
2bda0e17 KB |
118 | }; |
119 | ||
120 | class WXDLLEXPORT wxTreeCtrl: public wxControl | |
121 | { | |
092bddef VZ |
122 | public: |
123 | /* | |
124 | * Public interface | |
125 | */ | |
126 | ||
127 | // creation | |
128 | // -------- | |
129 | wxTreeCtrl(); | |
130 | ||
131 | inline wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
132 | const wxPoint& pos = wxDefaultPosition, | |
133 | const wxSize& size = wxDefaultSize, | |
134 | long style = wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT, | |
135 | const wxValidator& validator = wxDefaultValidator, | |
136 | const wxString& name = "wxTreeCtrl") | |
137 | { | |
138 | Create(parent, id, pos, size, style, validator, name); | |
139 | } | |
140 | ~wxTreeCtrl(); | |
141 | ||
142 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
143 | const wxPoint& pos = wxDefaultPosition, | |
144 | const wxSize& size = wxDefaultSize, | |
145 | long style = wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT, | |
146 | const wxValidator& validator = wxDefaultValidator, | |
147 | const wxString& name = "wxTreeCtrl"); | |
148 | ||
149 | // accessors | |
150 | // --------- | |
151 | // | |
152 | int GetCount() const; | |
153 | ||
154 | // indent | |
155 | int GetIndent() const; | |
156 | void SetIndent(int indent); | |
157 | // image list | |
158 | wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const; | |
159 | void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL); | |
160 | ||
161 | // navigation inside the tree | |
162 | long GetNextItem(long item, int code) const; | |
163 | bool ItemHasChildren(long item) const; | |
164 | long GetChild(long item) const; | |
165 | long GetParent(long item) const; | |
166 | long GetFirstVisibleItem() const; | |
167 | long GetNextVisibleItem(long item) const; | |
168 | long GetSelection() const; | |
169 | long GetRootItem() const; | |
170 | ||
171 | // generic function for (g|s)etting item attributes | |
172 | bool GetItem(wxTreeItem& info) const; | |
173 | bool SetItem(wxTreeItem& info); | |
174 | // item state | |
175 | int GetItemState(long item, long stateMask) const; | |
176 | bool SetItemState(long item, long state, long stateMask); | |
177 | // item image | |
178 | bool SetItemImage(long item, int image, int selImage); | |
179 | // item text | |
180 | wxString GetItemText(long item) const; | |
181 | void SetItemText(long item, const wxString& str); | |
182 | // custom data associated with the item | |
183 | long GetItemData(long item) const; | |
184 | bool SetItemData(long item, long data); | |
185 | // convenience function | |
186 | bool IsItemExpanded(long item) | |
187 | { | |
188 | return (GetItemState(item, wxTREE_STATE_EXPANDED) & | |
189 | wxTREE_STATE_EXPANDED) != 0; | |
190 | } | |
191 | ||
192 | // bounding rect | |
193 | bool GetItemRect(long item, wxRectangle& rect, bool textOnly = FALSE) const; | |
194 | // | |
bbcdf8bc | 195 | wxTextCtrl* GetEditControl() const; |
092bddef VZ |
196 | |
197 | // operations | |
198 | // ---------- | |
199 | // adding/deleting items | |
200 | bool DeleteItem(long item); | |
201 | long InsertItem(long parent, wxTreeItem& info, | |
202 | long insertAfter = wxTREE_INSERT_LAST); | |
203 | // If image > -1 and selImage == -1, the same image is used for | |
204 | // both selected and unselected items. | |
205 | long InsertItem(long parent, const wxString& label, | |
206 | int image = -1, int selImage = -1, | |
207 | long insertAfter = wxTREE_INSERT_LAST); | |
208 | ||
209 | // changing item state | |
210 | bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); } | |
211 | bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); } | |
212 | bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); } | |
213 | // common interface for {Expand|Collapse|Toggle}Item | |
214 | bool ExpandItem(long item, int action); | |
215 | ||
216 | // | |
217 | bool SelectItem(long item); | |
218 | bool ScrollTo(long item); | |
219 | bool DeleteAllItems(); | |
bbcdf8bc JS |
220 | |
221 | // Edit the label (tree must have the focus) | |
222 | wxTextCtrl* EditLabel(long item, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)); | |
223 | ||
224 | // End label editing, optionally cancelling the edit | |
225 | bool EndEditLabel(bool cancel); | |
226 | ||
092bddef VZ |
227 | long HitTest(const wxPoint& point, int& flags); |
228 | // wxImageList *CreateDragImage(long item); | |
229 | bool SortChildren(long item); | |
230 | bool EnsureVisible(long item); | |
231 | ||
232 | // IMPLEMENTATION | |
233 | void Command(wxCommandEvent& event) { ProcessCommand(event); }; | |
234 | bool MSWCommand(WXUINT param, WXWORD id); | |
235 | bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam); | |
236 | ||
2bda0e17 | 237 | protected: |
bbcdf8bc JS |
238 | wxTextCtrl* m_textCtrl; |
239 | wxImageList* m_imageListNormal; | |
240 | wxImageList* m_imageListState; | |
092bddef VZ |
241 | |
242 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
2bda0e17 KB |
243 | }; |
244 | ||
245 | /* | |
246 | wxEVT_COMMAND_TREE_BEGIN_DRAG, | |
247 | wxEVT_COMMAND_TREE_BEGIN_RDRAG, | |
248 | wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, | |
249 | wxEVT_COMMAND_TREE_END_LABEL_EDIT, | |
250 | wxEVT_COMMAND_TREE_DELETE_ITEM, | |
251 | wxEVT_COMMAND_TREE_GET_INFO, | |
252 | wxEVT_COMMAND_TREE_SET_INFO, | |
253 | wxEVT_COMMAND_TREE_ITEM_EXPANDED, | |
254 | wxEVT_COMMAND_TREE_ITEM_EXPANDING, | |
092bddef VZ |
255 | wxEVT_COMMAND_TREE_ITEM_COLLAPSED, |
256 | wxEVT_COMMAND_TREE_ITEM_COLLAPSING, | |
2bda0e17 KB |
257 | wxEVT_COMMAND_TREE_SEL_CHANGED, |
258 | wxEVT_COMMAND_TREE_SEL_CHANGING, | |
259 | wxEVT_COMMAND_TREE_KEY_DOWN | |
260 | */ | |
261 | ||
262 | class WXDLLEXPORT wxTreeEvent: public wxCommandEvent | |
263 | { | |
264 | DECLARE_DYNAMIC_CLASS(wxTreeEvent) | |
265 | ||
266 | public: | |
64693098 | 267 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
2bda0e17 KB |
268 | |
269 | int m_code; | |
270 | wxTreeItem m_item; | |
271 | long m_oldItem; | |
272 | wxPoint m_pointDrag; | |
64693098 JS |
273 | |
274 | inline long GetOldItem() const { return m_oldItem; } | |
275 | inline wxTreeItem& GetItem() const { return (wxTreeItem&) m_item; } | |
276 | inline wxPoint GetPoint() const { return m_pointDrag; } | |
277 | inline int GetCode() const { return m_code; } | |
2bda0e17 KB |
278 | }; |
279 | ||
280 | typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); | |
281 | ||
fe71f65c RR |
282 | #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
283 | #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
284 | #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
285 | #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
286 | #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
287 | #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
288 | #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
289 | #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
290 | #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
092bddef VZ |
291 | #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
292 | #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
fe71f65c RR |
293 | #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
294 | #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
295 | #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
2bda0e17 KB |
296 | |
297 | #endif | |
bbcdf8bc | 298 | // _WX_TREECTRL_H_ |