vcl/inc/DropTarget.hxx | 4 - vcl/inc/qt5/QtDragAndDrop.hxx | 27 ++-------- vcl/qt5/QtDragAndDrop.cxx | 77 +------------------------------ vcl/qt5/QtFrame.cxx | 10 +--- vcl/source/app/DropTarget.cxx | 6 +- vcl/unx/generic/dtrans/X11_selection.cxx | 31 ++++-------- vcl/unx/generic/dtrans/X11_selection.hxx | 1 vcl/unx/gtk3/gtkframe.cxx | 4 - 8 files changed, 31 insertions(+), 129 deletions(-)
New commits: commit 4b17d7b1a1c263fa544e3a750d8dc86607ac0f95 Author: Michael Weghorn <[email protected]> AuthorDate: Fri Jul 4 19:30:35 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jul 5 07:46:48 2025 +0200 vcl: Simplify DropTarget::dragExit use Move logic to create the event into the method instead of taking the event as a param, to simplify and deduplicate logic in the callers. Change-Id: I2e5923d5b439f562f5c8c479b40c8426a625ccfe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187423 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/DropTarget.hxx b/vcl/inc/DropTarget.hxx index 798ee9f1ab10..00686524ff9a 100644 --- a/vcl/inc/DropTarget.hxx +++ b/vcl/inc/DropTarget.hxx @@ -39,7 +39,7 @@ protected: 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 dragExit() noexcept; void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) noexcept; virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) noexcept; diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 4c58165f64a8..b67ed31017d2 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -1417,9 +1417,7 @@ void QtFrame::handleDrop(QDropEvent* pEvent) void QtFrame::handleDragLeave() { - css::datatransfer::dnd::DropTargetEvent aEvent; - aEvent.Source = static_cast<css::datatransfer::dnd::XDropTarget*>(m_pDropTarget); - m_pDropTarget->dragExit(aEvent); + m_pDropTarget->dragExit(); m_bInDrag = false; } diff --git a/vcl/source/app/DropTarget.cxx b/vcl/source/app/DropTarget.cxx index fec6a17bf8ab..e7339d0db6d3 100644 --- a/vcl/source/app/DropTarget.cxx +++ b/vcl/source/app/DropTarget.cxx @@ -88,15 +88,17 @@ void DropTarget::dragEnter(const DropTargetDragEnterEvent& dtde) noexcept } } -void DropTarget::dragExit(const DropTargetEvent& dte) noexcept +void DropTarget::dragExit() noexcept { osl::ClearableGuard<::osl::Mutex> aGuard(m_aMutex); std::vector<uno::Reference<XDropTargetListener>> aListeners(m_aListeners); aGuard.clear(); + DropTargetEvent aEvent; + aEvent.Source = getXWeak(); for (auto const& listener : aListeners) { - listener->dragExit(dte); + listener->dragExit(aEvent); } } diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx index 9178d12ea2dc..ba1fc519da8e 100644 --- a/vcl/unx/generic/dtrans/X11_selection.cxx +++ b/vcl/unx/generic/dtrans/X11_selection.cxx @@ -2257,14 +2257,13 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) << std::showbase << std::hex << aTarget); #endif - DropTargetEvent aEvent; - aEvent.Source = static_cast< XDropTarget* >(it->second.m_pTarget); + m_aDropEnterEvent.data.l[0] = None; if( m_aCurrentDropWindow == aTarget ) m_aCurrentDropWindow = None; m_nCurrentProtocolVersion = nXdndProtocolRevision; aGuard.clear(); - it->second.m_pTarget->dragExit(aEvent); + it->second.m_pTarget->dragExit(); } else if( rMessage.message_type == m_nXdndDrop && @@ -2306,10 +2305,8 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) SAL_INFO("vcl.unx.dtrans", "XdndDrop canceled due to " << "m_bLastDropAccepted = false." ); #endif - DropTargetEvent aEvent; - aEvent.Source = static_cast< XDropTarget* >(it->second.m_pTarget); aGuard.clear(); - it->second.m_pTarget->dragExit(aEvent); + it->second.m_pTarget->dragExit(); // reset the drop status, notify source dropComplete( false, m_aCurrentDropWindow ); } @@ -2726,10 +2723,8 @@ bool SelectionManager::handleDragEvent( XEvent const & rMessage ) // abort drag if( it != m_aDropTargets.end() ) { - DropTargetEvent dte; - dte.Source = it->second.m_pTarget->getXWeak(); aGuard.clear(); - it->second.m_pTarget->dragExit( dte ); + it->second.m_pTarget->dragExit(); aGuard.reset(); } else if( m_aDropProxy != None && m_nCurrentProtocolVersion >= 0 ) @@ -3113,10 +3108,8 @@ void SelectionManager::updateDragWindow( int nX, int nY, ::Window aRoot ) if( it != m_aDropTargets.end() ) // shortcut for own drop targets { - DropTargetEvent dte; - dte.Source = it->second.m_pTarget->getXWeak(); aGuard.clear(); - it->second.m_pTarget->dragExit( dte ); + it->second.m_pTarget->dragExit(); aGuard.reset(); } else @@ -3994,10 +3987,8 @@ void SelectionManager::deregisterDropTarget( ::Window aWindow ) m_aDropTargets.find( m_aDropWindow ); if( it != m_aDropTargets.end() ) { - DropTargetEvent dte; - dte.Source = it->second.m_pTarget->getXWeak(); aGuard.clear(); - it->second.m_pTarget->dragExit( dte ); + it->second.m_pTarget->dragExit(); aGuard.reset(); } else if( m_aDropProxy != None && m_nCurrentProtocolVersion >= 0 ) diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index f918c3d0c12f..7d78bef83bd1 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -5448,9 +5448,7 @@ void GtkSalFrame::signalDragLeave(GtkWidget* pWidget, GdkDragContext* /*context* 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->dragExit(aEvent); + pThis->dragExit(); return false; } commit 9ea4f910067a2441a3da4c7e25d6b90057e14d72 Author: Michael Weghorn <[email protected]> AuthorDate: Fri Jul 4 19:15:24 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jul 5 07:46:42 2025 +0200 gen: Drop DropTargetEntry::operator-> Explicitly access the m_pTarget member instead to unify code and make this a bit more obvious. Change-Id: Id021f21b0f7f8b9314b0ee800f84343e3e72c61d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187422 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx index da2aec2cdeee..9178d12ea2dc 100644 --- a/vcl/unx/generic/dtrans/X11_selection.cxx +++ b/vcl/unx/generic/dtrans/X11_selection.cxx @@ -2238,12 +2238,12 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) m_bDropEnterSent = true; aEvent.SupportedDataFlavors = m_xDropTransferable->getTransferDataFlavors(); aGuard.clear(); - it->second->dragEnter( aEvent ); + it->second.m_pTarget->dragEnter(aEvent); } else { aGuard.clear(); - it->second->dragOver( aEvent ); + it->second.m_pTarget->dragOver(aEvent); } } else if( @@ -2264,7 +2264,7 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) m_aCurrentDropWindow = None; m_nCurrentProtocolVersion = nXdndProtocolRevision; aGuard.clear(); - it->second->dragExit( aEvent ); + it->second.m_pTarget->dragExit(aEvent); } else if( rMessage.message_type == m_nXdndDrop && @@ -2298,7 +2298,7 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) m_bDropWaitingForCompletion = true; aGuard.clear(); - it->second->drop( aEvent ); + it->second.m_pTarget->drop(aEvent); } else { @@ -2309,7 +2309,7 @@ bool SelectionManager::handleDropEvent( XClientMessageEvent const & rMessage ) DropTargetEvent aEvent; aEvent.Source = static_cast< XDropTarget* >(it->second.m_pTarget); aGuard.clear(); - it->second->dragExit( aEvent ); + it->second.m_pTarget->dragExit(aEvent); // reset the drop status, notify source dropComplete( false, m_aCurrentDropWindow ); } @@ -2538,7 +2538,7 @@ void SelectionManager::sendDropPosition( bool bForce, Time eventTime ) dtde.DropAction = getUserDragAction(); dtde.SourceActions = m_nSourceActions; aGuard.clear(); - it->second->dragOver( dtde ); + it->second.m_pTarget->dragOver(dtde); } } else if( bForce || @@ -2812,7 +2812,7 @@ bool SelectionManager::handleDragEvent( XEvent const & rMessage ) m_nDropTimeout = time( nullptr ); m_bDropWaitingForCompletion = true; aGuard.clear(); - it->second->drop( dtde ); + it->second.m_pTarget->drop(dtde); bCancel = false; } else bCancel = true; diff --git a/vcl/unx/generic/dtrans/X11_selection.hxx b/vcl/unx/generic/dtrans/X11_selection.hxx index 253229320269..3fcfdc97d224 100644 --- a/vcl/unx/generic/dtrans/X11_selection.hxx +++ b/vcl/unx/generic/dtrans/X11_selection.hxx @@ -202,7 +202,6 @@ namespace x11 { m_aRootWindow( rEntry.m_aRootWindow ) {} - X11DropTarget* operator->() const { return m_pTarget; } DropTargetEntry& operator=(const DropTargetEntry& rEntry) { m_pTarget = rEntry.m_pTarget; m_aRootWindow = rEntry.m_aRootWindow; return *this; } }; commit 9e69e4becb63a726993b80787b5610cadd71a765 Author: Michael Weghorn <[email protected]> AuthorDate: Fri Jul 4 18:56:31 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Jul 5 07:46:35 2025 +0200 qt: Subclass DropTarget to deduplicate code Subclass the new base class introduced in Change-Id: Ib6783437ab34b1e7788bbbfc67aff85026ac62f3 Author: Michael Weghorn <[email protected]> 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. Override the base class DropTarget::drop in order to keep setting QtDropTarget::m_bDropSuccessful to true in addition to what the base class logic implements. Change-Id: I622cf298b3bde49c1115fab8422a2fddb0d92b45 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187421 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/DropTarget.hxx b/vcl/inc/DropTarget.hxx index 6ac7c5b8ff28..798ee9f1ab10 100644 --- a/vcl/inc/DropTarget.hxx +++ b/vcl/inc/DropTarget.hxx @@ -41,7 +41,7 @@ public: 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; + virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) noexcept; // XDropTarget virtual void SAL_CALL addDropTargetListener( diff --git a/vcl/inc/qt5/QtDragAndDrop.hxx b/vcl/inc/qt5/QtDragAndDrop.hxx index b6bfb0188ac8..364431994fbb 100644 --- a/vcl/inc/qt5/QtDragAndDrop.hxx +++ b/vcl/inc/qt5/QtDragAndDrop.hxx @@ -10,6 +10,8 @@ #pragma once +#include <DropTarget.hxx> + #include <com/sun/star/datatransfer/dnd/XDragSource.hpp> #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -54,33 +56,19 @@ public: class QtDropTarget final : public QObject, - public cppu::WeakComponentImplHelper< - css::datatransfer::dnd::XDropTarget, css::datatransfer::dnd::XDropTargetDragContext, - css::datatransfer::dnd::XDropTargetDropContext, css::lang::XServiceInfo> + public cppu::ImplInheritanceHelper<DropTarget, css::datatransfer::dnd::XDropTargetDragContext, + css::datatransfer::dnd::XDropTargetDropContext, + css::lang::XServiceInfo> { Q_OBJECT - osl::Mutex m_aMutex; sal_Int8 m_nDropAction; - bool m_bActive; - sal_Int8 m_nDefaultActions; - std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners; bool m_bDropSuccessful; public: QtDropTarget(); virtual ~QtDropTarget() 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; - // XDropTargetDragContext virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override; virtual void SAL_CALL rejectDrag() override; @@ -95,10 +83,7 @@ public: 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& dtde); - void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte); - void fire_dragOver(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde); - void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde); + virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) noexcept override; sal_Int8 proposedDropAction() const { return m_nDropAction; } bool dropSuccessful() const { return m_bDropSuccessful; } diff --git a/vcl/qt5/QtDragAndDrop.cxx b/vcl/qt5/QtDragAndDrop.cxx index ecc967e1dc15..9a72758e3cbb 100644 --- a/vcl/qt5/QtDragAndDrop.cxx +++ b/vcl/qt5/QtDragAndDrop.cxx @@ -114,10 +114,7 @@ css::uno::Sequence<OUString> SAL_CALL QtDragSource::getSupportedServiceNames() } QtDropTarget::QtDropTarget() - : WeakComponentImplHelper(m_aMutex) - , m_nDropAction(datatransfer::dnd::DNDConstants::ACTION_NONE) - , m_bActive(false) - , m_nDefaultActions(0) + : m_nDropAction(datatransfer::dnd::DNDConstants::ACTION_NONE) { } @@ -138,79 +135,11 @@ css::uno::Sequence<OUString> SAL_CALL QtDropTarget::getSupportedServiceNames() QtDropTarget::~QtDropTarget() {} -void QtDropTarget::addDropTargetListener( - const uno::Reference<css::datatransfer::dnd::XDropTargetListener>& xListener) -{ - ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); - - m_aListeners.push_back(xListener); -} - -void QtDropTarget::removeDropTargetListener( - const uno::Reference<css::datatransfer::dnd::XDropTargetListener>& xListener) -{ - ::osl::Guard<::osl::Mutex> aGuard(m_aMutex); - - std::erase(m_aListeners, xListener); -} - -sal_Bool QtDropTarget::isActive() { return m_bActive; } - -void QtDropTarget::setActive(sal_Bool bActive) { m_bActive = bActive; } - -sal_Int8 QtDropTarget::getDefaultActions() { return m_nDefaultActions; } - -void QtDropTarget::setDefaultActions(sal_Int8 nDefaultActions) -{ - m_nDefaultActions = nDefaultActions; -} - -void QtDropTarget::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 QtDropTarget::fire_dragOver(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->dragOver(dtde); -} - -void QtDropTarget::fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) +void QtDropTarget::drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) noexcept { m_bDropSuccessful = true; - 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 QtDropTarget::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); + DropTarget::drop(dtde); } void QtDropTarget::acceptDrag(sal_Int8 dragOperation) { m_nDropAction = dragOperation; } diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 96fdf8ab98a6..4c58165f64a8 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -1361,11 +1361,11 @@ void QtFrame::handleDragMove(QDragMoveEvent* pEvent) // ask the drop target to accept our drop action if (!m_bInDrag) { - m_pDropTarget->fire_dragEnter(aEvent); + m_pDropTarget->dragEnter(aEvent); m_bInDrag = true; } else - m_pDropTarget->fire_dragOver(aEvent); + m_pDropTarget->dragOver(aEvent); // the drop target accepted our drop action => inform Qt if (m_pDropTarget->proposedDropAction() != 0) @@ -1390,7 +1390,7 @@ void QtFrame::handleDrop(QDropEvent* pEvent) aEvent.LocationY *= fDevicePixelRatio; // ask the drop target to accept our drop action - m_pDropTarget->fire_drop(aEvent); + m_pDropTarget->drop(aEvent); m_bInDrag = false; const bool bDropSuccessful = m_pDropTarget->dropSuccessful(); @@ -1419,7 +1419,7 @@ void QtFrame::handleDragLeave() { css::datatransfer::dnd::DropTargetEvent aEvent; aEvent.Source = static_cast<css::datatransfer::dnd::XDropTarget*>(m_pDropTarget); - m_pDropTarget->fire_dragExit(aEvent); + m_pDropTarget->dragExit(aEvent); m_bInDrag = false; }
