]> git.tdb.fi Git - libs/gltk.git/commitdiff
Remember the last input focus of a Container and restore it when focused
authorMikko Rasa <tdb@tdb.fi>
Mon, 16 Sep 2019 16:30:45 +0000 (19:30 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 16 Sep 2019 16:30:45 +0000 (19:30 +0300)
source/container.cpp
source/container.h

index 23227331139edab708849e8a63379d78ef5835d1..03dff1137bfdf6416f6d755c61bae65604f8733b 100644 (file)
@@ -17,6 +17,7 @@ Container::Container():
        pointer_focus(0),
        pointer_grabbed(false),
        input_focus(0),
+       saved_input_focus(0),
        touch_focus(0)
 { }
 
@@ -312,8 +313,16 @@ bool Container::character(wchar_t ch)
                return false;
 }
 
+void Container::focus_in()
+{
+       if(saved_input_focus && saved_input_focus->get_parent()==this)
+               set_input_focus(saved_input_focus);
+       Widget::focus_in();
+}
+
 void Container::focus_out()
 {
+       saved_input_focus = input_focus;
        set_input_focus(0);
        Widget::focus_out();
 }
index 3117236daa7463d80961604732de717c778e59f8..f16a9ba5d814b1e21841bdf0b18c4e49cc8a2a79 100644 (file)
@@ -42,6 +42,7 @@ protected:
        Widget *pointer_focus;
        bool pointer_grabbed;
        Widget *input_focus;
+       Widget *saved_input_focus;
        Widget *touch_focus;
 
        Container();
@@ -85,6 +86,7 @@ public:
        virtual bool key_press(unsigned, unsigned);
        virtual bool key_release(unsigned, unsigned);
        virtual bool character(wchar_t);
+       virtual void focus_in();
        virtual void focus_out();
        virtual bool navigate(Navigation);
        virtual void animate(const Time::TimeDelta &);