X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.cpp;h=5c175031d76515e8b2bd2c269bdd9806baeb39bc;hb=eeec8c83778e73c02c414db772f790540e626d2c;hp=4f4d2a370152fe6fda3b05c2e65de7d92d59ef35;hpb=81c4024fb6acf37df702a803dc4efdf82a81525a;p=libs%2Fgltk.git diff --git a/source/container.cpp b/source/container.cpp index 4f4d2a3..5c17503 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -21,7 +21,7 @@ Container::~Container() void Container::add(Widget &wdg) { wdg.set_parent(this); - children.push_back(create_child(&wdg)); + children.push_back(new Child(*this, &wdg)); if(wdg.get_animation_interval()) check_animation_interval(); children_rebuild_needed = true; @@ -35,6 +35,8 @@ void Container::remove(Widget &wdg) if(i==children.end()) throw hierarchy_error("widget not in container"); + if(&wdg==saved_input_focus) + saved_input_focus = nullptr; wdg.set_parent(nullptr); delete *i; children.erase(i); @@ -43,11 +45,6 @@ void Container::remove(Widget &wdg) on_child_removed(wdg); } -Container::Child *Container::create_child(Widget *wdg) -{ - return new Child(*this, wdg); -} - Geometry Container::determine_child_geometry(const Widget &child, const Part &part) const { Geometry pgeom = part.get_geometry(); @@ -78,15 +75,15 @@ void Container::reposition_child(Widget &child, const Part &part) const child.set_geometry(determine_child_geometry(child, part)); } -list Container::get_children() const +vector Container::get_children() const { - list result; + vector result; for(const Child *c: children) result.push_back(c->widget); return result; } -Widget *Container::get_child_at(int x, int y) const +Widget *Container::find_child_at(int x, int y) const { for(auto i=children.end(); i!=children.begin();) if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y)) @@ -95,14 +92,13 @@ Widget *Container::get_child_at(int x, int y) const return nullptr; } -Widget *Container::get_descendant_at(int x, int y) const +Widget *Container::find_descendant_at(int x, int y) const { - Widget *wdg = get_child_at(x, y); + Widget *wdg = find_child_at(x, y); if(Container *cont = dynamic_cast(wdg)) { const Geometry &cgeom = wdg->get_geometry(); - Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y); - if(wdg2) + if(Widget *wdg2 = cont->find_descendant_at(x-cgeom.x, y-cgeom.y)) return wdg2; } return wdg; @@ -114,7 +110,9 @@ void Container::raise(Widget &wdg) if(i==children.end()) throw hierarchy_error("widget not in container"); - children.splice(children.end(), children, i); + Child *c = *i; + children.erase(i); + children.push_back(c); } void Container::set_pointer_focus(Widget *wdg, bool grab) @@ -211,7 +209,7 @@ void Container::button_release(int x, int y, unsigned btn) { click_focus = nullptr; if(!pointer_focus) - set_pointer_focus(get_child_at(x, y)); + set_pointer_focus(find_child_at(x, y)); } const Geometry &cgeom = child->get_geometry(); @@ -242,7 +240,7 @@ Widget *Container::get_pointer_target(int x, int y, bool touch) const return touch_focus; else { - Widget *child = get_child_at(x, y); + Widget *child = find_child_at(x, y); if(child && child->is_enabled()) return child; else @@ -317,7 +315,7 @@ bool Container::character(wchar_t ch) void Container::focus_in() { - if(saved_input_focus && saved_input_focus->get_parent()==this) + if(saved_input_focus) set_input_focus(saved_input_focus); Widget::focus_in(); }