From e8d45fe35e6abb01d235aba263f6ff41a3efd5ed Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 2 Apr 2025 15:36:32 +0200 Subject: [PATCH] editeng a11y: Drop custom WeakCppRef, use unotools::WeakReference Use the existing unotools::WeakReference instead of the custom WeakCppRef template class to hold weak references to the AccessibleEditableTextPara objects in AccessibleParaManager. An AccessibleEditableTextPara forward-declaration is not sufficient to use unotools::WeakReference, so re-arrange includes/forward-declarations a bit. Drop the now unused WeakCppRef. Change-Id: I54553059a7cb36515109573c5b22d73738b1c46f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183672 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- ...d-can-be-private-symbols.functions.results | 1 - compilerplugins/clang/refcounting.cxx | 2 - .../AccessibleEditableTextPara.cxx | 1 + .../editeng/AccessibleEditableTextPara.hxx | 4 +- include/editeng/AccessibleParaManager.hxx | 51 ++----------------- 5 files changed, 8 insertions(+), 51 deletions(-) diff --git a/bin/find-can-be-private-symbols.functions.results b/bin/find-can-be-private-symbols.functions.results index 9102813cc553..223f26a67015 100644 --- a/bin/find-can-be-private-symbols.functions.results +++ b/bin/find-can-be-private-symbols.functions.results @@ -10349,7 +10349,6 @@ accessibility::AccessibleParaManager::IsReferencable(int) const accessibility::AccessibleParaManager::IsReferencable(rtl::Reference const&) accessibility::AccessibleParaManager::SetState(int, long) accessibility::AccessibleParaManager::SetState(long) -accessibility::AccessibleParaManager::ShutdownPara(std::pair, com::sun::star::awt::Rectangle> const&) accessibility::AccessibleParaManager::UnSetState(int, long) accessibility::AccessibleParaManager::UnSetState(long) accessibility::AccessibleShape::CreateAccessibleBaseName() diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 4140b6a10688..3b4cea9d368c 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -135,8 +135,6 @@ bool containsXInterfaceSubclass(const clang::Type* pType0) { .Namespace("sun").Namespace("com").GlobalNamespace()) || (dc.Class("Sequence").Namespace("uno").Namespace("star") .Namespace("sun").Namespace("com").GlobalNamespace()) - || (dc.Class("WeakCppRef").Namespace("accessibility") - .GlobalNamespace()) || (dc.Class("OAutoRegistration").Namespace("dba") .GlobalNamespace()) || (dc.Class("OMultiInstanceAutoRegistration").Namespace("dbp") diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx b/editeng/source/accessibility/AccessibleEditableTextPara.cxx index ebc8b49a9e11..19ed64c8ab35 100644 --- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx +++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx @@ -48,6 +48,7 @@ #include #include +#include #include #include #include diff --git a/include/editeng/AccessibleEditableTextPara.hxx b/include/editeng/AccessibleEditableTextPara.hxx index 7e9cae44a13b..423852e4427f 100644 --- a/include/editeng/AccessibleEditableTextPara.hxx +++ b/include/editeng/AccessibleEditableTextPara.hxx @@ -38,9 +38,9 @@ #include #include -#include #include #include +#include #include class SvxViewForwarder; @@ -52,6 +52,8 @@ namespace accessibility { class AccessibleImageBullet; } namespace accessibility { +class AccessibleParaManager; + typedef ::comphelper::WeakComponentImplHelper< css::accessibility::XAccessible, css::accessibility::XAccessibleContext, css::accessibility::XAccessibleComponent, diff --git a/include/editeng/AccessibleParaManager.hxx b/include/editeng/AccessibleParaManager.hxx index b6df448c9a36..f6ec8cb53300 100644 --- a/include/editeng/AccessibleParaManager.hxx +++ b/include/editeng/AccessibleParaManager.hxx @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include namespace com::sun::star::accessibility { class XAccessible; } @@ -37,60 +39,15 @@ class SvxEditSourceAdapter; namespace accessibility { -class AccessibleEditableTextPara; - -/** Helper class for weak object references plus implementation - - This class combines a weak reference (to facilitate automatic - object disposal if user drops last reference) and hard - reference to the c++ class (for fast access and bypassing of - the UNO interface) -*/ -template < class UnoType, class CppType > class WeakCppRef -{ -public: - - typedef UnoType UnoInterfaceType; - typedef CppType InterfaceType; - - WeakCppRef() : maWeakRef(), maUnsafeRef( nullptr ) {} - - WeakCppRef(rtl::Reference const & rImpl): - maWeakRef(rImpl.get()), - maUnsafeRef(rImpl.get()) - { - } - - // get object with c++ object and hard reference (which - // prevents the c++ object from destruction during use) - rtl::Reference get() const { - css::uno::Reference ref(maWeakRef); - return ref.is() ? maUnsafeRef : rtl::Reference(); - } - - // default copy constructor and assignment will do - // WeakCppRef( const WeakCppRef& ); - // WeakCppRef& operator= ( const WeakCppRef& ); - -private: - - // the interface, hold weakly - css::uno::WeakReference< UnoInterfaceType > maWeakRef; - - // hard ref to c++ class, _only_ valid if maWeakRef.is() is true - InterfaceType* maUnsafeRef; -}; - - /** This class manages the paragraphs of an AccessibleTextHelper To facilitate automatic deletion of paragraphs no longer used, - this class uses the WeakCppRef helper to hold the objects weakly. + this class uses unotools::WeakReference to hold the objects weakly. */ class UNLESS_MERGELIBS(EDITENG_DLLPUBLIC) AccessibleParaManager { public: - typedef WeakCppRef < css::accessibility::XAccessible, AccessibleEditableTextPara > WeakPara; + typedef unotools::WeakReference WeakPara; typedef ::std::pair< WeakPara, css::awt::Rectangle > WeakChild; typedef ::std::vector< WeakChild > VectorOfChildren;