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