mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-15 00:24:19 +00:00
Fix for listbox mousewheeling when using select-on-mouse-move mode.
This commit is contained in:
parent
e10dfff1af
commit
1bf9f441e6
3 changed files with 41 additions and 30 deletions
|
|
@ -240,7 +240,7 @@ public:
|
|||
/** @internal */
|
||||
void resized();
|
||||
/** @internal */
|
||||
void scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart);
|
||||
void scrollBarMoved (ScrollBar*, double newRangeStart);
|
||||
/** @internal */
|
||||
void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&);
|
||||
/** @internal */
|
||||
|
|
|
|||
|
|
@ -157,7 +157,6 @@ public:
|
|||
|
||||
Component* const content = new Component();
|
||||
setViewedComponent (content);
|
||||
content->addMouseListener (this, false);
|
||||
content->setWantsKeyboardFocus (false);
|
||||
}
|
||||
|
||||
|
|
@ -335,18 +334,42 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ListViewport)
|
||||
};
|
||||
|
||||
enum { defaultListRowHeight = 22 };
|
||||
//==============================================================================
|
||||
class ListBoxMouseMoveSelector : public MouseListener
|
||||
{
|
||||
public:
|
||||
ListBoxMouseMoveSelector (ListBox& lb) : owner (lb)
|
||||
{
|
||||
owner.addMouseListener (this, true);
|
||||
}
|
||||
|
||||
void mouseMove (const MouseEvent& e)
|
||||
{
|
||||
const MouseEvent e2 (e.getEventRelativeTo (&owner));
|
||||
owner.selectRow (owner.getRowContainingPosition (e2.x, e2.y), true);
|
||||
}
|
||||
|
||||
void mouseExit (const MouseEvent& e)
|
||||
{
|
||||
mouseMove (e);
|
||||
}
|
||||
|
||||
private:
|
||||
ListBox& owner;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ListBoxMouseMoveSelector)
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
ListBox::ListBox (const String& name, ListBoxModel* const m)
|
||||
: Component (name),
|
||||
model (m),
|
||||
totalItems (0),
|
||||
rowHeight (defaultListRowHeight),
|
||||
rowHeight (22),
|
||||
minimumRowWidth (0),
|
||||
outlineThickness (0),
|
||||
lastRowSelected (-1),
|
||||
mouseMoveSelects (false),
|
||||
multipleSelection (false),
|
||||
hasDoneInitialUpdate (false)
|
||||
{
|
||||
|
|
@ -379,10 +402,15 @@ void ListBox::setMultipleSelectionEnabled (bool b)
|
|||
|
||||
void ListBox::setMouseMoveSelectsRows (bool b)
|
||||
{
|
||||
mouseMoveSelects = b;
|
||||
|
||||
if (b)
|
||||
addMouseListener (this, true);
|
||||
{
|
||||
if (mouseMoveSelector == nullptr)
|
||||
mouseMoveSelector = new ListBoxMouseMoveSelector (*this);
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseMoveSelector = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -528,7 +556,7 @@ void ListBox::selectRangeOfRows (int firstRow, int lastRow)
|
|||
{
|
||||
const int numRows = totalItems - 1;
|
||||
firstRow = jlimit (0, jmax (0, numRows), firstRow);
|
||||
lastRow = jlimit (0, jmax (0, numRows), lastRow);
|
||||
lastRow = jlimit (0, jmax (0, numRows), lastRow);
|
||||
|
||||
selected.addRange (Range <int> (jmin (firstRow, lastRow),
|
||||
jmax (firstRow, lastRow) + 1));
|
||||
|
|
@ -766,13 +794,13 @@ void ListBox::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& whee
|
|||
{
|
||||
bool eventWasUsed = false;
|
||||
|
||||
if (viewport->getHorizontalScrollBar()->isVisible() && wheel.deltaX != 0)
|
||||
if (wheel.deltaX != 0 && viewport->getHorizontalScrollBar()->isVisible())
|
||||
{
|
||||
eventWasUsed = true;
|
||||
viewport->getHorizontalScrollBar()->mouseWheelMove (e, wheel);
|
||||
}
|
||||
|
||||
if (viewport->getVerticalScrollBar()->isVisible() && wheel.deltaY != 0)
|
||||
if (wheel.deltaY != 0 && viewport->getVerticalScrollBar()->isVisible())
|
||||
{
|
||||
eventWasUsed = true;
|
||||
viewport->getVerticalScrollBar()->mouseWheelMove (e, wheel);
|
||||
|
|
@ -782,20 +810,6 @@ void ListBox::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& whee
|
|||
Component::mouseWheelMove (e, wheel);
|
||||
}
|
||||
|
||||
void ListBox::mouseMove (const MouseEvent& e)
|
||||
{
|
||||
if (mouseMoveSelects)
|
||||
{
|
||||
const MouseEvent e2 (e.getEventRelativeTo (this));
|
||||
selectRow (getRowContainingPosition (e2.x, e2.y), true);
|
||||
}
|
||||
}
|
||||
|
||||
void ListBox::mouseExit (const MouseEvent& e)
|
||||
{
|
||||
mouseMove (e);
|
||||
}
|
||||
|
||||
void ListBox::mouseUp (const MouseEvent& e)
|
||||
{
|
||||
if (e.mouseWasClicked() && model != nullptr)
|
||||
|
|
|
|||
|
|
@ -541,10 +541,6 @@ public:
|
|||
/** @internal */
|
||||
void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&);
|
||||
/** @internal */
|
||||
void mouseMove (const MouseEvent&);
|
||||
/** @internal */
|
||||
void mouseExit (const MouseEvent&);
|
||||
/** @internal */
|
||||
void mouseUp (const MouseEvent&);
|
||||
/** @internal */
|
||||
void colourChanged();
|
||||
|
|
@ -560,10 +556,11 @@ private:
|
|||
ListBoxModel* model;
|
||||
ScopedPointer<ListViewport> viewport;
|
||||
ScopedPointer<Component> headerComponent;
|
||||
ScopedPointer<MouseListener> mouseMoveSelector;
|
||||
int totalItems, rowHeight, minimumRowWidth;
|
||||
int outlineThickness;
|
||||
int lastRowSelected;
|
||||
bool mouseMoveSelects, multipleSelection, hasDoneInitialUpdate;
|
||||
bool multipleSelection, hasDoneInitialUpdate;
|
||||
SparseSet <int> selected;
|
||||
|
||||
void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue