include/vcl/transfer.hxx | 13 ++++----- vcl/source/treelist/transfer.cxx | 52 ++++++++++++--------------------------- 2 files changed, 23 insertions(+), 42 deletions(-)
New commits: commit 14c2c76474b93551195fab3b75d5ba42535c7f11 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Jun 3 15:31:24 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Jun 4 07:35:25 2025 +0200 tdf#166837 vcl: Drop TransferableDataHelper_Impl Move its only member directly to TransferableDataHelper to simplify things. Change-Id: I82759ac25794192b6055fe9aa06c54327c0d5763 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186148 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/transfer.hxx b/include/vcl/transfer.hxx index 9582c5fa2197..4af956e60418 100644 --- a/include/vcl/transfer.hxx +++ b/include/vcl/transfer.hxx @@ -57,6 +57,7 @@ class ImageMap; class INetBookmark; class INetImage; class FileList; +class TransferableClipboardNotifier; namespace vcl { class Window; } // Drag&Drop defines @@ -263,8 +264,6 @@ public: static void ClearPrimarySelection(); }; -struct TransferableDataHelper_Impl; - class VCL_DLLPUBLIC TransferableDataHelper final { friend class DropTargetHelper; @@ -273,7 +272,7 @@ class VCL_DLLPUBLIC TransferableDataHelper final css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard; DataFlavorExVector maFormats; std::unique_ptr<TransferableObjectDescriptor> mxObjDesc; - std::unique_ptr<TransferableDataHelper_Impl> mxImpl; + rtl::Reference<TransferableClipboardNotifier> mxClipboardListener; void InitFormats(); diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx index d486eb8bea19..3638c33007d3 100644 --- a/vcl/source/treelist/transfer.cxx +++ b/vcl/source/treelist/transfer.cxx @@ -1060,8 +1060,6 @@ void TransferableHelper::ClearPrimarySelection() xSelection->setContents( nullptr, nullptr ); } -namespace { - class TransferableClipboardNotifier : public ::cppu::WeakImplHelper< XClipboardListener > { private: @@ -1085,7 +1083,6 @@ public: void dispose(); }; -} TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener ) :mxNotifier( _rxClipboard, UNO_QUERY ) @@ -1131,25 +1128,14 @@ void TransferableClipboardNotifier::dispose() mpListener = nullptr; } -struct TransferableDataHelper_Impl -{ - rtl::Reference<TransferableClipboardNotifier> mxClipboardListener; - - TransferableDataHelper_Impl() - { - } -}; - TransferableDataHelper::TransferableDataHelper() : mxObjDesc(new TransferableObjectDescriptor) - , mxImpl(new TransferableDataHelper_Impl) { } TransferableDataHelper::TransferableDataHelper(const Reference< css::datatransfer::XTransferable >& rxTransferable) : mxTransfer(rxTransferable) , mxObjDesc(new TransferableObjectDescriptor) - , mxImpl(new TransferableDataHelper_Impl) { InitFormats(); } @@ -1159,7 +1145,6 @@ TransferableDataHelper::TransferableDataHelper(const TransferableDataHelper& rDa , mxClipboard(rDataHelper.mxClipboard) , maFormats(rDataHelper.maFormats) , mxObjDesc(new TransferableObjectDescriptor(*rDataHelper.mxObjDesc)) - , mxImpl(new TransferableDataHelper_Impl) { } @@ -1168,7 +1153,6 @@ TransferableDataHelper::TransferableDataHelper(TransferableDataHelper&& rDataHel , mxClipboard(std::move(rDataHelper.mxClipboard)) , maFormats(std::move(rDataHelper.maFormats)) , mxObjDesc(std::move(rDataHelper.mxObjDesc)) - , mxImpl(new TransferableDataHelper_Impl) { } @@ -1178,7 +1162,7 @@ TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDat { SolarMutexGuard g; - const bool bWasClipboardListening = mxImpl->mxClipboardListener.is(); + const bool bWasClipboardListening = mxClipboardListener.is(); if (bWasClipboardListening) StopClipboardListening(); @@ -1199,7 +1183,7 @@ TransferableDataHelper& TransferableDataHelper::operator=(TransferableDataHelper { SolarMutexGuard g; - const bool bWasClipboardListening = mxImpl->mxClipboardListener.is(); + const bool bWasClipboardListening = mxClipboardListener.is(); if (bWasClipboardListening) StopClipboardListening(); @@ -2133,19 +2117,19 @@ bool TransferableDataHelper::StartClipboardListening( ) StopClipboardListening( ); - mxImpl->mxClipboardListener = new TransferableClipboardNotifier(mxClipboard, *this); + mxClipboardListener = new TransferableClipboardNotifier(mxClipboard, *this); - return mxImpl->mxClipboardListener->isListening(); + return mxClipboardListener->isListening(); } void TransferableDataHelper::StopClipboardListening( ) { SolarMutexGuard g; - if (mxImpl->mxClipboardListener.is()) + if (mxClipboardListener.is()) { - mxImpl->mxClipboardListener->dispose(); - mxImpl->mxClipboardListener.clear(); + mxClipboardListener->dispose(); + mxClipboardListener.clear(); } } commit d37fdb9ef2662e8dae5df864d93fe0ef9152f9b0 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Jun 3 14:55:14 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Jun 4 07:35:17 2025 +0200 tdf#166837 vcl: Avoid some const_cast Make methods non-const instead of having const methods and const_cast'ing in them. Change-Id: I704da690e52b14645e8c535099221e9bcce2c713 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186147 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/transfer.hxx b/include/vcl/transfer.hxx index 0d1e0687d11e..9582c5fa2197 100644 --- a/include/vcl/transfer.hxx +++ b/include/vcl/transfer.hxx @@ -247,16 +247,16 @@ protected: virtual void DragFinished( sal_Int8 nDropAction ); virtual void ObjectReleased(); - void CopyToSelection(const css::uno::Reference<css::datatransfer::clipboard::XClipboard> &rClipboard) const; + void CopyToSelection(const css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rClipboard); public: void PrepareOLE( const TransferableObjectDescriptor& rObjDesc ); - void CopyToClipboard(const css::uno::Reference<css::datatransfer::clipboard::XClipboard> &rClipboard) const; + void CopyToClipboard(const css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rClipboard); // convenience versions of the above which extract the XClipboard from the pWindow - void CopyToClipboard( vcl::Window *pWindow ) const; - void CopyToPrimarySelection() const; + void CopyToClipboard(vcl::Window* pWindow); + void CopyToPrimarySelection(); void StartDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions ); diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx index af119397e0a8..d486eb8bea19 100644 --- a/vcl/source/treelist/transfer.cxx +++ b/vcl/source/treelist/transfer.cxx @@ -957,7 +957,7 @@ void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDes AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); } -void TransferableHelper::CopyToClipboard(const Reference<XClipboard>& rClipboard) const +void TransferableHelper::CopyToClipboard(const Reference<XClipboard>& rClipboard) { if( rClipboard.is() ) mxClipboard = rClipboard; @@ -967,19 +967,18 @@ void TransferableHelper::CopyToClipboard(const Reference<XClipboard>& rClipboard try { - TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); - pThis->mxTerminateListener = new TerminateListener( *pThis ); + mxTerminateListener = new TerminateListener(*this); Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); - xDesktop->addTerminateListener( pThis->mxTerminateListener ); + xDesktop->addTerminateListener(mxTerminateListener); - mxClipboard->setContents( pThis, pThis ); + mxClipboard->setContents(this, this); } catch( const css::uno::Exception& ) { } } -void TransferableHelper::CopyToClipboard( vcl::Window *pWindow ) const +void TransferableHelper::CopyToClipboard(vcl::Window* pWindow) { DBG_ASSERT( pWindow, "Window pointer is NULL" ); Reference< XClipboard > xClipboard; @@ -990,26 +989,25 @@ void TransferableHelper::CopyToClipboard( vcl::Window *pWindow ) const CopyToClipboard(xClipboard); } -void TransferableHelper::CopyToSelection(const Reference<XClipboard>& rSelection) const +void TransferableHelper::CopyToSelection(const Reference<XClipboard>& rSelection) { if( !rSelection.is() || mxTerminateListener.is() ) return; try { - TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); - pThis->mxTerminateListener = new TerminateListener( *pThis ); + mxTerminateListener = new TerminateListener(*this); Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); - xDesktop->addTerminateListener( pThis->mxTerminateListener ); + xDesktop->addTerminateListener(mxTerminateListener); - rSelection->setContents( pThis, pThis ); + rSelection->setContents(this, this); } catch( const css::uno::Exception& ) { } } -void TransferableHelper::CopyToPrimarySelection() const +void TransferableHelper::CopyToPrimarySelection() { CopyToSelection(GetSystemPrimarySelection()); }