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