tdf#124990: DnD operation can be set to fail in dropComplete

thus we reimplement it for Qt5DropTarget. This is qt5 remix of
tdf#118302 (in Calc drop into the same tab should cancel DnD, instead
of causing data loss)

Change-Id: Ib37ea5a018133779e85e8e131d81bb6cee7d9206
Reviewed-on: https://gerrit.libreoffice.org/71531
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
(cherry picked from commit cc6c1798b8d6d9d27dc40145e1ec71dd480c788a)
Reviewed-on: https://gerrit.libreoffice.org/71569
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/vcl/inc/qt5/Qt5DragAndDrop.hxx b/vcl/inc/qt5/Qt5DragAndDrop.hxx
index 099ba44..3547131 100644
--- a/vcl/inc/qt5/Qt5DragAndDrop.hxx
+++ b/vcl/inc/qt5/Qt5DragAndDrop.hxx
@@ -75,6 +75,8 @@ public:
    void fire_dragEnd(sal_Int8 nAction);

    static Qt5DragSource* m_ActiveDragSource;
    static bool m_bDropSuccessSet;
    static bool m_bDropSuccess;

    css::uno::Reference<css::datatransfer::XTransferable> const& GetTransferable() const
    {
diff --git a/vcl/qt5/Qt5DragAndDrop.cxx b/vcl/qt5/Qt5DragAndDrop.cxx
index adc7a94..42e6107 100644
--- a/vcl/qt5/Qt5DragAndDrop.cxx
+++ b/vcl/qt5/Qt5DragAndDrop.cxx
@@ -94,6 +94,9 @@ std::vector<css::datatransfer::DataFlavor> Qt5DnDTransferable::getTransferDataFl
    return aVector;
}

bool Qt5DragSource::m_bDropSuccessSet = false;
bool Qt5DragSource::m_bDropSuccess = false;

Qt5DragSource::~Qt5DragSource()
{
    //if (m_pFrame)
@@ -140,6 +143,8 @@ void Qt5DragSource::startDrag(
    {
        Qt5Widget* qw = static_cast<Qt5Widget*>(m_pFrame->GetQWidget());
        m_ActiveDragSource = this;
        m_bDropSuccessSet = false;
        m_bDropSuccess = false;
        qw->startDrag(sourceActions);
    }
    else
@@ -165,7 +170,14 @@ void Qt5DragSource::fire_dragEnd(sal_Int8 nAction)
    {
        datatransfer::dnd::DragSourceDropEvent aEv;
        aEv.DropAction = nAction;
        aEv.DropSuccess = true; // FIXME: what if drop didn't work out?

        // internal DnD can accept the drop
        // but still fail in Qt5DropTarget::dropComplete
        if (m_bDropSuccessSet)
            aEv.DropSuccess = m_bDropSuccess;
        else
            aEv.DropSuccess = true;

        auto xListener = m_xListener;
        m_xListener.clear();
        xListener->dragDropEnd(aEv);
@@ -341,6 +353,16 @@ void Qt5DropTarget::rejectDrop()
    return;
}

void Qt5DropTarget::dropComplete(sal_Bool /*success*/) { return; }
void Qt5DropTarget::dropComplete(sal_Bool success)
{
    // internal DnD
    if (Qt5DragSource::m_ActiveDragSource)
    {
        Qt5DragSource::m_bDropSuccessSet = true;
        Qt5DragSource::m_bDropSuccess = success;
    }

    return;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */