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