Fl_Tree_Prefs.H 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. //
  2. // "$Id: Fl_Tree_Prefs.H 11679 2016-04-23 04:30:39Z manolo $"
  3. //
  4. #ifndef FL_TREE_PREFS_H
  5. #define FL_TREE_PREFS_H
  6. #include <FL/Fl.H> // needed for ABI version features (via Enumerations.H)
  7. //////////////////////
  8. // FL/Fl_Tree_Prefs.H
  9. //////////////////////
  10. //
  11. // Fl_Tree_Prefs -- This file is part of the Fl_Tree widget for FLTK
  12. // Copyright (C) 2009-2010 by Greg Ercolano.
  13. //
  14. // This library is free software. Distribution and use rights are outlined in
  15. // the file "COPYING" which should have been included with this file. If this
  16. // file is missing or damaged, see the license at:
  17. //
  18. // http://www.fltk.org/COPYING.php
  19. //
  20. // Please report all bugs and problems on the following page:
  21. //
  22. // http://www.fltk.org/str.php
  23. //
  24. ///
  25. /// \file
  26. /// \brief This file contains the definitions for Fl_Tree's preferences.
  27. ///
  28. /// \code
  29. /// Fl_Tree_Prefs
  30. /// :
  31. /// .....:.......
  32. /// : :
  33. /// Fl_Tree :
  34. /// |_____ Fl_Tree_Item
  35. ///
  36. /// \endcode
  37. ///
  38. /// \class Fl_Tree_Prefs
  39. /// \brief Tree widget's preferences.
  40. /// \enum Fl_Tree_Sort
  41. /// Sort order options for items added to the tree
  42. ///
  43. enum Fl_Tree_Sort {
  44. FL_TREE_SORT_NONE=0, ///< No sorting; items are added in the order defined (default).
  45. FL_TREE_SORT_ASCENDING=1, ///< Add items in ascending sort order.
  46. FL_TREE_SORT_DESCENDING=2 ///< Add items in descending sort order.
  47. };
  48. /// \enum Fl_Tree_Connector
  49. /// Defines the style of connection lines between items.
  50. ///
  51. enum Fl_Tree_Connector {
  52. FL_TREE_CONNECTOR_NONE=0, ///< Use no lines connecting items
  53. FL_TREE_CONNECTOR_DOTTED=1, ///< Use dotted lines connecting items (default)
  54. FL_TREE_CONNECTOR_SOLID=2 ///< Use solid lines connecting items
  55. };
  56. /// \enum Fl_Tree_Select
  57. /// Tree selection style.
  58. ///
  59. enum Fl_Tree_Select {
  60. FL_TREE_SELECT_NONE=0, ///< Nothing selected when items are clicked
  61. FL_TREE_SELECT_SINGLE=1, ///< Single item selected when item is clicked (default)
  62. FL_TREE_SELECT_MULTI=2, ///< Multiple items can be selected by clicking
  63. ///< with SHIFT, CTRL or mouse drags.
  64. FL_TREE_SELECT_SINGLE_DRAGGABLE=3 ///< Single items may be selected, and they may be
  65. ///< reordered by mouse drag.
  66. };
  67. /// \enum Fl_Tree_Item_Reselect_Mode
  68. /// Defines the ways an item can be (re) selected
  69. /// via item_reselect_mode().
  70. ///
  71. enum Fl_Tree_Item_Reselect_Mode {
  72. FL_TREE_SELECTABLE_ONCE=0, ///< Item can only be selected once (default)
  73. FL_TREE_SELECTABLE_ALWAYS, ///< Enables FL_TREE_REASON_RESELECTED events for callbacks
  74. };
  75. /// \enum Fl_Tree_Item_Draw_Mode
  76. /// Bit flags that control how item's labels and widget()s are drawn in the tree
  77. /// via item_draw_mode().
  78. ///
  79. enum Fl_Tree_Item_Draw_Mode {
  80. FL_TREE_ITEM_DRAW_DEFAULT=0, ///< If widget() defined, draw in place of label,
  81. ///< and widget() tracks item height (default)
  82. FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET=1, ///< If widget() defined, include label to the left of the widget
  83. FL_TREE_ITEM_HEIGHT_FROM_WIDGET=2 ///< If widget() defined, widget()'s height controls item's height
  84. };
  85. class Fl_Tree_Item;
  86. typedef void (Fl_Tree_Item_Draw_Callback)(Fl_Tree_Item*, void*);
  87. /// \class Fl_Tree_Prefs
  88. ///
  89. /// \brief Fl_Tree's Preferences class.
  90. ///
  91. /// This class manages the Fl_Tree's defaults.
  92. /// You should probably be using the methods in Fl_Tree
  93. /// instead of trying to accessing tree's preferences settings directly.
  94. ///
  95. class FL_EXPORT Fl_Tree_Prefs {
  96. Fl_Font _labelfont; // label's font face
  97. Fl_Fontsize _labelsize; // label's font size
  98. int _margintop; // --
  99. int _marginleft; // |- tree's controllable margins
  100. int _marginbottom; // --
  101. int _openchild_marginbottom; // extra space below an open child tree
  102. int _usericonmarginleft; // space to left of user icon (if any)
  103. int _labelmarginleft; // space to left of label
  104. int _widgetmarginleft; // space to left of widget
  105. int _connectorwidth; // connector width (right of open/close icon)
  106. int _linespacing; // vertical space between lines
  107. // Colors
  108. Fl_Color _labelfgcolor; // label's foreground color
  109. Fl_Color _labelbgcolor; // label's background color
  110. Fl_Color _connectorcolor; // connector dotted line color
  111. Fl_Tree_Connector _connectorstyle; // connector line style
  112. Fl_Image *_openimage; // the 'open' icon [+]
  113. Fl_Image *_closeimage; // the 'close' icon [-]
  114. Fl_Image *_userimage; // user's own icon
  115. Fl_Image *_opendeimage; // deactivated 'open' icon
  116. Fl_Image *_closedeimage; // deactivated 'close' icon
  117. Fl_Image *_userdeimage; // deactivated user icon
  118. char _showcollapse; // 1=show collapse icons, 0=don't
  119. char _showroot; // show the root item as part of the tree
  120. Fl_Tree_Sort _sortorder; // none, ascening, descending, etc.
  121. Fl_Boxtype _selectbox; // selection box type
  122. Fl_Tree_Select _selectmode; // selection mode
  123. Fl_Tree_Item_Reselect_Mode _itemreselectmode; // controls item selection callback() behavior
  124. Fl_Tree_Item_Draw_Mode _itemdrawmode; // controls how items draw label + widget()
  125. Fl_Tree_Item_Draw_Callback *_itemdrawcallback; // callback to handle drawing items (0=none)
  126. void *_itemdrawuserdata; // data for drawing items (0=none)
  127. public:
  128. Fl_Tree_Prefs();
  129. ~Fl_Tree_Prefs();
  130. ////////////////////////////
  131. // Labels
  132. ////////////////////////////
  133. /// Return the label's font.
  134. inline Fl_Font item_labelfont() const { return(_labelfont); }
  135. /// Set the label's font to \p val.
  136. inline void item_labelfont(Fl_Font val) { _labelfont = val; }
  137. /// Return the label's size in pixels.
  138. inline Fl_Fontsize item_labelsize() const { return(_labelsize); }
  139. /// Set the label's size in pixels to \p val.
  140. inline void item_labelsize(Fl_Fontsize val) { _labelsize = val; }
  141. /// Get the default label foreground color
  142. inline Fl_Color item_labelfgcolor() const { return(_labelfgcolor); }
  143. /// Set the default label foreground color
  144. inline void item_labelfgcolor(Fl_Color val) { _labelfgcolor = val; }
  145. /// Get the default label background color.
  146. /// This returns the Fl_Tree::color() unless item_labelbgcolor()
  147. /// has been set explicitly.
  148. ///
  149. inline Fl_Color item_labelbgcolor() const {
  150. return _labelbgcolor;
  151. }
  152. /// Set the default label background color.
  153. /// Once set, overrides the default behavior of using Fl_Tree::color().
  154. ///
  155. inline void item_labelbgcolor(Fl_Color val) {
  156. _labelbgcolor = val;
  157. }
  158. /////////////////
  159. // Obsolete names - for 1.3.0 backwards compat
  160. /////////////////
  161. /// Obsolete: Return the label's font. Please use item_labelfont() instead.
  162. inline Fl_Font labelfont() const { return(_labelfont); }
  163. /// Obsolete: Set the label's font to \p val. Please use item_labelfont(Fl_Font) instead.
  164. inline void labelfont(Fl_Font val) { _labelfont = val; }
  165. /// Obsolete: Return the label's size in pixels. Please use item_labelsize() instead.
  166. inline Fl_Fontsize labelsize() const { return(_labelsize); }
  167. /// Obsolete: Set the label's size in pixels to \p val. Please use item_labelsize(Fl_Fontsize) instead.
  168. inline void labelsize(Fl_Fontsize val) { _labelsize = val; }
  169. /// Obsolete: Get the default label foreground color. Please use item_labelfgcolor() instead.
  170. inline Fl_Color labelfgcolor() const { return(_labelfgcolor); }
  171. /// Obsolete: Set the default label foreground color. Please use item_labelfgcolor(Fl_Color) instead.
  172. inline void labelfgcolor(Fl_Color val) { _labelfgcolor = val; }
  173. /// Obsolete: Get the default label background color. Please use item_labelbgcolor() instead.
  174. inline Fl_Color labelbgcolor() const { return(item_labelbgcolor()); }
  175. /// Obsolete: Set the default label background color. Please use item_labelbgcolor(Fl_Color) instead.
  176. inline void labelbgcolor(Fl_Color val) { item_labelbgcolor(val); }
  177. ////////////////////////////
  178. // Margins
  179. ////////////////////////////
  180. /// Get the left margin's value in pixels
  181. inline int marginleft() const {
  182. return(_marginleft);
  183. }
  184. /// Set the left margin's value in pixels
  185. inline void marginleft(int val) {
  186. _marginleft = val;
  187. }
  188. /// Get the top margin's value in pixels
  189. inline int margintop() const {
  190. return(_margintop);
  191. }
  192. /// Set the top margin's value in pixels
  193. inline void margintop(int val) {
  194. _margintop = val;
  195. }
  196. /// Get the bottom margin's value in pixels.
  197. /// This is the extra distance the vertical scroller lets you travel.
  198. inline int marginbottom() const {
  199. return(_marginbottom);
  200. }
  201. /// Set the bottom margin's value in pixels
  202. /// This is the extra distance the vertical scroller lets you travel.
  203. inline void marginbottom(int val) {
  204. _marginbottom = val;
  205. }
  206. /// Get the margin below an open child in pixels
  207. inline int openchild_marginbottom() const {
  208. return(_openchild_marginbottom);
  209. }
  210. /// Set the margin below an open child in pixels
  211. inline void openchild_marginbottom(int val) {
  212. _openchild_marginbottom = val;
  213. }
  214. /// Get the user icon's left margin value in pixels
  215. inline int usericonmarginleft() const {
  216. return(_usericonmarginleft);
  217. }
  218. /// Set the user icon's left margin value in pixels
  219. inline void usericonmarginleft(int val) {
  220. _usericonmarginleft = val;
  221. }
  222. /// Get the label's left margin value in pixels
  223. inline int labelmarginleft() const {
  224. return(_labelmarginleft);
  225. }
  226. /// Set the label's left margin value in pixels
  227. inline void labelmarginleft(int val) {
  228. _labelmarginleft = val;
  229. }
  230. /// Get the widget()'s left margin value in pixels
  231. inline int widgetmarginleft() const {
  232. return(_widgetmarginleft);
  233. }
  234. /// Set the widget's left margin value in pixels
  235. inline void widgetmarginleft(int val) {
  236. _widgetmarginleft = val;
  237. }
  238. /// Get the line spacing value in pixels
  239. inline int linespacing() const {
  240. return(_linespacing);
  241. }
  242. /// Set the line spacing value in pixels
  243. inline void linespacing(int val) {
  244. _linespacing = val;
  245. }
  246. ////////////////////////////
  247. // Colors and Styles
  248. ////////////////////////////
  249. /// Get the connector color used for tree connection lines.
  250. inline Fl_Color connectorcolor() const {
  251. return(_connectorcolor);
  252. }
  253. /// Set the connector color used for tree connection lines.
  254. inline void connectorcolor(Fl_Color val) {
  255. _connectorcolor = val;
  256. }
  257. /// Get the connector style.
  258. inline Fl_Tree_Connector connectorstyle() const {
  259. return(_connectorstyle);
  260. }
  261. /// Set the connector style.
  262. inline void connectorstyle(Fl_Tree_Connector val) {
  263. _connectorstyle = val;
  264. }
  265. /// Set the connector style [integer].
  266. inline void connectorstyle(int val) {
  267. _connectorstyle = Fl_Tree_Connector(val);
  268. }
  269. /// Get the tree connection line's width.
  270. inline int connectorwidth() const {
  271. return(_connectorwidth);
  272. }
  273. /// Set the tree connection line's width.
  274. inline void connectorwidth(int val) {
  275. _connectorwidth = val;
  276. }
  277. ////////////////////////////
  278. // Icons
  279. ////////////////////////////
  280. /// Get the current default 'open' icon.
  281. /// Returns the Fl_Image* of the icon, or 0 if none.
  282. ///
  283. inline Fl_Image *openicon() const {
  284. return(_openimage);
  285. }
  286. void openicon(Fl_Image *val);
  287. /// Gets the default 'close' icon
  288. /// Returns the Fl_Image* of the icon, or 0 if none.
  289. ///
  290. inline Fl_Image *closeicon() const {
  291. return(_closeimage);
  292. }
  293. void closeicon(Fl_Image *val);
  294. /// Gets the default 'user icon' (default is 0)
  295. inline Fl_Image *usericon() const {
  296. return(_userimage);
  297. }
  298. /// Sets the default 'user icon'
  299. /// Returns the Fl_Image* of the icon, or 0 if none (default).
  300. ///
  301. inline void usericon(Fl_Image *val) {
  302. _userimage = val;
  303. // Update deactivated version of icon..
  304. if ( _userdeimage ) delete _userdeimage;
  305. if ( _userimage ) {
  306. _userdeimage = _userimage->copy();
  307. _userdeimage->inactive();
  308. } else {
  309. _userdeimage = 0;
  310. }
  311. }
  312. /// Return the deactivated version of the open icon, if any.
  313. /// Returns 0 if none.
  314. inline Fl_Image *opendeicon() const {
  315. return _opendeimage;
  316. }
  317. /// Return the deactivated version of the close icon, if any.
  318. /// Returns 0 if none.
  319. inline Fl_Image *closedeicon() const {
  320. return _closedeimage;
  321. }
  322. /// Return the deactivated version of the user icon, if any.
  323. /// Returns 0 if none.
  324. inline Fl_Image *userdeicon() const {
  325. return _userdeimage;
  326. }
  327. ////////////////////////////
  328. // Options
  329. ////////////////////////////
  330. /// Returns 1 if the collapse icon is enabled, 0 if not.
  331. inline char showcollapse() const {
  332. return(_showcollapse);
  333. }
  334. /// Set if we should show the collapse icon or not.
  335. /// If collapse icons are disabled, the user will not be able
  336. /// to interactively collapse items in the tree, unless the application
  337. /// provides some other means via open() and close().
  338. ///
  339. /// \param[in] val 1: shows collapse icons (default),\n
  340. /// 0: hides collapse icons.
  341. ///
  342. inline void showcollapse(int val) {
  343. _showcollapse = val;
  344. }
  345. /// Get the default sort order value
  346. inline Fl_Tree_Sort sortorder() const {
  347. return(_sortorder);
  348. }
  349. /// Set the default sort order value.
  350. /// Defines the order new items appear when add()ed to the tree.
  351. /// See Fl_Tree_Sort for possible values.
  352. ///
  353. inline void sortorder(Fl_Tree_Sort val) {
  354. _sortorder = val;
  355. }
  356. /// Get the default selection box's box drawing style as an Fl_Boxtype.
  357. inline Fl_Boxtype selectbox() const {
  358. return(_selectbox);
  359. }
  360. /// Set the default selection box's box drawing style to \p val.
  361. inline void selectbox(Fl_Boxtype val) {
  362. _selectbox = val;
  363. }
  364. /// Returns 1 if the root item is to be shown, or 0 if not.
  365. inline int showroot() const {
  366. return(int(_showroot));
  367. }
  368. /// Set if the root item should be shown or not.
  369. /// \param[in] val 1 -- show the root item (default)\n
  370. /// 0 -- hide the root item.
  371. ///
  372. inline void showroot(int val) {
  373. _showroot = char(val);
  374. }
  375. /// Get the selection mode used for the tree
  376. inline Fl_Tree_Select selectmode() const {
  377. return(_selectmode);
  378. }
  379. /// Set the selection mode used for the tree to \p val.
  380. /// This affects how items in the tree are selected
  381. /// when clicked on and dragged over by the mouse.
  382. /// See Fl_Tree_Select for possible values.
  383. ///
  384. inline void selectmode(Fl_Tree_Select val) {
  385. _selectmode = val;
  386. }
  387. /// Returns the current item re/selection mode
  388. Fl_Tree_Item_Reselect_Mode item_reselect_mode() const {
  389. return _itemreselectmode;
  390. }
  391. /// Sets the item re/selection mode
  392. void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
  393. _itemreselectmode = mode;
  394. }
  395. /// Get the 'item draw mode' used for the tree
  396. inline Fl_Tree_Item_Draw_Mode item_draw_mode() const {
  397. return(_itemdrawmode);
  398. }
  399. /// Set the 'item draw mode' used for the tree to \p val.
  400. /// This affects how items in the tree are drawn,
  401. /// such as when a widget() is defined.
  402. /// See Fl_Tree_Item_Draw_Mode for possible values.
  403. ///
  404. inline void item_draw_mode(Fl_Tree_Item_Draw_Mode val) {
  405. _itemdrawmode = val;
  406. }
  407. void item_draw_callback(Fl_Tree_Item_Draw_Callback *cb, void *data=0) {
  408. _itemdrawcallback = cb;
  409. _itemdrawuserdata = data;
  410. }
  411. Fl_Tree_Item_Draw_Callback* item_draw_callback() const {
  412. return(_itemdrawcallback);
  413. }
  414. void* item_draw_user_data() const {
  415. return(_itemdrawuserdata);
  416. }
  417. void do_item_draw_callback(Fl_Tree_Item *o) const {
  418. _itemdrawcallback(o, _itemdrawuserdata);
  419. }
  420. };
  421. #endif /*FL_TREE_PREFS_H*/
  422. //
  423. // End of "$Id: Fl_Tree_Prefs.H 11679 2016-04-23 04:30:39Z manolo $".
  424. //