sw/source/core/unocore/unostyle.cxx | 995 +++++++++++++++--------------------- 1 file changed, 437 insertions(+), 558 deletions(-)
New commits: commit 394895de8c47e7ab3b560d1ecb3242901a9ff92b Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 22:28:52 2016 +0100 use a map for dispatch Change-Id: I29c88c834a01f8d04a2998ea3edfa95cd0cadb85 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 50ca5ae..f18f9ef 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1812,72 +1812,47 @@ void SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>(const SfxItemPropertySimpleE void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - switch(rEntry.nWID) + using propertytype_t = decltype(rEntry.nWID); + using coresetter_t = std::function<void(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>; + static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore; + if(!pUnoToCore) { - case FN_UNO_HIDDEN: - SetPropertyValue<FN_UNO_HIDDEN>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_STYLE_INTEROP_GRAB_BAG: - SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(rEntry, rPropSet, rValue, rBase); - break; - case XATTR_FILLGRADIENT: - case XATTR_FILLHATCH: - case XATTR_FILLBITMAP: - case XATTR_FILLFLOATTRANSPARENCE: - SetPropertyValue<XATTR_FILLGRADIENT>(rEntry, rPropSet, rValue, rBase); - break; - case RES_BACKGROUND: - SetPropertyValue<RES_BACKGROUND>(rEntry, rPropSet, rValue, rBase); - break; - case OWN_ATTR_FILLBMP_MODE: - SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(rEntry, rPropSet, rValue, rBase); - break; - case RES_PAPER_BIN: - SetPropertyValue<RES_PAPER_BIN>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: - SetPropertyValue<FN_UNO_NUM_RULES>(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_OUTLINELEVEL: - SetPropertyValue<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_FOLLOW_STYLE: - SetPropertyValue<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rValue, rBase); - break; - case RES_PAGEDESC: - SetPropertyValue<RES_PAGEDESC>(rEntry, rPropSet, rValue, rBase); - break; - case RES_TEXT_VERT_ADJUST: - SetPropertyValue<RES_TEXT_VERT_ADJUST>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_IS_AUTO_UPDATE: - SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_PARA_STYLE_CONDITIONS: - SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(rEntry, rPropSet, rValue, rBase); - break; - case FN_UNO_CATEGORY: - SetPropertyValue<FN_UNO_CATEGORY>(rEntry, rPropSet, rValue, rBase); - break; - case SID_SWREGISTER_COLLECTION: - SetPropertyValue<SID_SWREGISTER_COLLECTION>(rEntry, rPropSet, rValue, rBase); - break; - case RES_TXTATR_CJK_RUBY: - SetPropertyValue<RES_TXTATR_CJK_RUBY>(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_DROP: - SetPropertyValue<RES_PARATR_DROP>(rEntry, rPropSet, rValue, rBase); - break; - case RES_PARATR_NUMRULE: - SetPropertyValue<RES_PARATR_NUMRULE>(rEntry, rPropSet, rValue, rBase); - break; - default: - //UUUU adapted switch logic to a more readable state; removed goto's and made - // execution of standard setting of proerty in ItemSet dependent of this variable - uno::Any aValue(rValue); - lcl_TranslateMetric(rEntry, m_pDoc, aValue); - lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); - break; + pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> { + // these explicit std::mem_fn() calls shouldnt be needed, but apparently MSVC is currently too stupid for C++11 again + { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>) }, + { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>) }, + { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>) }, + { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>) }, + { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>) }, + { XATTR_FILLFLOATTRANSPARENCE, std::mem_fn(&SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>) }, + { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue<RES_BACKGROUND>) }, + { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>) }, + { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PAPER_BIN>) }, + { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>) }, + { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PARATR_OUTLINELEVEL>) }, + { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>) }, + { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PAGEDESC>) }, + { RES_TEXT_VERT_ADJUST, std::mem_fn(&SwXStyle::SetPropertyValue<RES_TEXT_VERT_ADJUST>) }, + { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>) }, + { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>) }, + { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>) }, + { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>) }, + { RES_TXTATR_CJK_RUBY, std::mem_fn(&SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>) }, + { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PARATR_DROP>) }, + { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PARATR_DROP>) }, + { RES_PARATR_NUMRULE, std::mem_fn(&SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>) } + }); + } + const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID)); + if(pUnoToCoreIt != pUnoToCore->end()) + pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase); + else + { + //UUUU adapted switch logic to a more readable state; removed goto's and made + // execution of standard setting of proerty in ItemSet dependent of this variable + uno::Any aValue(rValue); + lcl_TranslateMetric(rEntry, m_pDoc, aValue); + lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); } } commit ec5e17c4c8db3ece513822b8252a08b0cf993785 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 21:33:34 2016 +0100 remove bDone band-aid Change-Id: I7c4783ab70e7456d30ee86bb1c415e6d54df3285 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index f36ce71..50ca5ae 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1742,7 +1742,7 @@ void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemProperty o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); } template<> -void SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +void SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) { if(MID_RUBY_CHARSTYLE != rEntry.nMemberId) return; @@ -1766,6 +1766,7 @@ void SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>(const SfxItemPropertySimple pRuby->SetCharFormatId(nId); } rStyleSet.Put(*pRuby); + lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); } template<> void SwXStyle::SetPropertyValue<RES_PARATR_DROP>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) @@ -1811,104 +1812,73 @@ void SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>(const SfxItemPropertySimpleE void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - SfxStyleFamily eFamily = m_rEntry.m_eFamily; - SwDoc* pDoc(m_pDoc); - //UUUU adapted switch logic to a more readable state; removed goto's and made - // execution of standard setting of proerty in ItemSet dependent of this variable - bool bDone(false); - uno::Any aValue(rValue); - const auto nMemberId(lcl_TranslateMetric(rEntry, pDoc, aValue)); - switch(rEntry.nWID) { case FN_UNO_HIDDEN: SetPropertyValue<FN_UNO_HIDDEN>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case FN_UNO_STYLE_INTEROP_GRAB_BAG: SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case XATTR_FILLGRADIENT: case XATTR_FILLHATCH: case XATTR_FILLBITMAP: case XATTR_FILLFLOATTRANSPARENCE: SetPropertyValue<XATTR_FILLGRADIENT>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_BACKGROUND: SetPropertyValue<RES_BACKGROUND>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case OWN_ATTR_FILLBMP_MODE: SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_PAPER_BIN: SetPropertyValue<RES_PAPER_BIN>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: SetPropertyValue<FN_UNO_NUM_RULES>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_PARATR_OUTLINELEVEL: SetPropertyValue<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case FN_UNO_FOLLOW_STYLE: SetPropertyValue<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_PAGEDESC: SetPropertyValue<RES_PAGEDESC>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_TEXT_VERT_ADJUST: SetPropertyValue<RES_TEXT_VERT_ADJUST>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case FN_UNO_IS_AUTO_UPDATE: - { SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; - } case FN_UNO_PARA_STYLE_CONDITIONS: SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case FN_UNO_CATEGORY: - { SetPropertyValue<FN_UNO_CATEGORY>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; - } case SID_SWREGISTER_COLLECTION: - { SetPropertyValue<SID_SWREGISTER_COLLECTION>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; - } case RES_TXTATR_CJK_RUBY: SetPropertyValue<RES_TXTATR_CJK_RUBY>(rEntry, rPropSet, rValue, rBase); break; case RES_PARATR_DROP: SetPropertyValue<RES_PARATR_DROP>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; case RES_PARATR_NUMRULE: SetPropertyValue<RES_PARATR_NUMRULE>(rEntry, rPropSet, rValue, rBase); - bDone = true; break; default: - { - // nothing to do + //UUUU adapted switch logic to a more readable state; removed goto's and made + // execution of standard setting of proerty in ItemSet dependent of this variable + uno::Any aValue(rValue); + lcl_TranslateMetric(rEntry, m_pDoc, aValue); + lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); break; - } } - if(!bDone) - lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); } void SAL_CALL SwXStyle::SetPropertyValues_Impl( commit 1cdedb290a93d949c9311b33698b48822e181fab Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 21:22:52 2016 +0100 refactor out to limit scope: RES_PARATR_NUMRULE Change-Id: Iecea747a436de1afe529e024974006a256aa5f5a diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 328b55f..f36ce71 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1790,6 +1790,24 @@ void SwXStyle::SetPropertyValue<RES_PARATR_DROP>(const SfxItemPropertySimpleEntr pDrop->SetCharFormat(pStyle->GetCharFormat()); rStyleSet.Put(*pDrop); } +template<> +void SwXStyle::SetPropertyValue<RES_PARATR_NUMRULE>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + uno::Any aValue(rValue); + lcl_TranslateMetric(rEntry, m_pDoc, aValue); + lcl_SetDefaultWay(rEntry, rPropSet, aValue, o_rStyleBase); + // --> OD 2006-10-18 #i70223# + if(SFX_STYLE_FAMILY_PARA == m_rEntry.m_eFamily && + o_rStyleBase.getNewBase().is() && o_rStyleBase.getNewBase()->GetCollection() && + //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei + o_rStyleBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle()) ////<-end,add by zhaojianwei + { + OUString sNewNumberingRuleName; + aValue >>= sNewNumberingRuleName; + if(sNewNumberingRuleName.isEmpty() || sNewNumberingRuleName != m_pDoc->GetOutlineNumRule()->GetName()) + o_rStyleBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); + } +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1880,25 +1898,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const bDone = true; break; case RES_PARATR_NUMRULE: - { - lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); - // --> OD 2006-10-18 #i70223# - if ( SFX_STYLE_FAMILY_PARA == eFamily && - rBase.getNewBase().is() && rBase.getNewBase()->GetCollection() && - //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei - rBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle() ) ////<-end,add by zhaojianwei - { - OUString sNewNumberingRuleName; - aValue >>= sNewNumberingRuleName; - if ( sNewNumberingRuleName.isEmpty() || - sNewNumberingRuleName != pDoc->GetOutlineNumRule()->GetName() ) - { - rBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); - } - } + SetPropertyValue<RES_PARATR_NUMRULE>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } default: { // nothing to do commit 6766760e86b517c726204f9601b33a19cb0c5451 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 21:05:59 2016 +0100 refactor out to limit scope: RES_PARATR_DROP Change-Id: I8813b5676504e6de2af70d181fa9e905538fb05c diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index db13809..328b55f 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1767,6 +1767,29 @@ void SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>(const SfxItemPropertySimple } rStyleSet.Put(*pRuby); } +template<> +void SwXStyle::SetPropertyValue<RES_PARATR_DROP>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(MID_DROPCAP_CHAR_STYLE_NAME != rEntry.nMemberId) + return; + if(!rValue.has<OUString>()) + throw lang::IllegalArgumentException(); + SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); + std::unique_ptr<SwFormatDrop> pDrop; + const SfxPoolItem* pItem; + if(SfxItemState::SET == rStyleSet.GetItemState(RES_PARATR_DROP, true, &pItem)) + pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); + else + pDrop.reset(new SwFormatDrop); + const auto sValue(rValue.get<OUString>()); + OUString sStyle; + SwStyleNameMapper::FillUIName(sValue, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true); + auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR))); + if(!pStyle) + throw lang::IllegalArgumentException(); + pDrop->SetCharFormat(pStyle->GetCharFormat()); + rStyleSet.Put(*pDrop); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1853,38 +1876,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SetPropertyValue<RES_TXTATR_CJK_RUBY>(rEntry, rPropSet, rValue, rBase); break; case RES_PARATR_DROP: - { - if( MID_DROPCAP_CHAR_STYLE_NAME == nMemberId) - { - if(aValue.getValueType() == ::cppu::UnoType<OUString>::get()) - { - SfxItemSet& rStyleSet = rBase.GetItemSet(); - - std::unique_ptr<SwFormatDrop> pDrop; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState( RES_PARATR_DROP, true, &pItem ) ) - pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); - else - pDrop.reset( new SwFormatDrop ); - OUString uStyle; - aValue >>= uStyle; - OUString sStyle; - SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); - SwDocStyleSheet* pStyle = - static_cast<SwDocStyleSheet*>(pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR)); - if(pStyle) - pDrop->SetCharFormat(pStyle->GetCharFormat()); - else - throw lang::IllegalArgumentException(); - rStyleSet.Put(*pDrop); - } - else - throw lang::IllegalArgumentException(); - - bDone = true; - } + SetPropertyValue<RES_PARATR_DROP>(rEntry, rPropSet, rValue, rBase); + bDone = true; break; - } case RES_PARATR_NUMRULE: { lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); commit 209030f9fb87067fac57436e8e359380e0c4b584 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 20:52:53 2016 +0100 refactor out to limit scope: RES_TXTATR_CJK_RUBY Change-Id: I02b37ead4f930a91f9e8c6d472ffe0d2991bb78f diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index ece91c4..db13809 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1741,7 +1741,32 @@ void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemProperty SwStyleNameMapper::FillUIName(sName, aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true); o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); } - +template<> +void SwXStyle::SetPropertyValue<RES_TXTATR_CJK_RUBY>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(MID_RUBY_CHARSTYLE != rEntry.nMemberId) + return; + if(!rValue.has<OUString>()) + throw lang::IllegalArgumentException(); + const auto sValue(rValue.get<OUString>()); + SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); + std::unique_ptr<SwFormatRuby> pRuby; + const SfxPoolItem* pItem; + if(SfxItemState::SET == rStyleSet.GetItemState(RES_TXTATR_CJK_RUBY, true, &pItem)) + pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); + else + pRuby.reset(new SwFormatRuby(OUString())); + OUString sStyle; + SwStyleNameMapper::FillUIName(sValue, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true); + pRuby->SetCharFormatName(sValue); + pRuby->SetCharFormatId(0); + if(!sValue.isEmpty()) + { + const sal_uInt16 nId(SwStyleNameMapper::GetPoolIdFromUIName(sValue, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT)); + pRuby->SetCharFormatId(nId); + } + rStyleSet.Put(*pRuby); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1825,35 +1850,8 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const break; } case RES_TXTATR_CJK_RUBY: - { - if(MID_RUBY_CHARSTYLE == nMemberId ) - { - OUString sTmp; - if(aValue >>= sTmp) - { - SfxItemSet& rStyleSet = rBase.GetItemSet(); - std::unique_ptr<SwFormatRuby> pRuby; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState( RES_TXTATR_CJK_RUBY, true, &pItem ) ) - pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); - else - pRuby.reset(new SwFormatRuby(OUString())); - OUString sStyle; - SwStyleNameMapper::FillUIName(sTmp, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); - pRuby->SetCharFormatName( sTmp ); - pRuby->SetCharFormatId( 0 ); - if(!sTmp.isEmpty()) - { - sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sTmp, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ); - pRuby->SetCharFormatId(nId); - } - rStyleSet.Put(*pRuby); - } - else - throw lang::IllegalArgumentException(); - } + SetPropertyValue<RES_TXTATR_CJK_RUBY>(rEntry, rPropSet, rValue, rBase); break; - } case RES_PARATR_DROP: { if( MID_DROPCAP_CHAR_STYLE_NAME == nMemberId) commit b9f67808ab7d087f9f243ea475fafa8f2d7df142 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 19:36:36 2016 +0100 refactor to limit scope: SID_SWREGISTER_COLLECTION Change-Id: I67c259f4da968b9decc4ac95195864a28283d1b5 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 9bcb470..ece91c4 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1729,6 +1729,19 @@ void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntr throw lang::IllegalArgumentException(); o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SFXSTYLEBIT_USERDEF ); } +template<> +void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + OUString sName; + rValue >>= sName; + SwRegisterItem aReg(!sName.isEmpty()); + aReg.SetWhich(SID_SWREGISTER_MODE); + o_rStyleBase.GetItemSet().Put(aReg); + OUString aString; + SwStyleNameMapper::FillUIName(sName, aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true); + o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); +} + void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1807,15 +1820,7 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const } case SID_SWREGISTER_COLLECTION: { - OUString sName; - aValue >>= sName; - SwRegisterItem aReg( !sName.isEmpty() ); - aReg.SetWhich(SID_SWREGISTER_MODE); - rBase.GetItemSet().Put(aReg); - OUString aString; - SwStyleNameMapper::FillUIName(sName, aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true); - - rBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); + SetPropertyValue<SID_SWREGISTER_COLLECTION>(rEntry, rPropSet, rValue, rBase); bDone = true; break; } commit 8aa26b634bb612037e080dd043e62170b9bbb0d8 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 19:20:53 2016 +0100 refactor to limit scope: FN_UNO_CATEGORY Change-Id: I15ccdcf7c56a9677fb01646cad96e7c7d9ba7cd4 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 5acbe86..9bcb470 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1705,6 +1705,31 @@ void SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPrope } o_rStyleBase.GetItemSet().Put(aCondItem); } +template<> +void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + using paragraphstyle_t = std::remove_const<decltype(style::ParagraphStyleCategory::TEXT)>::type; + using paragraphcorestyle_t = sal_uInt16; + if(!o_rStyleBase.getNewBase()->IsUserDefined() || !rValue.has<paragraphstyle_t>()) + throw lang::IllegalArgumentException(); + static std::unique_ptr<std::map<paragraphstyle_t, paragraphcorestyle_t>> pUnoToCore; + if(!pUnoToCore) + { + pUnoToCore.reset(new std::map<paragraphstyle_t, paragraphcorestyle_t> { + { style::ParagraphStyleCategory::TEXT, SWSTYLEBIT_TEXT }, + { style::ParagraphStyleCategory::CHAPTER, SWSTYLEBIT_CHAPTER }, + { style::ParagraphStyleCategory::LIST, SWSTYLEBIT_LIST }, + { style::ParagraphStyleCategory::INDEX, SWSTYLEBIT_IDX }, + { style::ParagraphStyleCategory::EXTRA, SWSTYLEBIT_EXTRA }, + { style::ParagraphStyleCategory::HTML, SWSTYLEBIT_HTML } + }); + } + const auto pUnoToCoreIt(pUnoToCore->find(rValue.get<paragraphstyle_t>())); + if(pUnoToCoreIt == pUnoToCore->end()) + throw lang::IllegalArgumentException(); + o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SFXSTYLEBIT_USERDEF ); +} + void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { SfxStyleFamily eFamily = m_rEntry.m_eFamily; @@ -1776,36 +1801,7 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const break; case FN_UNO_CATEGORY: { - if(!rBase.getNewBase()->IsUserDefined()) - throw lang::IllegalArgumentException(); - short nSet = 0; - aValue >>= nSet; - - sal_uInt16 nId; - switch( nSet ) - { - case style::ParagraphStyleCategory::TEXT: - nId = SWSTYLEBIT_TEXT; - break; - case style::ParagraphStyleCategory::CHAPTER: - nId = SWSTYLEBIT_CHAPTER; - break; - case style::ParagraphStyleCategory::LIST: - nId = SWSTYLEBIT_LIST; - break; - case style::ParagraphStyleCategory::INDEX: - nId = SWSTYLEBIT_IDX; - break; - case style::ParagraphStyleCategory::EXTRA: - nId = SWSTYLEBIT_EXTRA; - break; - case style::ParagraphStyleCategory::HTML: - nId = SWSTYLEBIT_HTML; - break; - default: throw lang::IllegalArgumentException(); - } - - rBase.getNewBase()->SetMask( nId|SFXSTYLEBIT_USERDEF ); + SetPropertyValue<FN_UNO_CATEGORY>(rEntry, rPropSet, rValue, rBase); bDone = true; break; } commit 84da06858c5c754b04d3d3cd9492f346df2d6347 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Jan 14 00:11:16 2016 +0100 reafctor out to limit scope: FN_UNO_PARA_STYLE_CONDITIONS Change-Id: Id1d5afee85d54c48e2cd14d9604cbbae4b0b8fc2 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 6531b06..5acbe86 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1673,9 +1673,40 @@ void SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertySimp else if(SFX_STYLE_FAMILY_FRAME == m_rEntry.m_eFamily) o_rStyleBase.getNewBase()->GetFrameFormat()->SetAutoUpdateFormat(bAuto); } +template<> +void SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?"); + using expectedarg_t = uno::Sequence<beans::NamedValue>; + if(!rValue.has<expectedarg_t>() || !m_pBasePool) + throw lang::IllegalArgumentException(); + SwCondCollItem aCondItem; + for(auto& rNamedValue : rValue.get<expectedarg_t>()) + { + if(!rNamedValue.Value.has<OUString>()) + throw lang::IllegalArgumentException(); + + const OUString sValue(rNamedValue.Value.get<OUString>()); + // get UI style name from programmatic style name + OUString aStyleName; + SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.m_eFamily), true); + + // check for correct context and style name + const auto nIdx(GetCommandContextIndex(rNamedValue.Name)); + if(nIdx == -1) + throw lang::IllegalArgumentException(); + m_pBasePool->SetSearchMask(SFX_STYLE_FAMILY_PARA); + for(auto pBase = m_pBasePool->First(); pBase->GetName() != aStyleName; pBase = m_pBasePool->Next()) + { + if(!pBase) + throw lang::IllegalArgumentException(); + } + aCondItem.SetStyle(&aStyleName, nIdx); + } + o_rStyleBase.GetItemSet().Put(aCondItem); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - SfxStyleSheetBasePool* pBasePool = m_pBasePool; SfxStyleFamily eFamily = m_rEntry.m_eFamily; SwDoc* pDoc(m_pDoc); //UUUU adapted switch logic to a more readable state; removed goto's and made @@ -1740,62 +1771,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const break; } case FN_UNO_PARA_STYLE_CONDITIONS: - { - uno::Sequence< beans::NamedValue > aSeq; - if (!(aValue >>= aSeq)) - throw lang::IllegalArgumentException(); - - OSL_ENSURE(COND_COMMAND_COUNT == 28, - "invalid size of command count?"); - const beans::NamedValue *pSeq = aSeq.getConstArray(); - const sal_Int32 nLen = aSeq.getLength(); - - bool bFailed = false; - SwCondCollItem aCondItem; - for(sal_Int32 i = 0; i < nLen; ++i) - { - OUString aTmp; - if ((pSeq[i].Value >>= aTmp)) - { - // get UI style name from programmatic style name - OUString aStyleName; - SwStyleNameMapper::FillUIName(aTmp, aStyleName, - lcl_GetSwEnumFromSfxEnum(eFamily), true); - - // check for correct context and style name - - sal_Int16 nIdx = GetCommandContextIndex( pSeq[i].Name ); - - bool bStyleFound = false; - if (pBasePool) - { - pBasePool->SetSearchMask( SFX_STYLE_FAMILY_PARA); - const SfxStyleSheetBase* pBase = pBasePool->First(); - while (pBase && !bStyleFound) - { - if(pBase->GetName() == aStyleName) - bStyleFound = true; - pBase = pBasePool->Next(); - } - } - - if (nIdx == -1 || !bStyleFound) - { - bFailed = true; - break; - } - - aCondItem.SetStyle(&aStyleName, nIdx); - } - else - bFailed = true; - } - if (bFailed) - throw lang::IllegalArgumentException(); - rBase.GetItemSet().Put( aCondItem ); + SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case FN_UNO_CATEGORY: { if(!rBase.getNewBase()->IsUserDefined()) commit cad3c33af1ac772d4653cc512086e4de7315cf9c Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Wed Jan 13 22:07:35 2016 +0100 refactor out to limit scope: FN_UNO_IS_AUTO_UPDATE ... also check type of args and throw if it doesnt match Change-Id: Ic7a45aeab58b79abf3baee4bd3bf6f78fe3fa116 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index f13332f..6531b06 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1662,7 +1662,17 @@ void SwXStyle::SetPropertyValue<RES_TEXT_VERT_ADJUST>(const SfxItemPropertySimpl if(pPageDesc) pPageDesc->SetVerticalAdjustment(rValue.get<drawing::TextVerticalAdjust>()); } - +template<> +void SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!rValue.has<bool>()) + throw lang::IllegalArgumentException(); + const bool bAuto(rValue.get<bool>()); + if(SFX_STYLE_FAMILY_PARA == m_rEntry.m_eFamily) + o_rStyleBase.getNewBase()->GetCollection()->SetAutoUpdateFormat(bAuto); + else if(SFX_STYLE_FAMILY_FRAME == m_rEntry.m_eFamily) + o_rStyleBase.getNewBase()->GetFrameFormat()->SetAutoUpdateFormat(bAuto); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { SfxStyleSheetBasePool* pBasePool = m_pBasePool; @@ -1725,12 +1735,7 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const break; case FN_UNO_IS_AUTO_UPDATE: { - bool bAuto = *static_cast<sal_Bool const *>(aValue.getValue()); - if(SFX_STYLE_FAMILY_PARA == eFamily) - rBase.getNewBase()->GetCollection()->SetAutoUpdateFormat(bAuto); - else if(SFX_STYLE_FAMILY_FRAME == eFamily) - rBase.getNewBase()->GetFrameFormat()->SetAutoUpdateFormat(bAuto); - + SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(rEntry, rPropSet, rValue, rBase); bDone = true; break; } commit 3f6f4ebc6f162690481a5641a7f6fe35c3d99906 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 18:53:45 2016 +0100 refactor out to limit scope: RES_TEXT_VERT_ADJUST Change-Id: I030c6854e925c2a51b8c40de38e889a96c5ae32d diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 88e96fb..f13332f 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1653,6 +1653,15 @@ void SwXStyle::SetPropertyValue<RES_PAGEDESC>(const SfxItemPropertySimpleEntry& rStyleSet.Put(*pNewDesc); } } +template<> +void SwXStyle::SetPropertyValue<RES_TEXT_VERT_ADJUST>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!m_pDoc || !rValue.has<drawing::TextVerticalAdjust>() || !o_rStyleBase.GetOldPageDesc()) + return; + SwPageDesc* pPageDesc = m_pDoc->FindPageDesc(o_rStyleBase.GetOldPageDesc()->GetName()); + if(pPageDesc) + pPageDesc->SetVerticalAdjustment(rValue.get<drawing::TextVerticalAdjust>()); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1711,21 +1720,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const bDone = true; break; case RES_TEXT_VERT_ADJUST: - { - if( pDoc ) - { - const SwPageDesc* pOldPageDesc = rBase.GetOldPageDesc(); - SwPageDesc* pPageDesc = pOldPageDesc ? pDoc->FindPageDesc(pOldPageDesc->GetName()) : nullptr; - if (pPageDesc) - { - drawing::TextVerticalAdjust nVA; - rValue >>= nVA; - pPageDesc->SetVerticalAdjustment( nVA ); - } - } + SetPropertyValue<RES_TEXT_VERT_ADJUST>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case FN_UNO_IS_AUTO_UPDATE: { bool bAuto = *static_cast<sal_Bool const *>(aValue.getValue()); commit 6182554f91224015984f19196abaa38b44aa0621 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 18:32:54 2016 +0100 refactor out to limit scope: RES_PAGEDESC Change-Id: Id5c83f8dcc19dc5e94a895f1e15bc5dc8e800d9f diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index f825542..88e96fb 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1616,7 +1616,43 @@ void SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySimple SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.m_aPoolId, true); o_rStyleBase.getNewBase()->SetFollow(aString); } - +template<> +void SwXStyle::SetPropertyValue<RES_PAGEDESC>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId) + { + lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); + return; + } + if(!rValue.has<OUString>()) + throw lang::IllegalArgumentException(); + // special handling for RES_PAGEDESC + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + std::unique_ptr<SwFormatPageDesc> pNewDesc; + const SfxPoolItem* pItem; + if(SfxItemState::SET == rStyleSet.GetItemState(RES_PAGEDESC, true, &pItem)) + pNewDesc.reset(new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem))); + else + pNewDesc.reset(new SwFormatPageDesc); + const auto sValue(rValue.get<OUString>()); + OUString sDescName; + SwStyleNameMapper::FillUIName(sValue, sDescName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true); + if(pNewDesc->GetPageDesc() && pNewDesc->GetPageDesc()->GetName() == sDescName) + return; + if(sDescName.isEmpty()) + { + rStyleSet.ClearItem(RES_BREAK); + rStyleSet.Put(SwFormatPageDesc()); + } + else + { + SwPageDesc* pPageDesc(SwPageDesc::GetByName(*m_pDoc, sDescName)); + if(!pPageDesc) + throw lang::IllegalArgumentException(); + pNewDesc->RegisterToPageDesc(*pPageDesc); + rStyleSet.Put(*pNewDesc); + } +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1670,55 +1706,10 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SetPropertyValue<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - case RES_PAGEDESC : - { - if (MID_PAGEDESC_PAGEDESCNAME != nMemberId) - break; - // special handling for RES_PAGEDESC - if(aValue.getValueType() != ::cppu::UnoType<OUString>::get()) - throw lang::IllegalArgumentException(); - SfxItemSet& rStyleSet = rBase.GetItemSet(); - - std::unique_ptr<SwFormatPageDesc> pNewDesc; - const SfxPoolItem* pItem; - if(SfxItemState::SET == rStyleSet.GetItemState( RES_PAGEDESC, true, &pItem ) ) - { - pNewDesc.reset( new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem)) ); - } - else - pNewDesc.reset( new SwFormatPageDesc ); - OUString uDescName; - aValue >>= uDescName; - OUString sDescName; - SwStyleNameMapper::FillUIName(uDescName, sDescName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true ); - if(!pNewDesc->GetPageDesc() || pNewDesc->GetPageDesc()->GetName() != sDescName) - { - bool bPut = false; - if (!sDescName.isEmpty()) - { - SwPageDesc* pPageDesc = SwPageDesc::GetByName(*pDoc, sDescName); - if(pPageDesc) - { - pNewDesc->RegisterToPageDesc( *pPageDesc ); - bPut = true; - } - else - { - throw lang::IllegalArgumentException(); - } - } - if(!bPut) - { - rStyleSet.ClearItem(RES_BREAK); - rStyleSet.Put(SwFormatPageDesc()); - } - else - rStyleSet.Put(*pNewDesc); - - } + case RES_PAGEDESC: + SetPropertyValue<RES_PAGEDESC>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case RES_TEXT_VERT_ADJUST: { if( pDoc ) commit d632f64124af502147faa66b697fe1733f3aa4de Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 18:06:15 2016 +0100 refactor out to limit scope: FN_UNO_FOLLOW_STYLE Change-Id: I2f5f36fe9b9c7d1ee4289f2af268c25ebf8963d9 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index c217943..f825542 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1606,6 +1606,16 @@ void SwXStyle::SetPropertyValue<RES_PARATR_OUTLINELEVEL>(const SfxItemPropertySi if(0 <= nLevel && nLevel <= MAXLEVEL) o_rStyleBase.getNewBase()->GetCollection()->SetAttrOutlineLevel(nLevel); } +template<> +void SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!rValue.has<OUString>()) + return; + const auto sValue(rValue.get<OUString>()); + OUString aString; + SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.m_aPoolId, true); + o_rStyleBase.getNewBase()->SetFollow(aString); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) @@ -1653,23 +1663,13 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const bDone = true; break; case RES_PARATR_OUTLINELEVEL: - { SetPropertyValue<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } - case FN_UNO_FOLLOW_STYLE: - { - OUString sTmp; - aValue >>= sTmp; - OUString aString; - SwStyleNameMapper::FillUIName(sTmp, aString, lcl_GetSwEnumFromSfxEnum ( eFamily ), true ) ; - rBase.getNewBase()->SetFollow( aString ); - + SetPropertyValue<FN_UNO_FOLLOW_STYLE>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case RES_PAGEDESC : { if (MID_PAGEDESC_PAGEDESCNAME != nMemberId) commit d9df090ea8e3b8715626d7ca226931897b59485a Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 17:44:11 2016 +0100 refactor out to limit scope: RES_PARATR_OUTLINELEVEL Change-Id: Ia06a716f4ddcfd6884f5b9578d7c0b361d3f66f4 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index cd1127c..c217943 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1597,6 +1597,16 @@ void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertySimpleEnt } o_rStyleBase.getNewBase()->SetNumRule(aSetRule); } +template<> +void SwXStyle::SetPropertyValue<RES_PARATR_OUTLINELEVEL>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!rValue.has<sal_Int16>()) + return; + const auto nLevel(rValue.get<sal_Int16>()); + if(0 <= nLevel && nLevel <= MAXLEVEL) + o_rStyleBase.getNewBase()->GetCollection()->SetAttrOutlineLevel(nLevel); +} + void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1644,11 +1654,7 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const break; case RES_PARATR_OUTLINELEVEL: { - sal_Int16 nLevel = 0; - aValue >>= nLevel; - if( 0 <= nLevel && nLevel <= MAXLEVEL) - rBase.getNewBase()->GetCollection()->SetAttrOutlineLevel( nLevel ); - + SetPropertyValue<RES_PARATR_OUTLINELEVEL>(rEntry, rPropSet, rValue, rBase); bDone = true; break; } commit 62e0d000182d1f2dfba9ba5e41ddf1ce608eadf9 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 15:59:03 2016 +0100 refactor out to limit scope: FN_UNO_NUM_RULES Change-Id: I171fe6370d554ace330df254f07b3b2d45693edd diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 94f01e9..cd1127c 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1546,6 +1546,57 @@ void SwXStyle::SetPropertyValue<RES_PAPER_BIN>(const SfxItemPropertySimpleEntry& rPropSet.setPropertyValue(rEntry, uno::makeAny(static_cast<sal_Int8>(nBin == std::numeric_limits<printeridx_t>::max()-1 ? -1 : nBin)), aSet); rStyleSet.Put(aSet); } +template<> +void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!rValue.has<uno::Reference<container::XIndexReplace>>() || !rValue.has<uno::Reference<lang::XUnoTunnel>>()) + throw lang::IllegalArgumentException(); + auto xNumberTunnel(rValue.get<uno::Reference<lang::XUnoTunnel>>()); + SwXNumberingRules* pSwXRules = reinterpret_cast<SwXNumberingRules*>(sal::static_int_cast<sal_IntPtr>(xNumberTunnel->getSomething(SwXNumberingRules::getUnoTunnelId()))); + if(!pSwXRules) + return; + SwNumRule aSetRule(*pSwXRules->GetNumRule()); + for(sal_uInt16 i = 0; i < MAXLEVEL; ++i) + { + const SwNumFormat* pFormat = aSetRule.GetNumFormat(i); + if(!pFormat) + continue; + SwNumFormat aFormat(*pFormat); + const auto pCharName(pSwXRules->GetNewCharStyleNames()[i]); + if(!pCharName.isEmpty() + && !SwXNumberingRules::isInvalidStyle(pCharName) + && (!pFormat->GetCharFormat() || pFormat->GetCharFormat()->GetName() != pCharName)) + { + auto pCharFormatIt(std::find_if(m_pDoc->GetCharFormats()->begin(), m_pDoc->GetCharFormats()->end(), + [pCharName] (SwCharFormat* pF) { return pF->GetName() == pCharName; })); + if(pCharFormatIt != m_pDoc->GetCharFormats()->end()) + aFormat.SetCharFormat(*pCharFormatIt); + else if(m_pBasePool) + { + auto pBase(static_cast<SfxStyleSheetBasePool*>(m_pBasePool)->Find(pCharName, SFX_STYLE_FAMILY_CHAR)); + if(!pBase) + pBase = &m_pBasePool->Make(pCharName, SFX_STYLE_FAMILY_CHAR); + aFormat.SetCharFormat(static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()); + } + else + aFormat.SetCharFormat(nullptr); + } + // same for fonts: + const auto pBulletName(pSwXRules->GetBulletFontNames()[i]); + if(!pBulletName.isEmpty() + && !SwXNumberingRules::isInvalidStyle(pBulletName) + && (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetName() != pBulletName)) + { + const auto pFontListItem(static_cast<const SvxFontListItem*>(m_pDoc->GetDocShell()->GetItem(SID_ATTR_CHAR_FONTLIST))); + const auto pList(pFontListItem->GetFontList()); + FontMetric aFontInfo(pList->Get(pBulletName, WEIGHT_NORMAL, ITALIC_NONE)); + vcl::Font aFont(aFontInfo); + aFormat.SetBulletFont(&aFont); + } + aSetRule.Set(i, &aFormat); + } + o_rStyleBase.getNewBase()->SetNumRule(aSetRule); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1587,91 +1638,10 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SetPropertyValue<RES_PAPER_BIN>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: - { - if(aValue.getValueType() == cppu::UnoType<container::XIndexReplace>::get()) - { - uno::Reference< container::XIndexReplace > const * pxRulesRef = - static_cast<uno::Reference< container::XIndexReplace > const *>(aValue.getValue()); - - uno::Reference<lang::XUnoTunnel> xNumberTunnel( *pxRulesRef, uno::UNO_QUERY); - - SwXNumberingRules* pSwXRules = nullptr; - if(xNumberTunnel.is()) - { - pSwXRules = reinterpret_cast< SwXNumberingRules * >( - sal::static_int_cast< sal_IntPtr >(xNumberTunnel->getSomething( SwXNumberingRules::getUnoTunnelId()) )); - } - if(pSwXRules) - { - const OUString* pCharStyleNames = pSwXRules->GetNewCharStyleNames(); - const OUString* pBulletFontNames = pSwXRules->GetBulletFontNames(); - - SwNumRule aSetRule(*pSwXRules->GetNumRule()); - const SwCharFormats* pFormats = pDoc->GetCharFormats(); - const size_t nChCount = pFormats->size(); - for(sal_uInt16 i = 0; i < MAXLEVEL; i++) - { - - const SwNumFormat* pFormat = aSetRule.GetNumFormat( i ); - if(pFormat) - { - SwNumFormat aFormat(*pFormat); - if (!pCharStyleNames[i].isEmpty() && - !SwXNumberingRules::isInvalidStyle(pCharStyleNames[i]) && - (!pFormat->GetCharFormat() || pFormat->GetCharFormat()->GetName() != pCharStyleNames[i]) ) - { - - SwCharFormat* pCharFormat = nullptr; - for(size_t j = 0; j< nChCount; ++j) - { - SwCharFormat* pTmp = (*pFormats)[j]; - if(pTmp->GetName() == pCharStyleNames[i]) - { - pCharFormat = pTmp; - break; - } - } - if(!pCharFormat && pBasePool) - { - - SfxStyleSheetBase* pBase; - pBase = static_cast<SfxStyleSheetBasePool*>(pBasePool)->Find(pCharStyleNames[i], SFX_STYLE_FAMILY_CHAR); - if(!pBase) - pBase = &pBasePool->Make(pCharStyleNames[i], SFX_STYLE_FAMILY_CHAR); - pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat(); - - } - - aFormat.SetCharFormat( pCharFormat ); - } - // same for fonts: - if (!pBulletFontNames[i].isEmpty() && - !SwXNumberingRules::isInvalidStyle(pBulletFontNames[i]) && - (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetName() != pBulletFontNames[i]) ) - { - const SvxFontListItem* pFontListItem = - static_cast<const SvxFontListItem*>(pDoc->GetDocShell() - ->GetItem( SID_ATTR_CHAR_FONTLIST )); - const FontList* pList = pFontListItem->GetFontList(); - FontMetric aFontMetric = pList->Get( - pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE); - vcl::Font aFont(aFontMetric); - aFormat.SetBulletFont(&aFont); - } - aSetRule.Set( i, &aFormat ); - } - } - rBase.getNewBase()->SetNumRule(aSetRule); - } - } - else - throw lang::IllegalArgumentException(); - + case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: + SetPropertyValue<FN_UNO_NUM_RULES>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } - case RES_PARATR_OUTLINELEVEL: { sal_Int16 nLevel = 0; commit 4e312ebddbee763f6b9bc19ca186cb49a900bcd2 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 14:28:04 2016 +0100 refactor out to limit scope: RES_PAPER_BIN - also use decltype(..) to prevent integer overflow Change-Id: Id3fd76d79702e01642758db08d74b7a8e0f7f62b diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 1a158da..94f01e9 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -89,6 +89,7 @@ #include <cassert> #include <memory> #include <set> +#include <limits> namespace { @@ -1515,6 +1516,36 @@ void SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertySimp rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode)); rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode)); } +template<> +void SwXStyle::SetPropertyValue<RES_PAPER_BIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + if(!rValue.has<OUString>()) + throw lang::IllegalArgumentException(); + SfxPrinter* pPrinter = m_pDoc->getIDocumentDeviceAccess().getPrinter(true); + OUString sValue(rValue.get<OUString>()); + using printeridx_t = decltype(pPrinter->GetPaperBinCount()); + printeridx_t nBin = std::numeric_limits<printeridx_t>::max(); + if(sValue == "[From printer settings]") + nBin = std::numeric_limits<printeridx_t>::max()-1; + else if(pPrinter) + { + for(sal_uInt16 i=0, nEnd = pPrinter->GetPaperBinCount(); i < nEnd; ++i) + { + if (sValue == pPrinter->GetPaperBinName(i)) + { + nBin = i; + break; + } + } + } + if(nBin == std::numeric_limits<printeridx_t>::max()) + throw lang::IllegalArgumentException(); + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID); + aSet.SetParent(&rStyleSet); + rPropSet.setPropertyValue(rEntry, uno::makeAny(static_cast<sal_Int8>(nBin == std::numeric_limits<printeridx_t>::max()-1 ? -1 : nBin)), aSet); + rStyleSet.Put(aSet); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1553,39 +1584,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const bDone = true; break; case RES_PAPER_BIN: - { - SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( true ); - OUString sTmp; - sal_uInt16 nBin = USHRT_MAX; - if ( !( aValue >>= sTmp ) ) - throw lang::IllegalArgumentException(); - if ( sTmp == "[From printer settings]" ) - nBin = USHRT_MAX-1; - else if ( pPrinter ) - { - for (sal_uInt16 i=0, nEnd = pPrinter->GetPaperBinCount(); i < nEnd; i++ ) - { - if (sTmp == pPrinter->GetPaperBinName ( i ) ) - { - nBin = i; - break; - } - } - } - if ( nBin == USHRT_MAX ) - throw lang::IllegalArgumentException(); - else - { - SfxItemSet& rStyleSet = rBase.GetItemSet(); - SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID); - aSet.SetParent(&rStyleSet); - rPropSet.setPropertyValue(rEntry, uno::makeAny ( static_cast < sal_Int8 > ( nBin == USHRT_MAX-1 ? -1 : nBin ) ), aSet); - rStyleSet.Put(aSet); - } - + SetPropertyValue<RES_PAPER_BIN>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case FN_UNO_NUM_RULES: // special handling for a SvxNumRuleItem: { if(aValue.getValueType() == cppu::UnoType<container::XIndexReplace>::get()) commit f7374c8d4a4f649e3b3a47e30fa4a29b7b2bd12f Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 13:51:07 2016 +0100 refactor out to limit scope: OWN_ATTR_FILLBMP_MODE Change-Id: Ic515b7868c747d5ce5ff0856890aa0af9e567339 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 0a70e65..1a158da 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1501,6 +1501,20 @@ void SwXStyle::SetPropertyValue<RES_BACKGROUND>(const SfxItemPropertySimpleEntry setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, rStyleSet); } +template<> +void SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + drawing::BitmapMode eMode; + if(!(rValue >>= eMode)) + { + if(!rValue.has<sal_Int32>()) + throw lang::IllegalArgumentException(); + eMode = ((drawing::BitmapMode)rValue.get<sal_Int32>()); + } + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode)); + rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode)); +} void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { @@ -1535,30 +1549,9 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const bDone = true; break; case OWN_ATTR_FILLBMP_MODE: - { - //UUUU - drawing::BitmapMode eMode; - - if(!(aValue >>= eMode)) - { - sal_Int32 nMode = 0; - - if(!(aValue >>= nMode)) - { - throw lang::IllegalArgumentException(); - } - - eMode = (drawing::BitmapMode)nMode; - } - - SfxItemSet& rStyleSet = rBase.GetItemSet(); - - rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode)); - rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode)); - + SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(rEntry, rPropSet, rValue, rBase); bDone = true; break; - } case RES_PAPER_BIN: { SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( true ); @@ -3312,7 +3305,6 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( } default: { - //UUUU SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); break; } commit 717f14ff07dfa0881e13c3d15f802e004dc35a77 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 13:23:14 2016 +0100 make PutItemToSet and SetStyleProperty members to save half the params Change-Id: I77a1c71f1a801e83f861b43e05e456a75fc511da diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 070807e..0a70e65 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -363,6 +363,8 @@ public: void Invalidate(); void ApplyDescriptorProperties(); void SetStyleName(const OUString& rSet){ m_sStyleName = rSet;} + void SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception); + void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl); }; class SwXFrameStyle @@ -1496,38 +1498,41 @@ void SwXStyle::SetPropertyValue<RES_BACKGROUND>(const SfxItemPropertySimpleEntry // to potentially override parent style, which is unknown yet if(aChangedBrushItem == aOriginalBrushItem && (MID_GRAPHIC_TRANSPARENT != nMemberId || !aValue.has<bool>() || !aValue.get<bool>())) return; + setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, rStyleSet); } -static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, - const SfxItemPropertySet& rPropSet, - const uno::Any& rValue, - SwStyleBase_Impl& rBase, - SfxStyleSheetBasePool* pBasePool, - SwDoc* pDoc, - SfxStyleFamily eFamily) - throw(beans::PropertyVetoException, lang::IllegalArgumentException, - lang::WrappedTargetException, uno::RuntimeException, - std::exception) - +void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) throw(beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { + SfxStyleSheetBasePool* pBasePool = m_pBasePool; + SfxStyleFamily eFamily = m_rEntry.m_eFamily; + SwDoc* pDoc(m_pDoc); //UUUU adapted switch logic to a more readable state; removed goto's and made // execution of standard setting of proerty in ItemSet dependent of this variable bool bDone(false); uno::Any aValue(rValue); const auto nMemberId(lcl_TranslateMetric(rEntry, pDoc, aValue)); - switch(rEntry.nWID) { case FN_UNO_HIDDEN: + SetPropertyValue<FN_UNO_HIDDEN>(rEntry, rPropSet, rValue, rBase); + bDone = true; + break; case FN_UNO_STYLE_INTEROP_GRAB_BAG: + SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(rEntry, rPropSet, rValue, rBase); + bDone = true; + break; case XATTR_FILLGRADIENT: case XATTR_FILLHATCH: case XATTR_FILLBITMAP: case XATTR_FILLFLOATTRANSPARENCE: + SetPropertyValue<XATTR_FILLGRADIENT>(rEntry, rPropSet, rValue, rBase); + bDone = true; + break; case RES_BACKGROUND: - assert(false); + SetPropertyValue<RES_BACKGROUND>(rEntry, rPropSet, rValue, rBase); + bDone = true; break; case OWN_ATTR_FILLBMP_MODE: { @@ -1966,7 +1971,6 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, break; } } - if(!bDone) lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); } @@ -2010,26 +2014,7 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl( throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this)); if(aBaseImpl.getNewBase().is()) { - switch(pEntry->nWID) - { - case FN_UNO_HIDDEN: - SetPropertyValue<FN_UNO_HIDDEN>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); - case FN_UNO_STYLE_INTEROP_GRAB_BAG: - SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); - case XATTR_FILLGRADIENT: - case XATTR_FILLHATCH: - case XATTR_FILLBITMAP: - case XATTR_FILLFLOATTRANSPARENCE: - // not yet needed; activate when LineStyle support may be added - // case XATTR_LINESTART: - // case XATTR_LINEEND: - // case XATTR_LINEDASH: - SetPropertyValue<XATTR_FILLGRADIENT>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); - case RES_BACKGROUND: - SetPropertyValue<RES_BACKGROUND>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); - default: - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); - } + SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); } else if(m_bIsDescriptor) { @@ -3067,20 +3052,20 @@ SwXPageStyle::~SwXPageStyle() } -static void lcl_putItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl, SfxStyleSheetBasePool* pPool, SwDoc *pDoc, SfxStyleFamily eFamily) +void SwXStyle::PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl) { // create a new SvxSetItem and get it's ItemSet as new target SvxSetItem* pNewSetItem = static_cast< SvxSetItem* >(pSetItem->Clone()); SfxItemSet& rSetSet = pNewSetItem->GetItemSet(); // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem - rSetSet.SetParent(&pDoc->GetDfltFrameFormat()->GetAttrSet()); + rSetSet.SetParent(&m_pDoc->GetDfltFrameFormat()->GetAttrSet()); // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the // default method to set the property { SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet); - lcl_SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl, pPool, pDoc, eFamily); + SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl); } // reset paret at ItemSet from SetItem @@ -3169,7 +3154,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), rPropName, bFooter, pSetItem)) { - lcl_putItemToSet(pSetItem, *pPropSet, *pEntry, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + PutItemToSet(pSetItem, *pPropSet, *pEntry, pValues[nProp], aBaseImpl); if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST) { @@ -3178,7 +3163,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) { - lcl_putItemToSet(pSetItem, *pPropSet, *pEntry, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + PutItemToSet(pSetItem, *pPropSet, *pEntry, pValues[nProp], aBaseImpl); } } } @@ -3233,7 +3218,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( default: { // part of PageStyle, fallback to default - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); } } } @@ -3284,7 +3269,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( // default method to set the property { SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet); - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); } // reset paret at ItemSet from SetItem @@ -3298,7 +3283,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( else { // part of PageStyle, fallback to default - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); } break; @@ -3328,7 +3313,7 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( default: { //UUUU - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); break; } } commit 9384b61927eb1f2c9dad2d8c69655f7d9bf4a33f Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 05:06:31 2016 +0100 use Any::has<> instead of Any::isExtractableTo<>() Change-Id: I4927986485feb665339e6708bb66286a54926ab8 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 5b9bcd2..070807e 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1096,7 +1096,7 @@ static uno::Reference<beans::XPropertySet> lcl_InitStandardStyle(const SfxStyleF if(eFamily != SFX_STYLE_FAMILY_PARA && eFamily != SFX_STYLE_FAMILY_PAGE) return {}; auto aResult(rxStyleFamily->getByName("Standard")); - if(!aResult.isExtractableTo(cppu::UnoType<return_t>::get())) + if(!aResult.has<return_t>()) return {}; return aResult.get<return_t>(); } @@ -1112,7 +1112,7 @@ static uno::Reference<container::XNameAccess> lcl_InitStyleFamily(SwDoc* pDoc, c uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xModel, uno::UNO_QUERY); auto xFamilies = xFamilySupplier->getStyleFamilies(); auto aResult(xFamilies->getByName(rEntry.m_sName)); - if(!aResult.isExtractableTo(cppu::UnoType<return_t>::get())) + if(!aResult.has<return_t>()) return {}; return aResult.get<return_t>(); } @@ -1421,7 +1421,7 @@ sal_uInt8 lcl_TranslateMetric(const SfxItemPropertySimpleEntry& rEntry, SwDoc* p // exception: If these ItemTypes are used, do not convert when these are negative // since this means they are intended as percent values if((XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID) - && o_aValue.isExtractableTo(cppu::UnoType<sal_Int32>::get()) + && o_aValue.has<sal_Int32>() && o_aValue.get<sal_Int32>() < 0) return rEntry.nMemberId; if(!pDoc) @@ -1461,7 +1461,7 @@ void SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>(const SfxItemPropertySimpleE { // add set commands for FillName items SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); - if(!aValue.isExtractableTo(cppu::UnoType<OUString>::get())) + if(!aValue.has<OUString>()) throw lang::IllegalArgumentException(); SvxShape::SetFillAttribute(rEntry.nWID, aValue.get<OUString>(), rStyleSet); } commit 183b7fb6261cc9c5eed50e2965f8b273010e33e7 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 05:01:29 2016 +0100 refactor out to limit scope: RES_BACKGROUND Change-Id: Ic50f66a4a08dab6fd55a14475d1e9a4947e16048 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 3c88bd6..5b9bcd2 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1480,6 +1480,24 @@ void SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>(const SfxItemPropertySimpleE else lcl_SetDefaultWay(rEntry, rPropSet, aValue, o_rStyleBase); } +template<> +void SwXStyle::SetPropertyValue<RES_BACKGROUND>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, m_pDoc->IsInXMLImport())); + SvxBrushItem aChangedBrushItem(aOriginalBrushItem); + + uno::Any aValue(rValue); + const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue)); + aChangedBrushItem.PutValue(aValue, nMemberId); + + // 0xff is already the default - but if BackTransparent is set + // to true, it must be applied in the item set on ODF import + // to potentially override parent style, which is unknown yet + if(aChangedBrushItem == aOriginalBrushItem && (MID_GRAPHIC_TRANSPARENT != nMemberId || !aValue.has<bool>() || !aValue.get<bool>())) + return; + setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, rStyleSet); +} static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, @@ -1508,29 +1526,9 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, case XATTR_FILLHATCH: case XATTR_FILLBITMAP: case XATTR_FILLFLOATTRANSPARENCE: - assert(false); - break; case RES_BACKGROUND: - { - //UUUU - SfxItemSet& rStyleSet = rBase.GetItemSet(); - const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, pDoc->IsInXMLImport())); - SvxBrushItem aChangedBrushItem(aOriginalBrushItem); - - aChangedBrushItem.PutValue(aValue, nMemberId); - - if (!(aChangedBrushItem == aOriginalBrushItem) || - // 0xff is already the default - but if BackTransparent is set - // to true, it must be applied in the item set on ODF import - // to potentially override parent style, which is unknown yet - (MID_GRAPHIC_TRANSPARENT == nMemberId && aValue.has<bool>() && aValue.get<bool>())) - { - setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, rStyleSet); - } - - bDone = true; + assert(false); break; - } case OWN_ATTR_FILLBMP_MODE: { //UUUU @@ -2027,6 +2025,8 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl( // case XATTR_LINEEND: // case XATTR_LINEDASH: SetPropertyValue<XATTR_FILLGRADIENT>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); + case RES_BACKGROUND: + SetPropertyValue<RES_BACKGROUND>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); default: lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); } commit 8bca1f4e3bffaee88fbff36421d1c8cb4f5bf7e8 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 04:36:43 2016 +0100 refactor out to limit scope: XATTR_FILLGRADIENT Change-Id: Ie9dd59319a6cba1181388708efc40c2bea76de32 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index d94b319..3c88bd6 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1413,6 +1413,26 @@ static void lcl_SetDefaultWay(const SfxItemPropertySimpleEntry& rEntry, const Sf rStyleSet.Put(aSet); } +sal_uInt8 lcl_TranslateMetric(const SfxItemPropertySimpleEntry& rEntry, SwDoc* pDoc, uno::Any& o_aValue) +{ + // check for needed metric translation + if(!(rEntry.nMemberId & SFX_METRIC_ITEM)) + return rEntry.nMemberId; + // exception: If these ItemTypes are used, do not convert when these are negative + // since this means they are intended as percent values + if((XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID) + && o_aValue.isExtractableTo(cppu::UnoType<sal_Int32>::get()) + && o_aValue.get<sal_Int32>() < 0) + return rEntry.nMemberId; + if(!pDoc) + return rEntry.nMemberId & (~SFX_METRIC_ITEM); + + const SfxItemPool& rPool = pDoc->GetAttrPool(); + const SfxMapUnit eMapUnit(rPool.GetMetric(rEntry.nWID)); + if(eMapUnit != SFX_MAPUNIT_100TH_MM) + SvxUnoConvertFromMM(eMapUnit, o_aValue); + return rEntry.nMemberId & (~SFX_METRIC_ITEM); +} template<> void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) { @@ -1432,6 +1452,34 @@ void SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemProp o_rStyleBase.getNewBase()->SetGrabBagItem(rValue); lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); } +template<> +void SwXStyle::SetPropertyValue<XATTR_FILLGRADIENT>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + uno::Any aValue(rValue); + const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue)); + if(MID_NAME == nMemberId) + { + // add set commands for FillName items + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + if(!aValue.isExtractableTo(cppu::UnoType<OUString>::get())) + throw lang::IllegalArgumentException(); + SvxShape::SetFillAttribute(rEntry.nWID, aValue.get<OUString>(), rStyleSet); + } + else if(MID_GRAFURL == nMemberId) + { + if(XATTR_FILLBITMAP == rEntry.nWID) + { + // Bitmap also has the MID_GRAFURL mode where a Bitmap URL is used + const Graphic aNullGraphic; + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + XFillBitmapItem aXFillBitmapItem(rStyleSet.GetPool(), aNullGraphic); + aXFillBitmapItem.PutValue(aValue, nMemberId); + rStyleSet.Put(aXFillBitmapItem); + } + } + else + lcl_SetDefaultWay(rEntry, rPropSet, aValue, o_rStyleBase); +} static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, @@ -1448,86 +1496,20 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, //UUUU adapted switch logic to a more readable state; removed goto's and made // execution of standard setting of proerty in ItemSet dependent of this variable bool bDone(false); - - //UUUU - const sal_uInt8 nMemberId(rEntry.nMemberId & (~SFX_METRIC_ITEM)); uno::Any aValue(rValue); + const auto nMemberId(lcl_TranslateMetric(rEntry, pDoc, aValue)); - //UUUU check for needed metric translation - if(rEntry.nMemberId & SFX_METRIC_ITEM) - { - bool bDoIt(true); - - if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID) - { - // exception: If these ItemTypes are used, do not convert when these are negative - // since this means they are intended as percent values - sal_Int32 nValue = 0; - - if(aValue >>= nValue) - { - bDoIt = nValue > 0; - } - } - - if(bDoIt && pDoc) - { - const SfxItemPool& rPool = pDoc->GetAttrPool(); - const SfxMapUnit eMapUnit(rPool.GetMetric(rEntry.nWID)); - - if(eMapUnit != SFX_MAPUNIT_100TH_MM) - { - SvxUnoConvertFromMM(eMapUnit, aValue); - } - } - } switch(rEntry.nWID) { case FN_UNO_HIDDEN: case FN_UNO_STYLE_INTEROP_GRAB_BAG: - assert(false); - break; case XATTR_FILLGRADIENT: case XATTR_FILLHATCH: case XATTR_FILLBITMAP: case XATTR_FILLFLOATTRANSPARENCE: - // not yet needed; activate when LineStyle support may be added - // case XATTR_LINESTART: - // case XATTR_LINEEND: - // case XATTR_LINEDASH: - { - if(MID_NAME == nMemberId) - { - //UUUU add set commands for FillName items - OUString aTempName; - SfxItemSet& rStyleSet = rBase.GetItemSet(); - - if(!(aValue >>= aTempName)) - { - throw lang::IllegalArgumentException(); - } - - SvxShape::SetFillAttribute(rEntry.nWID, aTempName, rStyleSet); - bDone = true; - } - else if(MID_GRAFURL == nMemberId) - { - if(XATTR_FILLBITMAP == rEntry.nWID) - { - //UUUU Bitmap also has the MID_GRAFURL mode where a Bitmap URL is used - const Graphic aNullGraphic; - SfxItemSet& rStyleSet = rBase.GetItemSet(); - XFillBitmapItem aXFillBitmapItem(rStyleSet.GetPool(), aNullGraphic); - - aXFillBitmapItem.PutValue(aValue, nMemberId); - rStyleSet.Put(aXFillBitmapItem); - bDone = true; - } - } - + assert(false); break; - } case RES_BACKGROUND: { //UUUU @@ -2036,6 +2018,15 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl( SetPropertyValue<FN_UNO_HIDDEN>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); case FN_UNO_STYLE_INTEROP_GRAB_BAG: SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); + case XATTR_FILLGRADIENT: + case XATTR_FILLHATCH: + case XATTR_FILLBITMAP: + case XATTR_FILLFLOATTRANSPARENCE: + // not yet needed; activate when LineStyle support may be added + // case XATTR_LINESTART: + // case XATTR_LINEEND: + // case XATTR_LINEDASH: + SetPropertyValue<XATTR_FILLGRADIENT>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); default: lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); } commit 6dbcf11ff0036a12bd524c0efdd12aacd7b04826 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 03:52:09 2016 +0100 refactor out to limit scope: FN_UNO_STYLE_INTEROP_GRAB_BAG Change-Id: I0d85021ded0b33d9c2c8d2454ad737842323a099 diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index c534865..d94b319 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1425,6 +1425,13 @@ void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry& } lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); } +template<> +void SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + o_rStyleBase.getNewBase()->GetItemSet(); + o_rStyleBase.getNewBase()->SetGrabBagItem(rValue); + lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); +} static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, @@ -1478,15 +1485,9 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, switch(rEntry.nWID) { case FN_UNO_HIDDEN: + case FN_UNO_STYLE_INTEROP_GRAB_BAG: assert(false); break; - case FN_UNO_STYLE_INTEROP_GRAB_BAG: - { - rBase.getNewBase()->GetItemSet(); - rBase.getNewBase()->SetGrabBagItem(rValue); - } - break; - case XATTR_FILLGRADIENT: case XATTR_FILLHATCH: case XATTR_FILLBITMAP: @@ -2033,6 +2034,8 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl( { case FN_UNO_HIDDEN: SetPropertyValue<FN_UNO_HIDDEN>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); + case FN_UNO_STYLE_INTEROP_GRAB_BAG: + SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); default: lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); } commit d333bf69316dcf5d90d272158ac765c0c56e45c3 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Sat Jan 2 03:45:15 2016 +0100 refactor out to limit scope: FN_UNO_HIDDEN Change-Id: I3fd30be5e84c4a88d2c334f573fc4fc56a03646b diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 7227aed..c534865 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -243,6 +243,8 @@ namespace sw }; } + +class SwStyleBase_Impl; class SwXStyle : public cppu::WeakImplHelper < css::style::XStyle, @@ -269,6 +271,8 @@ protected: css::uno::Reference<css::container::XNameAccess> m_xStyleFamily; css::uno::Reference<css::beans::XPropertySet> m_xStyleData; + template<sal_uInt16> + void SetPropertyValue(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&); void SAL_CALL SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) throw (css::beans::UnknownPropertyException, css::beans::PropertyVetoException, @@ -1399,6 +1403,28 @@ const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc() return m_pOldPageDesc; } +static void lcl_SetDefaultWay(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + // default ItemSet handling + SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); + SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID); + aSet.SetParent(&rStyleSet); + rPropSet.setPropertyValue(rEntry, rValue, aSet); + rStyleSet.Put(aSet); +} + +template<> +void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) +{ + bool bHidden = false; + if(rValue >>= bHidden) + { + //make it a 'real' style - necessary for pooled styles + o_rStyleBase.getNewBase()->GetItemSet(); + o_rStyleBase.getNewBase()->SetHidden(bHidden); + } + lcl_SetDefaultWay(rEntry, rPropSet, rValue, o_rStyleBase); +} static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, @@ -1452,17 +1478,8 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, switch(rEntry.nWID) { case FN_UNO_HIDDEN: - { - bool bHidden = false; - if ( rValue >>= bHidden ) - { - //make it a 'real' style - necessary for pooled styles - rBase.getNewBase()->GetItemSet(); - rBase.getNewBase()->SetHidden( bHidden ); - } - } - break; - + assert(false); + break; case FN_UNO_STYLE_INTEROP_GRAB_BAG: { rBase.getNewBase()->GetItemSet(); @@ -1942,6 +1959,26 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, } break; } + case RES_PARATR_NUMRULE: + { + lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); + // --> OD 2006-10-18 #i70223# + if ( SFX_STYLE_FAMILY_PARA == eFamily && + rBase.getNewBase().is() && rBase.getNewBase()->GetCollection() && + //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei + rBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle() ) ////<-end,add by zhaojianwei + { + OUString sNewNumberingRuleName; + aValue >>= sNewNumberingRuleName; + if ( sNewNumberingRuleName.isEmpty() || + sNewNumberingRuleName != pDoc->GetOutlineNumRule()->GetName() ) + { + rBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); + } + } + bDone = true; + break; + } default: { // nothing to do @@ -1950,30 +1987,7 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, } if(!bDone) - { - // default ItemSet handling - SfxItemSet& rStyleSet = rBase.GetItemSet(); - SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID); - aSet.SetParent(&rStyleSet); - rPropSet.setPropertyValue(rEntry, aValue, aSet); - rStyleSet.Put(aSet); - - // --> OD 2006-10-18 #i70223# - if ( SFX_STYLE_FAMILY_PARA == eFamily && - rEntry.nWID == RES_PARATR_NUMRULE && - rBase.getNewBase().is() && rBase.getNewBase()->GetCollection() && - //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei - rBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle() ) ////<-end,add by zhaojianwei - { - OUString sNewNumberingRuleName; - aValue >>= sNewNumberingRuleName; - if ( sNewNumberingRuleName.isEmpty() || - sNewNumberingRuleName != pDoc->GetOutlineNumRule()->GetName() ) - { - rBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); - } - } - } + lcl_SetDefaultWay(rEntry, rPropSet, aValue, rBase); } void SAL_CALL SwXStyle::SetPropertyValues_Impl( @@ -2015,7 +2029,13 @@ void SAL_CALL SwXStyle::SetPropertyValues_Impl( throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this)); if(aBaseImpl.getNewBase().is()) { - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); + switch(pEntry->nWID) + { + case FN_UNO_HIDDEN: + SetPropertyValue<FN_UNO_HIDDEN>(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); + default: + lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, m_pDoc, m_rEntry.m_eFamily); + } } else if(m_bIsDescriptor) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits