]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/container.cpp
Clear saved input focus if the widget is removed from the container
[libs/gltk.git] / source / container.cpp
index 4f4d2a370152fe6fda3b05c2e65de7d92d59ef35..9ef46f1ab85fcd511238ecb83f3f45cf912b7caa 100644 (file)
@@ -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);
@@ -86,7 +88,7 @@ list<Widget *> Container::get_children() const
        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,13 +97,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<Container *>(wdg))
        {
                const Geometry &cgeom = wdg->get_geometry();
-               Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
+               Widget *wdg2 = cont->find_descendant_at(x-cgeom.x, y-cgeom.y);
                if(wdg2)
                        return wdg2;
        }
@@ -211,7 +213,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 +244,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 +319,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();
 }