include/svl/poolitem.hxx | 33 +++++++++++++++++++++++++++++++++ sw/source/core/doc/docfmt.cxx | 13 ++++++------- sw/source/core/doc/fmtcol.cxx | 16 ++++++++-------- sw/source/filter/xml/xmlimp.cxx | 2 +- 4 files changed, 48 insertions(+), 16 deletions(-)
New commits: commit dd7825765f83d09d132d1e6138b27cb03564aae8 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Dec 31 20:44:20 2020 +0300 Commit: Justin Luth <justin_l...@sil.org> CommitDate: Wed Jan 13 18:20:18 2021 +0100 tdf#138544 sw LoadUserSettings: default SubtractFlysAnchoredAtFlys This is the third patch in the series. When you start a new document, Writer compat setting "Tolerate white lines of PDF page backgrounds for compatibility with old documents" is off. Now, when saving and reloading it with LoadUserSettings disabled, it is still the program default of "off", instead of "on". Change-Id: I06869600f0d75c9d5457372d56e39750ff5b3dae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108547 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_l...@sil.org> diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx index e164da851430..13198a2f9cfc 100644 --- a/sw/source/filter/xml/xmlimp.cxx +++ b/sw/source/filter/xml/xmlimp.cxx @@ -1596,7 +1596,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC if (!bPropLineSpacingShrinksFirstLine) xProps->setPropertyValue("PropLineSpacingShrinksFirstLine", makeAny(false)); - if (!bSubtractFlysAnchoredAtFlys) + if (!bSubtractFlysAnchoredAtFlys && bAreUserSettingsFromDocument) xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true)); if (!bCollapseEmptyCellPara) commit fcb6e076d9004ef907a2616d04bf9c39908e6e8a Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Sat Jan 9 21:49:51 2021 +0100 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Wed Jan 13 18:20:09 2021 +0100 SfxPoolItem: introduce StaticWhichCast and DynamicWhichCast - at least in Writer it is a common pattern to switch case on a Which and then static_cast the SfxPoolItem to the assumed "right" type - instead, it would much less errorprone to use the TypedWhichId to be sure to cast to the right, matching type for an id - also, this allow to assert the dynamic_cast in debug build to highlight type confusion - finally, there is some example use added in sw showing how it gets rid of explicit manual lookup of the type to cast to - likely, many of the static_cast<TypedWhichId>(SfxPoolItem*) can be found and replaced with a compiler plugin. This is left as an exercise to the reader. - alternatively, this might be a nice easy EasyHack to start .... Change-Id: I00110c0fe25626bc89d835e3c4e7ff75839756b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109042 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx index ce4ebeaef679..8ccf65e5565c 100644 --- a/include/svl/poolitem.hxx +++ b/include/svl/poolitem.hxx @@ -149,6 +149,39 @@ public: m_nWhich = nId; } sal_uInt16 Which() const { return m_nWhich; } + // StaticWhichCast asserts if the TypedWhichId is not matching its type, otherwise it returns a reference. + // You can use StaticWhichCast when you are sure about the type at compile time -- like a static_cast. + template<class T> T& StaticWhichCast(TypedWhichId<T> nId) + { + (void)nId; + assert(nId == m_nWhich); + assert(dynamic_cast<T*>(this)); + return *static_cast<T*>(this); + } + template<class T> const T& StaticWhichCast(TypedWhichId<T> nId) const + { + (void)nId; + assert(nId == m_nWhich); + assert(dynamic_cast<const T*>(this)); + return *static_cast<const T*>(this); + } + // DynamicWhichCast returns nullptr if the TypedWhichId is not matching its type, otherwise it returns a typed pointer. + // it asserts if the TypedWhichId matches its Which, but not the RTTI type. + // You can use DynamicWhichCast when you are not sure about the type at compile time -- like a dynamic_cast. + template<class T> T* DynamicWhichCast(TypedWhichId<T> nId) + { + if(m_nWhich != nId) + return nullptr; + assert(dynamic_cast<T*>(this)); + return static_cast<T*>(this); + } + template<class T> const T* DynamicWhichCast(TypedWhichId<T> nId) const + { + if(m_nWhich != nId) + return nullptr; + assert(dynamic_cast<const T*>(this)); + return static_cast<const T*>(this); + } virtual bool operator==( const SfxPoolItem& ) const = 0; bool operator!=( const SfxPoolItem& rItem ) const { return !(*this == rItem); } diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 45855c20c9b5..e3ecd4616fcb 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -147,13 +147,13 @@ static bool lcl_RstAttr( const SwNodePtr& rpNd, void* pArgs ) switch( aSavId ) { case RES_PAGEDESC: - bSave = nullptr != static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); + bSave = nullptr != pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc(); break; case RES_BREAK: - bSave = SvxBreak::NONE != static_cast<const SvxFormatBreakItem*>(pItem)->GetBreak(); + bSave = SvxBreak::NONE != pItem->StaticWhichCast(RES_BREAK).GetBreak(); break; case RES_PARATR_NUMRULE: - bSave = !static_cast<const SwNumRuleItem*>(pItem)->GetValue().isEmpty(); + bSave = !pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue().isEmpty(); break; } if( bSave ) @@ -606,20 +606,19 @@ void SwDoc::SetDefault( const SfxItemSet& rSet ) const SfxPoolItem* pTmpItem; if( ( SfxItemState::SET == aNew.GetItemState( RES_PARATR_TABSTOP, false, &pTmpItem ) ) && - static_cast<const SvxTabStopItem*>(pTmpItem)->Count() ) + pTmpItem->StaticWhichCast(RES_PARATR_TABSTOP).Count() ) { // Set the default values of all TabStops to the new value. // Attention: we always work with the PoolAttribute here, so that // we don't calculate the same value on the same TabStop (pooled!) for all sets. // We send a FormatChg to modify. - SwTwips nNewWidth = (*static_cast<const SvxTabStopItem*>(pTmpItem))[ 0 ].GetTabPos(), + SwTwips nNewWidth = pTmpItem->StaticWhichCast(RES_PARATR_TABSTOP)[ 0 ].GetTabPos(), nOldWidth = aOld.Get(RES_PARATR_TABSTOP)[ 0 ].GetTabPos(); bool bChg = false; for (const SfxPoolItem* pItem2 : GetAttrPool().GetItemSurrogates(RES_PARATR_TABSTOP)) { - auto pTabStopItem = dynamic_cast<const SvxTabStopItem*>(pItem2); - if(pTabStopItem) + if(auto pTabStopItem = pItem2->DynamicWhichCast(RES_PARATR_TABSTOP)) bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth, *const_cast<SvxTabStopItem*>(pTabStopItem) ); } diff --git a/sw/source/core/doc/fmtcol.cxx b/sw/source/core/doc/fmtcol.cxx index e4753ba2767c..20d149dcf396 100644 --- a/sw/source/core/doc/fmtcol.cxx +++ b/sw/source/core/doc/fmtcol.cxx @@ -133,8 +133,8 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH { case RES_ATTRSET_CHG: // Only recalculate if we're not the sender! - pNewChgSet = static_cast<const SwAttrSetChg*>(pNew); - pOldChgSet = static_cast<const SwAttrSetChg*>(pOld); + pNewChgSet = &pNew->StaticWhichCast(RES_ATTRSET_CHG); + pOldChgSet = &pOld->StaticWhichCast(RES_ATTRSET_CHG); pNewChgSet->GetChgSet()->GetItemState( RES_LR_SPACE, false, reinterpret_cast<const SfxPoolItem**>(&pNewLRSpace) ); pNewChgSet->GetChgSet()->GetItemState( @@ -171,25 +171,25 @@ void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rH break; case RES_LR_SPACE: - pNewLRSpace = static_cast<const SvxLRSpaceItem*>(pNew); + pNewLRSpace = &pNew->StaticWhichCast(RES_LR_SPACE); break; case RES_UL_SPACE: - pNewULSpace = static_cast<const SvxULSpaceItem*>(pNew); + pNewULSpace = &pNew->StaticWhichCast(RES_UL_SPACE); break; case RES_CHRATR_FONTSIZE: - aFontSizeArr[0] = static_cast<const SvxFontHeightItem*>(pNew); + aFontSizeArr[0] = &pNew->StaticWhichCast(RES_CHRATR_CJK_FONTSIZE); break; case RES_CHRATR_CJK_FONTSIZE: - aFontSizeArr[1] = static_cast<const SvxFontHeightItem*>(pNew); + aFontSizeArr[1] = &pNew->StaticWhichCast(RES_CHRATR_CJK_FONTSIZE); break; case RES_CHRATR_CTL_FONTSIZE: - aFontSizeArr[2] = static_cast<const SvxFontHeightItem*>(pNew); + aFontSizeArr[2] = &pNew->StaticWhichCast(RES_CHRATR_CTL_FONTSIZE); break; // #i70223# case RES_PARATR_NUMRULE: if (bAssignedToListLevelOfOutlineStyle) { - pNewNumRuleItem = static_cast<const SwNumRuleItem*>(pNew); + pNewNumRuleItem = &pNew->StaticWhichCast(RES_PARATR_NUMRULE); } break; default: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits