summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2013-11-06 20:44:47 +0000
committerGreg Ercolano <erco@seriss.com>2013-11-06 20:44:47 +0000
commit33ab9cfed1693a3cb9577c680e1d504354cd98c0 (patch)
treed06ccdcd4953a08c74b8a01a527dfab66b3c8b95 /src
parent52d395ad818d28053d34e7a634d4c9c3eb8ab755 (diff)
Fl_Tree:
o Added new method Fl_Tree::get_selected_items() o Modified Fl_Tree_Item_Array to usable in a general way (i.e. beyond Fl_Tree's internal use) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10016 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx25
-rw-r--r--src/Fl_Tree_Item.cxx3
-rw-r--r--src/Fl_Tree_Item_Array.cxx68
3 files changed, 82 insertions, 14 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 0ff40a8c7..ba37dab3f 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -924,6 +924,31 @@ Fl_Tree_Item *Fl_Tree::next_selected_item(Fl_Tree_Item *item) {
return(0);
}
+#if FLTK_ABI_VERSION >= 10303 /* reason for this: Fl_Tree_Item_Array::manage_item_destroy() */
+/// Returns the currently selected items as an array. Example:
+/// \code
+/// // Get selected items as an array
+/// Fl_Tree_Item_Array items;
+/// tree->get_selected_items(items);
+/// // Manipulate the returned array
+/// for ( int t=0; t<items.total(); t++ ) {
+/// Fl_Tree_Item &item = items[t];
+/// ..do stuff with each selected item..
+/// }
+/// \endcode
+/// \param[in] items The returned array of selected items.
+/// \returns The number of items in the returned array.
+/// \see first_selected_item(), next_selected_item()
+///
+int Fl_Tree::get_selected_items(Fl_Tree_Item_Array &ret_items) {
+ ret_items.clear();
+ for ( Fl_Tree_Item *i=first_selected_item(); i; i=next_selected_item(i) ) {
+ ret_items.add(i);
+ }
+ return ret_items.total();
+}
+#endif
+
/// Open the specified 'item'.
/// This causes the item's children (if any) to be shown.
/// Handles redrawing if anything was actually changed.
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index 307f1e9c3..daccbdbde 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -67,6 +67,9 @@ Fl_Tree_Item::Fl_Tree_Item(const Fl_Tree_Prefs &prefs) {
_usericon = 0;
_userdata = 0;
_parent = 0;
+#if FLTK_ABI_VERSION >= 10303
+ _children.manage_item_destroy(1); // let array's dtor manage destroying Fl_Tree_Items
+#endif
#if FLTK_ABI_VERSION >= 10301
_prev_sibling = 0;
_next_sibling = 0;
diff --git a/src/Fl_Tree_Item_Array.cxx b/src/Fl_Tree_Item_Array.cxx
index b6eddd09d..2519cf226 100644
--- a/src/Fl_Tree_Item_Array.cxx
+++ b/src/Fl_Tree_Item_Array.cxx
@@ -36,6 +36,9 @@ Fl_Tree_Item_Array::Fl_Tree_Item_Array(int new_chunksize) {
_items = 0;
_total = 0;
_size = 0;
+#if FLTK_ABI_VERSION >= 10303
+ _flags = 0;
+#endif
_chunksize = new_chunksize;
}
@@ -50,10 +53,24 @@ Fl_Tree_Item_Array::Fl_Tree_Item_Array(const Fl_Tree_Item_Array* o) {
_total = 0;
_size = o->_size;
_chunksize = o->_chunksize;
+#if FLTK_ABI_VERSION >= 10303
+ _flags = o->_flags;
+#endif
for ( int t=0; t<o->_total; t++ ) {
- _items[t] = new Fl_Tree_Item(o->_items[t]);
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM ) {
+ _items[t] = new Fl_Tree_Item(o->_items[t]); // make new copy of item
+ ++_total;
+ _items[t]->update_prev_next(t); // update uses _total's current value
+ } else {
+ _items[t] = o->_items[t]; // copy ptr only
+ ++_total;
+ }
+#else
+ _items[t] = new Fl_Tree_Item(o->_items[t]); // make new copy of item
++_total;
- _items[t]->update_prev_next(t); // update uses _total's current value
+ _items[t]->update_prev_next(t); // update uses _total's current value
+#endif
}
}
@@ -65,8 +82,13 @@ Fl_Tree_Item_Array::Fl_Tree_Item_Array(const Fl_Tree_Item_Array* o) {
void Fl_Tree_Item_Array::clear() {
if ( _items ) {
for ( int t=0; t<_total; t++ ) {
- delete _items[t];
- _items[t] = 0;
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM )
+#endif
+ {
+ delete _items[t];
+ _items[t] = 0;
+ }
}
free((void*)_items); _items = 0;
}
@@ -110,7 +132,12 @@ void Fl_Tree_Item_Array::insert(int pos, Fl_Tree_Item *new_item) {
}
_items[pos] = new_item;
_total++;
- _items[pos]->update_prev_next(pos); // adjust item's prev/next and its neighbors
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM )
+#endif
+ {
+ _items[pos]->update_prev_next(pos); // adjust item's prev/next and its neighbors
+ }
}
/// Add an item* to the end of the array.
@@ -129,18 +156,26 @@ void Fl_Tree_Item_Array::add(Fl_Tree_Item *val) {
///
void Fl_Tree_Item_Array::remove(int index) {
if ( _items[index] ) { // delete if non-zero
- delete _items[index];
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM )
+#endif
+ delete _items[index];
}
_items[index] = 0;
_total--;
for ( int i=index; i<_total; i++ ) { // reshuffle the array
_items[i] = _items[i+1];
}
- if ( index < _total ) { // removed item not last?
- _items[index]->update_prev_next(index); // update next item's prev/next and neighbors
- } else if ( ((index-1) >= 0) && // removed item IS last?
- ((index-1) < _total)) {
- _items[index-1]->update_prev_next(index-1); // update prev item's prev/next and neighbors
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM )
+#endif
+ {
+ if ( index < _total ) { // removed item not last?
+ _items[index]->update_prev_next(index); // update next item's prev/next and neighbors
+ } else if ( ((index-1) >= 0) && // removed item IS last?
+ ((index-1) < _total)) {
+ _items[index-1]->update_prev_next(index-1);// update prev item's prev/next and neighbors
+ }
}
}
@@ -164,9 +199,14 @@ void Fl_Tree_Item_Array::swap(int ax, int bx) {
Fl_Tree_Item *asave = _items[ax];
_items[ax] = _items[bx];
_items[bx] = asave;
- // Adjust prev/next ptrs
- _items[ax]->update_prev_next(ax);
- _items[bx]->update_prev_next(bx);
+#if FLTK_ABI_VERSION >= 10303
+ if ( _flags & MANAGE_ITEM )
+#endif
+ {
+ // Adjust prev/next ptrs
+ _items[ax]->update_prev_next(ax);
+ _items[bx]->update_prev_next(bx);
+ }
}
#endif /* FLTK_ABI_VERSION */