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__
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
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 // WXDLLEXPORT extern const char *wxTreeNameStr;
44 #define wxTREE_MASK_HANDLE 0x0001
45 #define wxTREE_MASK_STATE 0x0002
46 #define wxTREE_MASK_TEXT 0x0004
47 #define wxTREE_MASK_IMAGE 0x0008
48 #define wxTREE_MASK_SELECTED_IMAGE 0x0010
49 #define wxTREE_MASK_CHILDREN 0x0020
50 #define wxTREE_MASK_DATA 0x0040
52 #define wxTREE_STATE_BOLD 0x0001
53 #define wxTREE_STATE_DROPHILITED 0x0002
54 #define wxTREE_STATE_EXPANDED 0x0004
55 #define wxTREE_STATE_EXPANDEDONCE 0x0008
56 #define wxTREE_STATE_FOCUSED 0x0010
57 #define wxTREE_STATE_SELECTED 0x0020
58 #define wxTREE_STATE_CUT 0x0040
60 #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area.
61 #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area.
62 #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
63 #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item.
64 #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
65 #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item.
66 #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
67 #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
68 #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
69 #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area.
70 #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area.
72 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
74 // Flags for GetNextItem
76 wxTREE_NEXT_CARET
, // Retrieves the currently selected item.
77 wxTREE_NEXT_CHILD
, // Retrieves the first child item. The hItem parameter must be NULL.
78 wxTREE_NEXT_DROPHILITE
, // Retrieves the item that is the target of a drag-and-drop operation.
79 wxTREE_NEXT_FIRSTVISIBLE
, // Retrieves the first visible item.
80 wxTREE_NEXT_NEXT
, // Retrieves the next sibling item.
81 wxTREE_NEXT_NEXTVISIBLE
, // Retrieves the next visible item that follows the specified item.
82 wxTREE_NEXT_PARENT
, // Retrieves the parent of the specified item.
83 wxTREE_NEXT_PREVIOUS
, // Retrieves the previous sibling item.
84 wxTREE_NEXT_PREVIOUSVISIBLE
, // Retrieves the first visible item that precedes the specified item.
85 wxTREE_NEXT_ROOT
// Retrieves the first child item of the root item of which the specified item is a part.
88 // Flags for ExpandItem
91 wxTREE_EXPAND_COLLAPSE
,
92 wxTREE_EXPAND_COLLAPSE_RESET
,
96 // Flags for InsertItem
98 wxTREE_INSERT_LAST
= -1,
99 wxTREE_INSERT_FIRST
= -2,
100 wxTREE_INSERT_SORT
= -3
103 /* defined in "wx/event.h"
104 wxEVT_COMMAND_TREE_BEGIN_DRAG,
105 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
106 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
107 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
108 wxEVT_COMMAND_TREE_DELETE_ITEM,
109 wxEVT_COMMAND_TREE_GET_INFO,
110 wxEVT_COMMAND_TREE_SET_INFO,
111 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
112 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
113 wxEVT_COMMAND_TREE_SEL_CHANGED,
114 wxEVT_COMMAND_TREE_SEL_CHANGING,
115 wxEVT_COMMAND_TREE_KEY_DOWN
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
122 class WXDLLEXPORT wxTreeItem
: public wxObject
124 DECLARE_DYNAMIC_CLASS(wxTreeItem
)
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 GetSelectedImage(int selImage
) { m_selectedImage
= selImage
; }
157 inline void SetChildren(int children
) { m_children
= children
; }
158 inline void SetData(long data
) { m_data
= data
; }
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
165 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
167 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
170 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
177 inline long GetOldItem() const { return m_oldItem
; }
178 inline wxTreeItem
& GetItem() const { return (wxTreeItem
&) m_item
; }
179 inline wxPoint
GetPoint() const { return m_pointDrag
; }
180 inline int GetCode() const { return m_code
; }
183 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
185 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
186 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
187 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
188 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
189 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
190 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
191 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
192 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
193 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
194 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
195 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
196 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 class WXDLLEXPORT wxGenericTreeItem
: public wxObject
204 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem
)
218 int m_height
,m_width
;
219 int m_xCross
,m_yCross
;
222 wxGenericTreeItem
*m_parent
;
225 wxGenericTreeItem(void) {};
226 wxGenericTreeItem( wxGenericTreeItem
*parent
);
227 wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
);
228 void SetItem( const wxTreeItem
&item
, wxDC
*dc
);
229 void SetText( const wxString
&text
, wxDC
*dc
);
231 void GetItem( wxTreeItem
&item
) const;
232 void AddChild( const wxTreeItem
&item
);
233 bool HasChildren(void);
235 int NumberOfVisibleDescendents(void);
236 int NumberOfVisibleChildren(void);
237 wxGenericTreeItem
*FindItem( long itemId
) const;
238 void AddChild( wxGenericTreeItem
*child
);
239 void SetCross( int x
, int y
);
240 void GetSize( int &x
, int &y
);
241 long HitTest( const wxPoint
& point
, int &flags
);
242 void PrepareEvent( wxTreeEvent
&event
);
243 void SendKeyDown( wxWindow
*target
);
244 void SendSelected( wxWindow
*target
);
245 void SendDelete( wxWindow
*target
);
246 void SendExpand( wxWindow
*target
);
247 void SetHilight( bool set
= TRUE
);
248 bool HasHilight(void);
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
255 class wxTreeCtrl
: public wxScrolledWindow
257 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
262 wxTreeCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
263 const wxPoint
& pos
= wxDefaultPosition
,
264 const wxSize
& size
= wxDefaultSize
,
265 const long style
= wxTR_HAS_BUTTONS
,
266 const wxString
& name
= "wxTreeCtrl" );
268 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
269 const wxPoint
& pos
= wxDefaultPosition
,
270 const wxSize
& size
= wxDefaultSize
,
271 const long style
= wxTR_HAS_BUTTONS
,
272 const wxString
& name
= "wxTreeCtrl");
274 int GetCount(void) const;
275 long InsertItem( const long parent
, const wxString
& label
, const int image
= -1,
276 const int selImage
= -1, const long insertAfter
= wxTREE_INSERT_LAST
);
277 long InsertItem( const long parent
, wxTreeItem
&info
, const long insertAfter
= wxTREE_INSERT_LAST
);
278 bool DeleteAllItems(void);
279 bool ExpandItem( const long item
, const int action
);
280 bool GetItem( wxTreeItem
&info
) const;
281 long GetItemData( const long item
) const;
282 wxString
GetItemText( const long item
) const;
283 long GetParent( const long item
) const;
284 long GetRootItem(void) const;
285 long GetSelection(void) const;
286 bool SelectItem( const long item
) const;
287 bool ItemHasChildren( const long item
) const;
288 void SetIndent( const int indent
);
289 int GetIndent(void) const;
290 bool SetItem( wxTreeItem
&info
);
291 bool SetItemData( const long item
, const long data
);
292 bool SetItemText( const long item
, const wxString
&text
);
293 long HitTest( const wxPoint
& point
, int &flags
);
295 void AdjustMyScrollbars(void);
296 void PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
297 void OnPaint( const wxPaintEvent
&event
);
298 void OnSetFocus( const wxFocusEvent
&event
);
299 void OnKillFocus( const wxFocusEvent
&event
);
300 void OnChar( wxKeyEvent
&event
);
301 void OnMouse( const wxMouseEvent
&event
);
305 wxGenericTreeItem
*m_anchor
;
306 wxGenericTreeItem
*m_current
;
308 int m_xScroll
,m_yScroll
;
315 wxBrush
*m_hilightBrush
;
317 void CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
318 void CalculatePositions(void);
319 wxGenericTreeItem
*FindItem( const long itemId
) const;
320 void RefreshLine( wxGenericTreeItem
*item
);
322 DECLARE_EVENT_TABLE()
326 // __GTKTREECTRLH_G__