Skip to content

Commit

Permalink
Checked in SebHoll's API mods, fixed indents.
Browse files Browse the repository at this point in the history
	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
  • Loading branch information
erco77 committed Dec 8, 2009
1 parent 5bc4880 commit a657069
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 222 deletions.
77 changes: 40 additions & 37 deletions FL/Fl_Tree.H
Expand Up @@ -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.
///
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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").
Expand All @@ -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);
}
Expand All @@ -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".
Expand All @@ -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);
}
Expand Down Expand Up @@ -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").
Expand All @@ -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);
}
Expand All @@ -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").
Expand All @@ -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);
}
Expand Down Expand Up @@ -524,54 +527,54 @@ 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();
}
/// Returns the icon to be used as the 'open' icon.
/// 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();
}
/// Returns the icon to be used as the 'close' icon.
/// 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();
}
Expand Down
41 changes: 24 additions & 17 deletions FL/Fl_Tree_Item.H
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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.
Expand All @@ -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);
}
//////////////////
Expand Down
6 changes: 3 additions & 3 deletions FL/Fl_Tree_Item_Array.H
Expand Up @@ -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.
Expand Down

0 comments on commit a657069

Please sign in to comment.