Fl_Tree.H 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // "$Id: Fl_Tree.H 10081 2014-01-24 19:03:15Z greg.ercolano $"
  3. //
  4. #ifndef FL_TREE_H
  5. #define FL_TREE_H
  6. #include <FL/Fl.H>
  7. #include <FL/Fl_Group.H>
  8. #include <FL/Fl_Scrollbar.H>
  9. #include <FL/fl_draw.H>
  10. #include <FL/Fl_Tree_Item.H>
  11. #include <FL/Fl_Tree_Prefs.H>
  12. //////////////////////
  13. // FL/Fl_Tree.H
  14. //////////////////////
  15. //
  16. // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
  17. // Copyright (C) 2009-2010 by Greg Ercolano.
  18. //
  19. // This library is free software. Distribution and use rights are outlined in
  20. // the file "COPYING" which should have been included with this file. If this
  21. // file is missing or damaged, see the license at:
  22. //
  23. // http://www.fltk.org/COPYING.php
  24. //
  25. // Please report all bugs and problems on the following page:
  26. //
  27. // http://www.fltk.org/str.php
  28. //
  29. ///
  30. /// \file
  31. /// \brief This file contains the definitions of the Fl_Tree class
  32. ///
  33. /// \class Fl_Tree
  34. ///
  35. /// \brief Tree widget.
  36. ///
  37. /// \image html tree-simple.png "Fl_Tree example program"
  38. /// \image latex tree-simple.png "Fl_Tree example program" width=4cm
  39. ///
  40. /// \code
  41. /// Fl_Tree // Top level widget
  42. /// |--- Fl_Tree_Item // Items in the tree
  43. /// |--- Fl_Tree_Prefs // Preferences for the tree
  44. /// |--- Fl_Tree_Connector (enum) // Connection modes
  45. /// |--- Fl_Tree_Select (enum) // Selection modes
  46. /// |--- Fl_Tree_Sort (enum) // Sort behavior
  47. /// \endcode
  48. ///
  49. /// Similar to Fl_Browser, Fl_Tree is a browser of Fl_Tree_Item's arranged
  50. /// in a parented hierarchy, or 'tree'. Subtrees can be expanded or closed.
  51. /// Items can be added, deleted, inserted, sorted and re-ordered.
  52. ///
  53. /// The tree items may also contain other FLTK widgets, like buttons, input fields,
  54. /// or even "custom" widgets.
  55. ///
  56. /// The callback() is invoked depending on the value of when():
  57. ///
  58. /// - FL_WHEN_RELEASE -- callback invoked when left mouse button is released on an item
  59. /// - FL_WHEN_CHANGED -- callback invoked when left mouse changes selection state
  60. ///
  61. /// The simple way to define a tree:
  62. /// \code
  63. /// #include <FL/Fl_Tree.H>
  64. /// [..]
  65. /// Fl_Tree tree(X,Y,W,H);
  66. /// tree.begin();
  67. /// tree.add("Flintstones/Fred");
  68. /// tree.add("Flintstones/Wilma");
  69. /// tree.add("Flintstones/Pebbles");
  70. /// tree.add("Simpsons/Homer");
  71. /// tree.add("Simpsons/Marge");
  72. /// tree.add("Simpsons/Bart");
  73. /// tree.add("Simpsons/Lisa");
  74. /// tree.end();
  75. /// \endcode
  76. ///
  77. /// \par FEATURES
  78. /// Items can be added with add(),<BR>
  79. /// removed with remove(),<BR>
  80. /// completely cleared with clear(),<BR>
  81. /// inserted with insert() and insert_above(),<BR>
  82. /// selected/deselected with select() and deselect(),<BR>
  83. /// open/closed with open() and close(),<BR>
  84. /// positioned on the screen with show_item_top(), show_item_middle() and
  85. /// show_item_bottom(),<BR>
  86. /// item children can be swapped around with Fl_Tree_Item::swap_children(),<BR>
  87. /// sorting can be controlled when items are add()ed via sortorder().<BR>
  88. /// You can walk the entire tree with first() and next().<BR>
  89. /// You can walk visible items with first_visible_item()
  90. /// and next_visible_item().<BR>
  91. /// You can walk selected items with first_selected_item() and
  92. /// next_selected_item().<BR>
  93. /// Items can be found by their pathname using find_item(const char*),
  94. /// and an item's pathname can be found with item_pathname().<BR>
  95. /// The selected items' colors are controlled by selection_color()
  96. /// (inherited from Fl_Widget).<BR>
  97. /// A hook is provided to allow you to redefine how item's labels are drawn
  98. /// via Fl_Tree::item_draw_callback().<BR>
  99. ///
  100. /// \par SELECTION OF ITEMS
  101. /// The tree can have different selection behaviors controlled by selectmode().
  102. /// The background color used for selected items is the Fl_Tree::selection_color().
  103. /// The foreground color for selected items is controlled internally with fl_contrast().
  104. ///
  105. /// \par CHILD WIDGETS
  106. /// FLTK widgets (including custom widgets) can be assigned to tree items via
  107. /// Fl_Tree_Item::widget().
  108. /// \par
  109. /// When an Fl_Tree_Item::widget() is defined, the default behavior is for the
  110. /// widget() to be shown in place of the item's label (if it has one).
  111. /// Only the widget()'s width will be used; the widget()'s x() and y() position
  112. /// will be managed by the tree, and the h() will track the item's height.
  113. /// This default behavior can be altered (ABI 1.3.1):
  114. /// Setting Fl_Tree::item_draw_mode()'s FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET flag
  115. /// causes the label + widget to be displayed together in that order, and
  116. /// adding the FL_TREE_ITEM_HEIGHT_FROM_WIDGET flag causes widget's height
  117. /// to define the widget()'s height.
  118. ///
  119. /// \par ICONS
  120. /// The tree's open/close icons can be redefined with
  121. /// Fl_Tree::openicon(), Fl_Tree::closeicon(). User icons
  122. /// can either be changed globally with Fl_Tree::usericon(),
  123. /// or on a per-item basis with Fl_Tree_Item::usericon().
  124. /// \par
  125. /// Various default preferences can be globally manipulated via Fl_Tree_Prefs,
  126. /// including colors, margins, icons, connection lines, etc.
  127. ///
  128. /// \par FONTS AND COLORS
  129. /// When adding new items to the tree, the new items get the
  130. /// defaults for fonts and colors from:
  131. /// \par
  132. /// - Fl_Tree::item_labelfont() -- The default item label font (default: FL_HELVETICA)
  133. /// - Fl_Tree::item_labelsize() -- The default item label size (default: FL_NORMAL_SIZE)
  134. /// - Fl_Tree::item_labelfgcolor() -- The default item label foreground color (default: FL_FOREGROUND_COLOR)
  135. /// - Fl_Tree::item_labelbgcolor() -- The default item label background color (default: 0xffffffff, which tree uses as 'transparent')
  136. /// \par
  137. /// Each item (Fl_Tree_Item) inherits a copy of these font/color attributes when created,
  138. /// and each item has its own methods to let the app change these values on a per-item basis
  139. /// using methods of the same name:
  140. /// \par
  141. /// - Fl_Tree_Item::labelfont() -- The item's label font (default: FL_HELVETICA)
  142. /// - Fl_Tree_Item::labelsize() -- The item's label size (default: FL_NORMAL_SIZE)
  143. /// - Fl_Tree_Item::labelfgcolor() -- The item's label foreground color (default: FL_FOREGROUND_COLOR)
  144. /// - Fl_Tree_Item::labelbgcolor() -- The item's label background color (default: 0xffffffff, which uses the tree's own bg color)
  145. ///
  146. /// \par CALLBACKS
  147. /// The tree's callback() will be invoked when items change state or are open/closed.
  148. /// when() controls when mouse/keyboard events invoke the callback.
  149. /// callback_item() and callback_reason() can be used to determine the cause of the callback. e.g.
  150. /// \par
  151. /// \code
  152. /// void MyTreeCallback(Fl_Widget *w, void *data) {
  153. /// Fl_Tree *tree = (Fl_Tree*)w;
  154. /// Fl_Tree_Item *item = (Fl_Tree_Item*)tree->callback_item(); // get selected item
  155. /// switch ( tree->callback_reason() ) {
  156. /// case FL_TREE_REASON_SELECTED: [..]
  157. /// case FL_TREE_REASON_DESELECTED: [..]
  158. /// case FL_TREE_REASON_RESELECTED: [..]
  159. /// case FL_TREE_REASON_OPENED: [..]
  160. /// case FL_TREE_REASON_CLOSED: [..]
  161. /// }
  162. /// \endcode
  163. ///
  164. /// \par SIMPLE EXAMPLES
  165. /// To find all the selected items:
  166. /// \code
  167. /// for ( Fl_Tree_Item *i=first_selected_item(); i; i=next_selected_item(i) )
  168. /// printf("Item %s is selected\n", i->label());
  169. /// \endcode
  170. /// To get an item's full menu pathname, use Fl_Tree::item_pathname(), e.g.
  171. /// \code
  172. /// char pathname[256] = "???";
  173. /// tree->item_pathname(pathname, sizeof(pathname), item); // eg. "Parent/Child/Item"
  174. /// \endcode
  175. /// \par
  176. /// To walk all the items of the tree from top to bottom:
  177. /// \code
  178. /// // Walk all the items in the tree, and print their labels
  179. /// for ( Fl_Tree_Item *item = tree->first(); item; item = tree->next(item) ) {
  180. /// printf("Item: %s\n", item->label());
  181. /// }
  182. /// \endcode
  183. /// \par
  184. /// To recursively walk all the children of a particular item,
  185. /// define a function that uses recursion:
  186. /// \code
  187. /// // Find all of the item's children and print an indented report of their labels
  188. /// void my_print_all_children(Fl_Tree_Item *item, int indent=0) {
  189. /// for ( int t=0; t<item->children(); t++ ) {
  190. /// printf("%*s Item: %s\n", indent, "", item->child(t)->label());
  191. /// my_print_all_children(item->child(t), indent+4); // recurse
  192. /// }
  193. /// }
  194. /// \endcode
  195. /// \par
  196. /// To change the default label font and color when creating new items:
  197. /// \code
  198. /// tree = new Fl_Tree(..);
  199. /// tree->item_labelfont(FL_COURIER); // Use Courier font for all new items
  200. /// tree->item_labelfgcolor(FL_RED); // Use red color for labels of all new items
  201. /// [..]
  202. /// // Now create the items in the tree using the above defaults.
  203. /// tree->add("Aaa");
  204. /// tree->add("Bbb");
  205. /// [..]
  206. /// \endcode
  207. /// \par
  208. /// To change the font and color of all existing items in the tree:
  209. /// \code
  210. /// // Change the font and color of all items currently in the tree
  211. /// for ( Fl_Tree_Item *item = tree->first(); item; item = tree->next(item) ) {
  212. /// item->labelfont(FL_COURIER);
  213. /// item->labelcolor(FL_RED);
  214. /// }
  215. /// \endcode
  216. ///
  217. /// \par DISPLAY DESCRIPTION
  218. /// The following image shows the tree's various visual elements
  219. /// and the methods that control them:
  220. /// \par
  221. /// \image html tree-elements.png
  222. /// \image latex tree-elements.png "Fl_Tree elements" width=6cm
  223. /// \par
  224. /// The following shows the protected 'tree inner' (tix..)
  225. /// and 'tree outer' (tox..) dimension variables:
  226. /// \image html tree-dimensions.png "Fl_Tree inner/outer dimensions" width=6cm
  227. /// \image latex tree-dimensions.png "Fl_Tree inner/outer dimensions" width=6cm
  228. ///
  229. /// \par KEYBOARD BINDINGS
  230. /// The following table lists keyboard bindings for navigating the tree:
  231. ///
  232. /// <TABLE BORDER="1" SUMMARY="Fl_Tree keyboard bindings.">
  233. /// <CAPTION ALIGN=TOP>Fl_Tree keyboard bindings.</CAPTION>
  234. /// <TR>
  235. /// <TD WIDTH=25% ALIGN=CENTER><B>Keyboard</B></TD>
  236. /// <TD WIDTH=25% ALIGN=CENTER><B>FL_TREE_SELECT_MULTI</B></TD>
  237. /// <TD WIDTH=25% ALIGN=CENTER><B>FL_TREE_SELECT_SINGLE</B></TD>
  238. /// <TD WIDTH=25% ALIGN=CENTER><B>FL_TREE_SELECT_NONE</B></TD>
  239. ///
  240. /// </TR><TR>
  241. /// <TD ALIGN=CENTER><B>Ctrl-A</B> (Linux/Windows)<BR><B>Command-A</B> (Mac)</TD>
  242. /// <TD ALIGN=CENTER>Select all items.</TD>
  243. /// <TD ALIGN=CENTER>N/A</TD>
  244. /// <TD ALIGN=CENTER>N/A</TD>
  245. ///
  246. /// </TR><TR>
  247. /// <TD ALIGN=CENTER><B>Space </B></TD>
  248. /// <TD ALIGN=CENTER>Selects item.</TD>
  249. /// <TD ALIGN=CENTER>Selects item.</TD>
  250. /// <TD ALIGN=CENTER>N/A</TD>
  251. ///
  252. /// </TR><TR>
  253. /// <TD ALIGN=CENTER><B>Ctrl-Space </B></TD>
  254. /// <TD ALIGN=CENTER>Toggle item.</TD>
  255. /// <TD ALIGN=CENTER>Toggle item.</TD>
  256. /// <TD ALIGN=CENTER>N/A</TD>
  257. ///
  258. /// </TR><TR>
  259. /// <TD ALIGN=CENTER><B>Shift-Space </B></TD>
  260. /// <TD ALIGN=CENTER>Extends selection<BR>from last item.</TD>
  261. /// <TD ALIGN=CENTER>Selects item.</TD>
  262. /// <TD ALIGN=CENTER>N/A</TD>
  263. ///
  264. /// </TR><TR>
  265. /// <TD ALIGN=CENTER><B>Enter,<BR>Ctrl-Enter,<BR>Shift-Enter </B></TD>
  266. /// <TD ALIGN=CENTER>Toggles open/close</TD>
  267. /// <TD ALIGN=CENTER>Toggles open/close</TD>
  268. /// <TD ALIGN=CENTER>Toggles open/close</TD>
  269. ///
  270. /// </TR><TR>
  271. /// <TD ALIGN=CENTER><B>Right / Left</B></TD>
  272. /// <TD ALIGN=CENTER>Open/Close item.</TD>
  273. /// <TD ALIGN=CENTER>Open/Close item.</TD>
  274. /// <TD ALIGN=CENTER>Open/Close item.</TD>
  275. ///
  276. /// </TR><TR>
  277. /// <TD ALIGN=CENTER><B>Up / Down</B></TD>
  278. /// <TD ALIGN=CENTER>Move focus box up/down.</TD>
  279. /// <TD ALIGN=CENTER>Move focus box up/down.</TD>
  280. /// <TD ALIGN=CENTER>N/A</TD>
  281. ///
  282. /// </TR><TR>
  283. /// <TD ALIGN=CENTER><B>Shift-Up / Shift-Down</B></TD>
  284. /// <TD ALIGN=CENTER>Extend selection up/down.</TD>
  285. /// <TD ALIGN=CENTER>Move focus up/down.</TD>
  286. /// <TD ALIGN=CENTER>N/A</TD>
  287. ///
  288. /// </TR><TR>
  289. /// <TD ALIGN=CENTER><B>Home / End</B></TD>
  290. /// <TD ALIGN=CENTER>Move to top/bottom of tree.</TD>
  291. /// <TD ALIGN=CENTER>Move to top/bottom of tree.</TD>
  292. /// <TD ALIGN=CENTER>Move to top/bottom of tree.</TD>
  293. ///
  294. /// </TR><TR>
  295. /// <TD ALIGN=CENTER><B>PageUp / PageDown</B></TD>
  296. /// <TD ALIGN=CENTER>Page up/down.</TD>
  297. /// <TD ALIGN=CENTER>Page up/down.</TD>
  298. /// <TD ALIGN=CENTER>Page up/down.</TD>
  299. ///
  300. /// </TD></TR></TABLE>
  301. ///
  302. /// \enum Fl_Tree_Reason
  303. /// The reason the callback was invoked.
  304. ///
  305. enum Fl_Tree_Reason {
  306. FL_TREE_REASON_NONE=0, ///< unknown reason
  307. FL_TREE_REASON_SELECTED, ///< an item was selected
  308. FL_TREE_REASON_DESELECTED, ///< an item was de-selected
  309. #if FLTK_ABI_VERSION >= 10301
  310. FL_TREE_REASON_RESELECTED, ///< an item was re-selected (e.g. double-clicked)
  311. #endif /*FLTK_ABI_VERSION*/
  312. FL_TREE_REASON_OPENED, ///< an item was opened
  313. FL_TREE_REASON_CLOSED ///< an item was closed
  314. };
  315. class FL_EXPORT Fl_Tree : public Fl_Group {
  316. protected:
  317. friend class Fl_Tree_Item;
  318. Fl_Tree_Item *_root; // can be null!
  319. Fl_Tree_Item *_item_focus; // item that has focus box
  320. int _select_focus; //select item instead of only draw focus
  321. Fl_Tree_Item *_callback_item; // item invoked during callback (can be NULL)
  322. Fl_Tree_Reason _callback_reason; // reason for the callback
  323. Fl_Tree_Prefs _prefs; // all the tree's settings
  324. int _scrollbar_size; // size of scrollbar trough
  325. #if FLTK_ABI_VERSION >= 10301
  326. // NEW:
  327. Fl_Tree_Item *_lastselect;
  328. #else /*FLTK_ABI_VERSION*/
  329. // OLD: static data inside handle() method
  330. #endif /*FLTK_ABI_VERSION*/
  331. void fix_scrollbar_order();
  332. protected:
  333. Fl_Scrollbar *_vscroll; ///< Vertical scrollbar
  334. #if FLTK_ABI_VERSION >= 10303
  335. Fl_Scrollbar *_hscroll; ///< Horizontal scrollbar
  336. int _tox,_toy,_tow,_toh; ///< Tree widget outer xywh dimension: outside scrollbars, inside widget border
  337. int _tix,_tiy,_tiw,_tih; ///< Tree widget inner xywh dimension: inside borders + scrollbars
  338. /// the calculated width of the entire tree hierarchy. See calc_tree()
  339. int _tree_w;
  340. /// the calculated height of the entire tree hierarchy. See calc_tree()
  341. int _tree_h;
  342. #endif
  343. void item_clicked(Fl_Tree_Item* val);
  344. void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
  345. #if FLTK_ABI_VERSION >= 10303
  346. // next_visible_item() and extend_selection() moved to 'public' in ABI 1.3.3
  347. // undocmented draw_tree() dropped -- draw() does all the work now
  348. #else
  349. Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);
  350. void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to);
  351. int draw_tree();
  352. #endif
  353. void set_root(Fl_Tree_Item *item);
  354. public:
  355. Fl_Tree(int X, int Y, int W, int H, const char *L=0);
  356. ~Fl_Tree();
  357. int handle(int e);
  358. void draw();
  359. void show_self();
  360. void resize(int,int,int,int);
  361. ///////////////////////
  362. // root methods
  363. ///////////////////////
  364. void root_label(const char *new_label);
  365. Fl_Tree_Item* root();
  366. void root(Fl_Tree_Item *newitem);
  367. const Fl_Tree_Prefs& prefs() const { return _prefs; }
  368. ////////////////////////////////
  369. // Item creation/removal methods
  370. ////////////////////////////////
  371. virtual Fl_Tree_Item *new_fl_tree_item(const Fl_Tree_Prefs &prefs);
  372. #if FLTK_ABI_VERSION >= 10303
  373. Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem=0);
  374. #else
  375. Fl_Tree_Item *add(const char *path);
  376. Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem);
  377. #endif
  378. Fl_Tree_Item* add(Fl_Tree_Item *parent_item, const char *name);
  379. Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
  380. Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
  381. int remove(Fl_Tree_Item *item);
  382. void clear();
  383. void clear_children(Fl_Tree_Item *item);
  384. ////////////////////////
  385. // Item lookup methods
  386. ////////////////////////
  387. Fl_Tree_Item *find_item(const char *path);
  388. const Fl_Tree_Item *find_item(const char *path) const;
  389. int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
  390. #if FLTK_ABI_VERSION >= 10303
  391. const Fl_Tree_Item* find_clicked(int yonly=0) const;
  392. Fl_Tree_Item* find_clicked(int yonly=0);
  393. #else
  394. const Fl_Tree_Item *find_clicked() const;
  395. Fl_Tree_Item *find_clicked();
  396. #endif
  397. Fl_Tree_Item *item_clicked();
  398. /// Return the parent for specified \p item.
  399. ///
  400. /// \returns item's parent, or 0 if none (root).
  401. ///
  402. Fl_Tree_Item *parent(Fl_Tree_Item *item) {
  403. return(item->parent());
  404. }
  405. Fl_Tree_Item *item_focus() {
  406. return(_item_focus);
  407. }
  408. Fl_Tree_Item *first();
  409. Fl_Tree_Item *first_visible(); // deprecated in ABI 10303
  410. Fl_Tree_Item *first_visible_item();
  411. Fl_Tree_Item *next(Fl_Tree_Item *item=0);
  412. Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
  413. Fl_Tree_Item *last();
  414. Fl_Tree_Item *last_visible(); // deprecated in ABI 10303
  415. Fl_Tree_Item *last_visible_item();
  416. #if FLTK_ABI_VERSION >= 10303
  417. Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir); // made public in 1.3.3 ABI
  418. #endif
  419. Fl_Tree_Item *first_selected_item();
  420. Fl_Tree_Item *last_selected_item();
  421. Fl_Tree_Item *next_item(Fl_Tree_Item *item, int dir=FL_Down, bool visible=false);
  422. #if FLTK_ABI_VERSION >= 10303
  423. Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0, int dir=FL_Down);
  424. int get_selected_items(Fl_Tree_Item_Array &items);
  425. #else
  426. Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0);
  427. Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item, int dir);
  428. #endif
  429. //////////////////////////
  430. // Item open/close methods
  431. //////////////////////////
  432. int open(Fl_Tree_Item *item, int docallback=1);
  433. int open(const char *path, int docallback=1);
  434. void open_toggle(Fl_Tree_Item *item, int docallback=1);
  435. int close(Fl_Tree_Item *item, int docallback=1);
  436. int close(const char *path, int docallback=1);
  437. int is_open(Fl_Tree_Item *item) const;
  438. int is_open(const char *path) const;
  439. int is_close(Fl_Tree_Item *item) const;
  440. int is_close(const char *path) const;
  441. /////////////////////////
  442. // Item selection methods
  443. /////////////////////////
  444. int select(Fl_Tree_Item *item, int docallback=1);
  445. int select(const char *path, int docallback=1);
  446. void select_toggle(Fl_Tree_Item *item, int docallback=1);
  447. int deselect(Fl_Tree_Item *item, int docallback=1);
  448. int deselect(const char *path, int docallback=1);
  449. int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
  450. int select_only(Fl_Tree_Item *selitem, int docallback=1);
  451. int select_all(Fl_Tree_Item *item=0, int docallback=1);
  452. int extend_selection_dir(Fl_Tree_Item *from,
  453. Fl_Tree_Item *to,
  454. int dir,
  455. int val,
  456. bool visible);
  457. #if FLTK_ABI_VERSION >= 10303
  458. int extend_selection(Fl_Tree_Item *from,
  459. Fl_Tree_Item *to,
  460. int val=1,
  461. bool visible=false);
  462. #else
  463. private:
  464. // Adding overload if not at least one overload breaks ABI, so avoid
  465. // by keeping private until we can break ABI. ref: http://www.ros.org/reps/rep-0009.html
  466. int extend_selection__(Fl_Tree_Item *from,
  467. Fl_Tree_Item *to,
  468. int val,
  469. bool visible);
  470. public:
  471. #endif
  472. void set_item_focus(Fl_Tree_Item *item);
  473. Fl_Tree_Item *get_item_focus() const;
  474. int is_selected(Fl_Tree_Item *item) const;
  475. int is_selected(const char *path);
  476. /////////////////////////////////
  477. // Item attribute related methods
  478. /////////////////////////////////
  479. Fl_Font item_labelfont() const;
  480. void item_labelfont(Fl_Font val);
  481. Fl_Fontsize item_labelsize() const;
  482. void item_labelsize(Fl_Fontsize val);
  483. Fl_Color item_labelfgcolor(void) const;
  484. void item_labelfgcolor(Fl_Color val);
  485. Fl_Color item_labelbgcolor(void) const;
  486. void item_labelbgcolor(Fl_Color val);
  487. Fl_Color connectorcolor() const;
  488. void connectorcolor(Fl_Color val);
  489. int marginleft() const;
  490. void marginleft(int val);
  491. int margintop() const;
  492. void margintop(int val);
  493. #if FLTK_ABI_VERSION >= 10301
  494. int marginbottom() const;
  495. void marginbottom(int val);
  496. #endif /*FLTK_ABI_VERSION*/
  497. int linespacing() const;
  498. void linespacing(int val);
  499. int openchild_marginbottom() const;
  500. void openchild_marginbottom(int val);
  501. int usericonmarginleft() const;
  502. void usericonmarginleft(int val);
  503. int labelmarginleft() const;
  504. void labelmarginleft(int val);
  505. #if FLTK_ABI_VERSION >= 10301
  506. int widgetmarginleft() const;
  507. void widgetmarginleft(int val);
  508. #endif /*FLTK_ABI_VERSION*/
  509. int connectorwidth() const;
  510. void connectorwidth(int val);
  511. Fl_Image* usericon() const;
  512. void usericon(Fl_Image *val);
  513. Fl_Image* openicon() const;
  514. void openicon(Fl_Image *val);
  515. Fl_Image* closeicon() const;
  516. void closeicon(Fl_Image *val);
  517. int showcollapse() const;
  518. void showcollapse(int val);
  519. int showroot() const;
  520. void showroot(int val);
  521. Fl_Tree_Connector connectorstyle() const;
  522. void connectorstyle(Fl_Tree_Connector val);
  523. Fl_Tree_Sort sortorder() const;
  524. void sortorder(Fl_Tree_Sort val);
  525. Fl_Boxtype selectbox() const;
  526. void selectbox(Fl_Boxtype val);
  527. Fl_Tree_Select selectmode() const;
  528. void selectmode(Fl_Tree_Select val);
  529. #if FLTK_ABI_VERSION >= 10301
  530. Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
  531. void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
  532. Fl_Tree_Item_Draw_Mode item_draw_mode() const;
  533. void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
  534. void item_draw_mode(int mode);
  535. #endif
  536. #if FLTK_ABI_VERSION >= 10303
  537. void calc_dimensions();
  538. void calc_tree();
  539. #endif
  540. void recalc_tree();
  541. int displayed(Fl_Tree_Item *item);
  542. void show_item(Fl_Tree_Item *item, int yoff);
  543. void show_item(Fl_Tree_Item *item);
  544. void show_item_top(Fl_Tree_Item *item);
  545. void show_item_middle(Fl_Tree_Item *item);
  546. void show_item_bottom(Fl_Tree_Item *item);
  547. void select_focus(int b) {_select_focus=b;};
  548. int select_focus() {return _select_focus;};
  549. void display(Fl_Tree_Item *item);
  550. int vposition() const;
  551. void vposition(int pos);
  552. int hposition() const;
  553. void hposition(int pos);
  554. int is_scrollbar(Fl_Widget *w);
  555. int scrollbar_size() const;
  556. void scrollbar_size(int size);
  557. int is_vscroll_visible() const;
  558. int is_hscroll_visible() const;
  559. ///////////////////////
  560. // callback related
  561. ///////////////////////
  562. void callback_item(Fl_Tree_Item* item);
  563. Fl_Tree_Item* callback_item();
  564. void callback_reason(Fl_Tree_Reason reason);
  565. Fl_Tree_Reason callback_reason() const;
  566. /// Load FLTK preferences
  567. void load(class Fl_Preferences&);
  568. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Tree, Fl_Group)
  569. };
  570. #endif /*FL_TREE_H*/
  571. //
  572. // End of "$Id: Fl_Tree.H 10081 2014-01-24 19:03:15Z greg.ercolano $".
  573. //