diff options
-rw-r--r-- | vcl/Library_vclplug_qt5.mk | 1 | ||||
-rw-r--r-- | vcl/inc/qt5/Qt5DragAndDrop.hxx | 107 | ||||
-rw-r--r-- | vcl/inc/qt5/Qt5Frame.hxx | 10 | ||||
-rw-r--r-- | vcl/inc/qt5/Qt5Instance.hxx | 2 | ||||
-rw-r--r-- | vcl/qt5/Qt5DragAndDrop.cxx | 192 | ||||
-rw-r--r-- | vcl/qt5/Qt5Frame.cxx | 28 | ||||
-rw-r--r-- | vcl/qt5/Qt5Instance.cxx | 11 |
7 files changed, 351 insertions, 0 deletions
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index a57fd53ddf24..c835b748696b 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -87,6 +87,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/Qt5Bitmap \ vcl/qt5/Qt5Clipboard \ vcl/qt5/Qt5Data \ + vcl/qt5/Qt5DragAndDrop \ vcl/qt5/Qt5FilePicker \ vcl/qt5/Qt5Font \ vcl/qt5/Qt5FontFace \ diff --git a/vcl/inc/qt5/Qt5DragAndDrop.hxx b/vcl/inc/qt5/Qt5DragAndDrop.hxx new file mode 100644 index 000000000000..733cf4d03570 --- /dev/null +++ b/vcl/inc/qt5/Qt5DragAndDrop.hxx @@ -0,0 +1,107 @@ +/* -*- 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 <cppuhelper/compbase.hxx> + +#include <com/sun/star/datatransfer/dnd/XDragSource.hpp> +#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +class Qt5Frame; + +class Qt5DragSource + : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDragSource, + css::lang::XInitialization, css::lang::XServiceInfo> +{ + osl::Mutex m_aMutex; + Qt5Frame* m_pFrame; + css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener; + css::uno::Reference<css::datatransfer::XTransferable> m_xTrans; + +public: + Qt5DragSource() + : WeakComponentImplHelper(m_aMutex) + , m_pFrame(nullptr) + { + } + + virtual ~Qt5DragSource() override; + + // XDragSource + virtual sal_Bool SAL_CALL isDragImageSupported() override; + virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) override; + virtual void SAL_CALL startDrag( + const css::datatransfer::dnd::DragGestureEvent& trigger, sal_Int8 sourceActions, + sal_Int32 cursor, sal_Int32 image, + const css::uno::Reference<css::datatransfer::XTransferable>& transferable, + const css::uno::Reference<css::datatransfer::dnd::XDragSourceListener>& listener) override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; + void deinitialize(); + + OUString SAL_CALL getImplementationName() override; + + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + void dragFailed(); +}; + +class Qt5DropTarget + : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget, + css::datatransfer::dnd::XDropTargetDragContext, + css::datatransfer::dnd::XDropTargetDropContext, + css::lang::XInitialization, css::lang::XServiceInfo> +{ + osl::Mutex m_aMutex; + Qt5Frame* m_pFrame; + bool m_bActive; + sal_Int8 m_nDefaultActions; + std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners; + +public: + Qt5DropTarget(); + virtual ~Qt5DropTarget() override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArgs) override; + void deinitialize(); + + // XDropTarget + virtual void SAL_CALL addDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override; + virtual void SAL_CALL removeDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override; + virtual sal_Bool SAL_CALL isActive() override; + virtual void SAL_CALL setActive(sal_Bool active) override; + virtual sal_Int8 SAL_CALL getDefaultActions() override; + virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override; + + // XDropTargetDragContext + virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override; + virtual void SAL_CALL rejectDrag() override; + + // XDropTargetDropContext + virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) override; + virtual void SAL_CALL rejectDrop() override; + virtual void SAL_CALL dropComplete(sal_Bool success) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx index 577a9cce2fde..ce468ded3c18 100644 --- a/vcl/inc/qt5/Qt5Frame.hxx +++ b/vcl/inc/qt5/Qt5Frame.hxx @@ -34,6 +34,8 @@ class Qt5Instance; class Qt5Menu; class QWidget; class Qt5MainWindow; +class Qt5DragSource; +class Qt5DropTarget; class QPaintDevice; class QScreen; class QImage; @@ -68,6 +70,9 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame Qt5Menu* m_pSalMenu; + Qt5DragSource* m_pDragSource; + Qt5DropTarget* m_pDropTarget; + bool m_bDefaultSize; bool m_bDefaultPos; @@ -121,6 +126,11 @@ public: virtual void SetMenu(SalMenu* pMenu) override; virtual void DrawMenuBar() override; + virtual void registerDragSource(Qt5DragSource* pDragSource); + virtual void deregisterDragSource(Qt5DragSource const* pDragSource); + virtual void registerDropTarget(Qt5DropTarget* pDropTarget); + virtual void deregisterDropTarget(Qt5DropTarget const* pDropTarget); + virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override; virtual void Show(bool bVisible, bool bNoActivate = false) override; virtual void SetMinClientSize(long nWidth, long nHeight) override; diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx index 58ab6e329544..8f5a2670b238 100644 --- a/vcl/inc/qt5/Qt5Instance.hxx +++ b/vcl/inc/qt5/Qt5Instance.hxx @@ -112,6 +112,8 @@ 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; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/Qt5DragAndDrop.cxx b/vcl/qt5/Qt5DragAndDrop.cxx new file mode 100644 index 000000000000..6e83f6ff40fa --- /dev/null +++ b/vcl/qt5/Qt5DragAndDrop.cxx @@ -0,0 +1,192 @@ +/* -*- 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/. + * + */ + +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/datatransfer/DataFlavor.hpp> +#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> +#include <cppuhelper/supportsservice.hxx> +#include <sal/log.hxx> + +#include <Qt5DragAndDrop.hxx> +#include <Qt5Frame.hxx> + +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; + +Qt5DragSource::~Qt5DragSource() +{ + //if (m_pFrame) + // m_pFrame->deregisterDragSource(this); +} + +void Qt5DragSource::deinitialize() { m_pFrame = nullptr; } + +sal_Bool Qt5DragSource::isDragImageSupported() { return true; } + +sal_Int32 Qt5DragSource::getDefaultCursor(sal_Int8) { return 0; } + +void Qt5DragSource::initialize(const css::uno::Sequence<css::uno::Any>& rArguments) +{ + if (rArguments.getLength() < 2) + { + throw RuntimeException("DragSource::initialize: Cannot install window event handler", + static_cast<OWeakObject*>(this)); + } + + sal_IntPtr nFrame = 0; + rArguments.getConstArray()[1] >>= nFrame; + + if (!nFrame) + { + throw RuntimeException("DragSource::initialize: missing SalFrame", + static_cast<OWeakObject*>(this)); + } + + m_pFrame = reinterpret_cast<Qt5Frame*>(nFrame); + m_pFrame->registerDragSource(this); +} + +void Qt5DragSource::startDrag( + const datatransfer::dnd::DragGestureEvent& /*rEvent*/, sal_Int8 /*sourceActions*/, + sal_Int32 /*cursor*/, sal_Int32 /*image*/, + const css::uno::Reference<css::datatransfer::XTransferable>& rTrans, + const css::uno::Reference<css::datatransfer::dnd::XDragSourceListener>& rListener) +{ + m_xListener = rListener; + m_xTrans = rTrans; + + if (!m_pFrame) + dragFailed(); +} + +void Qt5DragSource::dragFailed() +{ + if (m_xListener.is()) + { + datatransfer::dnd::DragSourceDropEvent aEv; + aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_NONE; + aEv.DropSuccess = false; + auto xListener = m_xListener; + m_xListener.clear(); + xListener->dragDropEnd(aEv); + } +} + +OUString SAL_CALL Qt5DragSource::getImplementationName() +{ + return OUString("com.sun.star.datatransfer.dnd.VclQt5DragSource"); +} + +sal_Bool SAL_CALL Qt5DragSource::supportsService(OUString const& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence<OUString> SAL_CALL Qt5DragSource::getSupportedServiceNames() +{ + Sequence<OUString> aRet{ "com.sun.star.datatransfer.dnd.Qt5DragSource" }; + return aRet; +} + +Qt5DropTarget::Qt5DropTarget() + : WeakComponentImplHelper(m_aMutex) + , m_pFrame(nullptr) + , m_bActive(false) + , m_nDefaultActions(0) +{ +} + +OUString SAL_CALL Qt5DropTarget::getImplementationName() +{ + return OUString("com.sun.star.datatransfer.dnd.VclQt5DropTarget"); +} + +sal_Bool SAL_CALL Qt5DropTarget::supportsService(OUString const& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence<OUString> SAL_CALL Qt5DropTarget::getSupportedServiceNames() +{ + Sequence<OUString> aRet{ "com.sun.star.datatransfer.dnd.Qt5DropTarget" }; + return aRet; +} + +Qt5DropTarget::~Qt5DropTarget() +{ + //if (m_pFrame) + //m_pFrame->deregisterDropTarget(this); +} + +void Qt5DropTarget::deinitialize() +{ + m_pFrame = nullptr; + m_bActive = false; +} + +void Qt5DropTarget::initialize(const Sequence<Any>& rArguments) +{ + if (rArguments.getLength() < 2) + { + throw RuntimeException("DropTarget::initialize: Cannot install window event handler", + static_cast<OWeakObject*>(this)); + } + + sal_IntPtr nFrame = 0; + rArguments.getConstArray()[1] >>= nFrame; + + if (!nFrame) + { + throw RuntimeException("DropTarget::initialize: missing SalFrame", + static_cast<OWeakObject*>(this)); + } + + m_pFrame = reinterpret_cast<Qt5Frame*>(nFrame); + //m_pFrame->registerDropTarget(this); + m_bActive = true; +} + +void Qt5DropTarget::addDropTargetListener( + const Reference<css::datatransfer::dnd::XDropTargetListener>& xListener) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + m_aListeners.push_back(xListener); +} + +void Qt5DropTarget::removeDropTargetListener( + const Reference<css::datatransfer::dnd::XDropTargetListener>& xListener) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), xListener), + m_aListeners.end()); +} + +sal_Bool Qt5DropTarget::isActive() { return m_bActive; } + +void Qt5DropTarget::setActive(sal_Bool bActive) { m_bActive = bActive; } + +sal_Int8 Qt5DropTarget::getDefaultActions() { return m_nDefaultActions; } + +void Qt5DropTarget::setDefaultActions(sal_Int8 nDefaultActions) +{ + m_nDefaultActions = nDefaultActions; +} + +void Qt5DropTarget::acceptDrag(sal_Int8 /*dragOperation*/) { return; } +void Qt5DropTarget::rejectDrag() { return; } + +void Qt5DropTarget::acceptDrop(sal_Int8 /*dropOperation*/) { return; } +void Qt5DropTarget::rejectDrop() { return; } +void Qt5DropTarget::dropComplete(sal_Bool /*success*/) { return; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx index b42ec5e08a0c..070342601bbd 100644 --- a/vcl/qt5/Qt5Frame.cxx +++ b/vcl/qt5/Qt5Frame.cxx @@ -27,6 +27,7 @@ #include <Qt5MainWindow.hxx> #include <Qt5Data.hxx> #include <Qt5Menu.hxx> +#include <Qt5DragAndDrop.hxx> #include <QtCore/QPoint> #include <QtCore/QSize> @@ -835,4 +836,31 @@ void Qt5Frame::SetApplicationID(const OUString&) // So the hope is that QGuiApplication deals with this properly.. } +// Drag'n'drop foo +void Qt5Frame::registerDragSource(Qt5DragSource* pDragSource) +{ + assert(!m_pDragSource); + m_pDragSource = pDragSource; +} + +void Qt5Frame::deregisterDragSource(Qt5DragSource const* pDragSource) +{ + assert(m_pDragSource == pDragSource); + (void)pDragSource; + m_pDragSource = nullptr; +} + +void Qt5Frame::registerDropTarget(Qt5DropTarget* pDropTarget) +{ + assert(!m_pDropTarget); + m_pDropTarget = pDropTarget; +} + +void Qt5Frame::deregisterDropTarget(Qt5DropTarget const* pDropTarget) +{ + assert(m_pDropTarget == pDropTarget); + (void)pDropTarget; + m_pDropTarget = nullptr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx index 71e9883416f1..f780860dccc5 100644 --- a/vcl/qt5/Qt5Instance.cxx +++ b/vcl/qt5/Qt5Instance.cxx @@ -25,6 +25,7 @@ #include <Qt5Bitmap.hxx> #include <Qt5Clipboard.hxx> #include <Qt5Data.hxx> +#include <Qt5DragAndDrop.hxx> #include <Qt5FilePicker.hxx> #include <Qt5Frame.hxx> #include <Qt5Menu.hxx> @@ -241,6 +242,16 @@ Qt5Instance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments) return xClipboard; } +Reference<XInterface> Qt5Instance::CreateDragSource() +{ + return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new Qt5DragSource())); +} + +Reference<XInterface> Qt5Instance::CreateDropTarget() +{ + return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new Qt5DropTarget())); +} + extern "C" { VCLPLUG_QT5_PUBLIC SalInstance* create_SalInstance() { |