]> git.tdb.fi Git - libs/gltk.git/commitdiff
Make keyboard event handlers indicate whether the event was handled
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2016 13:12:22 +0000 (16:12 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Aug 2016 13:12:22 +0000 (16:12 +0300)
source/container.cpp
source/container.h
source/dialog.cpp
source/dialog.h
source/entry.cpp
source/entry.h
source/root.cpp
source/widget.h

index d02cc606394298c612bd7c94142298f88ffaf708..068986b15aca7b329626974c6349941a8d68422f 100644 (file)
@@ -272,22 +272,28 @@ void Container::touch_motion(int x, int y, unsigned finger)
        }
 }
 
-void Container::key_press(unsigned key, unsigned mod)
+bool Container::key_press(unsigned key, unsigned mod)
 {
        if(input_focus)
-               input_focus->key_press(key, mod);
+               return input_focus->key_press(key, mod);
+       else
+               return false;
 }
 
-void Container::key_release(unsigned key, unsigned mod)
+bool Container::key_release(unsigned key, unsigned mod)
 {
        if(input_focus)
-               input_focus->key_release(key, mod);
+               return input_focus->key_release(key, mod);
+       else
+               return false;
 }
 
-void Container::character(wchar_t ch)
+bool Container::character(wchar_t ch)
 {
        if(input_focus)
-               input_focus->character(ch);
+               return input_focus->character(ch);
+       else
+               return false;
 }
 
 void Container::focus_out()
index 6c75e38e9625f6a17a14d69209358aa69883351a..3907bde04e1376a25c29ba55d03f4c8a22cd11e2 100644 (file)
@@ -76,9 +76,9 @@ public:
        virtual void touch_press(int, int, unsigned);
        virtual void touch_release(int, int, unsigned);
        virtual void touch_motion(int, int, unsigned);
-       virtual void key_press(unsigned, unsigned);
-       virtual void key_release(unsigned, unsigned);
-       virtual void character(wchar_t);
+       virtual bool key_press(unsigned, unsigned);
+       virtual bool key_release(unsigned, unsigned);
+       virtual bool character(wchar_t);
        virtual void focus_out();
 protected:
        virtual void on_reparent();
index 2342e8483786b6ce5eba91f1a6c497290a70f7da..7b47b66e9571c80800ae9bcd152fd0e1ea06b250 100644 (file)
@@ -23,11 +23,12 @@ void Dialog::button_release(int x, int y, unsigned button)
                delete this;
 }
 
-void Dialog::key_release(unsigned key, unsigned mod)
+bool Dialog::key_release(unsigned key, unsigned mod)
 {
-       Panel::key_release(key, mod);
+       bool result = Panel::key_release(key, mod);
        if(stale)
                delete this;
+       return result;
 }
 
 void Dialog::response(int code)
index 1925c61ee740460cb9897791fdaf6bef8559ed34..aa4380a8881f16f5a855f45bd6c7a0566c0542bb 100644 (file)
@@ -36,7 +36,7 @@ public:
        void add_button(Button &, int);
 
        virtual void button_release(int, int, unsigned);
-       virtual void key_release(unsigned, unsigned);
+       virtual bool key_release(unsigned, unsigned);
 protected:
        void response(int);
 
index cee23b02372904317419fc294a17f783fa457589..43dad5e7de46dbcb69569427c083352eee0aabac 100644 (file)
@@ -125,7 +125,7 @@ void Entry::render_special(const Part &part, GL::Renderer &renderer) const
                slider->render(renderer);
 }
 
-void Entry::key_press(unsigned key, unsigned)
+bool Entry::key_press(unsigned key, unsigned)
 {
        got_key_press = true;
        if(key==Input::KEY_LEFT)
@@ -170,16 +170,23 @@ void Entry::key_press(unsigned key, unsigned)
                else
                        signal_enter.emit();
        }
+       else
+               return false;
+
+       return true;
 }
 
-void Entry::character(wchar_t ch)
+bool Entry::character(wchar_t ch)
 {
        if(got_key_press && ch>=' ')
        {
                text.insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
                ++edit_pos;
                rebuild();
+               return true;
        }
+
+       return false;
 }
 
 void Entry::focus_out()
index fbd5f921054b3a0c17d1ed0a1385475c710831fe..72345b797001c36aa3da241f3a43ef1147ff4a0e 100644 (file)
@@ -69,8 +69,8 @@ private:
        virtual void render_special(const Part &, GL::Renderer &) const;
 
 public:
-       virtual void key_press(unsigned, unsigned);
-       virtual void character(wchar_t);
+       virtual bool key_press(unsigned, unsigned);
+       virtual bool character(wchar_t);
        virtual void focus_out();
 private:
        virtual void on_geometry_change();
index a90ea5a23d9eec4a3b3bacc34b94fb1a912b8b4c..c54ab7b00682b78bd39041eb09565bc46cd3254d 100644 (file)
@@ -210,14 +210,7 @@ bool Root::key_press_event(unsigned key)
 {
        // XXX Modifiers
        if(visible)
-       {
-               Widget *old_focus = input_focus;
-
-               key_press(key, 0);
-
-               if(input_focus || old_focus)
-                       return true;
-       }
+               return key_press(key, 0);
 
        return false;
 }
@@ -225,14 +218,7 @@ bool Root::key_press_event(unsigned key)
 bool Root::key_release_event(unsigned key)
 {
        if(visible)
-       {
-               Widget *old_focus = input_focus;
-
-               key_release(key, 0);
-
-               if(input_focus || old_focus)
-                       return true;
-       }
+               return key_release(key, 0);
 
        return false;
 }
@@ -240,14 +226,7 @@ bool Root::key_release_event(unsigned key)
 bool Root::character_event(StringCodec::unichar ch)
 {
        if(visible)
-       {
-               Widget *old_focus = input_focus;
-
-               character(ch);
-
-               if(input_focus || old_focus)
-                       return true;
-       }
+               return character(ch);
 
        return false;
 }
index 2bf751a714f0db3a25bc45015894181fe3c96562..f852ec354f4874c75bf91945090ab4330c9bc342 100644 (file)
@@ -139,9 +139,9 @@ public:
        virtual void touch_press(int, int, unsigned);
        virtual void touch_release(int, int, unsigned);
        virtual void touch_motion(int, int, unsigned);
-       virtual void key_press(unsigned, unsigned) { }
-       virtual void key_release(unsigned, unsigned) { }
-       virtual void character(wchar_t) { }
+       virtual bool key_press(unsigned, unsigned) { return false; }
+       virtual bool key_release(unsigned, unsigned) { return false; }
+       virtual bool character(wchar_t) { return false; }
        virtual void focus_in();
        virtual void focus_out();
 protected: