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