FLTK 1.3.2
Fl_Tree.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Tree.H 9706 2012-11-06 20:46:14Z matt $"
3 //
4 
5 #ifndef FL_TREE_H
6 #define FL_TREE_H
7 
8 #include <FL/Fl.H>
9 #include <FL/Fl_Group.H>
10 #include <FL/Fl_Scrollbar.H>
11 #include <FL/fl_draw.H>
12 
13 #include <FL/Fl_Tree_Item.H>
14 #include <FL/Fl_Tree_Prefs.H>
15 
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 //
33 
38 
295 
303 #if FLTK_ABI_VERSION >= 10301
304  FL_TREE_REASON_RESELECTED,
305 #endif /*FLTK_ABI_VERSION*/
308 };
309 
310 class FL_EXPORT Fl_Tree : public Fl_Group {
311  friend class Fl_Tree_Item;
312  Fl_Tree_Item *_root; // can be null!
313  Fl_Tree_Item *_item_focus; // item that has focus box
314  Fl_Tree_Item *_callback_item; // item invoked during callback (can be NULL)
315  Fl_Tree_Reason _callback_reason; // reason for the callback
316  Fl_Tree_Prefs _prefs; // all the tree's settings
317  int _scrollbar_size; // size of scrollbar trough
318 
319 #if FLTK_ABI_VERSION >= 10301
320  // NEW:
321  Fl_Tree_Item *_lastselect;
322 #else /*FLTK_ABI_VERSION*/
323  // OLD: static data inside handle() method
324 #endif /*FLTK_ABI_VERSION*/
325 
326  void fix_scrollbar_order();
327 
328 protected:
330  void item_clicked(Fl_Tree_Item* val);
331  void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
332  Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir);
333  void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to);
334  int draw_tree();
335 
336 public:
337  Fl_Tree(int X, int Y, int W, int H, const char *L=0);
338  ~Fl_Tree();
339  int handle(int e);
340  void draw();
341  void show_self();
342 
344  // root methods
346  void root_label(const char *new_label);
347  Fl_Tree_Item* root();
348 
350  // Item creation/removal methods
352  Fl_Tree_Item *add(const char *path);
353  Fl_Tree_Item* add(Fl_Tree_Item *item, const char *name);
354  Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
355  Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
356  int remove(Fl_Tree_Item *item);
357  void clear();
358  void clear_children(Fl_Tree_Item *item);
359 
361  // Item lookup methods
363  Fl_Tree_Item *find_item(const char *path);
364  const Fl_Tree_Item *find_item(const char *path) const;
365  int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
366  const Fl_Tree_Item *find_clicked() const;
367  Fl_Tree_Item *item_clicked();
368  Fl_Tree_Item *first();
369  Fl_Tree_Item *first_visible();
370  Fl_Tree_Item *next(Fl_Tree_Item *item=0);
371  Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
372  Fl_Tree_Item *last();
373  Fl_Tree_Item *last_visible();
374  Fl_Tree_Item *first_selected_item();
375  Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0);
376 
378  // Item open/close methods
380  int open(Fl_Tree_Item *item, int docallback=1);
381  int open(const char *path, int docallback=1);
382  void open_toggle(Fl_Tree_Item *item, int docallback=1);
383  int close(Fl_Tree_Item *item, int docallback=1);
384  int close(const char *path, int docallback=1);
385  int is_open(Fl_Tree_Item *item) const;
386  int is_open(const char *path) const;
387  int is_close(Fl_Tree_Item *item) const;
388  int is_close(const char *path) const;
389 
391  // Item selection methods
393  int select(Fl_Tree_Item *item, int docallback=1);
394  int select(const char *path, int docallback=1);
395  void select_toggle(Fl_Tree_Item *item, int docallback=1);
396  int deselect(Fl_Tree_Item *item, int docallback=1);
397  int deselect(const char *path, int docallback=1);
398  int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
399  int select_only(Fl_Tree_Item *selitem, int docallback=1);
400  int select_all(Fl_Tree_Item *item=0, int docallback=1);
401  void set_item_focus(Fl_Tree_Item *item);
402  Fl_Tree_Item *get_item_focus() const;
403  int is_selected(Fl_Tree_Item *item) const;
404  int is_selected(const char *path);
405 
407  // Item attribute related methods
409  Fl_Font item_labelfont() const;
410  void item_labelfont(Fl_Font val);
411  Fl_Fontsize item_labelsize() const;
412  void item_labelsize(Fl_Fontsize val);
413  Fl_Color item_labelfgcolor(void) const;
414  void item_labelfgcolor(Fl_Color val);
415  Fl_Color item_labelbgcolor(void) const;
416  void item_labelbgcolor(Fl_Color val);
417  Fl_Color connectorcolor() const;
418  void connectorcolor(Fl_Color val);
419  int marginleft() const;
420  void marginleft(int val);
421  int margintop() const;
422  void margintop(int val);
423 #if FLTK_ABI_VERSION >= 10301
424  int marginbottom() const;
425  void marginbottom(int val);
426 #endif /*FLTK_ABI_VERSION*/
427  int linespacing() const;
428  void linespacing(int val);
429  int openchild_marginbottom() const;
430  void openchild_marginbottom(int val);
431  int usericonmarginleft() const;
432  void usericonmarginleft(int val);
433  int labelmarginleft() const;
434  void labelmarginleft(int val);
435 #if FLTK_ABI_VERSION >= 10301
436  int widgetmarginleft() const;
437  void widgetmarginleft(int val);
438 #endif /*FLTK_ABI_VERSION*/
439  int connectorwidth() const;
440  void connectorwidth(int val);
441  Fl_Image* usericon() const;
442  void usericon(Fl_Image *val);
443  Fl_Image* openicon() const;
444  void openicon(Fl_Image *val);
445  Fl_Image* closeicon() const;
446  void closeicon(Fl_Image *val);
447  int showcollapse() const;
448  void showcollapse(int val);
449  int showroot() const;
450  void showroot(int val);
451  Fl_Tree_Connector connectorstyle() const;
452  void connectorstyle(Fl_Tree_Connector val);
453  Fl_Tree_Sort sortorder() const;
454  void sortorder(Fl_Tree_Sort val);
455  Fl_Boxtype selectbox() const;
456  void selectbox(Fl_Boxtype val);
457  Fl_Tree_Select selectmode() const;
458  void selectmode(Fl_Tree_Select val);
459 #if FLTK_ABI_VERSION >= 10301
460  Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
461  void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
462  Fl_Tree_Item_Draw_Mode item_draw_mode() const;
463  void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
464  void item_draw_mode(int mode);
465 #endif /*FLTK_ABI_VERSION*/
466  int displayed(Fl_Tree_Item *item);
467  void show_item(Fl_Tree_Item *item, int yoff);
468  void show_item(Fl_Tree_Item *item);
469  void show_item_top(Fl_Tree_Item *item);
470  void show_item_middle(Fl_Tree_Item *item);
471  void show_item_bottom(Fl_Tree_Item *item);
472  void display(Fl_Tree_Item *item);
473  int vposition() const;
474  void vposition(int pos);
475 
476  int is_scrollbar(Fl_Widget *w);
477  int scrollbar_size() const;
478  void scrollbar_size(int size);
479  int is_vscroll_visible() const;
480 
482  // callback related
484  void callback_item(Fl_Tree_Item* item);
485  Fl_Tree_Item* callback_item();
486  void callback_reason(Fl_Tree_Reason reason);
487  Fl_Tree_Reason callback_reason() const;
488 
490  void load(class Fl_Preferences&);
491 };
492 
493 #endif /*FL_TREE_H*/
494 
495 //
496 // End of "$Id: Fl_Tree.H 9706 2012-11-06 20:46:14Z matt $".
497 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
Fl_Tree_Item * next()
Return the next item in the tree.
Definition: Fl_Tree_Item.cxx:872
an item was opened
Definition: Fl_Tree.H:306
void select(int val=1)
Change the item's selection state to the optionally specified 'val'.
Definition: Fl_Tree_Item.H:238
Fl_Tree_Sort
Sort order options for items added to the tree.
Definition: Fl_Tree_Prefs.H:49
Fl_Tree_Select
Tree selection style.
Definition: Fl_Tree_Prefs.H:67
Tree widget.
Definition: Fl_Tree.H:310
int deselect_all()
Deselect item and all its children.
Definition: Fl_Tree_Item.H:272
Fl static class.
an item was selected
Definition: Fl_Tree.H:301
void open()
Open this item and all its children.
Definition: Fl_Tree_Item.cxx:833
void deselect()
Disable the item's selection state.
Definition: Fl_Tree_Item.H:265
Fl_Image is the base class used for caching and drawing all kinds of images in FLTK.
Definition: Fl_Image.H:44
int select_all()
Select item and all its children.
Definition: Fl_Tree_Item.H:253
void close()
Close this item and all its children.
Definition: Fl_Tree_Item.cxx:842
void draw()
Draws the widget.
Definition: Fl_Group.cxx:736
Fl_Boxtype
Definition: Enumerations.H:469
void clear()
Deletes all child widgets from memory recursively.
Definition: Fl_Group.cxx:381
Fl_Tree_Reason
The reason the callback was invoked.
Definition: Fl_Tree.H:299
Fl_Scrollbar * _vscroll
Vertical scrollbar.
Definition: Fl_Tree.H:329
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:456
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:36
an item was closed
Definition: Fl_Tree.H:307
void select_toggle()
Toggle the item's selection state.
Definition: Fl_Tree_Item.H:242
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:489
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:145
Fl_Tree_Item * insert_above(const Fl_Tree_Prefs &prefs, const char *new_label)
Insert a new item above this item.
Definition: Fl_Tree_Item.cxx:348
void clear_children()
Clear all the children for this item.
Definition: Fl_Tree_Item.cxx:166
Fl_Tree_Item * prev()
Return the previous item in the tree.
Definition: Fl_Tree_Item.cxx:903
Fl_Preferences provides methods to store user settings between application starts.
Definition: Fl_Preferences.H:60
Fl_Tree_Connector
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:228
Fl_Image * usericon() const
Get the item's user icon as an Fl_Image. Returns '0' if disabled.
Definition: Fl_Tree_Item.H:336
void open_toggle()
Toggle the item's open/closed state.
Definition: Fl_Tree_Item.H:232
const Fl_Tree_Item * find_item(char **arr) const
Find item by descending array of names.
Definition: Fl_Tree_Item.cxx:232
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
an item was de-selected
Definition: Fl_Tree.H:302
utility header to pull drawing functions together
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
Tree item.
Definition: Fl_Tree_Item.H:54
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
This file contains the definitions for Fl_Tree's preferences.
Tree widget's preferences.
Definition: Fl_Tree_Prefs.H:104
const Fl_Tree_Item * find_clicked(const Fl_Tree_Prefs &prefs) const
Find the item that the last event was over.
Definition: Fl_Tree_Item.cxx:478
This file contains the definitions for Fl_Tree_Item.
char is_selected() const
See if the item is selected.
Definition: Fl_Tree_Item.H:284
void show_self(const char *indent="") const
Print the tree as 'ascii art' to stdout.
Definition: Fl_Tree_Item.cxx:127
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:300
int is_open() const
See if the item is 'open'.
Definition: Fl_Tree_Item.H:224