diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-09-14 12:53:54 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-09-14 12:53:59 +0200 |
commit | f2e43a33fe769c28f648b492aaefb731c3cf3ce0 (patch) | |
tree | f0ed1120091dc14b1b4ae46401123904fbb0cabb | |
parent | 38b4c12135a83fe9488c767ae7345708096a4f91 (diff) |
handle mousemove and drop events in svpfeature/eszka
it uses handling from Henry's:
https://gerrit.libreoffice.org/c/core/+/118869/9
Change-Id: Ifb06dcd4e94ec3cd379389199ac35bee4a59c6b2
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 2 | ||||
-rw-r--r-- | vcl/inc/dndeventdispatcher.hxx | 146 | ||||
-rw-r--r-- | vcl/source/components/dtranscomp.cxx | 135 | ||||
-rw-r--r-- | vcl/source/window/winproc.cxx | 53 |
4 files changed, 219 insertions, 117 deletions
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 7fbbda5decd2..261caf9536e6 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -6495,7 +6495,7 @@ void ScGridWindow::UpdateDragRectOverlay() // #i70788# get the OverlayManager safely rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = getOverlayManager(); - if (xOverlayManager.is() && !comphelper::LibreOfficeKit::isActive()) + if (xOverlayManager.is())// && !comphelper::LibreOfficeKit::isActive()) { std::vector< basegfx::B2DRange > aRanges; const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation()); diff --git a/vcl/inc/dndeventdispatcher.hxx b/vcl/inc/dndeventdispatcher.hxx index bc2f5d9991e8..a790335fda68 100644 --- a/vcl/inc/dndeventdispatcher.hxx +++ b/vcl/inc/dndeventdispatcher.hxx @@ -22,11 +22,157 @@ #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp> #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/datatransfer/XTransferable.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp> +#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp> +#include <com/sun/star/datatransfer/dnd/XDragSource.hpp> +#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> +#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> #include <com/sun/star/datatransfer/dnd/XDragGestureListener.hpp> #include <cppuhelper/implbase.hxx> #include <vcl/window.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/supportsservice.hxx> +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; + +namespace vcl +{ +class GenericDropTarget : public cppu::WeakComponentImplHelper< + css::datatransfer::dnd::XDropTarget, + XInitialization, + css::lang::XServiceInfo + > +{ + osl::Mutex m_aMutex; + ::std::vector< css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > > m_aListeners; +public: + GenericDropTarget() : WeakComponentImplHelper( m_aMutex ) + {} + + // XInitialization + virtual void SAL_CALL initialize( const Sequence< Any >& args ) override; + + // 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; + + void dragEnter( const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtde ) noexcept + { + osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); + std::vector< css::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetListener > > aListeners( m_aListeners ); + aGuard.clear(); + + for (auto const& listener : aListeners) + { + listener->dragEnter(dtde); + } + } + + OUString SAL_CALL getImplementationName() override + { return "com.sun.star.datatransfer.dnd.VclGenericDropTarget"; } + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override + { return cppu::supportsService(this, ServiceName); } + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { return getSupportedServiceNames_static(); } + + static Sequence< OUString > getSupportedServiceNames_static() + { + return { "com.sun.star.datatransfer.dnd.GenericDropTarget" }; + } +}; + +/* +* generic DragSource dummy +*/ +class GenericDragSource : public cppu::WeakComponentImplHelper< + datatransfer::dnd::XDragSource, + XInitialization, + css::lang::XServiceInfo + > +{ + osl::Mutex m_aMutex; + css::uno::Reference<css::datatransfer::XTransferable> m_xTrans; + css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener; + std::vector<GenericDropTarget*> m_pTarget; +public: + GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {} + + static GenericDragSource& get( const OUString& rDisplayName ); + + void registerDropTarget( /*::Window aXLIB_Window,*/ GenericDropTarget* pTarget ); + + void accept( sal_Int8 dragOperation ); + + // XDragSource + virtual sal_Bool SAL_CALL isDragImageSupported() override; + virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) override; + virtual void SAL_CALL startDrag( + const datatransfer::dnd::DragGestureEvent& trigger, + sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image, + const css::uno::Reference< datatransfer::XTransferable >& transferable, + const css::uno::Reference< datatransfer::dnd::XDragSourceListener >& listener + ) override; + + // XInitialization + virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) override; + + OUString SAL_CALL getImplementationName() override + { return "com.sun.star.datatransfer.dnd.VclGenericDragSource"; } + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override + { return cppu::supportsService(this, ServiceName); } + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { return getSupportedServiceNames_static(); } + + static Sequence< OUString > getSupportedServiceNames_static() + { + return { "com.sun.star.datatransfer.dnd.GenericDragSource" }; + } + +private: + static std::unordered_map< OUString, GenericDragSource* >& getInstances(); +}; + +class GenericDropTargetDropContext : + public ::cppu::WeakImplHelper<css::datatransfer::dnd::XDropTargetDropContext> +{ +public: + GenericDropTargetDropContext(); + // XDropTargetDropContext + virtual void SAL_CALL acceptDrop( sal_Int8 dragOperation ) override; + virtual void SAL_CALL rejectDrop() override; + virtual void SAL_CALL dropComplete( sal_Bool success ) override; +}; + +class GenericDropTargetDragContext : + public ::cppu::WeakImplHelper<css::datatransfer::dnd::XDropTargetDragContext> +{ + GenericDragSource* m_pDragSource; + +public: + GenericDropTargetDragContext(GenericDragSource* pDragSource); + + // XDropTargetDragContext + virtual void SAL_CALL acceptDrag( sal_Int8 dragOperation ) override; + virtual void SAL_CALL rejectDrag() override; +}; +} class DNDEventDispatcher final : public ::cppu::WeakImplHelper< css::datatransfer::dnd::XDropTargetListener, css::datatransfer::dnd::XDropTargetDragContext, diff --git a/vcl/source/components/dtranscomp.cxx b/vcl/source/components/dtranscomp.cxx index 5d54e4b5b459..cdfb8d39a9cc 100644 --- a/vcl/source/components/dtranscomp.cxx +++ b/vcl/source/components/dtranscomp.cxx @@ -44,6 +44,7 @@ #include <cppuhelper/compbase.hxx> #include <cppuhelper/supportsservice.hxx> +#include <dndeventdispatcher.hxx> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -52,121 +53,6 @@ using namespace com::sun::star::lang; namespace vcl { namespace { -class GenericDropTarget : public cppu::WeakComponentImplHelper< - datatransfer::dnd::XDropTarget, - XInitialization, - css::lang::XServiceInfo - > -{ - osl::Mutex m_aMutex; - ::std::vector< css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > > m_aListeners; -public: - GenericDropTarget() : WeakComponentImplHelper( m_aMutex ) - {} - - // XInitialization - virtual void SAL_CALL initialize( const Sequence< Any >& args ) override; - - // XDropTarget - virtual void SAL_CALL addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) override; - virtual void SAL_CALL removeDropTargetListener( const 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; - - void dragEnter( const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtde ) noexcept - { - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector< Reference< com::sun::star::datatransfer::dnd::XDropTargetListener > > aListeners( m_aListeners ); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragEnter(dtde); - } - } - - OUString SAL_CALL getImplementationName() override - { return "com.sun.star.datatransfer.dnd.VclGenericDropTarget"; } - - sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override - { return cppu::supportsService(this, ServiceName); } - - css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override - { return getSupportedServiceNames_static(); } - - static Sequence< OUString > getSupportedServiceNames_static() - { - return { "com.sun.star.datatransfer.dnd.GenericDropTarget" }; - } -}; - -/* -* generic DragSource dummy -*/ -class GenericDragSource : public cppu::WeakComponentImplHelper< - datatransfer::dnd::XDragSource, - XInitialization, - css::lang::XServiceInfo - > -{ - osl::Mutex m_aMutex; - css::uno::Reference<css::datatransfer::XTransferable> m_xTrans; - css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener; - std::vector<GenericDropTarget*> m_pTarget; -public: - GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {} - - static GenericDragSource& get( const OUString& rDisplayName ); - - void registerDropTarget( /*::Window aXLIB_Window,*/ GenericDropTarget* pTarget ); - - void accept( sal_Int8 dragOperation ); - - // XDragSource - virtual sal_Bool SAL_CALL isDragImageSupported() override; - virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) override; - virtual void SAL_CALL startDrag( - const datatransfer::dnd::DragGestureEvent& trigger, - sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image, - const Reference< datatransfer::XTransferable >& transferable, - const Reference< datatransfer::dnd::XDragSourceListener >& listener - ) override; - - // XInitialization - virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) override; - - OUString SAL_CALL getImplementationName() override - { return "com.sun.star.datatransfer.dnd.VclGenericDragSource"; } - - sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override - { return cppu::supportsService(this, ServiceName); } - - css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override - { return getSupportedServiceNames_static(); } - - static Sequence< OUString > getSupportedServiceNames_static() - { - return { "com.sun.star.datatransfer.dnd.GenericDragSource" }; - } - -private: - static std::unordered_map< OUString, GenericDragSource* >& getInstances(); -}; - -class GenericDropTargetDragContext : - public ::cppu::WeakImplHelper<css::datatransfer::dnd::XDropTargetDragContext> -{ - GenericDragSource* m_pDragSource; - -public: - GenericDropTargetDragContext(GenericDragSource* pDragSource); - - // XDropTargetDragContext - virtual void SAL_CALL acceptDrag( sal_Int8 dragOperation ) override; - virtual void SAL_CALL rejectDrag() override; -}; // generic implementation to satisfy SalInstance class GenericClipboard : @@ -228,6 +114,22 @@ public: } +/* + * GenericDropTargetDropContext + */ +GenericDropTargetDropContext::GenericDropTargetDropContext() +{ +} +void GenericDropTargetDropContext::acceptDrop( sal_Int8 /*dragOperation*/ ) +{ +} +void GenericDropTargetDropContext::rejectDrop() +{ +} +void GenericDropTargetDropContext::dropComplete( sal_Bool /*success*/ ) +{ +} + GenericDropTargetDragContext::GenericDropTargetDragContext(GenericDragSource* pDragSource) : m_pDragSource(pDragSource) { @@ -235,7 +137,8 @@ GenericDropTargetDragContext::GenericDropTargetDragContext(GenericDragSource* pD void GenericDropTargetDragContext::acceptDrag( sal_Int8 dragOperation ) { - m_pDragSource->accept( dragOperation ); + if (m_pDragSource) + m_pDragSource->accept( dragOperation ); } void GenericDropTargetDragContext::rejectDrag() diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 2096b7cf3da1..ee2c867d595a 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -56,6 +56,8 @@ #include <com/sun/star/datatransfer/dnd/XDragSource.hpp> #include <com/sun/star/awt/MouseEvent.hpp> +#include <dndeventdispatcher.hxx> +#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> #define IMPL_MIN_NEEDSYSWIN 49 @@ -273,6 +275,57 @@ bool ImplHandleMouseEvent( const VclPtr<vcl::Window>& xWindow, MouseNotifyEvent ImplFrameData* pWinFrameData = xWindow->ImplGetFrameData(); sal_uInt16 nOldCode = pWinFrameData->mnMouseCode; + vcl::Window* pDragWin = pWinFrameData->mpMouseDownWin; + if (pDragWin && pDragWin->ImplGetFrameData()->mbStartDragCalled && + nSVEvent == MouseNotifyEvent::MOUSEMOVE) + { + css::uno::Reference<css::datatransfer::dnd::XDropTargetDragContext> xDropTargetDragContext = + new vcl::GenericDropTargetDragContext(nullptr); + css::uno::Reference<css::datatransfer::dnd::XDropTarget> xDropTarget( + pDragWin->ImplGetWindowImpl()->mxDNDListenerContainer, css::uno::UNO_QUERY); + if (!xDropTargetDragContext.is() || + !xDropTarget.is() || + (nCode & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)) == + (MouseSettings::GetStartDragCode() & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE))) + { + // cancel dragdrop + pDragWin->ImplGetFrameData()->mbStartDragCalled = false; + return false; + } + Point dragOverPos = pDragWin->ImplFrameToOutput(aMousePos); + static_cast<DNDListenerContainer *>(xDropTarget.get())->fireDragOverEvent( + xDropTargetDragContext, + css::datatransfer::dnd::DNDConstants::ACTION_MOVE, + dragOverPos.X(), + dragOverPos.Y(), + (css::datatransfer::dnd::DNDConstants::ACTION_COPY | + css::datatransfer::dnd::DNDConstants::ACTION_MOVE | + css::datatransfer::dnd::DNDConstants::ACTION_LINK)); + return true; + } + if (pDragWin && pDragWin->ImplGetFrameData()->mbStartDragCalled && + nSVEvent == MouseNotifyEvent::MOUSEBUTTONUP) + { + css::uno::Reference<css::datatransfer::dnd::XDropTargetDropContext> xDropTargetDropContext = + new vcl::GenericDropTargetDropContext(); + css::uno::Reference<css::datatransfer::dnd::XDropTarget> xDropTarget( + pDragWin->ImplGetWindowImpl()->mxDNDListenerContainer, css::uno::UNO_QUERY); + if (xDropTargetDropContext.is() && xDropTarget.is()) + { + Point dragOverPos = pDragWin->ImplFrameToOutput(aMousePos); + static_cast<DNDListenerContainer *>(xDropTarget.get())->fireDropEvent( + xDropTargetDropContext, + css::datatransfer::dnd::DNDConstants::ACTION_MOVE, + dragOverPos.X(), + dragOverPos.Y(), + (css::datatransfer::dnd::DNDConstants::ACTION_COPY | + css::datatransfer::dnd::DNDConstants::ACTION_MOVE | + css::datatransfer::dnd::DNDConstants::ACTION_LINK), + css::uno::Reference<css::datatransfer::XTransferable>()); + } + pDragWin->ImplGetFrameData()->mbStartDragCalled = false; + } + // we need a mousemove event, before we get a mousebuttondown or a // mousebuttonup event if ( (nSVEvent == MouseNotifyEvent::MOUSEBUTTONDOWN) || (nSVEvent == MouseNotifyEvent::MOUSEBUTTONUP) ) |