]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/treectrl.h
reverting to native mac pathnames
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
08b7c251 9// Licence: wxWindows license
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
2bda0e17 19#ifdef __GNUG__
08b7c251 20 #pragma interface "treectrl.h"
2bda0e17
KB
21#endif
22
ad5c34f3 23#include "wx/textctrl.h"
2899e223 24#include "wx/dynarray.h"
484523cf 25#include "wx/treebase.h"
2bda0e17 26
d427503c
VZ
27#ifdef __GNUWIN32__
28 // Cygwin windows.h defines these identifiers
29 #undef GetFirstChild
30 #undef GetNextSibling
31#endif // Cygwin
32
08b7c251
VZ
33// the type for "untyped" data
34typedef long wxDataType;
35
36// fwd decl
06e38c8e 37class WXDLLEXPORT wxImageList;
23f681ec 38class WXDLLEXPORT wxDragImage;
06e38c8e 39struct WXDLLEXPORT wxTreeViewItem;
08b7c251
VZ
40
41// a callback function used for sorting tree items, it should return -1 if the
42// first item precedes the second, +1 if the second precedes the first or 0 if
43// they're equivalent
44class wxTreeItemData;
08b7c251 45
08b7c251
VZ
46// NB: all the following flags are for compatbility only and will be removed in the
47// next versions
48
49// flags for deprecated `Expand(int action)'
50enum
51{
2bda0e17
KB
52 wxTREE_EXPAND_EXPAND,
53 wxTREE_EXPAND_COLLAPSE,
54 wxTREE_EXPAND_COLLAPSE_RESET,
55 wxTREE_EXPAND_TOGGLE
56};
57
08b7c251 58// flags for deprecated InsertItem() variant
3197ed26
VZ
59#define wxTREE_INSERT_FIRST 0xFFFF0001
60#define wxTREE_INSERT_LAST 0xFFFF0002
2bda0e17 61
08b7c251
VZ
62// ----------------------------------------------------------------------------
63// wxTreeCtrl
64// ----------------------------------------------------------------------------
65class WXDLLEXPORT wxTreeCtrl : public wxControl
2bda0e17 66{
092bddef 67public:
092bddef
VZ
68 // creation
69 // --------
08b7c251
VZ
70 wxTreeCtrl() { Init(); }
71
72 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
73 const wxPoint& pos = wxDefaultPosition,
74 const wxSize& size = wxDefaultSize,
75 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
76 const wxValidator& validator = wxDefaultValidator,
77 const wxString& name = "wxTreeCtrl")
092bddef
VZ
78 {
79 Create(parent, id, pos, size, style, validator, name);
80 }
08b7c251
VZ
81
82 virtual ~wxTreeCtrl();
83
092bddef
VZ
84 bool Create(wxWindow *parent, wxWindowID id = -1,
85 const wxPoint& pos = wxDefaultPosition,
86 const wxSize& size = wxDefaultSize,
08b7c251 87 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
092bddef
VZ
88 const wxValidator& validator = wxDefaultValidator,
89 const wxString& name = "wxTreeCtrl");
08b7c251 90
092bddef
VZ
91 // accessors
92 // ---------
092bddef 93
08b7c251
VZ
94 // get the total number of items in the control
95 size_t GetCount() const;
96
97 // indent is the number of pixels the children are indented relative to
98 // the parents position. SetIndent() also redraws the control
99 // immediately.
100 unsigned int GetIndent() const;
101 void SetIndent(unsigned int indent);
102
74b31181
VZ
103 // spacing is the number of pixels between the start and the Text
104 // not implemented under wxMSW
cf724bce 105 unsigned int GetSpacing() const { return 18; } // return wxGTK default
74b31181 106 void SetSpacing(unsigned int WXUNUSED(spacing)) { }
cf724bce 107
08b7c251
VZ
108 // image list: these functions allow to associate an image list with
109 // the control and retrieve it. Note that the control does _not_ delete
110 // the associated image list when it's deleted in order to allow image
111 // lists to be shared between different controls.
112 //
113 // The normal image list is for the icons which correspond to the
114 // normal tree item state (whether it is selected or not).
115 // Additionally, the application might choose to show a state icon
116 // which corresponds to an app-defined item state (for example,
117 // checked/unchecked) which are taken from the state image list.
118 wxImageList *GetImageList() const;
119 wxImageList *GetStateImageList() const;
120
121 void SetImageList(wxImageList *imageList);
122 void SetStateImageList(wxImageList *imageList);
0377efa2
VS
123 void AssignImageList(wxImageList *imageList);
124 void AssignStateImageList(wxImageList *imageList);
08b7c251
VZ
125
126 // Functions to work with tree ctrl items. Unfortunately, they can _not_ be
127 // member functions of wxTreeItem because they must know the tree the item
128 // belongs to for Windows implementation and storing the pointer to
129 // wxTreeCtrl in each wxTreeItem is just too much waste.
130
131 // accessors
132 // ---------
133
134 // retrieve items label
135 wxString GetItemText(const wxTreeItemId& item) const;
74b31181
VZ
136 // get one of the images associated with the item (normal by default)
137 int GetItemImage(const wxTreeItemId& item,
138 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
08b7c251
VZ
139 // get the data associated with the item
140 wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
141
142 // modifiers
143 // ---------
144
145 // set items label
146 void SetItemText(const wxTreeItemId& item, const wxString& text);
74b31181
VZ
147 // get one of the images associated with the item (normal by default)
148 void SetItemImage(const wxTreeItemId& item, int image,
149 wxTreeItemIcon which = wxTreeItemIcon_Normal);
08b7c251
VZ
150 // associate some data with the item
151 void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
152
3a5a2f56
VZ
153 // force appearance of [+] button near the item. This is useful to
154 // allow the user to expand the items which don't have any children now
155 // - but instead add them only when needed, thus minimizing memory
156 // usage and loading time.
157 void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE);
158
add28c55
VZ
159 // the item will be shown in bold
160 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
161
58a8ab88
JS
162 // the item will be shown with a drop highlight
163 void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = TRUE);
164
9ec64fa7
VZ
165 // set the items text colour
166 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
167
168 // set the items background colour
169 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
170
171 // set the items font (should be of the same height for all items)
172 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
173
08b7c251
VZ
174 // item status inquiries
175 // ---------------------
176
177 // is the item visible (it might be outside the view or not expanded)?
178 bool IsVisible(const wxTreeItemId& item) const;
179 // does the item has any children?
180 bool ItemHasChildren(const wxTreeItemId& item) const;
181 // is the item expanded (only makes sense if HasChildren())?
182 bool IsExpanded(const wxTreeItemId& item) const;
183 // is this item currently selected (the same as has focus)?
184 bool IsSelected(const wxTreeItemId& item) const;
add28c55
VZ
185 // is item text in bold font?
186 bool IsBold(const wxTreeItemId& item) const;
08b7c251 187
4832f7c0
VZ
188 // number of children
189 // ------------------
190
191 // if 'recursively' is FALSE, only immediate children count, otherwise
192 // the returned number is the number of all items in this branch
9dfbf520
VZ
193 size_t GetChildrenCount(const wxTreeItemId& item,
194 bool recursively = TRUE) const;
4832f7c0 195
08b7c251
VZ
196 // navigation
197 // ----------
198
199 // wxTreeItemId.IsOk() will return FALSE if there is no such item
200
201 // get the root tree item
202 wxTreeItemId GetRootItem() const;
203
204 // get the item currently selected (may return NULL if no selection)
205 wxTreeItemId GetSelection() const;
206
9dfbf520
VZ
207 // get the items currently selected, return the number of such item
208 //
209 // NB: this operation is expensive and can take a long time for a
210 // control with a lot of items (~ O(number of items)).
211 size_t GetSelections(wxArrayTreeItemIds& selections) const;
212
08b7c251
VZ
213 // get the parent of this item (may return NULL if root)
214 wxTreeItemId GetParent(const wxTreeItemId& item) const;
215
216 // for this enumeration function you must pass in a "cookie" parameter
217 // which is opaque for the application but is necessary for the library
218 // to make these functions reentrant (i.e. allow more than one
219 // enumeration on one and the same object simultaneously). Of course,
220 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
221 // the same!
222
223 // get the first child of this item
06e38c8e 224 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& _cookie) const;
08b7c251 225 // get the next child
06e38c8e 226 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& _cookie) const;
978f38c2
VZ
227 // get the last child of this item - this method doesn't use cookies
228 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
08b7c251
VZ
229
230 // get the next sibling of this item
231 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
232 // get the previous sibling
233 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
234
235 // get first visible item
236 wxTreeItemId GetFirstVisibleItem() const;
237 // get the next visible item: item must be visible itself!
238 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
239 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
240 // get the previous visible item: item must be visible itself!
241 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
242
092bddef
VZ
243 // operations
244 // ----------
08b7c251
VZ
245
246 // add the root node to the tree
247 wxTreeItemId AddRoot(const wxString& text,
248 int image = -1, int selectedImage = -1,
249 wxTreeItemData *data = NULL);
250
251 // insert a new item in as the first child of the parent
252 wxTreeItemId PrependItem(const wxTreeItemId& parent,
253 const wxString& text,
254 int image = -1, int selectedImage = -1,
255 wxTreeItemData *data = NULL);
256
257 // insert a new item after a given one
258 wxTreeItemId InsertItem(const wxTreeItemId& parent,
259 const wxTreeItemId& idPrevious,
260 const wxString& text,
261 int image = -1, int selectedImage = -1,
262 wxTreeItemData *data = NULL);
263
2ef31e80
VZ
264 // insert a new item before the one with the given index
265 wxTreeItemId InsertItem(const wxTreeItemId& parent,
266 size_t index,
267 const wxString& text,
268 int image = -1, int selectedImage = -1,
269 wxTreeItemData *data = NULL);
270
08b7c251
VZ
271 // insert a new item in as the last child of the parent
272 wxTreeItemId AppendItem(const wxTreeItemId& parent,
273 const wxString& text,
274 int image = -1, int selectedImage = -1,
275 wxTreeItemData *data = NULL);
276
277 // delete this item and associated data if any
278 void Delete(const wxTreeItemId& item);
372edb9d
VZ
279 // delete all children (but don't delete the item itself)
280 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
281 void DeleteChildren(const wxTreeItemId& item);
08b7c251 282 // delete all items from the tree
372edb9d 283 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
08b7c251
VZ
284 void DeleteAllItems();
285
286 // expand this item
287 void Expand(const wxTreeItemId& item);
288 // collapse the item without removing its children
289 void Collapse(const wxTreeItemId& item);
290 // collapse the item and remove all children
291 void CollapseAndReset(const wxTreeItemId& item);
292 // toggles the current state
293 void Toggle(const wxTreeItemId& item);
294
295 // remove the selection from currently selected item (if any)
296 void Unselect();
9dfbf520
VZ
297 // unselect all items (only makes sense for multiple selection control)
298 void UnselectAll();
08b7c251
VZ
299 // select this item
300 void SelectItem(const wxTreeItemId& item);
301 // make sure this item is visible (expanding the parent item and/or
302 // scrolling to this item if necessary)
303 void EnsureVisible(const wxTreeItemId& item);
304 // scroll to this item (but don't expand its parent)
305 void ScrollTo(const wxTreeItemId& item);
306
307 // start editing the item label: this (temporarily) replaces the item
308 // with a one line edit control. The item will be selected if it hadn't
309 // been before. textCtrlClass parameter allows you to create an edit
310 // control of arbitrary user-defined class deriving from wxTextCtrl.
311 wxTextCtrl* EditLabel(const wxTreeItemId& item,
312 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
313 // returns the same pointer as StartEdit() if the item is being edited,
314 // NULL otherwise (it's assumed that no more than one item may be
315 // edited simultaneously)
316 wxTextCtrl* GetEditControl() const;
317 // end editing and accept or discard the changes to item label
318 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
319
95aabccc
VZ
320 // sorting
321 // this function is called to compare 2 items and should return -1, 0
322 // or +1 if the first item is less than, equal to or greater than the
323 // second one. The base class version performs alphabetic comparaison
324 // of item labels (GetText)
325 virtual int OnCompareItems(const wxTreeItemId& item1,
326 const wxTreeItemId& item2);
327 // sort the children of this item using OnCompareItems
08b7c251 328 //
95aabccc
VZ
329 // NB: this function is not reentrant and not MT-safe (FIXME)!
330 void SortChildren(const wxTreeItemId& item);
08b7c251
VZ
331
332 // helpers
333 // -------
334
add28c55
VZ
335 // determine to which item (if any) belongs the given point (the
336 // coordinates specified are relative to the client area of tree ctrl)
337 // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx
338 // constants.
339 //
340 // The first function is more portable (because easier to implement
341 // on other platforms), but the second one returns some extra info.
342 wxTreeItemId HitTest(const wxPoint& point)
343 { int dummy; return HitTest(point, dummy); }
344 wxTreeItemId HitTest(const wxPoint& point, int& flags);
08b7c251
VZ
345
346 // get the bounding rectangle of the item (or of its label only)
f7c832a7 347 bool GetBoundingRect(const wxTreeItemId& item,
16e93305 348 wxRect& rect,
08b7c251
VZ
349 bool textOnly = FALSE) const;
350
08b7c251
VZ
351 // deprecated
352 // ----------
353
354 // these methods are deprecated and will be removed in future versions of
355 // wxWindows, they're here for compatibility only, don't use them in new
356 // code (the comments indicate why these methods are now useless and how to
357 // replace them)
358
359 // use Expand, Collapse, CollapseAndReset or Toggle
360 void ExpandItem(const wxTreeItemId& item, int action);
361
362 // use AddRoot, PrependItem or AppendItem
363 wxTreeItemId InsertItem(const wxTreeItemId& parent,
364 const wxString& text,
365 int image = -1, int selImage = -1,
366 long insertAfter = wxTREE_INSERT_LAST);
367
368 // use Set/GetImageList and Set/GetStateImageList
369 wxImageList *GetImageList(int) const
370 { return GetImageList(); }
371 void SetImageList(wxImageList *imageList, int)
372 { SetImageList(imageList); }
373
74b31181
VZ
374 // use Set/GetItemImage directly
375 // get the selected item image
376 int GetItemSelectedImage(const wxTreeItemId& item) const
377 { return GetItemImage(item, wxTreeItemIcon_Selected); }
378 // set the selected item image
379 void SetItemSelectedImage(const wxTreeItemId& item, int image)
380 { SetItemImage(item, image, wxTreeItemIcon_Selected); }
381
08b7c251
VZ
382 // implementation
383 // --------------
3f7bc32b 384
23f681ec 385 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
fd3f686c 386 virtual bool MSWCommand(WXUINT param, WXWORD id);
a23fd0e1 387 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
08b7c251 388
bb448552
VZ
389 // override some base class virtuals
390 virtual bool SetBackgroundColour(const wxColour &colour);
391 virtual bool SetForegroundColour(const wxColour &colour);
392
9dfbf520
VZ
393 // get/set the check state for the item (only for wxTR_MULTIPLE)
394 bool IsItemChecked(const wxTreeItemId& item) const;
395 void SetItemCheck(const wxTreeItemId& item, bool check = TRUE);
396
2bda0e17 397protected:
08b7c251
VZ
398 // SetImageList helper
399 void SetAnyImageList(wxImageList *imageList, int which);
400
74b31181 401 wxTextCtrl *m_textCtrl; // used while editing the item label
08b7c251
VZ
402 wxImageList *m_imageListNormal, // images for tree elements
403 *m_imageListState; // special images for app defined states
0377efa2 404 bool m_ownsImageListNormal, m_ownsImageListState;
08b7c251
VZ
405
406private:
407 // the common part of all ctors
408 void Init();
409
410 // helper functions
411 inline bool DoGetItem(wxTreeViewItem *tvItem) const;
412 inline void DoSetItem(wxTreeViewItem *tvItem);
413
414 inline void DoExpand(const wxTreeItemId& item, int flag);
415
416 wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
417 wxTreeItemId hInsertAfter,
418 const wxString& text,
419 int image, int selectedImage,
420 wxTreeItemData *data);
421
74b31181
VZ
422 int DoGetItemImageFromData(const wxTreeItemId& item,
423 wxTreeItemIcon which) const;
424 void DoSetItemImageFromData(const wxTreeItemId& item,
425 int image,
426 wxTreeItemIcon which) const;
9dfbf520
VZ
427 void DoSetItemImages(const wxTreeItemId& item, int image, int imageSel);
428
08b7c251 429 void DeleteTextCtrl();
092bddef 430
74b31181
VZ
431 // support for additional item images
432 friend class wxTreeItemIndirectData;
433 void SetIndirectItemData(const wxTreeItemId& item,
434 wxTreeItemIndirectData *data);
435 bool HasIndirectData(const wxTreeItemId& item) const;
436
696e1ea0 437 // the array storing all item ids which have indirect data
74b31181
VZ
438 wxArrayTreeItemIds m_itemsWithIndirectData;
439
696e1ea0
VZ
440 // the hash storing the items attributes (indexed by items ids)
441 wxHashTable m_attrs;
442
443 // TRUE if the hash above is not empty
444 bool m_hasAnyAttr;
445
23f681ec
VZ
446 // used for dragging
447 wxDragImage *m_dragImage;
448
3f7bc32b
VZ
449 // the starting item for selection with Shift
450 WXHTREEITEM m_htSelStart;
451
092bddef 452 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
2bda0e17
KB
453};
454
2bda0e17 455#endif
bbcdf8bc 456 // _WX_TREECTRL_H_