]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/treelist.h
Try native method first in LoadFile() and SaveFile()
[wxWidgets.git] / interface / wx / treelist.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: interface/wx/treelist.h
3 // Purpose: wxTreeListCtrl class documentation
4 // Author: Vadim Zeitlin
5 // Created: 2011-08-17
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 /**
11 wxTreeListCtrl styles.
12
13 Notice that using wxTL_USER_3STATE implies wxTL_3STATE and wxTL_3STATE in
14 turn implies wxTL_CHECKBOX.
15 */
16 enum
17 {
18 wxTL_SINGLE = 0x0000, /// This is the default anyhow.
19 wxTL_MULTIPLE = 0x0001, /// Allow multiple selection.
20 wxTL_CHECKBOX = 0x0002, /// Show checkboxes in the first column.
21 wxTL_3STATE = 0x0004, /// Allow 3rd state in checkboxes.
22 wxTL_USER_3STATE = 0x0008, /// Allow user to set 3rd state.
23 /**
24 Don't show the column headers.
25
26 By default this control shows the column headers, using this class
27 allows to avoid this and show only the data.
28
29 @since 2.9.5
30 */
31 wxTL_NO_HEADER = 0x0010,
32
33 wxTL_DEFAULT_STYLE = wxTL_SINGLE,
34 wxTL_STYLE_MASK = wxTL_SINGLE |
35 wxTL_MULTIPLE |
36 wxTL_CHECKBOX |
37 wxTL_3STATE |
38 wxTL_USER_3STATE
39 };
40
41
42 /**
43 @class wxTreeListItem
44
45 Unique identifier of an item in wxTreeListCtrl.
46
47 This is an opaque class which can't be used by the application in any other
48 way than receiving or passing it to wxTreeListCtrl and checking for
49 validity.
50
51 @see wxTreeListCtrl
52
53 @library{wxadv}
54 @category{ctrl}
55
56 @since 2.9.3
57 */
58 class wxTreeListItem
59 {
60 public:
61 /**
62 Only the default constructor is publicly accessible.
63
64 Default constructing a wxTreeListItem creates an invalid item.
65 */
66 wxTreeListItem();
67
68 /**
69 Return true if the item is valid.
70 */
71 bool IsOk() const;
72 };
73
74
75 /**
76 @class wxTreeListItemComparator
77
78 Class defining sort order for the items in wxTreeListCtrl.
79
80 @see wxTreeListCtrl
81
82 @library{wxadv}
83 @category{ctrl}
84
85 @since 2.9.3
86 */
87 class wxTreeListItemComparator
88 {
89 public:
90 /**
91 Default constructor.
92
93 Notice that this class is not copyable, comparators are not passed by
94 value.
95 */
96 wxTreeListItemComparator();
97
98 /**
99 Pure virtual function which must be overridden to define sort order.
100
101 The comparison function should return negative, null or positive value
102 depending on whether the first item is less than, equal to or greater
103 than the second one. The items should be compared using their values
104 for the given column.
105
106 @param treelist
107 The control whose contents is being sorted.
108 @param column
109 The column of this control used for sorting.
110 @param first
111 First item to compare.
112 @param second
113 Second item to compare.
114 @return
115 A negative value if the first item is less than (i.e. should appear
116 above) the second one, zero if the two items are equal or a
117 positive value if the first item is greater than (i.e. should
118 appear below) the second one.
119 */
120 virtual int
121 Compare(wxTreeListCtrl* treelist,
122 unsigned column,
123 wxTreeListItem first,
124 wxTreeListItem second) = 0;
125
126 /**
127 Trivial but virtual destructor.
128
129 Although this class is not used polymorphically by wxWidgets itself,
130 provide virtual dtor in case it's used like this in the user code.
131 */
132 virtual ~wxTreeListItemComparator();
133 };
134
135
136 /**
137 Container of multiple items.
138 */
139 typedef wxVector<wxTreeListItem> wxTreeListItems;
140
141
142 /**
143 Special wxTreeListItem value meaning "insert before the first item".
144
145 This value can be passed to wxTreeListCtrl::InsertItem() to achieve the
146 same effect as calling wxTreeListCtrl::PrependItem().
147 */
148 extern const wxTreeListItem wxTLI_FIRST;
149
150
151 /**
152 Special wxTreeListItem value meaning "insert after the last item".
153
154 This value can be passed to wxTreeListCtrl::InsertItem() to achieve the
155 same effect as calling wxTreeListCtrl::AppendItem().
156 */
157 extern const wxTreeListItem wxTLI_LAST;
158
159
160 /**
161 @class wxTreeListCtrl
162
163 A control combining wxTreeCtrl and wxListCtrl features.
164
165 This is a multi-column tree control optionally supporting images and
166 checkboxes for the items in the first column.
167
168 It is currently implemented using wxDataViewCtrl internally but provides a
169 much simpler interface for the common use case it addresses. Thus, one of
170 the design principles for this control is simplicity and intentionally
171 doesn't provide all the features of wxDataViewCtrl. Most importantly, this
172 class stores all its data internally and doesn't require you to define a
173 custom model for it.
174
175 Instead, this controls works like wxTreeCtrl or non-virtual wxListCtrl and
176 allows you to simply add items to it using wxTreeListCtrl::AppendItem() and
177 related methods. Typically, you start by setting up the columns (you must
178 have at least one) by calling wxTreeListCtrl::AppendColumn() and then add
179 the items. While only the text of the first column can be specified when
180 adding them, you can use wxTreeListCtrl::SetItemText() to set the text of
181 the other columns.
182
183
184 Unlike wxTreeCtrl or wxListCtrl this control can sort its items on its own.
185 To allow user to sort the control contents by clicking on some column you
186 should use wxCOL_SORTABLE flag when adding that column to the control. When
187 a column with this flag is clicked, the control resorts itself using the
188 values in this column. By default the sort is done using alphabetical order
189 comparison of the items text, which is not always correct (e.g. this
190 doesn't work for the numeric columns). To change this you may use
191 SetItemComparator() method to provide a custom comparator, i.e. simply an
192 object that implements comparison between the two items. The treelist
193 sample shows an example of doing this. And if you need to sort the control
194 programmatically, you can call SetSortColumn() method.
195
196
197 Here are the styles supported by this control. Notice that using
198 wxTL_USER_3STATE implies wxTL_3STATE and wxTL_3STATE in turn implies
199 wxTL_CHECKBOX.
200
201 @beginStyleTable
202 @style{wxTL_SINGLE}
203 Single selection, this is the default.
204 @style{wxTL_MULTIPLE}
205 Allow multiple selection, see GetSelections().
206 @style{wxTL_CHECKBOX}
207 Show the usual, 2 state, checkboxes for the items in the first column.
208 @style{wxTL_3STATE}
209 Show the checkboxes that can possibly be set by the program, but not
210 the user, to a third, undetermined, state, for the items in the first
211 column. Implies wxTL_CHECKBOX.
212 @style{wxTL_USER_3STATE}
213 Same as wxTL_3STATE but the user can also set the checkboxes to the
214 undetermined state. Implies wxTL_3STATE.
215 @style{wxTL_DEFAULT_STYLE}
216 Style used by the control by default, just wxTL_SINGLE currently.
217 @endStyleTable
218
219 @beginEventTable{wxTreeListEvent}
220 @event{EVT_TREELIST_SELECTION_CHANGED(id, func)}
221 Process @c wxEVT_TREELIST_SELECTION_CHANGED event and notifies
222 about the selection change in the control. In the single selection case
223 the item indicated by the event has been selected and previously
224 selected item, if any, was deselected. In multiple selection case, the
225 selection of this item has just changed (it may have been either
226 selected or deselected) but notice that the selection of other items
227 could have changed as well, use wxTreeListCtrl::GetSelections() to
228 retrieve the new selection if necessary.
229 @event{EVT_TREELIST_ITEM_EXPANDING(id, func)}
230 Process @c wxEVT_TREELIST_ITEM_EXPANDING event notifying about
231 the given branch being expanded. This event is sent before the
232 expansion occurs and can be vetoed to prevent it from happening.
233 @event{EVT_TREELIST_ITEM_EXPANDED(id, func)}
234 Process @c wxEVT_TREELIST_ITEM_EXPANDED event notifying about
235 the expansion of the given branch. This event is sent after the
236 expansion occurs and can't be vetoed.
237 @event{EVT_TREELIST_ITEM_CHECKED(id, func)}
238 Process @c wxEVT_TREELIST_ITEM_CHECKED event notifying about
239 the user checking or unchecking the item. You can use
240 wxTreeListCtrl::GetCheckedState() to retrieve the new item state and
241 wxTreeListEvent::GetOldCheckedState() to get the previous one.
242 @event{EVT_TREELIST_ITEM_ACTIVATED(id, func)}
243 Process @c wxEVT_TREELIST_ITEM_ACTIVATED event notifying about
244 the user double clicking the item or activating it from keyboard.
245 @event{EVT_TREELIST_ITEM_CONTEXT_MENU(id, func)}
246 Process @c wxEVT_TREELIST_ITEM_CONTEXT_MENU event indicating
247 that the popup menu for the given item should be displayed.
248 @event{EVT_TREELIST_COLUMN_SORTED(id, func)}
249 Process @c wxEVT_TREELIST_COLUMN_SORTED event indicating that
250 the control contents has just been resorted using the specified column.
251 The event doesn't carry the sort direction, use GetSortColumn() method
252 if you need to know it.
253 @endEventTable
254
255 @library{wxadv}
256 @category{ctrl}
257
258 @since 2.9.3
259
260 @see wxTreeCtrl, wxDataViewCtrl
261 */
262 class wxTreeListCtrl : public wxWindow
263 {
264 public:
265 /**
266 Default constructor, call Create() later.
267
268 This constructor is used during two-part construction process when it
269 is impossible or undesirable to create the window when constructing the
270 object.
271 */
272 wxTreeListCtrl();
273
274 /**
275 Full constructing, creating the object and its window.
276
277 See Create() for the parameters description.
278 */
279 wxTreeListCtrl(wxWindow* parent,
280 wxWindowID id,
281 const wxPoint& pos = wxDefaultPosition,
282 const wxSize& size = wxDefaultSize,
283 long style = wxTL_DEFAULT_STYLE,
284 const wxString& name = wxTreeListCtrlNameStr);
285
286 /**
287 Create the control window.
288
289 Can be only called for the objects created using the default
290 constructor and exactly once.
291
292 @param parent
293 The parent window, must be non-NULL.
294 @param id
295 The window identifier, may be ::wxID_ANY.
296 @param pos
297 The initial window position, usually unused.
298 @param size
299 The initial window size, usually unused.
300 @param style
301 The window style, see their description in the class documentation.
302 @param name
303 The name of the window.
304 */
305 bool Create(wxWindow* parent,
306 wxWindowID id,
307 const wxPoint& pos = wxDefaultPosition,
308 const wxSize& size = wxDefaultSize,
309 long style = wxTL_DEFAULT_STYLE,
310 const wxString& name = wxTreeListCtrlNameStr);
311
312
313 /**
314 Image list methods.
315
316 Like wxTreeCtrl and wxListCtrl this class uses wxImageList so if you
317 intend to use item icons with it, you must construct wxImageList
318 containing them first and then specify the indices of the icons in this
319 image list when adding the items later.
320 */
321 //@{
322
323 /// A constant indicating that no image should be used for an item.
324 static const int NO_IMAGE = -1;
325
326 /**
327 Sets the image list and gives its ownership to the control.
328
329 The image list assigned with this method will be automatically deleted
330 by wxTreeCtrl as appropriate (i.e. it takes ownership of the list).
331
332 @see SetImageList().
333 */
334 void AssignImageList(wxImageList* imageList);
335
336 /**
337 Sets the image list.
338
339 The image list assigned with this method will @b not be deleted by the
340 control itself and you will need to delete it yourself, use
341 AssignImageList() to give the image list ownership to the control.
342
343 @param imageList
344 Image list to use, may be @NULL to not show any images any more.
345 */
346 void SetImageList(wxImageList* imageList);
347
348 //@}
349
350
351 /**
352 Column methods.
353 */
354 //@{
355
356 /**
357 Add a column with the given title and attributes.
358
359 @param title
360 The column label.
361 @param width
362 The width of the column in pixels or the special
363 wxCOL_WIDTH_AUTOSIZE value indicating that the column should adjust
364 to its contents. Notice that the first column is special and will
365 be always resized to fill all the space not taken by the other
366 columns, i.e. the width specified here is ignored for it.
367 @param align
368 Alignment of both the column header and its items.
369 @param flags
370 Column flags, currently can include wxCOL_RESIZABLE to allow the
371 user to resize the column and wxCOL_SORTABLE to allow the user to
372 resort the control contents by clicking on this column.
373 @return
374 Index of the new column or -1 on failure.
375 */
376 int AppendColumn(const wxString& title,
377 int width = wxCOL_WIDTH_AUTOSIZE,
378 wxAlignment align = wxALIGN_LEFT,
379 int flags = wxCOL_RESIZABLE);
380
381 /// Return the total number of columns.
382 unsigned GetColumnCount() const;
383
384 /**
385 Delete the column with the given index.
386
387 @param col
388 Column index in 0 to GetColumnCount() (exclusive) range.
389 @return
390 True if the column was deleted, false if index is invalid or
391 deleting the column failed for some other reason.
392 */
393 bool DeleteColumn(unsigned col);
394
395 /**
396 Delete all columns.
397
398 @see DeleteAllItems()
399 */
400 void ClearColumns();
401
402 /**
403 Change the width of the given column.
404
405 Set column width to either the given value in pixels or to the value
406 large enough to fit all of the items if width is wxCOL_WIDTH_AUTOSIZE.
407
408 Notice that setting the width of the first column is ignored as this
409 column is always resized to fill the space left by the other columns.
410 */
411 void SetColumnWidth(unsigned col, int width);
412
413 /// Get the current width of the given column in pixels.
414 int GetColumnWidth(unsigned col) const;
415
416 /**
417 Get the width appropriate for showing the given text.
418
419 This is typically used as second argument for AppendColumn() or with
420 SetColumnWidth().
421 */
422 int WidthFor(const wxString& text) const;
423
424 //@}
425
426
427 /**
428 Adding and removing items.
429
430 When adding items, the parent and text of the first column of the new item
431 must always be specified, the rest is optional.
432
433 Each item can have two images: one used for closed state and another
434 for opened one. Only the first one is ever used for the items that
435 don't have children. And both are not set by default.
436
437 It is also possible to associate arbitrary client data pointer with the
438 new item. It will be deleted by the control when the item is deleted
439 (either by an explicit DeleteItem() call or because the entire control
440 is destroyed).
441 */
442 //@{
443
444 /// Same as InsertItem() with wxTLI_LAST.
445 wxTreeListItem AppendItem(wxTreeListItem parent,
446 const wxString& text,
447 int imageClosed = NO_IMAGE,
448 int imageOpened = NO_IMAGE,
449 wxClientData* data = NULL);
450
451 /**
452 Insert a new item into the tree.
453
454 @param parent
455 The item parent. Must be valid, may be GetRootItem().
456 @param previous
457 The previous item that this one should be inserted immediately
458 after. It must be valid but may be one of the special values
459 wxTLI_FIRST or wxTLI_LAST indicating that the item should be either
460 inserted before the first child of its parent (if any) or after the
461 last one.
462 @param imageClosed
463 The normal item image, may be NO_IMAGE to not show any image.
464 @param imageOpened
465 The item image shown when it's in the expanded state.
466 @param data
467 Optional client data pointer that can be later retrieved using
468 GetItemData() and will be deleted by the tree when the item itself
469 is deleted.
470 */
471 wxTreeListItem InsertItem(wxTreeListItem parent,
472 wxTreeListItem previous,
473 const wxString& text,
474 int imageClosed = NO_IMAGE,
475 int imageOpened = NO_IMAGE,
476 wxClientData* data = NULL);
477
478 /// Same as InsertItem() with wxTLI_FIRST.
479 wxTreeListItem PrependItem(wxTreeListItem parent,
480 const wxString& text,
481 int imageClosed = NO_IMAGE,
482 int imageOpened = NO_IMAGE,
483 wxClientData* data = NULL);
484
485 /// Delete the specified item.
486 void DeleteItem(wxTreeListItem item);
487
488 /// Delete all tree items.
489 void DeleteAllItems();
490
491 //@}
492
493
494 /**
495 Methods for the tree navigation.
496
497 The tree has an invisible root item which is the hidden parent of all
498 top-level items in the tree. Starting from it it is possible to iterate
499 over all tree items using GetNextItem().
500
501 It is also possible to iterate over just the children of the given item
502 by using GetFirstChild() to get the first of them and then calling
503 GetNextSibling() to retrieve all the others.
504 */
505 //@{
506
507 /// Return the (never shown) root item.
508 wxTreeListItem GetRootItem() const;
509
510 /**
511 Return the parent of the given item.
512
513 All the tree items visible in the tree have valid parent items, only
514 the never shown root item has no parent.
515 */
516 wxTreeListItem GetItemParent(wxTreeListItem item) const;
517
518 /**
519 Return the first child of the given item.
520
521 Item may be the root item.
522
523 Return value may be invalid if the item doesn't have any children.
524 */
525 wxTreeListItem GetFirstChild(wxTreeListItem item) const;
526
527 /**
528 Return the next sibling of the given item.
529
530 Return value may be invalid if there are no more siblings.
531 */
532 wxTreeListItem GetNextSibling(wxTreeListItem item) const;
533
534 /**
535 Return the first item in the tree.
536
537 This is the first child of the root item.
538
539 @see GetNextItem()
540 */
541 wxTreeListItem GetFirstItem() const;
542
543 /**
544 Get item after the given one in the depth-first tree-traversal order.
545
546 Calling this function starting with the result of GetFirstItem() allows
547 iterating over all items in the tree.
548
549 The iteration stops when this function returns an invalid item, i.e.
550 @code
551 for ( wxTreeListItem item = tree->GetFirstItem();
552 item.IsOk();
553 item = tree->GetNextItem(item) )
554 {
555 ... Do something with every tree item ...
556 }
557 @endcode
558 */
559 wxTreeListItem GetNextItem(wxTreeListItem item) const;
560
561 //@}
562
563
564 /**
565 Items attributes
566 */
567 //@{
568
569 /**
570 Return the text of the given item.
571
572 By default, returns the text of the first column but any other one can
573 be specified using @a col argument.
574 */
575 const wxString& GetItemText(wxTreeListItem item, unsigned col = 0) const;
576
577 /**
578 Set the text of the specified column of the given item.
579 */
580 void SetItemText(wxTreeListItem item, unsigned col, const wxString& text);
581
582 /**
583 Set the text of the first column of the given item.
584 */
585 void SetItemText(wxTreeListItem item, const wxString& text);
586
587 /**
588 Set the images for the given item.
589
590 See InsertItem() for the images parameters descriptions.
591 */
592 void SetItemImage(wxTreeListItem item, int closed, int opened = NO_IMAGE);
593
594 /**
595 Get the data associated with the given item.
596
597 The returned pointer may be @NULL.
598
599 It must not be deleted by the caller as this will be done by the
600 control itself.
601 */
602 wxClientData* GetItemData(wxTreeListItem item) const;
603
604 /**
605 Set the data associated with the given item.
606
607 Previous client data, if any, is deleted when this function is called
608 so it may be used to delete the current item data object and reset it
609 by passing @NULL as @a data argument.
610 */
611 void SetItemData(wxTreeListItem item, wxClientData* data);
612
613 //@}
614
615
616 /**
617 Expanding and collapsing tree branches.
618
619 Notice that calling neither Expand() nor Collapse() method generates
620 any events.
621 */
622 //@{
623
624 /**
625 Expand the given tree branch.
626 */
627 void Expand(wxTreeListItem item);
628
629 /**
630 Collapse the given tree branch.
631 */
632 void Collapse(wxTreeListItem item);
633
634 /**
635 Return whether the given item is expanded.
636 */
637 bool IsExpanded(wxTreeListItem item) const;
638
639 //@}
640
641
642 /**
643 Selection methods.
644
645 The behaviour of the control is different in single selection mode (the
646 default) and multi-selection mode (if @c wxTL_MULTIPLE was specified
647 when creating it). Not all methods can be used in both modes and some
648 of those that can don't behave in the same way in two cases.
649 */
650 //@{
651
652 /**
653 Return the currently selected item.
654
655 This method can't be used with multi-selection controls, use
656 GetSelections() instead.
657
658 The return value may be invalid if no item has been selected yet. Once
659 an item in a single selection control was selected, it will keep a
660 valid selection.
661 */
662 wxTreeListItem GetSelection() const;
663
664 /**
665 Fill in the provided array with all the selected items.
666
667 This method can be used in both single and multi-selection case.
668
669 The previous array contents is destroyed.
670
671 Returns the number of selected items.
672 */
673 unsigned GetSelections(wxTreeListItems& selections) const;
674
675 /**
676 Select the given item.
677
678 In single selection mode, deselects any other selected items, in
679 multi-selection case it adds to the selection.
680 */
681 void Select(wxTreeListItem item);
682
683 /**
684 Deselect the given item.
685
686 This method can be used in multiple selection mode only.
687 */
688 void Unselect(wxTreeListItem item);
689
690 /**
691 Return true if the item is selected.
692
693 This method can be used in both single and multiple selection modes.
694 */
695 bool IsSelected(wxTreeListItem item) const;
696
697 /**
698 Select all the control items.
699
700 Can be only used in multi-selection mode.
701 */
702 void SelectAll();
703
704 /**
705 Deselect all the control items.
706
707 Can be only used in multi-selection mode.
708 */
709 void UnselectAll();
710
711 //@}
712
713
714 /**
715 Checkbox handling
716
717 Methods in this section can only be used with the controls created with
718 wxTL_CHECKBOX style.
719 */
720 //@{
721
722 /**
723 Change the item checked state.
724
725 @param item
726 Valid non-root tree item.
727 @param state
728 One of wxCHK_CHECKED, wxCHK_UNCHECKED or, for the controls with
729 wxTL_3STATE or wxTL_USER_3STATE styles, wxCHK_UNDETERMINED.
730 */
731 void CheckItem(wxTreeListItem item, wxCheckBoxState state = wxCHK_CHECKED);
732
733 /**
734 Change the checked state of the given item and all its children.
735
736 This is the same as CheckItem() but checks or unchecks not only this
737 item itself but all its children recursively as well.
738 */
739 void CheckItemRecursively(wxTreeListItem item,
740 wxCheckBoxState state = wxCHK_CHECKED);
741
742 /**
743 Uncheck the given item.
744
745 This is synonymous with CheckItem(wxCHK_UNCHECKED).
746 */
747 void UncheckItem(wxTreeListItem item);
748
749 /**
750 Update the state of the parent item to reflect the checked state of its
751 children.
752
753 This method updates the parent of this item recursively: if this item
754 and all its siblings are checked, the parent will become checked as
755 well. If this item and all its siblings are unchecked, the parent will
756 be unchecked. And if the siblings of this item are not all in the same
757 state, the parent will be switched to indeterminate state. And then the
758 same logic will be applied to the parents parent and so on recursively.
759
760 This is typically called when the state of the given item has changed
761 from EVT_TREELIST_ITEM_CHECKED() handler in the controls which have
762 wxTL_3STATE flag. Notice that without this flag this function can't
763 work as it would be unable to set the state of a parent with both
764 checked and unchecked items so it's only allowed to call it when this
765 flag is set.
766 */
767 void UpdateItemParentStateRecursively(wxTreeListItem item);
768
769 /**
770 Return the checked state of the item.
771
772 The return value can be wxCHK_CHECKED, wxCHK_UNCHECKED or
773 wxCHK_UNDETERMINED.
774 */
775 wxCheckBoxState GetCheckedState(wxTreeListItem item) const;
776
777 /**
778 Return true if all children of the given item are in the specified
779 state.
780
781 This is especially useful for the controls with @c wxTL_3STATE style to
782 allow to decide whether the parent effective state should be the same
783 @a state, if all its children are in it, or ::wxCHK_UNDETERMINED.
784
785 @see UpdateItemParentStateRecursively()
786 */
787 bool AreAllChildrenInState(wxTreeListItem item,
788 wxCheckBoxState state) const;
789
790 //@}
791
792 /**
793 Sorting.
794
795 If some control columns were added with wxCOL_SORTABLE flag, clicking
796 on them will automatically resort the control using the custom
797 comparator set by SetItemComparator() or by doing alphabetical
798 comparison by default.
799
800 In any case, i.e. even if the user can't sort the control by clicking
801 on its header, you may call SetSortColumn() to sort it programmatically
802 and call GetSortColumn() to determine whether it's sorted now and, if
803 so, by which column and in which order.
804 */
805 //@{
806
807 /**
808 Set the column to use for sorting and the order in which to sort.
809
810 Calling this method resorts the control contents using the values of
811 the items in the specified column. Sorting uses custom comparator set
812 with SetItemComparator() or alphabetical comparison of items texts if
813 none was specified.
814
815 Notice that currently there is no way to reset sort order.
816
817 @param col
818 A valid column index.
819 @param ascendingOrder
820 Indicates whether the items should be sorted in ascending (A to Z)
821 or descending (Z to A) order.
822 */
823 void SetSortColumn(unsigned col, bool ascendingOrder = true);
824
825 /**
826 Return the column currently used for sorting, if any.
827
828 If the control is currently unsorted, the function simply returns
829 @false and doesn't modify any of its output parameters.
830
831 @param col
832 Receives the index of the column used for sorting if non-@NULL.
833 @param ascendingOrder
834 Receives @true or @false depending on whether the items are sorted
835 in ascending or descending order.
836 @return
837 @true if the control is sorted or @false if it isn't sorted at all.
838 */
839 bool GetSortColumn(unsigned* col, bool* ascendingOrder = NULL);
840
841 /**
842 Set the object to use for comparing the items.
843
844 This object will be used when the control is being sorted because the
845 user clicked on a sortable column or SetSortColumn() was called.
846
847 The provided pointer is stored by the control so the object it points
848 to must have a life-time equal or greater to that of the control
849 itself. In addition, the pointer can be @NULL to stop using custom
850 comparator and revert to the default alphabetical comparison.
851 */
852 void SetItemComparator(wxTreeListItemComparator* comparator);
853
854 //@}
855
856
857 /**
858 View window.
859
860 This control itself is entirely covered by the "view window" which is
861 currently a wxDataViewCtrl but if you want to avoid relying on this to
862 allow your code to work with later versions which might not be
863 wxDataViewCtrl-based, use GetView() function only and only use
864 GetDataView() if you really need to call wxDataViewCtrl methods on it.
865 */
866 //@{
867
868 /**
869 Return the view part of this control as a wxWindow.
870
871 This method always returns non-@NULL pointer once the window was
872 created.
873 */
874 wxWindow* GetView() const;
875
876 /**
877 Return the view part of this control as wxDataViewCtrl.
878
879 This method may return @NULL in the future, non wxDataViewCtrl-based,
880 versions of this class, use GetView() unless you really need to use
881 wxDataViewCtrl methods on the returned object.
882 */
883 wxDataViewCtrl* GetDataView() const;
884
885 //@}
886 };
887
888
889
890 /**
891 Event generated by wxTreeListCtrl.
892
893 @since 2.9.3
894 */
895 class wxTreeListEvent : public wxNotifyEvent
896 {
897 public:
898 wxTreeListEvent();
899
900 /**
901 Return the item affected by the event.
902
903 This is the item being selected, expanded, checked or activated
904 (depending on the event type).
905 */
906 wxTreeListItem GetItem() const;
907
908 /**
909 Return the previous state of the item checkbox.
910
911 This method can be used with @c wxEVT_TREELIST_ITEM_CHECKED
912 events only.
913
914 Notice that the new state of the item can be retrieved using
915 wxTreeListCtrl::GetCheckedState().
916 */
917 wxCheckBoxState GetOldCheckedState() const;
918
919 /**
920 Return the column affected by the event.
921
922 This is currently only used with @c wxEVT_TREELIST_COLUMN_SORTED
923 event.
924 */
925 unsigned GetColumn() const;
926 };
927
928
929 /**
930 Type of wxTreeListEvent event handlers.
931
932 This macro should be used with wxEvtHandler::Connect() when connecting to
933 wxTreeListCtrl events.
934 */
935 #define wxTreeListEventHandler(func) \
936 wxEVENT_HANDLER_CAST(wxTreeListEventFunction, func)
937
938
939 wxEventType wxEVT_TREELIST_SELECTION_CHANGED;
940 wxEventType wxEVT_TREELIST_ITEM_EXPANDING;
941 wxEventType wxEVT_TREELIST_ITEM_EXPANDED;
942 wxEventType wxEVT_TREELIST_ITEM_CHECKED;
943 wxEventType wxEVT_TREELIST_ITEM_ACTIVATED;
944 wxEventType wxEVT_TREELIST_ITEM_CONTEXT_MENU;
945 wxEventType wxEVT_TREELIST_COLUMN_SORTED;