sw/source/core/text/porfld.cxx |    2 
 sw/source/core/text/porfld.hxx |    1 
 sw/source/core/text/txtfld.cxx |  213 +++++++++++------------------------------
 3 files changed, 58 insertions(+), 158 deletions(-)

New commits:
commit a805185f569463bfc8d597e37c0c3a83be686d67
Author:     Mike Kaganski <[email protected]>
AuthorDate: Wed Oct 25 12:34:51 2023 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Fri Oct 27 11:32:04 2023 +0200

    Simplify SwTextFormatter::NewFieldPortion
    
    Change-Id: I7e5cbce45bba4550f572606f44300b914ff5a41c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158433
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158479
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index 22b5287fce1f..7ca9b9e34fd6 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -69,17 +69,24 @@ static bool lcl_IsInBody( SwFrame const *pFrame )
     return pFrame->IsInDocBody();
 }
 
+static OUString ExpandField(const SwField& rField, const SwTextFormatter& 
rFormatter,
+                            const SwTextFormatInfo& rInf)
+{
+    if (rInf.GetOpt().IsFieldName())
+        return rField.GetFieldName();
+
+    const SwViewShell* pSh = rInf.GetVsh();
+    const SwDoc* pDoc(pSh ? pSh->GetDoc() : nullptr);
+    const bool bInClipboard(!pDoc || pDoc->IsClipBoard());
+    return rField.ExpandField(bInClipboard, 
rFormatter.GetTextFrame()->getRootFrame());
+}
+
 SwExpandPortion *SwTextFormatter::NewFieldPortion( SwTextFormatInfo &rInf,
                                                 const SwTextAttr *pHint ) const
 {
-    SwExpandPortion *pRet = nullptr;
-    SwFrame *pFrame = m_pFrame;
     SwField *pField = const_cast<SwField*>(pHint->GetFormatField().GetField());
     const bool bName = rInf.GetOpt().IsFieldName();
 
-    SwCharFormat* pChFormat = nullptr;
-    bool bNewFlyPor = false;
-
     // set language
     const_cast<SwTextFormatter*>(this)->SeekAndChg( rInf );
     if (pField->GetLanguage() != GetFnt()->GetLanguage())
@@ -91,191 +98,100 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( 
SwTextFormatInfo &rInf,
     }
 
     SwViewShell *pSh = rInf.GetVsh();
-    SwDoc *const pDoc( pSh ? pSh->GetDoc() : nullptr );
-    bool const bInClipboard( pDoc == nullptr || pDoc->IsClipBoard() );
-    bool bPlaceHolder = false;
 
-    switch( pField->GetTyp()->Which() )
+    switch (pField->GetTyp()->Which())
     {
         case SwFieldIds::Script:
         case SwFieldIds::Postit:
-            pRet = new SwPostItsPortion( SwFieldIds::Script == 
pField->GetTyp()->Which() );
-            break;
-
+            return new SwPostItsPortion(SwFieldIds::Script == 
pField->GetTyp()->Which());
         case SwFieldIds::CombinedChars:
-            {
-                if( bName )
-                    pRet = new SwFieldPortion( pField->GetFieldName() );
-                else
-                    pRet = new SwCombinedPortion( 
pField->ExpandField(bInClipboard, pFrame->getRootFrame()) );
-            }
+            if (!bName)
+                return new SwCombinedPortion(ExpandField(*pField, *this, 
rInf));
             break;
-
         case SwFieldIds::HiddenText:
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwHiddenPortion(aStr);
-            }
-            break;
-
+            return new SwHiddenPortion(ExpandField(*pField, *this, rInf));
         case SwFieldIds::Chapter:
-            if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() )
+            if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields())
             {
-                static_cast<SwChapterField*>(pField)->ChangeExpansion(*pFrame,
-                    &static_txtattr_cast<SwTextField 
const*>(pHint)->GetTextNode());
-            }
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion( aStr );
+                static_cast<SwChapterField*>(pField)->ChangeExpansion(
+                    *m_pFrame, &static_txtattr_cast<SwTextField 
const*>(pHint)->GetTextNode());
             }
             break;
-
         case SwFieldIds::DocStat:
-            if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() )
+            if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields())
             {
-                static_cast<SwDocStatField*>(pField)->ChangeExpansion( pFrame 
);
-            }
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion( aStr );
+                
static_cast<SwDocStatField*>(pField)->ChangeExpansion(m_pFrame);
             }
             break;
-
         case SwFieldIds::PageNumber:
-        {
-            if( !bName && pSh && pSh->GetLayout() && 
!pSh->Imp()->IsUpdateExpFields() )
+            if (!bName && pSh && pSh->GetLayout() && 
!pSh->Imp()->IsUpdateExpFields())
             {
-                SwPageNumberFieldType *pPageNr = 
static_cast<SwPageNumberFieldType *>(pField->GetTyp());
+                auto pPageNr = 
static_cast<SwPageNumberFieldType*>(pField->GetTyp());
 
                 const SwRootFrame* pTmpRootFrame = pSh->GetLayout();
                 const bool bVirt = pTmpRootFrame->IsVirtPageNum();
 
-                sal_uInt16 nVirtNum = pFrame->GetVirtPageNum();
+                sal_uInt16 nVirtNum = m_pFrame->GetVirtPageNum();
                 sal_uInt16 nNumPages = pTmpRootFrame->GetPageNum();
                 SvxNumType nNumFormat = SvxNumType(-1);
-                if(SVX_NUM_PAGEDESC == pField->GetFormat())
-                    nNumFormat = 
pFrame->FindPageFrame()->GetPageDesc()->GetNumType().GetNumberingType();
-                static_cast<SwPageNumberField*>(pField)
-                    ->ChangeExpansion(nVirtNum, nNumPages);
-                pPageNr->ChangeExpansion(pDoc,
-                                            bVirt, nNumFormat != 
SvxNumType(-1) ? &nNumFormat : nullptr);
-            }
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion( aStr );
+                if (SVX_NUM_PAGEDESC == pField->GetFormat())
+                    nNumFormat
+                        = 
m_pFrame->FindPageFrame()->GetPageDesc()->GetNumType().GetNumberingType();
+                
static_cast<SwPageNumberField*>(pField)->ChangeExpansion(nVirtNum, nNumPages);
+                pPageNr->ChangeExpansion(pSh->GetDoc(), bVirt,
+                                         nNumFormat != SvxNumType(-1) ? 
&nNumFormat : nullptr);
             }
             break;
-        }
         case SwFieldIds::GetExp:
-        {
-            if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() )
+            if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields())
             {
-                SwGetExpField* pExpField = static_cast<SwGetExpField*>(pField);
-                if( !::lcl_IsInBody( pFrame ) )
+                auto pExpField = static_cast<SwGetExpField*>(pField);
+                if (!::lcl_IsInBody(m_pFrame))
                 {
-                    pExpField->ChgBodyTextFlag( false );
-                    pExpField->ChangeExpansion(*pFrame,
-                            *static_txtattr_cast<SwTextField const*>(pHint));
+                    pExpField->ChgBodyTextFlag(false);
+                    pExpField->ChangeExpansion(*m_pFrame,
+                                               
*static_txtattr_cast<SwTextField const*>(pHint));
                 }
-                else if( !pExpField->IsInBodyText() )
+                else if (!pExpField->IsInBodyText())
                 {
                     // Was something else previously, thus: expand first, then 
convert it!
-                    pExpField->ChangeExpansion(*pFrame,
-                            *static_txtattr_cast<SwTextField const*>(pHint));
-                    pExpField->ChgBodyTextFlag( true );
+                    pExpField->ChangeExpansion(*m_pFrame,
+                                               
*static_txtattr_cast<SwTextField const*>(pHint));
+                    pExpField->ChgBodyTextFlag(true);
                 }
             }
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion( aStr );
-            }
             break;
-        }
         case SwFieldIds::Database:
-        {
-            if( !bName )
-            {
-                SwDBField* pDBField = static_cast<SwDBField*>(pField);
-                pDBField->ChgBodyTextFlag( ::lcl_IsInBody( pFrame ) );
-            }
+            if (!bName)
             {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion(aStr);
+                
static_cast<SwDBField*>(pField)->ChgBodyTextFlag(::lcl_IsInBody(m_pFrame));
             }
             break;
-        }
         case SwFieldIds::RefPageGet:
-            if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() )
-            {
-                
static_cast<SwRefPageGetField*>(pField)->ChangeExpansion(*pFrame,
-                        static_txtattr_cast<SwTextField const*>(pHint));
-            }
+            if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields())
             {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion(aStr);
+                static_cast<SwRefPageGetField*>(pField)->ChangeExpansion(
+                    *m_pFrame, static_txtattr_cast<SwTextField const*>(pHint));
             }
             break;
-
         case SwFieldIds::JumpEdit:
-            if( !bName )
-                pChFormat = 
static_cast<SwJumpEditField*>(pField)->GetCharFormat();
-            bNewFlyPor = true;
-            bPlaceHolder = true;
-            break;
-        case SwFieldIds::GetRef:
-            {
-                OUString const str( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion(str);
-            }
-            break;
-        case SwFieldIds::DateTime:
+        {
+            std::unique_ptr<SwFont> pFont;
+            if (!bName)
             {
-                OUString const str( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion(str);
+                pFont = std::make_unique<SwFont>(*m_pFont);
+                pFont->SetDiffFnt(
+                    
&static_cast<SwJumpEditField*>(pField)->GetCharFormat()->GetAttrSet(),
+                    &m_pFrame->GetDoc().getIDocumentSettingAccess());
             }
+            return new SwFieldPortion(ExpandField(*pField, *this, rInf), 
std::move(pFont), true);
+        }
+        case SwFieldIds::GetRef:
             break;
         default:
-            {
-                OUString const aStr( bName
-                    ? pField->GetFieldName()
-                    : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
-                pRet = new SwFieldPortion(aStr);
-            }
-    }
-
-    if( bNewFlyPor )
-    {
-        std::unique_ptr<SwFont> pTmpFnt;
-        if( !bName )
-        {
-            pTmpFnt.reset(new SwFont( *m_pFont ));
-            pTmpFnt->SetDiffFnt(&pChFormat->GetAttrSet(), 
&m_pFrame->GetDoc().getIDocumentSettingAccess());
-        }
-        OUString const aStr( bName
-            ? pField->GetFieldName()
-            : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) );
-        pRet = new SwFieldPortion(aStr, std::move(pTmpFnt), bPlaceHolder);
+            break;
     }
-
-    return pRet;
+    return new SwFieldPortion(ExpandField(*pField, *this, rInf));
 }
 
 static SwFieldPortion * lcl_NewMetaPortion(SwTextAttr & rHint, const bool 
bPrefix)
commit fd1a9d9f0b74851290215455f14890b0f9a9c6cf
Author:     Mike Kaganski <[email protected]>
AuthorDate: Wed Oct 25 11:51:13 2023 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Fri Oct 27 11:31:53 2023 +0200

    Drop unused SwFieldPortion::m_nAttrFieldType
    
    Change-Id: Id5858018607c6b0cab0d55a5d247fb39db0978bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158431
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158478
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index e07747ff8a22..66f39644ffed 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -81,7 +81,6 @@ SwFieldPortion::SwFieldPortion(OUString aExpand, 
std::unique_ptr<SwFont> pFont,
     , m_bAnimated( false), m_bNoPaint( false)
     , m_bReplace( false), m_bPlaceHolder( bPlaceHold )
     , m_bNoLength( false )
-    , m_nAttrFieldType(0)
 {
     SetWhichPor( PortionType::Field );
 }
@@ -103,7 +102,6 @@ SwFieldPortion::SwFieldPortion( const SwFieldPortion& 
rField )
     , m_bReplace( rField.m_bReplace )
     , m_bPlaceHolder( rField.m_bPlaceHolder )
     , m_bNoLength( rField.m_bNoLength )
-    , m_nAttrFieldType( rField.m_nAttrFieldType)
 {
     if ( rField.HasFont() )
         m_pFont.reset( new SwFont( *rField.GetFont() ) );
diff --git a/sw/source/core/text/porfld.hxx b/sw/source/core/text/porfld.hxx
index 39a08a5db665..e1c18fc9bd18 100644
--- a/sw/source/core/text/porfld.hxx
+++ b/sw/source/core/text/porfld.hxx
@@ -63,7 +63,6 @@ public:
     SwFieldPortion(OUString aExpand, std::unique_ptr<SwFont> pFnt = nullptr, 
bool bPlaceHolder = false, TextFrameIndex nLen = TextFrameIndex(1));
     virtual ~SwFieldPortion() override;
 
-    sal_uInt16 m_nAttrFieldType;
     void TakeNextOffset( const SwFieldPortion* pField );
     void CheckScript( const SwTextSizeInfo &rInf );
     bool HasFont() const { return nullptr != m_pFont; }
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index f0732a84204a..22b5287fce1f 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -79,7 +79,6 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( 
SwTextFormatInfo &rInf,
 
     SwCharFormat* pChFormat = nullptr;
     bool bNewFlyPor = false;
-    sal_uInt16 subType = 0;
 
     // set language
     const_cast<SwTextFormatter*>(this)->SeekAndChg( rInf );
@@ -146,7 +145,6 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( 
SwTextFormatInfo &rInf,
                     : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
                 pRet = new SwFieldPortion( aStr );
             }
-            static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType= 
ATTR_PAGECOUNTFLD;
             break;
 
         case SwFieldIds::PageNumber:
@@ -174,7 +172,6 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( 
SwTextFormatInfo &rInf,
                     : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
                 pRet = new SwFieldPortion( aStr );
             }
-            static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType= 
ATTR_PAGENUMBERFLD;
             break;
         }
         case SwFieldIds::GetExp:
@@ -240,30 +237,20 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( 
SwTextFormatInfo &rInf,
             bPlaceHolder = true;
             break;
         case SwFieldIds::GetRef:
-            subType = static_cast<SwGetRefField*>(pField)->GetSubType();
             {
                 OUString const str( bName
                     ? pField->GetFieldName()
                     : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
                 pRet = new SwFieldPortion(str);
             }
-            if( subType == REF_BOOKMARK  )
-                static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType = 
ATTR_BOOKMARKFLD;
-            else if( subType == REF_SETREFATTR )
-                static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType = 
ATTR_SETREFATTRFLD;
             break;
         case SwFieldIds::DateTime:
-            subType = static_cast<SwDateTimeField*>(pField)->GetSubType();
             {
                 OUString const str( bName
                     ? pField->GetFieldName()
                     : pField->ExpandField(bInClipboard, 
pFrame->getRootFrame()) );
                 pRet = new SwFieldPortion(str);
             }
-            if( subType & DATEFLD  )
-                static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType= 
ATTR_DATEFLD;
-            else if( subType & TIMEFLD )
-                static_cast<SwFieldPortion*>(pRet)->m_nAttrFieldType = 
ATTR_TIMEFLD;
             break;
         default:
             {

Reply via email to