summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx22
-rw-r--r--src/Fl_Tree_Item.cxx51
-rw-r--r--src/Fl_Tree_Prefs.cxx20
3 files changed, 52 insertions, 41 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index bf5f9daa4..95247e354 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -102,9 +102,9 @@ Fl_Tree::Fl_Tree(int X, int Y, int W, int H, const char *L) : Fl_Group(X,Y,W,H,L
#if FLTK_ABI_VERSION >= 10302
// NEW
_lastselect = 0;
-#else
+#else /*FLTK_ABI_VERSION*/
// OLD: data initialized static inside handle()
-#endif
+#endif /*FLTK_ABI_VERSION*/
box(FL_DOWN_BOX);
color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR);
@@ -150,10 +150,10 @@ int Fl_Tree::handle(int e) {
char is_command = Fl::event_state() & FL_COMMAND ? 1 : 0; // ctrl on win/lin, 'Command' on mac
#if FLTK_ABI_VERSION >= 10302
// NEW: data inside Fl_Tree
-#else
+#else /*FLTK_ABI_VERSION*/
// OLD:
static Fl_Tree_Item *_lastselect = 0;
-#endif
+#endif /*FLTK_ABI_VERSION*/
// Developer note: Fl_Browser_::handle() used for reference here..
// #include <FL/names.h> // for event debugging
// fprintf(stderr, "DEBUG: %s (%d)\n", fl_eventnames[e], e);
@@ -477,10 +477,10 @@ int Fl_Tree::draw_tree() {
#if FLTK_ABI_VERSION >= 10302
// NEW
int SY = Y + _prefs.marginbottom();
-#else
+#else /*FLTK_ABI_VERSION*/
// OLD
int SY = Y;
-#endif
+#endif /*FLTK_ABI_VERSION*/
int ydiff = (SY+_prefs.margintop())-Ysave; // ydiff=size of tree
int ytoofar = (cy+ch) - SY; // ytoofar -- if >0, scrolled beyond bottom
if ( ytoofar > 0 ) ydiff += ytoofar;
@@ -1117,7 +1117,7 @@ int Fl_Tree::select(Fl_Tree_Item *item, int docallback) {
do_callback_for_item(item, FL_TREE_REASON_RESELECTED);
}
}
-#endif
+#endif /*FLTK_ABI_VERSION*/
return(0);
}
@@ -1412,11 +1412,13 @@ void Fl_Tree::item_labelfgcolor(Fl_Color val) {
}
/// Get the default label background color used for creating new items.
+/// If the color is 0xffffffff, it is 'transparent'.
Fl_Color Fl_Tree::item_labelbgcolor(void) const {
return(_prefs.labelbgcolor());
}
/// Set the default label background color used for creating new items.
+/// A special case is made for color 0xffffffff (default) which is treated as 'transparent'.
/// To change the background color on a per-item basis, use Fl_Tree_Item::labelbgcolor(Fl_Color)
///
void Fl_Tree::item_labelbgcolor(Fl_Color val) {
@@ -1478,7 +1480,7 @@ void Fl_Tree::marginbottom(int val) {
_prefs.marginbottom(val);
redraw();
}
-#endif
+#endif /*FLTK_ABI_VERSION*/
/// Get the amount of white space (in pixels) that should appear
/// between items in the tree.
@@ -1543,7 +1545,7 @@ void Fl_Tree::widgetmarginleft(int val) {
_prefs.widgetmarginleft(val);
redraw();
}
-#endif
+#endif /*FLTK_ABI_VERSION*/
/// Gets the width of the horizontal connection lines (in pixels)
/// that appear to the left of each tree item's label.
@@ -1728,7 +1730,7 @@ 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
+#endif /*FLTK_ABI_VERSION*/
/// 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 b527d649a..d20437b9e 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -44,10 +44,14 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Prefs &prefs) {
_labelfgcolor = prefs.labelfgcolor();
_labelbgcolor = prefs.labelbgcolor();
_widget = 0;
+#if FLTK_ABI_VERSION >= 10302
+ _flags = OPEN|VISIBLE|ACTIVE;
+#else /*FLTK_ABI_VERSION*/
_open = 1;
_visible = 1;
_active = 1;
_selected = 0;
+#endif /*FLTK_ABI_VERSION*/
_xywh[0] = 0;
_xywh[1] = 0;
_xywh[2] = 0;
@@ -88,10 +92,14 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) {
_labelfgcolor = o->labelfgcolor();
_labelbgcolor = o->labelbgcolor();
_widget = o->widget();
+#if FLTK_ABI_VERSION >= 10302
+ _flags = o->_flags;
+#else /*FLTK_ABI_VERSION*/
_open = o->_open;
_visible = o->_visible;
_active = o->_active;
_selected = o->_selected;
+#endif /*FLTK_ABI_VERSION*/
_xywh[0] = o->_xywh[0];
_xywh[1] = o->_xywh[1];
_xywh[2] = o->_xywh[2];
@@ -468,7 +476,7 @@ void Fl_Tree_Item::draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_
/// \returns const visible item under the event if found, or 0 if none.
///
const Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs) const {
- if ( ! _visible ) return(0);
+ if ( ! is_visible() ) return(0);
if ( is_root() && !prefs.showroot() ) {
// skip event check if we're root but root not being shown
} else {
@@ -498,7 +506,7 @@ const Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs) const
/// \returns the visible item under the event if found, or 0 if none.
///
Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs) {
- if ( ! _visible ) return(0);
+ if ( ! is_visible() ) return(0);
if ( is_root() && !prefs.showroot() ) {
// skip event check if we're root but root not being shown
} else {
@@ -562,7 +570,7 @@ static void draw_item_focus(Fl_Boxtype B, Fl_Color C, int X, int Y, int W, int H
/// Doesn't include linespacing(); prevents affecting eg. height of widget().
///
int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
- if ( ! _visible ) return(0);
+ if ( ! is_visible() ) return(0);
int H = 0;
if ( _label ) {
fl_font(_labelfont, _labelsize); // fl_descent() needs this :/
@@ -574,7 +582,7 @@ int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
H < widget()->h()) {
H = widget()->h();
}
-#endif
+#endif /*FLTK_ABI_VERSION*/
if ( has_children() && prefs.openicon() && H<prefs.openicon()->h() )
H = prefs.openicon()->h();
if ( usericon() && H<usericon()->h() )
@@ -586,7 +594,7 @@ int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
Fl_Tree_Item *itemfocus,
const Fl_Tree_Prefs &prefs, int lastchild) {
- if ( ! _visible ) return;
+ if ( ! is_visible() ) return;
int tree_top = tree->y();
int tree_bot = tree_top + tree->h();
int H = calc_item_height(prefs); // height of item
@@ -645,20 +653,20 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
? widget()->h() : H;
if ( _label &&
(prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) {
-#else
+#else /*FLTK_ABI_VERSION*/
int wh = H; // lock widget's height to item height
if ( _label && !widget() ) { // back compat: don't draw label if widget() present
-#endif
+#endif /*FLTK_ABI_VERSION*/
fl_font(_labelfont, _labelsize); // fldescent() needs this
int lw=0, lh=0;
fl_measure(_label,lw,lh); // get box around text (including white space)
#if FLTK_ABI_VERSION >= 10302
// NEW
wx += (lw + prefs.widgetmarginleft());
-#else
+#else /*FLTK_ABI_VERSION*/
// OLD
wx += (lw + 3);
-#endif
+#endif /*FLTK_ABI_VERSION*/
}
if ( widget()->x() != wx || widget()->y() != wy ||
widget()->w() != ww || widget()->h() != wh ) {
@@ -668,12 +676,13 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
char clipped = ((Y+H) < tree_top) || (Y>tree_bot) ? 1 : 0;
char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1;
if ( !clipped ) {
- Fl_Color fg = _selected ? fl_contrast(_labelfgcolor, tree->selection_color())
- : _active ? _labelfgcolor
- : fl_inactive(_labelfgcolor);
- Fl_Color bg = _selected ? _active ? tree->selection_color()
- : fl_inactive(tree->selection_color())
- : _labelbgcolor;
+ Fl_Color fg = is_selected() ? fl_contrast(_labelfgcolor, tree->selection_color())
+ : is_active() ? _labelfgcolor
+ : fl_inactive(_labelfgcolor);
+ Fl_Color bg = is_selected() ? is_active() ? tree->selection_color()
+ : fl_inactive(tree->selection_color())
+ : _labelbgcolor == 0xffffffff ? tree->color() // transparent bg?
+ : _labelbgcolor;
// See if we should draw this item
// If this item is root, and showroot() is disabled, don't draw.
// 'clipped' is an optimization to prevent drawing anything offscreen.
@@ -730,9 +739,9 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
if ( _label &&
( !widget() ||
(prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) )
-#else
+#else /*FLTK_ABI_VERSION*/
if ( _label && !widget() ) // back compat: don't draw label if widget() present
-#endif
+#endif /*FLTK_ABI_VERSION*/
{
fl_color(fg);
fl_font(_labelfont, _labelsize);
@@ -781,7 +790,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree,
/// Was the event on the 'collapse' button?
///
int Fl_Tree_Item::event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const {
- if ( _visible && _active && has_children() && prefs.showcollapse() ) {
+ if ( is_visible() && is_active() && has_children() && prefs.showcollapse() ) {
return(event_inside(_collapse_xywh) ? 1 : 0);
} else {
return(0);
@@ -791,7 +800,7 @@ int Fl_Tree_Item::event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const {
/// Was event on the label()?
///
int Fl_Tree_Item::event_on_label(const Fl_Tree_Prefs &prefs) const {
- if ( _visible && _active ) {
+ if ( is_visible() && is_active() ) {
return(event_inside(_label_xywh) ? 1 : 0);
} else {
return(0);
@@ -822,7 +831,7 @@ void Fl_Tree_Item::hide_widgets() {
/// Open this item and all its children.
void Fl_Tree_Item::open() {
- _open = 1;
+ set_flag(OPEN,1);
// Tell children to show() their widgets
for ( int t=0; t<_children.total(); t++ ) {
_children[t]->show_widgets();
@@ -831,7 +840,7 @@ void Fl_Tree_Item::open() {
/// Close this item and all its children.
void Fl_Tree_Item::close() {
- _open = 0;
+ set_flag(OPEN,0);
// Tell children to hide() their widgets
for ( int t=0; t<_children.total(); t++ ) {
_children[t]->hide_widgets();
diff --git a/src/Fl_Tree_Prefs.cxx b/src/Fl_Tree_Prefs.cxx
index 7f4a5337b..02d1aed61 100644
--- a/src/Fl_Tree_Prefs.cxx
+++ b/src/Fl_Tree_Prefs.cxx
@@ -5,7 +5,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Pixmap.H>
#include <FL/Fl_Tree_Prefs.H>
-#include <string.h>
+#include <string.h> // strcmp
//////////////////////
// Fl_Tree_Prefs.cxx
@@ -44,7 +44,7 @@ static const char *L_open_xpm[] = {
"...@@@.....",
"...@@......",
"...@......."
-#else
+#else /* __APPLE__ */
"11 11 3 1",
". c #fefefe",
"# c #444444",
@@ -60,7 +60,7 @@ static const char *L_open_xpm[] = {
"#.........#",
"#.........#",
"###########"
-#endif
+#endif /* __APPLE__ */
};
static Fl_Pixmap L_openpixmap(L_open_xpm);
@@ -80,7 +80,7 @@ static const char *L_close_xpm[] = {
"...@@@@@...",
"....@@@....",
".....@....."
-#else
+#else /* __APPLE__ */
"11 11 3 1",
". c #fefefe",
"# c #444444",
@@ -96,7 +96,7 @@ static const char *L_close_xpm[] = {
"#.........#",
"#.........#",
"###########"
-#endif
+#endif /* __APPLE__ */
};
static Fl_Pixmap L_closepixmap(L_close_xpm);
@@ -127,22 +127,22 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() {
_margintop = 3;
#if FLTK_ABI_VERSION >= 10302
_marginbottom = 20;
-#endif
+#endif /*FLTK_ABI_VERSION*/
_openchild_marginbottom = 0;
_usericonmarginleft = 3;
_labelmarginleft = 3;
#if FLTK_ABI_VERSION >= 10302
_widgetmarginleft = 3;
-#endif
+#endif /*FLTK_ABI_VERSION*/
_linespacing = 0;
_labelfgcolor = FL_BLACK;
- _labelbgcolor = FL_WHITE;
+ _labelbgcolor = 0xffffffff; // we use this as 'transparent'
_connectorcolor = Fl_Color(43);
#ifdef __APPLE__
_connectorstyle = FL_TREE_CONNECTOR_NONE;
-#else
+#else /* __APPLE__ */
_connectorstyle = FL_TREE_CONNECTOR_DOTTED;
-#endif
+#endif /* __APPLE__ */
_openimage = &L_openpixmap;
_closeimage = &L_closepixmap;
_userimage = 0;