]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/treectrl.h
Added missing declaration of wxIcon::operator =(const wxIcon &)
[wxWidgets.git] / include / wx / gtk / treectrl.h
1 /*
2 * Author: Robert Roebling
3 *
4 * Copyright: (C) 1997,1998 Robert Roebling
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the wxWindows Licence, which
8 * you have received with this library (see Licence.htm).
9 *
10 */
11
12 #ifndef __GTKTREECTRL_H__
13 #define __GTKTREECTRL_H__
14
15 #ifdef __GNUG__
16 #pragma interface "treectrl.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21 #include "wx/list.h"
22 #include "wx/control.h"
23 #include "wx/event.h"
24 #include "wx/imaglist.h"
25 #include "wx/scrolwin.h"
26 #include "wx/dcclient.h"
27
28 #include <gtk/gtk.h>
29
30 //-----------------------------------------------------------------------------
31 // classes
32 //-----------------------------------------------------------------------------
33
34 class wxTreeItem;
35 class wxTreeCtrl;
36 class wxTreeEvent;
37
38 class wxImageList;
39
40 //-----------------------------------------------------------------------------
41 // constants
42 //-----------------------------------------------------------------------------
43
44 // WXDLLEXPORT extern const char *wxTreeNameStr;
45
46 #define wxTREE_MASK_HANDLE 0x0001
47 #define wxTREE_MASK_STATE 0x0002
48 #define wxTREE_MASK_TEXT 0x0004
49 #define wxTREE_MASK_IMAGE 0x0008
50 #define wxTREE_MASK_SELECTED_IMAGE 0x0010
51 #define wxTREE_MASK_CHILDREN 0x0020
52 #define wxTREE_MASK_DATA 0x0040
53
54 #define wxTREE_STATE_BOLD 0x0001
55 #define wxTREE_STATE_DROPHILITED 0x0002
56 #define wxTREE_STATE_EXPANDED 0x0004
57 #define wxTREE_STATE_EXPANDEDONCE 0x0008
58 #define wxTREE_STATE_FOCUSED 0x0010
59 #define wxTREE_STATE_SELECTED 0x0020
60 #define wxTREE_STATE_CUT 0x0040
61
62 #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area.
63 #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area.
64 #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
65 #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item.
66 #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
67 #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item.
68 #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
69 #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
70 #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
71 #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area.
72 #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area.
73
74 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
75
76 // Flags for GetNextItem
77 enum {
78 wxTREE_NEXT_CARET, // Retrieves the currently selected item.
79 wxTREE_NEXT_CHILD, // Retrieves the first child item. The hItem parameter must be NULL.
80 wxTREE_NEXT_DROPHILITE, // Retrieves the item that is the target of a drag-and-drop operation.
81 wxTREE_NEXT_FIRSTVISIBLE, // Retrieves the first visible item.
82 wxTREE_NEXT_NEXT, // Retrieves the next sibling item.
83 wxTREE_NEXT_NEXTVISIBLE, // Retrieves the next visible item that follows the specified item.
84 wxTREE_NEXT_PARENT, // Retrieves the parent of the specified item.
85 wxTREE_NEXT_PREVIOUS, // Retrieves the previous sibling item.
86 wxTREE_NEXT_PREVIOUSVISIBLE, // Retrieves the first visible item that precedes the specified item.
87 wxTREE_NEXT_ROOT // Retrieves the first child item of the root item of which the specified item is a part.
88 };
89
90 // Flags for ExpandItem
91 enum {
92 wxTREE_EXPAND_EXPAND,
93 wxTREE_EXPAND_COLLAPSE,
94 wxTREE_EXPAND_COLLAPSE_RESET,
95 wxTREE_EXPAND_TOGGLE
96 };
97
98 // Flags for InsertItem
99 enum {
100 wxTREE_INSERT_LAST = -1,
101 wxTREE_INSERT_FIRST = -2,
102 wxTREE_INSERT_SORT = -3
103 };
104
105 //-----------------------------------------------------------------------------
106 // wxTreeItem
107 //-----------------------------------------------------------------------------
108
109
110 class WXDLLEXPORT wxTreeItem: public wxObject
111 {
112 public:
113 wxTreeCtrl *m_owner;
114 GtkWidget *m_parentwidget;
115 GtkTreeItem *m_widget;
116 GtkTree *m_tree;
117 long m_mask;
118 long m_itemId;
119 long m_state;
120 long m_stateMask;
121 wxString m_text;
122 int m_image;
123 int m_selectedImage;
124 int m_children;
125 wxList m_childlist;
126 long m_data;
127
128 wxTreeItem();
129 wxTreeItem(GtkWidget *parent, const wxTreeItem &item);
130 ~wxTreeItem();
131
132 void Create();
133
134 void AddChild(wxTreeItem *child);
135 void DeleteChildren();
136 bool HasChildren();
137 wxTreeItem *FindItem(long itemId) const;
138 wxTreeItem *FindItem(GtkTreeItem *item) const;
139
140 // Accessors
141 inline long GetMask() const { return m_mask; }
142 inline long GetItemId() const { return m_itemId; }
143 inline long GetState() const { return m_state; }
144 inline long GetStateMask() const { return m_stateMask; }
145 inline wxString GetText() const { return m_text; }
146 inline int GetImage() const { return m_image; }
147 inline int GetSelectedImage() const { return m_selectedImage; }
148 inline const wxList &GetChildren() const { return m_childlist; }
149 inline long GetData() const { return m_data; }
150
151 inline void SetMask(long mask) { m_mask = mask; }
152 inline void SetItemId(long id) { m_itemId = m_itemId = id; }
153 inline void GetState(long state) { m_state = state; }
154 inline void SetStateMask(long stateMask) { m_stateMask = stateMask; }
155 inline void GetText(const wxString& text) { m_text = text; }
156 inline void SetImage(int image) { m_image = image; }
157 inline void SetSelectedImage(int selImage) { m_selectedImage = selImage; }
158 inline void SetChildren(const wxList &children) { m_childlist = children; }
159 inline void SetData(long data) { m_data = data; }
160
161 int NumberOfVisibleDescendents();
162 private:
163 friend wxTreeCtrl;
164 friend void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItem *treeitem);
165 friend void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItem *treeitem);
166 friend void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem);
167 friend void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem);
168
169 void AddSubtree();
170 void PrepareEvent(wxTreeEvent &event);
171 void SendDelete(wxWindow *target);
172 void SendExpand(wxWindow *target);
173 void SendExpanding(wxWindow *target);
174 void SendCollapse(wxWindow *target);
175 void SendCollapsing(wxWindow *target);
176 void SendSelChanged(wxWindow *target);
177 void SendSelChanging(wxWindow *target);
178
179 inline wxTreeItem *GetChild(long no) {
180 return (wxTreeItem *)(m_childlist.Nth(no)->Data());
181 }
182 inline long GetChildrenNumber() {
183 return m_childlist.Number();
184 }
185
186 guint expand_handler;
187 guint collapse_handler;
188
189 DECLARE_DYNAMIC_CLASS(wxTreeItem)
190 };
191
192 //-----------------------------------------------------------------------------
193 // wxTreeCtrl
194 //-----------------------------------------------------------------------------
195
196 class wxTreeCtrl: public wxScrolledWindow {
197 public:
198 GtkTree *m_tree;
199
200 wxTreeCtrl();
201 wxTreeCtrl(wxWindow *parent, const wxWindowID id = -1,
202 const wxPoint& pos = wxDefaultPosition,
203 const wxSize& size = wxDefaultSize,
204 long style = wxTR_HAS_BUTTONS,
205 const wxString& name = "wxTreeCtrl" );
206 ~wxTreeCtrl();
207 bool Create(wxWindow *parent, const wxWindowID id = -1,
208 const wxPoint& pos = wxDefaultPosition,
209 const wxSize& size = wxDefaultSize,
210 long style = wxTR_HAS_BUTTONS,
211 const wxString& name = "wxTreeCtrl");
212
213 int GetCount() const;
214
215 long InsertItem( long parent, const wxString& label, long data = 0,
216 int image = -1, int selImage = -1,
217 long insertAfter = wxTREE_INSERT_LAST );
218
219 long InsertItem( long parent, wxTreeItem &info,
220 long insertAfter = wxTREE_INSERT_LAST );
221 void DeleteItem( long item );
222 void DeleteChildren( long item );
223 bool DeleteAllItems();
224
225 bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); }
226 bool ExpandItem( long item, int action );
227
228 bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); }
229 bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); }
230
231 // is the item expanded now?
232 bool IsItemExpanded(long item)
233 {
234 wxTreeItem *pItem = FindItem(item);
235 return pItem && (pItem->GetState() & wxTREE_STATE_EXPANDED);
236 }
237
238 /*
239 bool GetItem( wxTreeItem &info ) const;
240 */
241
242 long GetItemData( long item ) const;
243 wxString GetItemText( long item ) const;
244 int GetItemImage(long item) const;
245 long GetParent( long item ) const;
246 long GetRootItem() const;
247 /*
248 long GetSelection() const;
249 bool SelectItem( long item );
250 */
251
252 bool ItemHasChildren( long item ) const;
253 void SetIndent( int indent );
254 int GetIndent() const;
255
256 /*
257 bool SetItem( wxTreeItem &info );
258 bool SetItemData( long item, long data );
259 bool SetItemText( long item, const wxString &text );
260 void SetItemImage(long item, int image, int imageSel) const;
261 long HitTest( const wxPoint& point, int &flags );
262 */
263
264 wxTreeItem *FindItem(GtkTreeItem *item) const;
265
266 wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const;
267 void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL);
268
269 private:
270 // set the selection to the specified item generating appropriate event(s) if
271 // not disabled
272 void SelectItem(wxTreeItem *item, bool bDoEvents = TRUE);
273
274 wxTreeItem *m_anchor;
275 wxTreeItem *m_current;
276 int m_indent;
277 long m_lastId;
278 bool m_isCreated;
279 wxImageList *m_imageList;
280 wxImageList *m_smallImageList;
281
282 void CalculateLevel( wxTreeItem *item, wxPaintDC &dc, int level, int &y );
283 void CalculatePositions();
284 wxTreeItem *FindItem( long itemId ) const;
285
286 // DECLARE_EVENT_TABLE()
287 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
288 };
289
290 //-----------------------------------------------------------------------------
291 // wxTreeEvent
292 //-----------------------------------------------------------------------------
293
294 class WXDLLEXPORT wxTreeEvent: public wxCommandEvent
295 {
296 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
297
298 public:
299 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
300
301 int m_code;
302 wxTreeItem m_item;
303 long m_oldItem;
304 wxPoint m_pointDrag;
305
306 inline long GetOldItem() const { return m_oldItem; }
307 inline wxTreeItem& GetItem() const { return (wxTreeItem&) m_item; }
308 inline wxPoint GetPoint() const { return m_pointDrag; }
309 inline void SetCode(int code) { m_code = code; }
310 inline int GetCode() const { return m_code; }
311 };
312
313 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
314
315 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
316 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
317 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn , NULL },
318 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
319 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
320 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
321 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
322 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
323 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
324 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
325 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
326 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, ( wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
327 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
328 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
329
330 #endif
331 // __GTKTREECTRL_H__