]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/treectrl.h
introduced a common base class for both MSW and generic wxTreeCtrl implementations
[wxWidgets.git] / include / wx / msw / treectrl.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
3f7bc32b 2// Name: wx/msw/treectrl.h
2bda0e17
KB
3// Purpose: wxTreeCtrl class
4// Author: Julian Smart
08b7c251 5// Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98
2bda0e17
KB
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_TREECTRL_H_
13#define _WX_TREECTRL_H_
2bda0e17 14
08b7c251
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
d427503c 18
1e6feb95
VZ
19#if wxUSE_TREECTRL
20
ad5c34f3 21#include "wx/textctrl.h"
2899e223 22#include "wx/dynarray.h"
484523cf 23#include "wx/treebase.h"
ee4b2721 24#include "wx/hashmap.h"
2bda0e17 25
d427503c
VZ
26#ifdef __GNUWIN32__
27 // Cygwin windows.h defines these identifiers
28 #undef GetFirstChild
29 #undef GetNextSibling
30#endif // Cygwin
31
08b7c251 32// fwd decl
06e38c8e 33class WXDLLEXPORT wxImageList;
23f681ec 34class WXDLLEXPORT wxDragImage;
06e38c8e 35struct WXDLLEXPORT wxTreeViewItem;
08b7c251 36
08b7c251
VZ
37// NB: all the following flags are for compatbility only and will be removed in the
38// next versions
39
ee4b2721
VZ
40// flags for deprecated InsertItem() variant (their values are the same as of
41// TVI_FIRST and TVI_LAST)
3197ed26
VZ
42#define wxTREE_INSERT_FIRST 0xFFFF0001
43#define wxTREE_INSERT_LAST 0xFFFF0002
2bda0e17 44
ee4b2721
VZ
45// hash storing attributes for our items
46WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
47
08b7c251
VZ
48// ----------------------------------------------------------------------------
49// wxTreeCtrl
50// ----------------------------------------------------------------------------
ee4b2721 51
8cee4a30 52class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase
2bda0e17 53{
092bddef 54public:
092bddef
VZ
55 // creation
56 // --------
08b7c251
VZ
57 wxTreeCtrl() { Init(); }
58
dabbc6a5 59 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
08b7c251
VZ
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,
2b5f62a0 64 const wxString& name = wxTreeCtrlNameStr)
092bddef
VZ
65 {
66 Create(parent, id, pos, size, style, validator, name);
67 }
08b7c251
VZ
68
69 virtual ~wxTreeCtrl();
70
dabbc6a5 71 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
092bddef
VZ
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize,
08b7c251 74 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
092bddef 75 const wxValidator& validator = wxDefaultValidator,
2b5f62a0 76 const wxString& name = wxTreeCtrlNameStr);
08b7c251 77
8cee4a30
VZ
78 // implement base class pure virtuals
79 // ----------------------------------
08b7c251 80
8cee4a30 81 virtual size_t GetCount() const;
08b7c251 82
8cee4a30
VZ
83 virtual unsigned int GetIndent() const;
84 virtual void SetIndent(unsigned int indent);
08b7c251 85
8cee4a30
VZ
86 virtual void SetImageList(wxImageList *imageList);
87 virtual void SetStateImageList(wxImageList *imageList);
08b7c251 88
8cee4a30 89 virtual wxString GetItemText(const wxTreeItemId& item) const;
a78955e3 90 virtual int GetItemImage(const wxTreeItemId& item,
8cee4a30
VZ
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;
2b5f62a0 96
8cee4a30 97 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
a78955e3 98 virtual void SetItemImage(const wxTreeItemId& item, int image,
74b31181 99 wxTreeItemIcon which = wxTreeItemIcon_Normal);
8cee4a30
VZ
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);
9ec64fa7 110
08b7c251
VZ
111 // item status inquiries
112 // ---------------------
113
8cee4a30
VZ
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;
4832f7c0 122
08b7c251
VZ
123 // navigation
124 // ----------
125
8cee4a30
VZ
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;
08b7c251 143
092bddef
VZ
144 // operations
145 // ----------
08b7c251 146
a78955e3 147 virtual wxTreeItemId AddRoot(const wxString& text,
08b7c251
VZ
148 int image = -1, int selectedImage = -1,
149 wxTreeItemData *data = NULL);
8cee4a30
VZ
150 virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
151 const wxTreeItemId& idPrevious,
152 const wxString& text,
153 int image = -1, int selectedImage = -1,
154 wxTreeItemData *data = NULL);
08b7c251 155
8cee4a30
VZ
156 virtual void Delete(const wxTreeItemId& item);
157 virtual void DeleteChildren(const wxTreeItemId& item);
158 virtual void DeleteAllItems();
08b7c251 159
8cee4a30
VZ
160 virtual void Expand(const wxTreeItemId& item);
161 virtual void Collapse(const wxTreeItemId& item);
162 virtual void CollapseAndReset(const wxTreeItemId& item);
163 virtual void Toggle(const wxTreeItemId& item);
08b7c251 164
8cee4a30
VZ
165 virtual void Unselect();
166 virtual void UnselectAll();
167 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
2ef31e80 168
8cee4a30
VZ
169 virtual void EnsureVisible(const wxTreeItemId& item);
170 virtual void ScrollTo(const wxTreeItemId& item);
171
172 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
08b7c251 173 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
8cee4a30
VZ
174 virtual wxTextCtrl *GetEditControl() const;
175 virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
176 bool discardChanges = false)
d35dce3a
VZ
177 {
178 DoEndEditLabel(discardChanges);
179 }
08b7c251 180
8cee4a30
VZ
181 virtual void SortChildren(const wxTreeItemId& item);
182
183 virtual bool GetBoundingRect(const wxTreeItemId& item,
184 wxRect& rect,
185 bool textOnly = false) const;
08b7c251 186
08b7c251
VZ
187 // deprecated
188 // ----------
189
ee4b2721 190#if WXWIN_COMPATIBILITY_2_4
08b7c251 191 // these methods are deprecated and will be removed in future versions of
77ffb593 192 // wxWidgets, they're here for compatibility only, don't use them in new
08b7c251
VZ
193 // code (the comments indicate why these methods are now useless and how to
194 // replace them)
195
196 // use Expand, Collapse, CollapseAndReset or Toggle
ee4b2721 197 wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) );
08b7c251
VZ
198
199 // use AddRoot, PrependItem or AppendItem
ee4b2721 200 wxDEPRECATED( wxTreeItemId InsertItem(const wxTreeItemId& parent,
08b7c251
VZ
201 const wxString& text,
202 int image = -1, int selImage = -1,
ee4b2721 203 long insertAfter = wxTREE_INSERT_LAST) );
08b7c251
VZ
204
205 // use Set/GetImageList and Set/GetStateImageList
a6fb8636
WS
206 wxDEPRECATED( wxImageList *GetImageList(int) const );
207 wxDEPRECATED( void SetImageList(wxImageList *imageList, int) );
08b7c251 208
74b31181 209 // use Set/GetItemImage directly
a6fb8636
WS
210 wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const );
211 wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) );
74b31181 212
ee4b2721
VZ
213 // use the versions taking wxTreeItemIdValue cookies
214 wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item,
215 long& cookie) const );
216 wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item,
217 long& cookie) const );
218#endif // WXWIN_COMPATIBILITY_2_4
219
d4864e97 220
08b7c251
VZ
221 // implementation
222 // --------------
3f7bc32b 223
39c7a53c
VZ
224 virtual wxVisualAttributes GetDefaultAttributes() const
225 {
226 return GetClassDefaultAttributes(GetWindowVariant());
227 }
228
229 static wxVisualAttributes
230 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
231
232
c140b7e7 233 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fbd8ac52 234 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fd3f686c 235 virtual bool MSWCommand(WXUINT param, WXWORD id);
a23fd0e1 236 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
08b7c251 237
bb448552
VZ
238 // override some base class virtuals
239 virtual bool SetBackgroundColour(const wxColour &colour);
240 virtual bool SetForegroundColour(const wxColour &colour);
241
9dfbf520
VZ
242 // get/set the check state for the item (only for wxTR_MULTIPLE)
243 bool IsItemChecked(const wxTreeItemId& item) const;
dabbc6a5 244 void SetItemCheck(const wxTreeItemId& item, bool check = true);
9dfbf520 245
8a000b6b
VZ
246 // set/get the item state.image (state == -1 means cycle to the next one)
247 void SetState(const wxTreeItemId& node, int state);
248 int GetState(const wxTreeItemId& node);
249
2bda0e17 250protected:
08b7c251
VZ
251 // SetImageList helper
252 void SetAnyImageList(wxImageList *imageList, int which);
253
d00407b2
VZ
254 // refresh a single item
255 void RefreshItem(const wxTreeItemId& item);
256
d35dce3a
VZ
257 // end edit label
258 void DoEndEditLabel(bool discardChanges = false);
259
260
329eeca9
VZ
261 // data used only while editing the item label:
262 wxTextCtrl *m_textCtrl; // text control in which it is edited
263 wxTreeItemId m_idEdited; // the item being edited
264
08b7c251
VZ
265 wxImageList *m_imageListNormal, // images for tree elements
266 *m_imageListState; // special images for app defined states
329eeca9
VZ
267 bool m_ownsImageListNormal,
268 m_ownsImageListState;
08b7c251
VZ
269
270private:
271 // the common part of all ctors
272 void Init();
273
274 // helper functions
275 inline bool DoGetItem(wxTreeViewItem *tvItem) const;
276 inline void DoSetItem(wxTreeViewItem *tvItem);
277
278 inline void DoExpand(const wxTreeItemId& item, int flag);
279
8cee4a30
VZ
280 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
281 size_t pos,
282 const wxString& text,
283 int image, int selectedImage,
284 wxTreeItemData *data);
285 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
286 const wxTreeItemId& idPrevious,
287 const wxString& text,
288 int image = -1, int selImage = -1,
289 wxTreeItemData *data = NULL);
290 virtual wxTreeItemId DoHitTest(const wxPoint& point, int& flags);
08b7c251 291
74b31181
VZ
292 int DoGetItemImageFromData(const wxTreeItemId& item,
293 wxTreeItemIcon which) const;
294 void DoSetItemImageFromData(const wxTreeItemId& item,
295 int image,
296 wxTreeItemIcon which) const;
9dfbf520
VZ
297 void DoSetItemImages(const wxTreeItemId& item, int image, int imageSel);
298
08b7c251 299 void DeleteTextCtrl();
092bddef 300
502a2b18
VZ
301 // support for additional item images which we implement using
302 // wxTreeItemIndirectData technique - see the comments in msw/treectrl.cpp
74b31181 303 void SetIndirectItemData(const wxTreeItemId& item,
502a2b18 304 class wxTreeItemIndirectData *data);
74b31181 305 bool HasIndirectData(const wxTreeItemId& item) const;
502a2b18 306 bool IsDataIndirect(wxTreeItemData *data) const
8b4a9377 307 { return data && data->GetId().m_pItem == 0; }
74b31181 308
ee4b2721
VZ
309 // the hash storing the items attributes (indexed by item ids)
310 wxMapTreeAttr m_attrs;
696e1ea0 311
dabbc6a5 312 // true if the hash above is not empty
696e1ea0
VZ
313 bool m_hasAnyAttr;
314
23f681ec
VZ
315 // used for dragging
316 wxDragImage *m_dragImage;
317
a9c1265f
VZ
318 // Virtual root item, if wxTR_HIDE_ROOT is set.
319 void* m_pVirtualRoot;
320
3f7bc32b 321 // the starting item for selection with Shift
e3ad5702
JS
322 wxTreeItemId m_htSelStart, m_htClickedItem;
323 wxPoint m_ptClick;
3f7bc32b 324
502a2b18
VZ
325 friend class wxTreeItemIndirectData;
326 friend class wxTreeSortHelper;
327
092bddef 328 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
22f3361e 329 DECLARE_NO_COPY_CLASS(wxTreeCtrl)
2bda0e17
KB
330};
331
1e6feb95
VZ
332#endif // wxUSE_TREECTRL
333
2bda0e17 334#endif
bbcdf8bc 335 // _WX_TREECTRL_H_