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