2 * Author: Robert Roebling
4 * Copyright: (C) 1997,1998 Robert Roebling
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).
12 #ifndef __GTKTREECTRLH_G__
13 #define __GTKTREECTRLH_G__
16 #pragma interface "treectrl.h"
20 #include "wx/string.h"
22 #include "wx/control.h"
24 #include "wx/imaglist.h"
25 #include "wx/scrolwin.h"
26 #include "wx/dcclient.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
35 class wxGenericTreeItem
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 // WXDLLEXPORT extern const char *wxTreeNameStr;
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
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
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.
74 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
76 // Flags for GetNextItem
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.
90 // Flags for ExpandItem
93 wxTREE_EXPAND_COLLAPSE
,
94 wxTREE_EXPAND_COLLAPSE_RESET
,
98 // Flags for InsertItem
100 wxTREE_INSERT_LAST
= -1,
101 wxTREE_INSERT_FIRST
= -2,
102 wxTREE_INSERT_SORT
= -3
105 /* defined in "wx/event.h"
106 wxEVT_COMMAND_TREE_BEGIN_DRAG,
107 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
108 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
109 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
110 wxEVT_COMMAND_TREE_DELETE_ITEM,
111 wxEVT_COMMAND_TREE_GET_INFO,
112 wxEVT_COMMAND_TREE_SET_INFO,
113 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
114 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
115 wxEVT_COMMAND_TREE_SEL_CHANGED,
116 wxEVT_COMMAND_TREE_SEL_CHANGING,
117 wxEVT_COMMAND_TREE_KEY_DOWN
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
124 class WXDLLEXPORT wxTreeItem
: public wxObject
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 int GetChildren() const { return m_children
; }
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(int children
) { m_children
= children
; }
158 inline void SetData(long data
) { m_data
= data
; }
160 DECLARE_DYNAMIC_CLASS(wxTreeItem
)
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
167 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
169 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
172 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
179 inline long GetOldItem() const { return m_oldItem
; }
180 inline wxTreeItem
& GetItem() const { return (wxTreeItem
&) m_item
; }
181 inline wxPoint
GetPoint() const { return m_pointDrag
; }
182 inline void SetCode(int code
) { m_code
= code
; }
183 inline int GetCode() const { return m_code
; }
186 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
188 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
189 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
190 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
191 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
192 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
193 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
194 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
195 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
196 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
197 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
198 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
199 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
200 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
201 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
203 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
207 class WXDLLEXPORT wxGenericTreeItem
: public wxTreeItem
209 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem
)
216 int m_height
,m_width
;
217 int m_xCross
,m_yCross
;
220 wxGenericTreeItem
*m_parent
;
223 wxGenericTreeItem() {};
224 wxGenericTreeItem( wxGenericTreeItem
*parent
);
225 wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
);
226 void SetItem( const wxTreeItem
&item
, wxDC
*dc
);
227 void SetText( const wxString
&text
, wxDC
*dc
);
229 void GetItem( wxTreeItem
&item
) const;
230 void AddChild( const wxTreeItem
&item
);
233 int NumberOfVisibleDescendents();
234 int NumberOfVisibleChildren();
235 wxGenericTreeItem
*FindItem( long itemId
) const;
236 void AddChild( wxGenericTreeItem
*child
);
237 void SetCross( int x
, int y
);
238 void GetSize( int &x
, int &y
);
239 long HitTest( const wxPoint
& point
, int &flags
);
240 void PrepareEvent( wxTreeEvent
&event
);
241 void SendKeyDown( wxWindow
*target
);
242 void SendSelected( wxWindow
*target
);
243 void SendDelete( wxWindow
*target
);
244 void SendExpand( wxWindow
*target
);
245 void SendCollapse( wxWindow
*target
);
246 void SetHilight( bool set
= TRUE
);
248 bool IsExpanded() const { return !m_isCollapsed
; }
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
255 class wxTreeCtrl
: public wxScrolledWindow
259 wxTreeCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
260 const wxPoint
& pos
= wxDefaultPosition
,
261 const wxSize
& size
= wxDefaultSize
,
262 long style
= wxTR_HAS_BUTTONS
,
263 const wxString
& name
= "wxTreeCtrl" );
265 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
266 const wxPoint
& pos
= wxDefaultPosition
,
267 const wxSize
& size
= wxDefaultSize
,
268 long style
= wxTR_HAS_BUTTONS
,
269 const wxString
& name
= "wxTreeCtrl");
271 int GetCount() const;
272 long InsertItem( long parent
, const wxString
& label
, int image
= -1,
273 int selImage
= -1, long insertAfter
= wxTREE_INSERT_LAST
);
274 long InsertItem( long parent
, wxTreeItem
&info
,
275 long insertAfter
= wxTREE_INSERT_LAST
);
276 void DeleteItem( long item
);
277 void DeleteChildren( long item
);
278 bool DeleteAllItems();
279 bool ExpandItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_EXPAND
); }
280 bool CollapseItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_COLLAPSE
); }
281 bool ToggleItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_TOGGLE
); }
282 bool ExpandItem( long item
, int action
);
284 // is the item expanded now?
285 bool IsItemExpanded(long item
)
287 wxGenericTreeItem
*pItem
= FindItem(item
);
288 return pItem
&& (pItem
->GetState() & wxTREE_STATE_EXPANDED
);
291 bool GetItem( wxTreeItem
&info
) const;
292 long GetItemData( long item
) const;
293 wxString
GetItemText( long item
) const;
294 int GetItemImage(long item
) const;
295 long GetParent( long item
) const;
296 long GetRootItem() const;
297 long GetChild(long item
) const;
298 long GetNextItem(long item
, int code
) const;
299 long GetSelection() const;
300 bool SelectItem( long item
);
301 bool ItemHasChildren( long item
) const;
302 void SetIndent( int indent
);
303 int GetIndent() const;
304 bool SetItem( wxTreeItem
&info
);
305 bool SetItemData( long item
, long data
);
306 bool SetItemText( long item
, const wxString
&text
);
307 void SetItemImage(long item
, int image
, int imageSel
) const;
308 long HitTest( const wxPoint
& point
, int &flags
);
310 int GetItemState(long item
, long stateMask
) const;
311 bool SetItemState(long item
, long state
, long stateMask
);
313 void AdjustMyScrollbars();
314 void PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
);
315 void OnPaint( const wxPaintEvent
&event
);
316 void OnSetFocus( const wxFocusEvent
&event
);
317 void OnKillFocus( const wxFocusEvent
&event
);
318 void OnChar( wxKeyEvent
&event
);
319 void OnMouse( const wxMouseEvent
&event
);
321 wxImageList
*GetImageList(int which
= wxIMAGE_LIST_NORMAL
) const;
322 void SetImageList(wxImageList
*imageList
, int which
= wxIMAGE_LIST_NORMAL
);
325 // set the selection to the specified item generating appropriate event(s)
326 void SelectItem(wxGenericTreeItem
*item
);
328 wxGenericTreeItem
*m_anchor
;
329 wxGenericTreeItem
*m_current
;
331 int m_xScroll
,m_yScroll
;
337 wxBrush
*m_hilightBrush
;
338 wxImageList
*m_imageList
;
339 wxImageList
*m_smallImageList
;
341 void CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
);
342 void CalculatePositions();
343 wxGenericTreeItem
*FindItem( long itemId
) const;
344 void RefreshLine( wxGenericTreeItem
*item
);
346 DECLARE_EVENT_TABLE()
347 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
351 // __GTKTREECTRLH_G__