summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Fl_Tree_Item.H47
-rw-r--r--src/Fl_Tree_Item.cxx6
-rw-r--r--test/tree.fl36
3 files changed, 69 insertions, 20 deletions
diff --git a/FL/Fl_Tree_Item.H b/FL/Fl_Tree_Item.H
index 456c0c9de..45cc4fd59 100644
--- a/FL/Fl_Tree_Item.H
+++ b/FL/Fl_Tree_Item.H
@@ -390,23 +390,52 @@ public:
}
int visible_r() const;
- /// Set the item's user icon to an Fl_Image. '0' will disable.
+ /// Set the item's user icon to an Fl_Image. Use '0' to disable.
+ /// No internal copy is made, caller must manage icon's memory.
+ ///
+ /// Note, if you expect your items to be deactivated(),
+ /// use userdeicon(Fl_Image*) to set up a 'grayed out' version of your icon
+ /// to be used for display.
+ ///
+ /// \see userdeicon(Fl_Image*)
+ ///
void usericon(Fl_Image *val) {
_usericon = val;
- // Update deactivated version of icon..
- if ( _userdeicon ) delete _userdeicon;
- if ( _usericon ) {
- _userdeicon = _usericon->copy();
- _userdeicon->inactive();
- } else {
- _userdeicon = 0;
- }
recalc_tree(); // may change tree geometry
}
/// Get the item's user icon as an Fl_Image. Returns '0' if disabled.
Fl_Image *usericon() const {
return(_usericon);
}
+ /// Set the usericon to draw when the item is deactivated. Use '0' to disable.
+ /// No internal copy is made; caller must manage icon's memory.
+ ///
+ /// To create a typical 'grayed out' version of your usericon image,
+ /// you can do the following:
+ ///
+ /// \code
+ /// // Create tree + usericon for items
+ /// Fl_Tree *tree = new Fl_Tree(..);
+ /// Fl_Image *usr_icon = new Fl_Pixmap(..); // your usericon
+ /// Fl_Image *de_icon = usr_icon->copy(); // make a copy, and..
+ /// de_icon->inactive(); // make it 'grayed out'
+ /// ...
+ /// for ( .. ) { // item loop..
+ /// item = tree->add("..."); // create new item
+ /// item->usericon(usr_icon); // assign usericon to items
+ /// item->userdeicon(de_icon); // assign userdeicon to items
+ /// ..
+ /// }
+ /// \endcode
+ ///
+ /// In the above example, the app should 'delete' the two icons
+ /// when they're no longer needed (e.g. after the tree is destroyed)
+ ///
+ /// \version 1.3.4
+ ///
+ void userdeicon(Fl_Image* val) {
+ _userdeicon = val;
+ }
/// Return the deactivated version of the user icon, if any.
/// Returns 0 if none.
Fl_Image* userdeicon() const {
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 3472f8e99..9b0239617 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -95,7 +95,7 @@ Fl_Tree_Item::~Fl_Tree_Item() {
}
_widget = 0; // Fl_Group will handle destruction
_usericon = 0; // user handled allocation
- if ( _userdeicon ) delete _userdeicon; // delete our copy (if any) for deactivated icon
+ _userdeicon = 0; // user handled allocation
// focus item? set to null
if ( _tree && this == _tree->_item_focus )
{ _tree->_item_focus = 0; }
@@ -1108,12 +1108,12 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
// Item has user icon? Use it
int uicon_y = item_y_center - (usericon()->h() >> 1);
if ( active ) usericon()->draw(uicon_x,uicon_y);
- else userdeicon()->draw(uicon_x,uicon_y);
+ else if ( userdeicon() ) userdeicon()->draw(uicon_x,uicon_y);
} else if ( render && prefs.usericon() ) {
// Prefs has user icon? Use it
int uicon_y = item_y_center - (prefs.usericon()->h() >> 1);
if ( active ) prefs.usericon()->draw(uicon_x,uicon_y);
- else prefs.userdeicon()->draw(uicon_x,uicon_y);
+ else if ( prefs.userdeicon() ) prefs.userdeicon()->draw(uicon_x,uicon_y);
}
// Draw item's content
xmax = draw_item_content(render);
diff --git a/test/tree.fl b/test/tree.fl
index 8fb93fb8b..d1f253ba3 100644
--- a/test/tree.fl
+++ b/test/tree.fl
@@ -98,7 +98,7 @@ Function {AssignUserIcons()} {
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@@@@@@@@@@@"};
-static Fl_Pixmap L_folderpixmap(L_folder_xpm);
+static Fl_Pixmap L_folder_pixmap(L_folder_xpm);
static const char *L_document_xpm[] = {
"11 11 3 1",
@@ -116,18 +116,38 @@ static const char *L_document_xpm[] = {
".@xxxxxxx@.",
".@xxxxxxx@.",
".@@@@@@@@@."};
-static Fl_Pixmap L_documentpixmap(L_document_xpm);
+static Fl_Pixmap L_document_pixmap(L_document_xpm);
+
+// Create deactivated version of document icon
+static Fl_Pixmap L_folder_deicon_pixmap(L_folder_xpm); // copy
+static Fl_Pixmap L_document_deicon_pixmap(L_document_xpm); // copy
+static int first = 1;
+if ( first ) {
+ L_folder_deicon_pixmap.inactive();
+ L_document_deicon_pixmap.inactive();
+ first = 0;
+}
// Assign user icons to tree items
-for ( Fl_Tree_Item *item = tree->first(); item; item=item->next())
- if ( usericon_radio->value() )
+for ( Fl_Tree_Item *item = tree->first(); item; item=item->next()) {
+ if ( usericon_radio->value() ) {
// Assign custom icons
- item->usericon(item->has_children() ? &L_folderpixmap : &L_documentpixmap);
- else
+ if ( item->has_children() ) {
+ item->usericon(&L_folder_pixmap);
+ item->userdeicon(&L_folder_deicon_pixmap);
+ } else {
+ item->usericon(&L_document_pixmap);
+ item->userdeicon(&L_document_deicon_pixmap);
+ }
+ } else {
// Don't assign custom icons
item->usericon(0);
-tree->redraw();} {}
+ item->userdeicon(0);
+ }
+}
+tree->redraw();} {selected
+ }
}
Function {RebuildTree()} {
@@ -1233,7 +1253,7 @@ If none are selected, all are set.} xywh {758 134 100 16} selection_color 1 labe
callback {if ( deactivate_tree_toggle->value() )
tree->deactivate();
else
- tree->activate();} selected
+ tree->activate();}
tooltip {Deactivates the entire tree widget} xywh {758 154 100 16} selection_color 1 labelsize 9
}
Fl_Light_Button bold_toggle {