solenv/clang-format/excludelist        |    2 
 vcl/inc/dndhelper.hxx                  |   41 ++++++++++++++++++
 vcl/inc/osx/salinst.h                  |    4 -
 vcl/inc/qt5/QtInstance.hxx             |    6 +-
 vcl/inc/salinst.hxx                    |   10 +++-
 vcl/inc/unx/gtk/gtkinst.hxx            |    4 -
 vcl/inc/unx/salinst.h                  |    4 -
 vcl/inc/win/dnd_source.hxx             |    1 
 vcl/inc/win/dnd_target.hxx             |    1 
 vcl/inc/win/salinst.h                  |    3 +
 vcl/osx/service_entry.cxx              |   23 +++-------
 vcl/qt5/QtInstance.cxx                 |   14 +++---
 vcl/source/app/dndhelp.cxx             |   28 ++++++++++++
 vcl/source/components/dtranscomp.cxx   |   25 +++++++++--
 vcl/source/window/mouse.cxx            |   73 +++++----------------------------
 vcl/unx/generic/dtrans/X11_service.cxx |   21 ++-------
 vcl/unx/gtk3/gtkinst.cxx               |   21 ++-------
 vcl/win/app/salinst.cxx                |   18 ++++++++
 vcl/win/dtrans/idroptarget.hxx         |    2 
 vcl/win/dtrans/source.cxx              |    2 
 vcl/win/dtrans/sourcecontext.hxx       |    2 
 vcl/win/dtrans/target.cxx              |    2 
 vcl/win/dtrans/targetdragcontext.hxx   |    3 -
 vcl/win/dtrans/targetdropcontext.hxx   |    2 
 24 files changed, 177 insertions(+), 135 deletions(-)

New commits:
commit 031576105c21b2e0c2585a1236092487d5d193e2
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Thu Jan 6 14:16:53 2022 +0100
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Fri Jan 7 05:04:14 2022 +0100

    VCL move platform code from mouse.cxx into plugins
    
    ... by moving it into ImplCreate(DragSource|DropTarget).
    
    The existing Create* variant now checks for headless mode and the
    IsRunningUnitTest flag, before creating the platform variants.
    There are two small helpers to initialize either X11 or Ole based
    UNO DnD interace implementations.
    
    Unfortunatly Windows requires to move two dtrans header files, but
    at least any other changes are minimal.
    
    Change-Id: Id79459ad71a26243b1c9cb1fe38ab236b0ab8fa6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128049
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index 22c11a641d36..b8bebd05da48 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -14612,6 +14612,7 @@ vcl/inc/unx/x11_cursors/vshear_curs.h
 vcl/inc/unx/x11_cursors/vshear_mask.h
 vcl/inc/vclstatuslistener.hxx
 vcl/inc/wall2.hxx
+vcl/inc/win/dnd_source.hxx
 vcl/inc/win/DWriteTextRenderer.hxx
 vcl/inc/win/salbmp.h
 vcl/inc/win/saldata.hxx
@@ -15194,7 +15195,6 @@ vcl/win/dtrans/MtaOleClipb.cxx
 vcl/win/dtrans/MtaOleClipb.hxx
 vcl/win/dtrans/sourcecontext.cxx
 vcl/win/dtrans/source.cxx
-vcl/win/dtrans/source.hxx
 vcl/win/dtrans/target.cxx
 vcl/win/dtrans/TxtCnvtHlp.cxx
 vcl/win/dtrans/TxtCnvtHlp.hxx
diff --git a/vcl/inc/dndhelper.hxx b/vcl/inc/dndhelper.hxx
new file mode 100644
index 000000000000..f79382f4ee3a
--- /dev/null
+++ b/vcl/inc/dndhelper.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <vcl/dllapi.h>
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star::lang
+{
+class XInitialization;
+}
+namespace com::sun::star::uno
+{
+class XInterface;
+}
+
+namespace vcl
+{
+// Ole and X11 refer to the UNO DnD interface names and their expected 
XInitialization arguments.
+
+enum class DragOrDrop
+{
+    Drag,
+    Drop
+};
+VCL_DLLPUBLIC css::uno::Reference<css::uno::XInterface>
+OleDnDHelper(const css::uno::Reference<css::lang::XInitialization>&, 
sal_IntPtr pWin, DragOrDrop);
+
+VCL_DLLPUBLIC css::uno::Reference<css::uno::XInterface>
+X11DnDHelper(const css::uno::Reference<css::lang::XInitialization>&, 
sal_IntPtr pWin);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index 3be765057ca9..6d707807d38e 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -128,8 +128,8 @@ public:
     // dtrans implementation
     virtual css::uno::Reference< css::uno::XInterface > CreateClipboard(
             const css::uno::Sequence< css::uno::Any >& i_rArguments ) override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDragSource() 
override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget() 
override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDragSource(const SystemEnvData*) override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDropTarget(const SystemEnvData*) override;
 
     static void handleAppDefinedEvent( NSEvent* pEvent );
 
diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx
index 009b9ae8c312..b02dd6234633 100644
--- a/vcl/inc/qt5/QtInstance.hxx
+++ b/vcl/inc/qt5/QtInstance.hxx
@@ -158,8 +158,10 @@ public:
 
     virtual css::uno::Reference<css::uno::XInterface>
     CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) 
override;
-    virtual css::uno::Reference<css::uno::XInterface> CreateDragSource() 
override;
-    virtual css::uno::Reference<css::uno::XInterface> CreateDropTarget() 
override;
+    virtual css::uno::Reference<css::uno::XInterface>
+    ImplCreateDragSource(const SystemEnvData*) override;
+    virtual css::uno::Reference<css::uno::XInterface>
+    ImplCreateDropTarget(const SystemEnvData*) override;
 
     void UpdateStyle(bool bFontsChanged);
 
diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx
index 7d42cb51011b..a807d5c263f3 100644
--- a/vcl/inc/salinst.hxx
+++ b/vcl/inc/salinst.hxx
@@ -63,6 +63,7 @@ class SalSystem;
 class SalBitmap;
 struct SalItemParams;
 class SalSession;
+struct SystemEnvData;
 struct SystemGraphicsData;
 struct SystemWindowData;
 class Menu;
@@ -179,8 +180,10 @@ public:
 
     // dtrans implementation
     virtual css::uno::Reference< css::uno::XInterface > CreateClipboard( const 
css::uno::Sequence< css::uno::Any >& i_rArguments );
-    virtual css::uno::Reference< css::uno::XInterface > CreateDragSource();
-    virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget();
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDragSource(const SystemEnvData*);
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDropTarget(const SystemEnvData*);
+    css::uno::Reference<css::uno::XInterface> CreateDragSource(const 
SystemEnvData* = nullptr);
+    css::uno::Reference<css::uno::XInterface> CreateDropTarget(const 
SystemEnvData* = nullptr);
     virtual void            AddToRecentDocumentList(const OUString& rFileUrl, 
const OUString& rMimeType, const OUString& rDocumentService) = 0;
 
     virtual bool            hasNativeFileSelection() const { return false; }
@@ -208,6 +211,9 @@ public:
     virtual void* CreateGStreamerSink(const SystemChildWindow*) { return 
nullptr; }
 
     virtual void BeforeAbort(const OUString& /* rErrorText */, bool /* 
bDumpCore */) {}
+
+    // Note: we cannot make this a global variable, because it might be 
initialised BEFORE the putenv() call in cppunittester.
+    static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; 
}
 };
 
 // called from SVMain
diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx
index d40779d7f18f..8e243490b889 100644
--- a/vcl/inc/unx/gtk/gtkinst.hxx
+++ b/vcl/inc/unx/gtk/gtkinst.hxx
@@ -286,8 +286,8 @@ public:
         createFolderPicker( const css::uno::Reference< 
css::uno::XComponentContext >& ) override;
 
     virtual css::uno::Reference< css::uno::XInterface > CreateClipboard( const 
css::uno::Sequence< css::uno::Any >& i_rArguments ) override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDragSource() 
override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget() 
override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDragSource(const SystemEnvData*) override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDropTarget(const SystemEnvData*) override;
     virtual OpenGLContext* CreateOpenGLContext() override;
     virtual std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* 
pParent, const OUString& rUIRoot, const OUString& rUIFile) override;
     virtual std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* 
pParent, const OUString& rUIRoot, const OUString& rUIFile,
diff --git a/vcl/inc/unx/salinst.h b/vcl/inc/unx/salinst.h
index 75a5cd6ae5ab..1f8ccd92b19c 100644
--- a/vcl/inc/unx/salinst.h
+++ b/vcl/inc/unx/salinst.h
@@ -80,8 +80,8 @@ public:
     // dtrans implementation
     virtual css::uno::Reference< css::uno::XInterface >
         CreateClipboard( const css::uno::Sequence< css::uno::Any >& 
i_rArguments ) override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDragSource() 
override;
-    virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget() 
override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDragSource(const SystemEnvData*) override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDropTarget(const SystemEnvData*) override;
     virtual void            AddToRecentDocumentList(const OUString& rFileUrl, 
const OUString& rMimeType, const OUString& rDocumentService) override;
 };
 
diff --git a/vcl/win/dtrans/source.hxx b/vcl/inc/win/dnd_source.hxx
similarity index 99%
rename from vcl/win/dtrans/source.hxx
rename to vcl/inc/win/dnd_source.hxx
index f2124932be79..ea794f069f47 100644
--- a/vcl/win/dtrans/source.hxx
+++ b/vcl/inc/win/dnd_source.hxx
@@ -26,7 +26,6 @@
 #include <cppuhelper/basemutex.hxx>
 #include <cppuhelper/compbase.hxx>
 #include <com/sun/star/lang/XServiceInfo.hpp>
-#include "globals.hxx"
 #include <oleidl.h>
 
 #include <systools/win32/comtools.hxx>
diff --git a/vcl/win/dtrans/target.hxx b/vcl/inc/win/dnd_target.hxx
similarity index 99%
rename from vcl/win/dtrans/target.hxx
rename to vcl/inc/win/dnd_target.hxx
index 36dcbc8c1141..4c4e8eebcdee 100644
--- a/vcl/win/dtrans/target.hxx
+++ b/vcl/inc/win/dnd_target.hxx
@@ -29,7 +29,6 @@
 #include <osl/mutex.hxx>
 
 #include <oleidl.h>
-#include "globals.hxx"
 
 namespace com::sun::star::uno
 {
diff --git a/vcl/inc/win/salinst.h b/vcl/inc/win/salinst.h
index bde64dd1bb8d..c312b8b18c14 100644
--- a/vcl/inc/win/salinst.h
+++ b/vcl/inc/win/salinst.h
@@ -76,6 +76,9 @@ public:
     virtual void BeforeAbort(const OUString&, bool) override;
 
     static int WorkaroundExceptionHandlingInUSER32Lib(int nExcept, 
LPEXCEPTION_POINTERS pExceptionInfo);
+
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDragSource(const SystemEnvData*) override;
+    virtual css::uno::Reference<css::uno::XInterface> 
ImplCreateDropTarget(const SystemEnvData*) override;
 };
 
 SalFrame* ImplSalCreateFrame( WinSalInstance* pInst, HWND hWndParent, 
SalFrameStyleFlags nSalFrameStyle );
diff --git a/vcl/osx/service_entry.cxx b/vcl/osx/service_entry.cxx
index 73fd2aa9c958..849e73a77dcd 100644
--- a/vcl/osx/service_entry.cxx
+++ b/vcl/osx/service_entry.cxx
@@ -19,6 +19,8 @@
 
 
 #include <vcl/svapp.hxx>
+#include <dndhelper.hxx>
+#include <vcl/sysdata.hxx>
 
 #include <osx/saldata.hxx>
 #include <osx/salinst.h>
@@ -34,11 +36,6 @@ using namespace ::cppu;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::datatransfer::clipboard;
 
-// We run unit tests in parallel, which is a problem when touching a shared 
resource
-// the system clipboard, so rather use the dummy GenericClipboard.
-// Note, cannot make this a global variable, because it might be initialised 
BEFORE the putenv() call in cppunittester.
-static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
-
 uno::Reference< XInterface > AquaSalInstance::CreateClipboard( const Sequence< 
Any >& i_rArguments )
 {
     if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
@@ -50,20 +47,16 @@ uno::Reference< XInterface > 
AquaSalInstance::CreateClipboard( const Sequence< A
     return pSalData->mxClipboard;
 }
 
-uno::Reference<XInterface> AquaSalInstance::CreateDragSource()
+uno::Reference<XInterface> AquaSalInstance::ImplCreateDragSource(const 
SystemEnvData* pSysEnv)
 {
-    if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
-        return SalInstance::CreateDragSource();
-
-    return uno::Reference<XInterface>(static_cast< XInitialization* >(new 
DragSource()), UNO_QUERY);
+    return vcl::OleDnDHelper(new DragSource(), 
reinterpret_cast<sal_IntPtr>(pSysEnv->mpNSView),
+                             vcl::DragOrDrop::Drag);
 }
 
-uno::Reference<XInterface> AquaSalInstance::CreateDropTarget()
+uno::Reference<XInterface> AquaSalInstance::ImplCreateDropTarget(const 
SystemEnvData* pSysEnv)
 {
-    if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
-        return SalInstance::CreateDropTarget();
-
-    return uno::Reference<XInterface>(static_cast< XInitialization* >(new 
DropTarget()), UNO_QUERY);
+    return vcl::OleDnDHelper(new DropTarget(), 
reinterpret_cast<sal_IntPtr>(pSysEnv->mpNSView),
+                             vcl::DragOrDrop::Drop);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index 29a7d0e4ddf7..cde8924915a2 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -46,6 +46,8 @@
 #include <vclpluginapi.h>
 #include <tools/debug.hxx>
 #include <comphelper/flagguard.hxx>
+#include <dndhelper.hxx>
+#include <vcl/sysdata.hxx>
 #include <sal/log.hxx>
 #include <osl/process.h>
 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && ENABLE_GSTREAMER_1_0 && 
QT5_HAVE_GOBJECT
@@ -531,16 +533,16 @@ QtInstance::CreateClipboard(const 
css::uno::Sequence<css::uno::Any>& arguments)
     return xClipboard;
 }
 
-css::uno::Reference<css::uno::XInterface> QtInstance::CreateDragSource()
+css::uno::Reference<css::uno::XInterface>
+QtInstance::ImplCreateDragSource(const SystemEnvData* pSysEnv)
 {
-    return css::uno::Reference<css::uno::XInterface>(
-        static_cast<cppu::OWeakObject*>(new QtDragSource()));
+    return vcl::X11DnDHelper(new QtDragSource(), pSysEnv->aShellWindow);
 }
 
-css::uno::Reference<css::uno::XInterface> QtInstance::CreateDropTarget()
+css::uno::Reference<css::uno::XInterface>
+QtInstance::ImplCreateDropTarget(const SystemEnvData* pSysEnv)
 {
-    return css::uno::Reference<css::uno::XInterface>(
-        static_cast<cppu::OWeakObject*>(new QtDropTarget()));
+    return vcl::X11DnDHelper(new QtDropTarget(), pSysEnv->aShellWindow);
 }
 
 IMPL_LINK_NOARG(QtInstance, updateStyleHdl, Timer*, void)
diff --git a/vcl/source/app/dndhelp.cxx b/vcl/source/app/dndhelp.cxx
index ff4beb7898b8..d4d6ea059f06 100644
--- a/vcl/source/app/dndhelp.cxx
+++ b/vcl/source/app/dndhelp.cxx
@@ -19,8 +19,14 @@
 
 #include <vcl/dndhelp.hxx>
 
+#include <vcl/svapp.hxx>
+#include <dndhelper.hxx>
+
 #include <cppuhelper/queryinterface.hxx>
 
+#include <com/sun/star/awt/XDisplayConnection.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+
 using namespace ::com::sun::star;
 
 vcl::unohelper::DragAndDropClient::~DragAndDropClient() 
COVERITY_NOEXCEPT_FALSE {}
@@ -136,4 +142,26 @@ void 
vcl::unohelper::DragAndDropWrapper::dropActionChanged( const css::datatrans
 {
 }
 
+css::uno::Reference<css::uno::XInterface>
+vcl::OleDnDHelper(const css::uno::Reference<css::lang::XInitialization>& pDnD, 
const sal_IntPtr pWin, DragOrDrop eDoD)
+{
+    if (pWin && pDnD)
+    {
+        if (eDoD == vcl::DragOrDrop::Drag)
+            pDnD->initialize({ uno::Any(), 
uno::Any(static_cast<sal_uInt64>(pWin)) });
+        else
+            pDnD->initialize({ uno::Any(static_cast<sal_uInt64>(pWin)), 
uno::Any() });
+    }
+    return css::uno::Reference<css::uno::XInterface>(pDnD);
+}
+
+css::uno::Reference<css::uno::XInterface>
+vcl::X11DnDHelper(const css::uno::Reference<css::lang::XInitialization>& pDnD, 
const sal_IntPtr pWin)
+{
+    if (pWin && pDnD)
+        pDnD->initialize({ uno::Any(Application::GetDisplayConnection()),
+                           uno::Any(static_cast<sal_uInt64>(pWin)) });
+    return css::uno::Reference<css::uno::XInterface>(pDnD);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/components/dtranscomp.cxx 
b/vcl/source/components/dtranscomp.cxx
index acd03cc01912..a01fde73a649 100644
--- a/vcl/source/components/dtranscomp.cxx
+++ b/vcl/source/components/dtranscomp.cxx
@@ -436,14 +436,31 @@ Reference< XInterface > SalInstance::CreateClipboard( 
const Sequence< Any >& arg
     return m_clipboard;
 }
 
-Reference< XInterface > SalInstance::CreateDragSource()
+uno::Reference<uno::XInterface> SalInstance::ImplCreateDragSource(const 
SystemEnvData*)
 {
-    return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new 
vcl::GenericDragSource()) );
+    return css::uno::Reference<css::uno::XInterface>();
 }
 
-Reference< XInterface > SalInstance::CreateDropTarget()
+Reference< XInterface > SalInstance::CreateDragSource(const SystemEnvData* 
pSysEnv)
 {
-    return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new 
vcl::GenericDropTarget()) );
+    // We run unit tests in parallel, which is a problem when touching a 
shared resource
+    // the system clipboard, so rather use the dummy GenericClipboard.
+    if (Application::IsHeadlessModeEnabled() || IsRunningUnitTest())
+        return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new 
vcl::GenericDragSource()));
+    return ImplCreateDragSource(pSysEnv);
+}
+
+uno::Reference<uno::XInterface> SalInstance::ImplCreateDropTarget(const 
SystemEnvData*)
+{
+    return css::uno::Reference<css::uno::XInterface>();
+}
+
+Reference< XInterface > SalInstance::CreateDropTarget(const SystemEnvData* 
pSysEnv)
+{
+    // see SalInstance::CreateDragSource
+    if (Application::IsHeadlessModeEnabled() || IsRunningUnitTest())
+        return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new 
vcl::GenericDropTarget()));
+    return ImplCreateDropTarget(pSysEnv);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx
index dc50e3c11233..a25e226ed9fb 100644
--- a/vcl/source/window/mouse.cxx
+++ b/vcl/source/window/mouse.cxx
@@ -39,6 +39,7 @@
 #include <salobj.hxx>
 #include <salgdi.hxx>
 #include <salframe.hxx>
+#include <salinst.hxx>
 
 #include <dndlistenercontainer.hxx>
 #include <dndeventdispatcher.hxx>
@@ -724,70 +725,20 @@ Reference< css::datatransfer::dnd::XDropTarget > 
Window::GetDropTarget()
 
 Reference< css::datatransfer::dnd::XDragSource > Window::GetDragSource()
 {
-
 #if HAVE_FEATURE_DESKTOP
-
-    if( mpWindowImpl->mpFrameData )
-    {
-        if( ! mpWindowImpl->mpFrameData->mxDragSource.is() )
-        {
-            try
-            {
-                Reference< XComponentContext > xContext( 
comphelper::getProcessComponentContext() );
-                const SystemEnvData * pEnvData = GetSystemData();
-
-                if( pEnvData )
-                {
-                    Sequence< Any > aDragSourceAL( 2 ), aDropTargetAL( 2 );
-                    auto pDragSourceAL = aDragSourceAL.getArray();
-                    auto pDropTargetAL = aDropTargetAL.getArray();
-                    OUString aDragSourceSN, aDropTargetSN;
-#if defined(_WIN32)
-                    aDragSourceSN = 
"com.sun.star.datatransfer.dnd.OleDragSource";
-                    aDropTargetSN = 
"com.sun.star.datatransfer.dnd.OleDropTarget";
-                    pDragSourceAL[ 1 ] <<= static_cast<sal_uInt64>( 
reinterpret_cast<sal_IntPtr>(pEnvData->hWnd) );
-                    pDropTargetAL[ 0 ] <<= static_cast<sal_uInt64>( 
reinterpret_cast<sal_IntPtr>(pEnvData->hWnd) );
-#elif defined MACOSX
-            /* FIXME: macOS specific dnd interface does not exist! *
-             * Using Windows based dnd as a temporary solution        */
-                    aDragSourceSN = 
"com.sun.star.datatransfer.dnd.OleDragSource";
-                    aDropTargetSN = 
"com.sun.star.datatransfer.dnd.OleDropTarget";
-                    pDragSourceAL[ 1 ] <<= static_cast<sal_uInt64>( 
reinterpret_cast<sal_IntPtr>(pEnvData->mpNSView) );
-                    pDropTargetAL[ 0 ] <<= static_cast<sal_uInt64>( 
reinterpret_cast<sal_IntPtr>(pEnvData->mpNSView) );
-#elif USING_X11
-                    aDragSourceSN = 
"com.sun.star.datatransfer.dnd.X11DragSource";
-                    aDropTargetSN = 
"com.sun.star.datatransfer.dnd.X11DropTarget";
-
-                    pDragSourceAL[ 0 ] <<= Application::GetDisplayConnection();
-                    pDragSourceAL[ 1 ] <<= pEnvData->aShellWindow;
-                    pDropTargetAL[ 0 ] <<= Application::GetDisplayConnection();
-                    pDropTargetAL[ 1 ] <<= pEnvData->aShellWindow;
-#endif
-                    if( !aDragSourceSN.isEmpty() )
-                        mpWindowImpl->mpFrameData->mxDragSource.set(
-                            
xContext->getServiceManager()->createInstanceWithArgumentsAndContext( 
aDragSourceSN, aDragSourceAL, xContext ),
-                            UNO_QUERY );
-
-                    if( !aDropTargetSN.isEmpty() )
-                        mpWindowImpl->mpFrameData->mxDropTarget.set(
-                           
xContext->getServiceManager()->createInstanceWithArgumentsAndContext( 
aDropTargetSN, aDropTargetAL, xContext ),
-                           UNO_QUERY );
-                }
-            }
-
-            // createInstance can throw any exception
-            catch (const Exception&)
-            {
-                // release all instances
-                mpWindowImpl->mpFrameData->mxDropTarget.clear();
-                mpWindowImpl->mpFrameData->mxDragSource.clear();
-            }
-        }
-
+    const SystemEnvData* pEnvData = GetSystemData();
+    if (!mpWindowImpl->mpFrameData || !pEnvData)
+        return Reference<css::datatransfer::dnd::XDragSource>();
+    if (mpWindowImpl->mpFrameData->mxDragSource.is())
         return mpWindowImpl->mpFrameData->mxDragSource;
-    }
-#endif
+
+    SalInstance* pInst = ImplGetSVData()->mpDefInst;
+    
mpWindowImpl->mpFrameData->mxDragSource.set(pInst->CreateDragSource(pEnvData), 
UNO_QUERY);
+    
mpWindowImpl->mpFrameData->mxDropTarget.set(pInst->CreateDropTarget(pEnvData), 
UNO_QUERY);
+    return mpWindowImpl->mpFrameData->mxDragSource;
+#else
     return Reference< css::datatransfer::dnd::XDragSource > ();
+#endif
 }
 
 Reference< css::datatransfer::dnd::XDragGestureRecognizer > 
Window::GetDragGestureRecognizer()
diff --git a/vcl/unx/generic/dtrans/X11_service.cxx 
b/vcl/unx/generic/dtrans/X11_service.cxx
index 6738245cde6c..e633020b6dff 100644
--- a/vcl/unx/generic/dtrans/X11_service.cxx
+++ b/vcl/unx/generic/dtrans/X11_service.cxx
@@ -18,6 +18,8 @@
  */
 
 #include <unx/salinst.h>
+#include <dndhelper.hxx>
+#include <vcl/sysdata.hxx>
 
 #include "X11_clipboard.hxx"
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
@@ -44,11 +46,6 @@ Sequence< OUString > 
x11::Xdnd_dropTarget_getSupportedServiceNames()
     return { "com.sun.star.datatransfer.dnd.X11DropTarget" };
 }
 
-// We run unit tests in parallel, which is a problem when touching a shared 
resource
-// the system clipboard, so rather use the dummy GenericClipboard.
-// Note, cannot make this a global variable, because it might be initialised 
BEFORE the putenv() call in cppunittester.
-static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
-
 css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const 
Sequence< Any >& arguments )
 {
     if ( IsRunningUnitTest() )
@@ -78,20 +75,14 @@ css::uno::Reference< XInterface > 
X11SalInstance::CreateClipboard( const Sequenc
     return pClipboard;
 }
 
-css::uno::Reference< XInterface > X11SalInstance::CreateDragSource()
+css::uno::Reference<XInterface> X11SalInstance::ImplCreateDragSource(const 
SystemEnvData* pSysEnv)
 {
-    if ( IsRunningUnitTest() )
-        return SalInstance::CreateDragSource();
-
-    return css::uno::Reference < XInterface >( static_cast<OWeakObject *>(new 
SelectionManagerHolder()) );
+    return vcl::X11DnDHelper(new SelectionManagerHolder(), 
pSysEnv->aShellWindow);
 }
 
-css::uno::Reference< XInterface > X11SalInstance::CreateDropTarget()
+css::uno::Reference<XInterface> X11SalInstance::ImplCreateDropTarget(const 
SystemEnvData* pSysEnv)
 {
-    if ( IsRunningUnitTest() )
-        return SalInstance::CreateDropTarget();
-
-    return css::uno::Reference < XInterface >( static_cast<OWeakObject *>(new 
DropTarget()) );
+    return vcl::X11DnDHelper(new DropTarget(), pSysEnv->aShellWindow);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 6a7f09999af2..d6603d9b507d 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <string_view>
 
+#include <dndhelper.hxx>
 #include <osl/process.h>
 #include <unx/gtk/gtkdata.hxx>
 #include <unx/gtk/gtkinst.hxx>
@@ -29,6 +30,7 @@
 #include <vcl/builder.hxx>
 #include <vcl/inputtypes.hxx>
 #include <vcl/specialchars.hxx>
+#include <vcl/sysdata.hxx>
 #include <vcl/transfer.hxx>
 #include <vcl/toolkit/floatwin.hxx>
 #include <unx/genpspgraphics.h>
@@ -1572,11 +1574,6 @@ void VclGtkClipboard::removeClipboardListener( const 
Reference< datatransfer::cl
     m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), 
listener), m_aListeners.end());
 }
 
-// We run unit tests in parallel, which is a problem when touching a shared 
resource
-// the system clipboard, so rather use the dummy GenericClipboard.
-// Note, cannot make this a global variable, because it might be initialised 
BEFORE the putenv() call in cppunittester.
-static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
-
 Reference< XInterface > GtkInstance::CreateClipboard(const Sequence< Any >& 
arguments)
 {
     if ( IsRunningUnitTest() )
@@ -1745,12 +1742,9 @@ void GtkInstDropTarget::setDefaultActions(sal_Int8 
nDefaultActions)
     m_nDefaultActions = nDefaultActions;
 }
 
-Reference< XInterface > GtkInstance::CreateDropTarget()
+Reference<XInterface> GtkInstance::ImplCreateDropTarget(const SystemEnvData* 
pSysEnv)
 {
-    if ( IsRunningUnitTest() )
-        return SalInstance::CreateDropTarget();
-
-    return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new 
GtkInstDropTarget));
+    return vcl::X11DnDHelper(new GtkInstDropTarget(), pSysEnv->aShellWindow);
 }
 
 GtkInstDragSource::~GtkInstDragSource()
@@ -1817,12 +1811,9 @@ css::uno::Sequence<OUString> SAL_CALL 
GtkInstDragSource::getSupportedServiceName
     return aRet;
 }
 
-Reference< XInterface > GtkInstance::CreateDragSource()
+Reference<XInterface> GtkInstance::ImplCreateDragSource(const SystemEnvData* 
pSysEnv)
 {
-    if ( IsRunningUnitTest() )
-        return SalInstance::CreateDragSource();
-
-    return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new 
GtkInstDragSource()) );
+    return vcl::X11DnDHelper(new GtkInstDragSource(), pSysEnv->aShellWindow);
 }
 
 namespace {
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index c7538b519851..e9d8e73f8a5e 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -27,15 +27,21 @@
 #include <sal/log.hxx>
 #include <tools/debug.hxx>
 #include <tools/time.hxx>
+#include <comphelper/processfactory.hxx>
 #include <comphelper/solarmutex.hxx>
 #include <comphelper/windowserrorstring.hxx>
+#include <com/sun/star/uno/Reference.h>
 #include <o3tl/char16_t2wchar_t.hxx>
 
+#include <dndhelper.hxx>
 #include <vcl/inputtypes.hxx>
 #include <vcl/opengl/OpenGLContext.hxx>
+#include <vcl/sysdata.hxx>
 #include <vcl/timer.hxx>
 #include <vclpluginapi.h>
 
+#include <win/dnd_source.hxx>
+#include <win/dnd_target.hxx>
 #include <win/wincomp.hxx>
 #include <win/salids.hrc>
 #include <win/saldata.hxx>
@@ -934,4 +940,16 @@ void WinSalInstance::BeforeAbort(const OUString&, bool)
     ImplFreeSalGDI();
 }
 
+css::uno::Reference<css::uno::XInterface> 
WinSalInstance::ImplCreateDragSource(const SystemEnvData* pSysEnv)
+{
+    return vcl::OleDnDHelper(new 
DragSource(comphelper::getProcessComponentContext()),
+                             reinterpret_cast<sal_IntPtr>(pSysEnv->hWnd), 
vcl::DragOrDrop::Drag);
+}
+
+css::uno::Reference<css::uno::XInterface> 
WinSalInstance::ImplCreateDropTarget(const SystemEnvData* pSysEnv)
+{
+    return vcl::OleDnDHelper(new 
DropTarget(comphelper::getProcessComponentContext()),
+                             reinterpret_cast<sal_IntPtr>(pSysEnv->hWnd), 
vcl::DragOrDrop::Drop);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/win/dtrans/idroptarget.hxx b/vcl/win/dtrans/idroptarget.hxx
index 8bb2216aae4c..5871373c6c3d 100644
--- a/vcl/win/dtrans/idroptarget.hxx
+++ b/vcl/win/dtrans/idroptarget.hxx
@@ -18,7 +18,7 @@
  */
 #pragma once
 
-#include "target.hxx"
+#include <win/dnd_target.hxx>
 
 class IDropTargetImpl: public IDropTarget
 {
diff --git a/vcl/win/dtrans/source.cxx b/vcl/win/dtrans/source.cxx
index d8143a3791c9..34471730bcd3 100644
--- a/vcl/win/dtrans/source.cxx
+++ b/vcl/win/dtrans/source.cxx
@@ -28,7 +28,7 @@
 #include <process.h>
 #include <memory>
 
-#include "source.hxx"
+#include <win/dnd_source.hxx>
 #include "globals.hxx"
 #include "sourcecontext.hxx"
 #include "DtObjFactory.hxx"
diff --git a/vcl/win/dtrans/sourcecontext.hxx b/vcl/win/dtrans/sourcecontext.hxx
index b6ed4a90c906..4471747956e5 100644
--- a/vcl/win/dtrans/sourcecontext.hxx
+++ b/vcl/win/dtrans/sourcecontext.hxx
@@ -22,7 +22,7 @@
 #include <cppuhelper/compbase.hxx>
 #include <cppuhelper/basemutex.hxx>
 
-#include "source.hxx"
+#include <win/dnd_source.hxx>
 
 using namespace ::com::sun::star::datatransfer;
 using namespace ::com::sun::star::datatransfer::dnd;
diff --git a/vcl/win/dtrans/target.cxx b/vcl/win/dtrans/target.cxx
index fd4fb32a694a..077aeeb0d514 100644
--- a/vcl/win/dtrans/target.cxx
+++ b/vcl/win/dtrans/target.cxx
@@ -23,7 +23,7 @@
 #include <o3tl/any.hxx>
 
 #include <stdio.h>
-#include "target.hxx"
+#include <win/dnd_target.hxx>
 #include "idroptarget.hxx"
 #include "globals.hxx"
 #include "targetdropcontext.hxx"
diff --git a/vcl/win/dtrans/targetdragcontext.hxx 
b/vcl/win/dtrans/targetdragcontext.hxx
index 5c05acc35da9..a64ab6a30bc4 100644
--- a/vcl/win/dtrans/targetdragcontext.hxx
+++ b/vcl/win/dtrans/targetdragcontext.hxx
@@ -23,7 +23,8 @@
 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
 #include <com/sun/star/datatransfer/DataFlavor.hpp>
 
-#include "target.hxx"
+#include <win/dnd_target.hxx>
+
 using namespace ::com::sun::star::datatransfer;
 using namespace ::com::sun::star::datatransfer::dnd;
 using namespace ::cppu;
diff --git a/vcl/win/dtrans/targetdropcontext.hxx 
b/vcl/win/dtrans/targetdropcontext.hxx
index 6b3389c40017..938a23f850fd 100644
--- a/vcl/win/dtrans/targetdropcontext.hxx
+++ b/vcl/win/dtrans/targetdropcontext.hxx
@@ -22,7 +22,7 @@
 #include <cppuhelper/implbase.hxx>
 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
 
-#include "target.hxx"
+#include <win/dnd_target.hxx>
 
 using namespace ::com::sun::star::datatransfer::dnd;
 using namespace ::cppu;

Reply via email to