summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-05-03 13:40:15 +0200
committerMichael Stahl <mstahl@redhat.com>2017-05-03 14:07:11 +0200
commit91646b10315e2ee64b25fb8a604012c729343c07 (patch)
treea3cc9389553df4137c34acd8dd22ca86ee2dea99
parent8d31f114327e77c48c8cdc804e1e399ebeadd27c (diff)
tdf#88555 sw: use safe IsAlive function in Undo code
Now that we have some safe way to check if the formats are still alive, replace 1df637bde32c484b681ecdfebf56fdca03db7fc1 with this. Change-Id: I3d5bd9c16f5cadd90281eff7a8b42d03ccd4c672
-rw-r--r--sw/source/core/undo/unattr.cxx28
-rw-r--r--sw/source/core/undo/unfmco.cxx2
2 files changed, 17 insertions, 13 deletions
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index 058edab78750..8a0d68d15fc9 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -201,21 +201,23 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
{
// search for the Format in the Document; if it does not exist any more,
// the attribute is not restored!
- size_t nPos = SIZE_MAX;
+ bool isAlive(false);
switch ( m_nFormatWhich )
{
case RES_TXTFMTCOLL:
case RES_CONDTXTFMTCOLL:
- nPos = pDoc->GetTextFormatColls()->GetPos( m_pFormat );
+ isAlive = pDoc->GetTextFormatColls()->IsAlive(
+ static_cast<const SwTextFormatColl *>(m_pFormat));
break;
case RES_GRFFMTCOLL:
- nPos = pDoc->GetGrfFormatColls()->GetPos(
- static_cast<const SwGrfFormatColl*>(m_pFormat) );
+ isAlive = pDoc->GetGrfFormatColls()->IsAlive(
+ static_cast<const SwGrfFormatColl*>(m_pFormat));
break;
case RES_CHRFMT:
- nPos = pDoc->GetCharFormats()->GetPos( m_pFormat );
+ isAlive = pDoc->GetCharFormats()->IsAlive(
+ static_cast<const SwCharFormat *>(m_pFormat));
break;
case RES_FRMFMT:
@@ -226,14 +228,14 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
{
m_pFormat =
static_cast<SwTableNode*>(pNd)->GetTable().GetFrameFormat();
- nPos = 0;
+ isAlive = true;
break;
}
else if ( pNd->IsSectionNode() )
{
m_pFormat =
static_cast<SwSectionNode*>(pNd)->GetSection().GetFormat();
- nPos = 0;
+ isAlive = true;
break;
}
else if ( pNd->IsStartNode() && (SwTableBoxStartNode ==
@@ -247,7 +249,7 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
if ( pBox )
{
m_pFormat = pBox->GetFrameFormat();
- nPos = 0;
+ isAlive = true;
break;
}
}
@@ -256,13 +258,15 @@ bool SwUndoFormatAttr::IsFormatInDoc( SwDoc* pDoc )
SAL_FALLTHROUGH;
case RES_DRAWFRMFMT:
case RES_FLYFRMFMT:
- if ( ( pDoc->GetSpzFrameFormats()->find( static_cast<SwFrameFormat*>(m_pFormat) ) != pDoc->GetSpzFrameFormats()->end() )
- || ( pDoc->GetFrameFormats()->find( static_cast<SwFrameFormat*>( m_pFormat ) ) != pDoc->GetFrameFormats()->end() ) )
- nPos = 0;
+ if (pDoc->GetSpzFrameFormats()->IsAlive(static_cast<const SwFrameFormat *>(m_pFormat))
+ || pDoc->GetFrameFormats()->IsAlive(static_cast<const SwFrameFormat *>(m_pFormat)))
+ {
+ isAlive = true;
+ }
break;
}
- if ( nPos == SIZE_MAX )
+ if (!isAlive)
{
// Format does not exist; reset
m_pFormat = nullptr;
diff --git a/sw/source/core/undo/unfmco.cxx b/sw/source/core/undo/unfmco.cxx
index aa55ba045ca0..056ab4080c72 100644
--- a/sw/source/core/undo/unfmco.cxx
+++ b/sw/source/core/undo/unfmco.cxx
@@ -73,7 +73,7 @@ void SwUndoFormatColl::DoSetFormatColl(SwDoc & rDoc, SwPaM & rPaM)
// this array.
// does the format still exist?
- if( SIZE_MAX != rDoc.GetTextFormatColls()->GetPos(static_cast<SwTextFormatColl*>(pFormatColl)) )
+ if (rDoc.GetTextFormatColls()->IsAlive(static_cast<SwTextFormatColl*>(pFormatColl)))
{
rDoc.SetTextFormatColl(rPaM, static_cast<SwTextFormatColl*>(pFormatColl), mbReset,
mbResetListAttrs);