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@11840 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Greg Ercolano 2016-07-21 00:35:06 +00:00
parent d8676e6f4c
commit 2bb2192dd3
3 changed files with 79 additions and 25 deletions

View File

@ -425,26 +425,53 @@ 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;
#if FLTK_ABI_VERSION >= 10304
// Update deactivated version of icon..
if ( _userdeicon ) delete _userdeicon;
if ( _usericon ) {
_userdeicon = _usericon->copy();
_userdeicon->inactive();
} else {
_userdeicon = 0;
}
#endif
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
///
#if FLTK_ABI_VERSION >= 10304
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

@ -115,7 +115,7 @@ Fl_Tree_Item::~Fl_Tree_Item() {
_widget = 0; // Fl_Group will handle destruction
_usericon = 0; // user handled allocation
#if FLTK_ABI_VERSION >= 10304
if ( _userdeicon ) delete _userdeicon; // delete our copy (if any) for deactivated icon
_userdeicon = 0; // user handled allocation
#endif
#if FLTK_ABI_VERSION >= 10303
// focus item? set to null
@ -1206,12 +1206,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);
}
#else
if ( render && usericon() ) {
@ -1441,12 +1441,12 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
// 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 ( 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 ( userdeicon() ) prefs.userdeicon()->draw(uicon_x,uicon_y);
}
#else
if ( usericon() ) {

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,45 @@ 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);
\#if FLTK_ABI_VERSION >= 10304
// 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;
}
\#endif
// 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);
\#if FLTK_ABI_VERSION >= 10304
item->userdeicon(&L_folder_deicon_pixmap);
\#endif
} else {
item->usericon(&L_document_pixmap);
\#if FLTK_ABI_VERSION >= 10304
item->userdeicon(&L_document_deicon_pixmap);
\#endif
}
} else {
// Don't assign custom icons
item->usericon(0);
tree->redraw();} {}
\#if FLTK_ABI_VERSION >= 10304
item->userdeicon(0);
\#endif
}
}
tree->redraw();} {selected
}
}
Function {RebuildTree()} {
@ -1233,7 +1260,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 {