FLTK 1.3.4
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Tree.H 11975 2016-09-24 22:47:28Z AlbrechtS $"
3 //
5 #ifndef FL_TREE_H
6 #define FL_TREE_H
8 #include <FL/Fl.H>
9 #include <FL/Fl_Group.H>
10 #include <FL/Fl_Scrollbar.H>
11 #include <FL/fl_draw.H>
13 #include <FL/Fl_Tree_Item.H>
14 #include <FL/Fl_Tree_Prefs.H>
17 // FL/Fl_Tree.H
19 //
20 // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
21 // Copyright (C) 2009-2010 by Greg Ercolano.
22 //
23 // This library is free software. Distribution and use rights are outlined in
24 // the file "COPYING" which should have been included with this file. If this
25 // file is missing or damaged, see the license at:
26 //
27 // http://www.fltk.org/COPYING.php
28 //
29 // Please report all bugs and problems on the following page:
30 //
31 // http://www.fltk.org/str.php
32 //
315 #if FLTK_ABI_VERSION >= 10301
317 #endif /*FLTK_ABI_VERSION*/
321 };
323 class FL_EXPORT Fl_Tree : public Fl_Group {
324  friend class Fl_Tree_Item;
325  Fl_Tree_Item *_root; // can be null!
326  Fl_Tree_Item *_item_focus; // item that has focus box
327  Fl_Tree_Item *_callback_item; // item invoked during callback (can be NULL)
328  Fl_Tree_Reason _callback_reason; // reason for the callback
329  Fl_Tree_Prefs _prefs; // all the tree's settings
330  int _scrollbar_size; // size of scrollbar trough
331 #if FLTK_ABI_VERSION >= 10301
332  // NEW:
333  Fl_Tree_Item *_lastselect; // used to extend selections
334 #else /*FLTK_ABI_VERSION*/
335  // OLD: static data inside handle() method
336 #endif /*FLTK_ABI_VERSION*/
337  void fix_scrollbar_order();
339 protected:
341 #if FLTK_ABI_VERSION >= 10303
343  int _tox,_toy,_tow,_toh;
344  int _tix,_tiy,_tiw,_tih;
347  int _tree_w;
349  int _tree_h;
350 #endif
351  void item_clicked(Fl_Tree_Item* val);
352  void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
353 #if FLTK_ABI_VERSION >= 10303
354 // next_visible_item() and extend_selection() moved to 'public' in ABI 1.3.3
355 // undocmented draw_tree() dropped -- draw() does all the work now
356 #else
357  Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);
358  void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to);
359  int draw_tree();
360 #endif
362 public:
363  Fl_Tree(int X, int Y, int W, int H, const char *L=0);
364  ~Fl_Tree();
365  int handle(int e);
366  void draw();
367  void show_self();
368  void resize(int,int,int,int);
371  // root methods
373  void root_label(const char *new_label);
374  Fl_Tree_Item* root();
375  void root(Fl_Tree_Item *newitem);
376  const Fl_Tree_Prefs& prefs() const { return _prefs; }
379  // Item creation/removal methods
381 #if FLTK_ABI_VERSION >= 10303
382  Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem=0);
383 #else
384  Fl_Tree_Item *add(const char *path);
385  Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem);
386 #endif
387  Fl_Tree_Item* add(Fl_Tree_Item *parent_item, const char *name);
388  Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
389  Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
390  int remove(Fl_Tree_Item *item);
391  void clear();
392  void clear_children(Fl_Tree_Item *item);
395  // Item lookup methods
397  Fl_Tree_Item *find_item(const char *path);
398  const Fl_Tree_Item *find_item(const char *path) const;
399  int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
400 #if FLTK_ABI_VERSION >= 10303
401  const Fl_Tree_Item* find_clicked(int yonly=0) const;
402  Fl_Tree_Item* find_clicked(int yonly=0);
403 #else
404  const Fl_Tree_Item *find_clicked() const;
406 #endif
407  Fl_Tree_Item *item_clicked();
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 &ret_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
431  // Item open/close methods
433  int open(Fl_Tree_Item *item, int docallback=1);
434  int open(const char *path, int docallback=1);
435  void open_toggle(Fl_Tree_Item *item, int docallback=1);
436  int close(Fl_Tree_Item *item, int docallback=1);
437  int close(const char *path, int docallback=1);
438  int is_open(Fl_Tree_Item *item) const;
439  int is_open(const char *path) const;
440  int is_close(Fl_Tree_Item *item) const;
441  int is_close(const char *path) const;
444  // Item selection methods
446  int select(Fl_Tree_Item *item, int docallback=1);
447  int select(const char *path, int docallback=1);
448  void select_toggle(Fl_Tree_Item *item, int docallback=1);
449  int deselect(Fl_Tree_Item *item, int docallback=1);
450  int deselect(const char *path, int docallback=1);
451  int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
452  int select_only(Fl_Tree_Item *selitem, int docallback=1);
453  int select_all(Fl_Tree_Item *item=0, int docallback=1);
454  int extend_selection_dir(Fl_Tree_Item *from,
455  Fl_Tree_Item *to,
456  int dir,
457  int val,
458  bool visible);
459 #if FLTK_ABI_VERSION >= 10303
460  int extend_selection(Fl_Tree_Item *from,
461  Fl_Tree_Item *to,
462  int val=1,
463  bool visible=false);
464 #else
465 private:
466  // Adding overload if not at least one overload breaks ABI, so avoid
467  // by keeping private until we can break ABI. ref: http://www.ros.org/reps/rep-0009.html
468  int extend_selection__(Fl_Tree_Item *from,
469  Fl_Tree_Item *to,
470  int val,
471  bool visible);
472 public:
473 #endif
474  void set_item_focus(Fl_Tree_Item *item);
475  Fl_Tree_Item *get_item_focus() const;
476  int is_selected(Fl_Tree_Item *item) const;
477  int is_selected(const char *path);
480  // Item attribute related methods
482  Fl_Font item_labelfont() const;
483  void item_labelfont(Fl_Font val);
484  Fl_Fontsize item_labelsize() const;
485  void item_labelsize(Fl_Fontsize val);
486  Fl_Color item_labelfgcolor(void) const;
487  void item_labelfgcolor(Fl_Color val);
488  Fl_Color item_labelbgcolor(void) const;
489  void item_labelbgcolor(Fl_Color val);
490  Fl_Color connectorcolor() const;
491  void connectorcolor(Fl_Color val);
492  int marginleft() const;
493  void marginleft(int val);
494  int margintop() const;
495  void margintop(int val);
496 #if FLTK_ABI_VERSION >= 10301
497  int marginbottom() const;
498  void marginbottom(int val);
499 #endif /*FLTK_ABI_VERSION*/
500  int linespacing() const;
501  void linespacing(int val);
502  int openchild_marginbottom() const;
503  void openchild_marginbottom(int val);
504  int usericonmarginleft() const;
505  void usericonmarginleft(int val);
506  int labelmarginleft() const;
507  void labelmarginleft(int val);
508 #if FLTK_ABI_VERSION >= 10301
509  int widgetmarginleft() const;
510  void widgetmarginleft(int val);
511 #endif /*FLTK_ABI_VERSION*/
512  int connectorwidth() const;
513  void connectorwidth(int val);
514  Fl_Image* usericon() const;
515  void usericon(Fl_Image *val);
516  Fl_Image* openicon() const;
517  void openicon(Fl_Image *val);
518  Fl_Image* closeicon() const;
519  void closeicon(Fl_Image *val);
520  int showcollapse() const;
521  void showcollapse(int val);
522  int showroot() const;
523  void showroot(int val);
524  Fl_Tree_Connector connectorstyle() const;
525  void connectorstyle(Fl_Tree_Connector val);
526  Fl_Tree_Sort sortorder() const;
527  void sortorder(Fl_Tree_Sort val);
528  Fl_Boxtype selectbox() const;
529  void selectbox(Fl_Boxtype val);
530  Fl_Tree_Select selectmode() const;
531  void selectmode(Fl_Tree_Select val);
532 #if FLTK_ABI_VERSION >= 10301
533  Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
534  void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
535  Fl_Tree_Item_Draw_Mode item_draw_mode() const;
536  void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
537  void item_draw_mode(int mode);
538 #endif
539 #if FLTK_ABI_VERSION >= 10303
540  void calc_dimensions();
541  void calc_tree();
542 #endif
543  void recalc_tree();
544  int displayed(Fl_Tree_Item *item);
545  void show_item(Fl_Tree_Item *item, int yoff);
546  void show_item(Fl_Tree_Item *item);
547  void show_item_top(Fl_Tree_Item *item);
548  void show_item_middle(Fl_Tree_Item *item);
549  void show_item_bottom(Fl_Tree_Item *item);
550  void display(Fl_Tree_Item *item);
551  int vposition() const;
552  void vposition(int pos);
553  int hposition() const;
554  void hposition(int pos);
556  int is_scrollbar(Fl_Widget *w);
557  int scrollbar_size() const;
558  void scrollbar_size(int size);
559  int is_vscroll_visible() const;
560  int is_hscroll_visible() const;
563  // callback related
565  void callback_item(Fl_Tree_Item* item);
566  Fl_Tree_Item* callback_item();
567  void callback_reason(Fl_Tree_Reason reason);
568  Fl_Tree_Reason callback_reason() const;
571  void load(class Fl_Preferences&);
572 };
574 #endif /*FL_TREE_H*/
576 //
577 // End of "$Id: Fl_Tree.H 11975 2016-09-24 22:47:28Z AlbrechtS $".
578 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:101
Fl_Tree_Item * next()
Return the next item in the tree.
Definition: Fl_Tree_Item.cxx:1601
an item was opened
Definition: Fl_Tree.H:318
int _tih
Tree widget inner xywh dimension: inside borders + scrollbars.
Definition: Fl_Tree.H:344
void select(int val=1)
Change the item's selection state to the optionally specified 'val'.
Definition: Fl_Tree_Item.H:344
Sort order options for items added to the tree.
Definition: Fl_Tree_Prefs.H:49
const Fl_Tree_Prefs & prefs() const
Return the parent tree's prefs.
Definition: Fl_Tree_Item.cxx:611
int _toh
Tree widget outer xywh dimension: outside scrollbars, inside widget border.
Definition: Fl_Tree.H:343
Tree selection style.
Definition: Fl_Tree_Prefs.H:67
int _tree_w
the calculated width of the entire tree hierarchy. See calc_tree()
Definition: Fl_Tree.H:347
int visible() const
See if the item is visible. Alias for is_visible().
Definition: Fl_Tree_Item.H:427
Tree widget.
Definition: Fl_Tree.H:323
int deselect_all()
Deselect item and all its children.
Definition: Fl_Tree_Item.H:378
Fl static class.
an item was selected
Definition: Fl_Tree.H:313
void open()
Open this item and all its children.
Definition: Fl_Tree_Item.cxx:1559
void deselect()
Disable the item's selection state.
Definition: Fl_Tree_Item.H:371
Base class for image caching and drawing.
Definition: Fl_Image.H:55
int select_all()
Select item and all its children.
Definition: Fl_Tree_Item.H:359
void close()
Close this item and all its children.
Definition: Fl_Tree_Item.cxx:1569
void draw()
Draws the widget.
Definition: Fl_Group.cxx:738
Definition: Enumerations.H:603
void clear()
Deletes all child widgets from memory recursively.
Definition: Fl_Group.cxx:383
The reason the callback was invoked.
Definition: Fl_Tree.H:311
Fl_Scrollbar * _vscroll
Vertical scrollbar.
Definition: Fl_Tree.H:340
Fl_Scrollbar * _hscroll
Horizontal scrollbar.
Definition: Fl_Tree.H:342
void insert(Fl_Widget &, int i)
The widget is removed from its current group (if any) and then inserted into this group...
Definition: Fl_Group.cxx:458
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:41
an item was closed
Definition: Fl_Tree.H:319
void select_toggle()
Toggle the item's selection state.
Definition: Fl_Tree_Item.H:348
int _tree_h
the calculated height of the entire tree hierarchy. See calc_tree()
Definition: Fl_Tree.H:349
void add(Fl_Widget &)
The widget is removed from its current group (if any) and then added to the end of this group...
Definition: Fl_Group.cxx:491
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:147
Fl_Tree_Item * insert_above(const Fl_Tree_Prefs &prefs, const char *new_label)
Insert a new item named 'new_label' above this item.
Definition: Fl_Tree_Item.cxx:454
void clear_children()
Clear all the children for this item.
Definition: Fl_Tree_Item.cxx:213
int w() const
The entire item's width to right edge of Fl_Tree's inner width within scrollbars. ...
Definition: Fl_Tree_Item.H:142
Fl_Tree_Item * prev()
Return the previous item in the tree.
Definition: Fl_Tree_Item.cxx:1633
Fl_Preferences provides methods to store user settings between application starts.
Definition: Fl_Preferences.H:60
#define FL_Down
The down arrow key.
Definition: Enumerations.H:483
Defines the style of connection lines between items.
Definition: Fl_Tree_Prefs.H:58
int is_close() const
See if the item is 'closed'.
Definition: Fl_Tree_Item.H:334
Fl_Image * usericon() const
Get the item's user icon as an Fl_Image. Returns '0' if disabled.
Definition: Fl_Tree_Item.H:450
void open_toggle()
Toggle the item's open/closed state.
Definition: Fl_Tree_Item.H:338
const Fl_Tree_Item * find_item(char **arr) const
Find item by descending array of 'names'.
Definition: Fl_Tree_Item.cxx:291
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:906
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:634
an item was de-selected
Definition: Fl_Tree.H:314
void recalc_tree()
Call this when our geometry is changed.
Definition: Fl_Tree_Item.cxx:1835
utility header to pull drawing functions together
const Fl_Tree_Item * find_clicked(const Fl_Tree_Prefs &prefs, int yonly=0) const
Find the item that the last event was over.
Definition: Fl_Tree_Item.cxx:796
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:934
Bit flags that control how item's labels and widget()s are drawn in the tree via item_draw_mode().
Definition: Fl_Tree_Prefs.H:90
Tree widget item.
Definition: Fl_Tree_Item.H:67
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:877
This file contains the definitions for Fl_Tree's preferences.
Defines the ways an item can be (re) selected via item_reselect_mode().
Definition: Fl_Tree_Prefs.H:81
Manages an array of Fl_Tree_Item pointers.
Definition: Fl_Tree_Item_Array.H:47
an item was dragged into a new place
Definition: Fl_Tree.H:320
an item was re-selected (e.g. double-clicked)
Definition: Fl_Tree.H:316
Tree widget's preferences.
Definition: Fl_Tree_Prefs.H:111
This file contains the definitions for Fl_Tree_Item.
char is_selected() const
See if the item is selected.
Definition: Fl_Tree_Item.H:390
void show_self(const char *indent="") const
Print the tree as 'ascii art' to stdout.
Definition: Fl_Tree_Item.cxx:171
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:43
unknown reason
Definition: Fl_Tree.H:312
int is_open() const
See if the item is 'open'.
Definition: Fl_Tree_Item.H:330