]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/treectrl.h
few other fixes for wxChar => wxString
[wxWidgets.git] / interface / wx / treectrl.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: treectrl.h
e54c96f1 3// Purpose: interface of wxTreeItemData
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
e54c96f1 9
23324ae1
FM
10/**
11 @class wxTreeCtrl
7c913512 12
23324ae1 13 A tree control presents information as a hierarchy, with items that may be
7977b62a
BP
14 expanded to show further items. Items in a tree control are referenced by
15 wxTreeItemId handles, which may be tested for validity by calling
16 wxTreeItemId::IsOk().
03966fcb 17
f0871806
RR
18 A similar control with a fully native implemtation for GTK+ and OS X
19 as well is wxDataViewTreeCtrl.
7c913512 20
7977b62a
BP
21 To intercept events from a tree control, use the event table macros
22 described in wxTreeEvent.
7c913512 23
23324ae1 24 @beginStyleTable
8c6791e4 25 @style{wxTR_EDIT_LABELS}
7977b62a
BP
26 Use this style if you wish the user to be able to edit labels in the
27 tree control.
8c6791e4 28 @style{wxTR_NO_BUTTONS}
7977b62a 29 For convenience to document that no buttons are to be drawn.
8c6791e4 30 @style{wxTR_HAS_BUTTONS}
7977b62a 31 Use this style to show + and - buttons to the left of parent items.
8c6791e4 32 @style{wxTR_NO_LINES}
7977b62a 33 Use this style to hide vertical level connectors.
8c6791e4 34 @style{wxTR_FULL_ROW_HIGHLIGHT}
7977b62a
BP
35 Use this style to have the background colour and the selection highlight
36 extend over the entire horizontal row of the tree control window. (This
37 flag is ignored under Windows unless you specify @c wxTR_NO_LINES as
38 well.)
8c6791e4 39 @style{wxTR_LINES_AT_ROOT}
7977b62a
BP
40 Use this style to show lines between root nodes. Only applicable if @c
41 wxTR_HIDE_ROOT is set and @c wxTR_NO_LINES is not set.
8c6791e4 42 @style{wxTR_HIDE_ROOT}
7977b62a
BP
43 Use this style to suppress the display of the root node, effectively
44 causing the first-level nodes to appear as a series of root nodes.
8c6791e4 45 @style{wxTR_ROW_LINES}
7977b62a 46 Use this style to draw a contrasting border between displayed rows.
8c6791e4 47 @style{wxTR_HAS_VARIABLE_ROW_HEIGHT}
7977b62a
BP
48 Use this style to cause row heights to be just big enough to fit the
49 content. If not set, all rows use the largest row height. The default is
50 that this flag is unset. Generic only.
8c6791e4 51 @style{wxTR_SINGLE}
7977b62a
BP
52 For convenience to document that only one item may be selected at a
53 time. Selecting another item causes the current selection, if any, to be
54 deselected. This is the default.
8c6791e4 55 @style{wxTR_MULTIPLE}
7977b62a
BP
56 Use this style to allow a range of items to be selected. If a second
57 range is selected, the current range, if any, is deselected.
8c6791e4 58 @style{wxTR_DEFAULT_STYLE}
7977b62a
BP
59 The set of flags that are closest to the defaults for the native control
60 for a particular toolkit.
23324ae1 61 @endStyleTable
7c913512 62
98d45c55
RR
63 @beginEventTable{wxTreeEvent}
64 @event{EVT_TREE_BEGIN_DRAG(id, func)}
65 Begin dragging with the left mouse button.
66 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
67 Begin dragging with the right mouse button.
68 @event{EVT_TREE_END_DRAG(id, func)}
69 End dragging with the left or right mouse button.
70 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
71 Begin editing a label. This can be prevented by calling Veto().
72 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
73 Finish editing a label. This can be prevented by calling Veto().
74 @event{EVT_TREE_DELETE_ITEM(id, func)}
75 An item was deleted.
76 @event{EVT_TREE_GET_INFO(id, func)}
77 Request information from the application.
78 @event{EVT_TREE_SET_INFO(id, func)}
79 Information is being supplied.
80 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
81 The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard.
82 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
83 The item has been collapsed.
84 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
85 The item is being collapsed. This can be prevented by calling Veto().
86 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
87 The item has been expanded.
88 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
89 The item is being expanded. This can be prevented by calling Veto().
90 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
91 The user has clicked the item with the right mouse button.
92 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
93 The user has clicked the item with the middle mouse button.
94 @event{EVT_TREE_SEL_CHANGED(id, func)}
95 Selection has changed.
96 @event{EVT_TREE_SEL_CHANGING(id, func)}
97 Selection is changing. This can be prevented by calling Veto().
98 @event{EVT_TREE_KEY_DOWN(id, func)}
99 A key has been pressed.
100 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
101 The opportunity to set the item tooltip is being given to the application (call wxTreeEvent::SetToolTip). Windows only.
102 @event{EVT_TREE_ITEM_MENU(id, func)}
103 The context menu for the selected item has been requested, either by a right click or by using the menu key.
104 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
105 The state image has been clicked. Windows only.
106 @endEventTable
107
108
7977b62a 109 See also @ref overview_windowstyles.
03966fcb 110
7977b62a
BP
111 @b Win32 @b notes:
112
113 wxTreeCtrl class uses the standard common treeview control under Win32
114 implemented in the system library comctl32.dll. Some versions of this
115 library are known to have bugs with handling the tree control colours: the
116 usual symptom is that the expanded items leave black (or otherwise
117 incorrectly coloured) background behind them, especially for the controls
118 using non-default background colour. The recommended solution is to upgrade
119 the comctl32.dll to a newer version: see
120 http://www.microsoft.com/downloads/details.aspx?familyid=cb2cf3a2-8025-4e8f-8511-9b476a8d35d2
121
23324ae1
FM
122 @library{wxcore}
123 @category{ctrl}
7e59b885 124 @appearance{treectrl.png}
7c913512 125
f0871806 126 @see wxDataViewTreeCtrl, wxTreeEvent, wxTreeItemData, @ref overview_treectrl, wxListBox,
7977b62a 127 wxListCtrl, wxImageList
23324ae1
FM
128*/
129class wxTreeCtrl : public wxControl
130{
131public:
7977b62a
BP
132 /**
133 Default Constructor.
134 */
135 wxTreeCtrl();
136
23324ae1
FM
137 /**
138 Constructor, creating and showing a tree control.
3c4f71cc 139
7c913512 140 @param parent
4cc4bfaf 141 Parent window. Must not be @NULL.
7c913512 142 @param id
7977b62a 143 Window identifier. The value @c wxID_ANY indicates a default value.
7c913512 144 @param pos
4cc4bfaf 145 Window position.
7c913512 146 @param size
7977b62a 147 Window size. If wxDefaultSize is specified then the window is sized
4cc4bfaf 148 appropriately.
7c913512 149 @param style
4cc4bfaf 150 Window style. See wxTreeCtrl.
7c913512 151 @param validator
4cc4bfaf 152 Window validator.
7c913512 153 @param name
4cc4bfaf 154 Window name.
3c4f71cc 155
4cc4bfaf 156 @see Create(), wxValidator
23324ae1 157 */
cfbe5614 158 wxTreeCtrl(wxWindow* parent, wxWindowID id = wxID_ANY,
7c913512
FM
159 const wxPoint& pos = wxDefaultPosition,
160 const wxSize& size = wxDefaultSize,
cfbe5614 161 long style = wxTR_DEFAULT_STYLE,
7c913512 162 const wxValidator& validator = wxDefaultValidator,
cfbe5614 163 const wxString& name = wxTreeCtrlNameStr);
03966fcb 164
23324ae1
FM
165
166 /**
167 Destructor, destroying the tree control.
168 */
adaaa686 169 virtual ~wxTreeCtrl();
23324ae1
FM
170
171 /**
172 Adds the root node to the tree, returning the new item.
7977b62a
BP
173
174 The @a image and @a selImage parameters are an index within the normal
175 image list specifying the image to use for unselected and selected
176 items, respectively. If @a image -1 and @a selImage is -1, the same
177 image is used for both selected and unselected items.
23324ae1 178 */
adaaa686
FM
179 virtual wxTreeItemId AddRoot(const wxString& text, int image = -1,
180 int selImage = -1,
181 wxTreeItemData* data = NULL);
23324ae1
FM
182
183 /**
7977b62a
BP
184 Appends an item to the end of the branch identified by @a parent, return
185 a new item id.
03966fcb 186
7977b62a
BP
187 The @a image and @a selImage parameters are an index within the normal
188 image list specifying the image to use for unselected and selected
189 items, respectively. If @a image -1 and @a selImage is -1, the same
190 image is used for both selected and unselected items.
23324ae1
FM
191 */
192 wxTreeItemId AppendItem(const wxTreeItemId& parent,
193 const wxString& text,
194 int image = -1,
195 int selImage = -1,
4cc4bfaf 196 wxTreeItemData* data = NULL);
23324ae1
FM
197
198 /**
7977b62a
BP
199 Sets the buttons image list. The button images assigned with this method
200 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
201 takes ownership of the list).
202
203 Setting or assigning the button image list enables the display of image
204 buttons. Once enabled, the only way to disable the display of button
205 images is to set the button image list to @NULL.
206
23324ae1 207 This function is only available in the generic version.
7977b62a
BP
208
209 @see SetButtonsImageList().
23324ae1
FM
210 */
211 void AssignButtonsImageList(wxImageList* imageList);
212
213 /**
7977b62a
BP
214 Sets the normal image list. The image list assigned with this method
215 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
216 takes ownership of the list).
217
218 @see SetImageList().
23324ae1
FM
219 */
220 void AssignImageList(wxImageList* imageList);
221
222 /**
7977b62a
BP
223 Sets the state image list. Image list assigned with this method will be
224 automatically deleted by wxTreeCtrl as appropriate (i.e. it takes
225 ownership of the list).
226
227 @see SetStateImageList().
23324ae1
FM
228 */
229 void AssignStateImageList(wxImageList* imageList);
230
231 /**
232 Collapses the given item.
233 */
adaaa686 234 virtual void Collapse(const wxTreeItemId& item);
23324ae1
FM
235
236 /**
237 Collapses the root item.
3c4f71cc 238
4cc4bfaf 239 @see ExpandAll()
23324ae1
FM
240 */
241 void CollapseAll();
242
243 /**
244 Collapses this item and all of its children, recursively.
3c4f71cc 245
4cc4bfaf 246 @see ExpandAllChildren()
23324ae1
FM
247 */
248 void CollapseAllChildren(const wxTreeItemId& item);
249
250 /**
251 Collapses the given item and removes all children.
252 */
adaaa686 253 virtual void CollapseAndReset(const wxTreeItemId& item);
23324ae1
FM
254
255 /**
cfbe5614
FM
256 Creates the tree control.
257 See wxTreeCtrl::wxTreeCtrl() for further details.
23324ae1 258 */
cfbe5614 259 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
7977b62a
BP
260 const wxPoint& pos = wxDefaultPosition,
261 const wxSize& size = wxDefaultSize,
cfbe5614 262 long style = wxTR_DEFAULT_STYLE,
7977b62a 263 const wxValidator& validator = wxDefaultValidator,
cfbe5614 264 const wxString& name = wxTreeCtrlNameStr);
23324ae1
FM
265
266 /**
7977b62a 267 Deletes the specified item. A EVT_TREE_DELETE_ITEM() event will be
23324ae1 268 generated.
7977b62a
BP
269
270 This function may cause a subsequent call to GetNextChild() to fail.
23324ae1 271 */
adaaa686 272 virtual void Delete(const wxTreeItemId& item);
23324ae1
FM
273
274 /**
275 Deletes all items in the control. Note that this may not generate
7977b62a 276 EVT_TREE_DELETE_ITEM() events under some Windows versions although
23324ae1
FM
277 normally such event is generated for each removed item.
278 */
adaaa686 279 virtual void DeleteAllItems();
23324ae1
FM
280
281 /**
7977b62a
BP
282 Deletes all children of the given item (but not the item itself). Note
283 that this will @b not generate any events unlike Delete() method.
284
285 If you have called SetItemHasChildren(), you may need to call it again
286 since DeleteChildren() does not automatically clear the setting.
23324ae1 287 */
adaaa686 288 virtual void DeleteChildren(const wxTreeItemId& item);
23324ae1
FM
289
290 /**
7977b62a
BP
291 Starts editing the label of the given @a item. This function generates a
292 EVT_TREE_BEGIN_LABEL_EDIT() event which can be vetoed so that no text
293 control will appear for in-place editing.
294
295 If the user changed the label (i.e. s/he does not press ESC or leave the
296 text control without changes, a EVT_TREE_END_LABEL_EDIT() event will be
297 sent which can be vetoed as well.
3c4f71cc 298
4cc4bfaf 299 @see EndEditLabel(), wxTreeEvent
23324ae1 300 */
cfbe5614
FM
301 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
302 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
23324ae1
FM
303
304 /**
7977b62a
BP
305 Ends label editing. If @a cancelEdit is @true, the edit will be
306 cancelled.
307
308 @note
309 This function is currently supported under Windows only.
3c4f71cc 310
4cc4bfaf 311 @see EditLabel()
23324ae1 312 */
cfbe5614 313 virtual void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false);
23324ae1
FM
314
315 /**
316 Scrolls and/or expands items to ensure that the given item is visible.
317 */
adaaa686 318 virtual void EnsureVisible(const wxTreeItemId& item);
23324ae1
FM
319
320 /**
321 Expands the given item.
322 */
adaaa686 323 virtual void Expand(const wxTreeItemId& item);
23324ae1
FM
324
325 /**
326 Expands all items in the tree.
327 */
328 void ExpandAll();
329
330 /**
331 Expands the given item and all its children recursively.
332 */
333 void ExpandAllChildren(const wxTreeItemId& item);
334
335 /**
7977b62a
BP
336 Retrieves the rectangle bounding the @a item. If @a textOnly is @true,
337 only the rectangle around the item's label will be returned, otherwise
338 the item's image is also taken into account.
339
340 The return value is @true if the rectangle was successfully retrieved or
341 @c @false if it was not (in this case @a rect is not changed) -- for
342 example, if the item is currently invisible.
343
344 Notice that the rectangle coordinates are logical, not physical ones.
345 So, for example, the x coordinate may be negative if the tree has a
346 horizontal scrollbar and its position is not 0.
347
348 @beginWxPythonOnly
349 The wxPython version of this method requires only the @a item and @a
350 textOnly parameters. The return value is either a wxRect object or @c
351 None.
352 @endWxPythonOnly
23324ae1 353 */
fadc2df6
FM
354 virtual bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect,
355 bool textOnly = false) const;
23324ae1
FM
356
357 /**
7977b62a
BP
358 Returns the buttons image list (from which application-defined button
359 images are taken).
360
23324ae1
FM
361 This function is only available in the generic version.
362 */
328f5751 363 wxImageList* GetButtonsImageList() const;
23324ae1
FM
364
365 /**
4cc4bfaf 366 Returns the number of items in the branch. If @a recursively is @true,
7977b62a
BP
367 returns the total number of descendants, otherwise only one level of
368 children is counted.
23324ae1 369 */
cfbe5614
FM
370 virtual size_t GetChildrenCount(const wxTreeItemId& item,
371 bool recursively = true) const;
23324ae1
FM
372
373 /**
374 Returns the number of items in the control.
375 */
adaaa686 376 virtual unsigned int GetCount() const;
23324ae1
FM
377
378 /**
7977b62a
BP
379 Returns the edit control being currently used to edit a label. Returns
380 @NULL if no label is being edited.
381
382 @note This is currently only implemented for wxMSW.
23324ae1 383 */
adaaa686 384 virtual wxTextCtrl* GetEditControl() const;
23324ae1
FM
385
386 /**
387 Returns the first child; call GetNextChild() for the next child.
7977b62a 388
23324ae1 389 For this enumeration function you must pass in a 'cookie' parameter
7977b62a
BP
390 which is opaque for the application but is necessary for the library to
391 make these functions reentrant (i.e. allow more than one enumeration on
392 one and the same object simultaneously). The cookie passed to
393 GetFirstChild() and GetNextChild() should be the same variable.
394
395 Returns an invalid tree item (i.e. wxTreeItemId::IsOk() returns @false)
396 if there are no further children.
397
398 @beginWxPythonOnly
399 In wxPython the returned wxTreeItemId and the new cookie value are both
400 returned as a tuple containing the two values.
401 @endWxPythonOnly
3c4f71cc 402
4cc4bfaf 403 @see GetNextChild(), GetNextSibling()
23324ae1 404 */
fadc2df6
FM
405 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
406 wxTreeItemIdValue& cookie) const;
23324ae1
FM
407
408 /**
409 Returns the first visible item.
410 */
adaaa686 411 virtual wxTreeItemId GetFirstVisibleItem() const;
23324ae1
FM
412
413 /**
414 Returns the normal image list.
415 */
328f5751 416 wxImageList* GetImageList() const;
23324ae1
FM
417
418 /**
419 Returns the current tree control indentation.
420 */
cfbe5614 421 virtual unsigned int GetIndent() const;
23324ae1
FM
422
423 /**
424 Returns the background colour of the item.
425 */
adaaa686 426 virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
23324ae1 427
23324ae1 428 /**
7977b62a 429 Returns the tree item data associated with the item.
23324ae1 430
483724a1 431 @see wxTreeItemData
23324ae1 432
483724a1
FM
433 @beginWxPythonOnly
434 wxPython provides the following shortcut method:
435 @li GetPyData(item): Returns the Python Object associated with the
436 wxTreeItemData for the given item Id.
437 @endWxPythonOnly
438 */
adaaa686 439 virtual wxTreeItemData* GetItemData(const wxTreeItemId& item) const;
7977b62a
BP
440
441 /**
442 Returns the font of the item label.
443 */
adaaa686 444 virtual wxFont GetItemFont(const wxTreeItemId& item) const;
23324ae1
FM
445
446 /**
4cc4bfaf 447 Gets the specified item image. The value of @a which may be:
7977b62a
BP
448 - ::wxTreeItemIcon_Normal: to get the normal item image.
449 - ::wxTreeItemIcon_Selected: to get the selected item image (i.e. the
450 image which is shown when the item is currently selected).
451 - ::wxTreeItemIcon_Expanded: to get the expanded image (this only makes
452 sense for items which have children - then this image is shown when
453 the item is expanded and the normal image is shown when it is
454 collapsed).
455 - ::wxTreeItemIcon_SelectedExpanded: to get the selected expanded image
456 (which is shown when an expanded item is currently selected).
23324ae1 457 */
fadc2df6
FM
458 virtual int GetItemImage(const wxTreeItemId& item,
459 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
23324ae1
FM
460
461 /**
462 Returns the item's parent.
463 */
adaaa686 464 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
23324ae1 465
03966fcb
RR
466 /**
467 Gets the specified item state.
468 */
469 int GetItemState(const wxTreeItemId& item) const;
470
23324ae1
FM
471 /**
472 Returns the item label.
473 */
adaaa686 474 virtual wxString GetItemText(const wxTreeItemId& item) const;
23324ae1
FM
475
476 /**
477 Returns the colour of the item label.
478 */
adaaa686 479 virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
23324ae1
FM
480
481 /**
7977b62a
BP
482 Returns the last child of the item (or an invalid tree item if this item
483 has no children).
3c4f71cc 484
7977b62a 485 @see GetFirstChild(), GetNextSibling(), GetLastChild()
23324ae1 486 */
adaaa686 487 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
23324ae1
FM
488
489 /**
7977b62a
BP
490 Returns the next child; call GetFirstChild() for the first child. For
491 this enumeration function you must pass in a 'cookie' parameter which is
492 opaque for the application but is necessary for the library to make
493 these functions reentrant (i.e. allow more than one enumeration on one
494 and the same object simultaneously). The cookie passed to
495 GetFirstChild() and GetNextChild() should be the same.
496
23324ae1 497 Returns an invalid tree item if there are no further children.
3c4f71cc 498
7977b62a
BP
499 @beginWxPythonOnly
500 In wxPython the returned wxTreeItemId and the new cookie value are both
501 returned as a tuple containing the two values.
502 @endWxPythonOnly
503
4cc4bfaf 504 @see GetFirstChild()
23324ae1 505 */
fadc2df6
FM
506 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
507 wxTreeItemIdValue& cookie) const;
23324ae1
FM
508
509 /**
7977b62a
BP
510 Returns the next sibling of the specified item; call GetPrevSibling()
511 for the previous sibling.
512
23324ae1 513 Returns an invalid tree item if there are no further siblings.
3c4f71cc 514
4cc4bfaf 515 @see GetPrevSibling()
23324ae1 516 */
adaaa686 517 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
23324ae1
FM
518
519 /**
7977b62a
BP
520 Returns the next visible item or an invalid item if this item is the
521 last visible one.
522
523 @note The @a item itself must be visible.
23324ae1 524 */
adaaa686 525 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
23324ae1
FM
526
527 /**
7977b62a
BP
528 Returns the previous sibling of the specified item; call
529 GetNextSibling() for the next sibling.
530
23324ae1 531 Returns an invalid tree item if there are no further children.
3c4f71cc 532
4cc4bfaf 533 @see GetNextSibling()
23324ae1 534 */
adaaa686 535 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
23324ae1
FM
536
537 /**
7977b62a
BP
538 Returns the previous visible item or an invalid item if this item is the
539 first visible one.
540
541 @note The @a item itself must be visible.
23324ae1 542 */
adaaa686 543 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
23324ae1
FM
544
545 /**
7977b62a
BP
546 Returns @true if the control will use a quick calculation for the best
547 size, looking only at the first and last items. The default is @false.
3c4f71cc 548
4cc4bfaf 549 @see SetQuickBestSize()
23324ae1 550 */
328f5751 551 bool GetQuickBestSize() const;
23324ae1
FM
552
553 /**
554 Returns the root item for the tree control.
555 */
adaaa686 556 virtual wxTreeItemId GetRootItem() const;
23324ae1
FM
557
558 /**
7977b62a
BP
559 Returns the selection, or an invalid item if there is no selection. This
560 function only works with the controls without @c wxTR_MULTIPLE style,
561 use GetSelections() for the controls which do have this style.
23324ae1 562 */
adaaa686 563 virtual wxTreeItemId GetSelection() const;
23324ae1
FM
564
565 /**
7977b62a
BP
566 Fills the array of tree items passed in with the currently selected
567 items. This function can be called only if the control has the @c
568 wxTR_MULTIPLE style.
569
23324ae1 570 Returns the number of selected items.
03966fcb 571
7977b62a
BP
572 @beginWxPythonOnly
573 The wxPython version of this method accepts no parameters and returns a
574 Python list of @ref wxTreeItemId "wxTreeItemId"s.
575 @endWxPythonOnly
23324ae1 576 */
cfbe5614 577 virtual size_t GetSelections(wxArrayTreeItemIds& selection) const;
23324ae1
FM
578
579 /**
7977b62a
BP
580 Returns the state image list (from which application-defined state
581 images are taken).
23324ae1 582 */
328f5751 583 wxImageList* GetStateImageList() const;
23324ae1
FM
584
585 /**
7977b62a
BP
586 Calculates which (if any) item is under the given @a point, returning
587 the tree item id at this point plus extra information @a flags. @a flags
588 is a bitlist of the following:
589
590 - @c wxTREE_HITTEST_ABOVE: Above the client area.
591 - @c wxTREE_HITTEST_BELOW: Below the client area.
592 - @c wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
593 - @c wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
594 - @c wxTREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
595 - @c wxTREE_HITTEST_ONITEMINDENT: In the indentation associated with an
596 item.
597 - @c wxTREE_HITTEST_ONITEMLABEL: On the label (string) associated with
598 an item.
599 - @c wxTREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
600 - @c wxTREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view
601 item that is in a user-defined state.
602 - @c wxTREE_HITTEST_TOLEFT: To the right of the client area.
603 - @c wxTREE_HITTEST_TORIGHT: To the left of the client area.
03966fcb 604
7977b62a
BP
605 @beginWxPythonOnly
606 In wxPython both the wxTreeItemId and the flags are returned as a tuple.
607 @endWxPythonOnly
23324ae1 608 */
328f5751 609 wxTreeItemId HitTest(const wxPoint& point, int& flags) const;
23324ae1 610
7977b62a 611
23324ae1 612 /**
7977b62a
BP
613 Inserts an item after a given one (@a previous).
614
615 The @a image and @a selImage parameters are an index within the normal
616 image list specifying the image to use for unselected and selected
617 items, respectively. If @a image -1 and @a selImage is -1, the same
618 image is used for both selected and unselected items.
23324ae1
FM
619 */
620 wxTreeItemId InsertItem(const wxTreeItemId& parent,
621 const wxTreeItemId& previous,
622 const wxString& text,
623 int image = -1,
624 int selImage = -1,
4cc4bfaf 625 wxTreeItemData* data = NULL);
7977b62a
BP
626
627 /**
628 Inserts an item before one identified
629 by its position (@a before). @a before must be less than the number of
630 children.
631
632 The @a image and @a selImage parameters are an index within the normal
633 image list specifying the image to use for unselected and selected
634 items, respectively. If @a image -1 and @a selImage is -1, the same
635 image is used for both selected and unselected items.
636
637 @beginWxPythonOnly
638 In wxPython, this form of this method is called @c InsertItemBefore().
639 @endWxPythonOnly
640 */
7c913512
FM
641 wxTreeItemId InsertItem(const wxTreeItemId& parent,
642 size_t before,
643 const wxString& text,
644 int image = -1,
645 int selImage = -1,
4cc4bfaf 646 wxTreeItemData* data = NULL);
23324ae1
FM
647
648 /**
649 Returns @true if the given item is in bold state.
7977b62a
BP
650
651 @see SetItemBold()
23324ae1 652 */
adaaa686 653 virtual bool IsBold(const wxTreeItemId& item) const;
23324ae1
FM
654
655 /**
7977b62a
BP
656 Returns @true if the control is empty (i.e. has no items, even no root
657 one).
23324ae1 658 */
328f5751 659 bool IsEmpty() const;
23324ae1
FM
660
661 /**
7977b62a
BP
662 Returns @true if the item is expanded (only makes sense if it has
663 children).
23324ae1 664 */
adaaa686 665 virtual bool IsExpanded(const wxTreeItemId& item) const;
23324ae1
FM
666
667 /**
668 Returns @true if the item is selected.
669 */
adaaa686 670 virtual bool IsSelected(const wxTreeItemId& item) const;
23324ae1
FM
671
672 /**
673 Returns @true if the item is visible on the screen.
674 */
adaaa686 675 virtual bool IsVisible(const wxTreeItemId& item) const;
23324ae1
FM
676
677 /**
678 Returns @true if the item has children.
679 */
adaaa686 680 virtual bool ItemHasChildren(const wxTreeItemId& item) const;
23324ae1
FM
681
682 /**
7977b62a
BP
683 Override this function in the derived class to change the sort order of
684 the items in the tree control. The function should return a negative,
685 zero or positive value if the first item is less than, equal to or
686 greater than the second one.
687
688 Please note that you @b must use wxRTTI macros DECLARE_DYNAMIC_CLASS()
689 and IMPLEMENT_DYNAMIC_CLASS() if you override this function because
690 otherwise the base class considers that it is not overridden and uses
691 the default comparison, i.e. sorts the items alphabetically, which
23324ae1 692 allows it optimize away the calls to the virtual function completely.
7977b62a
BP
693
694 @see SortChildren()
23324ae1 695 */
fadc2df6
FM
696 virtual int OnCompareItems(const wxTreeItemId& item1,
697 const wxTreeItemId& item2);
23324ae1
FM
698
699 /**
7977b62a
BP
700 Appends an item as the first child of @a parent, return a new item id.
701
702 The @a image and @a selImage parameters are an index within the normal
703 image list specifying the image to use for unselected and selected
704 items, respectively. If @a image -1 and @a selImage is -1, the same
705 image is used for both selected and unselected items.
23324ae1
FM
706 */
707 wxTreeItemId PrependItem(const wxTreeItemId& parent,
708 const wxString& text,
709 int image = -1,
710 int selImage = -1,
4cc4bfaf 711 wxTreeItemData* data = NULL);
23324ae1
FM
712
713 /**
714 Scrolls the specified item into view.
715 */
adaaa686 716 virtual void ScrollTo(const wxTreeItemId& item);
23324ae1
FM
717
718 /**
7977b62a
BP
719 Selects the given item. In multiple selection controls, can be also used
720 to deselect a currently selected item if the value of @a select is
721 @false.
23324ae1 722 */
adaaa686 723 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
23324ae1
FM
724
725 /**
7977b62a
BP
726 Sets the buttons image list (from which application-defined button
727 images are taken).
728
729 The button images assigned with this method will @b not be deleted by
730 @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it yourself.
731 Setting or assigning the button image list enables the display of image
732 buttons. Once enabled, the only way to disable the display of button
733 images is to set the button image list to @NULL.
734
735 @note This function is only available in the generic version.
736
737 @see AssignButtonsImageList().
23324ae1
FM
738 */
739 void SetButtonsImageList(wxImageList* imageList);
740
741 /**
7977b62a
BP
742 Sets the normal image list. The image list assigned with this method
743 will @b not be deleted by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you
744 must delete it yourself.
745
746 @see AssignImageList().
23324ae1 747 */
adaaa686 748 virtual void SetImageList(wxImageList* imageList);
23324ae1
FM
749
750 /**
751 Sets the indentation for the tree control.
752 */
cfbe5614 753 virtual void SetIndent(unsigned int indent);
23324ae1
FM
754
755 /**
756 Sets the colour of the item's background.
757 */
fadc2df6
FM
758 virtual void SetItemBackgroundColour(const wxTreeItemId& item,
759 const wxColour& col);
23324ae1
FM
760
761 /**
7977b62a
BP
762 Makes item appear in bold font if @a bold parameter is @true or resets
763 it to the normal state.
764
765 @see IsBold()
23324ae1 766 */
adaaa686 767 virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
23324ae1 768
7977b62a
BP
769 /**
770 Sets the item client data.
771
772 @beginWxPythonOnly
773 - @b SetPyData( @a item, @c obj): Associate the given Python Object with
774 the wxTreeItemData for the given item Id.
775 @endWxPythonOnly
776
777 */
adaaa686 778 virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData* data);
7977b62a
BP
779
780
23324ae1
FM
781 /**
782 Gives the item the visual feedback for Drag'n'Drop actions, which is
783 useful if something is dragged from the outside onto the tree control
784 (as opposed to a DnD operation within the tree control, which already
785 is implemented internally).
786 */
fadc2df6
FM
787 virtual void SetItemDropHighlight(const wxTreeItemId& item,
788 bool highlight = true);
23324ae1
FM
789
790 /**
7977b62a
BP
791 Sets the item's font. All items in the tree should have the same height
792 to avoid text clipping, so the fonts height should be the same for all
793 of them, although font attributes may vary.
3c4f71cc 794
4cc4bfaf 795 @see SetItemBold()
23324ae1 796 */
adaaa686 797 virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
23324ae1
FM
798
799 /**
800 Force appearance of the button next to the item. This is useful to
801 allow the user to expand the items which don't have any children now,
802 but instead adding them only when needed, thus minimizing memory
803 usage and loading time.
804 */
fadc2df6
FM
805 virtual void SetItemHasChildren(const wxTreeItemId& item,
806 bool hasChildren = true);
23324ae1
FM
807
808 /**
7977b62a
BP
809 Sets the specified item's image. See GetItemImage() for the description
810 of the @a which parameter.
23324ae1 811 */
fadc2df6
FM
812 virtual void SetItemImage(const wxTreeItemId& item, int image,
813 wxTreeItemIcon which = wxTreeItemIcon_Normal);
23324ae1 814
03966fcb
RR
815 /**
816 Sets the specified item state. The value of @a state may be:
809ca837
RR
817 - @c wxTREE_ITEMSTATE_NONE: to disable the item state (the state image will
818 be not displayed).
819 - @c wxTREE_ITEMSTATE_NEXT: to set the next item state.
820 - @c wxTREE_ITEMSTATE_PREV: to set the previous item state.
03966fcb
RR
821 */
822 void SetItemState(const wxTreeItemId& item, int state);
823
23324ae1
FM
824 /**
825 Sets the item label.
826 */
adaaa686 827 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
23324ae1
FM
828
829 /**
830 Sets the colour of the item's text.
831 */
fadc2df6
FM
832 virtual void SetItemTextColour(const wxTreeItemId& item,
833 const wxColour& col);
23324ae1
FM
834
835 /**
7977b62a
BP
836 If @true is passed, specifies that the control will use a quick
837 calculation for the best size, looking only at the first and last items.
838 Otherwise, it will look at all items. The default is @false.
3c4f71cc 839
4cc4bfaf 840 @see GetQuickBestSize()
23324ae1
FM
841 */
842 void SetQuickBestSize(bool quickBestSize);
843
844 /**
7977b62a
BP
845 Sets the state image list (from which application-defined state images
846 are taken). Image list assigned with this method will @b not be deleted
847 by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it
848 yourself.
849
850 @see AssignStateImageList().
23324ae1 851 */
adaaa686 852 virtual void SetStateImageList(wxImageList* imageList);
23324ae1
FM
853
854 /**
7977b62a
BP
855 Sets the mode flags associated with the display of the tree control. The
856 new mode takes effect immediately.
857
858 @note Generic only; MSW ignores changes.
23324ae1
FM
859 */
860 void SetWindowStyle(long styles);
861
862 /**
7977b62a
BP
863 Sorts the children of the given item using OnCompareItems().
864 You should override that method to change the sort order (the default is
865 ascending case-sensitive alphabetical order).
3c4f71cc 866
4cc4bfaf 867 @see wxTreeItemData, OnCompareItems()
23324ae1 868 */
adaaa686 869 virtual void SortChildren(const wxTreeItemId& item);
23324ae1
FM
870
871 /**
872 Toggles the given item between collapsed and expanded states.
873 */
adaaa686 874 virtual void Toggle(const wxTreeItemId& item);
23324ae1
FM
875
876 /**
877 Toggles the given item between selected and unselected states. For
878 multiselection controls only.
879 */
880 void ToggleItemSelection(const wxTreeItemId& item);
881
882 /**
883 Removes the selection from the currently selected item (if any).
884 */
adaaa686 885 virtual void Unselect();
23324ae1
FM
886
887 /**
7977b62a
BP
888 This function either behaves the same as Unselect() if the control
889 doesn't have @c wxTR_MULTIPLE style, or removes the selection from all
890 items if it does have this style.
23324ae1 891 */
adaaa686 892 virtual void UnselectAll();
23324ae1
FM
893
894 /**
895 Unselects the given item. This works in multiselection controls only.
896 */
897 void UnselectItem(const wxTreeItemId& item);
898};
899
900
e54c96f1 901
23324ae1
FM
902/**
903 @class wxTreeEvent
7c913512 904
7977b62a
BP
905 A tree event holds information about events associated with wxTreeCtrl
906 objects.
907
908 To process input from a tree control, use these event handler macros to
909 direct input to member functions that take a wxTreeEvent argument.
910
911 @beginEventTable{wxTreeEvent}
912 @event{EVT_TREE_BEGIN_DRAG(id, func)}
913 Begin dragging with the left mouse button.
914 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
915 Begin dragging with the right mouse button.
916 @event{EVT_TREE_END_DRAG(id, func)}
917 End dragging with the left or right mouse button.
918 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
919 Begin editing a label. This can be prevented by calling Veto().
920 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
921 Finish editing a label. This can be prevented by calling Veto().
922 @event{EVT_TREE_DELETE_ITEM(id, func)}
923 Delete an item.
924 @event{EVT_TREE_GET_INFO(id, func)}
925 Request information from the application.
926 @event{EVT_TREE_SET_INFO(id, func)}
927 Information is being supplied.
928 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
929 The item has been activated, i.e. chosen by double clicking it with
930 mouse or from keyboard.
931 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
932 The item has been collapsed.
933 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
934 The item is being collapsed. This can be prevented by calling Veto().
935 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
936 The item has been expanded.
937 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
938 The item is being expanded. This can be prevented by calling Veto().
939 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
940 The user has clicked the item with the right mouse button.
941 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
942 The user has clicked the item with the middle mouse button.
943 @event{EVT_TREE_SEL_CHANGED(id, func)}
944 Selection has changed.
945 @event{EVT_TREE_SEL_CHANGING(id, func)}
946 Selection is changing. This can be prevented by calling Veto().
947 @event{EVT_TREE_KEY_DOWN(id, func)}
948 A key has been pressed.
949 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
950 The opportunity to set the item tooltip is being given to the
951 application (call SetToolTip()). Windows only.
952 @event{EVT_TREE_ITEM_MENU(id, func)}
953 The context menu for the selected item has been requested, either by a
954 right click or by using the menu key.
955 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
809ca837 956 The state image has been clicked.
7977b62a 957 @endEventTable
7c913512 958
23324ae1
FM
959 @library{wxbase}
960 @category{events}
7c913512 961
e54c96f1 962 @see wxTreeCtrl
23324ae1
FM
963*/
964class wxTreeEvent : public wxNotifyEvent
965{
966public:
967 /**
23324ae1
FM
968 Constructor, used by wxWidgets itself only.
969 */
cfbe5614
FM
970 wxTreeEvent(wxEventType commandType, wxTreeCtrl* tree,
971 const wxTreeItemId& item = wxTreeItemId());
23324ae1
FM
972
973 /**
974 Returns the item (valid for all events).
975 */
328f5751 976 wxTreeItemId GetItem() const;
23324ae1
FM
977
978 /**
7977b62a
BP
979 Returns the key code if the event is a key event. Use GetKeyEvent() to
980 get the values of the modifier keys for this event (i.e. Shift or Ctrl).
23324ae1 981 */
328f5751 982 int GetKeyCode() const;
23324ae1
FM
983
984 /**
7977b62a 985 Returns the key event for EVT_TREE_KEY_DOWN() events.
23324ae1 986 */
cfbe5614 987 const wxKeyEvent& GetKeyEvent() const;
23324ae1
FM
988
989 /**
990 Returns the label if the event is a begin or end edit label event.
991 */
cfbe5614 992 const wxString& GetLabel() const;
23324ae1
FM
993
994 /**
7977b62a
BP
995 Returns the old item index (valid for EVT_TREE_ITEM_CHANGING() and
996 EVT_TREE_ITEM_CHANGED() events).
23324ae1 997 */
328f5751 998 wxTreeItemId GetOldItem() const;
23324ae1
FM
999
1000 /**
1001 Returns the position of the mouse pointer if the event is a drag or
1002 menu-context event.
7977b62a
BP
1003
1004 In both cases the position is in client coordinates - i.e. relative to
1005 the wxTreeCtrl window (so that you can pass it directly to e.g.
1006 wxWindow::PopupMenu()).
23324ae1 1007 */
328f5751 1008 wxPoint GetPoint() const;
23324ae1
FM
1009
1010 /**
7977b62a
BP
1011 Returns @true if the label edit was cancelled. This should be called
1012 from within an EVT_TREE_END_LABEL_EDIT() handler.
23324ae1 1013 */
328f5751 1014 bool IsEditCancelled() const;
23324ae1
FM
1015
1016 /**
7977b62a
BP
1017 Set the tooltip for the item (valid for EVT_TREE_ITEM_GETTOOLTIP()
1018 events). Windows only.
23324ae1
FM
1019 */
1020 void SetToolTip(const wxString& tooltip);
1021};