1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

fixed drag and drop behaviour of ListBox for the new case selectOnMouseDown == false

This commit is contained in:
Timur Doumler 2015-04-21 16:14:56 +01:00
parent 9bb0be09a6
commit 9b7d2cb8d6
3 changed files with 30 additions and 19 deletions

View file

@ -106,16 +106,21 @@ public:
{
if (isEnabled() && ! (e.mouseWasClicked() || isDragging))
{
const SparseSet<int> selectedRows (owner.getSelectedRows());
SparseSet<int> rowsToDrag;
if (owner.selectOnMouseDown || owner.isRowSelected (row))
rowsToDrag = owner.getSelectedRows();
else
rowsToDrag.addRange (Range<int>::withStartAndLength (row, 1));
if (selectedRows.size() > 0)
if (rowsToDrag.size() > 0)
{
const var dragDescription (m->getDragSourceDescription (selectedRows));
const var dragDescription (m->getDragSourceDescription (rowsToDrag));
if (! (dragDescription.isVoid() || (dragDescription.isString() && dragDescription.toString().isEmpty())))
{
isDragging = true;
owner.startDragAndDrop (e, dragDescription, true);
owner.startDragAndDrop (e, rowsToDrag, dragDescription, true);
}
}
}
@ -881,7 +886,7 @@ void ListBox::repaintRow (const int rowNumber) noexcept
repaint (getRowPosition (rowNumber, true));
}
Image ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
Image ListBox::createSnapshotOfRows (SparseSet<int> rows, int& imageX, int& imageY)
{
Rectangle<int> imageArea;
const int firstRow = getRowContainingPosition (0, viewport->getY());
@ -890,7 +895,7 @@ Image ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
{
Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
if (rowComp != nullptr && isRowSelected (firstRow + i))
if (rowComp != nullptr && rows.contains (firstRow + i))
{
const Point<int> pos (getLocalPoint (rowComp, Point<int>()));
const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
@ -907,7 +912,7 @@ Image ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
{
Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
if (rowComp != nullptr && isRowSelected (firstRow + i))
if (rowComp != nullptr && rows.contains (firstRow + i))
{
Graphics g (snapshot);
g.setOrigin (getLocalPoint (rowComp, Point<int>()) - imageArea.getPosition());
@ -924,13 +929,13 @@ Image ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
return snapshot;
}
void ListBox::startDragAndDrop (const MouseEvent& e, const var& dragDescription, bool allowDraggingToOtherWindows)
void ListBox::startDragAndDrop (const MouseEvent& e, SparseSet<int> rowsToDrag, const var& dragDescription, bool allowDraggingToOtherWindows)
{
if (DragAndDropContainer* const dragContainer = DragAndDropContainer::findParentDragContainerFor (this))
{
int x, y;
Image dragImage (createSnapshotOfSelectedRows (x, y));
Image dragImage = createSnapshotOfRows (rowsToDrag, x, y);
MouseEvent e2 (e.getEventRelativeTo (this));
const Point<int> p (x - e2.x, y - e2.y);
dragContainer->startDragging (dragDescription, this, dragImage, allowDraggingToOtherWindows, &p);

View file

@ -146,7 +146,7 @@ public:
@see DragAndDropContainer::startDragging
*/
virtual var getDragSourceDescription (const SparseSet<int>& currentlySelectedRows);
virtual var getDragSourceDescription (const SparseSet<int>& rowsToDescribe);
/** You can override this to provide tool tips for specific rows.
@see TooltipClient
@ -518,8 +518,8 @@ public:
*/
void repaintRow (int rowNumber) noexcept;
/** This fairly obscure method creates an image that just shows the currently
selected row components.
/** This fairly obscure method creates an image that shows the row components specified
in rows (for example, these could be the currently selected row components).
It's a handy method for doing drag-and-drop, as it can be passed to the
DragAndDropContainer for use as the drag image.
@ -530,7 +530,7 @@ public:
@see Component::createComponentSnapshot
*/
virtual Image createSnapshotOfSelectedRows (int& x, int& y);
virtual Image createSnapshotOfRows (SparseSet<int> rows, int& x, int& y);
/** Returns the viewport that this ListBox uses.
@ -561,7 +561,8 @@ public:
/** @internal */
void parentHierarchyChanged() override;
/** @internal */
void startDragAndDrop (const MouseEvent&, const var& dragDescription, bool allowDraggingToOtherWindows);
void startDragAndDrop (const MouseEvent&, SparseSet<int> rowsToDrag,
const var& dragDescription, bool allowDraggingToOtherWindows);
private:
//==============================================================================

View file

@ -146,16 +146,21 @@ public:
{
if (isEnabled() && owner.getModel() != nullptr && ! (e.mouseWasClicked() || isDragging))
{
const SparseSet<int> selectedRows (owner.getSelectedRows());
SparseSet<int> rowsToDrag;
if (owner.selectOnMouseDown || owner.isRowSelected (row))
rowsToDrag = owner.getSelectedRows();
else
rowsToDrag.addRange (Range<int>::withStartAndLength (row, 1));
if (selectedRows.size() > 0)
if (rowsToDrag.size() > 0)
{
const var dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
const var dragDescription (owner.getModel()->getDragSourceDescription (rowsToDrag));
if (! (dragDescription.isVoid() || (dragDescription.isString() && dragDescription.toString().isEmpty())))
{
isDragging = true;
owner.startDragAndDrop (e, dragDescription, true);
owner.startDragAndDrop (e, rowsToDrag, dragDescription, true);
}
}
}