summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2009-12-08 08:39:31 +0000
committerGreg Ercolano <erco@seriss.com>2009-12-08 08:39:31 +0000
commit79cd1d2ccb62f22adf8b1ed4e8b5dfb5dea845bc (patch)
tree2709bb4cfd1b4ba290ac0e84eb0f92a909f9156a
parenta657069cc53cc05245762e9323efa040a9f70da2 (diff)
Small fixed to SebHoll's user_data() mods (init + copy ctor),
added select_all() to Fl_Tree and Fl_Tree_Item. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6957 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Tree.H1
-rw-r--r--FL/Fl_Tree_Item.H15
-rw-r--r--src/Fl_Tree.cxx13
-rw-r--r--src/Fl_Tree_Item.cxx3
4 files changed, 31 insertions, 1 deletions
diff --git a/FL/Fl_Tree.H b/FL/Fl_Tree.H
index 00d92e88e..7404d8936 100644
--- a/FL/Fl_Tree.H
+++ b/FL/Fl_Tree.H
@@ -415,6 +415,7 @@ public:
int deselect_all(Fl_Tree_Item *item=0);
int select_only(Fl_Tree_Item *selitem);
+ int select_all(Fl_Tree_Item *item=0);
/// See if the specified item is selected.
/// \return
diff --git a/FL/Fl_Tree_Item.H b/FL/Fl_Tree_Item.H
index 674955cd4..b10b1e838 100644
--- a/FL/Fl_Tree_Item.H
+++ b/FL/Fl_Tree_Item.H
@@ -221,6 +221,21 @@ public:
select(); // select if deselected
}
}
+ /// Select self and all children
+ /// Returns count of how many items were in the 'deselected' state,
+ /// ie. how many items were "changed".
+ ///
+ int select_all() {
+ int count = 0;
+ if ( ! is_selected() ) {
+ select();
+ ++count;
+ }
+ for ( int t=0; t<children(); t++ ) {
+ count += child(t)->select_all();
+ }
+ return(count);
+ }
/// Disable the item's selection state.
void deselect() {
_selected = 0;
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index e946ccaf5..4c3a99b14 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -347,6 +347,19 @@ int Fl_Tree::deselect_all(Fl_Tree_Item *item) {
return(count);
}
+/// Select item and all its children.
+/// If item is NULL, root() is used.
+/// Handles calling redraw() if anything was changed.
+/// Returns count of how many items were in the 'deselected' state,
+/// ie. how many items were "changed".
+///
+int Fl_Tree::select_all(Fl_Tree_Item *item) {
+ item = item ? item : root(); // NULL? use root()
+ int count = item->select_all();
+ if ( count ) redraw(); // anything changed? cause redraw
+ return(count);
+}
+
/// Select only this item.
/// If item is NULL, root() is used.
/// Handles calling redraw() if anything was changed.
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index cf92b7078..66950ed4f 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -64,6 +64,7 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Prefs &prefs) {
_label_xywh[2] = 0;
_label_xywh[3] = 0;
_usericon = 0;
+ _userdata = 0;
_parent = 0;
}
@@ -103,7 +104,7 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Item *o) {
_label_xywh[2] = o->_label_xywh[2];
_label_xywh[3] = o->_label_xywh[3];
_usericon = o->usericon();
- _userdata = 0;
+ _userdata = o->user_data();
_parent = o->_parent;
}