From e5e3730265431541c1b0d53e1a5c409204c425f4 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Sat, 28 Nov 2015 15:48:46 +0100 Subject: use entries to create styles Change-Id: Ie68277b2ca9f4a82d048c7b74ab6705e8ca164b2 --- sw/source/core/unocore/unostyle.cxx | 56 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'sw/source/core/unocore') diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 2be224d7b6e3..d8de4dcf6fe4 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -94,18 +94,21 @@ namespace { struct StyleFamilyEntry { - using GetCountOrName_t = std::function< sal_Int32 (const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)>; + using GetCountOrName_t = std::function; + using CreateStyle_t = std::function(SfxStyleSheetBasePool*, SwDocShell*, const OUString&)>; SfxStyleFamily m_eFamily; SwGetPoolIdFromName m_aPoolId; OUString m_sName; sal_uInt32 m_nResId; GetCountOrName_t m_fGetCountOrName; - StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString const& sName, sal_uInt32 nResId, GetCountOrName_t fGetCountOrName) + CreateStyle_t m_fCreateStyle; + StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString const& sName, sal_uInt32 nResId, GetCountOrName_t fGetCountOrName, CreateStyle_t fCreateStyle) : m_eFamily(eFamily) , m_aPoolId(aPoolId) , m_sName(sName) , m_nResId(nResId) , m_fGetCountOrName(fGetCountOrName) + , m_fCreateStyle(fCreateStyle) {} }; static const std::vector* our_pStyleFamilyEntries; @@ -500,6 +503,17 @@ sal_Int32 lcl_GetCountOrName(const SwDoc& rDoc, OUStrin return nCount + nPoolNumRange; } +template +static uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) + { return new SwXStyle(*pBasePool, eFamily, pDocShell->GetDoc(), sStyleName); }; + +template<> +uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) + { return new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName); }; + +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); }; uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex) throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) @@ -572,19 +586,7 @@ uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex) throw uno::RuntimeException(); uno::Reference xStyle = _FindStyle(sStyleName); if(!xStyle.is()) - { - switch(m_rEntry.m_eFamily) - { - case SFX_STYLE_FAMILY_PAGE: - xStyle = new SwXPageStyle(*m_pBasePool, m_pDocShell, m_rEntry.m_eFamily, sStyleName); - break; - case SFX_STYLE_FAMILY_FRAME: - xStyle = new SwXFrameStyle(*m_pBasePool, m_pDocShell->GetDoc(), pBase->GetName()); - break; - default: - xStyle = new SwXStyle(*m_pBasePool, m_rEntry.m_eFamily, m_pDocShell->GetDoc(), sStyleName); - } - } + xStyle = m_rEntry.m_fCreateStyle(m_pBasePool, m_pDocShell, m_rEntry.m_eFamily == SFX_STYLE_FAMILY_FRAME ? pBase->GetName() : sStyleName); return uno::makeAny(xStyle); } @@ -602,19 +604,7 @@ uno::Any XStyleFamily::getByName(const OUString& rName) throw container::NoSuchElementException(); uno::Reference xStyle = _FindStyle(sStyleName); if(!xStyle.is()) - { - switch(m_rEntry.m_eFamily) - { - case SFX_STYLE_FAMILY_PAGE: - xStyle = new SwXPageStyle(*m_pBasePool, m_pDocShell, m_rEntry.m_eFamily, sStyleName); - break; - case SFX_STYLE_FAMILY_FRAME: - xStyle = new SwXFrameStyle(*m_pBasePool, m_pDocShell->GetDoc(), pBase->GetName()); - break; - default: - xStyle = new SwXStyle(*m_pBasePool, m_rEntry.m_eFamily, m_pDocShell->GetDoc(), sStyleName); - } - } + xStyle = m_rEntry.m_fCreateStyle(m_pBasePool, m_pDocShell, m_rEntry.m_eFamily == SFX_STYLE_FAMILY_FRAME ? pBase->GetName() : sStyleName); return uno::makeAny(xStyle); } @@ -762,11 +752,11 @@ static const std::vector* lcl_GetStyleFamilyEntries() if(!our_pStyleFamilyEntries) { our_pStyleFamilyEntries = new std::vector{ - { SFX_STYLE_FAMILY_CHAR, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER, &lcl_GetCountOrName }, - { SFX_STYLE_FAMILY_PARA, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH, &lcl_GetCountOrName }, - { SFX_STYLE_FAMILY_PAGE, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles", STR_STYLE_FAMILY_PAGE, &lcl_GetCountOrName }, - { SFX_STYLE_FAMILY_FRAME, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, "FrameStyles", STR_STYLE_FAMILY_FRAME, &lcl_GetCountOrName }, - { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING, &lcl_GetCountOrName } + { SFX_STYLE_FAMILY_CHAR, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER, &lcl_GetCountOrName, &lcl_CreateStyle }, + { SFX_STYLE_FAMILY_PARA, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH, &lcl_GetCountOrName, &lcl_CreateStyle }, + { SFX_STYLE_FAMILY_PAGE, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles", STR_STYLE_FAMILY_PAGE, &lcl_GetCountOrName, &lcl_CreateStyle }, + { SFX_STYLE_FAMILY_FRAME, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, "FrameStyles", STR_STYLE_FAMILY_FRAME, &lcl_GetCountOrName, &lcl_CreateStyle }, + { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING, &lcl_GetCountOrName, &lcl_CreateStyle } }; } return our_pStyleFamilyEntries; -- cgit v1.2.3