]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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__ | |
0d3820b3 | 16 | #pragma interface "treectrl.h" |
c801d85f KB |
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 | ||
74bedbeb VZ |
38 | class wxImageList; |
39 | ||
c801d85f KB |
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 | ||
4efd7443 | 74 | #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON) |
c801d85f KB |
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 | { | |
a32dd690 VZ |
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 | ||
c801d85f | 160 | DECLARE_DYNAMIC_CLASS(wxTreeItem) |
c801d85f KB |
161 | }; |
162 | ||
163 | //----------------------------------------------------------------------------- | |
164 | // wxTreeEvent | |
165 | //----------------------------------------------------------------------------- | |
166 | ||
167 | class WXDLLEXPORT wxTreeEvent: public wxCommandEvent | |
168 | { | |
169 | DECLARE_DYNAMIC_CLASS(wxTreeEvent) | |
170 | ||
171 | public: | |
64693098 | 172 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
c801d85f KB |
173 | |
174 | int m_code; | |
175 | wxTreeItem m_item; | |
176 | long m_oldItem; | |
177 | wxPoint m_pointDrag; | |
64693098 JS |
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; } | |
74bedbeb | 182 | inline void SetCode(int code) { m_code = code; } |
64693098 | 183 | inline int GetCode() const { return m_code; } |
c801d85f KB |
184 | }; |
185 | ||
186 | typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); | |
187 | ||
fe71f65c RR |
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 }, | |
4c681997 RR |
197 | #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
198 | #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
fe71f65c RR |
199 | #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
200 | #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
201 | #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
c801d85f KB |
202 | |
203 | //----------------------------------------------------------------------------- | |
204 | // wxGenericTreeItem | |
205 | //----------------------------------------------------------------------------- | |
206 | ||
74bedbeb | 207 | class WXDLLEXPORT wxGenericTreeItem: public wxTreeItem |
c801d85f KB |
208 | { |
209 | DECLARE_DYNAMIC_CLASS(wxGenericTreeItem) | |
c801d85f | 210 | |
74bedbeb VZ |
211 | public: |
212 | bool m_hasChildren, | |
213 | m_isCollapsed; | |
c801d85f KB |
214 | |
215 | int m_x,m_y; | |
216 | int m_height,m_width; | |
217 | int m_xCross,m_yCross; | |
218 | int m_level; | |
219 | wxList m_children; | |
220 | wxGenericTreeItem *m_parent; | |
221 | bool m_hasHilight; | |
74bedbeb | 222 | |
a32dd690 | 223 | wxGenericTreeItem() {}; |
c801d85f KB |
224 | wxGenericTreeItem( wxGenericTreeItem *parent ); |
225 | wxGenericTreeItem( wxGenericTreeItem *parent, const wxTreeItem& item, wxDC *dc ); | |
226 | void SetItem( const wxTreeItem &item, wxDC *dc ); | |
227 | void SetText( const wxString &text, wxDC *dc ); | |
a32dd690 | 228 | void Reset(); |
c801d85f KB |
229 | void GetItem( wxTreeItem &item ) const; |
230 | void AddChild( const wxTreeItem &item ); | |
a32dd690 VZ |
231 | bool HasChildren(); |
232 | bool HasPlus(); | |
233 | int NumberOfVisibleDescendents(); | |
234 | int NumberOfVisibleChildren(); | |
c801d85f KB |
235 | wxGenericTreeItem *FindItem( long itemId ) const; |
236 | void AddChild( wxGenericTreeItem *child ); | |
237 | void SetCross( int x, int y ); | |
238 | void GetSize( int &x, int &y ); | |
239 | long HitTest( const wxPoint& point, int &flags ); | |
240 | void PrepareEvent( wxTreeEvent &event ); | |
241 | void SendKeyDown( wxWindow *target ); | |
242 | void SendSelected( wxWindow *target ); | |
243 | void SendDelete( wxWindow *target ); | |
244 | void SendExpand( wxWindow *target ); | |
74bedbeb | 245 | void SendCollapse( wxWindow *target ); |
c801d85f | 246 | void SetHilight( bool set = TRUE ); |
a32dd690 | 247 | bool HasHilight(); |
74bedbeb | 248 | bool IsExpanded() const { return !m_isCollapsed; } |
c801d85f KB |
249 | }; |
250 | ||
251 | //----------------------------------------------------------------------------- | |
252 | // wxTreeCtrl | |
253 | //----------------------------------------------------------------------------- | |
254 | ||
255 | class wxTreeCtrl: public wxScrolledWindow | |
256 | { | |
a32dd690 VZ |
257 | public: |
258 | wxTreeCtrl(); | |
259 | wxTreeCtrl(wxWindow *parent, const wxWindowID id = -1, | |
260 | const wxPoint& pos = wxDefaultPosition, | |
261 | const wxSize& size = wxDefaultSize, | |
262 | long style = wxTR_HAS_BUTTONS, | |
263 | const wxString& name = "wxTreeCtrl" ); | |
264 | ~wxTreeCtrl(); | |
265 | bool Create(wxWindow *parent, const wxWindowID id = -1, | |
266 | const wxPoint& pos = wxDefaultPosition, | |
267 | const wxSize& size = wxDefaultSize, | |
268 | long style = wxTR_HAS_BUTTONS, | |
269 | const wxString& name = "wxTreeCtrl"); | |
270 | ||
271 | int GetCount() const; | |
272 | long InsertItem( long parent, const wxString& label, int image = -1, | |
273 | int selImage = -1, long insertAfter = wxTREE_INSERT_LAST ); | |
274 | long InsertItem( long parent, wxTreeItem &info, | |
275 | long insertAfter = wxTREE_INSERT_LAST ); | |
276 | void DeleteItem( long item ); | |
4c681997 | 277 | void DeleteChildren( long item ); |
a32dd690 | 278 | bool DeleteAllItems(); |
e2414cbe RR |
279 | bool ExpandItem(long item) { return ExpandItem(item, wxTREE_EXPAND_EXPAND); } |
280 | bool CollapseItem(long item) { return ExpandItem(item, wxTREE_EXPAND_COLLAPSE); } | |
281 | bool ToggleItem(long item) { return ExpandItem(item, wxTREE_EXPAND_TOGGLE); } | |
a32dd690 | 282 | bool ExpandItem( long item, int action ); |
43fa96a8 VZ |
283 | |
284 | // is the item expanded now? | |
285 | bool IsItemExpanded(long item) | |
286 | { | |
287 | wxGenericTreeItem *pItem = FindItem(item); | |
288 | return pItem && (pItem->GetState() & wxTREE_STATE_EXPANDED); | |
289 | } | |
290 | ||
a32dd690 VZ |
291 | bool GetItem( wxTreeItem &info ) const; |
292 | long GetItemData( long item ) const; | |
293 | wxString GetItemText( long item ) const; | |
294 | int GetItemImage(long item) const; | |
295 | long GetParent( long item ) const; | |
296 | long GetRootItem() const; | |
297 | long GetSelection() const; | |
389cdc7a | 298 | bool SelectItem( long item ); |
a32dd690 VZ |
299 | bool ItemHasChildren( long item ) const; |
300 | void SetIndent( int indent ); | |
301 | int GetIndent() const; | |
302 | bool SetItem( wxTreeItem &info ); | |
303 | bool SetItemData( long item, long data ); | |
304 | bool SetItemText( long item, const wxString &text ); | |
305 | void SetItemImage(long item, int image, int imageSel) const; | |
306 | long HitTest( const wxPoint& point, int &flags ); | |
307 | ||
308 | void AdjustMyScrollbars(); | |
309 | void PaintLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, int &y ); | |
310 | void OnPaint( const wxPaintEvent &event ); | |
311 | void OnSetFocus( const wxFocusEvent &event ); | |
312 | void OnKillFocus( const wxFocusEvent &event ); | |
313 | void OnChar( wxKeyEvent &event ); | |
314 | void OnMouse( const wxMouseEvent &event ); | |
315 | ||
e2414cbe RR |
316 | wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const; |
317 | void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL); | |
43fa96a8 | 318 | |
a32dd690 | 319 | private: |
c614ed58 VZ |
320 | // set the selection to the specified item generating appropriate event(s) |
321 | void SelectItem(wxGenericTreeItem *item); | |
389cdc7a | 322 | |
a32dd690 VZ |
323 | wxGenericTreeItem *m_anchor; |
324 | wxGenericTreeItem *m_current; | |
325 | bool m_hasFocus; | |
326 | int m_xScroll,m_yScroll; | |
327 | int m_indent; | |
328 | long m_lastId; | |
329 | int m_lineHeight; | |
330 | wxPen m_dottedPen; | |
331 | bool m_isCreated; | |
a32dd690 VZ |
332 | wxBrush *m_hilightBrush; |
333 | wxImageList *m_imageList; | |
e2414cbe | 334 | wxImageList *m_smallImageList; |
a32dd690 VZ |
335 | |
336 | void CalculateLevel( wxGenericTreeItem *item, wxPaintDC &dc, int level, int &y ); | |
337 | void CalculatePositions(); | |
338 | wxGenericTreeItem *FindItem( long itemId ) const; | |
339 | void RefreshLine( wxGenericTreeItem *item ); | |
74bedbeb | 340 | |
c801d85f | 341 | DECLARE_EVENT_TABLE() |
a32dd690 | 342 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) |
c801d85f KB |
343 | }; |
344 | ||
345 | #endif | |
346 | // __GTKTREECTRLH_G__ |