vcl/win/dtrans/WinClipboard.cxx | 9 +++------ vcl/win/dtrans/WinClipboard.hxx | 2 +- vcl/win/dtrans/XNotifyingDataObject.cxx | 7 +++---- vcl/win/dtrans/XNotifyingDataObject.hxx | 3 ++- 4 files changed, 9 insertions(+), 12 deletions(-)
New commits: commit 9fdb7eca0c14c2449ab185014d132035d985b5d2 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Jul 15 21:30:13 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Jul 15 21:35:43 2024 +0200 Use WeakReference to CWinClipboard instead of pointer Change-Id: I30cbbec885e9132d45bf19293890b3e2f581e928 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170515 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/vcl/win/dtrans/WinClipboard.cxx b/vcl/win/dtrans/WinClipboard.cxx index be0266addd18..8341e446360b 100644 --- a/vcl/win/dtrans/WinClipboard.cxx +++ b/vcl/win/dtrans/WinClipboard.cxx @@ -352,18 +352,15 @@ dtrans_CWinClipboard_get_implementation(css::uno::XComponentContext* context, } } -void CWinClipboard::onReleaseDataObject(CXNotifyingDataObject* theCaller) +void CWinClipboard::onReleaseDataObject(CXNotifyingDataObject& theCaller) { - OSL_ASSERT(nullptr != theCaller); - - if (theCaller) - theCaller->lostOwnership(); + theCaller.lostOwnership(); // if the current caller is the one we currently hold, then set it to NULL // because an external source must be the clipboardowner now std::unique_lock aGuard(m_aMutex); - if (getOwnClipContent() == theCaller) + if (getOwnClipContent() == &theCaller) m_pCurrentOwnClipContent = m_pNewOwnClipContent = nullptr; } diff --git a/vcl/win/dtrans/WinClipboard.hxx b/vcl/win/dtrans/WinClipboard.hxx index 83d01da65e05..6d6a101058e8 100644 --- a/vcl/win/dtrans/WinClipboard.hxx +++ b/vcl/win/dtrans/WinClipboard.hxx @@ -66,7 +66,7 @@ class CWinClipboard final CXNotifyingDataObject* getOwnClipContent() const; void handleClipboardContentChanged(); - void onReleaseDataObject(CXNotifyingDataObject* theCaller); + void onReleaseDataObject(CXNotifyingDataObject& theCaller); void registerClipboardViewer(); void unregisterClipboardViewer(); diff --git a/vcl/win/dtrans/XNotifyingDataObject.cxx b/vcl/win/dtrans/XNotifyingDataObject.cxx index aab168f043d3..9d7c563a5a28 100644 --- a/vcl/win/dtrans/XNotifyingDataObject.cxx +++ b/vcl/win/dtrans/XNotifyingDataObject.cxx @@ -71,8 +71,8 @@ STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release( ) if ( 0 == nRefCnt ) { - if ( m_pWinClipImpl ) - m_pWinClipImpl->onReleaseDataObject( this ); + if (auto pWinClipImpl = m_pWinClipImpl.get()) + pWinClipImpl->onReleaseDataObject(*this); delete this; } @@ -137,8 +137,7 @@ void CXNotifyingDataObject::lostOwnership( ) try { if (m_XClipboardOwner.is()) - m_XClipboardOwner->lostOwnership( - static_cast<XClipboardEx*>(m_pWinClipImpl), m_XTransferable); + m_XClipboardOwner->lostOwnership(m_pWinClipImpl.get(), m_XTransferable); } catch(RuntimeException&) { diff --git a/vcl/win/dtrans/XNotifyingDataObject.hxx b/vcl/win/dtrans/XNotifyingDataObject.hxx index 408413a5de17..04fb5b93d49f 100644 --- a/vcl/win/dtrans/XNotifyingDataObject.hxx +++ b/vcl/win/dtrans/XNotifyingDataObject.hxx @@ -29,6 +29,7 @@ #include <objidl.h> #include <systools/win32/comtools.hxx> +#include <unotools/weakref.hxx> /*-------------------------------------------------------------------------- To implement the lostOwnership mechanism cleanly we need this wrapper @@ -76,7 +77,7 @@ private: IDataObjectPtr m_aIDataObject; const css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable; const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_XClipboardOwner; - CWinClipboard* const m_pWinClipImpl; + unotools::WeakReference<CWinClipboard> m_pWinClipImpl; friend class CWinClipboard; };