treelist.h 31 KB

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