From: Mikko Rasa Date: Tue, 30 Aug 2016 13:12:22 +0000 (+0300) Subject: Make keyboard event handlers indicate whether the event was handled X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6d73e04329fc3752552773e4d11d7374caf779f6;p=libs%2Fgltk.git Make keyboard event handlers indicate whether the event was handled --- diff --git a/source/container.cpp b/source/container.cpp index d02cc60..068986b 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -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() diff --git a/source/container.h b/source/container.h index 6c75e38..3907bde 100644 --- a/source/container.h +++ b/source/container.h @@ -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(); diff --git a/source/dialog.cpp b/source/dialog.cpp index 2342e84..7b47b66 100644 --- a/source/dialog.cpp +++ b/source/dialog.cpp @@ -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) diff --git a/source/dialog.h b/source/dialog.h index 1925c61..aa4380a 100644 --- a/source/dialog.h +++ b/source/dialog.h @@ -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); diff --git a/source/entry.cpp b/source/entry.cpp index cee23b0..43dad5e 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -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::ustring(1, ch))); ++edit_pos; rebuild(); + return true; } + + return false; } void Entry::focus_out() diff --git a/source/entry.h b/source/entry.h index fbd5f92..72345b7 100644 --- a/source/entry.h +++ b/source/entry.h @@ -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(); diff --git a/source/root.cpp b/source/root.cpp index a90ea5a..c54ab7b 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -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; } diff --git a/source/widget.h b/source/widget.h index 2bf751a..f852ec3 100644 --- a/source/widget.h +++ b/source/widget.h @@ -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: