summaryrefslogtreecommitdiff
path: root/src/Fl_Tree_Item_Array.cxx
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2014-09-05 02:59:00 +0000
committerGreg Ercolano <erco@seriss.com>2014-09-05 02:59:00 +0000
commitce1ab7e1ce58f33a0dc6e7dc883cfd6710e899e3 (patch)
treeabe32140045e230bedb5d7ec0be4565171566ec7 /src/Fl_Tree_Item_Array.cxx
parent107fc50e48c96d3eca7980cdb227d8d22aad30a8 (diff)
Fixes to how new move() operations handle the concept
of 'above' and 'below' when referring to items instead of index positions. Small offsets needed due to how the arrays are scrolled after a move operation. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10272 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tree_Item_Array.cxx')
-rw-r--r--src/Fl_Tree_Item_Array.cxx19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Fl_Tree_Item_Array.cxx b/src/Fl_Tree_Item_Array.cxx
index 2610bb2a6..7f7476569 100644
--- a/src/Fl_Tree_Item_Array.cxx
+++ b/src/Fl_Tree_Item_Array.cxx
@@ -234,6 +234,10 @@ void Fl_Tree_Item_Array::swap(int ax, int bx) {
#endif /* FLTK_ABI_VERSION */
/// Move item at 'from' to new position 'to' in the array.
+/// Due to how the moving an item shuffles the array around,
+/// a positional 'move' implies things that may not be obvious:
+/// - When 'from' moved lower in tree, appears BELOW item that was at 'to'.
+/// - When 'from' moved higher in tree, appears ABOVE item that was at 'to'.
///
/// \returns 0 on success, -1 on range error (e.g. if \p 'to' or \p 'from' out of range)
///
@@ -241,23 +245,18 @@ int Fl_Tree_Item_Array::move(int to, int from) {
if ( from == to ) return 0; // nop
if ( to<0 || to>=_total || from<0 || from>=_total ) return -1;
Fl_Tree_Item *item = _items[from];
- Fl_Tree_Item *prev = item->prev_sibling();
- Fl_Tree_Item *next = item->next_sibling();
// Remove item..
if ( from < to )
- for ( int t=from; t<to && t<_total; t++ )
+ for ( int t=from; t<to && t<(_total+1); t++ )
_items[t] = _items[t+1];
else
- for ( int t=from; t>to; t-- )
+ for ( int t=from; t>to && t>0; t-- )
_items[t] = _items[t-1];
// Move to new position
_items[to] = item;
- // Adjust for new siblings
- _items[to]->update_prev_next(to);
- _items[from]->update_prev_next(from);
- // Adjust old siblings
- if ( prev ) prev->update_prev_next(from-1);
- if ( next ) next->update_prev_next(from);
+ // Update all children
+ for ( int r=0; r<_total; r++ ) // XXX: excessive to do all children,
+ _items[r]->update_prev_next(r); // XXX: but avoids weird boundary issues
return 0;
}