diff options
author | Tametomo <irarice@gmail.com> | 2009-04-20 02:14:19 -0600 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-04-20 22:23:44 +0200 |
commit | 899f8e62b670726c61f8105f2226de448b180a19 (patch) | |
tree | 26ded058d794f2eb5345fbc5f2819b68d152d6a4 /src/gui/widgets | |
parent | 4244e0f4b1cb1973ed2919dfbb4ce5beaf3eff96 (diff) | |
download | mana-899f8e62b670726c61f8105f2226de448b180a19.tar.gz mana-899f8e62b670726c61f8105f2226de448b180a19.tar.bz2 mana-899f8e62b670726c61f8105f2226de448b180a19.tar.xz mana-899f8e62b670726c61f8105f2226de448b180a19.zip |
Fixed key handling in dropdowns when the dropdown portion isn't visible.
Signed-off-by: Tametomo <irarice@gmail.com>
Signed-off-by: Bjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 46 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 10 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 8688e07d..491e6396 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -25,6 +25,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/palette.h" +#include "gui/sdlinput.h" #include "configuration.h" #include "graphics.h" @@ -188,3 +189,48 @@ void DropDown::drawButton(gcn::Graphics *graphics) static_cast<Graphics*>(graphics)-> drawImage(buttons[mDroppedDown][mPushed], getWidth() - height + 2, 1); } + +// -- KeyListener notifications +void DropDown::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + { + if (!mDroppedDown) + dropDown(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelected(getSelected() - 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setSelected(getSelected() + 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == Key::END) + { + setSelected(mListBox->getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } +} + +void DropDown::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) +{ + setSelected(getSelected() - 1); + mouseEvent.consume(); +} + +void DropDown::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) +{ + setSelected(getSelected() + 1); + mouseEvent.consume(); +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 83d43f63..e593b4e0 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -53,6 +53,16 @@ class DropDown : public gcn::DropDown void drawFrame(gcn::Graphics *graphics); + // Inherited from KeyListener + + void keyPressed(gcn::KeyEvent& keyEvent); + + // Inherited from MouseListener + + void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + + void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + protected: /** * Draws the button with the little down arrow. |