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 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
144 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
146 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
149 wxTreeEvent(WXTYPE commandType
= 0, int id
= 0);
157 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
159 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
160 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
161 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
162 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
163 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
164 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
165 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
166 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
167 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
168 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
169 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
170 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
172 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
176 class WXDLLEXPORT wxGenericTreeItem
: public wxObject
178 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem
)
192 int m_height
,m_width
;
193 int m_xCross
,m_yCross
;
196 wxGenericTreeItem
*m_parent
;
199 wxGenericTreeItem(void) {};
200 wxGenericTreeItem( wxGenericTreeItem
*parent
);
201 wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
);
202 void SetItem( const wxTreeItem
&item
, wxDC
*dc
);
203 void SetText( const wxString
&text
, wxDC
*dc
);
205 void GetItem( wxTreeItem
&item
) const;
206 void AddChild( const wxTreeItem
&item
);
207 bool HasChildren(void);
209 int NumberOfVisibleDescendents(void);
210 int NumberOfVisibleChildren(void);
211 wxGenericTreeItem
*FindItem( long itemId
) const;
212 void AddChild( wxGenericTreeItem
*child
);
213 void SetCross( int x
, int y
);
214 void GetSize( int &x
, int &y
);
215 long HitTest( const wxPoint
& point
, int &flags
);
216 void PrepareEvent( wxTreeEvent
&event
);
217 void SendKeyDown( wxWindow
*target
);
218 void SendSelected( wxWindow
*target
);
219 void SendDelete( wxWindow
*target
);
220 void SendExpand( wxWindow
*target
);
221 void SetHilight( bool set
= TRUE
);
222 bool HasHilight(void);
225 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
229 class wxTreeCtrl
: public wxScrolledWindow
231 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
236 wxTreeCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
237 const wxPoint
& pos
= wxDefaultPosition
,
238 const wxSize
& size
= wxDefaultSize
,
239 const long style
= wxTR_HAS_BUTTONS
,
240 const wxString
& name
= "wxTreeCtrl" );
242 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
243 const wxPoint
& pos
= wxDefaultPosition
,
244 const wxSize
& size
= wxDefaultSize
,
245 const long style
= wxTR_HAS_BUTTONS
,
246 const wxString
& name
= "wxTreeCtrl");
248 int GetCount(void) const;
249 long InsertItem( const long parent
, const wxString
& label
, const int image
= -1,
250 const int selImage
= -1, const long insertAfter
= wxTREE_INSERT_LAST
);
251 long InsertItem( const long parent
, wxTreeItem
&info
, const long insertAfter
= wxTREE_INSERT_LAST
);
252 bool DeleteAllItems(void);
253 bool ExpandItem( const long item
, const int action
);
254 bool GetItem( wxTreeItem
&info
) const;
255 long GetItemData( const long item
) const;
256 wxString
GetItemText( const long item
) const;
257 long GetParent( const long item
) const;
258 long GetRootItem(void) const;
259 long GetSelection(void) const;
260 bool SelectItem( const long item
) const;
261 bool ItemHasChildren( const long item
) const;
262 void SetIndent( const int indent
);
263 int GetIndent(void) const;
264 bool SetItem( wxTreeItem
&info
);
265 bool SetItemData( const long item
, const long data
);
266 bool SetItemText( const long item
, const wxString
&text
);
267 long HitTest( const wxPoint
& point
, int &flags
);
269 void AdjustMyScrollbars(void);
270 void PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
271 void OnPaint( const wxPaintEvent
&event
);
272 void OnSetFocus( const wxFocusEvent
&event
);
273 void OnKillFocus( const wxFocusEvent
&event
);
274 void OnChar( wxKeyEvent
&event
);
275 void OnMouse( const wxMouseEvent
&event
);
279 wxGenericTreeItem
*m_anchor
;
280 wxGenericTreeItem
*m_current
;
282 int m_xScroll
,m_yScroll
;
289 wxBrush
*m_hilightBrush
;
291 void CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
);
292 void CalculatePositions(void);
293 wxGenericTreeItem
*FindItem( const long itemId
) const;
294 void RefreshLine( wxGenericTreeItem
*item
);
296 DECLARE_EVENT_TABLE()
300 // __GTKTREECTRLH_G__