FLTK
Fl_Tree.H
Go to the documentation of this file.
1 //
2 
3 #ifndef FL_TREE_H
4 #define FL_TREE_H
5 
6 #include <FL/Fl.H>
7 #include <FL/Fl_Group.H>
8 #include <FL/Fl_Scrollbar.H>
9 #include <FL/fl_draw.H>
10 
11 #include <FL/Fl_Tree_Item.H>
12 #include <FL/Fl_Tree_Prefs.H>
13 
15 // FL/Fl_Tree.H
17 //
18 // Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
19 // Copyright (C) 2009-2010 by Greg Ercolano.
20 //
21 // This library is free software. Distribution and use rights are outlined in
22 // the file "COPYING" which should have been included with this file. If this
23 // file is missing or damaged, see the license at:
24 //
25 // https://www.fltk.org/COPYING.php
26 //
27 // Please see the following page on how to report bugs and issues:
28 //
29 // https://www.fltk.org/bugs.php
30 //
31 
36 
272 enum Fl_Tree_Reason {
284 };
285 
286 class FL_EXPORT Fl_Tree : public Fl_Group {
287  friend class Fl_Tree_Item;
288  Fl_Tree_Item *_root; // can be null!
289  Fl_Tree_Item *_item_focus; // item that has focus box
290  Fl_Tree_Item *_callback_item; // item invoked during callback (can be NULL)
291  Fl_Tree_Reason _callback_reason; // reason for the callback
292  Fl_Tree_Prefs _prefs; // all the tree's settings
293  int _scrollbar_size; // size of scrollbar trough
294  Fl_Tree_Item *_lastselect; // last selected item
295  char _lastpushed; // FL_PUSH occurred on: 0=nothing, 1=open/close, 2=usericon, 3=label
296  void fix_scrollbar_order();
297 
298 protected:
301  int _tox,_toy,_tow,_toh;
302  int _tix,_tiy,_tiw,_tih;
303 
305  int _tree_w;
307  int _tree_h;
308  void item_clicked(Fl_Tree_Item* val);
309  void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
310 
311  // next_visible_item() and extend_selection() moved to 'public' in ABI 1.3.3
312  // undocmented draw_tree() dropped -- draw() does all the work now
313 
314  // draw() has to be protected per FLTK convention (was public in 1.3.x)
315  void draw();
316 
317 public:
318  Fl_Tree(int X, int Y, int W, int H, const char *L=0);
319  ~Fl_Tree();
320  int handle(int e);
321  void show_self();
322  void resize(int,int,int,int);
323 
325  // root methods
327  void root_label(const char *new_label);
328  Fl_Tree_Item* root();
329  void root(Fl_Tree_Item *newitem);
330  const Fl_Tree_Prefs& prefs() const { return _prefs; }
331 
333  // Item creation/removal methods
335  Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem=0);
336  Fl_Tree_Item* add(Fl_Tree_Item *parent_item, const char *name);
337  Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
338  Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
339  int remove(Fl_Tree_Item *item);
340  void clear();
341  void clear_children(Fl_Tree_Item *item);
342 
344  // Item lookup methods
346  Fl_Tree_Item *find_item(const char *path);
347  const Fl_Tree_Item *find_item(const char *path) const;
348  int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
349  const Fl_Tree_Item* find_clicked(int yonly=0) const;
350  Fl_Tree_Item* find_clicked(int yonly=0);
351  Fl_Tree_Item *item_clicked();
352  Fl_Tree_Item *first();
353  Fl_Tree_Item *first_visible(); // deprecated in ABI 10303
354  Fl_Tree_Item *first_visible_item();
355  Fl_Tree_Item *next(Fl_Tree_Item *item=0);
356  Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
357  Fl_Tree_Item *last();
358  Fl_Tree_Item *last_visible(); // deprecated in ABI 10303
359  Fl_Tree_Item *last_visible_item();
360  Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir); // made public in 1.3.3 ABI
361  Fl_Tree_Item *first_selected_item();
362  Fl_Tree_Item *last_selected_item();
363  Fl_Tree_Item *next_item(Fl_Tree_Item *item, int dir=FL_Down, bool visible=false);
364  Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0, int dir=FL_Down);
365  int get_selected_items(Fl_Tree_Item_Array &items);
366 
368  // Item open/close methods
370  int open(Fl_Tree_Item *item, int docallback=1);
371  int open(const char *path, int docallback=1);
372  void open_toggle(Fl_Tree_Item *item, int docallback=1);
373  int close(Fl_Tree_Item *item, int docallback=1);
374  int close(const char *path, int docallback=1);
375  int is_open(Fl_Tree_Item *item) const;
376  int is_open(const char *path) const;
377  int is_close(Fl_Tree_Item *item) const;
378  int is_close(const char *path) const;
379 
381  // Item selection methods
383  int select(Fl_Tree_Item *item, int docallback=1);
384  int select(const char *path, int docallback=1);
385  void select_toggle(Fl_Tree_Item *item, int docallback=1);
386  int deselect(Fl_Tree_Item *item, int docallback=1);
387  int deselect(const char *path, int docallback=1);
388  int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
389  int select_only(Fl_Tree_Item *selitem, int docallback=1);
390  int select_all(Fl_Tree_Item *item=0, int docallback=1);
391  int extend_selection_dir(Fl_Tree_Item *from,
392  Fl_Tree_Item *to,
393  int dir,
394  int val,
395  bool visible);
396  int extend_selection(Fl_Tree_Item *from,
397  Fl_Tree_Item *to,
398  int val=1,
399  bool visible=false);
400  void set_item_focus(Fl_Tree_Item *item);
401  Fl_Tree_Item *get_item_focus() const;
402  int is_selected(Fl_Tree_Item *item) const;
403  int is_selected(const char *path);
404 
406  // Item attribute related methods
408  Fl_Font item_labelfont() const;
409  void item_labelfont(Fl_Font val);
410  Fl_Fontsize item_labelsize() const;
411  void item_labelsize(Fl_Fontsize val);
412  Fl_Color item_labelfgcolor(void) const;
413  void item_labelfgcolor(Fl_Color val);
414  Fl_Color item_labelbgcolor(void) const;
415  void item_labelbgcolor(Fl_Color val);
416  Fl_Color connectorcolor() const;
417  void connectorcolor(Fl_Color val);
418  int marginleft() const;
419  void marginleft(int val);
420  int margintop() const;
421  void margintop(int val);
422  int marginbottom() const;
423  void marginbottom(int val);
424  int linespacing() const;
425  void linespacing(int val);
426  int openchild_marginbottom() const;
427  void openchild_marginbottom(int val);
428  int usericonmarginleft() const;
429  void usericonmarginleft(int val);
430  int labelmarginleft() const;
431  void labelmarginleft(int val);
432  int widgetmarginleft() const;
433  void widgetmarginleft(int val);
434  int connectorwidth() const;
435  void connectorwidth(int val);
436  Fl_Image* usericon() const;
437  void usericon(Fl_Image *val);
438  Fl_Image* openicon() const;
439  void openicon(Fl_Image *val);
440  Fl_Image* closeicon() const;
441  void closeicon(Fl_Image *val);
442  int showcollapse() const;
443  void showcollapse(int val);
444  int showroot() const;
445  void showroot(int val);
446  Fl_Tree_Connector connectorstyle() const;
447  void connectorstyle(Fl_Tree_Connector val);
448  Fl_Tree_Sort sortorder() const;
449  void sortorder(Fl_Tree_Sort val);
450  Fl_Boxtype selectbox() const;
451  void selectbox(Fl_Boxtype val);
452  Fl_Tree_Select selectmode() const;
453  void selectmode(Fl_Tree_Select val);
454  Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
455  void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
456  Fl_Tree_Item_Draw_Mode item_draw_mode() const;
457  void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
458  void item_draw_mode(int mode);
459  void calc_dimensions();
460  void calc_tree();
461  void recalc_tree();
462  int displayed(Fl_Tree_Item *item);
463  void show_item(Fl_Tree_Item *item, int yoff);
464  void show_item(Fl_Tree_Item *item);
465  void show_item_top(Fl_Tree_Item *item);
466  void show_item_middle(Fl_Tree_Item *item);
467  void show_item_bottom(Fl_Tree_Item *item);
468  void display(Fl_Tree_Item *item);
469  int vposition() const;
470  void vposition(int pos);
471  int hposition() const;
472  void hposition(int pos);
473 
474  int is_scrollbar(Fl_Widget *w);
475  int scrollbar_size() const;
476  void scrollbar_size(int size);
477  int is_vscroll_visible() const;
478  int is_hscroll_visible() const;
479 
481  // callback related
483  void callback_item(Fl_Tree_Item* item);
484  Fl_Tree_Item* callback_item();
485  void callback_reason(Fl_Tree_Reason reason);
486  Fl_Tree_Reason callback_reason() const;
487 
489  void load(class Fl_Preferences&);
490 };
491 
492 #endif /*FL_TREE_H*/
int w() const
The entire item&#39;s width to right edge of Fl_Tree&#39;s inner width within scrollbars. ...
Definition: Fl_Tree_Item.H:114
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
void show_self(const char *indent="") const
Print the tree as &#39;ascii art&#39; to stdout.
Definition: Fl_Tree_Item.cxx:137
Fl_Tree_Item * next()
Return the next item in the tree.
Definition: Fl_Tree_Item.cxx:1300
an item was opened
Definition: Fl_Tree.H:281
int _tih
Tree widget inner xywh dimension: inside borders + scrollbars.
Definition: Fl_Tree.H:302
void select(int val=1)
Change the item&#39;s selection state to the optionally specified &#39;val&#39;.
Definition: Fl_Tree_Item.H:305
Fl_Tree_Sort
Sort order options for items added to the tree.
Definition: Fl_Tree_Prefs.H:47
int _toh
Tree widget outer xywh dimension: outside scrollbars, inside widget border.
Definition: Fl_Tree.H:301
Fl_Tree_Select
Tree selection style.
Definition: Fl_Tree_Prefs.H:65
int is_open() const
See if the item is &#39;open&#39;.
Definition: Fl_Tree_Item.H:291
int _tree_w
the calculated width of the entire tree hierarchy. See calc_tree()
Definition: Fl_Tree.H:305
Tree widget.
Definition: Fl_Tree.H:286
int deselect_all()
Deselect item and all its children.
Definition: Fl_Tree_Item.H:339
Fl static class.
an item was selected
Definition: Fl_Tree.H:277
void open()
Open this item and all its children.
Definition: Fl_Tree_Item.cxx:1258
void deselect()
Disable the item&#39;s selection state.
Definition: Fl_Tree_Item.H:332
Base class for image caching, scaling and drawing.
Definition: Fl_Image.H:62
int select_all()
Select item and all its children.
Definition: Fl_Tree_Item.H:320
void close()
Close this item and all its children.
Definition: Fl_Tree_Item.cxx:1268
void draw()
Draws the widget.
Definition: Fl_Group.cxx:817
Fl_Boxtype
FLTK standard box types.
Definition: Enumerations.H:598
void clear()
Deletes all child widgets from memory recursively.
Definition: Fl_Group.cxx:388
Fl_Tree_Reason
The reason the callback was invoked.
Definition: Fl_Tree.H:275
Fl_Scrollbar * _vscroll
Vertical scrollbar.
Definition: Fl_Tree.H:299
Fl_Scrollbar * _hscroll
Horizontal scrollbar.
Definition: Fl_Tree.H:300
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:464
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
an item was closed
Definition: Fl_Tree.H:282
void select_toggle()
Toggle the item&#39;s selection state.
Definition: Fl_Tree_Item.H:309
int _tree_h
the calculated height of the entire tree hierarchy. See calc_tree()
Definition: Fl_Tree.H:307
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:497
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:144
Fl_Image * usericon() const
Get the item&#39;s user icon as an Fl_Image. Returns &#39;0&#39; if disabled.
Definition: Fl_Tree_Item.H:411
Fl_Tree_Item * insert_above(const Fl_Tree_Prefs &prefs, const char *new_label)
Insert a new item named &#39;new_label&#39; above this item.
Definition: Fl_Tree_Item.cxx:413
char is_selected() const
See if the item is selected.
Definition: Fl_Tree_Item.H:351
void clear_children()
Clear all the children for this item.
Definition: Fl_Tree_Item.cxx:174
int is_close() const
See if the item is &#39;closed&#39;.
Definition: Fl_Tree_Item.H:295
Fl_Tree_Item * prev()
Return the previous item in the tree.
Definition: Fl_Tree_Item.cxx:1321
Fl_Preferences provides methods to store user settings between application starts.
Definition: Fl_Preferences.H:63
#define FL_Down
The down arrow key.
Definition: Enumerations.H:465
Fl_Tree_Connector
Defines the style of connection lines between items.
Definition: Fl_Tree_Prefs.H:56
void open_toggle()
Toggle the item&#39;s open/closed state.
Definition: Fl_Tree_Item.H:299
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:700
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:764
an item was de-selected
Definition: Fl_Tree.H:278
void recalc_tree()
Call this when our geometry is changed.
Definition: Fl_Tree_Item.cxx:1480
utility header to pull drawing functions together
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
Fl_Tree_Item_Draw_Mode
Bit flags that control how item&#39;s labels and widget()s are drawn in the tree via item_draw_mode().
Definition: Fl_Tree_Prefs.H:87
Tree widget item.
Definition: Fl_Tree_Item.H:65
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
int visible() const
See if the item is visible. Alias for is_visible().
Definition: Fl_Tree_Item.H:388
This file contains the definitions for Fl_Tree&#39;s preferences.
Fl_Tree_Item_Reselect_Mode
Defines the ways an item can be (re) selected via item_reselect_mode().
Definition: Fl_Tree_Prefs.H:78
Manages an array of Fl_Tree_Item pointers.
Definition: Fl_Tree_Item_Array.H:45
an item was dragged into a new place
Definition: Fl_Tree.H:283
an item was re-selected (double-clicked).
Definition: Fl_Tree.H:279
Tree widget&#39;s preferences.
Definition: Fl_Tree_Prefs.H:105
const Fl_Tree_Item * find_item(char **arr) const
Find item by descending array of &#39;names&#39;.
Definition: Fl_Tree_Item.cxx:252
This file contains the definitions for Fl_Tree_Item.
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:41
unknown reason
Definition: Fl_Tree.H:276
const Fl_Tree_Prefs & prefs() const
Return the parent tree&#39;s prefs.
Definition: Fl_Tree_Item.cxx:581