mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-30 02:50:05 +00:00
Merge branch 'bugfix/broken_drag_and_drop'
This commit is contained in:
commit
4f28be946c
3 changed files with 33 additions and 19 deletions
|
|
@ -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 (const 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, const 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);
|
||||
|
|
|
|||
|
|
@ -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 (const 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&, const SparseSet<int>& rowsToDrag,
|
||||
const var& dragDescription, bool allowDraggingToOtherWindows);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
|
|
@ -585,6 +586,9 @@ private:
|
|||
#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
|
||||
// This method's bool parameter has changed: see the new method signature.
|
||||
JUCE_DEPRECATED (void setSelectedRows (const SparseSet<int>&, bool));
|
||||
// This method has been replaced by the more flexible method createSnapshotOfRows.
|
||||
// Please call createSnapshotOfRows (getSelectedRows(), x, y) to get the same behaviour.
|
||||
JUCE_DEPRECATED (virtual void createSnapshotOfSelectedRows (int&, int&)) {}
|
||||
#endif
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ListBox)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue