From 4bc9c291f33d0e64100b12f7011460250a08bcd1 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Sun, 13 Dec 2015 22:02:03 +0100 Subject: remove SwXStyle creation outside of compilation unit Change-Id: I136822a0ad581d1490fc6f8842c95f2d25dfeba4 --- sw/inc/unostyle.hxx | 5 +++++ sw/source/core/unocore/unocoll.cxx | 13 ++++++------- sw/source/core/unocore/unostyle.cxx | 24 ++++++++++++++++++++---- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx index df697fe49309..ea7f723354bc 100644 --- a/sw/inc/unostyle.hxx +++ b/sw/inc/unostyle.hxx @@ -96,6 +96,11 @@ public: virtual OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException, std::exception ) override; virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( css::uno::RuntimeException, std::exception ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException, std::exception ) override; + + static css::uno::Reference CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc); + // FIXME: This is very ugly as is the whole conditional paragraph style + // hackety. Should be folded into CreateStyle hopefully one day + static css::uno::Reference CreateStyleCondParagraph(SwDoc& rDoc); }; diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 51f1501a2900..24f9980ae3cb 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -673,12 +673,15 @@ SwXServiceProvider::MakeInstance(sal_uInt16 nObjectType, SwDoc & rDoc) case SW_SERVICE_STYLE_PAGE_STYLE: case SW_SERVICE_STYLE_NUMBERING_STYLE: { - SfxStyleFamily eFamily = SFX_STYLE_FAMILY_CHAR; + SfxStyleFamily eFamily = SFX_STYLE_FAMILY_CHAR; switch(nObjectType) { case SW_SERVICE_STYLE_PARAGRAPH_STYLE: + eFamily = SFX_STYLE_FAMILY_PARA; + break; case SW_SERVICE_STYLE_CONDITIONAL_PARAGRAPH_STYLE: eFamily = SFX_STYLE_FAMILY_PARA; + xRet = SwXStyleFamilies::CreateStyleCondParagraph(rDoc); break; case SW_SERVICE_STYLE_FRAME_STYLE: eFamily = SFX_STYLE_FAMILY_FRAME; @@ -690,12 +693,8 @@ SwXServiceProvider::MakeInstance(sal_uInt16 nObjectType, SwDoc & rDoc) eFamily = SFX_STYLE_FAMILY_PSEUDO; break; } - SwXStyle* pNewStyle = (SFX_STYLE_FAMILY_PAGE == eFamily) - ? new SwXPageStyle(rDoc.GetDocShell()) - : (eFamily == SFX_STYLE_FAMILY_FRAME) - ? new SwXFrameStyle(&rDoc) - : new SwXStyle(&rDoc, eFamily, nObjectType == SW_SERVICE_STYLE_CONDITIONAL_PARAGRAPH_STYLE); - xRet = static_cast(pNewStyle); + if(!xRet.is()) + xRet = SwXStyleFamilies::CreateStyle(eFamily, rDoc); } break; case SW_SERVICE_FIELDTYPE_DATETIME: diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 7eb0e9405e21..d0efe3d29461 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -509,15 +509,30 @@ sal_Int32 lcl_GetCountOrName(const SwDoc& rDoc, OUStrin template static uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) - { return new SwXStyle(*pBasePool, eFamily, pDocShell->GetDoc(), sStyleName); }; + { return pBasePool ? new SwXStyle(*pBasePool, eFamily, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), eFamily, false); }; template<> +uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) + { return pBasePool ? new SwXStyle(*pBasePool, SFX_STYLE_FAMILY_PARA, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), SFX_STYLE_FAMILY_PARA, false); }; +template<> uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) - { return new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName); }; + { return pBasePool ? new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName) : new SwXFrameStyle(pDocShell->GetDoc()); }; template<> uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) - { return new SwXPageStyle(*pBasePool, pDocShell, SFX_STYLE_FAMILY_PAGE, sStyleName); }; + { return pBasePool ? new SwXPageStyle(*pBasePool, pDocShell, SFX_STYLE_FAMILY_PAGE, sStyleName) : new SwXPageStyle(pDocShell); }; + +uno::Reference SwXStyleFamilies::CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc) +{ + auto pEntries(lcl_GetStyleFamilyEntries()); + const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), + [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; }); + return pEntry == pEntries->end() ? nullptr : pEntry->m_fCreateStyle(nullptr, rDoc.GetDocShell(), ""); +} + +// FIXME: Ugly special casing that should die. +uno::Reference SwXStyleFamilies::CreateStyleCondParagraph(SwDoc& rDoc) + { return new SwXStyle(&rDoc, SFX_STYLE_FAMILY_PARA, true); }; template static sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex); @@ -965,7 +980,8 @@ SwXStyle::SwXStyle(SfxStyleSheetBasePool& rPool, SfxStyleFamily eFam, m_bIsConditional(false), m_pPropertiesImpl(nullptr) { - StartListening(rPool); + if(!m_pBasePool) + return; if(eFam == SFX_STYLE_FAMILY_PARA) { m_pBasePool->SetSearchMask(m_eFamily); -- cgit v1.2.3