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
This commit is contained in:
Greg Ercolano 2009-12-08 08:06:44 +00:00
parent 5bc48808b6
commit a657069cc5
8 changed files with 251 additions and 222 deletions

View File

@ -106,7 +106,7 @@ class Fl_Tree : public Fl_Group {
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.
@ -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();
}

View File

@ -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();
@ -87,6 +88,12 @@ public:
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) {
_labelfont = val;
@ -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);
}
//////////////////

View File

@ -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.

View File

@ -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;
}
////////////////////////////

View File

@ -123,6 +123,18 @@ Fl_Tree_Item* Fl_Tree::insert_above(Fl_Tree_Item *above, const char *name) {
return(above->insert_above(_prefs, name));
}
/// Insert a new item into a tree-item's children at a specified position.
/// \returns the item that was added.
Fl_Tree_Item* Fl_Tree::insert(Fl_Tree_Item *item, const char *name, int pos) {
return(item->insert(_prefs, name, pos));
}
/// Add a new child to a tree-item.
/// \returns the item that was added.
Fl_Tree_Item* Fl_Tree::add(Fl_Tree_Item *item, const char *name) {
return(item->add(_prefs, name));
}
/// Find the item, given a menu style path, eg: "/Parent/Child/item".
///
/// There is both a const and non-const version of this method.
@ -226,6 +238,7 @@ int Fl_Tree::handle(int e) {
callback() &&
(!_vscroll->visible() || !Fl::event_inside(_vscroll)) ) {
item_clicked(o); // save item clicked
// Handle selection behavior
switch ( _prefs.selectmode() ) {
case FL_TREE_SELECT_NONE: { // no selection changes
@ -252,6 +265,7 @@ int Fl_Tree::handle(int e) {
break;
}
}
if ( changed ) {
redraw(); // make change(s) visible
if ( when() & FL_WHEN_CHANGED ) {

View File

@ -103,6 +103,7 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) {
_label_xywh[2] = o->_label_xywh[2];
_label_xywh[3] = o->_label_xywh[3];
_usericon = o->usericon();
_userdata = 0;
_parent = o->_parent;
}
@ -467,7 +468,9 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
const Fl_Tree_Prefs &prefs, int lastchild) {
if ( ! _visible ) return;
fl_font(_labelfont, _labelsize);
int H = _labelsize + fl_descent() + prefs.linespacing();
int H = _labelsize;
if(usericon() && H < usericon()->h()) H = usericon()->h();
H += prefs.linespacing() + fl_descent();
// Colors, fonts
Fl_Color fg = _selected ? prefs.bgcolor() : _labelfgcolor;
Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor;
@ -528,7 +531,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
int &bx = _label_xywh[0] = X+(icon_w/2-1+prefs.connectorwidth());
int &by = _label_xywh[1] = Y;
int &bw = _label_xywh[2] = W-(icon_w/2-1+prefs.connectorwidth());
int &bh = _label_xywh[3] = texth;
int &bh = _label_xywh[3] = H;
// Draw bg only if different from tree's bg
if ( bg != tree->color() || is_selected() ) {
if ( is_selected() ) {
@ -545,11 +548,13 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
if ( usericon() ) {
// Item has user icon? Use it
useroff += prefs.usericonmarginleft();
icon_y = textycenter - (usericon()->h() >> 1);
usericon()->draw(X+useroff,icon_y);
useroff += usericon()->w();
} else if ( prefs.usericon() ) {
// Prefs has user icon? Use it
useroff += prefs.usericonmarginleft();
icon_y = textycenter - (prefs.usericon()->h() >> 1);
prefs.usericon()->draw(X+useroff,icon_y);
useroff += prefs.usericon()->w();
}

View File

@ -73,19 +73,19 @@ static Fl_Pixmap L_closepixmap(L_close_xpm);
/// when items are add()ed to the tree.
/// 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 Fl_Tree_Prefs::openicon(Fl_Pixmap *val) {
_openpixmap = val ? val : &L_openpixmap;
void Fl_Tree_Prefs::openicon(Fl_Image *val) {
_openimage = val ? val : &L_openpixmap;
}
/// 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 Fl_Tree_Prefs::closeicon(Fl_Pixmap *val) {
_closepixmap = val ? val : &L_closepixmap;
void Fl_Tree_Prefs::closeicon(Fl_Image *val) {
_closeimage = val ? val : &L_closepixmap;
}
/// Fl_Tree_Prefs constructor
@ -106,9 +106,9 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_inactivecolor = FL_GRAY;
_connectorcolor = Fl_Color(43);
_connectorstyle = FL_TREE_CONNECTOR_DOTTED;
_openpixmap = &L_openpixmap;
_closepixmap = &L_closepixmap;
_userpixmap = 0;
_openimage = &L_openpixmap;
_closeimage = &L_closepixmap;
_userimage = 0;
_showcollapse = 1;
_showroot = 1;
_connectorwidth = 17;