diff options
| -rw-r--r-- | src/Fl_Tree.cxx | 8 | ||||
| -rw-r--r-- | src/Fl_Tree_Item.cxx | 15 | ||||
| -rw-r--r-- | src/Fl_Tree_Item_Array.cxx | 7 |
3 files changed, 25 insertions, 5 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index a658a38c7..1b83dda96 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -874,6 +874,14 @@ Fl_Tree_Item* Fl_Tree::insert_above(Fl_Tree_Item *above, const char *name) { /** Insert a new item \p 'name' into \p 'item's children at position \p 'pos'. + + If \p pos is out of range the new item is + - prepended if \p pos \< 0 or + - appended if \p pos \> item->children(). + + Note: \p pos == children() is not considered out of range: the item is + appended to the child list. + Example: \par \code diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx index 2b3e3602a..666a54674 100644 --- a/src/Fl_Tree_Item.cxx +++ b/src/Fl_Tree_Item.cxx @@ -387,10 +387,17 @@ Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs, : 0; // failed? error } -/// Insert a new item named \p 'new_label' into current item's -/// children at a specified position \p 'pos'. -/// \returns the new item inserted. -/// +/** + Insert a new item named \p 'new_label' into current item's + children at a specified position \p 'pos'. + + If \p pos is out of range the new item is + - prepended if \p pos \< 0 or + - appended if \p pos \> item->children(). + + \returns the new item inserted + \see Fl_Tree::insert() +*/ Fl_Tree_Item *Fl_Tree_Item::insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos) { Fl_Tree_Item *item = new Fl_Tree_Item(_tree); item->label(new_label); diff --git a/src/Fl_Tree_Item_Array.cxx b/src/Fl_Tree_Item_Array.cxx index 1da368c9a..0503a8000 100644 --- a/src/Fl_Tree_Item_Array.cxx +++ b/src/Fl_Tree_Item_Array.cxx @@ -109,9 +109,14 @@ void Fl_Tree_Item_Array::enlarge(int count) { /// Insert an item at index position \p pos. /// /// Handles enlarging array if needed, total increased by 1. -/// If \p pos == total(), an empty item is appended to the array. +/// If \p pos \>= total(), the item is appended to the array. +/// If \p pos \< 0, the item is prepended (works like pos == 0). /// void Fl_Tree_Item_Array::insert(int pos, Fl_Tree_Item *new_item) { + if (pos < 0) + pos = 0; + else if (pos > _total) + pos = _total; enlarge(1); // printf("*** POS=%d TOTAL-1=%d NITEMS=%d\n", pos, _total-1, (_total-pos)); if ( pos <= (_total - 1) ) { // need to move memory around? |
