]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/treectrl.h
nested iterator classes must be dll-exported
[wxWidgets.git] / include / wx / msw / treectrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/treectrl.h
3 // Purpose: wxTreeCtrl class
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TREECTRL_H_
13 #define _WX_TREECTRL_H_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #if wxUSE_TREECTRL
20
21 #include "wx/textctrl.h"
22 #include "wx/dynarray.h"
23 #include "wx/treebase.h"
24 #include "wx/hashmap.h"
25
26 #ifdef __GNUWIN32__
27 // Cygwin windows.h defines these identifiers
28 #undef GetFirstChild
29 #undef GetNextSibling
30 #endif // Cygwin
31
32 // fwd decl
33 class WXDLLEXPORT wxImageList;
34 class WXDLLEXPORT wxDragImage;
35 struct WXDLLEXPORT wxTreeViewItem;
36
37 // NB: all the following flags are for compatbility only and will be removed in the
38 // next versions
39
40 // flags for deprecated InsertItem() variant (their values are the same as of
41 // TVI_FIRST and TVI_LAST)
42 #define wxTREE_INSERT_FIRST 0xFFFF0001
43 #define wxTREE_INSERT_LAST 0xFFFF0002
44
45 // hash storing attributes for our items
46 WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
47
48 // ----------------------------------------------------------------------------
49 // wxTreeCtrl
50 // ----------------------------------------------------------------------------
51
52 class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase
53 {
54 public:
55 // creation
56 // --------
57 wxTreeCtrl() { Init(); }
58
59 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
63 const wxValidator& validator = wxDefaultValidator,
64 const wxString& name = wxTreeCtrlNameStr)
65 {
66 Create(parent, id, pos, size, style, validator, name);
67 }
68
69 virtual ~wxTreeCtrl();
70
71 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize,
74 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
75 const wxValidator& validator = wxDefaultValidator,
76 const wxString& name = wxTreeCtrlNameStr);
77
78 // implement base class pure virtuals
79 // ----------------------------------
80
81 virtual size_t GetCount() const;
82
83 virtual unsigned int GetIndent() const;
84 virtual void SetIndent(unsigned int indent);
85
86 virtual void SetImageList(wxImageList *imageList);
87 virtual void SetStateImageList(wxImageList *imageList);
88
89 virtual wxString GetItemText(const wxTreeItemId& item) const;
90 virtual int GetItemImage(const wxTreeItemId& item,
91 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
92 virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
93 virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
94 virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
95 virtual wxFont GetItemFont(const wxTreeItemId& item) const;
96
97 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
98 virtual void SetItemImage(const wxTreeItemId& item, int image,
99 wxTreeItemIcon which = wxTreeItemIcon_Normal);
100 virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
101 virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
102 virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
103 virtual void SetItemDropHighlight(const wxTreeItemId& item,
104 bool highlight = true);
105 virtual void SetItemTextColour(const wxTreeItemId& item,
106 const wxColour& col);
107 virtual void SetItemBackgroundColour(const wxTreeItemId& item,
108 const wxColour& col);
109 virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
110
111 // item status inquiries
112 // ---------------------
113
114 virtual bool IsVisible(const wxTreeItemId& item) const;
115 virtual bool ItemHasChildren(const wxTreeItemId& item) const;
116 virtual bool IsExpanded(const wxTreeItemId& item) const;
117 virtual bool IsSelected(const wxTreeItemId& item) const;
118 virtual bool IsBold(const wxTreeItemId& item) const;
119
120 virtual size_t GetChildrenCount(const wxTreeItemId& item,
121 bool recursively = true) const;
122
123 // navigation
124 // ----------
125
126 virtual wxTreeItemId GetRootItem() const;
127 virtual wxTreeItemId GetSelection() const;
128 virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
129
130 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
131 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
132 wxTreeItemIdValue& cookie) const;
133 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
134 wxTreeItemIdValue& cookie) const;
135 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
136
137 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
138 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
139
140 virtual wxTreeItemId GetFirstVisibleItem() const;
141 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
142 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
143
144 // operations
145 // ----------
146
147 virtual wxTreeItemId AddRoot(const wxString& text,
148 int image = -1, int selectedImage = -1,
149 wxTreeItemData *data = NULL);
150
151 virtual void Delete(const wxTreeItemId& item);
152 virtual void DeleteChildren(const wxTreeItemId& item);
153 virtual void DeleteAllItems();
154
155 virtual void Expand(const wxTreeItemId& item);
156 virtual void Collapse(const wxTreeItemId& item);
157 virtual void CollapseAndReset(const wxTreeItemId& item);
158 virtual void Toggle(const wxTreeItemId& item);
159
160 virtual void Unselect();
161 virtual void UnselectAll();
162 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
163
164 virtual void EnsureVisible(const wxTreeItemId& item);
165 virtual void ScrollTo(const wxTreeItemId& item);
166
167 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
168 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
169 virtual wxTextCtrl *GetEditControl() const;
170 virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
171 bool discardChanges = false)
172 {
173 DoEndEditLabel(discardChanges);
174 }
175
176 virtual void SortChildren(const wxTreeItemId& item);
177
178 virtual bool GetBoundingRect(const wxTreeItemId& item,
179 wxRect& rect,
180 bool textOnly = false) const;
181
182 // deprecated
183 // ----------
184
185 #if WXWIN_COMPATIBILITY_2_4
186 // these methods are deprecated and will be removed in future versions of
187 // wxWidgets, they're here for compatibility only, don't use them in new
188 // code (the comments indicate why these methods are now useless and how to
189 // replace them)
190
191 // use Expand, Collapse, CollapseAndReset or Toggle
192 wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) );
193
194 // use Set/GetImageList and Set/GetStateImageList
195 // Use base class GetImageList()
196 wxDEPRECATED( void SetImageList(wxImageList *imageList, int) );
197
198 // use Set/GetItemImage directly
199 wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const );
200 wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) );
201
202 // use the versions taking wxTreeItemIdValue cookies
203 wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item,
204 long& cookie) const );
205 wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item,
206 long& cookie) const );
207 #endif // WXWIN_COMPATIBILITY_2_4
208
209
210 // implementation
211 // --------------
212
213 virtual wxVisualAttributes GetDefaultAttributes() const
214 {
215 return GetClassDefaultAttributes(GetWindowVariant());
216 }
217
218 static wxVisualAttributes
219 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
220
221
222 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
223 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
224 virtual bool MSWCommand(WXUINT param, WXWORD id);
225 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
226
227 // override some base class virtuals
228 virtual bool SetBackgroundColour(const wxColour &colour);
229 virtual bool SetForegroundColour(const wxColour &colour);
230
231 // get/set the check state for the item (only for wxTR_MULTIPLE)
232 bool IsItemChecked(const wxTreeItemId& item) const;
233 void SetItemCheck(const wxTreeItemId& item, bool check = true);
234
235 // set/get the item state.image (state == -1 means cycle to the next one)
236 void SetState(const wxTreeItemId& node, int state);
237 int GetState(const wxTreeItemId& node);
238
239 protected:
240 // SetImageList helper
241 void SetAnyImageList(wxImageList *imageList, int which);
242
243 // refresh a single item
244 void RefreshItem(const wxTreeItemId& item);
245
246 // end edit label
247 void DoEndEditLabel(bool discardChanges = false);
248
249
250 // data used only while editing the item label:
251 wxTextCtrl *m_textCtrl; // text control in which it is edited
252 wxTreeItemId m_idEdited; // the item being edited
253
254 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
255 size_t pos,
256 const wxString& text,
257 int image, int selectedImage,
258 wxTreeItemData *data);
259 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
260 const wxTreeItemId& idPrevious,
261 const wxString& text,
262 int image = -1, int selImage = -1,
263 wxTreeItemData *data = NULL);
264 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags);
265
266 private:
267 // the common part of all ctors
268 void Init();
269
270 // helper functions
271 inline bool DoGetItem(wxTreeViewItem *tvItem) const;
272 inline void DoSetItem(wxTreeViewItem *tvItem);
273
274 inline void DoExpand(const wxTreeItemId& item, int flag);
275
276 int DoGetItemImageFromData(const wxTreeItemId& item,
277 wxTreeItemIcon which) const;
278 void DoSetItemImageFromData(const wxTreeItemId& item,
279 int image,
280 wxTreeItemIcon which) const;
281 void DoSetItemImages(const wxTreeItemId& item, int image, int imageSel);
282
283 void DeleteTextCtrl();
284
285 // support for additional item images which we implement using
286 // wxTreeItemIndirectData technique - see the comments in msw/treectrl.cpp
287 void SetIndirectItemData(const wxTreeItemId& item,
288 class wxTreeItemIndirectData *data);
289 bool HasIndirectData(const wxTreeItemId& item) const;
290 bool IsDataIndirect(wxTreeItemData *data) const
291 { return data && data->GetId().m_pItem == 0; }
292
293 // the hash storing the items attributes (indexed by item ids)
294 wxMapTreeAttr m_attrs;
295
296 // true if the hash above is not empty
297 bool m_hasAnyAttr;
298
299 // used for dragging
300 wxDragImage *m_dragImage;
301
302 // Virtual root item, if wxTR_HIDE_ROOT is set.
303 void* m_pVirtualRoot;
304
305 // the starting item for selection with Shift
306 wxTreeItemId m_htSelStart, m_htClickedItem;
307 wxPoint m_ptClick;
308
309 friend class wxTreeItemIndirectData;
310 friend class wxTreeSortHelper;
311
312 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
313 DECLARE_NO_COPY_CLASS(wxTreeCtrl)
314 };
315
316 #endif // wxUSE_TREECTRL
317
318 #endif
319 // _WX_TREECTRL_H_