vcl/Library_vcl.mk | 1 vcl/inc/DropTarget.hxx | 57 ++++++++++++++ vcl/inc/unx/gtk/gtkinst.hxx | 22 ----- vcl/source/app/DropTarget.cxx | 115 ++++++++++++++++++++++++++++++ vcl/unx/generic/dtrans/X11_droptarget.cxx | 105 ++------------------------- vcl/unx/generic/dtrans/X11_selection.cxx | 2 vcl/unx/generic/dtrans/X11_selection.hxx | 41 ++-------- vcl/unx/generic/dtrans/X11_service.cxx | 2 vcl/unx/gtk3/gtkframe.cxx | 18 ++-- vcl/unx/gtk3/gtkinst.cxx | 91 ----------------------- 10 files changed, 209 insertions(+), 245 deletions(-)
New commits: commit 3d08ea31fc1b6cfe27ca694c1acf21e2d1acb758 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Jul 4 18:39:51 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Jul 5 07:46:26 2025 +0200 gtk: Subclass DropTarget to deduplicate code Subclass the new base class introduced in Change-Id: Ib6783437ab34b1e7788bbbfc67aff85026ac62f3 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Fri Jul 4 18:22:04 2025 +0200 gen, vcl: Split base class from DropTarget for reuse which already implements some of the logic needed. Change-Id: I13f421231ed42893bc98062946e8f19a2bc00604 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187420 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx index fd3782137800..5727f1e4b62d 100644 --- a/vcl/inc/unx/gtk/gtkinst.hxx +++ b/vcl/inc/unx/gtk/gtkinst.hxx @@ -23,6 +23,7 @@ #include <stack> +#include <DropTarget.hxx> #include <unx/salinst.h> #include <unx/gensys.h> #include <headless/svpinst.hxx> @@ -125,16 +126,12 @@ public: class GtkDnDTransferable; class GtkInstDropTarget final - : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget, - css::lang::XServiceInfo> + : public cppu::ImplInheritanceHelper<DropTarget, css::lang::XServiceInfo> { - osl::Mutex m_aMutex; GtkSalFrame* m_pFrame; GtkDnDTransferable* m_pFormatConversionRequest; - bool m_bActive; bool m_bInDrag; - sal_Int8 m_nDefaultActions; - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners; + public: GtkInstDropTarget(); GtkInstDropTarget(GtkSalFrame* pFrame); @@ -142,25 +139,12 @@ public: 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; - OUString SAL_CALL getImplementationName() override; sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; - void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee); - void fire_dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde); - void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde); - void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte); - void SetFormatConversionRequest(GtkDnDTransferable *pRequest) { m_pFormatConversionRequest = pRequest; diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index 14da1c903202..f918c3d0c12f 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -5227,7 +5227,7 @@ gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* #endif } - fire_drop(aEvent); + drop(aEvent); return true; } @@ -5412,12 +5412,12 @@ GdkDragAction GtkInstDropTarget::signalDragMotion(GtkDropTargetAsync *context, G #endif } aEvent.SupportedDataFlavors = xTransferable->getTransferDataFlavors(); - fire_dragEnter(aEvent); + dragEnter(aEvent); m_bInDrag = true; } else { - fire_dragOver(aEvent); + dragOver(aEvent); } #if !GTK_CHECK_VERSION(4,0,0) @@ -5450,7 +5450,7 @@ static gboolean lcl_deferred_dragExit(gpointer user_data) GtkInstDropTarget* pThis = static_cast<GtkInstDropTarget*>(user_data); css::datatransfer::dnd::DropTargetEvent aEvent; aEvent.Source = static_cast<css::datatransfer::dnd::XDropTarget*>(pThis); - pThis->fire_dragExit(aEvent); + pThis->dragExit(aEvent); return false; } diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index a5775cb31a12..4924183de978 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -1612,14 +1612,11 @@ GtkInstance::CreateClipboard(const Sequence<Any>& arguments) } GtkInstDropTarget::GtkInstDropTarget() - : WeakComponentImplHelper(m_aMutex) - , m_pFrame(nullptr) + : m_pFrame(nullptr) , m_pFormatConversionRequest(nullptr) - , m_bActive(false) #if !GTK_CHECK_VERSION(4, 0, 0) , m_bInDrag(false) #endif - , m_nDefaultActions(0) { } @@ -1630,7 +1627,7 @@ GtkInstDropTarget::GtkInstDropTarget(GtkSalFrame* pFrame) m_pFrame = pFrame; m_pFrame->registerDropTarget(this); - m_bActive = true; + setActive(true); } OUString SAL_CALL GtkInstDropTarget::getImplementationName() @@ -1658,89 +1655,7 @@ GtkInstDropTarget::~GtkInstDropTarget() void GtkInstDropTarget::deinitialize() { m_pFrame = nullptr; - m_bActive = false; -} - -void GtkInstDropTarget::addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& xListener) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - m_aListeners.push_back( xListener ); -} - -void GtkInstDropTarget::removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& xListener) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - std::erase(m_aListeners, xListener); -} - -void GtkInstDropTarget::fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) -{ - osl::ClearableGuard<osl::Mutex> aGuard( m_aMutex ); - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(m_aListeners); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->drop( dtde ); - } -} - -void GtkInstDropTarget::fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde) -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(m_aListeners); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragEnter( dtde ); - } -} - -void GtkInstDropTarget::fire_dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(m_aListeners); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragOver( dtde ); - } -} - -void GtkInstDropTarget::fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(m_aListeners); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragExit( dte ); - } -} - -sal_Bool GtkInstDropTarget::isActive() -{ - return m_bActive; -} - -void GtkInstDropTarget::setActive(sal_Bool bActive) -{ - m_bActive = bActive; -} - -sal_Int8 GtkInstDropTarget::getDefaultActions() -{ - return m_nDefaultActions; -} - -void GtkInstDropTarget::setDefaultActions(sal_Int8 nDefaultActions) -{ - m_nDefaultActions = nDefaultActions; + setActive(false); } css::uno::Reference<css::datatransfer::dnd::XDropTarget> commit d91d550639b63042e0071a552bced774b0c731d7 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Jul 4 18:37:44 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Jul 5 07:46:18 2025 +0200 gtk4: Rename param 'drop' -> 'pDrop' This is in preparation for an upcoming commit that will turn GtkInstDropTarget into a DropTarget subclass, at which point that `drop` param would cause a naming conflict with the (then) base class method DropTarget::drop. Change-Id: I63ca6d705a4d85a170db1b1cf56b3bc9bdabb391 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187419 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index b93996085d27..14da1c903202 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -5165,7 +5165,7 @@ gboolean GtkSalFrame::signalDragDrop(GtkWidget* pWidget, GdkDragContext* context #if !GTK_CHECK_VERSION(4, 0, 0) gboolean GtkInstDropTarget::signalDragDrop(GtkWidget* pWidget, GdkDragContext* context, gint x, gint y, guint time) #else -gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* drop, double x, double y) +gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* pDrop, double x, double y) #endif { // remove the deferred dragExit, as we'll do a drop @@ -5186,14 +5186,14 @@ gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* #if !GTK_CHECK_VERSION(4, 0, 0) aEvent.Context = new GtkDropTargetDropContext(context, time); #else - aEvent.Context = new GtkDropTargetDropContext(drop); + aEvent.Context = new GtkDropTargetDropContext(pDrop); #endif aEvent.LocationX = x; aEvent.LocationY = y; #if !GTK_CHECK_VERSION(4, 0, 0) aEvent.DropAction = GdkToVcl(gdk_drag_context_get_selected_action(context)); #else - aEvent.DropAction = GdkToVcl(getPreferredDragAction(GdkToVcl(gdk_drop_get_actions(drop)))); + aEvent.DropAction = GdkToVcl(getPreferredDragAction(GdkToVcl(gdk_drop_get_actions(pDrop)))); #endif // ACTION_DEFAULT is documented as... // 'This means the user did not press any key during the Drag and Drop operation @@ -5208,7 +5208,7 @@ gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* GdkModifierType mask; gdk_window_get_pointer(widget_get_surface(pWidget), nullptr, nullptr, &mask); #else - aEvent.SourceActions = GdkToVcl(gdk_drop_get_actions(drop)); + aEvent.SourceActions = GdkToVcl(gdk_drop_get_actions(pDrop)); GdkModifierType mask = gtk_event_controller_get_current_event_state(GTK_EVENT_CONTROLLER(context)); #endif if (!(mask & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) @@ -5221,7 +5221,7 @@ gboolean GtkInstDropTarget::signalDragDrop(GtkDropTargetAsync* context, GdkDrop* else { #if GTK_CHECK_VERSION(4,0,0) - aEvent.Transferable = new GtkDnDTransferable(drop); + aEvent.Transferable = new GtkDnDTransferable(pDrop); #else aEvent.Transferable = new GtkDnDTransferable(context, time, pWidget, this); #endif commit 1b478ec7b4073b24729ff764d6465d975884c756 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Jul 4 18:22:04 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Jul 5 07:46:12 2025 +0200 gen, vcl: Split base class from DropTarget for reuse Split the DropTarget class implemented in the gen/x11 vcl plugin into two: Rename the existing class to X11DropTarget and extract the basic logic to implement the XDropTarget interface (handling listeners, notifying listeners, setting/getting active state and default actions) into a base class DropTarget. This will allow reusing the logic from elsewhere (in particular planned for the gtk and qt VCL plugins in upcoming commits) instead of implementing the same logic again. Change-Id: Ib6783437ab34b1e7788bbbfc67aff85026ac62f3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187418 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 2ae251b651c8..bb69f1ba0297 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -449,6 +449,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/app/customweld \ vcl/source/app/dbggui \ vcl/source/app/dndhelp \ + vcl/source/app/DropTarget \ vcl/source/app/help \ vcl/source/app/i18nhelp \ vcl/source/app/idle \ diff --git a/vcl/inc/DropTarget.hxx b/vcl/inc/DropTarget.hxx new file mode 100644 index 000000000000..6ac7c5b8ff28 --- /dev/null +++ b/vcl/inc/DropTarget.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> +#include <cppuhelper/compbase.hxx> +#include <osl/mutex.hxx> +#include <vcl/dllapi.h> + +#pragma once + +class VCL_DLLPUBLIC DropTarget + : public ::cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget> +{ + osl::Mutex m_aMutex; + bool m_bActive; + sal_Int8 m_nDefaultActions; + std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners; + +protected: + DropTarget(); + virtual ~DropTarget() override; + +public: + // convenience functions that loop over listeners + void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde) noexcept; + void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) noexcept; + void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) noexcept; + void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) noexcept; + + // XDropTarget + virtual void SAL_CALL addDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override final; + virtual void SAL_CALL removeDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override final; + virtual sal_Bool SAL_CALL isActive() override final; + virtual void SAL_CALL setActive(sal_Bool active) override final; + virtual sal_Int8 SAL_CALL getDefaultActions() override final; + virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override final; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/source/app/DropTarget.cxx b/vcl/source/app/DropTarget.cxx new file mode 100644 index 000000000000..fec6a17bf8ab --- /dev/null +++ b/vcl/source/app/DropTarget.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <DropTarget.hxx> + +using namespace com::sun::star; +using namespace com::sun::star::datatransfer; +using namespace com::sun::star::datatransfer::dnd; + +DropTarget::DropTarget() + : ::cppu::WeakComponentImplHelper<XDropTarget>(m_aMutex) + , m_bActive(false) + , m_nDefaultActions(0) +{ +} + +DropTarget::~DropTarget() {} + +void DropTarget::addDropTargetListener(const uno::Reference<XDropTargetListener>& xListener) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + m_aListeners.push_back(xListener); +} + +void DropTarget::removeDropTargetListener(const uno::Reference<XDropTargetListener>& xListener) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + std::erase(m_aListeners, xListener); +} + +sal_Bool DropTarget::isActive() { return m_bActive; } + +void DropTarget::setActive(sal_Bool active) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + m_bActive = active; +} + +sal_Int8 DropTarget::getDefaultActions() { return m_nDefaultActions; } + +void DropTarget::setDefaultActions(sal_Int8 actions) +{ + ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); + + m_nDefaultActions = actions; +} + +void DropTarget::drop(const DropTargetDropEvent& dtde) noexcept +{ + osl::ClearableGuard<::osl::Mutex> aGuard(m_aMutex); + std::vector<uno::Reference<XDropTargetListener>> aListeners(m_aListeners); + aGuard.clear(); + + for (auto const& listener : aListeners) + { + listener->drop(dtde); + } +} + +void DropTarget::dragEnter(const DropTargetDragEnterEvent& dtde) noexcept +{ + osl::ClearableGuard<::osl::Mutex> aGuard(m_aMutex); + std::vector<uno::Reference<XDropTargetListener>> aListeners(m_aListeners); + aGuard.clear(); + + for (auto const& listener : aListeners) + { + listener->dragEnter(dtde); + } +} + +void DropTarget::dragExit(const DropTargetEvent& dte) noexcept +{ + osl::ClearableGuard<::osl::Mutex> aGuard(m_aMutex); + std::vector<uno::Reference<XDropTargetListener>> aListeners(m_aListeners); + aGuard.clear(); + + for (auto const& listener : aListeners) + { + listener->dragExit(dte); + } +} + +void DropTarget::dragOver(const DropTargetDragEvent& dtde) noexcept +{ + osl::ClearableGuard<::osl::Mutex> aGuard(m_aMutex); + std::vector<uno::Reference<XDropTargetListener>> aListeners(m_aListeners); + aGuard.clear(); + + for (auto const& listener : aListeners) + { + listener->dragOver(dtde); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/unx/generic/dtrans/X11_droptarget.cxx b/vcl/unx/generic/dtrans/X11_droptarget.cxx index 5b5c448bf2d6..938339ceff55 100644 --- a/vcl/unx/generic/dtrans/X11_droptarget.cxx +++ b/vcl/unx/generic/dtrans/X11_droptarget.cxx @@ -27,21 +27,18 @@ using namespace com::sun::star::awt; using namespace com::sun::star::datatransfer; using namespace com::sun::star::datatransfer::dnd; -DropTarget::DropTarget() - : ::cppu::WeakComponentImplHelper<XDropTarget, XServiceInfo>(m_aMutex) - , m_bActive(false) - , m_nDefaultActions(0) - , m_aTargetWindow(None) +X11DropTarget::X11DropTarget() + : m_aTargetWindow(None) { } -DropTarget::~DropTarget() +X11DropTarget::~X11DropTarget() { if( m_xSelectionManager.is() ) m_xSelectionManager->deregisterDropTarget( m_aTargetWindow ); } -void DropTarget::initialize(::Window aWindow) +void X11DropTarget::initialize(::Window aWindow) { m_xSelectionManager = &SelectionManager::get(); m_xSelectionManager->initialize(); @@ -50,108 +47,22 @@ void DropTarget::initialize(::Window aWindow) { m_xSelectionManager->registerDropTarget( aWindow, this ); m_aTargetWindow = aWindow; - m_bActive = true; - } -} - -void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener ) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - m_aListeners.push_back( xListener ); -} - -void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener ) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - std::erase(m_aListeners, xListener); -} - -sal_Bool DropTarget::isActive() -{ - return m_bActive; -} - -void DropTarget::setActive( sal_Bool active ) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - m_bActive = active; -} - -sal_Int8 DropTarget::getDefaultActions() -{ - return m_nDefaultActions; -} - -void DropTarget::setDefaultActions( sal_Int8 actions ) -{ - ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); - - m_nDefaultActions = actions; -} - -void DropTarget::drop( const DropTargetDropEvent& dtde ) noexcept -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners ); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->drop(dtde); - } -} - -void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) noexcept -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners ); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragEnter(dtde); - } -} - -void DropTarget::dragExit( const DropTargetEvent& dte ) noexcept -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners ); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragExit(dte); - } -} - -void DropTarget::dragOver( const DropTargetDragEvent& dtde ) noexcept -{ - osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex ); - std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners ); - aGuard.clear(); - - for (auto const& listener : aListeners) - { - listener->dragOver(dtde); + setActive(true); } } // XServiceInfo -OUString DropTarget::getImplementationName() +OUString X11DropTarget::getImplementationName() { return u"com.sun.star.datatransfer.dnd.XdndDropTarget"_ustr; } -sal_Bool DropTarget::supportsService( const OUString& ServiceName ) +sal_Bool X11DropTarget::supportsService(const OUString& ServiceName) { return cppu::supportsService(this, ServiceName); } -Sequence< OUString > DropTarget::getSupportedServiceNames() +Sequence<OUString> X11DropTarget::getSupportedServiceNames() { return Xdnd_dropTarget_getSupportedServiceNames(); } diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx index 770845c7adb6..da2aec2cdeee 100644 --- a/vcl/unx/generic/dtrans/X11_selection.cxx +++ b/vcl/unx/generic/dtrans/X11_selection.cxx @@ -3939,7 +3939,7 @@ extern "C" typedef int(*xerror_hdl_t)(Display*,XErrorEvent*); } -void SelectionManager::registerDropTarget( ::Window aWindow, DropTarget* pTarget ) +void SelectionManager::registerDropTarget(::Window aWindow, X11DropTarget* pTarget) { osl::MutexGuard aGuard(m_aMutex); diff --git a/vcl/unx/generic/dtrans/X11_selection.hxx b/vcl/unx/generic/dtrans/X11_selection.hxx index fb5fb8dbd7ad..253229320269 100644 --- a/vcl/unx/generic/dtrans/X11_selection.hxx +++ b/vcl/unx/generic/dtrans/X11_selection.hxx @@ -20,6 +20,7 @@ #pragma once #include <displayconnectiondispatch.hxx> +#include <DropTarget.hxx> #include <cppuhelper/compbase.hxx> #include <cppuhelper/implbase.hxx> @@ -62,38 +63,18 @@ namespace x11 { ~SelectionAdaptor() {} }; - class DropTarget : public ::cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget, - css::lang::XServiceInfo> + class X11DropTarget : public ::cppu::ImplInheritanceHelper<DropTarget, css::lang::XServiceInfo> { - ::osl::Mutex m_aMutex; - bool m_bActive; - sal_Int8 m_nDefaultActions; ::Window m_aTargetWindow; rtl::Reference<SelectionManager> m_xSelectionManager; - ::std::vector< css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > > - m_aListeners; public: - DropTarget(); - virtual ~DropTarget() override; - - // convenience functions that loop over listeners - void dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde ) noexcept; - void dragExit( const css::datatransfer::dnd::DropTargetEvent& dte ) noexcept; - void dragOver( const css::datatransfer::dnd::DropTargetDragEvent& dtde ) noexcept; - void drop( const css::datatransfer::dnd::DropTargetDropEvent& dtde ) noexcept; + X11DropTarget(); + virtual ~X11DropTarget() override; void initialize(::Window aWindow); - // 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; - // XServiceInfo virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; @@ -208,20 +189,20 @@ namespace x11 { // a struct to hold data associated with a XDropTarget struct DropTargetEntry { - DropTarget* m_pTarget; + X11DropTarget* m_pTarget; ::Window m_aRootWindow; DropTargetEntry() : m_pTarget( nullptr ), m_aRootWindow( None ) {} - explicit DropTargetEntry( DropTarget* pTarget ) : - m_pTarget( pTarget ), - m_aRootWindow( None ) - {} + explicit DropTargetEntry(X11DropTarget* pTarget) + : m_pTarget(pTarget) + , m_aRootWindow(None) + {} DropTargetEntry( const DropTargetEntry& rEntry ) : m_pTarget( rEntry.m_pTarget ), m_aRootWindow( rEntry.m_aRootWindow ) {} - DropTarget* operator->() const { return m_pTarget; } + X11DropTarget* operator->() const { return m_pTarget; } DropTargetEntry& operator=(const DropTargetEntry& rEntry) { m_pTarget = rEntry.m_pTarget; m_aRootWindow = rEntry.m_aRootWindow; return *this; } }; @@ -425,7 +406,7 @@ namespace x11 { bool getPasteData( Atom selection, const OUString& rType, css::uno::Sequence< sal_Int8 >& rData ); // for XDropTarget to register/deregister itself - void registerDropTarget( ::Window aXLIB_Window, DropTarget* pTarget ); + void registerDropTarget(::Window aXLIB_Window, X11DropTarget* pTarget); void deregisterDropTarget( ::Window aXLIB_Window ); // for XDropTarget{Drag|Drop}Context diff --git a/vcl/unx/generic/dtrans/X11_service.cxx b/vcl/unx/generic/dtrans/X11_service.cxx index 4e268f4f20f9..191659b41653 100644 --- a/vcl/unx/generic/dtrans/X11_service.cxx +++ b/vcl/unx/generic/dtrans/X11_service.cxx @@ -90,7 +90,7 @@ X11SalInstance::ImplCreateDragSource(const SystemEnvData*) css::uno::Reference<css::datatransfer::dnd::XDropTarget> X11SalInstance::ImplCreateDropTarget(const SystemEnvData* pSysEnv) { - rtl::Reference<DropTarget> xDropTarget = new DropTarget(); + rtl::Reference<X11DropTarget> xDropTarget = new X11DropTarget(); X11SalFrame* pFrame = static_cast<X11SalFrame*>(pSysEnv->pSalFrame); ::Window aShellWindow = pFrame ? pFrame->GetShellWindow() : 0;