From: Mikko Rasa Date: Mon, 16 Sep 2019 16:30:45 +0000 (+0300) Subject: Remember the last input focus of a Container and restore it when focused X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5bb0cc92a28a7862571249a2512bcd23ed272344;p=libs%2Fgltk.git Remember the last input focus of a Container and restore it when focused --- diff --git a/source/container.cpp b/source/container.cpp index 2322733..03dff11 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -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(); } diff --git a/source/container.h b/source/container.h index 3117236..f16a9ba 100644 --- a/source/container.h +++ b/source/container.h @@ -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 &);