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