tdf#120774: in 6.2, restrict workaround to kde4 vclplug only

Fix of tdf#41996 is a workaround of kde4-specific condition and
has been since disabled on OS X (as tdf#51023). kde5 comes with
a new implementation of DnD and slide sorter in Impress now
exhibits exactly the same symptoms as on OS X in tdf#51023

Assuming that in 6.2 kde5 doesn't need this workaround anymore and
remaining platforms -- gtk[23] and Win -- never had issues with DnD
in slide sorter, keep it active only for kde4 vclplug.

We can't kill it with fire in its entirety, because kde4 has been
obsoleted only post-6.2

Change-Id: I1fd8bb9e5142effffbd43f3a8bead417832c808c
Reviewed-on: https://gerrit.libreoffice.org/73403
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx b/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx
index 4a3b066..2505486 100644
--- a/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx
@@ -61,6 +61,7 @@
#include <sfx2/dispatch.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svxids.hrc>
#include <vcl/svapp.hxx>
#include <boost/optional.hpp>
#include <sdmod.hxx>

@@ -225,17 +226,12 @@
    MultiSelectionModeHandler (
        SlideSorter& rSlideSorter,
        SelectionFunction& rSelectionFunction,
#ifndef MACOSX
        const Point& rMouseModelPosition);
#else
        const Point& rMouseModelPosition,
        const sal_uInt32 nEventCode);
#endif
        const sal_uInt32 nEventCode,
        bool bKDE4);
    virtual ~MultiSelectionModeHandler() override;

#ifndef MACOSX
    void Initialize(const sal_uInt32 nEventCode);
#endif

    virtual SelectionFunction::Mode GetMode() const override;
    virtual void Abort() override;
@@ -258,6 +254,7 @@
    bool mbAutoScrollInstalled;
    sal_Int32 mnAnchorIndex;
    sal_Int32 mnSecondIndex;
    bool mbKDE4;

    void UpdateModelPosition (const Point& rMouseModelPosition);
    void UpdateSelection();
@@ -281,18 +278,13 @@
public:
    DragAndDropModeHandler (
        SlideSorter& rSlideSorter,
#ifndef MACOSX
        SelectionFunction& rSelectionFunction);
#else
        SelectionFunction& rSelectionFunction,
        const Point& rMousePosition,
        vcl::Window* pWindow);
#endif
        vcl::Window* pWindow,
        bool bKDE4);
    virtual ~DragAndDropModeHandler() override;

#ifndef MACOSX
    void Initialize(const Point& rMousePosition, vcl::Window* pWindow);
#endif

    virtual SelectionFunction::Mode GetMode() const override;
    virtual void Abort() override;
@@ -303,6 +295,7 @@

private:
    std::unique_ptr<DragAndDropContext, o3tl::default_delete<DragAndDropContext>> mpDragAndDropContext;
    bool mbKDE4;
};

//===== SelectionFunction =====================================================
@@ -322,6 +315,7 @@
      mnShiftKeySelectionAnchor(-1),
      mpModeHandler(new NormalModeHandler(rSlideSorter, *this))
{
    mbKDE4 = Application::GetToolkitName() == "kde4";
}

SelectionFunction::~SelectionFunction()
@@ -684,18 +678,21 @@
{
    if (mpModeHandler->GetMode() != DragAndDropMode)
    {
#ifndef MACOSX
        std::shared_ptr<DragAndDropModeHandler> handler(
            new DragAndDropModeHandler(mrSlideSorter, *this));
        SwitchMode(handler);
        // Delayed initialization, only after mpModeHanler is set, otherwise DND initialization
        // could already trigger DND events, which would recursively trigger this code again,
        // and without mpModeHandler set it would again try to set a new handler.
        handler->Initialize(rMousePosition, mpWindow);
#else
        SwitchMode(std::shared_ptr<ModeHandler>(
            new DragAndDropModeHandler(mrSlideSorter, *this, rMousePosition, mpWindow)));
#endif
        if (mbKDE4)
        {
            std::shared_ptr<DragAndDropModeHandler> handler(
                new DragAndDropModeHandler(mrSlideSorter, *this, rMousePosition, mpWindow, mbKDE4));
            SwitchMode(handler);
            // Delayed initialization, only after mpModeHanler is set, otherwise DND initialization
            // could already trigger DND events, which would recursively trigger this code again,
            // and without mpModeHandler set it would again try to set a new handler.
            handler->Initialize(rMousePosition, mpWindow);
        }
        else
        {
            SwitchMode(std::shared_ptr<ModeHandler>(
                new DragAndDropModeHandler(mrSlideSorter, *this, rMousePosition, mpWindow, mbKDE4)));
        }
    }
}

@@ -704,19 +701,22 @@
    const sal_uInt32 nEventCode)
{
    if (mpModeHandler->GetMode() != MultiSelectionMode)
#ifndef MACOSX
    {
        std::shared_ptr<MultiSelectionModeHandler> handler(
            new MultiSelectionModeHandler(mrSlideSorter, *this, rMousePosition));
        SwitchMode(handler);
        // Delayed initialization, only after mpModeHanler is set, the handle ctor
        // is non-trivial, so it could possibly recurse just like the DND handler above.
        handler->Initialize(nEventCode);
        if (mbKDE4)
        {
            std::shared_ptr<MultiSelectionModeHandler> handler(
                new MultiSelectionModeHandler(mrSlideSorter, *this, rMousePosition, nEventCode, mbKDE4));
            SwitchMode(handler);
            // Delayed initialization, only after mpModeHanler is set, the handle ctor
            // is non-trivial, so it could possibly recurse just like the DND handler above.
            handler->Initialize(nEventCode);
        }
        else
        {
            SwitchMode(std::shared_ptr<ModeHandler>(
                new MultiSelectionModeHandler(mrSlideSorter, *this, rMousePosition, nEventCode, mbKDE4)));
        }
    }
#else
        SwitchMode(std::shared_ptr<ModeHandler>(
            new MultiSelectionModeHandler(mrSlideSorter, *this, rMousePosition, nEventCode)));
#endif
}

void SelectionFunction::SwitchMode (const std::shared_ptr<ModeHandler>& rpHandler)
@@ -1233,26 +1233,24 @@
MultiSelectionModeHandler::MultiSelectionModeHandler (
    SlideSorter& rSlideSorter,
    SelectionFunction& rSelectionFunction,
#ifndef MACOSX
    const Point& rMouseModelPosition)
#else
    const Point& rMouseModelPosition,
    const sal_uInt32 nEventCode)
#endif
    const sal_uInt32 nEventCode,
    bool bKDE4)
    : ModeHandler(rSlideSorter, rSelectionFunction, false),
      meSelectionMode(SM_Normal),
      maSecondCorner(rMouseModelPosition),
      maSavedPointer(mrSlideSorter.GetContentWindow()->GetPointer()),
      mbAutoScrollInstalled(false),
      mnAnchorIndex(-1),
      mnSecondIndex(-1)
      mnSecondIndex(-1),
      mbKDE4(bKDE4)
{
#ifndef MACOSX
    if (!mbKDE4)
        Initialize(nEventCode);
}

void MultiSelectionModeHandler::Initialize(const sal_uInt32 nEventCode)
{
#endif
    const Pointer aSelectionPointer (PointerStyle::Text);
    mrSlideSorter.GetContentWindow()->SetPointer(aSelectionPointer);
    SetSelectionModeFromModifier(nEventCode);
@@ -1461,21 +1459,19 @@

DragAndDropModeHandler::DragAndDropModeHandler (
    SlideSorter& rSlideSorter,
#ifndef MACOSX
    SelectionFunction& rSelectionFunction)
#else
    SelectionFunction& rSelectionFunction,
    const Point& rMousePosition,
    vcl::Window* pWindow)
#endif
    : ModeHandler(rSlideSorter, rSelectionFunction, false)
    vcl::Window* pWindow,
    bool bKDE4)
    : ModeHandler(rSlideSorter, rSelectionFunction, false),
      mbKDE4(bKDE4)
{
#ifndef MACOSX
    if (!mbKDE4)
        Initialize(rMousePosition, pWindow);
}

void DragAndDropModeHandler::Initialize(const Point& rMousePosition, vcl::Window* pWindow)
{
#endif
    SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
    if (pDragTransferable==nullptr && mrSlideSorter.GetViewShell() != nullptr)
    {
diff --git a/sd/source/ui/slidesorter/inc/controller/SlsSelectionFunction.hxx b/sd/source/ui/slidesorter/inc/controller/SlsSelectionFunction.hxx
index 9516e3d..0d6e03f 100644
--- a/sd/source/ui/slidesorter/inc/controller/SlsSelectionFunction.hxx
+++ b/sd/source/ui/slidesorter/inc/controller/SlsSelectionFunction.hxx
@@ -116,6 +116,8 @@
    */
    std::shared_ptr<ModeHandler> mpModeHandler;

    bool mbKDE4;

    /** Make the slide nOffset slides away of the current one the new
        current slide.  When the new index is outside the range of valid
        page numbers it is clipped to that range.