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