From 939657e7c8beca46f0b84faf7a89cda8b789e2f5 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Sat, 28 Nov 2015 17:50:13 +0100 Subject: use the entry vector for lcl_TranslateIndex dispatch Change-Id: I4a8361821b9a5af2a59ad29684ee243d2f4591ed --- sw/source/core/unocore/unostyle.cxx | 126 ++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 57 deletions(-) (limited to 'sw/source') diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 7e57dd80e253..6d5c4dbc5fa9 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -96,19 +96,22 @@ namespace { using GetCountOrName_t = std::function; using CreateStyle_t = std::function(SfxStyleSheetBasePool*, SwDocShell*, const OUString&)>; + using TranslateIndex_t = std::function; SfxStyleFamily m_eFamily; SwGetPoolIdFromName m_aPoolId; OUString m_sName; sal_uInt32 m_nResId; GetCountOrName_t m_fGetCountOrName; CreateStyle_t m_fCreateStyle; - StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString const& sName, sal_uInt32 nResId, GetCountOrName_t fGetCountOrName, CreateStyle_t fCreateStyle) + TranslateIndex_t m_fTranslateIndex; + StyleFamilyEntry(SfxStyleFamily eFamily, SwGetPoolIdFromName aPoolId, OUString const& sName, sal_uInt32 nResId, GetCountOrName_t fGetCountOrName, CreateStyle_t fCreateStyle, TranslateIndex_t fTranslateIndex) : m_eFamily(eFamily) , m_aPoolId(aPoolId) , m_sName(sName) , m_nResId(nResId) , m_fGetCountOrName(fGetCountOrName) , m_fCreateStyle(fCreateStyle) + , m_fTranslateIndex(fTranslateIndex) {} }; static const std::vector* our_pStyleFamilyEntries; @@ -515,6 +518,63 @@ 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); }; +template +static sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex); + +template<> +sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex) +{ + static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range"); + if(nIndex < nPoolChrNormalRange) + return nIndex + RES_POOLCHR_NORMAL_BEGIN; + else if(nIndex < (nPoolChrHtmlRange+nPoolChrNormalRange)) + return nIndex + RES_POOLCHR_HTML_BEGIN + nPoolChrNormalRange; + throw lang::IndexOutOfBoundsException(); +} + +template<> +sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex) +{ + static_assert(nPoolCollTextRange > 0 && nPoolCollListsRange > 0 && nPoolCollExtraRange > 0 && nPoolCollRegisterRange > 0 && nPoolCollDocRange > 0 && nPoolCollHtmlRange > 0, "weird pool range"); + if(nIndex < nPoolCollListsStackedStart) + return nIndex + RES_POOLCOLL_TEXT_BEGIN; + else if(nIndex < nPoolCollExtraStackedStart) + return nIndex + RES_POOLCOLL_LISTS_BEGIN + nPoolCollListsStackedStart; + else if(nIndex < nPoolCollRegisterStackedStart) + return nIndex + RES_POOLCOLL_EXTRA_BEGIN + nPoolCollExtraStackedStart; + else if(nIndex < nPoolCollDocStackedStart) + return nIndex + RES_POOLCOLL_REGISTER_BEGIN + nPoolCollRegisterStackedStart; + else if(nIndex < nPoolCollHtmlStackedStart) + return nIndex + RES_POOLCOLL_DOC_BEGIN + nPoolCollDocStackedStart; + else if(nIndex < nPoolCollHtmlStackedStart + nPoolCollTextRange) + return nIndex + RES_POOLCOLL_HTML_BEGIN + nPoolCollHtmlStackedStart; + throw lang::IndexOutOfBoundsException(); +} + +template<> +sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex) +{ + if(nIndex < nPoolFrameRange) + return nIndex + RES_POOLFRM_BEGIN; + throw lang::IndexOutOfBoundsException(); +} + +template<> +sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex) +{ + if(nIndex < nPoolPageRange) + return nIndex + RES_POOLPAGE_BEGIN; + throw lang::IndexOutOfBoundsException(); +} + +template<> +sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex) +{ + if(nIndex < nPoolNumRange) + return nIndex + RES_POOLNUMRULE_BEGIN; + throw lang::IndexOutOfBoundsException(); +} + uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex) throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) { @@ -524,58 +584,10 @@ uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex) if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - switch(m_rEntry.m_eFamily) + try { - case SFX_STYLE_FAMILY_CHAR: - { - static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range"); - const sal_uInt16 nIndex16 = static_cast(nIndex); - if(nIndex16 < nPoolChrNormalRange) - SwStyleNameMapper::FillUIName(static_cast(RES_POOLCHR_NORMAL_BEGIN + nIndex), sStyleName); - else if(nIndex16 < (nPoolChrHtmlRange+nPoolChrNormalRange)) - SwStyleNameMapper::FillUIName(RES_POOLCHR_HTML_BEGIN + nPoolChrNormalRange + nIndex, sStyleName ); - } - break; - case SFX_STYLE_FAMILY_PARA: - { - static_assert(nPoolCollTextRange > 0 && nPoolCollListsRange > 0 && nPoolCollExtraRange > 0 && nPoolCollRegisterRange > 0 && nPoolCollDocRange > 0 && nPoolCollHtmlRange > 0, "weird pool range"); - const sal_uInt16 nIndex16 = static_cast(nIndex); - if(nIndex16 < nPoolCollListsStackedStart) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_TEXT_BEGIN + nIndex16, sStyleName); - else if(nIndex16 < nPoolCollExtraStackedStart) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_LISTS_BEGIN + nPoolCollListsStackedStart + nIndex16, sStyleName); - else if(nIndex16 < nPoolCollRegisterStackedStart) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_EXTRA_BEGIN + nPoolCollExtraStackedStart + nIndex16, sStyleName); - else if(nIndex16 < nPoolCollDocStackedStart) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_REGISTER_BEGIN + nPoolCollRegisterStackedStart + nIndex16, sStyleName); - else if(nIndex16 < nPoolCollHtmlStackedStart) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_DOC_BEGIN + nPoolCollDocStackedStart + nIndex16, sStyleName); - else if(nIndex16 < nPoolCollHtmlStackedStart + nPoolCollTextRange) - SwStyleNameMapper::FillUIName(RES_POOLCOLL_HTML_BEGIN + nPoolCollHtmlStackedStart + nIndex16, sStyleName); - } - break; - case SFX_STYLE_FAMILY_FRAME: - { - if(nIndex < nPoolFrameRange) - SwStyleNameMapper::FillUIName(static_cast(RES_POOLFRM_BEGIN + nIndex), sStyleName); - } - break; - case SFX_STYLE_FAMILY_PAGE: - { - if(nIndex < nPoolPageRange) - SwStyleNameMapper::FillUIName(static_cast(RES_POOLPAGE_BEGIN + nIndex), sStyleName); - } - break; - case SFX_STYLE_FAMILY_PSEUDO: - { - if(nIndex < nPoolNumRange) - SwStyleNameMapper::FillUIName(static_cast(RES_POOLNUMRULE_BEGIN + nIndex), sStyleName); - } - break; - - default: - ; - } + SwStyleNameMapper::FillUIName(m_rEntry.m_fTranslateIndex(nIndex), sStyleName); + } catch(...) {} if (sStyleName.isEmpty()) GetCountOrName(&sStyleName, nIndex); @@ -746,11 +758,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, &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 } + { SFX_STYLE_FAMILY_CHAR, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER, &lcl_GetCountOrName, &lcl_CreateStyle, &lcl_TranslateIndex }, + { SFX_STYLE_FAMILY_PARA, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH, &lcl_GetCountOrName, &lcl_CreateStyle, &lcl_TranslateIndex }, + { SFX_STYLE_FAMILY_PAGE, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, "PageStyles", STR_STYLE_FAMILY_PAGE, &lcl_GetCountOrName, &lcl_CreateStyle, &lcl_TranslateIndex }, + { SFX_STYLE_FAMILY_FRAME, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, "FrameStyles", STR_STYLE_FAMILY_FRAME, &lcl_GetCountOrName, &lcl_CreateStyle, &lcl_TranslateIndex }, + { SFX_STYLE_FAMILY_PSEUDO, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING, &lcl_GetCountOrName, &lcl_CreateStyle, &lcl_TranslateIndex } }; } return our_pStyleFamilyEntries; -- cgit v1.2.3