Bringing over fix [r11840] from 1.3 current to the porting branch.

Solves STR#3294; added methods to let user set the userdeicon,
and removed the performance degrading automatic deicon creation.



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11841 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Greg Ercolano 2016-07-21 00:51:14 +00:00
parent aa5ac8656d
commit e92fa6914b
3 changed files with 69 additions and 20 deletions

View File

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

View File

@ -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);

View File

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