summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2009-12-08 08:06:44 +0000
committerGreg Ercolano <erco@seriss.com>2009-12-08 08:06:44 +0000
commita657069cc53cc05245762e9323efa040a9f70da2 (patch)
treec007a095998f8a4d20ed4359eb7174803c4f8784 /FL
parent5bc48808b6aed5469c3e62e1402e10c797a5d02a (diff)
Checked in SebHoll's API mods, fixed indents.
o Added user_data() to Fl_Tree_Item o Added insert() and add() methods that allow specification of Fl_Tree_Prefs o Changed Fl_Pixmap args to Fl_Image for more flexibility o Fixes for positioning of items in the presence of user icons o find_children() changed from protected -> public git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6956 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl_Tree.H77
-rw-r--r--FL/Fl_Tree_Item.H41
-rw-r--r--FL/Fl_Tree_Item_Array.H6
-rw-r--r--FL/Fl_Tree_Prefs.H40
4 files changed, 87 insertions, 77 deletions
diff --git a/FL/Fl_Tree.H b/FL/Fl_Tree.H
index 68d40bb02..00d92e88e 100644
--- a/FL/Fl_Tree.H
+++ b/FL/Fl_Tree.H
@@ -101,12 +101,12 @@
///
class Fl_Tree : public Fl_Group {
- Fl_Tree_Item *_root; // can be null!
+ Fl_Tree_Item *_root; // can be null!
Fl_Tree_Item *_item_clicked;
- Fl_Tree_Prefs _prefs; // all the tree's settings
+ Fl_Tree_Prefs _prefs; // all the tree's settings
Fl_Scrollbar *_vscroll;
-protected:
+public:
/// Find the item that was clicked.
/// You probably want to use item_clicked() instead, which is fast.
///
@@ -122,6 +122,7 @@ protected:
if ( ! _root ) return(0);
return(_root->find_clicked(_prefs));
}
+protected:
/// Set the item that was last clicked.
/// Should only be used by subclasses needing to change this value.
/// Normally Fl_Tree manages this value.
@@ -157,7 +158,9 @@ public:
// Item creation/removal methods
////////////////////////////////
Fl_Tree_Item *add(const char *path);
+ Fl_Tree_Item* add(Fl_Tree_Item *item, const char *name);
Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
+ Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
/// Remove the specified 'item' from the tree.
/// If it has children, all those are removed too.
@@ -166,11 +169,11 @@ public:
int remove(Fl_Tree_Item *item) {
if ( !item ) return(0);
if ( item == _root ) {
- clear();
+ clear();
} else {
- Fl_Tree_Item *parent = item->parent(); // find item's parent
- if ( ! parent ) return(-1);
- parent->remove_child(item); // remove child + children
+ Fl_Tree_Item *parent = item->parent(); // find item's parent
+ if ( ! parent ) return(-1);
+ parent->remove_child(item); // remove child + children
}
return(0);
}
@@ -185,8 +188,8 @@ public:
/// Clear all the children of a particular node in the tree.
void clear_children(Fl_Tree_Item *item) {
if ( item->has_children() ) {
- item->clear_children();
- redraw(); // redraw only if there were children to clear
+ item->clear_children();
+ redraw(); // redraw only if there were children to clear
}
}
@@ -242,7 +245,7 @@ public:
if ( ! _root ) return(0);
Fl_Tree_Item *item = _root;
while ( item->has_children() ) {
- item = item->child(item->children()-1);
+ item = item->child(item->children()-1);
}
return(item);
}
@@ -257,8 +260,8 @@ public:
///
void open(Fl_Tree_Item *item) {
if ( ! item->is_open() ) {
- item->open();
- redraw();
+ item->open();
+ redraw();
}
}
/// Opens the item specified by a 'menu item' style pathname (eg: "Parent/child/item").
@@ -272,8 +275,8 @@ public:
int open(const char *path) {
Fl_Tree_Item *item = find_item(path);
if ( item ) {
- open(item);
- return(0);
+ open(item);
+ return(0);
}
return(-1);
}
@@ -282,8 +285,8 @@ public:
///
void close(Fl_Tree_Item *item) {
if ( ! item->is_close() ) {
- item->close();
- redraw();
+ item->close();
+ redraw();
}
}
/// Closes the item specified by 'path', eg: "Parent/child/item".
@@ -297,8 +300,8 @@ public:
int close(const char *path) {
Fl_Tree_Item *item = find_item(path);
if ( item ) {
- close(item);
- return(0);
+ close(item);
+ return(0);
}
return(-1);
}
@@ -359,8 +362,8 @@ public:
///
void select(Fl_Tree_Item *item) {
if ( ! item->is_selected() ) {
- item->select();
- redraw();
+ item->select();
+ redraw();
}
}
/// Select an item specified by 'path' (eg: "Parent/child/item").
@@ -373,8 +376,8 @@ public:
int select(const char *path) {
Fl_Tree_Item *item = find_item(path);
if ( item ) {
- select(item);
- return(0);
+ select(item);
+ return(0);
}
return(-1);
}
@@ -390,8 +393,8 @@ public:
///
void deselect(Fl_Tree_Item *item) {
if ( item->is_selected() ) {
- item->deselect();
- redraw();
+ item->deselect();
+ redraw();
}
}
/// De-select an item specified by 'path' (eg: "Parent/child/item").
@@ -404,8 +407,8 @@ public:
int deselect(const char *path) {
Fl_Tree_Item *item = find_item(path);
if ( item ) {
- deselect(item);
- return(0);
+ deselect(item);
+ return(0);
}
return(-1);
}
@@ -524,22 +527,22 @@ public:
_prefs.connectorwidth(val);
redraw();
}
- /// Returns the Fl_Pixmap being used as the default user icon for newly created items.
+ /// Returns the Fl_Image being used as the default user icon for newly created items.
/// Returns zero if no icon has been set, which is the default.
///
- Fl_Pixmap *usericon() const {
+ Fl_Image *usericon() const {
return(_prefs.usericon());
}
- /// Sets the Fl_Pixmap to be used as the default user icon for all
+ /// Sets the Fl_Image to be used as the default user icon for all
/// newly created items.
///
/// If you want to specify user icons on a per-item basis,
/// use Fl_Tree_Item::usericon() instead.
///
- /// \param[in] val -- The new pixmap to be used, or
+ /// \param[in] val -- The new image to be used, or
/// zero to disable user icons.
///
- void usericon(Fl_Pixmap *val) {
+ void usericon(Fl_Image *val) {
_prefs.usericon(val);
redraw();
}
@@ -547,15 +550,15 @@ public:
/// If none was set, the internal default is returned,
/// a simple '[+]' icon.
///
- Fl_Pixmap *openicon() const {
+ Fl_Image *openicon() const {
return(_prefs.openicon());
}
/// Sets the icon to be used as the 'open' icon.
/// This overrides the built in default '[+]' icon.
///
- /// \param[in] val -- The new pixmap, or zero to use the default [+] icon.
+ /// \param[in] val -- The new image, or zero to use the default [+] icon.
///
- void openicon(Fl_Pixmap *val) {
+ void openicon(Fl_Image *val) {
_prefs.openicon(val);
redraw();
}
@@ -563,15 +566,15 @@ public:
/// If none was set, the internal default is returned,
/// a simple '[-]' icon.
///
- Fl_Pixmap *closeicon() const {
+ Fl_Image *closeicon() const {
return(_prefs.closeicon());
}
/// Sets the icon to be used as the 'close' icon.
/// This overrides the built in default '[-]' icon.
///
- /// \param[in] val -- The new pixmap, or zero to use the default [-] icon.
+ /// \param[in] val -- The new image, or zero to use the default [-] icon.
///
- void closeicon(Fl_Pixmap *val) {
+ void closeicon(Fl_Image *val) {
_prefs.closeicon(val);
redraw();
}
diff --git a/FL/Fl_Tree_Item.H b/FL/Fl_Tree_Item.H
index 55023d38b..674955cd4 100644
--- a/FL/Fl_Tree_Item.H
+++ b/FL/Fl_Tree_Item.H
@@ -7,7 +7,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
-#include <FL/Fl_Pixmap.H>
+#include <FL/Fl_Image.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Tree_Item_Array.H>
@@ -70,9 +70,10 @@ class Fl_Tree_Item {
int _collapse_xywh[4]; // xywh of collapse icon (if any)
int _label_xywh[4]; // xywh of label
Fl_Widget *_widget; // item's label widget (optional)
- Fl_Pixmap *_usericon; // item's user-specific icon (optional)
+ Fl_Image *_usericon; // item's user-specific icon (optional)
Fl_Tree_Item_Array _children; // array of child items
Fl_Tree_Item *_parent; // parent item (=0 if root)
+ void *_userdata; // user data that can be associated with an item
protected:
void show_widgets();
void hide_widgets();
@@ -81,11 +82,17 @@ protected:
public:
Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR
~Fl_Tree_Item(); // DTOR
- Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR
+ Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR
void draw(int X, int &Y, int W, Fl_Widget *tree, const Fl_Tree_Prefs &prefs, int lastchild=1);
void show_self(const char *indent = "") const;
void label(const char *val);
const char *label() const;
+
+ /// Set a user-data value for the item.
+ inline void user_data( void* data ) { _userdata = data; }
+
+ /// Retrieve the user-data value that has been assigned to the item.
+ inline void* user_data() const { return _userdata; }
/// Set item's label font face.
void labelfont(int val) {
@@ -209,9 +216,9 @@ public:
/// Toggle the item's selection state.
void select_toggle() {
if ( is_selected() ) {
- deselect(); // deselect if selected
+ deselect(); // deselect if selected
} else {
- select(); // select if deselected
+ select(); // select if deselected
}
}
/// Disable the item's selection state.
@@ -225,11 +232,11 @@ public:
int deselect_all() {
int count = 0;
if ( is_selected() ) {
- deselect();
- ++count;
+ deselect();
+ ++count;
}
for ( int t=0; t<children(); t++ ) {
- count += child(t)->deselect_all();
+ count += child(t)->deselect_all();
}
return(count);
}
@@ -249,12 +256,12 @@ public:
void activate(int val=1) {
_active = val;
if ( _widget && val != (int)_widget->active() ) {
- if ( val ) {
- _widget->activate();
- } else {
- _widget->deactivate();
- }
- _widget->redraw();
+ if ( val ) {
+ _widget->activate();
+ } else {
+ _widget->deactivate();
+ }
+ _widget->redraw();
}
}
/// Deactivate the item; the callback() won't be invoked when clicked.
@@ -271,12 +278,12 @@ public:
char is_active() const {
return(_active);
}
- /// Set the user icon's pixmap. '0' will disable.
- void usericon(Fl_Pixmap *val) {
+ /// Set the user icon's image. '0' will disable.
+ void usericon(Fl_Image *val) {
_usericon = val;
}
/// Get the user icon. Returns '0' if disabled.
- Fl_Pixmap *usericon() const {
+ Fl_Image *usericon() const {
return(_usericon);
}
//////////////////
diff --git a/FL/Fl_Tree_Item_Array.H b/FL/Fl_Tree_Item_Array.H
index 68e34db28..19a28b4dc 100644
--- a/FL/Fl_Tree_Item_Array.H
+++ b/FL/Fl_Tree_Item_Array.H
@@ -6,11 +6,11 @@
#define _FL_TREE_ITEM_ARRAY_H
class Fl_Tree_Item; // forward decl must *precede* first doxygen comment block
-// or doxygen will not document our class..
+ // or doxygen will not document our class..
-//////////////////////
+//////////////////////////
// FL/Fl_Tree_Item_Array.H
-//////////////////////
+//////////////////////////
//
// Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
// Copyright (C) 2009 by Greg Ercolano.
diff --git a/FL/Fl_Tree_Prefs.H b/FL/Fl_Tree_Prefs.H
index 7d9f2521a..05e2eef6e 100644
--- a/FL/Fl_Tree_Prefs.H
+++ b/FL/Fl_Tree_Prefs.H
@@ -88,11 +88,11 @@ class Fl_Tree_Prefs {
int _margintop; // --
int _marginleft; // |- tree's margins
//int _marginright; // |
- //int _marginbottom; // --
- int _openchild_marginbottom; // extra space below an open child tree
+ //int _marginbottom; // --
+ int _openchild_marginbottom; // extra space below an open child tree
int _usericonmarginleft; // space to left of user icon (if any)
- int _labelmarginleft; // space to left of label
- int _connectorwidth; // connector width (right of open/close icon)
+ int _labelmarginleft; // space to left of label
+ int _connectorwidth; // connector width (right of open/close icon)
int _linespacing; // vertical space between lines
// Colors
Fl_Color _fgcolor; // label's foreground color
@@ -101,9 +101,9 @@ class Fl_Tree_Prefs {
Fl_Color _inactivecolor; // inactive color
Fl_Color _connectorcolor; // connector dotted line color
Fl_Tree_Connector _connectorstyle; // connector line style
- Fl_Pixmap *_openpixmap; // the 'open' icon [+]
- Fl_Pixmap *_closepixmap; // the 'close' icon [-]
- Fl_Pixmap *_userpixmap; // user's own icon
+ Fl_Image *_openimage; // the 'open' icon [+]
+ Fl_Image *_closeimage; // the 'close' icon [-]
+ Fl_Image *_userimage; // user's own icon
char _showcollapse; // 1=show collapse icons, 0=don't
char _showroot; // show the root item as part of the tree
Fl_Tree_Sort _sortorder; // none, ascening, descending, etc.
@@ -268,28 +268,28 @@ public:
// Icons
////////////////////////////
/// Get the current default 'open' icon.
- /// Returns the Fl_Pixmap* of the icon, or 0 if none.
+ /// Returns the Fl_Image* of the icon, or 0 if none.
///
- inline Fl_Pixmap *openicon() const {
- return(_openpixmap);
+ inline Fl_Image *openicon() const {
+ return(_openimage);
}
- void openicon(Fl_Pixmap *val);
+ void openicon(Fl_Image *val);
/// Gets the default 'close' icon
- /// Returns the Fl_Pixmap* of the icon, or 0 if none.
+ /// Returns the Fl_Image* of the icon, or 0 if none.
///
- inline Fl_Pixmap *closeicon() const {
- return(_closepixmap);
+ inline Fl_Image *closeicon() const {
+ return(_closeimage);
}
- void closeicon(Fl_Pixmap *val);
+ void closeicon(Fl_Image *val);
/// Gets the default 'user icon' (default is 0)
- inline Fl_Pixmap *usericon() const {
- return(_userpixmap);
+ inline Fl_Image *usericon() const {
+ return(_userimage);
}
/// Sets the default 'user icon'
- /// Returns the Fl_Pixmap* of the icon, or 0 if none (default).
+ /// Returns the Fl_Image* of the icon, or 0 if none (default).
///
- inline void usericon(Fl_Pixmap *val) {
- _userpixmap = val;
+ inline void usericon(Fl_Image *val) {
+ _userimage = val;
}
////////////////////////////