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, NULL },
189 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
190 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
191 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
192 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
193 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
194 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
195 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
196 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
197 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
198 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
199 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
201 //-----------------------------------------------------------------------------
203 //-----------------------------------------------------------------------------
205 class WXDLLEXPORT wxGenericTreeItem
: public wxTreeItem
207 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem
)
214 int m_height
,m_width
;
215 int m_xCross
,m_yCross
;
218 wxGenericTreeItem
*m_parent
;
221 wxGenericTreeItem() {};
222 wxGenericTreeItem( wxGenericTreeItem
*parent
);
223 wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
);
224 void SetItem( const wxTreeItem
&item
, wxDC
*dc
);
225 void SetText( const wxString
&text
, wxDC
*dc
);
227 void GetItem( wxTreeItem
&item
) const;
228 void AddChild( const wxTreeItem
&item
);
231 int NumberOfVisibleDescendents();
232 int NumberOfVisibleChildren();
233 wxGenericTreeItem
*FindItem( long itemId
) const;
234 void AddChild( wxGenericTreeItem
*child
);
235 void SetCross( int x
, int y
);
236 void GetSize( int &x
, int &y
);
237 long HitTest( const wxPoint
& point
, int &flags
);
238 void PrepareEvent( wxTreeEvent
&event
);
239 void SendKeyDown( wxWindow
*target
);
240 void SendSelected( wxWindow
*target
);
241 void SendDelete( wxWindow
*target
);
242 void SendExpand( wxWindow
*target
);
243 void SendCollapse( wxWindow
*target
);
244 void SetHilight( bool set
= TRUE
);
246 bool IsExpanded() const { return !m_isCollapsed
; }
249 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
253 class wxTreeCtrl
: public wxScrolledWindow
257 wxTreeCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
258 const wxPoint
& pos
= wxDefaultPosition
,
259 const wxSize
& size
= wxDefaultSize
,
260 long style
= wxTR_HAS_BUTTONS
,
261 const wxString
& name
= "wxTreeCtrl" );
263 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
264 const wxPoint
& pos
= wxDefaultPosition
,
265 const wxSize
& size
= wxDefaultSize
,
266 long style
= wxTR_HAS_BUTTONS
,
267 const wxString
& name
= "wxTreeCtrl");
269 int GetCount() const;
270 long InsertItem( long parent
, const wxString
& label
, int image
= -1,
271 int selImage
= -1, long insertAfter
= wxTREE_INSERT_LAST
);
272 long InsertItem( long parent
, wxTreeItem
&info
,
273 long insertAfter
= wxTREE_INSERT_LAST
);
274 void DeleteItem( long item
);
275 bool DeleteAllItems();
276 bool ExpandItem( long item
, int action
);
277 bool GetItem( wxTreeItem
&info
) const;
278 long GetItemData( long item
) const;
279 wxString
GetItemText( long item
) const;
280 int GetItemImage(long item
) const;
281 long GetParent( long item
) const;
282 long GetRootItem() const;
283 long GetSelection() const;
284 bool SelectItem( long item
) const;
285 bool ItemHasChildren( long item
) const;
286 void SetIndent( int indent
);
287 int GetIndent() const;
288 bool SetItem( wxTreeItem
&info
);
289 bool SetItemData( long item
, long data
);
290 bool SetItemText( long item
, const wxString
&text
);
291 void SetItemImage(long item
, int image
, int imageSel
) const;
292 long HitTest( const wxPoint
& point
, int &flags
);
294 void AdjustMyScrollbars();
295 void PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
296 void OnPaint( const wxPaintEvent
&event
);
297 void OnSetFocus( const wxFocusEvent
&event
);
298 void OnKillFocus( const wxFocusEvent
&event
);
299 void OnChar( wxKeyEvent
&event
);
300 void OnMouse( const wxMouseEvent
&event
);
302 void SetImageList(wxImageList
*imageList
) { m_imageList
= imageList
; }
303 wxImageList
*GetImageList() const { return m_imageList
; }
306 wxGenericTreeItem
*m_anchor
;
307 wxGenericTreeItem
*m_current
;
309 int m_xScroll
,m_yScroll
;
316 wxBrush
*m_hilightBrush
;
317 wxImageList
*m_imageList
;
319 void CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
320 void CalculatePositions();
321 wxGenericTreeItem
*FindItem( long itemId
) const;
322 void RefreshLine( wxGenericTreeItem
*item
);
324 DECLARE_EVENT_TABLE()
325 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
329 // __GTKTREECTRLH_G__