diff options
Diffstat (limited to 'src/Fl_Group.cxx')
| -rw-r--r-- | src/Fl_Group.cxx | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index e256e81ec..31fca05d8 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -34,12 +34,9 @@ Fl_Group* Fl_Group::current_; \note This pointer is only valid until the next time a child is added or removed. - - \internal This "array" of children is the storage area of an - internal std::vector. */ Fl_Widget*const* Fl_Group::array() const { - return child_.data(); + return child_; } /** @@ -354,6 +351,9 @@ int Fl_Group::navigation(int key) { Fl_Group::Fl_Group(int X, int Y, int W, int H, const char *L) : Fl_Widget(X, Y, W, H, L) { align(FL_ALIGN_TOP); + child_ = 0; + children_ = 0; + children_alloc_ = 0; savedfocus_ = 0; resizable_ = this; bounds_ = 0; // this is allocated when first resize() is done @@ -437,6 +437,10 @@ Fl_Group::~Fl_Group() { if (current_ == this) end(); clear(); + if (child_) { + free(child_); + child_ = 0; + } } /** @@ -529,10 +533,24 @@ void Fl_Group::insert(Fl_Widget &o, int index) { index = on_insert(&o, index); if (index == -1) return; - if (index >= children()) { // append - child_.push_back(&o); + + // grow array if needed + if (children_ >= children_alloc_) { + int newsize = children_alloc_ ? children_alloc_ * 2 : 4; + Fl_Widget **newarray = (Fl_Widget**)realloc(child_, newsize * sizeof(Fl_Widget*)); + if (!newarray) return; // allocation failed + child_ = newarray; + children_alloc_ = newsize; + } + + if (index >= children_) { // append + child_[children_++] = &o; } else { // insert - child_.insert(child_.begin() + index, &o); + int i; + for (i = children_; i > index; i--) + child_[i] = child_[i - 1]; + child_[index] = &o; + children_++; } o.parent_ = this; init_sizes(); @@ -583,11 +601,11 @@ void Fl_Group::remove(int index) { o.parent_ = 0; } - if (index == children() - 1) { - child_.pop_back(); - } else { - child_.erase(child_.begin() + index); // remove the widget from the group - } + // remove the widget from the group + children_--; + int i; + for (i = index; i < children_; i++) + child_[i] = child_[i + 1]; init_sizes(); } |
