diff options
Diffstat (limited to 'src/gui')
-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. |