sw/source/filter/ww8/writerhelper.hxx | 49 ++-------------------------------- sw/source/filter/ww8/wrtw8nds.cxx | 11 ++----- sw/source/filter/ww8/ww8atr.cxx | 2 - 3 files changed, 8 insertions(+), 54 deletions(-)
New commits: commit 687a0d7093fc21235f745825da3d5913c1c6d803 Author: Mike Kaganski <[email protected]> AuthorDate: Mon Nov 24 13:17:52 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Nov 24 14:52:30 2025 +0100 Drop item_cast, and use StaticWhichCast Change-Id: I59b8f848789c049e12a7038456a3608ae8386e08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194412 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/source/filter/ww8/writerhelper.hxx b/sw/source/filter/ww8/writerhelper.hxx index c87d67f99880..c8d490718384 100644 --- a/sw/source/filter/ww8/writerhelper.hxx +++ b/sw/source/filter/ww8/writerhelper.hxx @@ -202,49 +202,6 @@ namespace sw { namespace util { - /** Provide a dynamic_cast style cast for SfxPoolItems - - A SfxPoolItem generally need to be cast back to its original type - to be useful, which is both tedious and error prone. So item_cast is - a helper template to aid the process and test if the cast is - correct. - - @param rItem - The SfxPoolItem which is to be casted - - @tplparam T - A SfxPoolItem derived class to cast rItem to - - @return A rItem upcasted back to a T - - @exception std::bad_cast Thrown if the rItem was not a T - */ - template<class T> const T & item_cast(const SfxPoolItem &rItem) - { - assert(dynamic_cast<const T *>(&rItem) && "bad type cast"); - return static_cast<const T &>(rItem); - } - - /** Provide a dynamic_cast style cast for SfxPoolItems - - A SfxPoolItem generally need to be cast back to its original type - to be useful, which is both tedious and error prone. So item_cast is - a helper template to aid the process and test if the cast is - correct. - - @param pItem - The SfxPoolItem which is to be casted - - @tplparam T - A SfxPoolItem derived class to cast pItem to - - @return A pItem upcasted back to a T or 0 if pItem was not a T - */ - template<class T> const T * item_cast(const SfxPoolItem *pItem) - { - return dynamic_cast<const T *>(pItem); - } - /** Get the Paragraph Styles of a SwDoc Writer's styles are in one of those dreaded macro based pre-STL diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 82c5bf497687..f795be4b6b0c 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -455,7 +455,7 @@ void SwWW8AttrIter::OutAttr(sal_Int32 nSwPos, bool bWriteCombChars) if( SfxItemState::SET == aIter.GetItemState( false, &pItem )) { if (nWhichId == nFontId) - pFont = &(item_cast<SvxFontItem>(*pItem)); + pFont = &pItem->StaticWhichCast(nFontId); else if (nWhichId == RES_CHRATR_GRABBAG) pGrabBag = pItem; else diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 3462cb3809b8..7a67175f7310 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -262,7 +262,7 @@ void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 if (bWriteCombChars && nWhich == RES_CHRATR_FONTSIZE) { - SvxFontHeightItem fontHeight(item_cast<SvxFontHeightItem>( *pItem )); + SvxFontHeightItem fontHeight(pItem->StaticWhichCast(RES_CHRATR_FONTSIZE)); fontHeight.SetHeight( fontHeight.GetHeight() / 2 ); AttrOutput().OutputItem( fontHeight ); commit e657e11cc5164e9f9797ada64c69b239a35a877a Author: Mike Kaganski <[email protected]> AuthorDate: Mon Nov 24 09:39:30 2025 +0100 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Nov 24 14:52:24 2025 +0100 Simplify HasItem using TypedWhichId It is only used with such id. One additional upside is avoiding a dynamic_cast. Change-Id: Ia748add0a115bdaedc9982a62c5e8202c016dc1d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194414 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/source/filter/ww8/writerhelper.hxx b/sw/source/filter/ww8/writerhelper.hxx index 710a9aa922af..c87d67f99880 100644 --- a/sw/source/filter/ww8/writerhelper.hxx +++ b/sw/source/filter/ww8/writerhelper.hxx @@ -319,10 +319,10 @@ namespace sw const SfxPoolItem *SearchPoolItems(const ww8::PoolItems &rItems, sal_uInt16 eType); - template<class T> const T* HasItem(const ww8::PoolItems &rItems, - sal_uInt16 eType) + template<class T> const T* HasItem(const ww8::PoolItems &rItems, TypedWhichId<T> eType) { - return item_cast<T>(SearchPoolItems(rItems, eType)); + const SfxPoolItem* pItem = SearchPoolItems(rItems, eType); + return pItem ? &pItem->StaticWhichCast(eType) : nullptr; } /** Remove properties from an SfxItemSet which a SwFormatCharFormat overrides diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 3c9b1a30ce14..82c5bf497687 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -478,14 +478,11 @@ void SwWW8AttrIter::OutAttr(sal_Int32 nSwPos, bool bWriteCombChars) aExportSet which a SwCharFormat would override, we can't rely on word doing this for us like writer does */ - const SwFormatCharFormat *pCharFormatItem = - HasItem< SwFormatCharFormat >( aRangeItems, RES_TXTATR_CHARFMT ); - if ( pCharFormatItem ) + if (const SwFormatCharFormat* pCharFormatItem = HasItem(aRangeItems, RES_TXTATR_CHARFMT)) + { ClearOverridesFromSet( *pCharFormatItem, aExportSet ); - // check toggle properties in DOCX output - if (pCharFormatItem) - { + // check toggle properties in DOCX output handleToggleProperty(aExportSet, *pCharFormatItem); }
