From a6ddfd13f78d8f1a319cc997c81db90bf4b7b8f2 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 9 Mar 2013 20:16:30 +0100 Subject: Make checkbox toggle on space-bar key press (release). --- plugingui/checkbox.cc | 10 ++++++++++ plugingui/checkbox.h | 1 + 2 files changed, 11 insertions(+) diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc index 496de21..5888d3c 100644 --- a/plugingui/checkbox.cc +++ b/plugingui/checkbox.cc @@ -58,6 +58,16 @@ void GUI::CheckBox::registerClickHandler(void (*handler)(void *), void *ptr) this->ptr = ptr; } +void GUI::CheckBox::keyEvent(KeyEvent *e) +{ + if(e->direction != -1) return; + + if(e->keycode == GUI::KeyEvent::KEY_CHARACTER && e->text == " ") { + state = !state; + repaintEvent(NULL); + } +} + void GUI::CheckBox::repaintEvent(GUI::RepaintEvent *e) { // printf("CheckBox::repaintEvent\n"); diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h index 1b8aa23..4b77964 100644 --- a/plugingui/checkbox.h +++ b/plugingui/checkbox.h @@ -49,6 +49,7 @@ public: virtual void repaintEvent(RepaintEvent *e); virtual void buttonEvent(ButtonEvent *e); + virtual void keyEvent(KeyEvent *e); private: bool state; -- cgit v1.2.3