diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-28 11:42:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-28 17:43:37 +0100 |
commit | 989b4f318339922080e8fa6ead14076b5d6402db (patch) | |
tree | a57b1f41604405cb50705acf9d01fbafb78b54ee | |
parent | tdf#160399 speed up print preview (diff) | |
download | core-989b4f318339922080e8fa6ead14076b5d6402db.tar.gz core-989b4f318339922080e8fa6ead14076b5d6402db.zip |
Add comphelper::WeakImplHelperBase
in the same way I added WeakComponentImplHelperBase
Change-Id: I26d93004c3ddf716063cfb2ded1bbda1b76c2a98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165449
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | comphelper/source/misc/compbase.cxx | 28 | ||||
-rw-r--r-- | include/comphelper/compbase.hxx | 56 | ||||
-rw-r--r-- | sd/source/ui/unoidl/UnoDocumentSettings.cxx | 2 | ||||
-rw-r--r-- | svx/source/unodraw/UnoGraphicExporter.cxx | 2 |
4 files changed, 86 insertions, 2 deletions
diff --git a/comphelper/source/misc/compbase.cxx b/comphelper/source/misc/compbase.cxx index d88a534777f1..1827527d1d56 100644 --- a/comphelper/source/misc/compbase.cxx +++ b/comphelper/source/misc/compbase.cxx @@ -227,6 +227,34 @@ css::uno::Any WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::c return pBase->comphelper::WeakComponentImplHelperBase::queryInterface(rType); } +WeakImplHelperBase::~WeakImplHelperBase() {} + +css::uno::Any SAL_CALL WeakImplHelperBase::queryInterface(css::uno::Type const& rType) +{ + css::uno::Any aReturn = ::cppu::queryInterface(rType, static_cast<css::uno::XWeak*>(this)); + if (aReturn.hasValue()) + return aReturn; + return OWeakObject::queryInterface(rType); +} + +css::uno::Any WeakImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd, + WeakImplHelperBase* pBase) +{ + checkInterface(rType); + typelib_TypeDescriptionReference* pTDR = rType.getTypeLibType(); + + // shortcut XInterface to WeakComponentImplHelperBase + if (!isXInterface(pTDR->pTypeName)) + { + void* p = queryDeepNoXInterface(pTDR, cd, pBase); + if (p) + { + return css::uno::Any(&p, pTDR); + } + } + return pBase->comphelper::WeakImplHelperBase::queryInterface(rType); +} + } // namespace comphelper /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/comphelper/compbase.hxx b/include/comphelper/compbase.hxx index 2d06a71047a6..c0ebf3f1ff1d 100644 --- a/include/comphelper/compbase.hxx +++ b/include/comphelper/compbase.hxx @@ -117,6 +117,62 @@ COMPHELPER_DLLPUBLIC css::uno::Any WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd, WeakComponentImplHelperBase* pBase); +/** + Serves two purposes + (1) extracts code that doesn't need to be templated + (2) helps to handle the custom where we have conflicting interfaces + e.g. multiple UNO interfaces that extend css::lang::XComponent +*/ +class COMPHELPER_DLLPUBLIC WeakImplHelperBase : public virtual comphelper::UnoImplBase, + public cppu::OWeakObject +{ +public: + virtual ~WeakImplHelperBase() override; + + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override; +}; + +template <typename... Ifc> +class SAL_DLLPUBLIC_TEMPLATE WeakImplHelper : public WeakImplHelperBase, + public css::lang::XTypeProvider, + public Ifc... +{ +public: + virtual void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); } + + virtual void SAL_CALL release() noexcept override { OWeakObject::release(); } + + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override + { + return WeakImplHelper_query(rType, class_data_get(), this); + } + + // css::lang::XTypeProvider + virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override + { + static const css::uno::Sequence<css::uno::Type> aTypeList{ + cppu::UnoType<css::uno::XWeak>::get(), cppu::UnoType<css::lang::XComponent>::get(), + cppu::UnoType<css::lang::XTypeProvider>::get(), cppu::UnoType<Ifc>::get()... + }; + return aTypeList; + } + virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override + { + return css::uno::Sequence<sal_Int8>(); + } + +private: + static cppu::class_data* class_data_get() + { + return cppu::detail::ImplClassData<WeakImplHelper, Ifc...>{}(); + } +}; + +/** WeakImplHelper +*/ +COMPHELPER_DLLPUBLIC css::uno::Any +WeakImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd, WeakImplHelperBase* pBase); + } // namespace comphelper /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sd/source/ui/unoidl/UnoDocumentSettings.cxx b/sd/source/ui/unoidl/UnoDocumentSettings.cxx index 331f90b53a50..5d3ee2d6d696 100644 --- a/sd/source/ui/unoidl/UnoDocumentSettings.cxx +++ b/sd/source/ui/unoidl/UnoDocumentSettings.cxx @@ -69,7 +69,7 @@ namespace sd { namespace { - class DocumentSettings : public WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >, + class DocumentSettings : public cppu::WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >, public comphelper::PropertySetHelper, public DocumentSettingsSerializer { diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx index 4b971936b82a..649b70a82b5d 100644 --- a/svx/source/unodraw/UnoGraphicExporter.cxx +++ b/svx/source/unodraw/UnoGraphicExporter.cxx @@ -130,7 +130,7 @@ namespace { @implements com.sun.star.drawing.GraphicExportFilter */ - class GraphicExporter : public WeakImplHelper< XGraphicExportFilter, XServiceInfo > + class GraphicExporter : public ::cppu::WeakImplHelper< XGraphicExportFilter, XServiceInfo > { public: GraphicExporter(); |