summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx50
-rw-r--r--src/Fl_Tree_Item.cxx78
-rw-r--r--src/Fl_Tree_Prefs.cxx4
3 files changed, 96 insertions, 36 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index ba37dab3f..455aba716 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -936,7 +936,7 @@ Fl_Tree_Item *Fl_Tree::next_selected_item(Fl_Tree_Item *item) {
/// ..do stuff with each selected item..
/// }
/// \endcode
-/// \param[in] items The returned array of selected items.
+/// \param[in] ret_items The returned array of selected items.
/// \returns The number of items in the returned array.
/// \see first_selected_item(), next_selected_item()
///
@@ -1787,7 +1787,9 @@ Fl_Tree_Item_Reselect_Mode Fl_Tree::item_reselect_mode() const {
void Fl_Tree::item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
_prefs.item_reselect_mode(mode);
}
+#endif
+#if FLTK_ABI_VERSION >= 10303
/// Get the 'item draw mode' used for the tree
Fl_Tree_Item_Draw_Mode Fl_Tree::item_draw_mode() const {
return(_prefs.item_draw_mode());
@@ -1804,7 +1806,51 @@ void Fl_Tree::item_draw_mode(Fl_Tree_Item_Draw_Mode val) {
void Fl_Tree::item_draw_mode(int val) {
_prefs.item_draw_mode(Fl_Tree_Item_Draw_Mode(val));
}
-#endif /*FLTK_ABI_VERSION*/
+
+/// Set a callback to be invoked to handle drawing the Fl_Tree_Item
+/// instead of the default label drawing behavior. Lets one define
+/// custom drawing behavior for Fl_Tree_Item's. eg:
+/// \code
+/// static void draw_item(Fl_Tree_Item *item, void *data) {
+/// Fl_Tree *tree = (Fl_Tree*)data;
+/// int X=item->label_x(), Y=item->label_y(),
+/// W=item->label_w(), H=item->label_h();
+/// // Draw the background
+/// fl_color(item->is_selected() ? tree->selection_color() : item->labelbgcolor());
+/// fl_rectf(X,Y,W,H);
+/// // Draw text
+/// fl_font(item->labelfont(), item->labelsize());
+/// fl_color(item->labelfgcolor());
+/// fl_draw("Some text", X+tree->labelmarginleft(),Y,W,H, FL_ALIGN_LEFT);
+/// }
+/// ..
+/// int main() {
+/// Fl_Tree *tree = new Fl_Tree(0,0,100,100);
+/// tree->item_draw_callback(draw_item, (void*)tree);
+/// [..]
+/// \endcode
+///
+/// Note: This only affects the drawing of item's labels;
+/// it does not affect the drawing of widgets assigned with
+/// Fl_Tree_Item::widget().
+///
+void Fl_Tree::item_draw_callback(Fl_Tree_Item_Draw_Callback *cb, void *data) {
+ _prefs.item_draw_callback(cb,data);
+}
+/// Get the current item draw callback. Returns 0 if none.
+Fl_Tree_Item_Draw_Callback* Fl_Tree::item_draw_callback() const {
+ return(_prefs.item_draw_callback());
+}
+/// Get the current item draw callback's user data.
+void* Fl_Tree::item_draw_user_data() const {
+ return(_prefs.item_draw_user_data());
+}
+/// Invoke the configured item_draw_callback().
+// Do NOT call this if no item_draw_callback() was configured.
+void Fl_Tree::do_item_draw_callback(Fl_Tree_Item *o) const {
+ _prefs.do_item_draw_callback(o);
+}
+#endif
/// See if \p item is currently displayed on-screen (visible within the widget).
/// This can be used to detect if the item is scrolled off-screen.
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index daccbdbde..2bbbb107c 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -529,7 +529,7 @@ Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs) {
return(0);
}
-static void draw_item_focus(Fl_Boxtype B, Fl_Color C, int X, int Y, int W, int H) {
+static void draw_item_focus(Fl_Boxtype B, Fl_Color fg, Fl_Color bg, int X, int Y, int W, int H) {
if (!Fl::visible_focus()) return;
switch (B) {
case FL_DOWN_BOX:
@@ -541,7 +541,7 @@ static void draw_item_focus(Fl_Boxtype B, Fl_Color C, int X, int Y, int W, int H
default:
break;
}
- fl_color(fl_contrast(FL_BLACK, C));
+ fl_color(fl_contrast(fg, bg));
#if defined(USE_X11) || defined(__APPLE_QUARTZ__)
fl_line_style(FL_DOT);
@@ -719,41 +719,51 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
prefs.openicon()->draw(icon_x,icon_y);
}
}
- // Background for this item
- // Draw bg only if different from tree's bg
- if ( bg != tree->color() || is_selected() ) {
- if ( is_selected() ) { // Selected? Use selectbox() style
- fl_draw_box(prefs.selectbox(),bg_x,bg_y,bg_w,bg_h,bg);
- } else { // Not Selected? use plain filled rectangle
- fl_color(bg);
- fl_rectf(bg_x,bg_y,bg_w,bg_h);
+ // Draw the item
+#if FLTK_ABI_VERSION >= 10303
+ if ( !widget() && prefs.item_draw_callback() ) {
+ // Draw item using user supplied custom item draw callback
+ prefs.do_item_draw_callback(this);
+ }
+ else
+#endif
+ {
+ // Background for this item
+ // Draw bg only if different from tree's bg
+ if ( bg != tree->color() || is_selected() ) {
+ if ( is_selected() ) { // Selected? Use selectbox() style
+ fl_draw_box(prefs.selectbox(),bg_x,bg_y,bg_w,bg_h,bg);
+ } else { // Not Selected? use plain filled rectangle
+ fl_color(bg);
+ fl_rectf(bg_x,bg_y,bg_w,bg_h);
+ }
+ if ( widget() ) widget()->damage(FL_DAMAGE_ALL); // if there's a child widget, we just damaged it
}
- if ( widget() ) widget()->damage(FL_DAMAGE_ALL); // if there's a child widget, we just damaged it
- }
- // Draw user icon (if any)
- if ( usericon() ) {
- // Item has user icon? Use it
- int uicon_y = item_y_center - (usericon()->h() >> 1);
- usericon()->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);
- prefs.usericon()->draw(uicon_x,uicon_y);
- }
- // Draw label
+ // Draw user icon (if any)
+ if ( usericon() ) {
+ // Item has user icon? Use it
+ int uicon_y = item_y_center - (usericon()->h() >> 1);
+ usericon()->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);
+ prefs.usericon()->draw(uicon_x,uicon_y);
+ }
+ // Draw label
#if FLTK_ABI_VERSION >= 10301
- if ( _label &&
- ( !widget() ||
- (prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) )
+ if ( _label &&
+ ( !widget() ||
+ (prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) )
#else /*FLTK_ABI_VERSION*/
- if ( _label && !widget() ) // back compat: don't draw label if widget() present
+ if ( _label && !widget() ) // back compat: don't draw label if widget() present
#endif /*FLTK_ABI_VERSION*/
- {
- fl_color(fg);
- fl_font(_labelfont, _labelsize);
- int label_y = Y+(H/2)+(_labelsize/2)-fl_descent()/2;
- fl_draw(_label, label_x, label_y);
- }
+ {
+ fl_color(fg);
+ fl_font(_labelfont, _labelsize);
+ int label_y = Y+(H/2)+(_labelsize/2)-fl_descent()/2;
+ fl_draw(_label, label_x, label_y);
+ }
+ } // end non-custom draw
} // end non-child damage
// Draw child FLTK widget?
if ( widget() ) {
@@ -766,7 +776,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
Fl::visible_focus() &&
Fl::focus() == tree &&
prefs.selectmode() != FL_TREE_SELECT_NONE ) {
- draw_item_focus(FL_NO_BOX,bg,bg_x+1,bg_y+1,bg_w-1,bg_h-1);
+ draw_item_focus(FL_NO_BOX,fg,bg,bg_x+1,bg_y+1,bg_w-1,bg_h-1);
}
} // end drawthis
} // end clipped
diff --git a/src/Fl_Tree_Prefs.cxx b/src/Fl_Tree_Prefs.cxx
index b52724aef..3fc9c4355 100644
--- a/src/Fl_Tree_Prefs.cxx
+++ b/src/Fl_Tree_Prefs.cxx
@@ -156,6 +156,10 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_itemreselectmode = FL_TREE_SELECTABLE_ONCE;
_itemdrawmode = FL_TREE_ITEM_DRAW_DEFAULT;
#endif
+#if FLTK_ABI_VERSION >= 10303
+ _itemdrawcallback = 0;
+ _itemdrawuserdata = 0;
+#endif
// Let fltk's current 'scheme' affect defaults
if ( Fl::scheme() ) {
if ( strcmp(Fl::scheme(), "gtk+") == 0 ) {