1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Denis Pershin
7 // Copyright: (c) 1998 Denis Pershin and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GTKTREECTRL_H__
12 #define __GTKTREECTRL_H__
15 #pragma interface "treectrl.h"
19 #include "wx/string.h"
21 #include "wx/control.h"
23 #include "wx/imaglist.h"
24 #include "wx/scrolwin.h"
25 #include "wx/dcclient.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 // WXDLLEXPORT extern const char *wxTreeNameStr;
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
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
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.
73 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
75 // Flags for GetNextItem
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.
89 // Flags for ExpandItem
92 wxTREE_EXPAND_COLLAPSE
,
93 wxTREE_EXPAND_COLLAPSE_RESET
,
97 // Flags for InsertItem
99 wxTREE_INSERT_LAST
= -1,
100 wxTREE_INSERT_FIRST
= -2,
101 wxTREE_INSERT_SORT
= -3
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
109 class WXDLLEXPORT wxTreeItem
: public wxObject
113 GtkWidget
*m_parentwidget
;
114 GtkTreeItem
*m_widget
;
128 wxTreeItem(GtkWidget
*parent
, const wxTreeItem
&item
);
133 void AddChild(wxTreeItem
*child
);
134 void DeleteChildren();
136 wxTreeItem
*FindItem(long itemId
) const;
137 wxTreeItem
*FindItem(GtkTreeItem
*item
) const;
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
; }
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
; }
160 int NumberOfVisibleDescendents();
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
);
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
);
178 inline wxTreeItem
*GetChild(long no
) {
179 return (wxTreeItem
*)(m_childlist
.Nth(no
)->Data());
181 inline long GetChildrenNumber() {
182 return m_childlist
.Number();
185 guint expand_handler
;
186 guint collapse_handler
;
188 // It is a quick hack to make TreeCtrl working... I do not know why
189 // but signals is GTK does not disconnected...
192 DECLARE_DYNAMIC_CLASS(wxTreeItem
)
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
199 class wxTreeCtrl
: public wxScrolledWindow
{
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" );
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");
216 int GetCount() const;
218 long InsertItem( long parent
, const wxString
& label
,
219 int image
= -1, int selImage
= -1,
220 long insertAfter
= wxTREE_INSERT_LAST
);
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();
228 bool ExpandItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_EXPAND
); }
229 bool ExpandItem( long item
, int action
);
231 bool CollapseItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_COLLAPSE
); }
232 bool ToggleItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_TOGGLE
); }
234 // is the item expanded now?
235 bool IsItemExpanded(long item
)
237 wxTreeItem
*pItem
= FindItem(item
);
238 return pItem
&& (pItem
->GetState() & wxTREE_STATE_EXPANDED
);
242 bool GetItem( wxTreeItem &info ) const;
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;
251 long GetSelection() const;
252 bool SelectItem( long item );
255 bool ItemHasChildren( long item
) const;
256 void SetIndent( int indent
);
257 int GetIndent() const;
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 );
267 wxTreeItem
*FindItem(GtkTreeItem
*item
) const;
269 wxImageList
*GetImageList(int which
= wxIMAGE_LIST_NORMAL
) const;
270 void SetImageList(wxImageList
*imageList
, int which
= wxIMAGE_LIST_NORMAL
);
273 // set the selection to the specified item generating appropriate event(s) if
275 void SelectItem(wxTreeItem
*item
, bool bDoEvents
= TRUE
);
277 wxTreeItem
*m_anchor
;
278 wxTreeItem
*m_current
;
282 wxImageList
*m_imageList
;
283 wxImageList
*m_smallImageList
;
285 void CalculateLevel( wxTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
286 void CalculatePositions();
287 wxTreeItem
*FindItem( long itemId
) const;
289 // DECLARE_EVENT_TABLE()
290 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
293 //-----------------------------------------------------------------------------
295 //-----------------------------------------------------------------------------
297 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
299 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
302 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
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
; }
316 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
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 },