diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-01-14 22:28:52 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-01-16 11:03:07 +0100 |
commit | 394895de8c47e7ab3b560d1ecb3242901a9ff92b (patch) | |
tree | c54c682f54ef0a5a07241cfc5bcd9c3a1f911f36 | |
parent | ec5e17c4c8db3ece513822b8252a08b0cf993785 (diff) |
use a map for dispatch
Change-Id: I29c88c834a01f8d04a2998ea3edfa95cd0cadb85
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 105 |
1 files changed, 40 insertions, 65 deletions
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 50ca5aefc0b8..f18f9ef29fb8 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); } } |