]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/treectrl.h
added notebook events: wxEVT_COMMAND_NOTEBOOK_PAGE_CHANG(ED|ING)
[wxWidgets.git] / include / wx / generic / treectrl.h
1 /*
2 * Author: Robert Roebling
3 *
4 * Copyright: (C) 1997,1998 Robert Roebling
5 *
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).
9 *
10 */
11
12 #ifndef __GTKTREECTRLH_G__
13 #define __GTKTREECTRLH_G__
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21 #include "wx/list.h"
22 #include "wx/control.h"
23 #include "wx/event.h"
24 #include "wx/imaglist.h"
25 #include "wx/scrolwin.h"
26 #include "wx/dcclient.h"
27
28 //-----------------------------------------------------------------------------
29 // classes
30 //-----------------------------------------------------------------------------
31
32 class wxTreeItem;
33 class wxTreeEvent;
34
35 class wxGenericTreeItem;
36 class wxTreeCtrl;
37
38 //-----------------------------------------------------------------------------
39 // constants
40 //-----------------------------------------------------------------------------
41
42 // WXDLLEXPORT extern const char *wxTreeNameStr;
43
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
51
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
59
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.
71
72 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
73
74 // Flags for GetNextItem
75 enum {
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.
86 };
87
88 // Flags for ExpandItem
89 enum {
90 wxTREE_EXPAND_EXPAND,
91 wxTREE_EXPAND_COLLAPSE,
92 wxTREE_EXPAND_COLLAPSE_RESET,
93 wxTREE_EXPAND_TOGGLE
94 };
95
96 // Flags for InsertItem
97 enum {
98 wxTREE_INSERT_LAST = -1,
99 wxTREE_INSERT_FIRST = -2,
100 wxTREE_INSERT_SORT = -3
101 };
102
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
116 */
117
118 //-----------------------------------------------------------------------------
119 // wxTreeItem
120 //-----------------------------------------------------------------------------
121
122 class WXDLLEXPORT wxTreeItem: public wxObject
123 {
124 DECLARE_DYNAMIC_CLASS(wxTreeItem)
125
126 public:
127 long m_mask;
128 long m_itemId;
129 long m_state;
130 long m_stateMask;
131 wxString m_text;
132 int m_image;
133 int m_selectedImage;
134 int m_children;
135 long m_data;
136
137 wxTreeItem(void);
138 };
139
140 //-----------------------------------------------------------------------------
141 // wxTreeEvent
142 //-----------------------------------------------------------------------------
143
144 class WXDLLEXPORT wxTreeEvent: public wxCommandEvent
145 {
146 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
147
148 public:
149 wxTreeEvent(WXTYPE commandType = 0, int id = 0);
150
151 int m_code;
152 wxTreeItem m_item;
153 long m_oldItem;
154 wxPoint m_pointDrag;
155 };
156
157 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
158
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 },
171
172 //-----------------------------------------------------------------------------
173 // wxGenericTreeItem
174 //-----------------------------------------------------------------------------
175
176 class WXDLLEXPORT wxGenericTreeItem: public wxObject
177 {
178 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem)
179
180 public:
181
182 long m_itemId;
183 long m_state;
184 wxString m_text;
185 int m_image;
186 int m_selectedImage;
187 // int m_children;
188 bool m_hasChildren;
189 long m_data;
190
191 int m_x,m_y;
192 int m_height,m_width;
193 int m_xCross,m_yCross;
194 int m_level;
195 wxList m_children;
196 wxGenericTreeItem *m_parent;
197 bool m_hasHilight;
198
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 );
204 void Reset(void);
205 void GetItem( wxTreeItem &item ) const;
206 void AddChild( const wxTreeItem &item );
207 bool HasChildren(void);
208 bool HasPlus(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);
223 };
224
225 //-----------------------------------------------------------------------------
226 // wxTreeCtrl
227 //-----------------------------------------------------------------------------
228
229 class wxTreeCtrl: public wxScrolledWindow
230 {
231 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
232
233 public:
234
235 wxTreeCtrl(void);
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" );
241 ~wxTreeCtrl(void);
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");
247
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 );
268
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 );
276
277 private:
278
279 wxGenericTreeItem *m_anchor;
280 wxGenericTreeItem *m_current;
281 bool m_hasFocus;
282 int m_xScroll,m_yScroll;
283 int m_indent;
284 long m_lastId;
285 int m_lineHeight;
286 wxPen m_dottedPen;
287 bool m_isCreated;
288 wxPaintDC *m_dc;
289 wxBrush *m_hilightBrush;
290
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 );
295
296 DECLARE_EVENT_TABLE()
297 };
298
299 #endif
300 // __GTKTREECTRLH_G__