diff options
| author | Greg Ercolano <erco@seriss.com> | 2013-12-15 18:59:02 +0000 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2013-12-15 18:59:02 +0000 |
| commit | d36882e67e2276a44336a63e498c46a73d21fcb6 (patch) | |
| tree | 519d7c91d077dce9dd1b21e20a7354a2a09f9658 /FL/Fl_Tree_Item.H | |
| parent | 6bf1ddf2b1fcc62fa52007e477a848fc2518b4ba (diff) | |
Adds horizontal scrollbar to Fl_Tree as an ABI 1.3.3 feature.
***************************************************************
NOTE: You MUST uncomment the FLTK_ABI_VERSION in Enumerations.H
to use these changes.
***************************************************************
Also: separated tree size calculation from draw() code,
so that one can cause the tree to recalculate immediately
after making modifications to the tree by calling Fl_Tree::calc_tree().
Numerous improvements to docs for the tree as well, enough
to create a rather large diff.
Large internal changes were needed to do this properly.
The following was added to the CHANGES file:
- Fl_Tree: various related changes:
o Added horizontal scrollbar
o Separated draw() and tree size calculation
o Added new public methods:
> resize() -- uses optimized dim calc, avoids tree recalc
> next_item() -- added parameters: direction, visibility
> extend_selection() -- added parameters, improved algorithm
> calc_dimensions() -- calc tix/y/w/h, tox/y/w/h and scrollbars
> calc_tree() -- calc tree_w/tree_h
> recalc_tree() -- schedules calc_tree()
> first_visible_item(), last_visible_item(), next_visible_item()
> first_selected_item(), last_selected_item(), next_selected_item()
o Added protected variables:
> _tix/y/w/h -- tree widget 'inner' dimension
> _tox/y/w/h -- tree widget 'outer' dimension
> _tree_w,_tree_h -- entire tree hierarchy width/height
o Deprecated:
> item_clicked() -- use callback_item() instead
> first_visible() -- use first_visible_item() instead
> last_visible() -- use last_visible_item() instead
- Fl_Tree_Item: various related changes:
o Added Fl_Tree ptr: needed for auto-recalc when item modified directly
o Added new methods tree(), recalc_tree()
o Added new ctor that accepts Fl_Tree*
o draw() parameters changed to include tree size calculations
o Deprecated:
> ctor using Fl_Tree_Prefs parameter (Fl_Tree* version better,
and must be used for 1.3.3 ABI features to work correctly)
> next_displayed() -- use next_visible() instead
> prev_displayed() -- use prev_visible() instead
- test/tree: added tests for newly added features
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10034 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL/Fl_Tree_Item.H')
| -rw-r--r-- | FL/Fl_Tree_Item.H | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/FL/Fl_Tree_Item.H b/FL/Fl_Tree_Item.H index 81c73fd64..b51d90907 100644 --- a/FL/Fl_Tree_Item.H +++ b/FL/Fl_Tree_Item.H @@ -36,7 +36,8 @@ /// \brief This file contains the definitions for Fl_Tree_Item /// -/// \brief Tree item +/// \class Fl_Tree_Item +/// \brief Tree widget item. /// /// This class is a single tree item, and manages all of the item's attributes. /// Fl_Tree_Item is used by Fl_Tree, which is comprised of many instances of Fl_Tree_Item. @@ -51,13 +52,23 @@ /// When you make changes to items, you'll need to tell the tree to redraw() /// for the changes to show up. /// +class Fl_Tree; class FL_EXPORT Fl_Tree_Item { +#if FLTK_ABI_VERSION >= 10303 + Fl_Tree *_tree; // parent tree +#endif const char *_label; // label (memory managed) Fl_Font _labelfont; // label's font face Fl_Fontsize _labelsize; // label's font size Fl_Color _labelfgcolor; // label's fg color Fl_Color _labelbgcolor; // label's bg color (0xffffffff is 'transparent') +#if FLTK_ABI_VERSION >= 10303 + /// \enum Fl_Tree_Item_Flags + enum Fl_Tree_Item_Flags { +#else + /// \enum enum { +#endif OPEN = 1<<0, ///> item is open VISIBLE = 1<<1, ///> item is visible ACTIVE = 1<<2, ///> item is active @@ -86,12 +97,18 @@ class FL_EXPORT Fl_Tree_Item { Fl_Tree_Item *_next_sibling; // next sibling (same level) #endif /*FLTK_ABI_VERSION*/ protected: + void _Init(const Fl_Tree_Prefs &prefs, Fl_Tree *tree); void show_widgets(); void hide_widgets(); void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs); void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs); + void recalc_tree(); + const Fl_Tree_Item* find_clicked_(const Fl_Tree_Prefs &prefs, int yonly=0) const; // internal public: - Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR + Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR -- backwards compatible +#if FLTK_ABI_VERSION >= 10303 + Fl_Tree_Item(Fl_Tree *tree); // CTOR -- ABI 1.3.3+ +#endif ~Fl_Tree_Item(); // DTOR Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR int x() const { return(_xywh[0]); } @@ -103,7 +120,12 @@ public: int label_w() const { return(_label_xywh[2]); } int label_h() const { return(_label_xywh[3]); } int calc_item_height(const Fl_Tree_Prefs &prefs) const; +#if FLTK_ABI_VERSION >= 10303 + void draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus, + int &tree_item_xmax, int lastchild=1, int render=1); +#else void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1); +#endif void show_self(const char *indent = "") const; void label(const char *val); const char *label() const; @@ -117,6 +139,7 @@ public: /// Set item's label font face. void labelfont(Fl_Font val) { _labelfont = val; + recalc_tree(); // may change tree geometry } /// Get item's label font face. Fl_Font labelfont() const { @@ -125,6 +148,7 @@ public: /// Set item's label font size. void labelsize(Fl_Fontsize val) { _labelsize = val; + recalc_tree(); // may change tree geometry } /// Get item's label font size. Fl_Fontsize labelsize() const { @@ -159,6 +183,7 @@ public: /// Assign an FLTK widget to this item. void widget(Fl_Widget *val) { _widget = val; + recalc_tree(); // may change tree geometry } /// Return FLTK widget assigned to this item. Fl_Widget *widget() const { @@ -202,8 +227,10 @@ public: Fl_Tree_Item *next_sibling(); Fl_Tree_Item *prev_sibling(); void update_prev_next(int index); - Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs); - Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs); + Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs); // deprecated + Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs); // deprecated + Fl_Tree_Item *next_visible(Fl_Tree_Prefs &prefs); + Fl_Tree_Item *prev_visible(Fl_Tree_Prefs &prefs); /// Return the parent for this item. Returns NULL if we are the root. Fl_Tree_Item *parent() { @@ -219,6 +246,12 @@ public: void parent(Fl_Tree_Item *val) { _parent = val; } +#if FLTK_ABI_VERSION >= 10303 + /// Return the tree for this item. + const Fl_Tree *tree() const { + return(_tree); + } +#endif ////////////////// // State ////////////////// @@ -234,7 +267,7 @@ public: } /// Toggle the item's open/closed state. void open_toggle() { - is_open()?close():open(); + is_open()?close():open(); // handles calling recalc_tree() } /// Change the item's selection state to the optionally specified 'val'. /// If 'val' is not specified, the item will be selected. @@ -335,6 +368,7 @@ public: /// Set the item's user icon to an Fl_Image. '0' will disable. void usericon(Fl_Image *val) { _usericon = val; + recalc_tree(); // may change tree geometry } /// Get the item's user icon as an Fl_Image. Returns '0' if disabled. Fl_Image *usericon() const { @@ -343,8 +377,8 @@ public: ////////////////// // Events ////////////////// - const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs) const; - Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs); + const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs, int yonly=0) const; + Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs, int yonly=0); int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const; int event_on_label(const Fl_Tree_Prefs &prefs) const; /// Is this item the root of the tree? @@ -357,6 +391,9 @@ protected: #if FLTK_ABI_VERSION >= 10301 /// Set a flag to an on or off value. val is 0 or 1. inline void set_flag(unsigned short flag,int val) { + if ( flag==OPEN || flag==VISIBLE ) { + recalc_tree(); // may change tree geometry + } if ( val ) _flags |= flag; else _flags &= ~flag; } /// See if flag set. Returns 0 or 1. |
