Browse Source

Changed ListBox to pass-on left/right key events.

tags/2021-05-28
jules 12 years ago
parent
commit
023b9ac6cc
3 changed files with 26 additions and 14 deletions
  1. +23
    -8
      modules/juce_gui_basics/layout/juce_Viewport.cpp
  2. +2
    -0
      modules/juce_gui_basics/layout/juce_Viewport.h
  3. +1
    -6
      modules/juce_gui_basics/widgets/juce_ListBox.cpp

+ 23
- 8
modules/juce_gui_basics/layout/juce_Viewport.cpp View File

@@ -403,23 +403,38 @@ bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelD
return false; 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) 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) if (verticalScrollBar.isVisible() && isUpDownKey)
return verticalScrollBar.keyPressed (key); return verticalScrollBar.keyPressed (key);
const bool isLeftRightKey = key == KeyPress::leftKey
|| key == KeyPress::rightKey;
const bool isLeftRightKey = isLeftRightKeyPress (key);
if (horizontalScrollBar.isVisible() && (isUpDownKey || isLeftRightKey)) if (horizontalScrollBar.isVisible() && (isUpDownKey || isLeftRightKey))
return horizontalScrollBar.keyPressed (key); return horizontalScrollBar.keyPressed (key);
return false; return false;
} }
bool Viewport::respondsToKey (const KeyPress& key)
{
return isUpDownKeyPress (key) || isLeftRightKeyPress (key);
}

+ 2
- 0
modules/juce_gui_basics/layout/juce_Viewport.h View File

@@ -246,6 +246,8 @@ public:
void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override; void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
/** @internal */ /** @internal */
bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&); bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&);
/** @internal */
static bool respondsToKey (const KeyPress&);
private: private:
//============================================================================== //==============================================================================


+ 1
- 6
modules/juce_gui_basics/widgets/juce_ListBox.cpp View File

@@ -304,12 +304,7 @@ public:
bool keyPressed (const KeyPress& key) override 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; const int allowableMods = owner.multipleSelection ? ModifierKeys::shiftModifier : 0;


Loading…
Cancel
Save