Fl_Tree_Prefs.H 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. //
  2. // "$Id: Fl_Tree_Prefs.H 10034 2013-12-15 18:59:02Z greg.ercolano $"
  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. };
  65. #if FLTK_ABI_VERSION >= 10301
  66. /// \enum Fl_Tree_Item_Reselect_Mode
  67. /// Defines the ways an item can be (re) selected
  68. /// via item_reselect_mode().
  69. ///
  70. enum Fl_Tree_Item_Reselect_Mode {
  71. FL_TREE_SELECTABLE_ONCE=0, ///< Item can only be selected once (default)
  72. FL_TREE_SELECTABLE_ALWAYS, ///< Enables FL_TREE_REASON_RESELECTED events for callbacks
  73. };
  74. /// \enum Fl_Tree_Item_Draw_Mode
  75. /// Bit flags that control how item's labels and widget()s are drawn in the tree
  76. /// via item_draw_mode().
  77. ///
  78. enum Fl_Tree_Item_Draw_Mode {
  79. FL_TREE_ITEM_DRAW_DEFAULT=0, ///< If widget() defined, draw in place of label,
  80. ///< and widget() tracks item height (default)
  81. FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET=1, ///< If widget() defined, include label to the left of the widget
  82. FL_TREE_ITEM_HEIGHT_FROM_WIDGET=2 ///< If widget() defined, widget()'s height controls item's height
  83. };
  84. #endif /*FLTK_ABI_VERSION*/
  85. #if FLTK_ABI_VERSION >= 10303
  86. class Fl_Tree_Item;
  87. typedef void (Fl_Tree_Item_Draw_Callback)(Fl_Tree_Item*, void*);
  88. #endif
  89. /// \class Fl_Tree_Prefs
  90. ///
  91. /// \brief Fl_Tree's Preferences class.
  92. ///
  93. /// This class manages the Fl_Tree's defaults.
  94. /// You should probably be using the methods in Fl_Tree
  95. /// instead of trying to accessing tree's preferences settings directly.
  96. ///
  97. class FL_EXPORT Fl_Tree_Prefs {
  98. Fl_Font _labelfont; // label's font face
  99. Fl_Fontsize _labelsize; // label's font size
  100. int _margintop; // --
  101. int _marginleft; // |- tree's controllable margins
  102. #if FLTK_ABI_VERSION >= 10301
  103. int _marginbottom; // --
  104. #endif
  105. int _openchild_marginbottom; // extra space below an open child tree
  106. int _usericonmarginleft; // space to left of user icon (if any)
  107. int _labelmarginleft; // space to left of label
  108. #if FLTK_ABI_VERSION >= 10301
  109. int _widgetmarginleft; // space to left of widget
  110. #endif
  111. int _connectorwidth; // connector width (right of open/close icon)
  112. int _linespacing; // vertical space between lines
  113. // Colors
  114. Fl_Color _labelfgcolor; // label's foreground color
  115. Fl_Color _labelbgcolor; // label's background color
  116. Fl_Color _connectorcolor; // connector dotted line color
  117. Fl_Tree_Connector _connectorstyle; // connector line style
  118. Fl_Image *_openimage; // the 'open' icon [+]
  119. Fl_Image *_closeimage; // the 'close' icon [-]
  120. Fl_Image *_userimage; // user's own icon
  121. char _showcollapse; // 1=show collapse icons, 0=don't
  122. char _showroot; // show the root item as part of the tree
  123. Fl_Tree_Sort _sortorder; // none, ascening, descending, etc.
  124. Fl_Boxtype _selectbox; // selection box type
  125. Fl_Tree_Select _selectmode; // selection mode
  126. #if FLTK_ABI_VERSION >= 10301
  127. Fl_Tree_Item_Reselect_Mode _itemreselectmode; // controls item selection callback() behavior
  128. Fl_Tree_Item_Draw_Mode _itemdrawmode; // controls how items draw label + widget()
  129. #endif /*FLTK_ABI_VERSION*/
  130. #if FLTK_ABI_VERSION >= 10303
  131. Fl_Tree_Item_Draw_Callback *_itemdrawcallback; // callback to handle drawing items (0=none)
  132. void *_itemdrawuserdata; // data for drawing items (0=none)
  133. #endif
  134. public:
  135. Fl_Tree_Prefs();
  136. ////////////////////////////
  137. // Labels
  138. ////////////////////////////
  139. /// Return the label's font.
  140. inline Fl_Font item_labelfont() const { return(_labelfont); }
  141. /// Set the label's font to \p val.
  142. inline void item_labelfont(Fl_Font val) { _labelfont = val; }
  143. /// Return the label's size in pixels.
  144. inline Fl_Fontsize item_labelsize() const { return(_labelsize); }
  145. /// Set the label's size in pixels to \p val.
  146. inline void item_labelsize(Fl_Fontsize val) { _labelsize = val; }
  147. /// Get the default label foreground color
  148. inline Fl_Color item_labelfgcolor() const { return(_labelfgcolor); }
  149. /// Set the default label foreground color
  150. inline void item_labelfgcolor(Fl_Color val) { _labelfgcolor = val; }
  151. #if FLTK_ABI_VERSION >= 10301
  152. /// Get the default label background color.
  153. /// This returns the Fl_Tree::color() unless item_labelbgcolor()
  154. /// has been set explicitly.
  155. ///
  156. inline Fl_Color item_labelbgcolor() const {
  157. return _labelbgcolor;
  158. }
  159. /// Set the default label background color.
  160. /// Once set, overrides the default behavior of using Fl_Tree::color().
  161. ///
  162. inline void item_labelbgcolor(Fl_Color val) {
  163. _labelbgcolor = val;
  164. }
  165. #else /*FLTK_ABI_VERSION*/
  166. /// Get the default label background color
  167. inline Fl_Color item_labelbgcolor() const {
  168. return(_labelbgcolor);
  169. }
  170. /// Set the default label background color
  171. inline void item_labelbgcolor(Fl_Color val) {
  172. _labelbgcolor = val;
  173. }
  174. #endif /*FLTK_ABI_VERSION*/
  175. /////////////////
  176. // Obsolete names - for 1.3.0 backwards compat
  177. /////////////////
  178. /// Obsolete: Return the label's font. Please use item_labelfont() instead.
  179. inline Fl_Font labelfont() const { return(_labelfont); }
  180. /// Obsolete: Set the label's font to \p val. Please use item_labelfont(Fl_Font) instead.
  181. inline void labelfont(Fl_Font val) { _labelfont = val; }
  182. /// Obsolete: Return the label's size in pixels. Please use item_labelsize() instead.
  183. inline Fl_Fontsize labelsize() const { return(_labelsize); }
  184. /// Obsolete: Set the label's size in pixels to \p val. Please use item_labelsize(Fl_Fontsize) instead.
  185. inline void labelsize(Fl_Fontsize val) { _labelsize = val; }
  186. /// Obsolete: Get the default label foreground color. Please use item_labelfgcolor() instead.
  187. inline Fl_Color labelfgcolor() const { return(_labelfgcolor); }
  188. /// Obsolete: Set the default label foreground color. Please use item_labelfgcolor(Fl_Color) instead.
  189. inline void labelfgcolor(Fl_Color val) { _labelfgcolor = val; }
  190. /// Obsolete: Get the default label background color. Please use item_labelbgcolor() instead.
  191. inline Fl_Color labelbgcolor() const { return(item_labelbgcolor()); }
  192. /// Obsolete: Set the default label background color. Please use item_labelbgcolor(Fl_Color) instead.
  193. inline void labelbgcolor(Fl_Color val) { item_labelbgcolor(val); }
  194. ////////////////////////////
  195. // Margins
  196. ////////////////////////////
  197. /// Get the left margin's value in pixels
  198. inline int marginleft() const {
  199. return(_marginleft);
  200. }
  201. /// Set the left margin's value in pixels
  202. inline void marginleft(int val) {
  203. _marginleft = val;
  204. }
  205. /// Get the top margin's value in pixels
  206. inline int margintop() const {
  207. return(_margintop);
  208. }
  209. /// Set the top margin's value in pixels
  210. inline void margintop(int val) {
  211. _margintop = val;
  212. }
  213. #if FLTK_ABI_VERSION >= 10301
  214. /// Get the bottom margin's value in pixels.
  215. /// This is the extra distance the vertical scroller lets you travel.
  216. inline int marginbottom() const {
  217. return(_marginbottom);
  218. }
  219. /// Set the bottom margin's value in pixels
  220. /// This is the extra distance the vertical scroller lets you travel.
  221. inline void marginbottom(int val) {
  222. _marginbottom = val;
  223. }
  224. #endif /*FLTK_ABI_VERSION*/
  225. /// Get the margin below an open child in pixels
  226. inline int openchild_marginbottom() const {
  227. return(_openchild_marginbottom);
  228. }
  229. /// Set the margin below an open child in pixels
  230. inline void openchild_marginbottom(int val) {
  231. _openchild_marginbottom = val;
  232. }
  233. /// Get the user icon's left margin value in pixels
  234. inline int usericonmarginleft() const {
  235. return(_usericonmarginleft);
  236. }
  237. /// Set the user icon's left margin value in pixels
  238. inline void usericonmarginleft(int val) {
  239. _usericonmarginleft = val;
  240. }
  241. /// Get the label's left margin value in pixels
  242. inline int labelmarginleft() const {
  243. return(_labelmarginleft);
  244. }
  245. /// Set the label's left margin value in pixels
  246. inline void labelmarginleft(int val) {
  247. _labelmarginleft = val;
  248. }
  249. #if FLTK_ABI_VERSION >= 10301
  250. /// Get the widget()'s left margin value in pixels
  251. inline int widgetmarginleft() const {
  252. return(_widgetmarginleft);
  253. }
  254. /// Set the widget's left margin value in pixels
  255. inline void widgetmarginleft(int val) {
  256. _widgetmarginleft = val;
  257. }
  258. #endif /*FLTK_ABI_VERSION*/
  259. /// Get the line spacing value in pixels
  260. inline int linespacing() const {
  261. return(_linespacing);
  262. }
  263. /// Set the line spacing value in pixels
  264. inline void linespacing(int val) {
  265. _linespacing = val;
  266. }
  267. ////////////////////////////
  268. // Colors and Styles
  269. ////////////////////////////
  270. /// Get the connector color used for tree connection lines.
  271. inline Fl_Color connectorcolor() const {
  272. return(_connectorcolor);
  273. }
  274. /// Set the connector color used for tree connection lines.
  275. inline void connectorcolor(Fl_Color val) {
  276. _connectorcolor = val;
  277. }
  278. /// Get the connector style.
  279. inline Fl_Tree_Connector connectorstyle() const {
  280. return(_connectorstyle);
  281. }
  282. /// Set the connector style.
  283. inline void connectorstyle(Fl_Tree_Connector val) {
  284. _connectorstyle = val;
  285. }
  286. /// Set the connector style [integer].
  287. inline void connectorstyle(int val) {
  288. _connectorstyle = Fl_Tree_Connector(val);
  289. }
  290. /// Get the tree connection line's width.
  291. inline int connectorwidth() const {
  292. return(_connectorwidth);
  293. }
  294. /// Set the tree connection line's width.
  295. inline void connectorwidth(int val) {
  296. _connectorwidth = val;
  297. }
  298. ////////////////////////////
  299. // Icons
  300. ////////////////////////////
  301. /// Get the current default 'open' icon.
  302. /// Returns the Fl_Image* of the icon, or 0 if none.
  303. ///
  304. inline Fl_Image *openicon() const {
  305. return(_openimage);
  306. }
  307. void openicon(Fl_Image *val);
  308. /// Gets the default 'close' icon
  309. /// Returns the Fl_Image* of the icon, or 0 if none.
  310. ///
  311. inline Fl_Image *closeicon() const {
  312. return(_closeimage);
  313. }
  314. void closeicon(Fl_Image *val);
  315. /// Gets the default 'user icon' (default is 0)
  316. inline Fl_Image *usericon() const {
  317. return(_userimage);
  318. }
  319. /// Sets the default 'user icon'
  320. /// Returns the Fl_Image* of the icon, or 0 if none (default).
  321. ///
  322. inline void usericon(Fl_Image *val) {
  323. _userimage = val;
  324. }
  325. ////////////////////////////
  326. // Options
  327. ////////////////////////////
  328. /// Returns 1 if the collapse icon is enabled, 0 if not.
  329. inline char showcollapse() const {
  330. return(_showcollapse);
  331. }
  332. /// Set if we should show the collapse icon or not.
  333. /// If collapse icons are disabled, the user will not be able
  334. /// to interactively collapse items in the tree, unless the application
  335. /// provides some other means via open() and close().
  336. ///
  337. /// \param[in] val 1: shows collapse icons (default),\n
  338. /// 0: hides collapse icons.
  339. ///
  340. inline void showcollapse(int val) {
  341. _showcollapse = val;
  342. }
  343. /// Get the default sort order value
  344. inline Fl_Tree_Sort sortorder() const {
  345. return(_sortorder);
  346. }
  347. /// Set the default sort order value.
  348. /// Defines the order new items appear when add()ed to the tree.
  349. /// See Fl_Tree_Sort for possible values.
  350. ///
  351. inline void sortorder(Fl_Tree_Sort val) {
  352. _sortorder = val;
  353. }
  354. /// Get the default selection box's box drawing style as an Fl_Boxtype.
  355. inline Fl_Boxtype selectbox() const {
  356. return(_selectbox);
  357. }
  358. /// Set the default selection box's box drawing style to \p val.
  359. inline void selectbox(Fl_Boxtype val) {
  360. _selectbox = val;
  361. }
  362. /// Returns 1 if the root item is to be shown, or 0 if not.
  363. inline int showroot() const {
  364. return(int(_showroot));
  365. }
  366. /// Set if the root item should be shown or not.
  367. /// \param[in] val 1 -- show the root item (default)\n
  368. /// 0 -- hide the root item.
  369. ///
  370. inline void showroot(int val) {
  371. _showroot = char(val);
  372. }
  373. /// Get the selection mode used for the tree
  374. inline Fl_Tree_Select selectmode() const {
  375. return(_selectmode);
  376. }
  377. /// Set the selection mode used for the tree to \p val.
  378. /// This affects how items in the tree are selected
  379. /// when clicked on and dragged over by the mouse.
  380. /// See Fl_Tree_Select for possible values.
  381. ///
  382. inline void selectmode(Fl_Tree_Select val) {
  383. _selectmode = val;
  384. }
  385. #if FLTK_ABI_VERSION >= 10301
  386. /// Returns the current item re/selection mode
  387. Fl_Tree_Item_Reselect_Mode item_reselect_mode() const {
  388. return _itemreselectmode;
  389. }
  390. /// Sets the item re/selection mode
  391. void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
  392. _itemreselectmode = mode;
  393. }
  394. /// Get the 'item draw mode' used for the tree
  395. inline Fl_Tree_Item_Draw_Mode item_draw_mode() const {
  396. return(_itemdrawmode);
  397. }
  398. /// Set the 'item draw mode' used for the tree to \p val.
  399. /// This affects how items in the tree are drawn,
  400. /// such as when a widget() is defined.
  401. /// See Fl_Tree_Item_Draw_Mode for possible values.
  402. ///
  403. inline void item_draw_mode(Fl_Tree_Item_Draw_Mode val) {
  404. _itemdrawmode = val;
  405. }
  406. #endif
  407. #if FLTK_ABI_VERSION >= 10303
  408. void item_draw_callback(Fl_Tree_Item_Draw_Callback *cb, void *data=0) {
  409. _itemdrawcallback = cb;
  410. _itemdrawuserdata = data;
  411. }
  412. Fl_Tree_Item_Draw_Callback* item_draw_callback() const {
  413. return(_itemdrawcallback);
  414. }
  415. void* item_draw_user_data() const {
  416. return(_itemdrawuserdata);
  417. }
  418. void do_item_draw_callback(Fl_Tree_Item *o) const {
  419. _itemdrawcallback(o, _itemdrawuserdata);
  420. }
  421. #endif
  422. };
  423. #endif /*FL_TREE_PREFS_H*/
  424. //
  425. // End of "$Id: Fl_Tree_Prefs.H 10034 2013-12-15 18:59:02Z greg.ercolano $".
  426. //