]>
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__ | |
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 | ||
4efd7443 | 72 | #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON) |
c801d85f KB |
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); | |
64693098 JS |
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 GetSelectedImage(int selImage) { m_selectedImage = selImage; } | |
157 | inline void SetChildren(int children) { m_children = children; } | |
158 | inline void SetData(long data) { m_data = data; } | |
c801d85f KB |
159 | }; |
160 | ||
161 | //----------------------------------------------------------------------------- | |
162 | // wxTreeEvent | |
163 | //----------------------------------------------------------------------------- | |
164 | ||
165 | class WXDLLEXPORT wxTreeEvent: public wxCommandEvent | |
166 | { | |
167 | DECLARE_DYNAMIC_CLASS(wxTreeEvent) | |
168 | ||
169 | public: | |
64693098 | 170 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
c801d85f KB |
171 | |
172 | int m_code; | |
173 | wxTreeItem m_item; | |
174 | long m_oldItem; | |
175 | wxPoint m_pointDrag; | |
64693098 JS |
176 | |
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; } | |
c801d85f KB |
181 | }; |
182 | ||
183 | typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); | |
184 | ||
fe71f65c RR |
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 }, | |
c801d85f KB |
197 | |
198 | //----------------------------------------------------------------------------- | |
199 | // wxGenericTreeItem | |
200 | //----------------------------------------------------------------------------- | |
201 | ||
202 | class WXDLLEXPORT wxGenericTreeItem: public wxObject | |
203 | { | |
204 | DECLARE_DYNAMIC_CLASS(wxGenericTreeItem) | |
205 | ||
206 | public: | |
207 | ||
208 | long m_itemId; | |
209 | long m_state; | |
210 | wxString m_text; | |
211 | int m_image; | |
212 | int m_selectedImage; | |
213 | // int m_children; | |
214 | bool m_hasChildren; | |
215 | long m_data; | |
216 | ||
217 | int m_x,m_y; | |
218 | int m_height,m_width; | |
219 | int m_xCross,m_yCross; | |
220 | int m_level; | |
221 | wxList m_children; | |
222 | wxGenericTreeItem *m_parent; | |
223 | bool m_hasHilight; | |
224 | ||
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 ); | |
230 | void Reset(void); | |
231 | void GetItem( wxTreeItem &item ) const; | |
232 | void AddChild( const wxTreeItem &item ); | |
233 | bool HasChildren(void); | |
234 | bool HasPlus(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); | |
249 | }; | |
250 | ||
251 | //----------------------------------------------------------------------------- | |
252 | // wxTreeCtrl | |
253 | //----------------------------------------------------------------------------- | |
254 | ||
255 | class wxTreeCtrl: public wxScrolledWindow | |
256 | { | |
257 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
258 | ||
259 | public: | |
260 | ||
261 | wxTreeCtrl(void); | |
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" ); | |
267 | ~wxTreeCtrl(void); | |
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"); | |
273 | ||
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 ); | |
294 | ||
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 ); | |
302 | ||
303 | private: | |
304 | ||
305 | wxGenericTreeItem *m_anchor; | |
306 | wxGenericTreeItem *m_current; | |
307 | bool m_hasFocus; | |
308 | int m_xScroll,m_yScroll; | |
309 | int m_indent; | |
310 | long m_lastId; | |
311 | int m_lineHeight; | |
312 | wxPen m_dottedPen; | |
313 | bool m_isCreated; | |
314 | wxPaintDC *m_dc; | |
315 | wxBrush *m_hilightBrush; | |
316 | ||
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 ); | |
321 | ||
322 | DECLARE_EVENT_TABLE() | |
323 | }; | |
324 | ||
325 | #endif | |
326 | // __GTKTREECTRLH_G__ |