[Libreoffice-commits] core.git: sw/source
Bjoern Michaelsen (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 9 21:28:00 UTC 2021
sw/source/core/inc/frmtool.hxx | 14 ++++++++------
sw/source/core/layout/frmtool.cxx | 27 ++++++++++++++++++++++-----
sw/source/core/layout/laycache.cxx | 5 +----
sw/source/core/layout/tabfrm.cxx | 21 ++++++++++++---------
sw/source/core/layout/wsfrm.cxx | 8 ++++----
5 files changed, 47 insertions(+), 28 deletions(-)
New commits:
commit debfdcfc0b2c07319e4a754decab18a292dc227c
Author: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Sun Jul 4 13:00:03 2021 +0200
Commit: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Fri Jul 9 23:27:26 2021 +0200
remove global bDontCreateObjects bit
Wrapping this in a scope based helper is mostly lipstick on a pig, but
at least one cant forget toggling back this way. Apparently, this flag
was already toggled in recursive calls without checking previous state,
which is likely buggy.
In the long run, this should a/ never be used recursively or better b/
not be a global flag at all.
Change-Id: Id3554d2acb94d565611701c046ca4d8669594cea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118371
Tested-by: Jenkins
Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx
index 1974338f7936..4e328ca32af9 100644
--- a/sw/source/core/inc/frmtool.hxx
+++ b/sw/source/core/inc/frmtool.hxx
@@ -150,9 +150,6 @@ void MakeFrames( SwDoc *pDoc, const SwNodeIndex &rSttIdx,
extern bool bObjsDirect;
-// prevent creation of Flys in InsertCnt_, e.g. for table headlines
-extern bool bDontCreateObjects;
-
// for FlyCnts, see SwFlyAtContentFrame::MakeAll()
extern bool bSetCompletePaintOnInvalidate;
@@ -161,9 +158,14 @@ SwTwips CalcRowRstHeight( SwLayoutFrame *pRow );
tools::Long CalcHeightWithFlys( const SwFrame *pFrame );
namespace sw {
-
-bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 nPageNum);
-
+ bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 nPageNum);
+ class FlyCreationSuppressor
+ {
+ const bool m_wasAlreadySuppressed;
+ public:
+ FlyCreationSuppressor(bool isAlreadySuppressedAllowed = true);
+ ~FlyCreationSuppressor();
+ };
} // namespace sw
SwPageFrame *InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper,
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index c50061bcf68e..59429f55ddf2 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -79,8 +79,25 @@
using namespace ::com::sun::star;
+namespace {
+ // FIXME: would likely better be a member of SwRootFrame instead of a global flag
+ bool isFlyCreationSuppressed = false;
+}
+namespace sw {
+ FlyCreationSuppressor::FlyCreationSuppressor(bool wasAlreadySuppressedAllowed)
+ : m_wasAlreadySuppressed(isFlyCreationSuppressed)
+ {
+ (void)wasAlreadySuppressedAllowed;
+ assert(wasAlreadySuppressedAllowed || !isFlyCreationSuppressed);
+ isFlyCreationSuppressed = true;
+ }
+ FlyCreationSuppressor::~FlyCreationSuppressor()
+ {
+ isFlyCreationSuppressed = m_wasAlreadySuppressed;
+ }
+}
+
bool bObjsDirect = true;
-bool bDontCreateObjects = false;
bool bSetCompletePaintOnInvalidate = false;
sal_uInt8 StackHack::s_nCnt = 0;
@@ -1588,7 +1605,7 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
lcl_SetPos( *pFrame, *pLay );
pPrv = pFrame;
- if ( !pTable->empty() && bObjsDirect && !bDontCreateObjects )
+ if ( !pTable->empty() && bObjsDirect && !isFlyCreationSuppressed )
AppendObjs( pTable, nIndex, pFrame, pPage, pDoc );
}
else if ( pNd->IsTableNode() )
@@ -1893,7 +1910,7 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
assert(false); // actually a fly-section can't be deleted?
continue; // skip it
}
- if ( !pTable->empty() && bObjsDirect && !bDontCreateObjects )
+ if ( !pTable->empty() && bObjsDirect && !isFlyCreationSuppressed )
{
SwFlyFrame* pFly = pLay->FindFlyFrame();
if( pFly )
@@ -1922,7 +1939,7 @@ void InsertCnt_( SwLayoutFrame *pLay, SwDoc *pDoc,
if ( bPages ) // let the Flys connect to each other
{
- if ( !bDontCreateObjects )
+ if ( !isFlyCreationSuppressed )
AppendAllObjs( pTable, pLayout );
bObjsDirect = true;
}
@@ -2110,7 +2127,7 @@ void MakeFrames( SwDoc *pDoc, const SwNodeIndex &rSttIdx,
nEndIdx, pPrv, eMode );
// OD 23.06.2003 #108784# - correction: append objects doesn't
// depend on value of <bAllowMove>
- if( !bDontCreateObjects )
+ if( !isFlyCreationSuppressed )
{
const SwFrameFormats *pTable = pDoc->GetSpzFrameFormats();
if( !pTable->empty() )
diff --git a/sw/source/core/layout/laycache.cxx b/sw/source/core/layout/laycache.cxx
index b9f8b1e96dbd..1e4ae047b5fc 100644
--- a/sw/source/core/layout/laycache.cxx
+++ b/sw/source/core/layout/laycache.cxx
@@ -833,8 +833,7 @@ bool SwLayHelper::CheckInsert( sal_uLong nNodeIndex )
SwFrame *pPrv;
if( nRepeat > 0 )
{
- bDontCreateObjects = true; //frmtool
-
+ sw::FlyCreationSuppressor aSuppressor;
// Insert new headlines:
sal_uInt16 nRowIdx = 0;
SwRowFrame* pHeadline = nullptr;
@@ -849,8 +848,6 @@ bool SwLayHelper::CheckInsert( sal_uLong nNodeIndex )
++nRowIdx;
}
-
- bDontCreateObjects = false;
pPrv = pHeadline;
nRows = nRows + nRepeat;
}
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 384c79615348..c54b24d59e3d 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -1215,14 +1215,15 @@ bool SwTabFrame::Split( const SwTwips nCutPos, bool bTryToSplit, bool bTableRowK
pFoll->InsertBehind( GetUpper(), this );
// Repeat the headlines.
+ auto& rLines = GetTable()->GetTabLines();
for ( nRowCount = 0; nRowCount < nRepeat; ++nRowCount )
{
// Insert new headlines:
- bDontCreateObjects = true; //frmtool
- SwRowFrame* pHeadline = new SwRowFrame(
- *GetTable()->GetTabLines()[ nRowCount ], this );
- pHeadline->SetRepeatedHeadline( true );
- bDontCreateObjects = false;
+ SwRowFrame* pHeadline = new SwRowFrame(*rLines[nRowCount], this);
+ {
+ sw::FlyCreationSuppressor aSuppressor;
+ pHeadline->SetRepeatedHeadline(true);
+ }
pHeadline->InsertBefore( pFoll, nullptr );
SwPageFrame *pPage = pHeadline->FindPageFrame();
@@ -3377,12 +3378,14 @@ void SwTabFrame::UpdateAttr_( const SfxPoolItem *pOld, const SfxPoolItem *pNew,
// insert new headlines
const sal_uInt16 nNewRepeat = GetTable()->GetRowsToRepeat();
+ auto& rLines = GetTable()->GetTabLines();
for ( sal_uInt16 nIdx = 0; nIdx < nNewRepeat; ++nIdx )
{
- bDontCreateObjects = true; //frmtool
- SwRowFrame* pHeadline = new SwRowFrame( *GetTable()->GetTabLines()[ nIdx ], this );
- pHeadline->SetRepeatedHeadline( true );
- bDontCreateObjects = false;
+ SwRowFrame* pHeadline = new SwRowFrame(*rLines[nIdx], this);
+ {
+ sw::FlyCreationSuppressor aSuppressor;
+ pHeadline->SetRepeatedHeadline(true);
+ }
pHeadline->Paste( this, pLowerRow );
}
}
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 9bf5cddc6d2a..53bf49df5346 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -4494,10 +4494,10 @@ static void UnHideRedlines(SwRootFrame & rLayout,
// InsertCnt_ also checks for hidden sections
SwNodeIndex const start(rNodes, i);
SwNodeIndex const end(rNodes, j);
- assert(!bDontCreateObjects);
- bDontCreateObjects = true; // suppress here, to be called once
- ::MakeFrames(rLayout.GetFormat()->GetDoc(), start, end);
- bDontCreateObjects = false;
+ {
+ sw::FlyCreationSuppressor aSuppressor(false);
+ ::MakeFrames(rLayout.GetFormat()->GetDoc(), start, end);
+ }
i = j - 1; // will be incremented again
}
}
More information about the Libreoffice-commits
mailing list