diff --git a/modules/juce_gui_basics/layout/juce_Viewport.cpp b/modules/juce_gui_basics/layout/juce_Viewport.cpp index 4a42a9d92d..d026740e38 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.cpp +++ b/modules/juce_gui_basics/layout/juce_Viewport.cpp @@ -403,23 +403,38 @@ bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelD return false; } +static bool isUpDownKeyPress (const KeyPress& key) +{ + return key == KeyPress::upKey + || key == KeyPress::downKey + || key == KeyPress::pageUpKey + || key == KeyPress::pageDownKey + || key == KeyPress::homeKey + || key == KeyPress::endKey; +} + +static bool isLeftRightKeyPress (const KeyPress& key) +{ + return key == KeyPress::leftKey + || key == KeyPress::rightKey; +} + bool Viewport::keyPressed (const KeyPress& key) { - const bool isUpDownKey = key == KeyPress::upKey - || key == KeyPress::downKey - || key == KeyPress::pageUpKey - || key == KeyPress::pageDownKey - || key == KeyPress::homeKey - || key == KeyPress::endKey; + const bool isUpDownKey = isUpDownKeyPress (key); if (verticalScrollBar.isVisible() && isUpDownKey) return verticalScrollBar.keyPressed (key); - const bool isLeftRightKey = key == KeyPress::leftKey - || key == KeyPress::rightKey; + const bool isLeftRightKey = isLeftRightKeyPress (key); if (horizontalScrollBar.isVisible() && (isUpDownKey || isLeftRightKey)) return horizontalScrollBar.keyPressed (key); return false; } + +bool Viewport::respondsToKey (const KeyPress& key) +{ + return isUpDownKeyPress (key) || isLeftRightKeyPress (key); +} diff --git a/modules/juce_gui_basics/layout/juce_Viewport.h b/modules/juce_gui_basics/layout/juce_Viewport.h index 8ac0f4690c..94404a6267 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.h +++ b/modules/juce_gui_basics/layout/juce_Viewport.h @@ -246,6 +246,8 @@ public: void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override; /** @internal */ bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&); + /** @internal */ + static bool respondsToKey (const KeyPress&); private: //============================================================================== diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.cpp b/modules/juce_gui_basics/widgets/juce_ListBox.cpp index 3cb4fb6a17..6483dc1fd8 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ListBox.cpp @@ -304,12 +304,7 @@ public: bool keyPressed (const KeyPress& key) override { - if (key.isKeyCode (KeyPress::upKey) - || key.isKeyCode (KeyPress::downKey) - || key.isKeyCode (KeyPress::pageUpKey) - || key.isKeyCode (KeyPress::pageDownKey) - || key.isKeyCode (KeyPress::homeKey) - || key.isKeyCode (KeyPress::endKey)) + if (Viewport::respondsToKey (key)) { const int allowableMods = owner.multipleSelection ? ModifierKeys::shiftModifier : 0;