summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/button.cpp23
-rw-r--r--src/gui/widgets/button.h4
-rw-r--r--src/guichan/include/guichan/widgets/button.hpp7
-rw-r--r--src/guichan/widgets/button.cpp26
4 files changed, 27 insertions, 33 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index c99f46149..9519c144f 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -448,3 +448,26 @@ void Button::setCaption(const std::string& caption)
mCaption = caption;
// adjustSize();
}
+
+void Button::keyPressed(gcn::KeyEvent& keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == gcn::Key::SPACE)
+ {
+ mKeyPressed = true;
+ keyEvent.consume();
+ }
+}
+
+void Button::keyReleased(gcn::KeyEvent& keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == gcn::Key::SPACE && mKeyPressed)
+ {
+ mKeyPressed = false;
+ distributeActionEvent();
+ keyEvent.consume();
+ }
+}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 6585d9850..8e4cdd9e6 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -113,6 +113,10 @@ class Button : public gcn::Button, public gcn::WidgetListener
void setCaption(const std::string& caption);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
+ void keyReleased(gcn::KeyEvent &keyEvent);
+
private:
void init();
diff --git a/src/guichan/include/guichan/widgets/button.hpp b/src/guichan/include/guichan/widgets/button.hpp
index a934499d0..b8a442c40 100644
--- a/src/guichan/include/guichan/widgets/button.hpp
+++ b/src/guichan/include/guichan/widgets/button.hpp
@@ -162,13 +162,6 @@ namespace gcn
virtual void mouseDragged(MouseEvent& mouseEvent);
-
- // Inherited from KeyListener
-
- virtual void keyPressed(KeyEvent& keyEvent);
-
- virtual void keyReleased(KeyEvent& keyEvent);
-
protected:
/**
* Checks if the button is pressed. Convenient method to use
diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp
index 6ae443705..42dc686f0 100644
--- a/src/guichan/widgets/button.cpp
+++ b/src/guichan/widgets/button.cpp
@@ -241,32 +241,6 @@ namespace gcn
mouseEvent.consume();
}
- void Button::keyPressed(KeyEvent& keyEvent)
- {
- Key key = keyEvent.getKey();
-
- if (key.getValue() == Key::ENTER
- || key.getValue() == Key::SPACE)
- {
- mKeyPressed = true;
- keyEvent.consume();
- }
- }
-
- void Button::keyReleased(KeyEvent& keyEvent)
- {
- Key key = keyEvent.getKey();
-
- if ((key.getValue() == Key::ENTER
- || key.getValue() == Key::SPACE)
- && mKeyPressed)
- {
- mKeyPressed = false;
- distributeActionEvent();
- keyEvent.consume();
- }
- }
-
void Button::focusLost(const Event& event A_UNUSED)
{
mMousePressed = false;