sw/inc/hintids.hxx                      |    6 ++++++
 sw/source/core/bastyp/calc.cxx          |    6 +++---
 sw/source/core/fields/expfld.cxx        |    8 ++++----
 sw/source/filter/ww8/writerhelper.cxx   |    2 +-
 sw/source/filter/ww8/writerhelper.hxx   |   28 ----------------------------
 sw/source/filter/ww8/writerwordglue.cxx |    4 ++--
 sw/source/filter/ww8/wrtw8esh.cxx       |    2 +-
 sw/source/filter/ww8/wrtw8nds.cxx       |    2 +-
 sw/source/filter/ww8/ww8atr.cxx         |   12 +++++-------
 sw/source/filter/ww8/ww8par6.cxx        |    2 +-
 sw/source/uibase/shells/annotsh.cxx     |    6 ++++--
 sw/source/uibase/shells/drwtxtsh.cxx    |    8 ++++++--
 sw/source/uibase/shells/textsh.cxx      |   12 +++++++-----
 13 files changed, 41 insertions(+), 57 deletions(-)

New commits:
commit 919b923e9fe59bd83d954a53c21635317fea0de7
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 1 19:04:01 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Mar 2 08:31:07 2022 +0100

    remove writerhelper::ItemGet
    
    the TypedWhichId template methods on SwContentNode supercede this
    
    Change-Id: Ibb9a6a6a1642e2d764004c7179dce642fef7a40a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130804
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/filter/ww8/writerhelper.cxx 
b/sw/source/filter/ww8/writerhelper.cxx
index 64cb0d7959c7..740274453dfb 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -592,7 +592,7 @@ namespace sw
                     pBreak = &(ItemGet<SvxFormatBreakItem>(*pApply, 
RES_BREAK));
             }
             else if (const SwContentNode *pNd = rNd.GetContentNode())
-                pBreak = &(ItemGet<SvxFormatBreakItem>(*pNd, RES_BREAK));
+                pBreak = &pNd->GetAttr(RES_BREAK);
 
             return pBreak && pBreak->GetBreak() == SvxBreak::PageBefore;
         }
diff --git a/sw/source/filter/ww8/writerhelper.hxx 
b/sw/source/filter/ww8/writerhelper.hxx
index 29e9a8e6b495..65d5c2501bc4 100644
--- a/sw/source/filter/ww8/writerhelper.hxx
+++ b/sw/source/filter/ww8/writerhelper.hxx
@@ -248,34 +248,6 @@ namespace sw
             return dynamic_cast<const T *>(pItem);
         }
 
-        /** Extract a SfxPoolItem derived property from a SwContentNode
-
-            Writer's attributes are retrieved by passing a numeric identifier
-            and receiving a SfxPoolItem reference which must then typically be
-            cast back to its original type which is both tedious and verbose.
-
-            ItemGet uses item_cast () on the retrieved reference to test that 
the
-            retrieved property is of the type that the developer thinks it is.
-
-            @param rNode
-            The SwContentNode to retrieve the property from
-
-            @param eType
-            The numeric identifier of the property to be retrieved
-
-            @tplparam T
-            A SfxPoolItem derived class of the retrieved property
-
-            @exception std::bad_cast Thrown if the property was not a T
-
-            @return The T requested
-        */
-        template<class T> const T & ItemGet(const SwContentNode &rNode,
-            sal_uInt16 eType)
-        {
-            return item_cast<T>(rNode.GetAttr(eType));
-        }
-
         /** Extract a SfxPoolItem derived property from a SwFormat
 
             Writer's attributes are retrieved by passing a numeric identifier
diff --git a/sw/source/filter/ww8/writerwordglue.cxx 
b/sw/source/filter/ww8/writerwordglue.cxx
index fda1043db476..5474148b5c5d 100644
--- a/sw/source/filter/ww8/writerwordglue.cxx
+++ b/sw/source/filter/ww8/writerwordglue.cxx
@@ -532,8 +532,8 @@ namespace sw
             if (!rText.isEmpty())
                 nScript = g_pBreakIt->GetBreakIter()->getScriptType(rText, 0);
 
-            rtl_TextEncoding eChrSet = ItemGet<SvxFontItem>(rTextNd,
-                GetWhichOfScript(RES_CHRATR_FONT, nScript)).GetCharSet();
+            TypedWhichId<SvxFontItem> nFontWhichId = 
GetWhichOfScript(RES_CHRATR_FONT, nScript);
+            rtl_TextEncoding eChrSet = 
rTextNd.GetAttr(nFontWhichId).GetCharSet();
             eChrSet = GetExtendedTextEncoding(eChrSet);
 
             CharRuns aRunChanges;
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx 
b/sw/source/filter/ww8/wrtw8esh.cxx
index 6ce80301125c..82392ea5106c 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2425,7 +2425,7 @@ bool WinwordAnchoring::ConvertPosition( 
SwFormatHoriOrient& _iorHoriOri,
     {
         SwTextNode& rAnchorTextNode =
             
dynamic_cast<SwTextNode&>(_rFrameFormat.GetAnchor().GetContentAnchor()->nNode.GetNode());
-        const SvxFormatBreakItem& rBreak = 
ItemGet<SvxFormatBreakItem>(rAnchorTextNode, RES_BREAK);
+        const SvxFormatBreakItem& rBreak = rAnchorTextNode.GetAttr(RES_BREAK);
         if (rBreak.GetBreak() == SvxBreak::ColumnBefore)
         {
             bConvDueToAnchoredAtColBreakPara = true;
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index bf0d049b1d6a..394203367dc4 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3069,7 +3069,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
                 {   // Even a pagedesc item is set, the break item can be set 
'NONE',
                     // this has to be overruled.
                     const SwFormatPageDesc& rPageDescAtParaStyle =
-                        ItemGet<SwFormatPageDesc>( rNode, RES_PAGEDESC );
+                        rNode.GetAttr( RES_PAGEDESC );
                     if( rPageDescAtParaStyle.KnowsPageDesc() )
                         oTmpSet->ClearItem( RES_BREAK );
                 }
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 97893aae6c13..531194cdf981 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -594,15 +594,13 @@ void MSWordExportBase::OutputSectionBreaks( const 
SfxItemSet *pSet, const SwNode
     {
         if ( const SwContentNode *pNd = rNd.GetContentNode() )
         {
-            const SvxFormatBreakItem &rBreak =
-                ItemGet<SvxFormatBreakItem>( *pNd, RES_BREAK );
+            const SvxFormatBreakItem &rBreak = pNd->GetAttr( RES_BREAK );
             if ( rBreak.GetBreak() == SvxBreak::PageBefore )
                 bHackInBreak = true;
             else
             {   // Even a pagedesc item is set, the break item can be set 
'NONE',
                 // but a pagedesc item is an implicit page break before...
-                const SwFormatPageDesc &rPageDesc =
-                    ItemGet<SwFormatPageDesc>( *pNd, RES_PAGEDESC );
+                const SwFormatPageDesc &rPageDesc = pNd->GetAttr( RES_PAGEDESC 
);
                 if ( rPageDesc.KnowsPageDesc() )
                     bHackInBreak = true;
             }
@@ -661,7 +659,7 @@ sal_uLong MSWordExportBase::GetSectionLineNo( const 
SfxItemSet* pSet, const SwNo
     }
     else if ( const SwContentNode *pNd = rNd.GetContentNode() )
     {
-        pNItem = &( ItemGet<SwFormatLineNumber>( *pNd, RES_LINENUMBER ) );
+        pNItem = &pNd->GetAttr( RES_LINENUMBER );
     }
 
     return pNItem? pNItem->GetStartValue() : 0;
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 6d4938a8557f..32028c0eebb3 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -2619,7 +2619,7 @@ void 
SwWW8ImplReader::StripNegativeAfterIndent(SwFrameFormat const *pFlyFormat)
         SwTextNode *pNd = aIdx.GetNode().GetTextNode();
         if (pNd)
         {
-            const SvxLRSpaceItem& rLR = ItemGet<SvxLRSpaceItem>(*pNd, 
RES_LR_SPACE);
+            const SvxLRSpaceItem& rLR = pNd->GetAttr(RES_LR_SPACE);
             if (rLR.GetRight() < 0)
             {
                 SvxLRSpaceItem aLR(rLR);
commit 31a8627f0323fad0f85f7859a513dbc039375afb
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 1 16:29:12 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Mar 2 08:30:52 2022 +0100

    add TypedWhichId version of GetWhichOfScript
    
    Change-Id: Ieb93f9525d0cc5b3a23e013f30ddaad6f44890ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130796
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx
index c3907b20dc16..76068d21ec47 100644
--- a/sw/inc/hintids.hxx
+++ b/sw/inc/hintids.hxx
@@ -547,6 +547,12 @@ template <class T> inline const T* 
GetDfltAttr(TypedWhichId<T> nWhich)
 
 SW_DLLPUBLIC sal_uInt16 GetWhichOfScript(sal_uInt16 nWhich, sal_uInt16 
nScript);
 
+template <class T>
+inline TypedWhichId<T> GetWhichOfScript(TypedWhichId<T> nWhich, sal_uInt16 
nScript)
+{
+    return TypedWhichId<T>(GetWhichOfScript(sal_uInt16(nWhich), nScript));
+}
+
 // return for the given TextAttribute without an end the correct character.
 // This function returns
 //      CH_TXTATR_BREAKWORD for Textattribute which breaks a word (default)
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 3ba77ed08a2d..02983568e0f9 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -196,10 +196,10 @@ CalcOp* FindOperator( const OUString& rSrch )
 
 static LanguageType GetDocAppScriptLang( SwDoc const & rDoc )
 {
-    return static_cast<const SvxLanguageItem&>(rDoc.GetDefault(
+    TypedWhichId<SvxLanguageItem> nWhich =
                GetWhichOfScript( RES_CHRATR_LANGUAGE,
-                                 
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ))
-            )).GetLanguage();
+                                 
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ));
+    return rDoc.GetDefault(nWhich).GetLanguage();
 }
 
 static double lcl_ConvertToDateValue( SwDoc& rDoc, sal_Int32 nDate )
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index d22e29ddd6c1..6c5f45f3716d 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -996,11 +996,11 @@ sal_Int32 SwGetExpField::GetReferenceTextPos( const 
SwFormatField& rFormat, SwDo
         SwAttrSet aSet(rDoc.GetAttrPool(), nIds);
         rTextNode.GetParaAttr(aSet, nRet, nRet+1);
 
-        if( RTL_TEXTENCODING_SYMBOL != static_cast<const 
SvxFontItem&>(aSet.Get(
-                GetWhichOfScript( RES_CHRATR_FONT, nSrcpt )) ).GetCharSet() )
+        TypedWhichId<SvxFontItem> nFontWhich = GetWhichOfScript( 
RES_CHRATR_FONT, nSrcpt );
+        if( RTL_TEXTENCODING_SYMBOL != aSet.Get( nFontWhich ).GetCharSet() )
         {
-            LanguageType eLang = static_cast<const SvxLanguageItem&>(aSet.Get(
-                GetWhichOfScript( RES_CHRATR_LANGUAGE, nSrcpt )) 
).GetLanguage();
+            TypedWhichId<SvxLanguageItem> nLangWhich = GetWhichOfScript( 
RES_CHRATR_LANGUAGE, nSrcpt ) ;
+            LanguageType eLang = aSet.Get(nLangWhich).GetLanguage();
             LanguageTag aLanguageTag( eLang);
             CharClass aCC( aLanguageTag);
             sal_Unicode c0 = sNodeText[0];
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index f90d04a765a3..97893aae6c13 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3246,8 +3246,8 @@ void AttributeOutputBase::TextField( const SwFormatField& 
rField )
         assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
         sal_uInt16 nScript = g_pBreakIt->GetBreakIter()->getScriptType( 
pField->GetPar1(), 0);
 
-        tools::Long nHeight = static_cast<const 
SvxFontHeightItem&>((GetExport().GetItem(
-            GetWhichOfScript(RES_CHRATR_FONTSIZE,nScript)))).GetHeight();
+        TypedWhichId<SvxFontHeightItem> nFontHeightWhich = 
GetWhichOfScript(RES_CHRATR_FONTSIZE,nScript);
+        tools::Long nHeight = 
GetExport().GetItem(nFontHeightWhich).GetHeight();
 
         nHeight = (nHeight + 10) / 20; //Font Size in points;
 
diff --git a/sw/source/uibase/shells/annotsh.cxx 
b/sw/source/uibase/shells/annotsh.cxx
index 3246e43bc404..21b249fb00d2 100644
--- a/sw/source/uibase/shells/annotsh.cxx
+++ b/sw/source/uibase/shells/annotsh.cxx
@@ -1762,9 +1762,11 @@ void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
         }
         else
         {
-            aSetDlgFont.reset(static_cast<SvxFontItem*>(aSet.Get( 
GetWhichOfScript(
+            TypedWhichId<SvxFontItem> nFontWhich =
+                GetWhichOfScript(
                         SID_ATTR_CHAR_FONT,
-                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) )).Clone()));
+                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) );
+            aSetDlgFont.reset(aSet.Get(nFontWhich).Clone());
         }
 
         if (sFontName.isEmpty())
diff --git a/sw/source/uibase/shells/drwtxtsh.cxx 
b/sw/source/uibase/shells/drwtxtsh.cxx
index 43c35159f671..2416c3a4863c 100644
--- a/sw/source/uibase/shells/drwtxtsh.cxx
+++ b/sw/source/uibase/shells/drwtxtsh.cxx
@@ -701,9 +701,13 @@ void SwDrawTextShell::InsertSymbol(SfxRequest& rReq)
         if( pI )
             aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
         else
-            aSetDlgFont.reset(static_cast<SvxFontItem*>(aSet.Get( 
GetWhichOfScript(
+        {
+            TypedWhichId<SvxFontItem> nFontWhich =
+                GetWhichOfScript(
                         SID_ATTR_CHAR_FONT,
-                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) )).Clone()));
+                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) );
+            aSetDlgFont.reset(aSet.Get( nFontWhich ).Clone());
+        }
         if (sFontName.isEmpty())
             sFontName = aSetDlgFont->GetFamilyName();
     }
diff --git a/sw/source/uibase/shells/textsh.cxx 
b/sw/source/uibase/shells/textsh.cxx
index 158e381b1351..8fe5862e3479 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -909,11 +909,11 @@ void SwTextShell::InsertSymbol( SfxRequest& rReq )
         }
         else
         {
-            aFont.reset(static_cast<SvxFontItem*>(
-                        aSet.Get(
+            TypedWhichId<SvxFontItem> nFontWhich =
                             GetWhichOfScript(
                                 RES_CHRATR_FONT,
-                                
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) 
)).Clone()));
+                                
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
+            aFont.reset(aSet.Get(nFontWhich).Clone());
         }
 
         if (aFontName.isEmpty())
@@ -966,9 +966,11 @@ void SwTextShell::InsertSymbol( SfxRequest& rReq )
         }
         else
         {
-            aFont.reset(static_cast<SvxFontItem*>(aSet.Get( GetWhichOfScript(
+            TypedWhichId<SvxFontItem> nFontWhich =
+                GetWhichOfScript(
                         RES_CHRATR_FONT,
-                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) )).Clone()));
+                        SvtLanguageOptions::GetI18NScriptTypeOfLanguage( 
GetAppLanguage() ) );
+            aFont.reset(aSet.Get( nFontWhich ).Clone());
         }
     }
 

Reply via email to