]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/treectrl.h
Changed __GTK__, __WINDOWS__ and __MOTIF__ to __WXGTK__, __WXMSW__ and __WXMOTIF__
[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 "treectrl.h"
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 class wxImageList;
39
40 //-----------------------------------------------------------------------------
41 // constants
42 //-----------------------------------------------------------------------------
43
44 // WXDLLEXPORT extern const char *wxTreeNameStr;
45
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
53
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
61
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.
73
74 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
75
76 // Flags for GetNextItem
77 enum {
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.
88 };
89
90 // Flags for ExpandItem
91 enum {
92 wxTREE_EXPAND_EXPAND,
93 wxTREE_EXPAND_COLLAPSE,
94 wxTREE_EXPAND_COLLAPSE_RESET,
95 wxTREE_EXPAND_TOGGLE
96 };
97
98 // Flags for InsertItem
99 enum {
100 wxTREE_INSERT_LAST = -1,
101 wxTREE_INSERT_FIRST = -2,
102 wxTREE_INSERT_SORT = -3
103 };
104
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
118 */
119
120 //-----------------------------------------------------------------------------
121 // wxTreeItem
122 //-----------------------------------------------------------------------------
123
124 class WXDLLEXPORT wxTreeItem: public wxObject
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();
138
139 // Accessors
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; }
149
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; }
159
160 DECLARE_DYNAMIC_CLASS(wxTreeItem)
161 };
162
163 //-----------------------------------------------------------------------------
164 // wxTreeEvent
165 //-----------------------------------------------------------------------------
166
167 class WXDLLEXPORT wxTreeEvent: public wxCommandEvent
168 {
169 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
170
171 public:
172 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
173
174 int m_code;
175 wxTreeItem m_item;
176 long m_oldItem;
177 wxPoint m_pointDrag;
178
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; }
184 };
185
186 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
187
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 },
200
201 //-----------------------------------------------------------------------------
202 // wxGenericTreeItem
203 //-----------------------------------------------------------------------------
204
205 class WXDLLEXPORT wxGenericTreeItem: public wxTreeItem
206 {
207 DECLARE_DYNAMIC_CLASS(wxGenericTreeItem)
208
209 public:
210 bool m_hasChildren,
211 m_isCollapsed;
212
213 int m_x,m_y;
214 int m_height,m_width;
215 int m_xCross,m_yCross;
216 int m_level;
217 wxList m_children;
218 wxGenericTreeItem *m_parent;
219 bool m_hasHilight;
220
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 );
226 void Reset();
227 void GetItem( wxTreeItem &item ) const;
228 void AddChild( const wxTreeItem &item );
229 bool HasChildren();
230 bool HasPlus();
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 );
245 bool HasHilight();
246 bool IsExpanded() const { return !m_isCollapsed; }
247 };
248
249 //-----------------------------------------------------------------------------
250 // wxTreeCtrl
251 //-----------------------------------------------------------------------------
252
253 class wxTreeCtrl: public wxScrolledWindow
254 {
255 public:
256 wxTreeCtrl();
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" );
262 ~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");
268
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 );
293
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 );
301
302 void SetImageList(wxImageList *imageList) { m_imageList = imageList; }
303 wxImageList *GetImageList() const { return m_imageList; }
304
305 private:
306 wxGenericTreeItem *m_anchor;
307 wxGenericTreeItem *m_current;
308 bool m_hasFocus;
309 int m_xScroll,m_yScroll;
310 int m_indent;
311 long m_lastId;
312 int m_lineHeight;
313 wxPen m_dottedPen;
314 bool m_isCreated;
315 wxPaintDC *m_dc;
316 wxBrush *m_hilightBrush;
317 wxImageList *m_imageList;
318
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 );
323
324 DECLARE_EVENT_TABLE()
325 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
326 };
327
328 #endif
329 // __GTKTREECTRLH_G__