From 33ab9cfed1693a3cb9577c680e1d504354cd98c0 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Wed, 6 Nov 2013 20:44:47 +0000 Subject: 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 --- src/Fl_Tree.cxx | 25 +++++++++++++++++ src/Fl_Tree_Item.cxx | 3 ++ src/Fl_Tree_Item_Array.cxx | 68 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 82 insertions(+), 14 deletions(-) (limited to 'src') 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= 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_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 */ -- cgit v1.2.3