summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-07-30 10:34:53 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-01 09:19:16 +0200
commit197e11313b139c23b71bd949c3769d506610bc83 (patch)
treeedc7a6fc97b5d6724464a0fa0ad941a266dfe787
parent63049e98a659290229d3356e76d49cea44575011 (diff)
loplugin:flatten in sw/core/fields
Change-Id: I42f9dd59300f215b6d8ff9f73a9f6893dbb9a8be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99899 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/source/core/fields/cellfml.cxx126
-rw-r--r--sw/source/core/fields/chpfld.cxx106
-rw-r--r--sw/source/core/fields/dbfld.cxx26
-rw-r--r--sw/source/core/fields/ddefld.cxx26
-rw-r--r--sw/source/core/fields/docufld.cxx152
-rw-r--r--sw/source/core/fields/expfld.cxx58
-rw-r--r--sw/source/core/fields/reffld.cxx190
-rw-r--r--sw/source/core/fields/textapi.cxx22
-rw-r--r--sw/source/core/fields/usrfld.cxx32
9 files changed, 369 insertions, 369 deletions
diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx
index db2375997e78..755d81f23fcc 100644
--- a/sw/source/core/fields/cellfml.cxx
+++ b/sw/source/core/fields/cellfml.cxx
@@ -946,42 +946,42 @@ void SwTableFormula::GetBoxes( const SwTableBox& rSttBox,
const SwTable* pTable = pStt->FindTabFrame()->GetTable();
// filter headline boxes
- if( pTable->GetRowsToRepeat() > 0 )
- {
- do { // middle-check loop
- const SwTableLine* pLine = rSttBox.GetUpper();
- while( pLine->GetUpper() )
- pLine = pLine->GetUpper()->GetUpper();
+ if( pTable->GetRowsToRepeat() <= 0 )
+ return;
- if( pTable->IsHeadline( *pLine ) )
- break; // headline in this area!
+ do { // middle-check loop
+ const SwTableLine* pLine = rSttBox.GetUpper();
+ while( pLine->GetUpper() )
+ pLine = pLine->GetUpper()->GetUpper();
- // maybe start and end are swapped
- pLine = rEndBox.GetUpper();
- while ( pLine->GetUpper() )
- pLine = pLine->GetUpper()->GetUpper();
+ if( pTable->IsHeadline( *pLine ) )
+ break; // headline in this area!
- if( pTable->IsHeadline( *pLine ) )
- break; // headline in this area!
+ // maybe start and end are swapped
+ pLine = rEndBox.GetUpper();
+ while ( pLine->GetUpper() )
+ pLine = pLine->GetUpper()->GetUpper();
- const SwTabFrame *pStartTable = pStt->FindTabFrame();
- const SwTabFrame *pEndTable = pEnd->FindTabFrame();
+ if( pTable->IsHeadline( *pLine ) )
+ break; // headline in this area!
- if (pStartTable == pEndTable) // no split table
- break;
+ const SwTabFrame *pStartTable = pStt->FindTabFrame();
+ const SwTabFrame *pEndTable = pEnd->FindTabFrame();
- // then remove table headers
- for (size_t n = 0; n < rBoxes.size(); ++n)
- {
- pLine = rBoxes[n]->GetUpper();
- while( pLine->GetUpper() )
- pLine = pLine->GetUpper()->GetUpper();
+ if (pStartTable == pEndTable) // no split table
+ break;
- if( pTable->IsHeadline( *pLine ) )
- rBoxes.erase( rBoxes.begin() + n-- );
- }
- } while( false );
- }
+ // then remove table headers
+ for (size_t n = 0; n < rBoxes.size(); ++n)
+ {
+ pLine = rBoxes[n]->GetUpper();
+ while( pLine->GetUpper() )
+ pLine = pLine->GetUpper()->GetUpper();
+
+ if( pTable->IsHeadline( *pLine ) )
+ rBoxes.erase( rBoxes.begin() + n-- );
+ }
+ } while( false );
}
/// Are all boxes valid that are referenced by the formula?
@@ -989,48 +989,48 @@ void SwTableFormula::HasValidBoxes_( const SwTable& rTable, OUStringBuffer& ,
OUString& rFirstBox, OUString* pLastBox, void* pPara ) const
{
bool* pBValid = static_cast<bool*>(pPara);
- if( *pBValid ) // wrong is wrong
- {
- SwTableBox* pSttBox = nullptr, *pEndBox = nullptr;
- rFirstBox = rFirstBox.copy(1); // delete identifier of box
+ if( !(*pBValid) ) // wrong is wrong
+ return;
- // area in this parenthesis?
- if( pLastBox )
- rFirstBox = rFirstBox.copy( pLastBox->getLength()+1 );
+ SwTableBox* pSttBox = nullptr, *pEndBox = nullptr;
+ rFirstBox = rFirstBox.copy(1); // delete identifier of box
- switch (m_eNmType)
- {
- case INTRNL_NAME:
- if( pLastBox )
- pEndBox = reinterpret_cast<SwTableBox*>(sal::static_int_cast<sal_IntPtr>(pLastBox->toInt64()));
- pSttBox = reinterpret_cast<SwTableBox*>(sal::static_int_cast<sal_IntPtr>(rFirstBox.toInt64()));
- break;
+ // area in this parenthesis?
+ if( pLastBox )
+ rFirstBox = rFirstBox.copy( pLastBox->getLength()+1 );
- case REL_NAME:
- {
- const SwNode* pNd = GetNodeOfFormula();
- const SwTableBox* pBox = !pNd ? nullptr
- : const_cast<SwTableBox *>(rTable.GetTableBox(
- pNd->FindTableBoxStartNode()->GetIndex() ));
- if( pLastBox )
- pEndBox = const_cast<SwTableBox*>(lcl_RelToBox( rTable, pBox, *pLastBox ));
- pSttBox = const_cast<SwTableBox*>(lcl_RelToBox( rTable, pBox, rFirstBox ));
- }
- break;
+ switch (m_eNmType)
+ {
+ case INTRNL_NAME:
+ if( pLastBox )
+ pEndBox = reinterpret_cast<SwTableBox*>(sal::static_int_cast<sal_IntPtr>(pLastBox->toInt64()));
+ pSttBox = reinterpret_cast<SwTableBox*>(sal::static_int_cast<sal_IntPtr>(rFirstBox.toInt64()));
+ break;
- case EXTRNL_NAME:
+ case REL_NAME:
+ {
+ const SwNode* pNd = GetNodeOfFormula();
+ const SwTableBox* pBox = !pNd ? nullptr
+ : const_cast<SwTableBox *>(rTable.GetTableBox(
+ pNd->FindTableBoxStartNode()->GetIndex() ));
if( pLastBox )
- pEndBox = const_cast<SwTableBox*>(rTable.GetTableBox( *pLastBox ));
- pSttBox = const_cast<SwTableBox*>(rTable.GetTableBox( rFirstBox ));
- break;
+ pEndBox = const_cast<SwTableBox*>(lcl_RelToBox( rTable, pBox, *pLastBox ));
+ pSttBox = const_cast<SwTableBox*>(lcl_RelToBox( rTable, pBox, rFirstBox ));
}
+ break;
- // Are these valid pointers?
- if( ( pLastBox &&
- ( !pEndBox || rTable.GetTabSortBoxes().find( pEndBox ) == rTable.GetTabSortBoxes().end() ) ) ||
- ( !pSttBox || rTable.GetTabSortBoxes().find( pSttBox ) == rTable.GetTabSortBoxes().end() ) )
- *pBValid = false;
+ case EXTRNL_NAME:
+ if( pLastBox )
+ pEndBox = const_cast<SwTableBox*>(rTable.GetTableBox( *pLastBox ));
+ pSttBox = const_cast<SwTableBox*>(rTable.GetTableBox( rFirstBox ));
+ break;
}
+
+ // Are these valid pointers?
+ if( ( pLastBox &&
+ ( !pEndBox || rTable.GetTabSortBoxes().find( pEndBox ) == rTable.GetTabSortBoxes().end() ) ) ||
+ ( !pSttBox || rTable.GetTabSortBoxes().find( pSttBox ) == rTable.GetTabSortBoxes().end() ) )
+ *pBValid = false;
}
bool SwTableFormula::HasValidBoxes() const
diff --git a/sw/source/core/fields/chpfld.cxx b/sw/source/core/fields/chpfld.cxx
index 9473b086d759..e85ba804a469 100644
--- a/sw/source/core/fields/chpfld.cxx
+++ b/sw/source/core/fields/chpfld.cxx
@@ -154,69 +154,69 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
SwDoc* pDoc = const_cast<SwDoc*>(rTextNd.GetDoc());
const SwTextNode *pTextNd = rTextNd.FindOutlineNodeOfLevel(rState.nLevel, pLayout);
- if( pTextNd )
+ if( !pTextNd )
+ return;
+
+ if( bSrchNum )
{
- if( bSrchNum )
- {
- const SwTextNode* pONd = pTextNd;
- do {
- if( pONd && pONd->GetTextColl() )
+ const SwTextNode* pONd = pTextNd;
+ do {
+ if( pONd && pONd->GetTextColl() )
+ {
+ sal_uInt8 nPrevLvl = rState.nLevel;
+
+ OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL,
+ "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect." );
+ rState.nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel());
+
+ if (nPrevLvl < rState.nLevel)
+ rState.nLevel = nPrevLvl;
+ else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule()
+ ->Get( rState.nLevel ).GetNumberingType() )
{
- sal_uInt8 nPrevLvl = rState.nLevel;
-
- OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL,
- "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect." );
- rState.nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel());
-
- if (nPrevLvl < rState.nLevel)
- rState.nLevel = nPrevLvl;
- else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule()
- ->Get( rState.nLevel ).GetNumberingType() )
- {
- pTextNd = pONd;
- break;
- }
-
- if (!rState.nLevel--)
- break;
- pONd = pTextNd->FindOutlineNodeOfLevel(rState.nLevel, pLayout);
+ pTextNd = pONd;
+ break;
}
- else
+
+ if (!rState.nLevel--)
break;
- } while( true );
- }
+ pONd = pTextNd->FindOutlineNodeOfLevel(rState.nLevel, pLayout);
+ }
+ else
+ break;
+ } while( true );
+ }
- // get the number without Pre-/Post-fixstrings
+ // get the number without Pre-/Post-fixstrings
- if ( pTextNd->IsOutline() )
- {
- // correction of refactoring done by cws swnumtree:
- // retrieve numbering string without prefix and suffix strings
- // as stated in the above german comment.
- rState.sNumber = pTextNd->GetNumString(false, MAXLEVEL, pLayout);
+ if ( pTextNd->IsOutline() )
+ {
+ // correction of refactoring done by cws swnumtree:
+ // retrieve numbering string without prefix and suffix strings
+ // as stated in the above german comment.
+ rState.sNumber = pTextNd->GetNumString(false, MAXLEVEL, pLayout);
- SwNumRule* pRule( pTextNd->GetNumRule() );
- if ( pTextNd->IsCountedInList() && pRule )
- {
- int nListLevel = pTextNd->GetActualListLevel();
- if (nListLevel < 0)
- nListLevel = 0;
- if (nListLevel >= MAXLEVEL)
- nListLevel = MAXLEVEL - 1;
-
- const SwNumFormat& rNFormat = pRule->Get(nListLevel);
- rState.sPost = rNFormat.GetSuffix();
- rState.sPre = rNFormat.GetPrefix();
- }
- }
- else
+ SwNumRule* pRule( pTextNd->GetNumRule() );
+ if ( pTextNd->IsCountedInList() && pRule )
{
- rState.sNumber = "??";
+ int nListLevel = pTextNd->GetActualListLevel();
+ if (nListLevel < 0)
+ nListLevel = 0;
+ if (nListLevel >= MAXLEVEL)
+ nListLevel = MAXLEVEL - 1;
+
+ const SwNumFormat& rNFormat = pRule->Get(nListLevel);
+ rState.sPost = rNFormat.GetSuffix();
+ rState.sPre = rNFormat.GetPrefix();
}
-
- rState.sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout,
- *pTextNd, false, false, ExpandMode(0)));
}
+ else
+ {
+ rState.sNumber = "??";
+ }
+
+ rState.sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout,
+ *pTextNd, false, false, ExpandMode(0)));
}
bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
diff --git a/sw/source/core/fields/dbfld.cxx b/sw/source/core/fields/dbfld.cxx
index abc9fbd375a8..6a898f6f0048 100644
--- a/sw/source/core/fields/dbfld.cxx
+++ b/sw/source/core/fields/dbfld.cxx
@@ -81,20 +81,20 @@ void SwDBFieldType::ReleaseRef()
{
OSL_ENSURE(m_nRefCnt > 0, "RefCount < 0!");
- if (--m_nRefCnt <= 0)
+ if (--m_nRefCnt > 0)
+ return;
+
+ size_t nPos = 0;
+ for (auto const & pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
{
- size_t nPos = 0;
- for (auto const & pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
- {
- if (pFieldType.get() == this)
- break;
- ++nPos;
- }
- if (nPos < GetDoc()->getIDocumentFieldsAccess().GetFieldTypes()->size())
- {
- GetDoc()->getIDocumentFieldsAccess().RemoveFieldType(nPos);
- delete this;
- }
+ if (pFieldType.get() == this)
+ break;
+ ++nPos;
+ }
+ if (nPos < GetDoc()->getIDocumentFieldsAccess().GetFieldTypes()->size())
+ {
+ GetDoc()->getIDocumentFieldsAccess().RemoveFieldType(nPos);
+ delete this;
}
}
diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx
index 9402db0bf65c..0b80f7feb2ae 100644
--- a/sw/source/core/fields/ddefld.cxx
+++ b/sw/source/core/fields/ddefld.cxx
@@ -308,23 +308,23 @@ void SwDDEFieldType::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
default:
assert(false);
}
- if( nPart>=0 )
+ if( nPart<0 )
+ return;
+
+ const OUString sOldCmd( GetCmd() );
+ OUStringBuffer sNewCmd;
+ sal_Int32 nIndex = 0;
+ for (sal_Int32 i=0; i<3; ++i)
{
- const OUString sOldCmd( GetCmd() );
- OUStringBuffer sNewCmd;
- sal_Int32 nIndex = 0;
- for (sal_Int32 i=0; i<3; ++i)
+ OUString sToken = sOldCmd.getToken(0, sfx2::cTokenSeparator, nIndex);
+ if (i==nPart)
{
- OUString sToken = sOldCmd.getToken(0, sfx2::cTokenSeparator, nIndex);
- if (i==nPart)
- {
- rVal >>= sToken;
- }
- sNewCmd.append((i < 2)
- ? sToken + OUStringChar(sfx2::cTokenSeparator) : sToken);
+ rVal >>= sToken;
}
- SetCmd( sNewCmd.makeStringAndClear() );
+ sNewCmd.append((i < 2)
+ ? sToken + OUStringChar(sfx2::cTokenSeparator) : sToken);
}
+ SetCmd( sNewCmd.makeStringAndClear() );
}
SwDDEField::SwDDEField( SwDDEFieldType* pInitType )
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 92afe5024bc7..8529b27a05ad 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -133,30 +133,30 @@ void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc,
m_nNumberingType = *pNumFormat;
m_bVirtual = false;
- if (bVirt && pDoc)
+ if (!(bVirt && pDoc))
+ return;
+
+ // check the flag since the layout NEVER sets it back
+ const SfxItemPool &rPool = pDoc->GetAttrPool();
+ for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_PAGEDESC))
{
- // check the flag since the layout NEVER sets it back
- const SfxItemPool &rPool = pDoc->GetAttrPool();
- for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_PAGEDESC))
+ auto pDesc = dynamic_cast<const SwFormatPageDesc*>(pItem);
+ if( pDesc && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
{
- auto pDesc = dynamic_cast<const SwFormatPageDesc*>(pItem);
- if( pDesc && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
+ const SwContentNode* pNd = dynamic_cast<const SwContentNode*>( pDesc->GetDefinedIn() );
+ if( pNd )
{
- const SwContentNode* pNd = dynamic_cast<const SwContentNode*>( pDesc->GetDefinedIn() );
- if( pNd )
- {
- if (SwIterator<SwFrame, SwContentNode, sw::IteratorMode::UnwrapMulti>(*pNd).First())
- // sw_redlinehide: not sure if this should happen only if
- // it's the first node, because that's where RES_PAGEDESC
- // is effective?
- m_bVirtual = true;
- }
- else if( dynamic_cast< const SwFormat* >(pDesc->GetDefinedIn()) != nullptr)
- {
- SwAutoFormatGetDocNode aGetHt( &pDoc->GetNodes() );
- m_bVirtual = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
- break;
- }
+ if (SwIterator<SwFrame, SwContentNode, sw::IteratorMode::UnwrapMulti>(*pNd).First())
+ // sw_redlinehide: not sure if this should happen only if
+ // it's the first node, because that's where RES_PAGEDESC
+ // is effective?
+ m_bVirtual = true;
+ }
+ else if( dynamic_cast< const SwFormat* >(pDesc->GetDefinedIn()) != nullptr)
+ {
+ SwAutoFormatGetDocNode aGetHt( &pDoc->GetNodes() );
+ m_bVirtual = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
+ break;
}
}
}
@@ -1323,56 +1323,56 @@ void SwHiddenTextField::Evaluate(SwDoc* pDoc)
{
OSL_ENSURE(pDoc, "got no document");
- if( SwFieldTypesEnum::ConditionalText == m_nSubType )
- {
+ if( SwFieldTypesEnum::ConditionalText != m_nSubType )
+ return;
+
#if !HAVE_FEATURE_DBCONNECTIVITY
- (void) pDoc;
+ (void) pDoc;
#else
- SwDBManager* pMgr = pDoc->GetDBManager();
+ SwDBManager* pMgr = pDoc->GetDBManager();
#endif
- m_bValid = false;
- OUString sTmpName = (m_bCanToggle && !m_bIsHidden) ? m_aTRUEText : m_aFALSEText;
-
- // Database expressions need to be different from normal text. Therefore, normal text is set
- // in quotes. If the latter exist they will be removed. If not, check if potential DB name.
- // Only if there are two or more dots and no quotes, we assume a database.
- if (sTmpName.getLength()>1 &&
- sTmpName.startsWith("\"") &&
- sTmpName.endsWith("\""))
- {
- m_aContent = sTmpName.copy(1, sTmpName.getLength() - 2);
- m_bValid = true;
+ m_bValid = false;
+ OUString sTmpName = (m_bCanToggle && !m_bIsHidden) ? m_aTRUEText : m_aFALSEText;
+
+ // Database expressions need to be different from normal text. Therefore, normal text is set
+ // in quotes. If the latter exist they will be removed. If not, check if potential DB name.
+ // Only if there are two or more dots and no quotes, we assume a database.
+ if (sTmpName.getLength()>1 &&
+ sTmpName.startsWith("\"") &&
+ sTmpName.endsWith("\""))
+ {
+ m_aContent = sTmpName.copy(1, sTmpName.getLength() - 2);
+ m_bValid = true;
+ }
+ else if(sTmpName.indexOf('\"')<0 &&
+ comphelper::string::getTokenCount(sTmpName, '.') > 2)
+ {
+ sTmpName = ::ReplacePoint(sTmpName);
+ if(sTmpName.startsWith("[") && sTmpName.endsWith("]"))
+ { // remove brackets
+ sTmpName = sTmpName.copy(1, sTmpName.getLength() - 2);
}
- else if(sTmpName.indexOf('\"')<0 &&
- comphelper::string::getTokenCount(sTmpName, '.') > 2)
- {
- sTmpName = ::ReplacePoint(sTmpName);
- if(sTmpName.startsWith("[") && sTmpName.endsWith("]"))
- { // remove brackets
- sTmpName = sTmpName.copy(1, sTmpName.getLength() - 2);
- }
#if HAVE_FEATURE_DBCONNECTIVITY
- if( pMgr)
+ if( pMgr)
+ {
+ sal_Int32 nIdx{ 0 };
+ OUString sDBName( GetDBName( sTmpName, pDoc ));
+ OUString sDataSource(sDBName.getToken(0, DB_DELIM, nIdx));
+ OUString sDataTableOrQuery(sDBName.getToken(0, DB_DELIM, nIdx));
+ if( pMgr->IsInMerge() && !sDBName.isEmpty() &&
+ pMgr->IsDataSourceOpen( sDataSource,
+ sDataTableOrQuery, false))
{
- sal_Int32 nIdx{ 0 };
- OUString sDBName( GetDBName( sTmpName, pDoc ));
- OUString sDataSource(sDBName.getToken(0, DB_DELIM, nIdx));
- OUString sDataTableOrQuery(sDBName.getToken(0, DB_DELIM, nIdx));
- if( pMgr->IsInMerge() && !sDBName.isEmpty() &&
- pMgr->IsDataSourceOpen( sDataSource,
- sDataTableOrQuery, false))
- {
- double fNumber;
- pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
- GetLanguage(), m_aContent, &fNumber );
- m_bValid = true;
- }
- else if( !sDBName.isEmpty() && !sDataSource.isEmpty() &&
- !sDataTableOrQuery.isEmpty() )
- m_bValid = true;
+ double fNumber;
+ pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
+ GetLanguage(), m_aContent, &fNumber );
+ m_bValid = true;
}
-#endif
+ else if( !sDBName.isEmpty() && !sDataSource.isEmpty() &&
+ !sDataTableOrQuery.isEmpty() )
+ m_bValid = true;
}
+#endif
}
}
@@ -2391,20 +2391,20 @@ void SwRefPageGetField::ChangeExpansion(const SwFrame& rFrame,
std::pair<Point, bool> const tmp(aPt, false);
const SwContentFrame *const pRefFrame = pRefTextField->GetTextNode().getLayoutFrame(
&rLayout, nullptr, &tmp);
- if( pSetField->IsOn() && pRefFrame )
- {
- // determine the correct offset
- const SwPageFrame* pPgFrame = rFrame.FindPageFrame();
- const short nDiff = pPgFrame->GetPhyPageNum() -
- pRefFrame->FindPageFrame()->GetPhyPageNum() + 1;
+ if( !(pSetField->IsOn() && pRefFrame) )
+ return;
- SwRefPageGetField* pGetField = const_cast<SwRefPageGetField*>(static_cast<const SwRefPageGetField*>(pField->GetFormatField().GetField()));
- SvxNumType nTmpFormat = SVX_NUM_PAGEDESC == pGetField->GetFormat()
- ? pPgFrame->GetPageDesc()->GetNumType().GetNumberingType()
- : static_cast<SvxNumType>(pGetField->GetFormat());
- const short nPageNum = std::max<short>(0, pSetField->GetOffset() + nDiff);
- pGetField->SetText(FormatNumber(nPageNum, nTmpFormat), &rLayout);
- }
+ // determine the correct offset
+ const SwPageFrame* pPgFrame = rFrame.FindPageFrame();
+ const short nDiff = pPgFrame->GetPhyPageNum() -
+ pRefFrame->FindPageFrame()->GetPhyPageNum() + 1;
+
+ SwRefPageGetField* pGetField = const_cast<SwRefPageGetField*>(static_cast<const SwRefPageGetField*>(pField->GetFormatField().GetField()));
+ SvxNumType nTmpFormat = SVX_NUM_PAGEDESC == pGetField->GetFormat()
+ ? pPgFrame->GetPageDesc()->GetNumType().GetNumberingType()
+ : static_cast<SvxNumType>(pGetField->GetFormat());
+ const short nPageNum = std::max<short>(0, pSetField->GetOffset() + nDiff);
+ pGetField->SetText(FormatNumber(nPageNum, nTmpFormat), &rLayout);
}
bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index 2872101dcada..6860d57a0fa8 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -640,26 +640,26 @@ void SwSetExpFieldType::SetChapter(SwSetExpField& rField, const SwNode& rNd,
SwRootFrame const*const pLayout)
{
const SwTextNode* pTextNd = rNd.FindOutlineNodeOfLevel(m_nLevel, pLayout);
- if( pTextNd )
- {
- SwNumRule * pRule = pTextNd->GetNumRule();
+ if( !pTextNd )
+ return;
- if (pRule)
- {
- // --> OD 2005-11-02 #i51089 - TUNING#
- if (SwNodeNum const*const pNum = pTextNd->GetNum(pLayout))
- {
- // only get the number, without pre-/post-fixstrings
- OUString const sNumber(pRule->MakeNumString(*pNum, false));
+ SwNumRule * pRule = pTextNd->GetNumRule();
- if( !sNumber.isEmpty() )
- rField.ChgExpStr(sNumber + m_sDelim + rField.GetExpStr(pLayout), pLayout);
- }
- else
- {
- OSL_ENSURE(pTextNd->GetNum(nullptr), "<SwSetExpFieldType::SetChapter(..)> - text node with numbering rule, but without number. This is a serious defect");
- }
- }
+ if (!pRule)
+ return;
+
+ // --> OD 2005-11-02 #i51089 - TUNING#
+ if (SwNodeNum const*const pNum = pTextNd->GetNum(pLayout))
+ {
+ // only get the number, without pre-/post-fixstrings
+ OUString const sNumber(pRule->MakeNumString(*pNum, false));
+
+ if( !sNumber.isEmpty() )
+ rField.ChgExpStr(sNumber + m_sDelim + rField.GetExpStr(pLayout), pLayout);
+ }
+ else
+ {
+ OSL_ENSURE(pTextNd->GetNum(nullptr), "<SwSetExpFieldType::SetChapter(..)> - text node with numbering rule, but without number. This is a serious defect");
}
}
@@ -912,18 +912,18 @@ void SwSetExpField::SetValue(const double& rValue, SwRootFrame const*const pLayo
{
SetValue(rValue);
}
- if (!pLayout || pLayout->IsHideRedlines())
+ if (!(!pLayout || pLayout->IsHideRedlines()))
+ return;
+
+ m_fValueRLHidden = rValue;
+ if (IsSequenceField())
{
- m_fValueRLHidden = rValue;
- if (IsSequenceField())
- {
- msExpandRLHidden = FormatNumber(rValue, static_cast<SvxNumType>(GetFormat()), GetLanguage());
- }
- else
- {
- msExpandRLHidden = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(
- rValue, GetFormat(), GetLanguage());
- }
+ msExpandRLHidden = FormatNumber(rValue, static_cast<SvxNumType>(GetFormat()), GetLanguage());
+ }
+ else
+ {
+ msExpandRLHidden = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(
+ rValue, GetFormat(), GetLanguage());
}
}
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 166bf24282d3..b96f35b999f4 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -326,22 +326,22 @@ static void lcl_formatReferenceLanguage( OUString& rRefText,
}
}
// not a title text starting already with a definitive article
- if ( !sNumbering.startsWith("A ") && !sNumbering.startsWith("Az ") &&
- !sNumbering.startsWith("a ") && !sNumbering.startsWith("az ") )
- {
- // lowercase, if rReferenceLanguage == "hu", not "Hu"
- OUString sArticle;
+ if ( !(!sNumbering.startsWith("A ") && !sNumbering.startsWith("Az ") &&
+ !sNumbering.startsWith("a ") && !sNumbering.startsWith("az ")) )
+ return;
- if ( rReferenceLanguage == "hu" )
- sArticle = "a";
- else
- sArticle = "A";
+ // lowercase, if rReferenceLanguage == "hu", not "Hu"
+ OUString sArticle;
+
+ if ( rReferenceLanguage == "hu" )
+ sArticle = "a";
+ else
+ sArticle = "A";
- if (bArticleAz)
- sArticle += "z";
+ if (bArticleAz)
+ sArticle += "z";
- rRefText = sArticle + " " + rRefText;
- }
+ rRefText = sArticle + " " + rRefText;
}
/// get references
@@ -433,28 +433,28 @@ static void FilterText(OUString & rText, LanguageType const eLang,
OUString const& rSetReferenceLanguage)
{
// remove all special characters (replace them with blanks)
- if (!rText.isEmpty())
+ if (rText.isEmpty())
+ return;
+
+ rText = rText.replaceAll(u"\u00ad", "");
+ OUStringBuffer aBuf(rText);
+ const sal_Int32 l = aBuf.getLength();
+ for (sal_Int32 i = 0; i < l; ++i)
{
- rText = rText.replaceAll(u"\u00ad", "");
- OUStringBuffer aBuf(rText);
- const sal_Int32 l = aBuf.getLength();
- for (sal_Int32 i = 0; i < l; ++i)
+ if (aBuf[i] < ' ')
{
- if (aBuf[i] < ' ')
- {
- aBuf[i] = ' ';
- }
- else if (aBuf[i] == 0x2011)
- {
- aBuf[i] = '-';
- }
+ aBuf[i] = ' ';
}
- rText = aBuf.makeStringAndClear();
- if (!rSetReferenceLanguage.isEmpty())
+ else if (aBuf[i] == 0x2011)
{
- lcl_formatReferenceLanguage(rText, false, eLang, rSetReferenceLanguage);
+ aBuf[i] = '-';
}
}
+ rText = aBuf.makeStringAndClear();
+ if (!rSetReferenceLanguage.isEmpty())
+ {
+ lcl_formatReferenceLanguage(rText, false, eLang, rSetReferenceLanguage);
+ }
}
// #i81002# - parameter <pFieldTextAttr> added
@@ -1027,37 +1027,37 @@ bool SwGetRefField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
void SwGetRefField::ConvertProgrammaticToUIName()
{
- if(GetTyp() && REF_SEQUENCEFLD == m_nSubType)
+ if(!(GetTyp() && REF_SEQUENCEFLD == m_nSubType))
+ return;
+
+ SwDoc* pDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc();
+ const OUString rPar1 = GetPar1();
+ // don't convert when the name points to an existing field type
+ if(pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::SetExp, rPar1, false))
+ return;
+
+ sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromProgName( rPar1, SwGetPoolIdFromName::TxtColl );
+ const char* pResId = nullptr;
+ switch( nPoolId )
{
- SwDoc* pDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc();
- const OUString rPar1 = GetPar1();
- // don't convert when the name points to an existing field type
- if(!pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::SetExp, rPar1, false))
- {
- sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromProgName( rPar1, SwGetPoolIdFromName::TxtColl );
- const char* pResId = nullptr;
- switch( nPoolId )
- {
- case RES_POOLCOLL_LABEL_ABB:
- pResId = STR_POOLCOLL_LABEL_ABB;
- break;
- case RES_POOLCOLL_LABEL_TABLE:
- pResId = STR_POOLCOLL_LABEL_TABLE;
- break;
- case RES_POOLCOLL_LABEL_FRAME:
- pResId = STR_POOLCOLL_LABEL_FRAME;
- break;
- case RES_POOLCOLL_LABEL_DRAWING:
- pResId = STR_POOLCOLL_LABEL_DRAWING;
- break;
- case RES_POOLCOLL_LABEL_FIGURE:
- pResId = STR_POOLCOLL_LABEL_FIGURE;
- break;
- }
- if (pResId)
- SetPar1(SwResId(pResId));
- }
+ case RES_POOLCOLL_LABEL_ABB:
+ pResId = STR_POOLCOLL_LABEL_ABB;
+ break;
+ case RES_POOLCOLL_LABEL_TABLE:
+ pResId = STR_POOLCOLL_LABEL_TABLE;
+ break;
+ case RES_POOLCOLL_LABEL_FRAME:
+ pResId = STR_POOLCOLL_LABEL_FRAME;
+ break;
+ case RES_POOLCOLL_LABEL_DRAWING:
+ pResId = STR_POOLCOLL_LABEL_DRAWING;
+ break;
+ case RES_POOLCOLL_LABEL_FIGURE:
+ pResId = STR_POOLCOLL_LABEL_FIGURE;
+ break;
}
+ if (pResId)
+ SetPar1(SwResId(pResId));
}
SwGetRefFieldType::SwGetRefFieldType( SwDoc* pDc )
@@ -1408,54 +1408,54 @@ void RefIdsMap::Check( SwDoc& rDoc, SwDoc& rDestDoc, SwGetRefField& rField,
/// what is most desirable since it's going to be wrong anyway
void SwGetRefFieldType::MergeWithOtherDoc( SwDoc& rDestDoc )
{
- if( &rDestDoc != m_pDoc )
+ if( &rDestDoc == m_pDoc )
+ return;
+
+ if (rDestDoc.IsClipBoard())
{
- if (rDestDoc.IsClipBoard())
- {
- // when copying _to_ clipboard, expectation is that no fields exist
- // so no re-mapping is required to avoid collisions
- assert(!rDestDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef)->HasWriterListeners());
- return; // don't modify the fields in the source doc
- }
+ // when copying _to_ clipboard, expectation is that no fields exist
+ // so no re-mapping is required to avoid collisions
+ assert(!rDestDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef)->HasWriterListeners());
+ return; // don't modify the fields in the source doc
+ }
- // then there are RefFields in the DescDox - so all RefFields in the SourceDoc
- // need to be converted to have unique IDs for both documents
- RefIdsMap aFntMap { OUString() };
- std::vector<std::unique_ptr<RefIdsMap>> aFieldMap;
+ // then there are RefFields in the DescDox - so all RefFields in the SourceDoc
+ // need to be converted to have unique IDs for both documents
+ RefIdsMap aFntMap { OUString() };
+ std::vector<std::unique_ptr<RefIdsMap>> aFieldMap;
- std::vector<SwFormatField*> vFields;
- GatherFields(vFields);
- for(auto pField: vFields)
+ std::vector<SwFormatField*> vFields;
+ GatherFields(vFields);
+ for(auto pField: vFields)
+ {
+ SwGetRefField& rRefField = *static_cast<SwGetRefField*>(pField->GetField());
+ switch( rRefField.GetSubType() )
{
- SwGetRefField& rRefField = *static_cast<SwGetRefField*>(pField->GetField());
- switch( rRefField.GetSubType() )
+ case REF_SEQUENCEFLD:
{
- case REF_SEQUENCEFLD:
+ RefIdsMap* pMap = nullptr;
+ for( auto n = aFieldMap.size(); n; )
{
- RefIdsMap* pMap = nullptr;
- for( auto n = aFieldMap.size(); n; )
+ if (aFieldMap[ --n ]->GetName() == rRefField.GetSetRefName())
{
- if (aFieldMap[ --n ]->GetName() == rRefField.GetSetRefName())
- {
- pMap = aFieldMap[ n ].get();
- break;
- }
- }
- if( !pMap )
- {
- pMap = new RefIdsMap( rRefField.GetSetRefName() );
- aFieldMap.push_back(std::unique_ptr<RefIdsMap>(pMap));
+ pMap = aFieldMap[ n ].get();
+ break;
}
-
- pMap->Check( *m_pDoc, rDestDoc, rRefField, true );
}
- break;
+ if( !pMap )
+ {
+ pMap = new RefIdsMap( rRefField.GetSetRefName() );
+ aFieldMap.push_back(std::unique_ptr<RefIdsMap>(pMap));
+ }
- case REF_FOOTNOTE:
- case REF_ENDNOTE:
- aFntMap.Check( *m_pDoc, rDestDoc, rRefField, false );
- break;
+ pMap->Check( *m_pDoc, rDestDoc, rRefField, true );
}
+ break;
+
+ case REF_FOOTNOTE:
+ case REF_ENDNOTE:
+ aFntMap.Check( *m_pDoc, rDestDoc, rRefField, false );
+ break;
}
}
}
diff --git a/sw/source/core/fields/textapi.cxx b/sw/source/core/fields/textapi.cxx
index 08331d40b882..647bcf102836 100644
--- a/sw/source/core/fields/textapi.cxx
+++ b/sw/source/core/fields/textapi.cxx
@@ -159,19 +159,19 @@ void SwTextAPIEditSource::SetText( OutlinerParaObject const & rText )
void SwTextAPIEditSource::SetString( const OUString& rText )
{
- if ( pImpl->mpPool )
+ if ( !pImpl->mpPool )
+ return;
+
+ if( !pImpl->mpOutliner )
{
- if( !pImpl->mpOutliner )
- {
- //init draw model first
- pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
- pImpl->mpOutliner.reset(new Outliner(pImpl->mpPool, OutlinerMode::TextObject));
- pImpl->mpDoc->SetCalcFieldValueHdl(pImpl->mpOutliner.get());
- }
- else
- pImpl->mpOutliner->Clear();
- pImpl->mpOutliner->Insert( rText );
+ //init draw model first
+ pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
+ pImpl->mpOutliner.reset(new Outliner(pImpl->mpPool, OutlinerMode::TextObject));
+ pImpl->mpDoc->SetCalcFieldValueHdl(pImpl->mpOutliner.get());
}
+ else
+ pImpl->mpOutliner->Clear();
+ pImpl->mpOutliner->Insert( rText );
}
std::unique_ptr<OutlinerParaObject> SwTextAPIEditSource::CreateText()
diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx
index 642f47c7f156..89914a2cc826 100644
--- a/sw/source/core/fields/usrfld.cxx
+++ b/sw/source/core/fields/usrfld.cxx
@@ -281,28 +281,28 @@ OUString SwUserFieldType::GetContent( sal_uInt32 nFormat )
void SwUserFieldType::SetContent( const OUString& rStr, sal_uInt32 nFormat )
{
- if( m_aContent != rStr )
- {
- m_aContent = rStr;
+ if( m_aContent == rStr )
+ return;
- if (nFormat && nFormat != SAL_MAX_UINT32)
- {
- double fValue;
+ m_aContent = rStr;
- if (GetDoc()->IsNumberFormat(rStr, nFormat, fValue))
- {
- SetValue(fValue);
- m_aContent = DoubleToString(fValue, nFormat);
- }
- }
+ if (nFormat && nFormat != SAL_MAX_UINT32)
+ {
+ double fValue;
- bool bModified = GetDoc()->getIDocumentState().IsModified();
- GetDoc()->getIDocumentState().SetModified();
- if( !bModified ) // Bug 57028
+ if (GetDoc()->IsNumberFormat(rStr, nFormat, fValue))
{
- GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
+ SetValue(fValue);
+ m_aContent = DoubleToString(fValue, nFormat);
}
}
+
+ bool bModified = GetDoc()->getIDocumentState().IsModified();
+ GetDoc()->getIDocumentState().SetModified();
+ if( !bModified ) // Bug 57028
+ {
+ GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
+ }
}
void SwUserFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const