summaryrefslogtreecommitdiff
path: root/src/Fl_Tree_Item.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-07-01 18:03:10 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2020-07-06 20:28:20 +0200
commitf09e17c3c564e8310125a10c03397cbf473ff643 (patch)
tree8d0fd4a28e3686c33aaa140d07ddba26ab28bdc2 /src/Fl_Tree_Item.cxx
parentb0e0c355edaa2e23148cb0260ada907aec930f05 (diff)
Remove $Id$ tags, update URL's, and more
- remove obsolete svn '$Id$' tags from all source files - update .fl files and generated files accordingly - replace 'http://www.fltk.org' URL's with 'https://...' - replace bug report URL 'str.php' with 'bugs.php' - remove trailing whitespace - fix other whitespace errors flagged by Git - add and/or fix missing or wrong standard headers - convert tabs to spaces in all source files The only relevant code changes are in the fluid/ folder where some .fl files and other source files were used to generate the '$Id' headers and footers.
Diffstat (limited to 'src/Fl_Tree_Item.cxx')
-rw-r--r--src/Fl_Tree_Item.cxx416
1 files changed, 205 insertions, 211 deletions
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 779f42073..3df432ca7 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -1,6 +1,4 @@
//
-// "$Id$"
-//
#include <stdio.h>
#include <stdlib.h>
@@ -21,11 +19,11 @@
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
-// Please report all bugs and problems on the following page:
+// Please see the following page on how to report bugs and issues:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/bugs.php
//
/////////////////////////////////////////////////////////////////////////// 80 /
@@ -70,7 +68,7 @@ void Fl_Tree_Item::_Init(const Fl_Tree_Prefs &prefs, Fl_Tree *tree) {
_userdeicon = 0;
_userdata = 0;
_parent = 0;
- _children.manage_item_destroy(1); // let array's dtor manage destroying Fl_Tree_Items
+ _children.manage_item_destroy(1); // let array's dtor manage destroying Fl_Tree_Items
_prev_sibling = 0;
_next_sibling = 0;
}
@@ -89,17 +87,17 @@ Fl_Tree_Item::Fl_Tree_Item(Fl_Tree *tree) {
// DTOR
Fl_Tree_Item::~Fl_Tree_Item() {
- if ( _label ) {
+ if ( _label ) {
free((void*)_label);
_label = 0;
}
- _widget = 0; // Fl_Group will handle destruction
- _usericon = 0; // user handled allocation
- _userdeicon = 0; // user handled allocation
+ _widget = 0; // Fl_Group will handle destruction
+ _usericon = 0; // user handled allocation
+ _userdeicon = 0; // user handled allocation
// focus item? set to null
if ( _tree && this == _tree->_item_focus )
{ _tree->_item_focus = 0; }
- //_children.clear(); // array's destructor handles itself
+ //_children.clear(); // array's destructor handles itself
}
/// Copy constructor.
@@ -127,8 +125,8 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) {
_usericon = o->usericon();
_userdata = o->user_data();
_parent = o->_parent;
- _prev_sibling = 0; // do not copy ptrs! use update_prev_next()
- _next_sibling = 0; // do not copy ptrs! use update_prev_next()
+ _prev_sibling = 0; // do not copy ptrs! use update_prev_next()
+ _next_sibling = 0; // do not copy ptrs! use update_prev_next()
}
/// Print the tree as 'ascii art' to stdout.
@@ -137,8 +135,8 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) {
void Fl_Tree_Item::show_self(const char *indent) const {
const char *thelabel = label() ? label() : "(NULL)";
printf("%s-%s (%d children, this=%p, parent=%p, prev=%p, next=%p, depth=%d)\n",
- indent,thelabel,children(),(void*)this, (void*)_parent,
- _prev_sibling, _next_sibling, depth());
+ indent,thelabel,children(),(void*)this, (void*)_parent,
+ _prev_sibling, _next_sibling, depth());
if ( children() ) {
char *i2 = new char [strlen(indent)+2];
strcpy(i2, indent);
@@ -157,7 +155,7 @@ void Fl_Tree_Item::show_self(const char *indent) const {
void Fl_Tree_Item::label(const char *name) {
if ( _label ) { free((void*)_label); _label = 0; }
_label = name ? strdup(name) : 0;
- recalc_tree(); // may change label geometry
+ recalc_tree(); // may change label geometry
}
/// Return the label.
@@ -173,7 +171,7 @@ const Fl_Tree_Item *Fl_Tree_Item::child(int index) const {
/// Clear all the children for this item.
void Fl_Tree_Item::clear_children() {
_children.clear();
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
}
/// Return the index of the immediate child of this item
@@ -211,7 +209,7 @@ const Fl_Tree_Item* Fl_Tree_Item::find_child_item(const char *name) const {
Fl_Tree_Item* Fl_Tree_Item::find_child_item(const char *name) {
// "Effective C++, 3rd Ed", p.23. Sola fide, Amen.
return(const_cast<Fl_Tree_Item*>(
- static_cast<const Fl_Tree_Item &>(*this).find_child_item(name)));
+ static_cast<const Fl_Tree_Item &>(*this).find_child_item(name)));
}
/// Find child item by descending array \p 'arr' of names.
@@ -224,10 +222,10 @@ Fl_Tree_Item* Fl_Tree_Item::find_child_item(const char *name) {
const Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) const {
for ( int t=0; t<children(); t++ ) {
if ( child(t)->label() ) {
- if ( strcmp(child(t)->label(), *arr) == 0 ) { // match?
- if ( *(arr+1) ) { // more in arr? descend
+ if ( strcmp(child(t)->label(), *arr) == 0 ) { // match?
+ if ( *(arr+1) ) { // more in arr? descend
return(_children[t]->find_child_item(arr+1));
- } else { // end of arr? done
+ } else { // end of arr? done
return(_children[t]);
}
}
@@ -240,7 +238,7 @@ const Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) const {
Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) {
// "Effective C++, 3rd Ed", p.23. Sola fide, Amen.
return(const_cast<Fl_Tree_Item*>(
- static_cast<const Fl_Tree_Item &>(*this).find_child_item(arr)));
+ static_cast<const Fl_Tree_Item &>(*this).find_child_item(arr)));
}
/// Find item by descending array of \p 'names'.
@@ -251,11 +249,11 @@ Fl_Tree_Item *Fl_Tree_Item::find_child_item(char **arr) {
///
const Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) const {
if ( ! *names ) return(0);
- if ( label() && strcmp(label(), *names) == 0 ) { // match self?
- ++names; // skip self
- if ( *names == 0 ) return(this); // end of names, found ourself
+ if ( label() && strcmp(label(), *names) == 0 ) { // match self?
+ ++names; // skip self
+ if ( *names == 0 ) return(this); // end of names, found ourself
}
- if ( children() ) { // check children..
+ if ( children() ) { // check children..
return(find_child_item(names));
}
return(0);
@@ -265,7 +263,7 @@ const Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) const {
Fl_Tree_Item *Fl_Tree_Item::find_item(char **names) {
// "Effective C++, 3rd Ed", p.23. Sola fide, Amen.
return(const_cast<Fl_Tree_Item*>(
- static_cast<const Fl_Tree_Item &>(*this).find_item(names)));
+ static_cast<const Fl_Tree_Item &>(*this).find_item(names)));
}
/// Find the index number for the specified \p 'item'
@@ -288,7 +286,7 @@ int Fl_Tree_Item::find_child(Fl_Tree_Item *item) {
/// \version 1.3.0 release
///
Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs,
- const char *new_label) {
+ const char *new_label) {
return(add(prefs, new_label, (Fl_Tree_Item*)0));
}
@@ -301,11 +299,11 @@ Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs,
/// \version 1.3.3
///
Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs,
- const char *new_label,
- Fl_Tree_Item *item) {
+ const char *new_label,
+ Fl_Tree_Item *item) {
if ( !item )
{ item = new Fl_Tree_Item(_tree); item->label(new_label); }
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
item->_parent = this;
switch ( prefs.sortorder() ) {
case FL_TREE_SORT_NONE: {
@@ -356,35 +354,35 @@ Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs, char **arr) {
/// \version 1.3.3 ABI feature
///
Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs,
- char **arr,
- Fl_Tree_Item *newitem) {
+ char **arr,
+ Fl_Tree_Item *newitem) {
if ( !*arr ) return 0;
// See if we can find an existing child with name requested.
Fl_Tree_Item *child = find_child_item(*arr);
- if ( child ) { // Child found?
- if ( *(arr+1) == 0 ) { // ..and at end of path?
- if ( !newitem ) { // ..and no item specified?
- return 0; // ..error: child exists already
+ if ( child ) { // Child found?
+ if ( *(arr+1) == 0 ) { // ..and at end of path?
+ if ( !newitem ) { // ..and no item specified?
+ return 0; // ..error: child exists already
} else {
// Child found, end of path, item specified
- return child->add(prefs, newitem->label(), newitem);
+ return child->add(prefs, newitem->label(), newitem);
}
}
// Child found: more path elements to go or item specified?
// Descend into child to handle add..
- return child->add(prefs, arr+1, newitem); // recurse
+ return child->add(prefs, arr+1, newitem); // recurse
}
// No child found, see if we reached end of path.
- // If so, add as an immediate child, done
- if ( *(arr+1) == 0 ) // end of path?
- return add(prefs, *arr, newitem); // add as immediate child
+ // If so, add as an immediate child, done
+ if ( *(arr+1) == 0 ) // end of path?
+ return add(prefs, *arr, newitem); // add as immediate child
// No child found, but more to path?
- // If so, create new child to handle add()
+ // If so, create new child to handle add()
Fl_Tree_Item *newchild;
- return (newchild=add(prefs, *arr)) // create new immediate child
+ return (newchild=add(prefs, *arr)) // create new immediate child
? newchild->add(prefs,arr+1,newitem) // it worked? recurse to add
- : 0; // failed? error
+ : 0; // failed? error
}
/**
@@ -403,7 +401,7 @@ Fl_Tree_Item *Fl_Tree_Item::insert(const Fl_Tree_Prefs &prefs, const char *new_l
item->label(new_label);
item->_parent = this;
_children.insert(pos, item);
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
return(item);
}
@@ -451,7 +449,7 @@ Fl_Tree_Item* Fl_Tree_Item::deparent(int pos) {
int Fl_Tree_Item::reparent(Fl_Tree_Item *newchild, int pos) {
int ret;
if ( (ret = _children.reparent(newchild, this, pos)) < 0 ) return ret;
- newchild->parent(this); // take custody
+ newchild->parent(this); // take custody
return 0;
}
@@ -489,21 +487,21 @@ int Fl_Tree_Item::move(Fl_Tree_Item *item, int op, int pos) {
Fl_Tree_Item *from_parent, *to_parent;
int from, to;
switch (op) {
- case 0: // "above"
+ case 0: // "above"
from_parent = this->parent();
to_parent = item->parent();
if ( !from_parent || !to_parent ) return -1;
from = from_parent->find_child(this);
to = to_parent->find_child(item);
break;
- case 1: // "below"
+ case 1: // "below"
from_parent = this->parent();
to_parent = item->parent();
if ( !from_parent || !to_parent ) return -1;
from = from_parent->find_child(this);
to = to_parent->find_child(item);
break;
- case 2: // "into"
+ case 2: // "into"
from_parent = this->parent();
if ( !from_parent ) return -1;
to_parent = item;
@@ -515,20 +513,20 @@ int Fl_Tree_Item::move(Fl_Tree_Item *item, int op, int pos) {
}
if ( !from_parent || !to_parent ) return -1;
if ( from < 0 || to < 0 ) return -2;
- if ( from_parent == to_parent ) { // same parent?
- switch (op) { // 'to' offsets due to scroll
+ if ( from_parent == to_parent ) { // same parent?
+ switch (op) { // 'to' offsets due to scroll
case 0: if ( from < to && to > 0 ) --to; break;
case 1: if ( from > to && to < to_parent->children() ) ++to; break;
}
- if ( from_parent->move(to, from) < 0 ) // simple move among siblings
+ if ( from_parent->move(to, from) < 0 ) // simple move among siblings
return -4;
- } else { // different parent?
- if ( to > to_parent->children() ) // try to prevent a reparent() error
+ } else { // different parent?
+ if ( to > to_parent->children() ) // try to prevent a reparent() error
return -4;
- if ( from_parent->deparent(from) == NULL ) // deparent self from current parent
+ if ( from_parent->deparent(from) == NULL ) // deparent self from current parent
return -5;
- if ( to_parent->reparent(this, to) < 0 ) { // reparent self to new parent at position 'to'
- to_parent->reparent(this, 0); // failed? shouldn't happen, reparent at 0
+ if ( to_parent->reparent(this, to) < 0 ) { // reparent self to new parent at position 'to'
+ to_parent->reparent(this, 0); // failed? shouldn't happen, reparent at 0
return -6;
}
}
@@ -597,8 +595,8 @@ const Fl_Tree_Prefs& Fl_Tree_Item::prefs() const {
///
Fl_Tree_Item *Fl_Tree_Item::replace(Fl_Tree_Item *newitem) {
Fl_Tree_Item *p = parent();
- if ( !p ) { // no parent? then we're the tree's root..
- _tree->root(newitem); // ..tell tree to replace root
+ if ( !p ) { // no parent? then we're the tree's root..
+ _tree->root(newitem); // ..tell tree to replace root
return newitem;
}
// has parent? ask parent to replace us
@@ -620,13 +618,13 @@ Fl_Tree_Item *Fl_Tree_Item::replace(Fl_Tree_Item *newitem) {
/// \version 1.3.3 ABI feature
///
Fl_Tree_Item *Fl_Tree_Item::replace_child(Fl_Tree_Item *olditem,
- Fl_Tree_Item *newitem) {
- int pos = find_child(olditem); // find our index for olditem
+ Fl_Tree_Item *newitem) {
+ int pos = find_child(olditem); // find our index for olditem
if ( pos == -1 ) return(NULL);
newitem->_parent = this;
// replace in array (handles stitching neighboring items)
_children.replace(pos, newitem);
- recalc_tree(); // newitem may have changed tree geometry
+ recalc_tree(); // newitem may have changed tree geometry
return newitem;
}
@@ -638,7 +636,7 @@ int Fl_Tree_Item::remove_child(Fl_Tree_Item *item) {
if ( child(t) == item ) {
item->clear_children();
_children.remove(t);
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
return(0);
}
}
@@ -657,7 +655,7 @@ int Fl_Tree_Item::remove_child(const char *name) {
if ( child(t)->label() ) {
if ( strcmp(child(t)->label(), name) == 0 ) {
_children.remove(t);
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
return(0);
}
}
@@ -676,7 +674,7 @@ void Fl_Tree_Item::swap_children(int ax, int bx) {
}
/// Swap two of our immediate children, given item pointers.
-/// Use e.g. for sorting.
+/// Use e.g. for sorting.
///
/// This method is SLOW because it involves linear lookups.<br>
/// For speed, use swap_children(int,int) instead.
@@ -689,11 +687,11 @@ void Fl_Tree_Item::swap_children(int ax, int bx) {
///
int Fl_Tree_Item::swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b) {
int ax = -1, bx = -1;
- for ( int t=0; t<children(); t++ ) { // find index for a and b
+ for ( int t=0; t<children(); t++ ) { // find index for a and b
if ( _children[t] == a ) { ax = t; if ( bx != -1 ) break; else continue; }
if ( _children[t] == b ) { bx = t; if ( ax != -1 ) break; else continue; }
}
- if ( ax == -1 || bx == -1 ) return(-1); // not found? fail
+ if ( ax == -1 || bx == -1 ) return(-1); // not found? fail
swap_children(ax,bx);
return(0);
}
@@ -708,15 +706,15 @@ void Fl_Tree_Item::draw_horizontal_connector(int x1, int x2, int y, const Fl_Tre
fl_color(prefs.connectorcolor());
switch ( prefs.connectorstyle() ) {
case FL_TREE_CONNECTOR_SOLID:
- y |= 1; // force alignment w/dot pattern
+ y |= 1; // force alignment w/dot pattern
fl_line(x1,y,x2,y);
return;
- case FL_TREE_CONNECTOR_DOTTED:
+ case FL_TREE_CONNECTOR_DOTTED:
{
- y |= 1; // force alignment w/dot pattern
+ y |= 1; // force alignment w/dot pattern
x1 |= 1;
for ( int xx=x1; xx<=x2; xx+=2 ) {
- fl_point(xx, y);
+ fl_point(xx, y);
}
return;
}
@@ -735,14 +733,14 @@ void Fl_Tree_Item::draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_
fl_color(prefs.connectorcolor());
switch ( prefs.connectorstyle() ) {
case FL_TREE_CONNECTOR_SOLID:
- y1 |= 1; // force alignment w/dot pattern
- y2 |= 1; // force alignment w/dot pattern
+ y1 |= 1; // force alignment w/dot pattern
+ y2 |= 1; // force alignment w/dot pattern
fl_line(x,y1,x,y2);
return;
case FL_TREE_CONNECTOR_DOTTED:
{
- y1 |= 1; // force alignment w/dot pattern
- y2 |= 1; // force alignment w/dot pattern
+ y1 |= 1; // force alignment w/dot pattern
+ y2 |= 1; // force alignment w/dot pattern
for ( int yy=y1; yy<=y2; yy+=2 ) {
fl_point(x, yy);
}
@@ -773,16 +771,16 @@ const Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs, int y
return(this);
}
} else {
- if ( event_inside(_xywh) ) { // event within this item?
- return(this); // found
+ if ( event_inside(_xywh) ) { // event within this item?
+ return(this); // found
}
}
}
- if ( is_open() ) { // open? check children of this item
+ if ( is_open() ) { // open? check children of this item
for ( int t=0; t<children(); t++ ) {
const Fl_Tree_Item *item;
if ( (item = _children[t]->find_clicked(prefs, yonly)) != NULL) // recurse into child for descendents
- return(item); // found?
+ return(item); // found?
}
}
return(0);
@@ -792,7 +790,7 @@ const Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs, int y
Fl_Tree_Item *Fl_Tree_Item::find_clicked(const Fl_Tree_Prefs &prefs, int yonly) {
// "Effective C++, 3rd Ed", p.23. Sola fide, Amen.
return(const_cast<Fl_Tree_Item*>(
- static_cast<const Fl_Tree_Item &>(*this).find_clicked(prefs, yonly)));
+ static_cast<const Fl_Tree_Item &>(*this).find_clicked(prefs, yonly)));
}
static void draw_item_focus(Fl_Boxtype B, Fl_Color fg, Fl_Color bg, int X, int Y, int W, int H) {
@@ -848,8 +846,8 @@ int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
if ( ! is_visible() ) return(0);
int H = 0;
if ( _label ) {
- fl_font(_labelfont, _labelsize); // fl_descent() needs this :/
- H = _labelsize + fl_descent() + 1; // at least one pixel space below descender
+ fl_font(_labelfont, _labelsize); // fl_descent() needs this :/
+ H = _labelsize + fl_descent() + 1; // at least one pixel space below descender
}
if ( widget() &&
(prefs.item_draw_mode() & FL_TREE_ITEM_HEIGHT_FROM_WIDGET) &&
@@ -871,8 +869,8 @@ int Fl_Tree_Item::calc_item_height(const Fl_Tree_Prefs &prefs) const {
///
Fl_Color Fl_Tree_Item::drawfgcolor() const {
return is_selected() ? fl_contrast(_labelfgcolor, tree()->selection_color())
- : (is_active() && tree()->active_r()) ? _labelfgcolor
- : fl_inactive(_labelfgcolor);
+ : (is_active() && tree()->active_r()) ? _labelfgcolor
+ : fl_inactive(_labelfgcolor);
}
/// Returns the recommended background color used for drawing this item.
@@ -881,10 +879,10 @@ Fl_Color Fl_Tree_Item::drawfgcolor() const {
///
Fl_Color Fl_Tree_Item::drawbgcolor() const {
const Fl_Color unspecified = 0xffffffff;
- return is_selected() ? is_active() && tree()->active_r() ? tree()->selection_color()
- : fl_inactive(tree()->selection_color())
- : _labelbgcolor == unspecified ? tree()->color()
- : _labelbgcolor;
+ return is_selected() ? is_active() && tree()->active_r() ? tree()->selection_color()
+ : fl_inactive(tree()->selection_color())
+ : _labelbgcolor == unspecified ? tree()->color()
+ : _labelbgcolor;
}
/// Draw the item content
@@ -903,7 +901,7 @@ Fl_Color Fl_Tree_Item::drawbgcolor() const {
/// // DRAW OUR CUSTOM CONTENT FOR THE ITEM
/// int draw_item_content(int render) {
/// // Our item's dimensions + text content
-/// int X=label_x(), Y=label_y(), W=label_w(), H=label_h();
+/// int X=label_x(), Y=label_y(), W=label_w(), H=label_h();
/// const char *text = label() ? label() : "";
/// // Rendering? Do any drawing that's needed
/// if ( render ) {
@@ -923,7 +921,7 @@ Fl_Color Fl_Tree_Item::drawbgcolor() const {
/// \endcode
///
/// You can draw anything you want inside draw_item_content()
-/// using any of the fl_draw.H functions, as long as it's
+/// using any of the fl_draw.H functions, as long as it's
/// within the label's xywh area.
///
/// To add instances of your custom item to the tree, you can use:
@@ -937,7 +935,7 @@ Fl_Color Fl_Tree_Item::drawbgcolor() const {
/// ..or you can insert or replace existing items:
///
/// \code
-/// // Example #2: using replace()
+/// // Example #2: using replace()
/// MyTreeItem *marge = new MyTreeItem(..); // class derived from Fl_Tree_Item
/// item = tree->add("/Simpsons/Marge"); // create item
/// item->replace(mi); // replace it with our own
@@ -961,19 +959,19 @@ int Fl_Tree_Item::draw_item_content(int render) {
int xmax = label_x();
// Background for this item, only if different from tree's bg
if ( render && (bg != tree()->color() || is_selected()) ) {
- if ( is_selected() ) { // Selected? Use selectbox() style
+ if ( is_selected() ) { // Selected? Use selectbox() style
fl_draw_box(prefs.selectbox(),
- label_x(), label_y(), label_w(), label_h(), bg);
- } else { // Not Selected? use plain filled rectangle
+ label_x(), label_y(), label_w(), label_h(), bg);
+ } else { // Not Selected? use plain filled rectangle
fl_color(bg);
fl_rectf(label_x(), label_y(), label_w(), label_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 label
- 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) ) ) {
if ( render ) {
fl_color(fg);
fl_font(_labelfont, _labelsize);
@@ -981,9 +979,9 @@ int Fl_Tree_Item::draw_item_content(int render) {
int lx = label_x()+(_label ? prefs.labelmarginleft() : 0);
int ly = label_y()+(label_h()/2)+(_labelsize/2)-fl_descent()/2;
int lw=0, lh=0;
- fl_measure(_label, lw, lh); // get box around text (including white space)
+ fl_measure(_label, lw, lh); // get box around text (including white space)
if ( render ) fl_draw(_label, lx, ly);
- xmax = lx + lw; // update max width of drawn item
+ xmax = lx + lw; // update max width of drawn item
}
return xmax;
}
@@ -1006,13 +1004,13 @@ int Fl_Tree_Item::draw_item_content(int render) {
/// \version 1.3.3 ABI feature: modified parameters
///
void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
- int &tree_item_xmax, int lastchild, int render) {
+ int &tree_item_xmax, int lastchild, int render) {
Fl_Tree_Prefs &prefs = _tree->_prefs;
- if ( !is_visible() ) return;
+ if ( !is_visible() ) return;
int tree_top = tree()->_tiy;
int tree_bot = tree_top + tree()->_tih;
- int H = calc_item_height(prefs); // height of item
- int H2 = H + prefs.linespacing(); // height of item with line spacing
+ int H = calc_item_height(prefs); // height of item
+ int H2 = H + prefs.linespacing(); // height of item with line spacing
// Update the xywh of this item
_xywh[0] = X;
@@ -1045,7 +1043,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
// Usericon position
int uicon_x = X+(icon_w/2-1+conn_w) + ( (usericon() || prefs.usericon())
- ? prefs.usericonmarginleft() : 0);
+ ? prefs.usericonmarginleft() : 0);
int uicon_w = usericon() ? usericon()->w()
: prefs.usericon() ? prefs.usericon()->w() : 0;
@@ -1068,23 +1066,23 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
if ( widget() ) {
int wx = uicon_x + uicon_w + (_label ? prefs.labelmarginleft() : 0);
int wy = label_y();
- int ww = widget()->w(); // use widget's width
+ int ww = widget()->w(); // use widget's width
int wh = (prefs.item_draw_mode() & FL_TREE_ITEM_HEIGHT_FROM_WIDGET)
? widget()->h() : H;
- if ( _label &&
+ if ( _label &&
(prefs.item_draw_mode() & FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET) ) {
- fl_font(_labelfont, _labelsize); // fldescent() needs this
+ fl_font(_labelfont, _labelsize); // fldescent() needs this
int lw=0, lh=0;
- fl_measure(_label,lw,lh); // get box around text (including white space)
+ fl_measure(_label,lw,lh); // get box around text (including white space)
wx += (lw + prefs.widgetmarginleft());
}
if ( widget()->x() != wx || widget()->y() != wy ||
- widget()->w() != ww || widget()->h() != wh ) {
- widget()->resize(wx,wy,ww,wh); // we'll handle redraw below
+ widget()->w() != ww || widget()->h() != wh ) {
+ widget()->resize(wx,wy,ww,wh); // we'll handle redraw below
}
}
char clipped = ((Y+H) < tree_top) || (Y>tree_bot) ? 1 : 0;
- if (!render) clipped = 0; // NOT rendering? Then don't clip, so we calc unclipped items
+ if (!render) clipped = 0; // NOT rendering? Then don't clip, so we calc unclipped items
char active = (is_active() && tree()->active_r()) ? 1 : 0;
char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1;
if ( !clipped ) {
@@ -1094,75 +1092,75 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
// If this item is root, and showroot() is disabled, don't draw.
// 'clipped' is an optimization to prevent drawing anything offscreen.
//
- if ( drawthis ) { // draw this item at all?
- if ( (tree()->damage() & ~FL_DAMAGE_CHILD) || !render ) { // non-child damage?
- // Draw connectors
- if ( render && prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) {
- // Horiz connector between center of icon and text
- // if this is root, the connector should not dangle in thin air on the left
- if (is_root()) draw_horizontal_connector(hconn_x_center, hconn_x2, item_y_center, prefs);
- else draw_horizontal_connector(hconn_x, hconn_x2, item_y_center, prefs);
- // Small vertical line down to children
- if ( has_children() && is_open() )
- draw_vertical_connector(hconn_x_center, item_y_center, Y+H2, prefs);
- // Connectors for last child
- if ( !is_root() ) {
- if ( lastchild ) draw_vertical_connector(hconn_x, Y, item_y_center, prefs);
- else draw_vertical_connector(hconn_x, Y, Y+H2, prefs);
- }
- }
- // Draw collapse icon
- if ( render && has_children() && prefs.showcollapse() ) {
- // Draw icon image
- if ( is_open() ) {
- if ( active ) prefs.closeicon()->draw(icon_x,icon_y);
- else prefs.closedeicon()->draw(icon_x,icon_y);
- } else {
- if ( active ) prefs.openicon()->draw(icon_x,icon_y);
- else prefs.opendeicon()->draw(icon_x,icon_y);
- }
- }
- // Draw user icon (if any)
- if ( render && usericon() ) {
- // Item has user icon? Use it
- int uicon_y = item_y_center - (usericon()->h() >> 1);
- if ( active ) usericon()->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 if ( prefs.userdeicon() ) prefs.userdeicon()->draw(uicon_x,uicon_y);
- }
- // Draw item's content
- xmax = draw_item_content(render);
- } // end non-child damage
+ if ( drawthis ) { // draw this item at all?
+ if ( (tree()->damage() & ~FL_DAMAGE_CHILD) || !render ) { // non-child damage?
+ // Draw connectors
+ if ( render && prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) {
+ // Horiz connector between center of icon and text
+ // if this is root, the connector should not dangle in thin air on the left
+ if (is_root()) draw_horizontal_connector(hconn_x_center, hconn_x2, item_y_center, prefs);
+ else draw_horizontal_connector(hconn_x, hconn_x2, item_y_center, prefs);
+ // Small vertical line down to children
+ if ( has_children() && is_open() )
+ draw_vertical_connector(hconn_x_center, item_y_center, Y+H2, prefs);
+ // Connectors for last child
+ if ( !is_root() ) {
+ if ( lastchild ) draw_vertical_connector(hconn_x, Y, item_y_center, prefs);
+ else draw_vertical_connector(hconn_x, Y, Y+H2, prefs);
+ }
+ }
+ // Draw collapse icon
+ if ( render && has_children() && prefs.showcollapse() ) {
+ // Draw icon image
+ if ( is_open() ) {
+ if ( active ) prefs.closeicon()->draw(icon_x,icon_y);
+ else prefs.closedeicon()->draw(icon_x,icon_y);
+ } else {
+ if ( active ) prefs.openicon()->draw(icon_x,icon_y);
+ else prefs.opendeicon()->draw(icon_x,icon_y);
+ }
+ }
+ // Draw user icon (if any)
+ if ( render && usericon() ) {
+ // Item has user icon? Use it
+ int uicon_y = item_y_center - (usericon()->h() >> 1);
+ if ( active ) usericon()->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 if ( prefs.userdeicon() ) prefs.userdeicon()->draw(uicon_x,uicon_y);
+ }
+ // Draw item's content
+ xmax = draw_item_content(render);
+ } // end non-child damage
// Draw child FLTK widget?
if ( widget() ) {
if (render)
- tree()->draw_child(*widget()); // let group handle drawing child
- if ( widget()->label() && render )
- tree()->draw_outside_label(*widget());// label too
- xmax = widget()->x() + widget()->w(); // update max width of widget
+ tree()->draw_child(*widget()); // let group handle drawing child
+ if ( widget()->label() && render )
+ tree()->draw_outside_label(*widget());// label too
+ xmax = widget()->x() + widget()->w(); // update max width of widget
}
// Draw focus box around item's bg last
if ( render &&
this == itemfocus &&
- Fl::visible_focus() &&
- Fl::focus() == tree() &&
- prefs.selectmode() != FL_TREE_SELECT_NONE ) {
- draw_item_focus(FL_NO_BOX,fg,bg,label_x()+1,label_y()+1,label_w()-1,label_h()-1);
+ Fl::visible_focus() &&
+ Fl::focus() == tree() &&
+ prefs.selectmode() != FL_TREE_SELECT_NONE ) {
+ draw_item_focus(FL_NO_BOX,fg,bg,label_x()+1,label_y()+1,label_w()-1,label_h()-1);
}
- } // end drawthis
- } // end clipped
- if ( drawthis ) Y += H2; // adjust Y (even if clipped)
+ } // end drawthis
+ } // end clipped
+ if ( drawthis ) Y += H2; // adjust Y (even if clipped)
// Manage tree_item_xmax
if ( xmax > tree_item_xmax )
tree_item_xmax = xmax;
// Draw child items (if any)
if ( has_children() && is_open() ) {
- int child_x = drawthis ? (hconn_x_center - (icon_w/2) + 1) // offset children to right,
- : X; // unless didn't drawthis
+ int child_x = drawthis ? (hconn_x_center - (icon_w/2) + 1) // offset children to right,
+ : X; // unless didn't drawthis
int child_w = W - (child_x-X);
int child_y_start = Y;
for ( int t=0; t<children(); t++ ) {
@@ -1170,7 +1168,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
_children[t]->draw(child_x, Y, child_w, itemfocus, tree_item_xmax, is_lastchild, render);
}
if ( has_children() && is_open() ) {
- Y += prefs.openchild_marginbottom(); // offset below open child tree
+ Y += prefs.openchild_marginbottom(); // offset below open child tree
}
if ( ! lastchild ) {
// Special 'clipped' calculation. (intentional variable shadowing)
@@ -1261,7 +1259,7 @@ void Fl_Tree_Item::open() {
for ( int t=0; t<_children.total(); t++ ) {
_children[t]->show_widgets();
}
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
}
/// Close this item and all its children.
@@ -1271,7 +1269,7 @@ void Fl_Tree_Item::close() {
for ( int t=0; t<_children.total(); t++ ) {
_children[t]->hide_widgets();
}
- recalc_tree(); // may change tree geometry
+ recalc_tree(); // may change tree geometry
}
/// Returns how many levels deep this item is in the hierarchy.
@@ -1294,7 +1292,7 @@ int Fl_Tree_Item::depth() const {
///
/// This method can be used to walk the tree forward.
/// For an example of how to use this method, see Fl_Tree::first().
-///
+///
/// \returns the next item in the tree, or 0 if there's no more items.
///
Fl_Tree_Item *Fl_Tree_Item::next() {
@@ -1302,26 +1300,26 @@ Fl_Tree_Item *Fl_Tree_Item::next() {
if ( c->has_children() ) {
return(c->child(0));
}
- while ( ( p = c->parent() ) != NULL ) { // loop upwards through parents
- if ( c->_next_sibling ) // not last child?
- return(c->_next_sibling); // return next child
- c = p; // child becomes parent to move up generation
- } // loop: moves up to next parent
- return(0); // hit root? done
+ while ( ( p = c->parent() ) != NULL ) { // loop upwards through parents
+ if ( c->_next_sibling ) // not last child?
+ return(c->_next_sibling); // return next child
+ c = p; // child becomes parent to move up generation
+ } // loop: moves up to next parent
+ return(0); // hit root? done
}
/// Return the previous item in the tree.
///
/// This method can be used to walk the tree backwards.
/// For an example of how to use this method, see Fl_Tree::last().
-///
-/// \returns the previous item in the tree,
+///
+/// \returns the previous item in the tree,
/// or 0 if there's no item above this one (hit the root).
///
Fl_Tree_Item *Fl_Tree_Item::prev() {
- if ( !parent() ) return(0); // hit root? done
- if ( !_prev_sibling ) { // are we first child?
- return(parent()); // return parent
+ if ( !parent() ) return(0); // hit root? done
+ if ( !_prev_sibling ) { // are we first child?
+ return(parent()); // return parent
}
// Tricky: in the following example our current position
// in the tree is 'j', and we need to move "up one" to 'i':
@@ -1341,9 +1339,9 @@ Fl_Tree_Item *Fl_Tree_Item::prev() {
// 2. Find b's 'last child' (g) |_ while loop
// 3. Find g's 'last child' (i) _|
//
- Fl_Tree_Item *p = _prev_sibling; // focus on our prev sibling
- while ( p->has_children() ) { // item has children?
- p = p->child(p->children()-1); // descend hierarchy finding deepest 'last child'
+ Fl_Tree_Item *p = _prev_sibling; // focus on our prev sibling
+ while ( p->has_children() ) { // item has children?
+ p = p->child(p->children()-1); // descend hierarchy finding deepest 'last child'
}
return(p);
}
@@ -1353,7 +1351,7 @@ Fl_Tree_Item *Fl_Tree_Item::prev() {
/// Moves to the next item below us at the same level (sibling).
/// Use this to move down the tree without changing depth().
/// effectively skipping over this item's children/descendents.
-///
+///
/// \returns item's next sibling, or 0 if none.
///
Fl_Tree_Item *Fl_Tree_Item::next_sibling() {
@@ -1364,7 +1362,7 @@ Fl_Tree_Item *Fl_Tree_Item::next_sibling() {
///
/// Moves to the previous item above us at the same level (sibling).
/// Use this to move up the tree without changing depth().
-///
+///
/// \returns This item's previous sibling, or 0 if none.
///
Fl_Tree_Item *Fl_Tree_Item::prev_sibling() {
@@ -1376,9 +1374,9 @@ Fl_Tree_Item *Fl_Tree_Item::prev_sibling() {
/// Call this whenever items in the array are added/removed/moved/swapped/etc.
/// \param[in] index Our index# in the parent.<br>
/// Special case if index=-1: become an orphan; null out all parent/sibling associations.
-///
+///
void Fl_Tree_Item::update_prev_next(int index) {
- if ( index == -1 ) { // special case: become an orphan
+ if ( index == -1 ) { // special case: become an orphan
_parent = 0;
_prev_sibling = 0;
_next_sibling = 0;
@@ -1397,13 +1395,13 @@ void Fl_Tree_Item::update_prev_next(int index) {
if ( item_prev ) item_prev->_next_sibling = this;
if ( item_next ) item_next->_prev_sibling = this;
}
-
-/// Return the next open(), visible() item.
+
+/// Return the next open(), visible() item.
/// (If this item has children and is closed, children are skipped)
///
/// This method can be used to walk the tree forward, skipping items
/// that are not currently open/visible to the user.
-///
+///
/// \returns the next open() visible() item below us,
/// or 0 if there's no more items.
/// \version 1.3.3
@@ -1424,33 +1422,33 @@ Fl_Tree_Item *Fl_Tree_Item::next_displayed(Fl_Tree_Prefs &prefs) {
return next_visible(prefs);
}
-/// Return the previous open(), visible() item.
+/// Return the previous open(), visible() item.
/// (If this item above us has children and is closed, its children are skipped)
///
-/// This method can be used to walk the tree backward,
+/// This method can be used to walk the tree backward,
/// skipping items that are not currently open/visible to the user.
-///
+///
/// \returns the previous open() visible() item above us,
/// or 0 if there's no more items.
///
Fl_Tree_Item *Fl_Tree_Item::prev_visible(Fl_Tree_Prefs &prefs) {
Fl_Tree_Item *c = this;
while ( c ) {
- c = c->prev(); // previous item
- if ( !c ) break; // no more items? done
- if ( c->is_root() ) // root
- return((prefs.showroot()&&c->visible()) ? c : 0); // return root if visible
- if ( !c->visible() ) continue; // item not visible? skip
+ c = c->prev(); // previous item
+ if ( !c ) break; // no more items? done
+ if ( c->is_root() ) // root
+ return((prefs.showroot()&&c->visible()) ? c : 0); // return root if visible
+ if ( !c->visible() ) continue; // item not visible? skip
// Check all parents to be sure none are closed.
// If closed, move up to that level and repeat until sure none are closed.
Fl_Tree_Item *p = c->parent();
while (1) {
- if ( !p || p->is_root() ) return(c); // hit top? then we're displayed, return c
- if ( p->is_close() ) c = p; // found closed parent? make it current
- p = p->parent(); // continue up tree
+ if ( !p || p->is_root() ) return(c); // hit top? then we're displayed, return c
+ if ( p->is_close() ) c = p; // found closed parent? make it current
+ p = p->parent(); // continue up tree
}
}
- return(0); // hit end: no more items
+ return(0); // hit end: no more items
}
/// Same as prev_visible().
@@ -1468,7 +1466,7 @@ Fl_Tree_Item *Fl_Tree_Item::prev_displayed(Fl_Tree_Prefs &prefs) {
int Fl_Tree_Item::visible_r() const {
if ( !visible() ) return(0);
for (const Fl_Tree_Item *p=parent(); p; p=p->parent())// move up through parents
- if (!p->visible() || p->is_close()) return(0); // any parent not visible or closed?
+ if (!p->visible() || p->is_close()) return(0); // any parent not visible or closed?
return(1);
}
@@ -1480,7 +1478,3 @@ int Fl_Tree_Item::visible_r() const {
void Fl_Tree_Item::recalc_tree() {
_tree->recalc_tree();
}
-
-//
-// End of "$Id$".
-//