LibreOffice Module sw (master)  1
tabfrm.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <pagefrm.hxx>
21 #include <rootfrm.hxx>
23 #include <viewimp.hxx>
24 #include <fesh.hxx>
25 #include <swtable.hxx>
26 #include <dflyobj.hxx>
27 #include <anchoreddrawobject.hxx>
28 #include <fmtanchr.hxx>
29 #include <viewopt.hxx>
30 #include <hints.hxx>
31 #include <dbg_lay.hxx>
32 #include <ftnidx.hxx>
33 #include <svl/itemiter.hxx>
34 #include <editeng/keepitem.hxx>
35 #include <editeng/ulspitem.hxx>
36 #include <editeng/brushitem.hxx>
37 #include <editeng/boxitem.hxx>
39 #include <fmtlsplt.hxx>
40 #include <fmtrowsplt.hxx>
41 #include <fmtsrnd.hxx>
42 #include <fmtornt.hxx>
43 #include <fmtpdsc.hxx>
44 #include <fmtfsize.hxx>
45 #include <swtblfmt.hxx>
46 #include <tabfrm.hxx>
47 #include <rowfrm.hxx>
48 #include <cellfrm.hxx>
49 #include <flyfrms.hxx>
50 #include <txtfrm.hxx>
51 #include <ftnfrm.hxx>
52 #include <notxtfrm.hxx>
53 #include <htmltbl.hxx>
54 #include <sectfrm.hxx>
55 #include <fmtfollowtextflow.hxx>
56 #include <sortedobjs.hxx>
57 #include <objectformatter.hxx>
58 #include <layouter.hxx>
59 #include <calbck.hxx>
61 #include <docary.hxx>
62 #include <sal/log.hxx>
63 #include <frmatr.hxx>
64 #include <frmtool.hxx>
65 #include <ndtxt.hxx>
66 #include <frameformats.hxx>
67 
68 using namespace ::com::sun::star;
69 
71  : SwLayoutFrame( rTab.GetFrameFormat(), pSib )
72  , SwFlowFrame( static_cast<SwFrame&>(*this) )
73  , m_pTable( &rTab )
74  , m_bComplete(false)
75  , m_bCalcLowers(false)
76  , m_bLowersFormatted(false)
77  , m_bLockBackMove(false)
78  , m_bResizeHTMLTable(false)
79  , m_bONECalcLowers(false)
80  , m_bHasFollowFlowLine(false)
81  , m_bIsRebuildLastLine(false)
82  , m_bRestrictTableGrowth(false)
83  , m_bRemoveFollowFlowLinePending(false)
84  , m_bConsiderObjsForMinCellHeight(true)
85  , m_bObjsDoesFit(true)
86  , m_bInRecalcLowerRow(false)
87  , m_bSplitRowDisabled(false)
88 {
89  mbFixSize = false; //Don't fall for import filter again.
91 
92  //Create the lines and insert them.
93  const SwTableLines &rLines = rTab.GetTabLines();
94  SwFrame *pTmpPrev = nullptr;
95  for ( size_t i = 0; i < rLines.size(); ++i )
96  {
97  SwRowFrame *pNew = new SwRowFrame( *rLines[i], this );
98  if( pNew->Lower() )
99  {
100  pNew->InsertBehind( this, pTmpPrev );
101  pTmpPrev = pNew;
102  }
103  else
104  SwFrame::DestroyFrame(pNew);
105  }
106  OSL_ENSURE( Lower() && Lower()->IsRowFrame(), "SwTabFrame::SwTabFrame: No rows." );
107 }
108 
110  : SwLayoutFrame( rTab.GetFormat(), &rTab )
111  , SwFlowFrame( static_cast<SwFrame&>(*this) )
112  , m_pTable( rTab.GetTable() )
113  , m_bComplete(false)
114  , m_bCalcLowers(false)
115  , m_bLowersFormatted(false)
116  , m_bLockBackMove(false)
117  , m_bResizeHTMLTable(false)
118  , m_bONECalcLowers(false)
119  , m_bHasFollowFlowLine(false)
120  , m_bIsRebuildLastLine(false)
121  , m_bRestrictTableGrowth(false)
122  , m_bRemoveFollowFlowLinePending(false)
123  , m_bConsiderObjsForMinCellHeight(true)
124  , m_bObjsDoesFit(true)
125  , m_bInRecalcLowerRow(false)
126  , m_bSplitRowDisabled(false)
127 {
128  mbFixSize = false; //Don't fall for import filter again.
130 
131  SetFollow( rTab.GetFollow() );
132  rTab.SetFollow( this );
133 }
134 
136 {
137  // There is some terrible code in fetab.cxx, that
138  // caches pointers to SwTabFrames.
139  ::ClearFEShellTabCols(*GetFormat()->GetDoc(), this);
140 
142 }
143 
145 {
146 }
147 
149 {
150  SwTabFrame *pFoll = GetFollow();
151  if ( pFoll->HasFollow() )
152  pFoll->JoinAndDelFollows();
153  pFoll->Cut();
154  SetFollow( pFoll->GetFollow() );
155  SwFrame::DestroyFrame(pFoll);
156 }
157 
159 {
160  OSL_ENSURE( Lower() && Lower()->IsRowFrame(), "No rows." );
161 
162  SwPageFrame *pPage = FindPageFrame();
163  if ( pPage )
164  {
165  SwRowFrame *pRow = static_cast<SwRowFrame*>(Lower());
166  do
167  {
168  pRow->RegistFlys( pPage );
169  pRow = static_cast<SwRowFrame*>(pRow->GetNext());
170  } while ( pRow );
171  }
172 }
173 
174 static void SwInvalidateAll( SwFrame *pFrame, tools::Long nBottom );
175 static void lcl_RecalcRow( SwRowFrame& rRow, tools::Long nBottom );
176 static bool lcl_ArrangeLowers( SwLayoutFrame *pLay, tools::Long lYStart, bool bInva );
177 // #i26945# - add parameter <_bOnlyRowsAndCells> to control
178 // that only row and cell frames are formatted.
179 static bool lcl_InnerCalcLayout( SwFrame *pFrame,
180  tools::Long nBottom,
181  bool _bOnlyRowsAndCells = false );
182 // OD 2004-02-18 #106629# - correct type of 1st parameter
183 // #i26945# - add parameter <_bConsiderObjs> in order to
184 // control, if floating screen objects have to be considered for the minimal
185 // cell height.
186 static SwTwips lcl_CalcMinRowHeight( const SwRowFrame *pRow,
187  const bool _bConsiderObjs );
189 
191 
192 static SwTwips lcl_GetHeightOfRows( const SwFrame* pStart, tools::Long nCount )
193 {
194  if ( !nCount || !pStart)
195  return 0;
196 
197  SwTwips nRet = 0;
198  SwRectFnSet aRectFnSet(pStart);
199  while ( pStart && nCount > 0 )
200  {
201  nRet += aRectFnSet.GetHeight(pStart->getFrameArea());
202  pStart = pStart->GetNext();
203  --nCount;
204  }
205 
206  return nRet;
207 }
208 
209 // Local helper function to insert a new follow flow line
210 static SwRowFrame* lcl_InsertNewFollowFlowLine( SwTabFrame& rTab, const SwFrame& rTmpRow, bool bRowSpanLine )
211 {
212  OSL_ENSURE( rTmpRow.IsRowFrame(), "No row frame to copy for FollowFlowLine" );
213  const SwRowFrame& rRow = static_cast<const SwRowFrame&>(rTmpRow);
214 
215  rTab.SetFollowFlowLine( true );
216  SwRowFrame *pFollowFlowLine = new SwRowFrame(*rRow.GetTabLine(), &rTab, false );
217  pFollowFlowLine->SetRowSpanLine( bRowSpanLine );
218  SwFrame* pFirstRow = rTab.GetFollow()->GetFirstNonHeadlineRow();
219  pFollowFlowLine->InsertBefore( rTab.GetFollow(), pFirstRow );
220  return pFollowFlowLine;
221 }
222 
223 // #i26945# - local helper function to invalidate all lower
224 // objects. By parameter <_bMoveObjsOutOfRange> it can be controlled, if
225 // additionally the objects are moved 'out of range'.
226 static void lcl_InvalidateLowerObjs( SwLayoutFrame& _rLayoutFrame,
227  const bool _bMoveObjsOutOfRange = false,
228  SwPageFrame* _pPageFrame = nullptr )
229 {
230  // determine page frame, if needed
231  if ( !_pPageFrame )
232  {
233  _pPageFrame = _rLayoutFrame.FindPageFrame();
234  OSL_ENSURE( _pPageFrame,
235  "<lcl_InvalidateLowerObjs(..)> - missing page frame -> no move of lower objects out of range" );
236  if ( !_pPageFrame )
237  {
238  return;
239  }
240  }
241 
242  // loop on lower frames
243  SwFrame* pLowerFrame = _rLayoutFrame.Lower();
244  while ( pLowerFrame )
245  {
246  if ( pLowerFrame->IsLayoutFrame() )
247  {
248  ::lcl_InvalidateLowerObjs( *static_cast<SwLayoutFrame*>(pLowerFrame),
249  _bMoveObjsOutOfRange, _pPageFrame );
250  }
251  if ( pLowerFrame->GetDrawObjs() )
252  {
253  for (SwAnchoredObject* pAnchoredObj : *pLowerFrame->GetDrawObjs())
254  {
255  // invalidate position of anchored object
256  pAnchoredObj->SetTmpConsiderWrapInfluence( false );
257  pAnchoredObj->SetConsiderForTextWrap( false );
258  pAnchoredObj->UnlockPosition();
259  pAnchoredObj->InvalidateObjPos();
260 
261  SwFlyFrame *pFly = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
262 
263  // move anchored object 'out of range'
264  if ( _bMoveObjsOutOfRange )
265  {
266  // indicate, that positioning is progress to avoid
267  // modification of the anchored object resp. it's attributes
268  // due to the movement
269  SwObjPositioningInProgress aObjPosInProgress( *pAnchoredObj );
270  pAnchoredObj->SetObjLeft( _pPageFrame->getFrameArea().Right() );
271  // #115759# - reset character rectangle,
272  // top of line and relative position in order to assure,
273  // that anchored object is correctly positioned.
274  pAnchoredObj->ClearCharRectAndTopOfLine();
275  pAnchoredObj->SetCurrRelPos( Point( 0, 0 ) );
276  if ( pAnchoredObj->GetFrameFormat().GetAnchor().GetAnchorId()
277  == RndStdIds::FLY_AS_CHAR )
278  {
279  pAnchoredObj->AnchorFrame()
281  &(pAnchoredObj->GetFrameFormat()) );
282  }
283  if ( pFly != nullptr )
284  {
285  pFly->GetVirtDrawObj()->SetRectsDirty();
286  pFly->GetVirtDrawObj()->SetChanged();
287  }
288  }
289 
290  // If anchored object is a fly frame, invalidate its lower objects
291  if ( pFly != nullptr )
292  {
293  ::lcl_InvalidateLowerObjs( *pFly, _bMoveObjsOutOfRange, _pPageFrame );
294  }
295  }
296  }
297  pLowerFrame = pLowerFrame->GetNext();
298  }
299 }
300 
301 // Local helper function to shrink all lowers of pRow to 0 height
303 {
304  SwCellFrame* pCurrMasterCell = static_cast<SwCellFrame*>(rRow.Lower());
305  SwRectFnSet aRectFnSet(pCurrMasterCell);
306 
307  bool bAllCellsCollapsed = true;
308  while ( pCurrMasterCell )
309  {
310  // NEW TABLES
311  SwCellFrame& rToAdjust = pCurrMasterCell->GetTabBox()->getRowSpan() < 1 ?
312  const_cast<SwCellFrame&>(pCurrMasterCell->FindStartEndOfRowSpanCell( true )) :
313  *pCurrMasterCell;
314 
315  // #i26945#
316  // all lowers should have the correct position
317  lcl_ArrangeLowers( &rToAdjust,
318  aRectFnSet.GetPrtTop(rToAdjust),
319  false );
320  // TODO: Optimize number of frames which are set to 0 height
321  // we have to start with the last lower frame, otherwise
322  // the shrink will not shrink the current cell
323  SwFrame* pTmp = rToAdjust.GetLastLower();
324  bool bAllLowersCollapsed = true;
325 
326  if ( pTmp && pTmp->IsRowFrame() )
327  {
328  SwRowFrame* pTmpRow = static_cast<SwRowFrame*>(pTmp);
329  lcl_ShrinkCellsAndAllContent( *pTmpRow );
330  }
331  else
332  {
333  // TODO: Optimize number of frames which are set to 0 height
334  while ( pTmp )
335  {
336  // the frames have to be shrunk
337  if ( pTmp->IsTabFrame() )
338  {
339  SwRowFrame* pTmpRow = static_cast<SwRowFrame*>(static_cast<SwTabFrame*>(pTmp)->Lower());
340  bool bAllRowsCollapsed = true;
341 
342  while ( pTmpRow )
343  {
344  lcl_ShrinkCellsAndAllContent( *pTmpRow );
345 
346  if (aRectFnSet.GetHeight(pTmpRow->getFrameArea()) > 0)
347  bAllRowsCollapsed = false;
348 
349  pTmpRow = static_cast<SwRowFrame*>(pTmpRow->GetNext());
350  }
351 
352  if (bAllRowsCollapsed)
353  {
354  // All rows of this table have 0 height -> set height of the table itself as well.
356  aRectFnSet.SetHeight(aFrm, 0);
357 
359  aRectFnSet.SetTop(aPrt, 0);
360  aRectFnSet.SetHeight(aPrt, 0);
361  }
362  else
363  bAllLowersCollapsed = false;
364  }
365  else
366  {
367  pTmp->Shrink(aRectFnSet.GetHeight(pTmp->getFrameArea()));
369  aRectFnSet.SetTop(aPrt, 0);
370  aRectFnSet.SetHeight(aPrt, 0);
371 
372  if (aRectFnSet.GetHeight(pTmp->getFrameArea()) > 0)
373  {
374  bAllLowersCollapsed = false;
375  }
376  }
377 
378  pTmp = pTmp->GetPrev();
379  }
380 
381  // all lowers should have the correct position
382  lcl_ArrangeLowers( &rToAdjust,
383  aRectFnSet.GetPrtTop(rToAdjust),
384  false );
385  }
386 
387  if (bAllLowersCollapsed)
388  {
389  // All lower frame of this cell have 0 height -> set height of the cell itself as well.
390  SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*pCurrMasterCell);
391  aRectFnSet.SetHeight(aFrm, 0);
392 
394  aRectFnSet.SetTop(aPrt, 0);
395  aRectFnSet.SetHeight(aPrt, 0);
396  }
397  else
398  bAllCellsCollapsed = false;
399 
400  pCurrMasterCell = static_cast<SwCellFrame*>(pCurrMasterCell->GetNext());
401  }
402 
403  if (bAllCellsCollapsed)
404  {
405  // All cells have 0 height -> set height of row as well.
407  aRectFnSet.SetHeight(aFrm, 0);
408 
410  aRectFnSet.SetTop(aPrt, 0);
411  aRectFnSet.SetHeight(aPrt, 0);
412  }
413 }
414 
415 // Local helper function to move the content from rSourceLine to rDestLine
416 // The content is inserted behind the last content in the corresponding
417 // cell in rDestLine.
418 static void lcl_MoveRowContent( SwRowFrame& rSourceLine, SwRowFrame& rDestLine )
419 {
420  SwCellFrame* pCurrDestCell = static_cast<SwCellFrame*>(rDestLine.Lower());
421  SwCellFrame* pCurrSourceCell = static_cast<SwCellFrame*>(rSourceLine.Lower());
422 
423  // Move content of follow cells into master cells
424  while ( pCurrSourceCell )
425  {
426  if ( pCurrSourceCell->Lower() && pCurrSourceCell->Lower()->IsRowFrame() )
427  {
428  SwRowFrame* pTmpSourceRow = static_cast<SwRowFrame*>(pCurrSourceCell->Lower());
429  while ( pTmpSourceRow )
430  {
431  // #125926# Attention! It is possible,
432  // that pTmpSourceRow->IsFollowFlowRow() but pTmpDestRow
433  // cannot be found. In this case, we have to move the complete
434  // row.
435  SwRowFrame* pTmpDestRow = static_cast<SwRowFrame*>(pCurrDestCell->Lower());
436 
437  if ( pTmpSourceRow->IsFollowFlowRow() && pTmpDestRow )
438  {
439  // move content from follow flow row to pTmpDestRow:
440  while ( pTmpDestRow->GetNext() )
441  pTmpDestRow = static_cast<SwRowFrame*>(pTmpDestRow->GetNext());
442 
443  assert(pTmpDestRow->GetFollowRow() == pTmpSourceRow);
444 
445  lcl_MoveRowContent( *pTmpSourceRow, *pTmpDestRow );
446  pTmpDestRow->SetFollowRow( pTmpSourceRow->GetFollowRow() );
447  pTmpSourceRow->RemoveFromLayout();
448  SwFrame::DestroyFrame(pTmpSourceRow);
449  }
450  else
451  {
452  // move complete row:
453  pTmpSourceRow->RemoveFromLayout();
454  pTmpSourceRow->InsertBefore( pCurrDestCell, nullptr );
455  }
456 
457  pTmpSourceRow = static_cast<SwRowFrame*>(pCurrSourceCell->Lower());
458  }
459  }
460  else
461  {
462  SwFrame *pTmp = ::SaveContent( pCurrSourceCell );
463  if ( pTmp )
464  {
465  // NEW TABLES
466  SwCellFrame* pDestCell = pCurrDestCell;
467  if ( pDestCell->GetTabBox()->getRowSpan() < 1 )
468  pDestCell = & const_cast<SwCellFrame&>(pDestCell->FindStartEndOfRowSpanCell( true ));
469 
470  // Find last content
471  SwFrame* pFrame = pDestCell->GetLastLower();
472  ::RestoreContent( pTmp, pDestCell, pFrame );
473  }
474  }
475  pCurrDestCell = static_cast<SwCellFrame*>(pCurrDestCell->GetNext());
476  pCurrSourceCell = static_cast<SwCellFrame*>(pCurrSourceCell->GetNext());
477  }
478 }
479 
480 // Local helper function to move all footnotes in rRowFrame from
481 // the footnote boss of rSource to the footnote boss of rDest.
482 static void lcl_MoveFootnotes( SwTabFrame& rSource, SwTabFrame& rDest, SwLayoutFrame& rRowFrame )
483 {
484  if ( !rSource.GetFormat()->GetDoc()->GetFootnoteIdxs().empty() )
485  {
486  SwFootnoteBossFrame* pOldBoss = rSource.FindFootnoteBossFrame( true );
487  SwFootnoteBossFrame* pNewBoss = rDest.FindFootnoteBossFrame( true );
488  rRowFrame.MoveLowerFootnotes( nullptr, pOldBoss, pNewBoss, true );
489  }
490 }
491 
492 // Local helper function to handle nested table cells before the split process
493 static void lcl_PreprocessRowsInCells( SwTabFrame& rTab, SwRowFrame& rLastLine,
494  SwRowFrame& rFollowFlowLine, SwTwips nRemain )
495 {
496  SwCellFrame* pCurrLastLineCell = static_cast<SwCellFrame*>(rLastLine.Lower());
497  SwCellFrame* pCurrFollowFlowLineCell = static_cast<SwCellFrame*>(rFollowFlowLine.Lower());
498 
499  SwRectFnSet aRectFnSet(pCurrLastLineCell);
500 
501  // Move content of follow cells into master cells
502  while ( pCurrLastLineCell )
503  {
504  if ( pCurrLastLineCell->Lower() && pCurrLastLineCell->Lower()->IsRowFrame() )
505  {
506  SwTwips nTmpCut = nRemain;
507  SwRowFrame* pTmpLastLineRow = static_cast<SwRowFrame*>(pCurrLastLineCell->Lower());
508 
509  // #i26945#
510  SwTwips nCurrentHeight =
511  lcl_CalcMinRowHeight( pTmpLastLineRow,
513  while ( pTmpLastLineRow->GetNext() && nTmpCut > nCurrentHeight )
514  {
515  nTmpCut -= nCurrentHeight;
516  pTmpLastLineRow = static_cast<SwRowFrame*>(pTmpLastLineRow->GetNext());
517  // #i26945#
518  nCurrentHeight =
519  lcl_CalcMinRowHeight( pTmpLastLineRow,
521  }
522 
523  // pTmpLastLineRow does not fit to the line or it is the last line
524  // Check if we can move pTmpLastLineRow to the follow table,
525  // or if we have to split the line:
526  bool bTableLayoutTooComplex = false;
527  tools::Long nMinHeight = 0;
528 
529  // We have to take into account:
530  // 1. The fixed height of the row
531  // 2. The borders of the cells inside the row
532  // 3. The minimum height of the row
533  if ( pTmpLastLineRow->HasFixSize() )
534  nMinHeight = aRectFnSet.GetHeight(pTmpLastLineRow->getFrameArea());
535  else
536  {
537  {
538  const SwFormatFrameSize &rSz = pTmpLastLineRow->GetFormat()->GetFrameSize();
540  nMinHeight = rSz.GetHeight() - lcl_calcHeightOfRowBeforeThisFrame(*pTmpLastLineRow);
541  }
542 
543  SwFrame* pCell = pTmpLastLineRow->Lower();
544  while ( pCell )
545  {
546  if ( static_cast<SwCellFrame*>(pCell)->Lower() &&
547  static_cast<SwCellFrame*>(pCell)->Lower()->IsRowFrame() )
548  {
549  bTableLayoutTooComplex = true;
550  break;
551  }
552 
553  SwBorderAttrAccess aAccess( SwFrame::GetCache(), pCell );
554  const SwBorderAttrs &rAttrs = *aAccess.Get();
555  nMinHeight = std::max( nMinHeight, lcl_CalcTopAndBottomMargin( *static_cast<SwLayoutFrame*>(pCell), rAttrs ) );
556  pCell = pCell->GetNext();
557  }
558  }
559 
560  // 1. Case:
561  // The line completely fits into the master table.
562  // Nevertheless, we build a follow (otherwise painting problems
563  // with empty cell).
564 
565  // 2. Case:
566  // The line has to be split, the minimum height still fits into
567  // the master table, and the table structure is not too complex.
568  if ( nTmpCut > nCurrentHeight ||
569  ( pTmpLastLineRow->IsRowSplitAllowed() &&
570  !bTableLayoutTooComplex && nMinHeight < nTmpCut ) )
571  {
572  // The line has to be split:
573  SwRowFrame* pNewRow = new SwRowFrame( *pTmpLastLineRow->GetTabLine(), &rTab, false );
574  pNewRow->SetFollowFlowRow( true );
575  pNewRow->SetFollowRow( pTmpLastLineRow->GetFollowRow() );
576  pTmpLastLineRow->SetFollowRow( pNewRow );
577  pNewRow->InsertBehind( pCurrFollowFlowLineCell, nullptr );
578  pTmpLastLineRow = static_cast<SwRowFrame*>(pTmpLastLineRow->GetNext());
579  }
580 
581  // The following lines have to be moved:
582  while ( pTmpLastLineRow )
583  {
584  SwRowFrame* pTmp = static_cast<SwRowFrame*>(pTmpLastLineRow->GetNext());
585  lcl_MoveFootnotes( rTab, *rTab.GetFollow(), *pTmpLastLineRow );
586  pTmpLastLineRow->RemoveFromLayout();
587  pTmpLastLineRow->InsertBefore( pCurrFollowFlowLineCell, nullptr );
588  pTmpLastLineRow->Shrink( aRectFnSet.GetHeight(pTmpLastLineRow->getFrameArea()) );
589  pCurrFollowFlowLineCell->Grow( aRectFnSet.GetHeight(pTmpLastLineRow->getFrameArea()) );
590  pTmpLastLineRow = pTmp;
591  }
592  }
593 
594  pCurrLastLineCell = static_cast<SwCellFrame*>(pCurrLastLineCell->GetNext());
595  pCurrFollowFlowLineCell = static_cast<SwCellFrame*>(pCurrFollowFlowLineCell->GetNext());
596  }
597 }
598 
599 // Local helper function to handle nested table cells after the split process
600 static void lcl_PostprocessRowsInCells( SwTabFrame& rTab, SwRowFrame& rLastLine )
601 {
602  SwCellFrame* pCurrMasterCell = static_cast<SwCellFrame*>(rLastLine.Lower());
603  while ( pCurrMasterCell )
604  {
605  if ( pCurrMasterCell->Lower() &&
606  pCurrMasterCell->Lower()->IsRowFrame() )
607  {
608  SwRowFrame* pRowFrame = static_cast<SwRowFrame*>(pCurrMasterCell->GetLastLower());
609 
610  if ( nullptr != pRowFrame->GetPrev() && !pRowFrame->ContainsContent() )
611  {
612  OSL_ENSURE( pRowFrame->GetFollowRow(), "Deleting row frame without follow" );
613 
614  // The footnotes have to be moved:
615  lcl_MoveFootnotes( rTab, *rTab.GetFollow(), *pRowFrame );
616  pRowFrame->Cut();
617  SwRowFrame* pFollowRow = pRowFrame->GetFollowRow();
618  pRowFrame->Paste( pFollowRow->GetUpper(), pFollowRow );
619  pRowFrame->SetFollowRow( pFollowRow->GetFollowRow() );
620  lcl_MoveRowContent( *pFollowRow, *pRowFrame );
621  pFollowRow->Cut();
622  SwFrame::DestroyFrame(pFollowRow);
623  ::SwInvalidateAll( pCurrMasterCell, LONG_MAX );
624  }
625  }
626 
627  pCurrMasterCell = static_cast<SwCellFrame*>(pCurrMasterCell->GetNext());
628  }
629 }
630 
631 // Local helper function to re-calculate the split line.
632 inline void TableSplitRecalcLock( SwFlowFrame *pTab ) { pTab->LockJoin(); }
633 inline void TableSplitRecalcUnlock( SwFlowFrame *pTab ) { pTab->UnlockJoin(); }
634 
635 static bool lcl_RecalcSplitLine( SwRowFrame& rLastLine, SwRowFrame& rFollowLine,
636  SwTwips nRemainingSpaceForLastRow, SwTwips nAlreadyFree )
637 {
638  bool bRet = true;
639 
640  vcl::RenderContext* pRenderContext = rLastLine.getRootFrame()->GetCurrShell()->GetOut();
641  SwTabFrame& rTab = static_cast<SwTabFrame&>(*rLastLine.GetUpper());
642  SwRectFnSet aRectFnSet(rTab.GetUpper());
643  SwTwips nCurLastLineHeight = aRectFnSet.GetHeight(rLastLine.getFrameArea());
644 
645  // If there are nested cells in rLastLine, the recalculation of the last
646  // line needs some preprocessing.
647  lcl_PreprocessRowsInCells( rTab, rLastLine, rFollowLine, nRemainingSpaceForLastRow );
648 
649  // Here the recalculation process starts:
650  rTab.SetRebuildLastLine( true );
651  // #i26945#
652  rTab.SetDoesObjsFit( true );
653 
654  // #i26945# - invalidate and move floating screen
655  // objects 'out of range'
656  ::lcl_InvalidateLowerObjs( rLastLine, true );
657 
658  // manipulate row and cell sizes
659 
660  // #i26945# - Do *not* consider floating screen objects
661  // for the minimal cell height.
662  rTab.SetConsiderObjsForMinCellHeight( false );
663  ::lcl_ShrinkCellsAndAllContent( rLastLine );
664  rTab.SetConsiderObjsForMinCellHeight( true );
665 
666  // invalidate last line
667  ::SwInvalidateAll( &rLastLine, LONG_MAX );
668 
669  // Shrink the table to account for the shrunk last row, as well as lower rows
670  // that had been moved to follow table in SwTabFrame::Split.
671  // It will grow later when last line will recalc its height.
672  rTab.Shrink(nAlreadyFree + nCurLastLineHeight - nRemainingSpaceForLastRow + 1);
673 
674  // Lock this tab frame and its follow
675  bool bUnlockMaster = false;
676  SwFlowFrame * pFollow = nullptr;
677  SwTabFrame* pMaster = rTab.IsFollow() ? rTab.FindMaster() : nullptr;
678  if ( pMaster && !pMaster->IsJoinLocked() )
679  {
680  bUnlockMaster = true;
681  ::TableSplitRecalcLock( pMaster );
682  }
683  if ( !rTab.GetFollow()->IsJoinLocked() )
684  {
685  pFollow = rTab.GetFollow();
686  ::TableSplitRecalcLock( pFollow );
687  }
688 
689  bool bInSplit = rLastLine.IsInSplit();
690  rLastLine.SetInSplit();
691 
692  // Do the recalculation
693  lcl_RecalcRow( rLastLine, LONG_MAX );
694  // #115759# - force a format of the last line in order to
695  // get the correct height.
696  rLastLine.InvalidateSize();
697  rLastLine.Calc(pRenderContext);
698 
699  rLastLine.SetInSplit(bInSplit);
700 
701  // Unlock this tab frame and its follow
702  if ( pFollow )
703  ::TableSplitRecalcUnlock( pFollow );
704  if ( bUnlockMaster )
705  ::TableSplitRecalcUnlock( pMaster );
706 
707  // If there are nested cells in rLastLine, the recalculation of the last
708  // line needs some postprocessing.
709  lcl_PostprocessRowsInCells( rTab, rLastLine );
710 
711  // Do a couple of checks on the current situation.
712 
713  // If we are not happy with the current situation we return false.
714  // This will start a new try to split the table, this time we do not
715  // try to split the table rows.
716 
717  // 1. Check if table fits to its upper.
718  // #i26945# - include check, if objects fit
719  const SwTwips nDistanceToUpperPrtBottom =
720  aRectFnSet.BottomDist(rTab.getFrameArea(), aRectFnSet.GetPrtBottom(*rTab.GetUpper()));
721  // tdf#125685 ignore footnotes that are anchored in follow-table of this
722  // table - if split is successful they move to the next page/column anyway
723  assert(rTab.GetFollow() == rFollowLine.GetUpper());
724  SwTwips nFollowFootnotes(0);
725  // actually there should always be a boss frame, except if "this" isn't
726  // connected to a page yet; not sure if that can happen
727  if (SwFootnoteBossFrame const*const pBoss = rTab.FindFootnoteBossFrame())
728  {
729  if (SwFootnoteContFrame const*const pCont = pBoss->FindFootnoteCont())
730  {
731  for (SwFootnoteFrame const* pFootnote = static_cast<SwFootnoteFrame const*>(pCont->Lower());
732  pFootnote != nullptr;
733  pFootnote = static_cast<SwFootnoteFrame const*>(pFootnote->GetNext()))
734  {
735  SwContentFrame const*const pAnchor = pFootnote->GetRef();
736  SwTabFrame const* pTab = pAnchor->FindTabFrame();
737  if (pTab)
738  {
739  while (pTab->GetUpper()->IsInTab())
740  {
741  pTab = pTab->GetUpper()->FindTabFrame();
742  }
743  // TODO currently do this only for top-level tables?
744  // otherwise would need to check rTab's follow and any upper table's follow?
745  if (pTab == rTab.GetFollow())
746  {
747  nFollowFootnotes += aRectFnSet.GetHeight(pFootnote->getFrameArea());
748  }
749  }
750  }
751  }
752  }
753  if (nDistanceToUpperPrtBottom + nFollowFootnotes < 0 || !rTab.DoesObjsFit())
754  bRet = false;
755 
756  // 2. Check if each cell in the last line has at least one content frame.
757 
758  // Note: a FollowFlowRow may contains empty cells!
759  if ( bRet )
760  {
761  if ( !rLastLine.IsInFollowFlowRow() )
762  {
763  SwCellFrame* pCurrMasterCell = static_cast<SwCellFrame*>(rLastLine.Lower());
764  while ( pCurrMasterCell )
765  {
766  if ( !pCurrMasterCell->ContainsContent() && pCurrMasterCell->GetTabBox()->getRowSpan() >= 1 )
767  {
768  bRet = false;
769  break;
770  }
771  pCurrMasterCell = static_cast<SwCellFrame*>(pCurrMasterCell->GetNext());
772  }
773  }
774  }
775 
776  // 3. Check if last line does not contain any content:
777  if ( bRet )
778  {
779  if ( !rLastLine.ContainsContent() )
780  {
781  bRet = false;
782  }
783  }
784 
785  // 4. Check if follow flow line does not contain content:
786  if ( bRet )
787  {
788  if ( !rFollowLine.IsRowSpanLine() && !rFollowLine.ContainsContent() )
789  {
790  bRet = false;
791  }
792  }
793 
794  if ( bRet )
795  {
796  // Everything looks fine. Splitting seems to be successful. We invalidate
797  // rFollowLine to force a new formatting.
798  ::SwInvalidateAll( &rFollowLine, LONG_MAX );
799  }
800  else
801  {
802  // Splitting the table row gave us an unexpected result.
803  // Everything has to be prepared for a second try to split
804  // the table, this time without splitting the row.
805  ::SwInvalidateAll( &rLastLine, LONG_MAX );
806  }
807 
808  rTab.SetRebuildLastLine( false );
809  // #i26945#
810  rTab.SetDoesObjsFit( true );
811 
812  return bRet;
813 }
814 
815 // Sets the correct height for all spanned cells
816 static void lcl_AdjustRowSpanCells( SwRowFrame* pRow )
817 {
818  SwRectFnSet aRectFnSet(pRow);
819  SwCellFrame* pCellFrame = static_cast<SwCellFrame*>(pRow->GetLower());
820  while ( pCellFrame )
821  {
822  const tools::Long nLayoutRowSpan = pCellFrame->GetLayoutRowSpan();
823  if ( nLayoutRowSpan > 1 )
824  {
825  // calculate height of cell:
826  const tools::Long nNewCellHeight = lcl_GetHeightOfRows( pRow, nLayoutRowSpan );
827  const tools::Long nDiff = nNewCellHeight - aRectFnSet.GetHeight(pCellFrame->getFrameArea());
828 
829  if ( nDiff )
830  {
832  aRectFnSet.AddBottom(aFrm, nDiff);
833  }
834  }
835 
836  pCellFrame = static_cast<SwCellFrame*>(pCellFrame->GetNext());
837  }
838 }
839 
840 // Returns the maximum layout row span of the row
841 // Looking for the next row that contains no covered cells:
843 {
844  tools::Long nRet = 1;
845 
846  const SwRowFrame* pCurrentRowFrame = static_cast<const SwRowFrame*>(rRow.GetNext());
847  bool bNextRow = false;
848 
849  while ( pCurrentRowFrame )
850  {
851  // if there is any covered cell, we proceed to the next row frame
852  const SwCellFrame* pLower = static_cast<const SwCellFrame*>( pCurrentRowFrame->Lower());
853  while ( pLower )
854  {
855  if ( pLower->GetTabBox()->getRowSpan() < 0 )
856  {
857  ++nRet;
858  bNextRow = true;
859  break;
860  }
861  pLower = static_cast<const SwCellFrame*>(pLower->GetNext());
862  }
863  pCurrentRowFrame = bNextRow ?
864  static_cast<const SwRowFrame*>(pCurrentRowFrame->GetNext() ) :
865  nullptr;
866  }
867 
868  return nRet;
869 }
870 
871 // Function to remove the FollowFlowLine of rTab.
872 // The content of the FollowFlowLine is moved to the associated line in the
873 // master table.
875 {
876  // find FollowFlowLine
877  SwTabFrame *pFoll = GetFollow();
878  SwRowFrame* pFollowFlowLine = pFoll ? pFoll->GetFirstNonHeadlineRow() : nullptr;
879 
880  // find last row in master
881  SwFrame* pLastLine = GetLastLower();
882 
883  OSL_ENSURE( HasFollowFlowLine() &&
884  pFollowFlowLine &&
885  pLastLine, "There should be a flowline in the follow" );
886 
887  // #140081# Make code robust.
888  if ( !pFollowFlowLine || !pLastLine )
889  return true;
890  if (pFollowFlowLine->IsDeleteForbidden())
891  {
892  SAL_WARN("sw.layout", "Cannot remove in-use Follow Flow Line");
893  return false;
894  }
895 
896  // We have to reset the flag here, because lcl_MoveRowContent
897  // calls a GrowFrame(), which has a different behavior if
898  // this flag is set.
899  SetFollowFlowLine( false );
900 
901  // Move content
902  lcl_MoveRowContent( *pFollowFlowLine, *static_cast<SwRowFrame*>(pLastLine) );
903 
904  // NEW TABLES
905  // If a row span follow flow line is removed, we want to move the whole span
906  // to the master:
907  tools::Long nRowsToMove = lcl_GetMaximumLayoutRowSpan( *pFollowFlowLine );
908 
909  if ( nRowsToMove > 1 )
910  {
911  SwRectFnSet aRectFnSet(this);
912  SwFrame* pRow = pFollowFlowLine->GetNext();
913  SwFrame* pInsertBehind = GetLastLower();
914  SwTwips nGrow = 0;
915 
916  while ( pRow && nRowsToMove-- > 1 )
917  {
918  SwFrame* pNxt = pRow->GetNext();
919  nGrow += aRectFnSet.GetHeight(pRow->getFrameArea());
920 
921  // The footnotes have to be moved:
922  lcl_MoveFootnotes( *GetFollow(), *this, static_cast<SwRowFrame&>(*pRow) );
923 
924  pRow->RemoveFromLayout();
925  pRow->InsertBehind( this, pInsertBehind );
926  pRow->InvalidateAll_();
927  pRow->CheckDirChange();
928  pInsertBehind = pRow;
929  pRow = pNxt;
930  }
931 
932  SwFrame* pFirstRow = Lower();
933  while ( pFirstRow )
934  {
935  lcl_AdjustRowSpanCells( static_cast<SwRowFrame*>(pFirstRow) );
936  pFirstRow = pFirstRow->GetNext();
937  }
938 
939  Grow( nGrow );
940  GetFollow()->Shrink( nGrow );
941  }
942 
943  bool bJoin = !pFollowFlowLine->GetNext();
944  pFollowFlowLine->Cut();
945  SwFrame::DestroyFrame(pFollowFlowLine);
946 
947  return bJoin;
948 }
949 
950 // #i26945# - Floating screen objects are no longer searched.
951 static bool lcl_FindSectionsInRow( const SwRowFrame& rRow )
952 {
953  bool bRet = false;
954  const SwCellFrame* pLower = static_cast<const SwCellFrame*>(rRow.Lower());
955  while ( pLower )
956  {
957  if ( pLower->IsVertical() != rRow.IsVertical() )
958  return true;
959 
960  const SwFrame* pTmpFrame = pLower->Lower();
961  while ( pTmpFrame )
962  {
963  if ( pTmpFrame->IsRowFrame() )
964  {
965  bRet = lcl_FindSectionsInRow( *static_cast<const SwRowFrame*>(pTmpFrame) );
966  }
967  else
968  {
969  // #i26945# - search only for sections
970  if (pTmpFrame->IsSctFrame())
971  {
972  bRet = true;
973 
974  if (!rRow.IsInSct())
975  {
976  // This row is not in a section.
977  if (const SwFrame* pSectionLower = pTmpFrame->GetLower())
978  {
979  if (!pSectionLower->IsColumnFrame())
980  {
981  // Section has a single column only, try to
982  // split that.
983  bRet = false;
984 
985  for (const SwFrame* pFrame = pSectionLower; pFrame; pFrame = pFrame->GetNext())
986  {
987  if (pFrame->IsTabFrame())
988  {
989  // Section contains a table, no split in that case.
990  bRet = true;
991  break;
992  }
993  }
994  }
995  }
996  }
997  }
998  }
999 
1000  if ( bRet )
1001  return true;
1002  pTmpFrame = pTmpFrame->GetNext();
1003  }
1004 
1005  pLower = static_cast<const SwCellFrame*>(pLower->GetNext());
1006  }
1007  return bRet;
1008 }
1009 
1010 bool SwTabFrame::Split( const SwTwips nCutPos, bool bTryToSplit, bool bTableRowKeep )
1011 {
1012  bool bRet = true;
1013 
1014  SwRectFnSet aRectFnSet(this);
1015 
1016  // #i26745# - format row and cell frames of table
1017  {
1018  Lower()->InvalidatePos_();
1019  // #i43913# - correction
1020  // call method <lcl_InnerCalcLayout> with first lower.
1021  lcl_InnerCalcLayout( Lower(), LONG_MAX, true );
1022  }
1023 
1024  //In order to be able to compare the positions of the cells with CutPos,
1025  //they have to be calculated consecutively starting from the table.
1026  //They can definitely be invalid because of position changes of the table.
1027  SwRowFrame *pRow = static_cast<SwRowFrame*>(Lower());
1028  if( !pRow )
1029  return bRet;
1030 
1031  const sal_uInt16 nRepeat = GetTable()->GetRowsToRepeat();
1032  sal_uInt16 nRowCount = 0; // pRow currently points to the first row
1033 
1034  SwTwips nRemainingSpaceForLastRow =
1035  aRectFnSet.YDiff(nCutPos, aRectFnSet.GetTop(getFrameArea()));
1036  nRemainingSpaceForLastRow -= aRectFnSet.GetTopMargin(*this);
1037 
1038  // Make pRow point to the line that does not fit anymore:
1039  while( pRow->GetNext() &&
1040  nRemainingSpaceForLastRow >= ( aRectFnSet.GetHeight(pRow->getFrameArea()) +
1041  (IsCollapsingBorders() ?
1042  pRow->GetBottomLineSize() :
1043  0 ) ) )
1044  {
1045  if( bTryToSplit || !pRow->IsRowSpanLine() ||
1046  0 != aRectFnSet.GetHeight(pRow->getFrameArea()) )
1047  ++nRowCount;
1048  nRemainingSpaceForLastRow -= aRectFnSet.GetHeight(pRow->getFrameArea());
1049  pRow = static_cast<SwRowFrame*>(pRow->GetNext());
1050  }
1051 
1052  // bSplitRowAllowed: Row may be split according to its attributes.
1053  // bTryToSplit: Row will never be split if bTryToSplit = false.
1054  // This can either be passed as a parameter, indicating
1055  // that we are currently doing the second try to split the
1056  // table, or it will be set to false under certain
1057  // conditions that are not suitable for splitting
1058  // the row.
1059  bool bSplitRowAllowed = !IsSplitRowDisabled();
1060  if ( bSplitRowAllowed && !pRow->IsRowSplitAllowed() )
1061  {
1062  // A row larger than the entire page ought to be allowed to split regardless of setting,
1063  // otherwise it has hidden content and that makes no sense
1064  if ( pRow->getFrameArea().Height() > FindPageFrame()->getFramePrintArea().Height() )
1065  pRow->SetForceRowSplitAllowed( true );
1066  else
1067  bSplitRowAllowed = false;
1068  }
1069  // #i29438#
1070  // #i26945# - Floating screen objects no longer forbid
1071  // a splitting of the table row.
1072  // Special DoNotSplit case 1:
1073  // Search for sections inside pRow:
1074  if ( lcl_FindSectionsInRow( *pRow ) )
1075  {
1076  bTryToSplit = false;
1077  }
1078 
1079  // #i29771#
1080  // To avoid loops, we do some checks before actually trying to split
1081  // the row. Maybe we should keep the next row in this table.
1082  // Note: This is only done if we are at the beginning of our upper
1083  bool bKeepNextRow = false;
1084  if ( nRowCount < nRepeat )
1085  {
1086  // First case: One of the repeated headline does not fit to the page anymore.
1087  // tdf#88496 Disable repeated headline (like for #i44910#) to avoid loops and
1088  // to fix interoperability problems (very long tables only with headline)
1089  OSL_ENSURE( !GetIndPrev(), "Table is supposed to be at beginning" );
1091  return false;
1092  }
1093  else if ( !GetIndPrev() && nRepeat == nRowCount )
1094  {
1095  // Second case: The first non-headline row does not fit to the page.
1096  // If it is not allowed to be split, or it contains a sub-row that
1097  // is not allowed to be split, we keep the row in this table:
1098  if ( bTryToSplit && bSplitRowAllowed )
1099  {
1100  // Check if there are (first) rows inside this row,
1101  // which are not allowed to be split.
1102  SwCellFrame* pLowerCell = static_cast<SwCellFrame*>(pRow->Lower());
1103  while ( pLowerCell )
1104  {
1105  if ( pLowerCell->Lower() && pLowerCell->Lower()->IsRowFrame() )
1106  {
1107  const SwRowFrame* pLowerRow = static_cast<SwRowFrame*>(pLowerCell->Lower());
1108  if ( !pLowerRow->IsRowSplitAllowed() &&
1109  aRectFnSet.GetHeight(pLowerRow->getFrameArea()) > nRemainingSpaceForLastRow )
1110  {
1111  bKeepNextRow = true;
1112  break;
1113  }
1114  }
1115  pLowerCell = static_cast<SwCellFrame*>(pLowerCell->GetNext());
1116  }
1117  }
1118  else
1119  bKeepNextRow = true;
1120  }
1121 
1122  // Better keep the next row in this table:
1123  if ( bKeepNextRow )
1124  {
1125  pRow = GetFirstNonHeadlineRow();
1126  if ( pRow && pRow->IsRowSpanLine() && 0 == aRectFnSet.GetHeight(pRow->getFrameArea()) )
1127  pRow = static_cast<SwRowFrame*>(pRow->GetNext());
1128  if ( pRow )
1129  {
1130  pRow = static_cast<SwRowFrame*>(pRow->GetNext());
1131  ++nRowCount;
1132  }
1133  }
1134 
1135  // No more row to split or to move to follow table:
1136  if ( !pRow )
1137  return bRet;
1138 
1139  // We try to split the row if
1140  // - the attributes of the row are set accordingly and
1141  // - we are allowed to do so
1142  // - it should not be kept with the next row
1143  bSplitRowAllowed = bSplitRowAllowed && bTryToSplit &&
1144  ( !bTableRowKeep ||
1145  !pRow->ShouldRowKeepWithNext() );
1146 
1147  // Adjust pRow according to the keep-with-next attribute:
1148  if ( !bSplitRowAllowed && bTableRowKeep )
1149  {
1150  SwRowFrame* pTmpRow = static_cast<SwRowFrame*>(pRow->GetPrev());
1151  SwRowFrame* pOldRow = pRow;
1152  while ( pTmpRow && pTmpRow->ShouldRowKeepWithNext() &&
1153  nRowCount > nRepeat )
1154  {
1155  pRow = pTmpRow;
1156  --nRowCount;
1157  pTmpRow = static_cast<SwRowFrame*>(pTmpRow->GetPrev());
1158  }
1159 
1160  // loop prevention
1161  if ( nRowCount == nRepeat && !GetIndPrev())
1162  {
1163  pRow = pOldRow;
1164  }
1165  }
1166 
1167  // If we do not intend to split pRow, we check if we are
1168  // allowed to move pRow to a follow. Otherwise we return
1169  // false, indicating an error
1170  if ( !bSplitRowAllowed )
1171  {
1172  SwRowFrame* pFirstNonHeadlineRow = GetFirstNonHeadlineRow();
1173  if ( pRow == pFirstNonHeadlineRow )
1174  return false;
1175 
1176  // #i91764#
1177  // Ignore row span lines
1178  SwRowFrame* pTmpRow = pFirstNonHeadlineRow;
1179  while ( pTmpRow && pTmpRow->IsRowSpanLine() )
1180  {
1181  pTmpRow = static_cast<SwRowFrame*>(pTmpRow->GetNext());
1182  }
1183  if ( !pTmpRow || pRow == pTmpRow )
1184  {
1185  return false;
1186  }
1187  }
1188 
1189  // Build follow table if not already done:
1190  bool bNewFollow;
1191  SwTabFrame *pFoll;
1192  if ( GetFollow() )
1193  {
1194  pFoll = GetFollow();
1195  bNewFollow = false;
1196  }
1197  else
1198  {
1199  bNewFollow = true;
1200  pFoll = new SwTabFrame( *this );
1201 
1202  // We give the follow table an initial width.
1203  {
1205  aRectFnSet.AddWidth(aFrm, aRectFnSet.GetWidth(getFrameArea()));
1206  aRectFnSet.SetLeft(aFrm, aRectFnSet.GetLeft(getFrameArea()));
1207  }
1208 
1209  {
1211  aRectFnSet.AddWidth(aPrt, aRectFnSet.GetWidth(getFramePrintArea()));
1212  }
1213 
1214  // Insert the new follow table
1215  pFoll->InsertBehind( GetUpper(), this );
1216 
1217  // Repeat the headlines.
1218  for ( nRowCount = 0; nRowCount < nRepeat; ++nRowCount )
1219  {
1220  // Insert new headlines:
1221  bDontCreateObjects = true; //frmtool
1222  SwRowFrame* pHeadline = new SwRowFrame(
1223  *GetTable()->GetTabLines()[ nRowCount ], this );
1224  pHeadline->SetRepeatedHeadline( true );
1225  bDontCreateObjects = false;
1226  pHeadline->InsertBefore( pFoll, nullptr );
1227 
1228  SwPageFrame *pPage = pHeadline->FindPageFrame();
1229  const SwFrameFormats *pTable = GetFormat()->GetDoc()->GetSpzFrameFormats();
1230  if( !pTable->empty() )
1231  {
1232  sal_uLong nIndex;
1233  SwContentFrame* pFrame = pHeadline->ContainsContent();
1234  while( pFrame )
1235  {
1236  // sw_redlinehide: the implementation of AppendObjs
1237  // takes care of iterating merged SwTextFrame
1238  nIndex = pFrame->IsTextFrame()
1239  ? static_cast<SwTextFrame*>(pFrame)->GetTextNodeFirst()->GetIndex()
1240  : static_cast<SwNoTextFrame*>(pFrame)->GetNode()->GetIndex();
1241  AppendObjs( pTable, nIndex, pFrame, pPage, GetFormat()->GetDoc());
1242  pFrame = pFrame->GetNextContentFrame();
1243  if( !pHeadline->IsAnLower( pFrame ) )
1244  break;
1245  }
1246  }
1247  }
1248  }
1249 
1250  SwRowFrame* pLastRow = nullptr; // points to the last remaining line in master
1251  SwRowFrame* pFollowRow = nullptr; // points to either the follow flow line or the
1252  // first regular line in the follow
1253 
1254  if ( bSplitRowAllowed )
1255  {
1256  // If the row that does not fit anymore is allowed
1257  // to be split, the next row has to be moved to the follow table.
1258  pLastRow = pRow;
1259  pRow = static_cast<SwRowFrame*>(pRow->GetNext());
1260 
1261  // new follow flow line for last row of master table
1262  pFollowRow = lcl_InsertNewFollowFlowLine( *this, *pLastRow, false );
1263  }
1264  else
1265  {
1266  pFollowRow = pRow;
1267 
1268  // NEW TABLES
1269  // check if we will break a row span by moving pFollowRow to the follow:
1270  // In this case we want to reformat the last line.
1271  const SwCellFrame* pCellFrame = static_cast<const SwCellFrame*>(pFollowRow->GetLower());
1272  while ( pCellFrame )
1273  {
1274  if ( pCellFrame->GetTabBox()->getRowSpan() < 1 )
1275  {
1276  pLastRow = static_cast<SwRowFrame*>(pRow->GetPrev());
1277  break;
1278  }
1279 
1280  pCellFrame = static_cast<const SwCellFrame*>(pCellFrame->GetNext());
1281  }
1282 
1283  // new follow flow line for last row of master table
1284  if ( pLastRow )
1285  pFollowRow = lcl_InsertNewFollowFlowLine( *this, *pLastRow, true );
1286  }
1287 
1288  SwTwips nShrink = 0;
1289 
1290  //Optimization: There is no paste needed for the new Follow and the
1291  //optimized insert can be used (large numbers of rows luckily only occur in
1292  //such situations).
1293  if ( bNewFollow )
1294  {
1295  SwFrame* pInsertBehind = pFoll->GetLastLower();
1296 
1297  while ( pRow )
1298  {
1299  SwFrame* pNxt = pRow->GetNext();
1300  nShrink += aRectFnSet.GetHeight(pRow->getFrameArea());
1301  // The footnotes do not have to be moved, this is done in the
1302  // MoveFwd of the follow table!!!
1303  pRow->RemoveFromLayout();
1304  pRow->InsertBehind( pFoll, pInsertBehind );
1305  pRow->InvalidateAll_();
1306  pInsertBehind = pRow;
1307  pRow = static_cast<SwRowFrame*>(pNxt);
1308  }
1309  }
1310  else
1311  {
1312  SwFrame* pPasteBefore = HasFollowFlowLine() ?
1313  pFollowRow->GetNext() :
1314  pFoll->GetFirstNonHeadlineRow();
1315 
1316  while ( pRow )
1317  {
1318  SwFrame* pNxt = pRow->GetNext();
1319  nShrink += aRectFnSet.GetHeight(pRow->getFrameArea());
1320 
1321  // The footnotes have to be moved:
1322  lcl_MoveFootnotes( *this, *GetFollow(), *pRow );
1323 
1324  pRow->RemoveFromLayout();
1325  pRow->Paste( pFoll, pPasteBefore );
1326 
1327  pRow->CheckDirChange();
1328  pRow = static_cast<SwRowFrame*>(pNxt);
1329  }
1330  }
1331 
1332  if ( !pLastRow )
1333  Shrink( nShrink );
1334  else
1335  {
1336  // we rebuild the last line to assure that it will be fully formatted
1337  // we also don't shrink here, because we will be doing that in lcl_RecalcSplitLine
1338 
1339  // recalculate the split line
1340  bRet = lcl_RecalcSplitLine( *pLastRow, *pFollowRow, nRemainingSpaceForLastRow, nShrink );
1341 
1342  // RecalcSplitLine did not work. In this case we conceal the split error:
1343  if (!bRet && !bSplitRowAllowed)
1344  {
1345  bRet = true;
1346  }
1347 
1348  // NEW TABLES
1349  // check if each cell in the row span line has a good height
1350  if ( bRet && pFollowRow->IsRowSpanLine() )
1351  lcl_AdjustRowSpanCells( pFollowRow );
1352  }
1353 
1354  return bRet;
1355 }
1356 
1358 {
1359  OSL_ENSURE( !HasFollowFlowLine(), "Joining follow flow line" );
1360 
1361  SwTabFrame *pFoll = GetFollow();
1362 
1363  if (!pFoll || pFoll->IsJoinLocked())
1364  return;
1365 
1366  SwRectFnSet aRectFnSet(this);
1367  pFoll->Cut(); //Cut out first to avoid unnecessary notifications.
1368 
1369  SwFrame *pRow = pFoll->GetFirstNonHeadlineRow(),
1370  *pNxt;
1371 
1372  SwFrame* pPrv = GetLastLower();
1373 
1374  SwTwips nHeight = 0; //Total height of the inserted rows as return value.
1375 
1376  while ( pRow )
1377  {
1378  pNxt = pRow->GetNext();
1379  nHeight += aRectFnSet.GetHeight(pRow->getFrameArea());
1380  pRow->RemoveFromLayout();
1381  pRow->InvalidateAll_();
1382  pRow->InsertBehind( this, pPrv );
1383  pRow->CheckDirChange();
1384  pPrv = pRow;
1385  pRow = pNxt;
1386  }
1387 
1388  SetFollow( pFoll->GetFollow() );
1390  SwFrame::DestroyFrame(pFoll);
1391 
1392  Grow( nHeight );
1393 }
1394 
1395 static void SwInvalidatePositions( SwFrame *pFrame, tools::Long nBottom )
1396 {
1397  // LONG_MAX == nBottom means we have to calculate all
1398  bool bAll = LONG_MAX == nBottom;
1399  SwRectFnSet aRectFnSet(pFrame);
1400  do
1401  { pFrame->InvalidatePos_();
1402  pFrame->InvalidateSize_();
1403  if( pFrame->IsLayoutFrame() )
1404  {
1405  if ( static_cast<SwLayoutFrame*>(pFrame)->Lower() )
1406  {
1407  ::SwInvalidatePositions( static_cast<SwLayoutFrame*>(pFrame)->Lower(), nBottom);
1408  // #i26945#
1409  ::lcl_InvalidateLowerObjs( *static_cast<SwLayoutFrame*>(pFrame) );
1410  }
1411  }
1412  else
1414  pFrame = pFrame->GetNext();
1415  } while ( pFrame &&
1416  ( bAll ||
1417  aRectFnSet.YDiff( aRectFnSet.GetTop(pFrame->getFrameArea()), nBottom ) < 0 ) );
1418 }
1419 
1420 void SwInvalidateAll( SwFrame *pFrame, tools::Long nBottom )
1421 {
1422  // LONG_MAX == nBottom means we have to calculate all
1423  bool bAll = LONG_MAX == nBottom;
1424  SwRectFnSet aRectFnSet(pFrame);
1425  do
1426  {
1427  pFrame->InvalidatePos_();
1428  pFrame->InvalidateSize_();
1429  pFrame->InvalidatePrt_();
1430  if( pFrame->IsLayoutFrame() )
1431  {
1432  // NEW TABLES
1433  SwLayoutFrame* pToInvalidate = static_cast<SwLayoutFrame*>(pFrame);
1434  SwCellFrame* pThisCell = dynamic_cast<SwCellFrame*>(pFrame);
1435  if ( pThisCell && pThisCell->GetTabBox()->getRowSpan() < 1 )
1436  {
1437  pToInvalidate = & const_cast<SwCellFrame&>(pThisCell->FindStartEndOfRowSpanCell( true ));
1438  pToInvalidate->InvalidatePos_();
1439  pToInvalidate->InvalidateSize_();
1440  pToInvalidate->InvalidatePrt_();
1441  }
1442 
1443  if ( pToInvalidate->Lower() )
1444  ::SwInvalidateAll( pToInvalidate->Lower(), nBottom);
1445  }
1446  else
1447  pFrame->Prepare();
1448 
1449  pFrame = pFrame->GetNext();
1450  } while ( pFrame &&
1451  ( bAll ||
1452  aRectFnSet.YDiff( aRectFnSet.GetTop(pFrame->getFrameArea()), nBottom ) < 0 ) );
1453 }
1454 
1455 // #i29550#
1457 {
1458  pLayFrame->InvalidatePrt_();
1459  pLayFrame->InvalidateSize_();
1460  pLayFrame->SetCompletePaint();
1461 
1462  SwFrame* pFrame = pLayFrame->Lower();
1463 
1464  while ( pFrame )
1465  {
1466  if ( pFrame->IsLayoutFrame() )
1467  lcl_InvalidateAllLowersPrt( static_cast<SwLayoutFrame*>(pFrame) );
1468  else
1469  {
1470  pFrame->InvalidatePrt_();
1471  pFrame->InvalidateSize_();
1472  pFrame->SetCompletePaint();
1473  }
1474 
1475  pFrame = pFrame->GetNext();
1476  }
1477 }
1478 
1480  tools::Long nBottom, bool bSkipRowSpanCells )
1481 {
1482  vcl::RenderContext* pRenderContext = rLay.getRootFrame()->GetCurrShell()->GetOut();
1483  // LONG_MAX == nBottom means we have to calculate all
1484  bool bAll = LONG_MAX == nBottom;
1485  bool bRet = false;
1486  SwContentFrame *pCnt = rLay.ContainsContent();
1487  SwRectFnSet aRectFnSet(&rLay);
1488 
1489  // FME 2007-08-30 #i81146# new loop control
1490  int nLoopControlRuns = 0;
1491  const int nLoopControlMax = 10;
1492  const SwModify* pLoopControlCond = nullptr;
1493 
1494  while (pCnt && rDontLeave.IsAnLower(pCnt))
1495  {
1496  // #115759# - check, if a format of content frame is
1497  // possible. Thus, 'copy' conditions, found at the beginning of
1498  // <SwContentFrame::MakeAll(..)>, and check these.
1499  const bool bFormatPossible = !pCnt->IsJoinLocked() &&
1500  ( !pCnt->IsTextFrame() ||
1501  !static_cast<SwTextFrame*>(pCnt)->IsLocked() ) &&
1502  ( pCnt->IsFollow() || !StackHack::IsLocked() );
1503 
1504  // NEW TABLES
1505  bool bSkipContent = false;
1506  if ( bSkipRowSpanCells && pCnt->IsInTab() )
1507  {
1508  const SwFrame* pCell = pCnt->GetUpper();
1509  while ( pCell && !pCell->IsCellFrame() )
1510  pCell = pCell->GetUpper();
1511  if ( pCell && 1 != static_cast<const SwCellFrame*>( pCell )->GetLayoutRowSpan() )
1512  bSkipContent = true;
1513  }
1514 
1515  if ( bFormatPossible && !bSkipContent )
1516  {
1517  bRet |= !pCnt->isFrameAreaDefinitionValid();
1518  // #i26945# - no extra invalidation of floating
1519  // screen objects needed.
1520  // Thus, delete call of method <SwFrame::InvalidateObjs( true )>
1521  pCnt->Calc(pRenderContext);
1522  // #i46941# - frame has to be valid
1523  // Note: frame could be invalid after calling its format, if it's locked.
1524  OSL_ENSURE( !pCnt->IsTextFrame() ||
1525  pCnt->isFrameAreaDefinitionValid() ||
1526  static_cast<SwTextFrame*>(pCnt)->IsJoinLocked(),
1527  "<SwContentFrame::CalcLowers(..)> - text frame invalid and not locked." );
1528  if ( pCnt->IsTextFrame() && pCnt->isFrameAreaDefinitionValid() )
1529  {
1530  // #i23129#, #i36347# - pass correct page frame to
1531  // the object formatter
1533  *(pCnt->FindPageFrame()) ) )
1534  {
1535  SwTextNode const*const pTextNode(
1536  static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst());
1537  if (pTextNode == pLoopControlCond)
1538  ++nLoopControlRuns;
1539  else
1540  {
1541  nLoopControlRuns = 0;
1542  pLoopControlCond = pTextNode;
1543  }
1544 
1545  if ( nLoopControlRuns < nLoopControlMax )
1546  {
1547  // restart format with first content
1548  pCnt = rLay.ContainsContent();
1549  continue;
1550  }
1551 
1552 #if OSL_DEBUG_LEVEL > 1
1553  OSL_FAIL( "LoopControl in SwContentFrame::CalcLowers" );
1554 #endif
1555  }
1556  }
1557  if (!rDontLeave.IsAnLower(pCnt)) // moved backward?
1558  {
1559  pCnt = rLay.ContainsContent();
1560  continue; // avoid formatting new upper on different page
1561  }
1562  pCnt->GetUpper()->Calc(pRenderContext);
1563  }
1564  if( ! bAll && aRectFnSet.YDiff(aRectFnSet.GetTop(pCnt->getFrameArea()), nBottom) > 0 )
1565  break;
1566  pCnt = pCnt->GetNextContentFrame();
1567  }
1568  return bRet;
1569 }
1570 
1571 // #i26945# - add parameter <_bOnlyRowsAndCells> to control
1572 // that only row and cell frames are formatted.
1573 static bool lcl_InnerCalcLayout( SwFrame *pFrame,
1574  tools::Long nBottom,
1575  bool _bOnlyRowsAndCells )
1576 {
1577  vcl::RenderContext* pRenderContext = pFrame->getRootFrame()->GetCurrShell() ? pFrame->getRootFrame()->GetCurrShell()->GetOut() : nullptr;
1578  // LONG_MAX == nBottom means we have to calculate all
1579  bool bAll = LONG_MAX == nBottom;
1580  bool bRet = false;
1581  const SwFrame* pOldUp = pFrame->GetUpper();
1582  SwRectFnSet aRectFnSet(pFrame);
1583  do
1584  {
1585  // #i26945# - parameter <_bOnlyRowsAndCells> controls,
1586  // if only row and cell frames are formatted.
1587  if ( pFrame->IsLayoutFrame() &&
1588  ( !_bOnlyRowsAndCells || pFrame->IsRowFrame() || pFrame->IsCellFrame() ) )
1589  {
1590  // #130744# An invalid locked table frame will
1591  // not be calculated => It will not become valid =>
1592  // Loop in lcl_RecalcRow(). Therefore we do not consider them for bRet.
1593  bRet |= !pFrame->isFrameAreaDefinitionValid() && ( !pFrame->IsTabFrame() || !static_cast<SwTabFrame*>(pFrame)->IsJoinLocked() );
1594  pFrame->Calc(pRenderContext);
1595  if( static_cast<SwLayoutFrame*>(pFrame)->Lower() )
1596  bRet |= lcl_InnerCalcLayout( static_cast<SwLayoutFrame*>(pFrame)->Lower(), nBottom);
1597 
1598  // NEW TABLES
1599  SwCellFrame* pThisCell = dynamic_cast<SwCellFrame*>(pFrame);
1600  if ( pThisCell && pThisCell->GetTabBox()->getRowSpan() < 1 )
1601  {
1602  SwCellFrame& rToCalc = const_cast<SwCellFrame&>(pThisCell->FindStartEndOfRowSpanCell( true ));
1603  bRet |= !rToCalc.isFrameAreaDefinitionValid();
1604  rToCalc.Calc(pRenderContext);
1605  if ( rToCalc.Lower() )
1606  bRet |= lcl_InnerCalcLayout( rToCalc.Lower(), nBottom);
1607  }
1608  }
1609  pFrame = pFrame->GetNext();
1610  } while( pFrame &&
1611  ( bAll ||
1612  aRectFnSet.YDiff(aRectFnSet.GetTop(pFrame->getFrameArea()), nBottom) < 0 )
1613  && pFrame->GetUpper() == pOldUp );
1614  return bRet;
1615 }
1616 
1617 static void lcl_RecalcRow(SwRowFrame & rRow, tools::Long const nBottom)
1618 {
1619  // FME 2007-08-30 #i81146# new loop control
1620  int nLoopControlRuns_1 = 0;
1621  sal_uInt16 nLoopControlStage_1 = 0;
1622  const int nLoopControlMax = 10;
1623 
1624  bool bCheck = true;
1625  do
1626  {
1627  // FME 2007-08-30 #i81146# new loop control
1628  int nLoopControlRuns_2 = 0;
1629  sal_uInt16 nLoopControlStage_2 = 0;
1630 
1631  while (lcl_InnerCalcLayout(&rRow, nBottom))
1632  {
1633  if ( ++nLoopControlRuns_2 > nLoopControlMax )
1634  {
1635  SAL_WARN_IF(nLoopControlStage_2 == 0, "sw.layout", "LoopControl_2 in lcl_RecalcRow: Stage 1!");
1636  SAL_WARN_IF(nLoopControlStage_2 == 1, "sw.layout", "LoopControl_2 in lcl_RecalcRow: Stage 2!!");
1637  SAL_WARN_IF(nLoopControlStage_2 >= 2, "sw.layout", "LoopControl_2 in lcl_RecalcRow: Stage 3!!!");
1638  rRow.ValidateThisAndAllLowers( nLoopControlStage_2++ );
1639  nLoopControlRuns_2 = 0;
1640  if( nLoopControlStage_2 > 2 )
1641  break;
1642  }
1643 
1644  bCheck = true;
1645  }
1646 
1647  if( bCheck )
1648  {
1649  // #115759# - force another format of the
1650  // lowers, if at least one of it was invalid.
1651  bCheck = SwContentFrame::CalcLowers(rRow, *rRow.GetUpper(), nBottom, true);
1652 
1653  // NEW TABLES
1654  // First we calculate the cells with row span of < 1, afterwards
1655  // all cells with row span of > 1:
1656  for ( int i = 0; i < 2; ++i )
1657  {
1658  SwCellFrame* pCellFrame = static_cast<SwCellFrame*>(rRow.Lower());
1659  while ( pCellFrame )
1660  {
1661  const bool bCalc = 0 == i ?
1662  pCellFrame->GetLayoutRowSpan() < 1 :
1663  pCellFrame->GetLayoutRowSpan() > 1;
1664 
1665  if ( bCalc )
1666  {
1667  SwCellFrame& rToRecalc = 0 == i ?
1668  const_cast<SwCellFrame&>(pCellFrame->FindStartEndOfRowSpanCell( true )) :
1669  *pCellFrame;
1670  bCheck |= SwContentFrame::CalcLowers(rToRecalc, rToRecalc, nBottom, false);
1671  }
1672 
1673  pCellFrame = static_cast<SwCellFrame*>(pCellFrame->GetNext());
1674  }
1675  }
1676 
1677  if ( bCheck )
1678  {
1679  if ( ++nLoopControlRuns_1 > nLoopControlMax )
1680  {
1681  SAL_WARN_IF(nLoopControlStage_1 == 0, "sw.layout", "LoopControl_1 in lcl_RecalcRow: Stage 1!");
1682  SAL_WARN_IF(nLoopControlStage_1 == 1, "sw.layout", "LoopControl_1 in lcl_RecalcRow: Stage 2!!");
1683  SAL_WARN_IF(nLoopControlStage_1 >= 2, "sw.layout", "LoopControl_1 in lcl_RecalcRow: Stage 3!!!");
1684  rRow.ValidateThisAndAllLowers( nLoopControlStage_1++ );
1685  nLoopControlRuns_1 = 0;
1686  if( nLoopControlStage_1 > 2 )
1687  break;
1688  }
1689 
1690  continue;
1691  }
1692  }
1693  break;
1694  } while( true );
1695 }
1696 
1697 static void lcl_RecalcTable( SwTabFrame& rTab,
1698  SwLayoutFrame *pFirstRow,
1699  SwLayNotify &rNotify )
1700 {
1701  if ( rTab.Lower() )
1702  {
1703  if ( !pFirstRow )
1704  {
1705  pFirstRow = static_cast<SwLayoutFrame*>(rTab.Lower());
1706  rNotify.SetLowersComplete( true );
1707  }
1708  ::SwInvalidatePositions( pFirstRow, LONG_MAX );
1709  lcl_RecalcRow( *static_cast<SwRowFrame*>(pFirstRow), LONG_MAX );
1710  }
1711 }
1712 
1713 // This is a new function to check the first condition whether
1714 // a tab frame may move backward. It replaces the formerly used
1715 // GetIndPrev(), which did not work correctly for #i5947#
1716 static bool lcl_NoPrev( const SwFrame& rFrame )
1717 {
1718  // #i79774#
1719  // skip empty sections on investigation of direct previous frame.
1720  // use information, that at least one empty section is skipped in the following code.
1721  bool bSkippedDirectPrevEmptySection( false );
1722  if ( rFrame.GetPrev() )
1723  {
1724  const SwFrame* pPrev( rFrame.GetPrev() );
1725  while ( pPrev &&
1726  pPrev->IsSctFrame() &&
1727  !dynamic_cast<const SwSectionFrame&>(*pPrev).GetSection() )
1728  {
1729  pPrev = pPrev->GetPrev();
1730  bSkippedDirectPrevEmptySection = true;
1731  }
1732  if ( pPrev )
1733  {
1734  return false;
1735  }
1736  }
1737 
1738  if ( ( !bSkippedDirectPrevEmptySection && !rFrame.GetIndPrev() ) ||
1739  ( bSkippedDirectPrevEmptySection &&
1740  ( !rFrame.IsInSct() || !rFrame.GetIndPrev_() ) ) )
1741  {
1742  return true;
1743  }
1744 
1745  // I do not have a direct prev, but I have an indirect prev.
1746  // In section frames I have to check if I'm located inside
1747  // the first column:
1748  if ( rFrame.IsInSct() )
1749  {
1750  const SwFrame* pSct = rFrame.GetUpper();
1751  if ( pSct && pSct->IsColBodyFrame() &&
1752  pSct->GetUpper()->GetUpper()->IsSctFrame() )
1753  {
1754  const SwFrame* pPrevCol = rFrame.GetUpper()->GetUpper()->GetPrev();
1755  if ( pPrevCol )
1756  // I'm not inside the first column and do not have a direct
1757  // prev. I can try to go backward.
1758  return true;
1759  }
1760  }
1761 
1762  return false;
1763 }
1764 
1765 #define KEEPTAB ( !GetFollow() && !IsFollow() )
1766 
1767 // - helper method to find next content frame of
1768 // a table frame and format it to assure keep attribute.
1769 // method return true, if a next content frame is formatted.
1770 // Precondition: The given table frame hasn't a follow and isn't a follow.
1772 {
1773  vcl::RenderContext* pRenderContext = pTabFrame->getRootFrame()->GetCurrShell()->GetOut();
1774  // find next content, table or section
1775  SwFrame* pNxt = pTabFrame->FindNext();
1776 
1777  // skip empty sections
1778  while ( pNxt && pNxt->IsSctFrame() &&
1779  !static_cast<SwSectionFrame*>(pNxt)->GetSection() )
1780  {
1781  pNxt = pNxt->FindNext();
1782  }
1783 
1784  // if found next frame is a section, get its first content.
1785  if ( pNxt && pNxt->IsSctFrame() )
1786  {
1787  pNxt = static_cast<SwSectionFrame*>(pNxt)->ContainsAny();
1788  }
1789 
1790  // format found next frame.
1791  // if table frame is inside another table, method <SwFrame::MakeAll()> is
1792  // called to avoid that the superior table frame is formatted.
1793  if ( pNxt )
1794  {
1795  if ( pTabFrame->GetUpper()->IsInTab() )
1796  pNxt->MakeAll(pNxt->getRootFrame()->GetCurrShell()->GetOut());
1797  else
1798  pNxt->Calc(pRenderContext);
1799  }
1800 
1801  return pNxt;
1802 }
1803 
1804 namespace {
1805  bool AreAllRowsKeepWithNext( const SwRowFrame* pFirstRowFrame, const bool bCheckParents = true )
1806  {
1807  bool bRet = pFirstRowFrame != nullptr &&
1808  pFirstRowFrame->ShouldRowKeepWithNext( bCheckParents );
1809 
1810  while ( bRet && pFirstRowFrame->GetNext() != nullptr )
1811  {
1812  pFirstRowFrame = dynamic_cast<const SwRowFrame*>(pFirstRowFrame->GetNext());
1813  bRet = pFirstRowFrame != nullptr &&
1814  pFirstRowFrame->ShouldRowKeepWithNext( bCheckParents );
1815  }
1816 
1817  return bRet;
1818  }
1819 }
1820 
1821 // extern because static can't be friend
1823 {
1824  // hilariously static_cast<SwTabFrame*>(GetLower()) would not require friend declaration, but it's UB...
1825  rRowFrame.setFrameAreaPositionValid(false);
1826 }
1827 
1828 static void InvalidateFramePositions(SwFrame * pFrame)
1829 {
1830  while (pFrame)
1831  {
1832  if (pFrame->IsLayoutFrame())
1833  {
1835  }
1836  else if (pFrame->IsTextFrame())
1837  {
1839  }
1840  pFrame = pFrame->GetNext();
1841  }
1842 }
1843 
1845 {
1846  if ( IsJoinLocked() || StackHack::IsLocked() || StackHack::Count() > 50 )
1847  return;
1848 
1849  if ( HasFollow() )
1850  {
1851  SwTabFrame* pFollowFrame = GetFollow();
1852  OSL_ENSURE( !pFollowFrame->IsJoinLocked() || !pFollowFrame->IsRebuildLastLine(),
1853  "SwTabFrame::MakeAll for master while follow is in RebuildLastLine()" );
1854  if ( pFollowFrame->IsJoinLocked() && pFollowFrame->IsRebuildLastLine() )
1855  return;
1856  }
1857 
1858  PROTOCOL_ENTER( this, PROT::MakeAll, DbgAction::NONE, nullptr )
1859 
1860  LockJoin(); //I don't want to be destroyed on the way.
1861  SwLayNotify aNotify( this ); //does the notification in the DTor
1862  // If pos is invalid, we have to call a SetInvaKeep at aNotify.
1863  // Otherwise the keep attribute would not work in front of a table.
1864  const bool bOldValidPos = isFrameAreaPositionValid();
1865 
1866  //If my neighbour is my Follow at the same time, I'll swallow it up.
1867  // OD 09.04.2003 #108698# - join all follows, which are placed on the
1868  // same page/column.
1869  // OD 29.04.2003 #109213# - join follow, only if join for the follow
1870  // is not locked. Otherwise, join will not be performed and this loop
1871  // will be endless.
1872  while ( GetNext() && GetNext() == GetFollow() &&
1873  !GetFollow()->IsJoinLocked()
1874  )
1875  {
1876  if ( HasFollowFlowLine() )
1878  Join();
1879  }
1880 
1881  // The bRemoveFollowFlowLinePending is set if the split attribute of the
1882  // last line is set:
1884  {
1885  if ( RemoveFollowFlowLine() )
1886  Join();
1888  }
1889 
1890  if (m_bResizeHTMLTable) //Optimized interplay with grow/shrink of the content
1891  {
1892  m_bResizeHTMLTable = false;
1894  if ( pLayout )
1895  m_bCalcLowers = pLayout->Resize(
1896  pLayout->GetBrowseWidthByTabFrame( *this ) );
1897  }
1898 
1899  // as long as bMakePage is true, a new page can be created (exactly once)
1900  bool bMakePage = true;
1901  // bMovedBwd gets set to true when the frame flows backwards
1902  bool bMovedBwd = false;
1903  // as long as bMovedFwd is false, the Frame may flow backwards (until
1904  // it has been moved forward once)
1905  bool bMovedFwd = false;
1906  // gets set to true when the Frame is split
1907  bool bSplit = false;
1908  const bool bFootnotesInDoc = !GetFormat()->GetDoc()->GetFootnoteIdxs().empty();
1909  const bool bFly = IsInFly();
1910 
1911  auto pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
1912  const SwBorderAttrs *pAttrs = pAccess->Get();
1913 
1914  // All rows should keep together
1915  const bool bDontSplit = !IsFollow() &&
1916  ( !GetFormat()->GetLayoutSplit().GetValue() );
1917 
1918  // The number of repeated headlines
1919  const sal_uInt16 nRepeat = GetTable()->GetRowsToRepeat();
1920 
1921  // This flag indicates that we are allowed to try to split the
1922  // table rows.
1923  bool bTryToSplit = true;
1924 
1925  // Indicates that two individual rows may keep together, based on the keep
1926  // attribute set at the first paragraph in the first cell.
1927  const bool bTableRowKeep = !bDontSplit && GetFormat()->GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::TABLE_ROW_KEEP);
1928 
1929  // The Magic Move: Used for the table row keep feature.
1930  // If only the last row of the table wants to keep (implicitly by setting
1931  // keep for the first paragraph in the first cell), and this table does
1932  // not have a next, the last line will be cut. Loop prevention: Only
1933  // one try.
1934  // WHAT IS THIS??? It "magically" hides last line (paragraph) in a table,
1935  // if first is set to keep with next???
1936  bool bLastRowHasToMoveToFollow = false;
1937  bool bLastRowMoveNoMoreTries = false;
1938 
1939  const bool bLargeTable = GetTable()->GetTabLines().size() > 64; //arbitrary value, virtually guaranteed to be larger than one page.
1940  const bool bEmulateTableKeep = !bLargeTable && bTableRowKeep && AreAllRowsKeepWithNext( GetFirstNonHeadlineRow(), /*bCheckParents=*/false );
1941  // The beloved keep attribute
1942  const bool bKeep = IsKeep(pAttrs->GetAttrSet().GetKeep(), GetBreakItem(), bEmulateTableKeep);
1943 
1944  // Join follow table, if this table is not allowed to split:
1945  if ( bDontSplit )
1946  {
1947  while ( GetFollow() && !GetFollow()->IsJoinLocked() )
1948  {
1949  if ( HasFollowFlowLine() )
1951  Join();
1952  }
1953  }
1954 
1955  // Join follow table, if this does not have enough (repeated) lines:
1956  if ( nRepeat )
1957  {
1958  if( GetFollow() && !GetFollow()->IsJoinLocked() &&
1959  nullptr == GetFirstNonHeadlineRow() )
1960  {
1961  if ( HasFollowFlowLine() )
1963  Join();
1964  }
1965  }
1966 
1967  // Join follow table, if last row of this table should keep:
1968  if ( bTableRowKeep && GetFollow() && !GetFollow()->IsJoinLocked() )
1969  {
1970  const SwRowFrame* pTmpRow = static_cast<const SwRowFrame*>(GetLastLower());
1971  if ( pTmpRow && pTmpRow->ShouldRowKeepWithNext() )
1972  {
1973  if ( HasFollowFlowLine() )
1975  Join();
1976  }
1977  }
1978 
1979  // a new one is moved forwards immediately
1980  if ( !getFrameArea().Top() && IsFollow() )
1981  {
1982  SwFrame *pPre = GetPrev();
1983  if ( pPre && pPre->IsTabFrame() && static_cast<SwTabFrame*>(pPre)->GetFollow() == this)
1984  {
1985  // don't make the effort to move fwd if its known
1986  // conditions that are known not to work
1988  bMakePage = false;
1989  else if (!MoveFwd(bMakePage, false))
1990  bMakePage = false;
1991  bMovedFwd = true;
1992  }
1993  }
1994 
1995  int nUnSplitted = 5; // Just another loop control :-(
1996  int nThrowAwayValidLayoutLimit = 5; // And another one :-(
1997  SwRectFnSet aRectFnSet(this);
1999  {
2000  const bool bMoveable = IsMoveable();
2001  if (bMoveable &&
2002  !(bMovedFwd && bEmulateTableKeep) )
2003  if ( CheckMoveFwd( bMakePage, bKeep && KEEPTAB, bEmulateTableKeep ) )
2004  {
2005  bMovedFwd = true;
2006  m_bCalcLowers = true;
2007  // #i99267#
2008  // reset <bSplit> after forward move to assure that follows
2009  // can be joined, if further space is available.
2010  bSplit = false;
2011  }
2012 
2013  Point aOldPos( aRectFnSet.GetPos(getFrameArea()) );
2014  MakePos();
2015 
2016  if ( aOldPos != aRectFnSet.GetPos(getFrameArea()) )
2017  {
2018  if ( aOldPos.Y() != aRectFnSet.GetTop(getFrameArea()) )
2019  {
2021  if( pLayout )
2022  {
2023  pAccess.reset();
2024  m_bCalcLowers |= pLayout->Resize(
2025  pLayout->GetBrowseWidthByTabFrame( *this ) );
2026  pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
2027  pAttrs = pAccess->Get();
2028  }
2029 
2030  setFramePrintAreaValid(false);
2031  aNotify.SetLowersComplete( false );
2032  }
2033  SwFrame *pPre;
2034  if ( bKeep || (nullptr != (pPre = FindPrev()) &&
2035  pPre->GetAttrSet()->GetKeep().GetValue()) )
2036  {
2037  m_bCalcLowers = true;
2038  }
2039  if (GetLower())
2040  { // it's possible that the rows already have valid pos - but it is surely wrong if the table's pos changed!
2042  // invalidate text frames to get rid of their SwFlyPortions
2044  }
2045  }
2046 
2047  //We need to know the height of the first row, because the master needs
2048  //to be invalidated if it shrinks and then absorb the row if possible.
2049  tools::Long n1StLineHeight = 0;
2050  if ( IsFollow() )
2051  {
2052  SwFrame* pFrame = GetFirstNonHeadlineRow();
2053  if ( pFrame )
2054  n1StLineHeight = aRectFnSet.GetHeight(pFrame->getFrameArea());
2055  }
2056 
2058  {
2059  const tools::Long nOldPrtWidth = aRectFnSet.GetWidth(getFramePrintArea());
2060  const tools::Long nOldFrameWidth = aRectFnSet.GetWidth(getFrameArea());
2061  const Point aOldPrtPos = aRectFnSet.GetPos(getFramePrintArea());
2062  Format( getRootFrame()->GetCurrShell()->GetOut(), pAttrs );
2063 
2065  if ( pLayout &&
2066  (aRectFnSet.GetWidth(getFramePrintArea()) != nOldPrtWidth ||
2067  aRectFnSet.GetWidth(getFrameArea()) != nOldFrameWidth) )
2068  {
2069  pAccess.reset();
2070  m_bCalcLowers |= pLayout->Resize(
2071  pLayout->GetBrowseWidthByTabFrame( *this ) );
2072  pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
2073  pAttrs = pAccess->Get();
2074  }
2075  if ( aOldPrtPos != aRectFnSet.GetPos(getFramePrintArea()) )
2076  aNotify.SetLowersComplete( false );
2077  }
2078 
2079  // If this is the first one in a chain, check if this can flow
2080  // backwards (if this is movable at all).
2081  // To prevent oscillations/loops, check that this has not just
2082  // flowed forwards.
2083  if ( !bMovedFwd && (bMoveable || bFly) && lcl_NoPrev( *this ) )
2084  {
2085  // for Follows notify Master.
2086  // only move Follow if it has to skip empty pages.
2087  if ( IsFollow() )
2088  {
2089  // Only if the height of the first line got smaller.
2090  SwFrame *pFrame = GetFirstNonHeadlineRow();
2091  if( pFrame && n1StLineHeight >aRectFnSet.GetHeight(pFrame->getFrameArea()) )
2092  {
2093  SwTabFrame *pMaster = FindMaster();
2094  bool bDummy;
2095  if ( ShouldBwdMoved( pMaster->GetUpper(), bDummy ) )
2096  pMaster->InvalidatePos();
2097  }
2098  }
2099  SwFootnoteBossFrame *pOldBoss = bFootnotesInDoc ? FindFootnoteBossFrame( true ) : nullptr;
2100  bool bReformat;
2101  if ( MoveBwd( bReformat ) )
2102  {
2103  aRectFnSet.Refresh(this);
2104  bMovedBwd = true;
2105  aNotify.SetLowersComplete( false );
2106  if ( bFootnotesInDoc )
2107  MoveLowerFootnotes( nullptr, pOldBoss, nullptr, true );
2108  if ( bReformat || bKeep )
2109  {
2110  tools::Long nOldTop = aRectFnSet.GetTop(getFrameArea());
2111  MakePos();
2112  if( nOldTop != aRectFnSet.GetTop(getFrameArea()) )
2113  {
2114  SwHTMLTableLayout *pHTMLLayout =
2116  if( pHTMLLayout )
2117  {
2118  pAccess.reset();
2119  m_bCalcLowers |= pHTMLLayout->Resize(
2120  pHTMLLayout->GetBrowseWidthByTabFrame( *this ) );
2121 
2122  pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
2123  pAttrs = pAccess->Get();
2124  }
2125 
2126  setFramePrintAreaValid(false);
2127  Format( getRootFrame()->GetCurrShell()->GetOut(), pAttrs );
2128  }
2129  lcl_RecalcTable( *this, nullptr, aNotify );
2130  m_bLowersFormatted = true;
2131  if ( bKeep && KEEPTAB )
2132  {
2133 
2134  // Consider case that table is inside another table,
2135  // because it has to be avoided, that superior table
2136  // is formatted.
2137  // Thus, find next content, table or section
2138  // and, if a section is found, get its first
2139  // content.
2140  if ( nullptr != sw_FormatNextContentForKeep( this ) && !GetNext() )
2141  {
2143  }
2144  }
2145  }
2146  }
2147  }
2148 
2149  //Again an invalid value? - do it again...
2151  continue;
2152 
2153  // check, if calculation of table frame is ready.
2154 
2155  // Local variable <nDistanceToUpperPrtBottom>
2156  // Introduce local variable and init it with the distance from the
2157  // table frame bottom to the bottom of the upper printing area.
2158  // Note: negative values denotes the situation that table frame doesn't fit in its upper.
2159  SwTwips nDistanceToUpperPrtBottom =
2160  aRectFnSet.BottomDist(getFrameArea(), aRectFnSet.GetPrtBottom(*GetUpper()));
2161 
2163  const SwViewShell *pSh = getRootFrame()->GetCurrShell();
2164  const bool bBrowseMode = pSh && pSh->GetViewOptions()->getBrowseMode();
2165  if ( nDistanceToUpperPrtBottom < 0 && bBrowseMode )
2166  {
2167  if ( GetUpper()->Grow( -nDistanceToUpperPrtBottom ) )
2168  {
2169  // upper is grown --> recalculate <nDistanceToUpperPrtBottom>
2170  nDistanceToUpperPrtBottom = aRectFnSet.BottomDist(getFrameArea(), aRectFnSet.GetPrtBottom(*GetUpper()));
2171  }
2172  }
2173 
2174  // If there is still some space left in the upper, we check if we
2175  // can join some rows of the follow.
2176  // Setting bLastRowHasToMoveToFollow to true means we want to force
2177  // the table to be split! Only skip this if condition once.
2178  if( nDistanceToUpperPrtBottom >= 0 && !bLastRowHasToMoveToFollow )
2179  {
2180  // If there is space left in the upper printing area, join as for trial
2181  // at least one further row of an existing follow.
2182  if ( !bSplit && GetFollow() )
2183  {
2184  bool bDummy;
2185  if ( GetFollow()->ShouldBwdMoved( GetUpper(), bDummy ) )
2186  {
2187  SwFrame *pTmp = GetUpper();
2188  SwTwips nDeadLine = aRectFnSet.GetPrtBottom(*pTmp);
2189  if ( bBrowseMode )
2190  nDeadLine += pTmp->Grow( LONG_MAX, true );
2191  bool bFits = aRectFnSet.BottomDist(getFrameArea(), nDeadLine) > 0;
2192  if (!bFits && aRectFnSet.GetHeight(GetFollow()->getFrameArea()) == 0)
2193  // The follow should move backwards, so allow the case
2194  // when the upper has no space, but the follow is
2195  // empty.
2196  bFits = aRectFnSet.BottomDist(getFrameArea(), nDeadLine) >= 0;
2197  if (bFits)
2198  {
2199  // First, we remove an existing follow flow line.
2200  if ( HasFollowFlowLine() )
2201  {
2202  SwFrame* pLastLine = GetLastLower();
2204  // invalidate and rebuild last row
2205  if ( pLastLine )
2206  {
2207  ::SwInvalidateAll( pLastLine, LONG_MAX );
2208  SetRebuildLastLine( true );
2209  lcl_RecalcRow(*static_cast<SwRowFrame*>(pLastLine), LONG_MAX);
2210  SetRebuildLastLine( false );
2211  }
2212 
2214 
2215  if ( !pRow || !pRow->GetNext() )
2216  // The follow became empty and hence useless
2217  Join();
2218 
2219  continue;
2220  }
2221 
2222  // If there is no follow flow line, we move the first
2223  // row in the follow table to the master table.
2225 
2226  // The follow became empty and hence useless
2227  if ( !pRow )
2228  {
2229  Join();
2230  continue;
2231  }
2232 
2233  const SwTwips nOld = aRectFnSet.GetHeight(getFrameArea());
2234  tools::Long nRowsToMove = lcl_GetMaximumLayoutRowSpan( *pRow );
2235  SwFrame* pRowToMove = pRow;
2236 
2237  while ( pRowToMove && nRowsToMove-- > 0 )
2238  {
2239  const bool bMoveFootnotes = bFootnotesInDoc && !GetFollow()->IsJoinLocked();
2240 
2241  SwFootnoteBossFrame *pOldBoss = nullptr;
2242  if ( bMoveFootnotes )
2243  pOldBoss = pRowToMove->FindFootnoteBossFrame( true );
2244 
2245  SwFrame* pNextRow = pRowToMove->GetNext();
2246 
2247  if ( !pNextRow )
2248  {
2249  // The follow became empty and hence useless
2250  Join();
2251  }
2252  else
2253  {
2254  pRowToMove->Cut();
2255  pRowToMove->Paste( this );
2256  }
2257 
2258  // Move the footnotes!
2259  if ( bMoveFootnotes )
2260  if ( static_cast<SwLayoutFrame*>(pRowToMove)->MoveLowerFootnotes( nullptr, pOldBoss, FindFootnoteBossFrame( true ), true ) )
2261  GetUpper()->Calc(pRenderContext);
2262 
2263  pRowToMove = pNextRow;
2264  }
2265 
2266  if ( nOld != aRectFnSet.GetHeight(getFrameArea()) )
2267  lcl_RecalcTable( *this, static_cast<SwLayoutFrame*>(pRow), aNotify );
2268 
2269  continue;
2270  }
2271  }
2272  }
2273  else if ( KEEPTAB )
2274  {
2275  bool bFormat = false;
2276  if ( bKeep )
2277  bFormat = true;
2278  else if ( bTableRowKeep && !bLastRowMoveNoMoreTries )
2279  {
2280  // We only want to give the last row one chance to move
2281  // to the follow table. Set the flag as early as possible:
2282  bLastRowMoveNoMoreTries = true;
2283 
2284  // The last line of the table has to be cut off if:
2285  // 1. The table does not want to keep with its next
2286  // 2. The compatibility option is set and the table is allowed to split
2287  // 3. We did not already cut off the last row
2288  // 4. There is not break after attribute set at the table
2289  // 5. There is no break before attribute set behind the table
2290  // 6. There is no section change behind the table (see IsKeep)
2291  // 7. The last table row wants to keep with its next.
2292  const SwRowFrame* pLastRow = static_cast<const SwRowFrame*>(GetLastLower());
2293  if (pLastRow
2294  && IsKeep(pAttrs->GetAttrSet().GetKeep(), GetBreakItem(), true)
2295  && pLastRow->ShouldRowKeepWithNext())
2296  {
2297  bFormat = true;
2298  }
2299  }
2300 
2301  if ( bFormat )
2302  {
2303  pAccess.reset();
2304 
2305  // Consider case that table is inside another table, because
2306  // it has to be avoided, that superior table is formatted.
2307  // Thus, find next content, table or section and, if a section
2308  // is found, get its first content.
2309  const SwFrame* pTmpNxt = sw_FormatNextContentForKeep( this );
2310 
2311  pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
2312  pAttrs = pAccess->Get();
2313 
2314  // The last row wants to keep with the frame behind the table.
2315  // Check if the next frame is on a different page and valid.
2316  // In this case we do a magic trick:
2317  if ( !bKeep && !GetNext() && pTmpNxt && pTmpNxt->isFrameAreaDefinitionValid() )
2318  {
2320  bLastRowHasToMoveToFollow = true;
2321  }
2322  }
2323  }
2324 
2326  {
2327  if (m_bCalcLowers)
2328  {
2329  lcl_RecalcTable( *this, nullptr, aNotify );
2330  m_bLowersFormatted = true;
2331  m_bCalcLowers = false;
2332  }
2333  else if (m_bONECalcLowers)
2334  {
2335  lcl_RecalcRow(*static_cast<SwRowFrame*>(Lower()), LONG_MAX);
2336  m_bONECalcLowers = false;
2337  }
2338  }
2339  continue;
2340  }
2341 
2342  // I don't fit in the upper Frame anymore, therefore it's the
2343  // right moment to do some preferably constructive changes.
2344 
2345  // If I'm NOT allowed to leave the upper Frame, I've got a problem.
2346  // Following Arthur Dent, we do the only thing that you can do with
2347  // an unsolvable problem: We ignore it with all our power.
2348  if ( !bMoveable )
2349  {
2351  {
2352  lcl_RecalcTable( *this, nullptr, aNotify );
2353  m_bLowersFormatted = true;
2354  m_bCalcLowers = false;
2355  }
2356  else if (m_bONECalcLowers)
2357  {
2358  lcl_RecalcRow(*static_cast<SwRowFrame*>(Lower()), LONG_MAX);
2359  m_bONECalcLowers = false;
2360  }
2361 
2362  // It does not make sense to cut off the last line if we are
2363  // not moveable:
2364  bLastRowHasToMoveToFollow = false;
2365 
2366  continue;
2367  }
2368 
2370  {
2371  lcl_RecalcTable( *this, nullptr, aNotify );
2372  m_bLowersFormatted = true;
2373  m_bCalcLowers = false;
2375  continue;
2376  }
2377 
2378  // First try to split the table. Condition:
2379  // 1. We have at least one non headline row
2380  // 2. If this row wants to keep, we need an additional row
2381  // 3. The table is allowed to split or we do not have a pIndPrev:
2382  SwFrame* pIndPrev = GetIndPrev();
2383  const SwRowFrame* pFirstNonHeadlineRow = GetFirstNonHeadlineRow();
2384  // #i120016# if this row wants to keep, allow split in case that all rows want to keep with next,
2385  // the table can not move forward as it is the first one and a split is in general allowed.
2386  const bool bAllowSplitOfRow = bTableRowKeep && !pIndPrev && AreAllRowsKeepWithNext(pFirstNonHeadlineRow);
2387  // tdf91083 MSCompat: this extends bAllowSplitOfRow (and perhaps should just replace it).
2388  // If the kept-together items cannot move to a new page, a table split is in general allowed.
2389  const bool bEmulateTableKeepSplitAllowed = bEmulateTableKeep && !IsKeepFwdMoveAllowed(/*IgnoreMyOwnKeepValue=*/true);
2390 
2391  if ( pFirstNonHeadlineRow && nUnSplitted > 0 &&
2392  ( bEmulateTableKeepSplitAllowed || bAllowSplitOfRow ||
2393  ( ( !bTableRowKeep || pFirstNonHeadlineRow->GetNext() ||
2394  !pFirstNonHeadlineRow->ShouldRowKeepWithNext()
2395  ) && ( !bDontSplit || !pIndPrev )
2396  ) ) )
2397  {
2398  // #i29438#
2399  // Special DoNotSplit cases:
2400  // We better avoid splitting of a row frame if we are inside a columned
2401  // section which has a height of 0, because this is not growable and thus
2402  // all kinds of unexpected things could happen.
2403  if ( IsInSct() && FindSctFrame()->Lower()->IsColumnFrame() &&
2404  0 == aRectFnSet.GetHeight(GetUpper()->getFrameArea())
2405  )
2406  {
2407  bTryToSplit = false;
2408  }
2409 
2410  // 1. Try: bTryToSplit = true => Try to split the row.
2411  // 2. Try: bTryToSplit = false => Split the table between the rows.
2412  if ( pFirstNonHeadlineRow->GetNext() || bTryToSplit )
2413  {
2414  SwTwips nDeadLine = aRectFnSet.GetPrtBottom(*GetUpper());
2415  if( IsInSct() || GetUpper()->IsInTab() ) // TABLE IN TABLE)
2416  nDeadLine = aRectFnSet.YInc( nDeadLine,
2417  GetUpper()->Grow( LONG_MAX, true ) );
2418 
2419  {
2420  SwFrameDeleteGuard g(Lower()); // tdf#134965 prevent RemoveFollowFlowLine()
2421  SetInRecalcLowerRow( true );
2422  ::lcl_RecalcRow(*static_cast<SwRowFrame*>(Lower()), nDeadLine);
2423  SetInRecalcLowerRow( false );
2424  }
2425  m_bLowersFormatted = true;
2426  aNotify.SetLowersComplete( true );
2427 
2428  // One more check if it's really necessary to split the table.
2429  // 1. The table either has to exceed the deadline or
2430  // 2. We explicitly want to cut off the last row.
2431  if( aRectFnSet.BottomDist( getFrameArea(), nDeadLine ) > 0 && !bLastRowHasToMoveToFollow )
2432  {
2433  continue;
2434  }
2435 
2436  // Set to false again as early as possible.
2437  bLastRowHasToMoveToFollow = false;
2438 
2439  // #i52781#
2440  // YaSC - Yet another special case:
2441  // If our upper is inside a table cell which is not allowed
2442  // to split, we do not try to split:
2443  if ( GetUpper()->IsInTab() )
2444  {
2445  const SwFrame* pTmpRow = GetUpper();
2446  while ( pTmpRow && !pTmpRow->IsRowFrame() )
2447  pTmpRow = pTmpRow->GetUpper();
2448  if ( pTmpRow && !static_cast<const SwRowFrame*>(pTmpRow)->IsRowSplitAllowed() )
2449  continue;
2450  }
2451 
2452  sal_uInt16 nMinNumOfLines = nRepeat;
2453 
2454  if ( bTableRowKeep )
2455  {
2456  const SwRowFrame* pTmpRow = GetFirstNonHeadlineRow();
2457  while ( pTmpRow && pTmpRow->ShouldRowKeepWithNext() )
2458  {
2459  ++nMinNumOfLines;
2460  pTmpRow = static_cast<const SwRowFrame*>(pTmpRow->GetNext());
2461  }
2462  }
2463 
2464  if ( !bTryToSplit )
2465  ++nMinNumOfLines;
2466 
2467  const SwTwips nBreakLine = aRectFnSet.YInc(
2468  aRectFnSet.GetTop(getFrameArea()),
2469  aRectFnSet.GetTopMargin(*this) +
2470  lcl_GetHeightOfRows( GetLower(), nMinNumOfLines ) );
2471 
2472  // Some more checks if we want to call the split algorithm or not:
2473  // The repeating lines / keeping lines still fit into the upper or
2474  // if we do not have an (in)direct Prev, we split anyway.
2475  if( aRectFnSet.YDiff(nDeadLine, nBreakLine) >=0
2476  || !pIndPrev || bEmulateTableKeepSplitAllowed )
2477  {
2478  aNotify.SetLowersComplete( false );
2479  bSplit = true;
2480 
2481  // An existing follow flow line has to be removed.
2482  if ( HasFollowFlowLine() )
2483  {
2484  if (!nThrowAwayValidLayoutLimit)
2485  continue;
2486  const bool bInitialLoopEndCondition(isFrameAreaDefinitionValid());
2488  const bool bFinalLoopEndCondition(isFrameAreaDefinitionValid());
2489 
2490  if (bInitialLoopEndCondition && !bFinalLoopEndCondition)
2491  {
2492  --nThrowAwayValidLayoutLimit;
2493  }
2494  }
2495 
2496  const bool bSplitError = !Split( nDeadLine, bTryToSplit, ( bTableRowKeep && !(bAllowSplitOfRow || bEmulateTableKeepSplitAllowed) ) );
2497 
2498  // tdf#130639 don't start table on a new page after the fallback "switch off repeating header"
2499  if (bSplitError && nRepeat > GetTable()->GetRowsToRepeat())
2500  {
2502  break;
2503  }
2504 
2505  if (!bTryToSplit && !bSplitError)
2506  {
2507  --nUnSplitted;
2508  }
2509 
2510  // #i29771# Two tries to split the table
2511  // If an error occurred during splitting. We start a second
2512  // try, this time without splitting of table rows.
2513  if ( bSplitError && HasFollowFlowLine() )
2515 
2516  // If splitting the table was successful or not,
2517  // we do not want to have 'empty' follow tables.
2518  if ( GetFollow() && !GetFollow()->GetFirstNonHeadlineRow() )
2519  Join();
2520 
2521  // We want to restore the situation before the failed
2522  // split operation as good as possible. Therefore we
2523  // do some more calculations. Note: Restricting this
2524  // to nDeadLine may not be enough.
2525  if ( bSplitError && bTryToSplit ) // no restart if we did not try to split: i72847, i79426
2526  {
2527  lcl_RecalcRow(*static_cast<SwRowFrame*>(Lower()), LONG_MAX);
2529  bTryToSplit = false;
2530  continue;
2531  }
2532 
2533  bTryToSplit = !bSplitError;
2534 
2535  //To avoid oscillations the Follow must become valid now
2536  if ( GetFollow() )
2537  {
2538  // #i80924#
2539  // After a successful split assure that the first row
2540  // is invalid. When graphics are present, this isn't hold.
2541  // Note: defect i80924 could also be fixed, if it is
2542  // assured, that <SwLayNotify::bLowersComplete> is only
2543  // set, if all lower are valid *and* are correct laid out.
2544  if ( !bSplitError && GetFollow()->GetLower() )
2545  {
2547  }
2548  SwRectFnSet fnRectX(GetFollow());
2549 
2550  static sal_uInt8 nStack = 0;
2551  if ( !StackHack::IsLocked() && nStack < 4 )
2552  {
2553  ++nStack;
2554  StackHack aHack;
2555  pAccess.reset();
2556 
2557  GetFollow()->MakeAll(pRenderContext);
2558 
2559  pAccess = std::make_unique<SwBorderAttrAccess>(SwFrame::GetCache(), this);
2560  pAttrs = pAccess->Get();
2561 
2562  GetFollow()->SetLowersFormatted(false);
2563  // #i43913# - lock follow table
2564  // to avoid its formatting during the format of
2565  // its content.
2566  const bool bOldJoinLock = GetFollow()->IsJoinLocked();
2567  GetFollow()->LockJoin();
2568  ::lcl_RecalcRow(*static_cast<SwRowFrame*>(GetFollow()->Lower()),
2569  fnRectX.GetBottom(GetFollow()->GetUpper()->getFrameArea()) );
2570  // #i43913#
2571  // #i63632# Do not unlock the
2572  // follow if it wasn't locked before.
2573  if ( !bOldJoinLock )
2574  GetFollow()->UnlockJoin();
2575 
2576  if ( !GetFollow()->GetFollow() )
2577  {
2578  SwFrame* pNxt = static_cast<SwFrame*>(GetFollow())->FindNext();
2579  if ( pNxt )
2580  {
2581  // #i18103# - no formatting of found next
2582  // frame, if it's a follow section of the
2583  // 'ColLocked' section, the follow table is
2584  // in.
2585  bool bCalcNxt = true;
2586  if ( GetFollow()->IsInSct() && pNxt->IsSctFrame() )
2587  {
2588  SwSectionFrame* pSct = GetFollow()->FindSctFrame();
2589  if ( pSct->IsColLocked() &&
2590  pSct->GetFollow() == pNxt )
2591  {
2592  bCalcNxt = false;
2593  }
2594  }
2595  if ( bCalcNxt )
2596  {
2597  // tdf#119109 follow was just formatted,
2598  // don't do it again now
2600  pNxt->Calc(pRenderContext);
2601  }
2602  }
2603  }
2604  --nStack;
2605  }
2606  else if ( GetFollow() == GetNext() )
2607  GetFollow()->MoveFwd( true, false );
2608  }
2609  continue;
2610  }
2611  }
2612  }
2613 
2614  // Set to false again as early as possible.
2615  bLastRowHasToMoveToFollow = false;
2616 
2617  if( IsInSct() && bMovedFwd && bMakePage && GetUpper()->IsColBodyFrame() &&
2618  GetUpper()->GetUpper()->GetUpper()->IsSctFrame() &&
2619  ( GetUpper()->GetUpper()->GetPrev() || GetIndPrev() ) &&
2620  static_cast<SwSectionFrame*>(GetUpper()->GetUpper()->GetUpper())->MoveAllowed(this) )
2621  {
2622  bMovedFwd = false;
2623  }
2624 
2625  // #i29771# Reset bTryToSplit flag on change of upper
2626  const SwFrame* pOldUpper = GetUpper();
2627 
2628  //Let's see if we find some place anywhere...
2629  if (!bMovedFwd)
2630  {
2631  // don't make the effort to move fwd if its known
2632  // conditions that are known not to work
2634  bMakePage = false;
2635  else if (!MoveFwd(bMakePage, false))
2636  bMakePage = false;
2637  }
2638 
2639  // #i29771# Reset bSplitError flag on change of upper
2640  if ( GetUpper() != pOldUpper )
2641  {
2642  bTryToSplit = true;
2643  nUnSplitted = 5;
2644  }
2645 
2646  aRectFnSet.Refresh(this);
2647  m_bCalcLowers = true;
2648  bMovedFwd = true;
2649  aNotify.SetLowersComplete( false );
2650  if ( IsFollow() )
2651  {
2652  // To avoid oscillations, master should not remain invalid
2653  SwTabFrame *pTab = FindMaster();
2654  if ( pTab->GetUpper() )
2655  pTab->GetUpper()->Calc(pRenderContext);
2656  pTab->Calc(pRenderContext);
2657  pTab->SetLowersFormatted( false );
2658  }
2659 
2660  //If my neighbour is my Follow at the same time, I'll swallow it up.
2661  if ( ( GetNext() && GetNext() == GetFollow() ) || !GetLower() )
2662  {
2663  if ( HasFollowFlowLine() )
2665  if ( GetFollow() )
2666  Join();
2667  }
2668 
2669  if ( bMovedBwd && GetUpper() )
2670  {
2671  //During flowing back the upper was animated to do a full repaint,
2672  //we can now skip this after the whole flowing back and forth.
2674  }
2675 
2677  {
2678  // #i44910# - format of lower frames unnecessary
2679  // and can cause layout loops, if table doesn't fit and isn't
2680  // allowed to split.
2681  SwTwips nDistToUpperPrtBottom =
2682  aRectFnSet.BottomDist( getFrameArea(), aRectFnSet.GetPrtBottom(*GetUpper()));
2683  if ( nDistToUpperPrtBottom >= 0 || bTryToSplit )
2684  {
2685  lcl_RecalcTable( *this, nullptr, aNotify );
2686  m_bLowersFormatted = true;
2687  m_bCalcLowers = false;
2688  if (!isFramePrintAreaValid())
2690  }
2691 #if OSL_DEBUG_LEVEL > 0
2692  else
2693  {
2694  OSL_FAIL( "debug assertion: <SwTabFrame::MakeAll()> - format of table lowers suppressed by fix i44910" );
2695  }
2696 #endif
2697  }
2698 
2699  } //while ( !isFrameAreaPositionValid() || !isFrameAreaSizeValid() || !isFramePrintAreaValid() )
2700 
2701  //If my direct predecessor is my master now, it can destroy me during the
2702  //next best opportunity.
2703  if ( IsFollow() )
2704  {
2705  SwFrame *pPre = GetPrev();
2706  if ( pPre && pPre->IsTabFrame() && static_cast<SwTabFrame*>(pPre)->GetFollow() == this)
2707  pPre->InvalidatePos();
2708  }
2709 
2710  m_bCalcLowers = m_bONECalcLowers = false;
2711  pAccess.reset();
2712  UnlockJoin();
2713  if ( bMovedFwd || bMovedBwd || !bOldValidPos )
2714  aNotify.SetInvaKeep();
2715 }
2716 
2719  tools::Long& rLeftOffset,
2720  tools::Long& rRightOffset ) const
2721 {
2722  bool bInvalidatePrtArea = false;
2723  const SwPageFrame *pPage = FindPageFrame();
2724  const SwFlyFrame* pMyFly = FindFlyFrame();
2725 
2726  // --> #108724# Page header/footer content doesn't have to wrap around
2727  // floating screen objects
2728 
2730  const bool bWrapAllowed = rIDSA.get(DocumentSettingId::USE_FORMER_TEXT_WRAPPING) ||
2731  ( !IsInFootnote() && nullptr == FindFooterOrHeader() );
2732 
2733  if ( pPage->GetSortedObjs() && bWrapAllowed )
2734  {
2735  SwRectFnSet aRectFnSet(this);
2736  const bool bConsiderWrapOnObjPos = rIDSA.get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION);
2737  tools::Long nPrtPos = aRectFnSet.GetTop(getFrameArea());
2738  nPrtPos = aRectFnSet.YInc( nPrtPos, rUpper );
2739  SwRect aRect( getFrameArea() );
2740  tools::Long nYDiff = aRectFnSet.YDiff( aRectFnSet.GetTop(getFramePrintArea()), rUpper );
2741  if( nYDiff > 0 )
2742  aRectFnSet.AddBottom( aRect, -nYDiff );
2743 
2744  bool bAddVerticalFlyOffsets = rIDSA.get(DocumentSettingId::ADD_VERTICAL_FLY_OFFSETS);
2745 
2746  for ( size_t i = 0; i < pPage->GetSortedObjs()->size(); ++i )
2747  {
2748  SwAnchoredObject* pAnchoredObj = (*pPage->GetSortedObjs())[i];
2749  if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
2750  {
2751  const SwRect aFlyRect = pFly->GetObjRectWithSpaces();
2752  // #i26945# - correction of conditions,
2753  // if Writer fly frame has to be considered:
2754  // - no need to check, if top of Writer fly frame differs
2755  // from FAR_AWAY, because it's also checked, if the Writer
2756  // fly frame rectangle overlaps with <aRect>
2757  // - no check, if bottom of anchor frame is prior the top of
2758  // the table, because Writer fly frames can be negative positioned.
2759  // - correct check, if the Writer fly frame is a lower of the
2760  // table, because table lines/rows can split and an at-character
2761  // anchored Writer fly frame could be positioned in the follow
2762  // flow line.
2763  // - add condition, that an existing anchor character text frame
2764  // has to be on the same page as the table.
2765  // E.g., it could happen, that the fly frame is still registered
2766  // at the page frame, the table is on, but it's anchor character
2767  // text frame has already changed its page.
2768  const SwTextFrame* pAnchorCharFrame = pFly->FindAnchorCharFrame();
2769  bool bConsiderFly =
2770  // #i46807# - do not consider invalid
2771  // Writer fly frames.
2772  (pFly->isFrameAreaDefinitionValid() || bAddVerticalFlyOffsets) &&
2773  // fly anchored at character
2774  pFly->IsFlyAtContentFrame() &&
2775  // fly overlaps with corresponding table rectangle
2776  aFlyRect.IsOver( aRect ) &&
2777  // fly isn't lower of table and
2778  // anchor character frame of fly isn't lower of table
2779  ( !IsAnLower( pFly ) &&
2780  ( !pAnchorCharFrame || !IsAnLower( pAnchorCharFrame ) ) ) &&
2781  // table isn't lower of fly
2782  !pFly->IsAnLower( this ) &&
2783  // fly is lower of fly, the table is in
2784  // #123274# - correction
2785  // assure that fly isn't a lower of a fly, the table isn't in.
2786  // E.g., a table in the body doesn't wrap around a graphic,
2787  // which is inside a frame.
2788  ( ( !pMyFly ||
2789  pMyFly->IsAnLower( pFly ) ) &&
2790  pMyFly == pFly->GetAnchorFrameContainingAnchPos()->FindFlyFrame() ) &&
2791  // anchor frame not on following page
2792  pPage->GetPhyPageNum() >=
2793  pFly->GetAnchorFrame()->FindPageFrame()->GetPhyPageNum() &&
2794  // anchor character text frame on same page
2795  ( !pAnchorCharFrame ||
2796  pAnchorCharFrame->FindPageFrame()->GetPhyPageNum() ==
2797  pPage->GetPhyPageNum() );
2798 
2799  if ( bConsiderFly )
2800  {
2801  const SwFrame* pFlyHeaderFooterFrame = pFly->GetAnchorFrame()->FindFooterOrHeader();
2802  const SwFrame* pThisHeaderFooterFrame = FindFooterOrHeader();
2803 
2804  if ( pFlyHeaderFooterFrame != pThisHeaderFooterFrame &&
2805  // #148493# If bConsiderWrapOnObjPos is set,
2806  // we want to consider the fly if it is located in the header and
2807  // the table is located in the body:
2808  ( !bConsiderWrapOnObjPos || nullptr != pThisHeaderFooterFrame || !pFlyHeaderFooterFrame->IsHeaderFrame() ) )
2809  bConsiderFly = false;
2810  }
2811 
2812  if ( bConsiderFly )
2813  {
2814  const SwFormatSurround &rSur = pFly->GetFormat()->GetSurround();
2815  const SwFormatHoriOrient &rHori= pFly->GetFormat()->GetHoriOrient();
2816  bool bShiftDown = css::text::WrapTextMode_NONE == rSur.GetSurround();
2817  if (!bShiftDown && bAddVerticalFlyOffsets)
2818  {
2819  if (rSur.GetSurround() == text::WrapTextMode_PARALLEL
2821  {
2822  // We know that wrapping was requested and the table frame overlaps with
2823  // the fly frame. Check if the print area overlaps with the fly frame as
2824  // well (in case the table does not use all the available width).
2825  basegfx::B1DRange aTabRange(
2826  aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea()),
2827  aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea())
2828  + aRectFnSet.GetWidth(getFramePrintArea()));
2829 
2830  // Ignore spacing when determining the left/right edge of the fly, like
2831  // Word does.
2832  const SwRect aFlyRectWithoutSpaces = pFly->GetObjRect();
2833  basegfx::B1DRange aFlyRange(aRectFnSet.GetLeft(aFlyRectWithoutSpaces),
2834  aRectFnSet.GetRight(aFlyRectWithoutSpaces));
2835 
2836  // If it does, shift the table down. Do this only in the compat case,
2837  // normally an SwFlyPortion is created instead that increases the height
2838  // of the first table row.
2839  bShiftDown = aTabRange.overlaps(aFlyRange);
2840  }
2841  }
2842 
2843  if (bShiftDown)
2844  {
2845  tools::Long nBottom = aRectFnSet.GetBottom(aFlyRect);
2846  if( aRectFnSet.YDiff( nPrtPos, nBottom ) < 0 )
2847  nPrtPos = nBottom;
2848  bInvalidatePrtArea = true;
2849  }
2850  if ( (css::text::WrapTextMode_RIGHT == rSur.GetSurround() ||
2851  css::text::WrapTextMode_PARALLEL == rSur.GetSurround())&&
2852  text::HoriOrientation::LEFT == rHori.GetHoriOrient() )
2853  {
2854  const tools::Long nWidth = aRectFnSet.XDiff(
2855  aRectFnSet.GetRight(aFlyRect),
2856  aRectFnSet.GetLeft(pFly->GetAnchorFrame()->getFrameArea()) );
2857  rLeftOffset = std::max( rLeftOffset, nWidth );
2858  bInvalidatePrtArea = true;
2859  }
2860  if ( (css::text::WrapTextMode_LEFT == rSur.GetSurround() ||
2861  css::text::WrapTextMode_PARALLEL == rSur.GetSurround())&&
2862  text::HoriOrientation::RIGHT == rHori.GetHoriOrient() )
2863  {
2864  const tools::Long nWidth = aRectFnSet.XDiff(
2865  aRectFnSet.GetRight(pFly->GetAnchorFrame()->getFrameArea()),
2866  aRectFnSet.GetLeft(aFlyRect) );
2867  rRightOffset = std::max( rRightOffset, nWidth );
2868  bInvalidatePrtArea = true;
2869  }
2870  }
2871  }
2872  }
2873  rUpper = aRectFnSet.YDiff( nPrtPos, aRectFnSet.GetTop(getFrameArea()) );
2874  }
2875 
2876  return bInvalidatePrtArea;
2877 }
2878 
2881 void SwTabFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorderAttrs *pAttrs )
2882 {
2883  OSL_ENSURE( pAttrs, "TabFrame::Format, pAttrs is 0." );
2884 
2885  SwRectFnSet aRectFnSet(this);
2886  if ( !isFrameAreaSizeValid() )
2887  {
2888  tools::Long nDiff = aRectFnSet.GetWidth(GetUpper()->getFramePrintArea()) -
2889  aRectFnSet.GetWidth(getFrameArea());
2890  if( nDiff )
2891  {
2893  aRectFnSet.AddRight( aFrm, nDiff );
2894  }
2895  }
2896 
2897  //VarSize is always the height.
2898  //For the upper/lower margins the same rules apply as for ContentFrames (see
2899  //MakePrtArea() of those).
2900 
2901  SwTwips nUpper = CalcUpperSpace( pAttrs );
2902 
2903  // We want to dodge the flys. Two possibilities:
2904  // 1. There are flys with SurroundNone, dodge them completely
2905  // 2. There are flys which only wrap on the right or the left side and
2906  // those are right or left aligned, those set the minimum for the margins
2907  tools::Long nTmpRight = -1000000,
2908  nLeftOffset = 0;
2909  if( CalcFlyOffsets( nUpper, nLeftOffset, nTmpRight ) )
2910  {
2911  setFramePrintAreaValid(false);
2912  }
2913 
2914  tools::Long nRightOffset = std::max( 0L, nTmpRight );
2915 
2916  SwTwips nLower = pAttrs->CalcBottomLine();
2917  // #i29550#
2918  if ( IsCollapsingBorders() )
2919  nLower += GetBottomLineSize();
2920 
2921  if ( !isFramePrintAreaValid() )
2922  {
2923  setFramePrintAreaValid(true);
2924 
2925  // The width of the PrintArea is given by the FrameFormat, the margins
2926  // have to be set accordingly.
2927  // Minimum margins are determined depending on borders and shadows.
2928  // The margins are set so that the PrintArea is aligned into the
2929  // Frame according to the adjustment.
2930  // If the adjustment is 0, the margins are set according to the border
2931  // attributes.
2932 
2933  const SwTwips nOldHeight = aRectFnSet.GetHeight(getFramePrintArea());
2934  const SwTwips nMax = aRectFnSet.GetWidth(getFrameArea());
2935 
2936  // OD 14.03.2003 #i9040# - adjust variable names.
2937  const SwTwips nLeftLine = pAttrs->CalcLeftLine();
2938  const SwTwips nRightLine = pAttrs->CalcRightLine();
2939 
2940  // The width possibly is a percentage value. If the table is inside
2941  // something else, the value refers to the environment. If it's in the
2942  // body then in the BrowseView the value refers to the screen width.
2943  const SwFormatFrameSize &rSz = GetFormat()->GetFrameSize();
2944  // OD 14.03.2003 #i9040# - adjust variable name.
2945  const SwTwips nWishedTableWidth = CalcRel( rSz );
2946 
2947  bool bCheckBrowseWidth = false;
2948 
2949  // OD 14.03.2003 #i9040# - insert new variables for left/right spacing.
2950  SwTwips nLeftSpacing = 0;
2951  SwTwips nRightSpacing = 0;
2952  switch ( GetFormat()->GetHoriOrient().GetHoriOrient() )
2953  {
2954  case text::HoriOrientation::LEFT:
2955  {
2956  // left indent:
2957  nLeftSpacing = nLeftLine + nLeftOffset;
2958  // OD 06.03.2003 #i9040# - correct calculation of right indent:
2959  // - Consider right indent given by right line attributes.
2960  // - Consider negative right indent.
2961  // wished right indent determined by wished table width and
2962  // left offset given by surround fly frames on the left:
2963  const SwTwips nWishRight = nMax - nWishedTableWidth - nLeftOffset;
2964  if ( nRightOffset > 0 )
2965  {
2966  // surrounding fly frames on the right
2967  // -> right indent is maximum of given right offset
2968  // and wished right offset.
2969  nRightSpacing = nRightLine + std::max( nRightOffset, nWishRight );
2970  }
2971  else
2972  {
2973  // no surrounding fly frames on the right
2974  // If intrinsic right indent (intrinsic means not considering
2975  // determined left indent) is negative,
2976  // then hold this intrinsic indent,
2977  // otherwise non negative wished right indent is hold.
2978  nRightSpacing = nRightLine +
2979  ( ( (nWishRight+nLeftOffset) < 0 ) ?
2980  (nWishRight+nLeftOffset) :
2981  std::max( 0L, nWishRight ) );
2982  }
2983  }
2984  break;
2985  case text::HoriOrientation::RIGHT:
2986  {
2987  // right indent:
2988  nRightSpacing = nRightLine + nRightOffset;
2989  // OD 06.03.2003 #i9040# - correct calculation of left indent:
2990  // - Consider left indent given by left line attributes.
2991  // - Consider negative left indent.
2992  // wished left indent determined by wished table width and
2993  // right offset given by surrounding fly frames on the right:
2994  const SwTwips nWishLeft = nMax - nWishedTableWidth - nRightOffset;
2995  if ( nLeftOffset > 0 )
2996  {
2997  // surrounding fly frames on the left
2998  // -> right indent is maximum of given left offset
2999  // and wished left offset.
3000  nLeftSpacing = nLeftLine + std::max( nLeftOffset, nWishLeft );
3001  }
3002  else
3003  {
3004  // no surrounding fly frames on the left
3005  // If intrinsic left indent (intrinsic = not considering
3006  // determined right indent) is negative,
3007  // then hold this intrinsic indent,
3008  // otherwise non negative wished left indent is hold.
3009  nLeftSpacing = nLeftLine +
3010  ( ( (nWishLeft+nRightOffset) < 0 ) ?
3011  (nWishLeft+nRightOffset) :
3012  std::max( 0L, nWishLeft ) );
3013  }
3014  }
3015  break;
3016  case text::HoriOrientation::CENTER:
3017  {
3018  // OD 07.03.2003 #i9040# - consider left/right line attribute.
3019  const SwTwips nCenterSpacing = ( nMax - nWishedTableWidth ) / 2;
3020  nLeftSpacing = nLeftLine +
3021  ( (nLeftOffset > 0) ?
3022  std::max( nCenterSpacing, nLeftOffset ) :
3023  nCenterSpacing );
3024  nRightSpacing = nRightLine +
3025  ( (nRightOffset > 0) ?
3026  std::max( nCenterSpacing, nRightOffset ) :
3027  nCenterSpacing );
3028  }
3029  break;
3030  case text::HoriOrientation::FULL:
3031  //This things grows over the whole width.
3032  //Only the free space needed for the border is taken into
3033  //account. The attribute values of LRSpace are ignored
3034  //intentionally.
3035  bCheckBrowseWidth = true;
3036  nLeftSpacing = nLeftLine + nLeftOffset;
3037  nRightSpacing = nRightLine + nRightOffset;
3038  break;
3040  {
3041  // The margins are defined by the LRSpace attribute.
3042  nLeftSpacing = pAttrs->CalcLeft( this );
3043  if( nLeftOffset )
3044  {
3045  // OD 07.03.2003 #i9040# - surround fly frames only, if
3046  // they overlap with the table.
3047  // Thus, take maximum of left spacing and left offset.
3048  // OD 10.03.2003 #i9040# - consider left line attribute.
3049  nLeftSpacing = std::max( nLeftSpacing, ( nLeftOffset + nLeftLine ) );
3050  }
3051  // OD 23.01.2003 #106895# - add 1st param to <SwBorderAttrs::CalcRight(..)>
3052  nRightSpacing = pAttrs->CalcRight( this );
3053  if( nRightOffset )
3054  {
3055  // OD 07.03.2003 #i9040# - surround fly frames only, if
3056  // they overlap with the table.
3057  // Thus, take maximum of right spacing and right offset.
3058  // OD 10.03.2003 #i9040# - consider right line attribute.
3059  nRightSpacing = std::max( nRightSpacing, ( nRightOffset + nRightLine ) );
3060  }
3061  }
3062  break;
3063  case text::HoriOrientation::LEFT_AND_WIDTH:
3064  {
3065  // count left border and width (Word specialty)
3066  // OD 10.03.2003 #i9040# - no width alignment in online mode.
3067  //bCheckBrowseWidth = true;
3068  nLeftSpacing = pAttrs->CalcLeft( this );
3069  if( nLeftOffset )
3070  {
3071  // OD 10.03.2003 #i9040# - surround fly frames only, if
3072  // they overlap with the table.
3073  // Thus, take maximum of right spacing and right offset.
3074  // OD 10.03.2003 #i9040# - consider left line attribute.
3075  nLeftSpacing = std::max( nLeftSpacing, ( pAttrs->CalcLeftLine() + nLeftOffset ) );
3076  }
3077  // OD 10.03.2003 #i9040# - consider right and left line attribute.
3078  const SwTwips nWishRight =
3079  nMax - (nLeftSpacing-pAttrs->CalcLeftLine()) - nWishedTableWidth;
3080  nRightSpacing = nRightLine +
3081  ( (nRightOffset > 0) ?
3082  std::max( nWishRight, nRightOffset ) :
3083  nWishRight );
3084  }
3085  break;
3086  default:
3087  OSL_FAIL( "Invalid orientation for table." );
3088  }
3089 
3090  // #i26250# - extend bottom printing area, if table
3091  // is last content inside a table cell.
3092  if ( GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::ADD_PARA_SPACING_TO_TABLE_CELLS) &&
3093  GetUpper()->IsInTab() && !GetIndNext() )
3094  {
3095  nLower += pAttrs->GetULSpace().GetLower();
3096  }
3097  aRectFnSet.SetYMargins( *this, nUpper, nLower );
3098  if( (nMax - MINLAY) < (nLeftSpacing + nRightSpacing) )
3099  aRectFnSet.SetXMargins( *this, 0, 0 );
3100  else
3101  aRectFnSet.SetXMargins( *this, nLeftSpacing, nRightSpacing );
3102 
3104  if ( bCheckBrowseWidth &&
3105  pSh && pSh->GetViewOptions()->getBrowseMode() &&
3106  GetUpper()->IsPageBodyFrame() && // only PageBodyFrames and not ColBodyFrames
3107  pSh->VisArea().Width() )
3108  {
3109  //Don't go beyond the edge of the visible area.
3110  //The page width can be bigger because objects with
3111  //"over-size" are possible (RootFrame::ImplCalcBrowseWidth())
3112  tools::Long nWidth = pSh->GetBrowseWidth();
3113  nWidth -= getFramePrintArea().Left();
3114  nWidth -= pAttrs->CalcRightLine();
3115 
3117  aPrt.Width( std::min( nWidth, aPrt.Width() ) );
3118  }
3119 
3120  if ( nOldHeight != aRectFnSet.GetHeight(getFramePrintArea()) )
3121  {
3122  setFrameAreaSizeValid(false);
3123  }
3124  }
3125 
3126  if ( isFrameAreaSizeValid() )
3127  return;
3128 
3129  setFrameAreaSizeValid(true);
3130 
3131  // The size is defined by the content plus the margins.
3132  SwTwips nRemaining = 0, nDiff;
3133  SwFrame *pFrame = m_pLower;
3134  while ( pFrame )
3135  {
3136  nRemaining += aRectFnSet.GetHeight(pFrame->getFrameArea());
3137  pFrame = pFrame->GetNext();
3138  }
3139  // And now add the margins
3140  nRemaining += nUpper + nLower;
3141 
3142  nDiff = aRectFnSet.GetHeight(getFrameArea()) - nRemaining;
3143  if ( nDiff > 0 )
3144  Shrink( nDiff );
3145  else if ( nDiff < 0 )
3146  Grow( -nDiff );
3147 }
3148 
3149 SwTwips SwTabFrame::GrowFrame( SwTwips nDist, bool bTst, bool bInfo )
3150 {
3151  SwRectFnSet aRectFnSet(this);
3152  SwTwips nHeight = aRectFnSet.GetHeight(getFrameArea());
3153  if( nHeight > 0 && nDist > ( LONG_MAX - nHeight ) )
3154  nDist = LONG_MAX - nHeight;
3155 
3156  if ( bTst && !IsRestrictTableGrowth() )
3157  return nDist;
3158 
3159  if ( GetUpper() )
3160  {
3161  SwRect aOldFrame( getFrameArea() );
3162 
3163  //The upper only grows as far as needed. nReal provides the distance
3164  //which is already available.
3165  SwTwips nReal = aRectFnSet.GetHeight(GetUpper()->getFramePrintArea());
3166  SwFrame *pFrame = GetUpper()->Lower();
3167  while ( pFrame && GetFollow() != pFrame )
3168  {
3169  nReal -= aRectFnSet.GetHeight(pFrame->getFrameArea());
3170  pFrame = pFrame->GetNext();
3171  }
3172 
3173  if ( nReal < nDist )
3174  {
3175  tools::Long nTmp = GetUpper()->Grow( nDist - std::max<long>(nReal, 0), bTst, bInfo );
3176 
3177  if ( IsRestrictTableGrowth() )
3178  {
3179  nTmp = std::min( nDist, nReal + nTmp );
3180  nDist = nTmp < 0 ? 0 : nTmp;
3181  }
3182  }
3183 
3184  if ( !bTst )
3185  {
3186  {
3188  aRectFnSet.AddBottom( aFrm, nDist );
3189  }
3190 
3191  SwRootFrame *pRootFrame = getRootFrame();
3192  if( pRootFrame && pRootFrame->IsAnyShellAccessible() &&
3193  pRootFrame->GetCurrShell() )
3194  {
3195  pRootFrame->GetCurrShell()->Imp()->MoveAccessibleFrame( this, aOldFrame );
3196  }
3197  }
3198  }
3199 
3200  if ( !bTst && ( nDist || IsRestrictTableGrowth() ) )
3201  {
3202  SwPageFrame *pPage = FindPageFrame();
3203  if ( GetNext() )
3204  {
3205  GetNext()->InvalidatePos_();
3206  if ( GetNext()->IsContentFrame() )
3207  GetNext()->InvalidatePage( pPage );
3208  }
3209  // #i28701# - Due to the new object positioning the
3210  // frame on the next page/column can flow backward (e.g. it was moved
3211  // forward due to the positioning of its objects ). Thus, invalivate this
3212  // next frame, if document compatibility option 'Consider wrapping style
3213  // influence on object positioning' is ON.
3214  else if ( GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) )
3215  {
3217  }
3218  InvalidateAll_();
3219  InvalidatePage( pPage );
3220  SetComplete();
3221 
3222  std::unique_ptr<SvxBrushItem> aBack = GetFormat()->makeBackgroundBrushItem();
3223  const SvxGraphicPosition ePos = aBack ? aBack->GetGraphicPos() : GPOS_NONE;
3224  if ( GPOS_NONE != ePos && GPOS_TILED != ePos )
3225  SetCompletePaint();
3226  }
3227 
3228  return nDist;
3229 }
3230 
3231 void SwTabFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem * pNew )
3232 {
3233  sal_uInt8 nInvFlags = 0;
3234  bool bAttrSetChg = pNew && RES_ATTRSET_CHG == pNew->Which();
3235 
3236  if( bAttrSetChg )
3237  {
3238  SfxItemIter aNIter( *static_cast<const SwAttrSetChg*>(pNew)->GetChgSet() );
3239  SfxItemIter aOIter( *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet() );
3240  const SfxPoolItem* pNItem = aNIter.GetCurItem();
3241  const SfxPoolItem* pOItem = aOIter.GetCurItem();
3242  SwAttrSetChg aOldSet( *static_cast<const SwAttrSetChg*>(pOld) );
3243  SwAttrSetChg aNewSet( *static_cast<const SwAttrSetChg*>(pNew) );
3244  do
3245  {
3246  UpdateAttr_(pOItem, pNItem, nInvFlags, &aOldSet, &aNewSet);
3247  pNItem = aNIter.NextItem();
3248  pOItem = aOIter.NextItem();
3249  } while (pNItem);
3250  if ( aOldSet.Count() || aNewSet.Count() )
3251  SwLayoutFrame::Modify( &aOldSet, &aNewSet );
3252  }
3253  else
3254  UpdateAttr_( pOld, pNew, nInvFlags );
3255 
3256  if ( nInvFlags == 0 )
3257  return;
3258 
3259  SwPageFrame *pPage = FindPageFrame();
3260  InvalidatePage( pPage );
3261  if ( nInvFlags & 0x02 )
3262  InvalidatePrt_();
3263  if ( nInvFlags & 0x40 )
3264  InvalidatePos_();
3265  SwFrame *pTmp = GetIndNext();
3266  if ( nullptr != pTmp )
3267  {
3268  if ( nInvFlags & 0x04 )
3269  {
3270  pTmp->InvalidatePrt_();
3271  if ( pTmp->IsContentFrame() )
3272  pTmp->InvalidatePage( pPage );
3273  }
3274  if ( nInvFlags & 0x10 )
3275  pTmp->SetCompletePaint();
3276  }
3277  if ( nInvFlags & 0x08 && nullptr != (pTmp = GetPrev()) )
3278  {
3279  pTmp->InvalidatePrt_();
3280  if ( pTmp->IsContentFrame() )
3281  pTmp->InvalidatePage( pPage );
3282  }
3283  if ( nInvFlags & 0x20 )
3284  {
3285  if ( pPage && pPage->GetUpper() && !IsFollow() )
3286  static_cast<SwRootFrame*>(pPage->GetUpper())->InvalidateBrowseWidth();
3287  }
3288  if ( nInvFlags & 0x80 )
3290 }
3291 
3292 void SwTabFrame::UpdateAttr_( const SfxPoolItem *pOld, const SfxPoolItem *pNew,
3293  sal_uInt8 &rInvFlags,
3294  SwAttrSetChg *pOldSet, SwAttrSetChg *pNewSet )
3295 {
3296  bool bClear = true;
3297  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
3298  switch( nWhich )
3299  {
3300  case RES_TBLHEADLINECHG:
3301  if ( IsFollow() )
3302  {
3303  // Delete remaining headlines:
3304  SwRowFrame* pLowerRow = nullptr;
3305  while ( nullptr != ( pLowerRow = static_cast<SwRowFrame*>(Lower()) ) && pLowerRow->IsRepeatedHeadline() )
3306  {
3307  pLowerRow->Cut();
3308  SwFrame::DestroyFrame(pLowerRow);
3309  }
3310 
3311  // insert new headlines
3312  const sal_uInt16 nNewRepeat = GetTable()->GetRowsToRepeat();
3313  for ( sal_uInt16 nIdx = 0; nIdx < nNewRepeat; ++nIdx )
3314  {
3315  bDontCreateObjects = true; //frmtool
3316  SwRowFrame* pHeadline = new SwRowFrame( *GetTable()->GetTabLines()[ nIdx ], this );
3317  pHeadline->SetRepeatedHeadline( true );
3318  bDontCreateObjects = false;
3319  pHeadline->Paste( this, pLowerRow );
3320  }
3321  }
3322  rInvFlags |= 0x02;
3323  break;
3324 
3325  case RES_FRM_SIZE:
3326  case RES_HORI_ORIENT:
3327  rInvFlags |= 0x22;
3328  break;
3329 
3330  case RES_PAGEDESC: //Attribute changes (on/off)
3331  if ( IsInDocBody() )
3332  {
3333  rInvFlags |= 0x40;
3334  SwPageFrame *pPage = FindPageFrame();
3335  if (pPage)
3336  {
3337  if ( !GetPrev() )
3338  CheckPageDescs( pPage );
3339  if (GetFormat()->GetPageDesc().GetNumOffset())
3340  static_cast<SwRootFrame*>(pPage->GetUpper())->SetVirtPageNum( true );
3341  SwDocPosUpdate aMsgHint( pPage->getFrameArea().Top() );
3343  }
3344  }
3345  break;
3346 
3347  case RES_BREAK:
3348  rInvFlags |= 0xC0;
3349  break;
3350 
3351  case RES_LAYOUT_SPLIT:
3352  if ( !IsFollow() )
3353  rInvFlags |= 0x40;
3354  break;
3355  case RES_FRAMEDIR :
3356  SetDerivedR2L( false );
3357  CheckDirChange();
3358  break;
3359  case RES_COLLAPSING_BORDERS :
3360  rInvFlags |= 0x02;
3362  break;
3363  case RES_UL_SPACE:
3364  rInvFlags |= 0x1C;
3365  [[fallthrough]];
3366 
3367  default:
3368  bClear = false;
3369  }
3370  if ( bClear )
3371  {
3372  if ( pOldSet || pNewSet )
3373  {
3374  if ( pOldSet )
3375  pOldSet->ClearItem( nWhich );
3376  if ( pNewSet )
3377  pNewSet->ClearItem( nWhich );
3378  }
3379  else
3380  SwLayoutFrame::Modify( pOld, pNew );
3381  }
3382 }
3383 
3384 bool SwTabFrame::GetInfo( SfxPoolItem &rHint ) const
3385 {
3386  if ( RES_VIRTPAGENUM_INFO == rHint.Which() && IsInDocBody() && !IsFollow() )
3387  {
3388  SwVirtPageNumInfo &rInfo = static_cast<SwVirtPageNumInfo&>(rHint);
3389  const SwPageFrame *pPage = FindPageFrame();
3390  if ( pPage )
3391  {
3392  if ( pPage == rInfo.GetOrigPage() && !GetPrev() )
3393  {
3394  // Should be the one (can temporarily be different, should we be
3395  // concerned about this possibility?)
3396  rInfo.SetInfo( pPage, this );
3397  return false;
3398  }
3399  if ( pPage->GetPhyPageNum() < rInfo.GetOrigPage()->GetPhyPageNum() &&
3400  (!rInfo.GetPage() || pPage->GetPhyPageNum() > rInfo.GetPage()->GetPhyPageNum()))
3401  {
3402  //This could be the one.
3403  rInfo.SetInfo( pPage, this );
3404  }
3405  }
3406  }
3407  return true;
3408 }
3409 
3411 {
3412  SwFrame *pRet = m_pLower;
3413 
3414  while ( pRet && !pRet->IsContentFrame() )
3415  {
3416  SwFrame *pOld = pRet;
3417 
3418  SwFrame *pTmp = pRet; // To skip empty section frames
3419  while ( pRet->GetNext() )
3420  {
3421  pRet = pRet->GetNext();
3422  if( !pRet->IsSctFrame() || static_cast<SwSectionFrame*>(pRet)->GetSection() )
3423  pTmp = pRet;
3424  }
3425  pRet = pTmp;
3426 
3427  if ( pRet->GetLower() )
3428  pRet = pRet->GetLower();
3429  if ( pRet == pOld )
3430  {
3431  // Check all other columns if there is a column based section with
3432  // an empty last column at the end of the last cell - this is done
3433  // by SwSectionFrame::FindLastContent
3434  if( pRet->IsColBodyFrame() )
3435  {
3436 #if OSL_DEBUG_LEVEL > 0
3437  SwSectionFrame* pSect = pRet->FindSctFrame();
3438  OSL_ENSURE( pSect, "Where does this column come from?");
3439  OSL_ENSURE( IsAnLower( pSect ), "Split cell?" );
3440 #endif
3441  return pRet->FindSctFrame()->FindLastContent();
3442  }
3443 
3444  // pRet may be a cell frame without a lower (cell has been split).
3445  // We have to find the last content the hard way:
3446 
3447  OSL_ENSURE( pRet->IsCellFrame(), "SwTabFrame::FindLastContent failed" );
3448  const SwFrame* pRow = pRet->GetUpper();
3449  while ( pRow && !pRow->GetUpper()->IsTabFrame() )
3450  pRow = pRow->GetUpper();
3451  const SwContentFrame* pContentFrame = pRow ? static_cast<const SwLayoutFrame*>(pRow)->ContainsContent() : nullptr;
3452  pRet = nullptr;
3453 
3454  while ( pContentFrame && static_cast<const SwLayoutFrame*>(pRow)->IsAnLower( pContentFrame ) )
3455  {
3456  pRet = const_cast<SwContentFrame*>(pContentFrame);
3457  pContentFrame = pContentFrame->GetNextContentFrame();
3458  }
3459  }
3460  }
3461 
3462  // #112929# There actually is a situation, which results in pRet = 0:
3463  // Insert frame, insert table via text <-> table. This gives you a frame
3464  // containing a table without any other content frames. Split the table
3465  // and undo the splitting. This operation gives us a table frame without
3466  // a lower.
3467  if ( pRet )
3468  {
3469  while ( pRet->GetNext() )
3470  pRet = pRet->GetNext();
3471 
3472  if (pRet->IsSctFrame())
3473  pRet = static_cast<SwSectionFrame*>(pRet)->FindLastContent();
3474  }
3475 
3476  assert(pRet == nullptr || dynamic_cast<SwContentFrame*>(pRet) || dynamic_cast<SwTabFrame*>(pRet));
3477  return pRet;
3478 }
3479 
3481 {
3482  SwFrame * pRet(FindLastContentOrTable());
3483 
3484  while (pRet && pRet->IsTabFrame()) // possibly there's only tables here!
3485  { // tdf#126138 skip table, don't look inside
3486  pRet = pRet->GetPrev();
3487  }
3488 
3489  assert(pRet == nullptr || dynamic_cast<SwContentFrame*>(pRet));
3490  return static_cast<SwContentFrame*>(pRet);
3491 }
3492 
3494 bool SwTabFrame::ShouldBwdMoved( SwLayoutFrame *pNewUpper, bool &rReformat )
3495 {
3496  rReformat = false;
3498  {
3499  //Flowing back Frames is quite time consuming unfortunately.
3500  //Most often the location where the Frame wants to flow to has the same
3501  //FixSize as the Frame itself. In such a situation it's easy to check if
3502  //the Frame will find enough space for its VarSize, if this is not the
3503  //case, the relocation can be skipped.
3504  //Checking if the Frame will find enough space is done by the Frame itself,
3505  //this also takes the possibility of splitting the Frame into account.
3506  //If the FixSize is different or Flys are involved (at the old or the
3507  //new position) the checks are pointless, the Frame then
3508  //needs to be relocated tentatively (if a bit of space is available).
3509 
3510  //The FixSize of the environments which contain tables is always the
3511  //width.
3512 
3513  SwPageFrame *pOldPage = FindPageFrame(),
3514  *pNewPage = pNewUpper->FindPageFrame();
3515  bool bMoveAnyway = false;
3516  SwTwips nSpace = 0;
3517 
3518  SwRectFnSet aRectFnSet(this);
3519  if ( !SwFlowFrame::IsMoveBwdJump() )
3520  {
3521 
3522  tools::Long nOldWidth = aRectFnSet.GetWidth(GetUpper()->getFramePrintArea());
3523  SwRectFnSet fnRectX(pNewUpper);
3524  tools::Long nNewWidth = fnRectX.GetWidth(pNewUpper->getFramePrintArea());
3525  if( std::abs( nNewWidth - nOldWidth ) < 2 )
3526  {
3527  bMoveAnyway = BwdMoveNecessary( pOldPage, getFrameArea() ) > 1;
3528  if( !bMoveAnyway )
3529  {
3530  SwRect aRect( pNewUpper->getFramePrintArea() );
3531  aRect.Pos() += pNewUpper->getFrameArea().Pos();
3532  const SwFrame *pPrevFrame = pNewUpper->Lower();
3533  while ( pPrevFrame && pPrevFrame != this )
3534  {
3535  fnRectX.SetTop( aRect, fnRectX.GetBottom(pPrevFrame->getFrameArea()) );
3536  pPrevFrame = pPrevFrame->GetNext();
3537  }
3538  bMoveAnyway = BwdMoveNecessary( pNewPage, aRect) > 1;
3539 
3540  // #i54861# Due to changes made in PrepareMake,
3541  // the tabfrm may not have a correct position. Therefore
3542  // it is possible that pNewUpper->getFramePrintArea().Height == 0. In this
3543  // case the above calculation of nSpace might give wrong
3544  // results and we really do not want to MoveBackward into a
3545  // 0 height frame. If nTmpSpace is already <= 0, we take this
3546  // value:
3547  const SwTwips nTmpSpace = fnRectX.GetHeight(aRect);
3548  if ( fnRectX.GetHeight(pNewUpper->getFramePrintArea()) > 0 || nTmpSpace <= 0 )
3549  nSpace = nTmpSpace;
3550 
3551  const SwViewShell *pSh = getRootFrame()->GetCurrShell();
3552  if( pSh && pSh->GetViewOptions()->getBrowseMode() )
3553  nSpace += pNewUpper->Grow( LONG_MAX, true );
3554  }
3555  }
3556  else if (!m_bLockBackMove)
3557  bMoveAnyway = true;
3558  }
3559  else if (!m_bLockBackMove)
3560  bMoveAnyway = true;
3561 
3562  if ( bMoveAnyway )
3563  {
3564  rReformat = true;
3565  return true;
3566  }
3567 
3568  bool bFits = nSpace > 0;
3569  if (!bFits && aRectFnSet.GetHeight(getFrameArea()) == 0)
3570  // This frame fits into pNewUpper in case it has no space, but this
3571  // frame is empty.
3572  bFits = nSpace >= 0;
3573  if (!m_bLockBackMove && bFits)
3574  {
3575  // #i26945# - check, if follow flow line
3576  // contains frame, which are moved forward due to its object
3577  // positioning.
3578  const SwRowFrame* pFirstRow = GetFirstNonHeadlineRow();
3579  if ( pFirstRow && pFirstRow->IsInFollowFlowRow() &&
3581  *(pFirstRow->GetFormat()->GetDoc()),
3582  *pFirstRow ) )
3583  {
3584  return false;
3585  }
3586  SwTwips nTmpHeight = CalcHeightOfFirstContentLine();
3587 
3588  // For some mysterious reason, I changed the good old
3589  // 'return nHeight <= nSpace' to 'return nTmpHeight < nSpace'.
3590  // This obviously results in problems with table frames in
3591  // sections. Remember: Every twip is sacred.
3592  return nTmpHeight <= nSpace;
3593  }
3594  }
3595  return false;
3596 }
3597 
3599 {
3600  OSL_ENSURE( GetUpper(), "Cut without Upper()." );
3601 
3602  SwPageFrame *pPage = FindPageFrame();
3603  InvalidatePage( pPage );
3604  SwFrame *pFrame = GetNext();
3605  if( pFrame )
3606  {
3607  // Possibly the old follow calculated a spacing to the predecessor
3608  // which is obsolete now when it becomes the first frame
3609  pFrame->InvalidatePrt_();
3610  pFrame->InvalidatePos_();
3611  if ( pFrame->IsContentFrame() )
3612  pFrame->InvalidatePage( pPage );
3613  if( IsInSct() && !GetPrev() )
3614  {
3615  SwSectionFrame* pSct = FindSctFrame();
3616  if( !pSct->IsFollow() )
3617  {
3618  pSct->InvalidatePrt_();
3619  pSct->InvalidatePage( pPage );
3620  }
3621  }
3622  }
3623  else
3624  {
3626  //Someone has to do the retouch: predecessor or upper
3627  pFrame = GetPrev();
3628  if ( nullptr != pFrame )
3629  {
3630  pFrame->SetRetouche();
3632  pFrame->InvalidatePos_();
3633  if ( pFrame->IsContentFrame() )
3634  pFrame->InvalidatePage( pPage );
3635  }
3636  //If I am (was) the only FlowFrame in my own upper, it has to do
3637  //the retouch. Moreover a new empty page might be created.
3638  else
3639  { SwRootFrame *pRoot = static_cast<SwRootFrame*>(pPage->GetUpper());
3640  pRoot->SetSuperfluous();
3642  if( IsInSct() )
3643  {
3644  SwSectionFrame* pSct = FindSctFrame();
3645  if( !pSct->IsFollow() )
3646  {
3647  pSct->InvalidatePrt_();
3648  pSct->InvalidatePage( pPage );
3649  }
3650  }
3651  }
3652  }
3653 
3654  //First remove, then shrink the upper.
3655  SwLayoutFrame *pUp = GetUpper();
3656  SwRectFnSet aRectFnSet(this);
3657  RemoveFromLayout();
3658  if ( pUp )
3659  {
3660  OSL_ENSURE( !pUp->IsFootnoteFrame(), "Table in Footnote." );
3661  SwSectionFrame *pSct = nullptr;
3662  // #126020# - adjust check for empty section
3663  // #130797# - correct fix #126020#
3664  if ( !pUp->Lower() && pUp->IsInSct() &&
3665  !(pSct = pUp->FindSctFrame())->ContainsContent() &&
3666  !pSct->ContainsAny( true ) )
3667  {
3668  if ( pUp->GetUpper() )
3669  {
3670  pSct->DelEmpty( false );
3671  pSct->InvalidateSize_();
3672  }
3673  }
3674  // table-in-footnote: delete empty footnote frames (like SwContentFrame::Cut)
3675  else if (!pUp->Lower() && pUp->IsFootnoteFrame() && !pUp->IsColLocked())
3676  {
3677  if (pUp->GetNext() && !pUp->GetPrev())
3678  {
3679  if (SwFrame *const pTmp = static_cast<SwLayoutFrame*>(pUp->GetNext())->ContainsAny())
3680  {
3681  pTmp->InvalidatePrt_();
3682  }
3683  }
3684  if (!pUp->IsDeleteForbidden())
3685  {
3686  pUp->Cut();
3687  SwFrame::DestroyFrame(pUp);
3688  }
3689  }
3690  else if( aRectFnSet.GetHeight(getFrameArea()) )
3691  {
3692  // OD 26.08.2003 #i18103# - *no* 'ColUnlock' of section -
3693  // undo changes of fix for #104992#
3694  pUp->Shrink( getFrameArea().Height() );
3695  }
3696  }
3697 
3698 
3699  if ( pPage && !IsFollow() && pPage->GetUpper() )
3700  static_cast<SwRootFrame*>(pPage->GetUpper())->InvalidateBrowseWidth();
3701 }
3702 
3703 void SwTabFrame::Paste( SwFrame* pParent, SwFrame* pSibling )
3704 {
3705  OSL_ENSURE( pParent, "No parent for pasting." );
3706  OSL_ENSURE( pParent->IsLayoutFrame(), "Parent is ContentFrame." );
3707  OSL_ENSURE( pParent != this, "I'm the parent myself." );
3708  OSL_ENSURE( pSibling != this, "I'm my own neighbour." );
3709  OSL_ENSURE( !GetPrev() && !GetNext() && !GetUpper(),
3710  "I'm still registered somewhere." );
3711 
3712  //Insert in the tree.
3713  InsertBefore( static_cast<SwLayoutFrame*>(pParent), pSibling );
3714 
3715  InvalidateAll_();
3716  SwPageFrame *pPage = FindPageFrame();
3717  InvalidatePage( pPage );
3718 
3719  if ( GetNext() )
3720  {
3721  GetNext()->InvalidatePos_();
3722  GetNext()->InvalidatePrt_();
3723  if ( GetNext()->IsContentFrame() )
3724  GetNext()->InvalidatePage( pPage );
3725  }
3726 
3727  SwRectFnSet aRectFnSet(this);
3728  if( aRectFnSet.GetHeight(getFrameArea()) )
3729  pParent->Grow( aRectFnSet.GetHeight(getFrameArea()) );
3730 
3731  if( aRectFnSet.GetWidth(getFrameArea()) != aRectFnSet.GetWidth(pParent->getFramePrintArea()) )
3733  if ( GetPrev() )
3734  {
3735  if ( !IsFollow() )
3736  {
3737  GetPrev()->InvalidateSize();
3738  if ( GetPrev()->IsContentFrame() )
3739  GetPrev()->InvalidatePage( pPage );
3740  }
3741  }
3742  else if ( GetNext() )
3743  // Take the spacing into account when dealing with ContentFrames.
3744  // There are two situations (both always happen at the same time):
3745  // a) The Content becomes the first in a chain
3746  // b) The new follower was previously the first in a chain
3747  GetNext()->InvalidatePrt_();
3748 
3749  if ( !pPage || IsFollow() )
3750  return;
3751 
3752  if ( pPage->GetUpper() )
3753  static_cast<SwRootFrame*>(pPage->GetUpper())->InvalidateBrowseWidth();
3754 
3755  if ( !GetPrev() )//At least needed for HTML with a table at the beginning.
3756  {
3758  if ( (pDesc && pDesc != pPage->GetPageDesc()) ||
3759  (!pDesc && pPage->GetPageDesc() != &GetFormat()->GetDoc()->GetPageDesc(0)) )
3760  CheckPageDescs( pPage );
3761  }
3762 }
3763 
3764 bool SwTabFrame::Prepare( const PrepareHint eHint, const void *, bool )
3765 {
3766  if( PrepareHint::BossChanged == eHint )
3767  CheckDirChange();
3768  return false;
3769 }
3770 
3771 SwRowFrame::SwRowFrame(const SwTableLine &rLine, SwFrame* pSib, bool bInsertContent)
3772  : SwLayoutFrame( rLine.GetFrameFormat(), pSib )
3773  , m_pTabLine( &rLine )
3774  , m_pFollowRow( nullptr )
3775  // #i29550#
3776  , mnTopMarginForLowers( 0 )
3777  , mnBottomMarginForLowers( 0 )
3778  , mnBottomLineSize( 0 )
3779  // --> split table rows
3780  , m_bIsFollowFlowRow( false )
3781  // <-- split table rows
3782  , m_bIsRepeatedHeadline( false )
3783  , m_bIsRowSpanLine( false )
3784  , m_bForceRowSplitAllowed( false )
3785  , m_bIsInSplit( false )
3786 {
3788 
3789  //Create the boxes and insert them.
3790  const SwTableBoxes &rBoxes = rLine.GetTabBoxes();
3791  SwFrame *pTmpPrev = nullptr;
3792  for ( size_t i = 0; i < rBoxes.size(); ++i )
3793  {
3794  SwCellFrame *pNew = new SwCellFrame( *rBoxes[i], this, bInsertContent );
3795  pNew->InsertBehind( this, pTmpPrev );
3796  pTmpPrev = pNew;
3797  }
3798 }
3799 
3801 {
3802  SwModify* pMod = GetFormat();
3803  if( pMod )
3804  {
3805  pMod->Remove( this );
3806  if( !pMod->HasWriterListeners() )
3807  delete pMod;
3808  }
3809 
3811 }
3812 
3814 {
3815 }
3816 
3818 {
3819  ::RegistFlys( pPage ? pPage : FindPageFrame(), this );
3820 }
3821 
3822 void SwRowFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem * pNew )
3823 {
3824  bool bAttrSetChg = pNew && RES_ATTRSET_CHG == pNew->Which();
3825  const SfxPoolItem *pItem = nullptr;
3826 
3827  if( bAttrSetChg )
3828  {
3829  const SwAttrSet* pChgSet = static_cast<const SwAttrSetChg*>(pNew)->GetChgSet();
3830  pChgSet->GetItemState( RES_FRM_SIZE, false, &pItem);
3831  if ( !pItem )
3832  pChgSet->GetItemState( RES_ROW_SPLIT, false, &pItem);
3833  }
3834  else if (pNew && (RES_FRM_SIZE == pNew->Which() || RES_ROW_SPLIT == pNew->Which()))
3835  pItem = pNew;
3836 
3837  if ( pItem )
3838  {
3839  SwTabFrame *pTab = FindTabFrame();
3840  if ( pTab )
3841  {
3842  const bool bInFirstNonHeadlineRow = pTab->IsFollow() &&
3843  this == pTab->GetFirstNonHeadlineRow();
3844  // #i35063#
3845  // Invalidation required is pRow is last row
3846  if ( bInFirstNonHeadlineRow || !GetNext() )
3847  {
3848  if ( bInFirstNonHeadlineRow )
3849  pTab = pTab->FindMaster();
3850  pTab->InvalidatePos();
3851  }
3852  }
3853  }
3854 
3855  SwLayoutFrame::Modify( pOld, pNew );
3856 }
3857 
3859 {
3860  if ( !GetNext() )
3861  {
3862  setFrameAreaSizeValid(false);
3863  }
3864 
3865  SwLayoutFrame::MakeAll(pRenderContext);
3866 }
3867 
3869 {
3870  SwRectFnSet aRectFnSet(pFrame);
3871  tools::Long nHeight = 0;
3872  const SwFrame* pTmp = pFrame->IsSctFrame() ?
3873  static_cast<const SwSectionFrame*>(pFrame)->ContainsContent() : pFrame;
3874  while( pTmp )
3875  {
3876  // #i26945# - consider follow text frames
3877  const SwSortedObjs* pObjs( nullptr );
3878  bool bIsFollow( false );
3879  if ( pTmp->IsTextFrame() && static_cast<const SwTextFrame*>(pTmp)->IsFollow() )
3880  {
3881  const SwFrame* pMaster;
3882  // #i46450# Master does not necessarily have
3883  // to exist if this function is called from JoinFrame() ->
3884  // Cut() -> Shrink()
3885  const SwTextFrame* pTmpFrame = static_cast<const SwTextFrame*>(pTmp);
3886  if ( pTmpFrame->GetPrev() && pTmpFrame->GetPrev()->IsTextFrame() &&
3887  static_cast<const SwTextFrame*>(pTmpFrame->GetPrev())->GetFollow() &&
3888  static_cast<const SwTextFrame*>(pTmpFrame->GetPrev())->GetFollow() != pTmp )
3889  pMaster = nullptr;
3890  else
3891  pMaster = pTmpFrame->FindMaster();
3892 
3893  if ( pMaster )
3894  {
3895  pObjs = static_cast<const SwTextFrame*>(pTmp)->FindMaster()->GetDrawObjs();
3896  bIsFollow = true;
3897  }
3898  }
3899  else
3900  {
3901  pObjs = pTmp->GetDrawObjs();
3902  }
3903  if ( pObjs )
3904  {
3905  for (SwAnchoredObject* pAnchoredObj : *pObjs)
3906  {
3907  // #i26945# - if <pTmp> is follow, the
3908  // anchor character frame has to be <pTmp>.
3909  if ( bIsFollow &&
3910  pAnchoredObj->FindAnchorCharFrame() != pTmp )
3911  {
3912  continue;
3913  }
3914  // #i26945# - consider also drawing objects
3915  {
3916  // OD 30.09.2003 #i18732# - only objects, which follow
3917  // the text flow have to be considered.
3918  const SwFrameFormat& rFrameFormat = pAnchoredObj->GetFrameFormat();
3919  bool bFollowTextFlow = rFrameFormat.GetFollowTextFlow().GetValue();
3920  bool bIsFarAway = pAnchoredObj->GetObjRect().Top() != FAR_AWAY;
3921  const SwPageFrame* pPageFrm = pTmp->FindPageFrame();
3922  bool bIsAnchoredToTmpFrm = false;
3923  if ( pPageFrm && pPageFrm->IsPageFrame() && pAnchoredObj->GetPageFrame())
3924  bIsAnchoredToTmpFrm = pAnchoredObj->GetPageFrame() == pPageFrm ||
3925  (pPageFrm->GetFormatPage().GetPhyPageNum() == pAnchoredObj->GetPageFrame()->GetFormatPage().GetPhyPageNum() + 1);
3926  const bool bConsiderObj =
3927  (rFrameFormat.GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR) &&
3928  bIsFarAway &&
3929  bFollowTextFlow && bIsAnchoredToTmpFrm;
3930  bool bWrapThrough = rFrameFormat.GetSurround().GetValue() == text::WrapTextMode_THROUGH;
3931  if (pFrame->IsInTab() && bFollowTextFlow && bWrapThrough)
3932  {
3933  // Ignore wrap-through objects when determining the cell height.
3934  // Normally FollowTextFlow requires a resize of the cell, but not in case of
3935  // wrap-through.
3936  continue;
3937  }
3938 
3939  if ( bConsiderObj )
3940  {
3941  const SwFormatFrameSize &rSz = rFrameFormat.GetFrameSize();
3942  if( !rSz.GetHeightPercent() )
3943  {
3944  const SwTwips nDistOfFlyBottomToAnchorTop =
3945  aRectFnSet.GetHeight(pAnchoredObj->GetObjRect()) +
3946  ( aRectFnSet.IsVert() ?
3947  pAnchoredObj->GetCurrRelPos().X() :
3948  pAnchoredObj->GetCurrRelPos().Y() );
3949 
3950  const SwTwips nFrameDiff =
3951  aRectFnSet.YDiff(
3952  aRectFnSet.GetTop(pTmp->getFrameArea()),
3953  aRectFnSet.GetTop(pFrame->getFrameArea()) );
3954 
3955  nHeight = std::max( nHeight, nDistOfFlyBottomToAnchorTop + nFrameDiff -
3956  aRectFnSet.GetHeight(pFrame->getFrameArea()) );
3957 
3958  // #i56115# The first height calculation
3959  // gives wrong results if pFrame->getFramePrintArea().Y() > 0. We do
3960  // a second calculation based on the actual rectangles of
3961  // pFrame and pAnchoredObj, and use the maximum of the results.
3962  // I do not want to remove the first calculation because
3963  // if clipping has been applied, using the GetCurrRelPos
3964  // might be the better option to calculate nHeight.
3965  const SwTwips nDistOfFlyBottomToAnchorTop2 = aRectFnSet.YDiff(
3966  aRectFnSet.GetBottom(pAnchoredObj->GetObjRect()),
3967  aRectFnSet.GetBottom(pFrame->getFrameArea()) );
3968 
3969  nHeight = std::max( nHeight, nDistOfFlyBottomToAnchorTop2 );
3970  }
3971  }
3972  }
3973  }
3974  }
3975  if( !pFrame->IsSctFrame() )
3976  break;
3977  pTmp = pTmp->FindNextCnt();
3978  if( !static_cast<const SwSectionFrame*>(pFrame)->IsAnLower( pTmp ) )
3979  break;
3980  }
3981  return nHeight;
3982 }
3983 
3984 static SwTwips lcl_CalcTopAndBottomMargin( const SwLayoutFrame& rCell, const SwBorderAttrs& rAttrs )
3985 {
3986  const SwTabFrame* pTab = rCell.FindTabFrame();
3987  SwTwips nTopSpace = 0;
3988  SwTwips nBottomSpace = 0;
3989 
3990  // #i29550#
3991  if ( pTab->IsCollapsingBorders() && rCell.Lower() && !rCell.Lower()->IsRowFrame() )
3992  {
3993  nTopSpace = static_cast<const SwRowFrame*>(rCell.GetUpper())->GetTopMarginForLowers();
3994  nBottomSpace = static_cast<const SwRowFrame*>(rCell.GetUpper())->GetBottomMarginForLowers();
3995  }
3996  else
3997  {
3998  if ( pTab->IsVertical() != rCell.IsVertical() )
3999  {
4000  nTopSpace = rAttrs.CalcLeft( &rCell );
4001  nBottomSpace = rAttrs.CalcRight( &rCell );
4002  }
4003  else
4004  {
4005  nTopSpace = rAttrs.CalcTop();
4006  nBottomSpace = rAttrs.CalcBottom();
4007  }
4008  }
4009 
4010  return nTopSpace + nBottomSpace;
4011 }
4012 
4013 // #i26945# - add parameter <_bConsiderObjs> in order to
4014 // control, if floating screen objects have to be considered for the minimal
4015 // cell height.
4017  const bool _bConsiderObjs,
4018  const SwBorderAttrs *pAttrs = nullptr )
4019 {
4020  SwRectFnSet aRectFnSet(_pCell);
4021  SwTwips nHeight = 0;
4022  const SwFrame* pLow = _pCell->Lower();
4023  if ( pLow )
4024  {
4025  tools::Long nFlyAdd = 0;
4026  while ( pLow )
4027  {
4028  if ( pLow->IsRowFrame() )
4029  {
4030  // #i26945#
4031  nHeight += ::lcl_CalcMinRowHeight( static_cast<const SwRowFrame*>(pLow),
4032  _bConsiderObjs );
4033  }
4034  else
4035  {
4036  tools::Long nLowHeight = aRectFnSet.GetHeight(pLow->getFrameArea());
4037  nHeight += nLowHeight;
4038  // #i26945#
4039  if ( _bConsiderObjs )
4040  {
4041  nFlyAdd = std::max( 0L, nFlyAdd - nLowHeight );
4042  nFlyAdd = std::max( nFlyAdd, ::CalcHeightWithFlys( pLow ) );
4043  }
4044  }
4045 
4046  pLow = pLow->GetNext();
4047  }
4048  if ( nFlyAdd )
4049  nHeight += nFlyAdd;
4050  }
4051  // The border/margin needs to be considered too, unfortunately it can't be
4052  // calculated using PrintArea and FrameArea because any or all of those
4053  // may be invalid.
4054  if ( _pCell->Lower() )
4055  {
4056  if ( pAttrs )
4057  nHeight += lcl_CalcTopAndBottomMargin( *_pCell, *pAttrs );
4058  else
4059  {
4060  SwBorderAttrAccess aAccess( SwFrame::GetCache(), _pCell );
4061  const SwBorderAttrs &rAttrs = *aAccess.Get();
4062  nHeight += lcl_CalcTopAndBottomMargin( *_pCell, rAttrs );
4063  }
4064  }
4065  return nHeight;
4066 }
4067 
4068 // #i26945# - add parameter <_bConsiderObjs> in order to control,
4069 // if floating screen objects have to be considered for the minimal cell height
4071  const bool _bConsiderObjs )
4072 {
4073  SwTwips nHeight = 0;
4074  if ( !_pRow->IsRowSpanLine() )
4075  {
4076  const SwFormatFrameSize &rSz = _pRow->GetFormat()->GetFrameSize();
4077  if ( _pRow->HasFixSize() )
4078  {
4079  OSL_ENSURE(SwFrameSize::Fixed == rSz.GetHeightSizeType(), "pRow claims to have fixed size");
4080  return rSz.GetHeight();
4081  }
4082  // If this row frame is being split, then row's minimal height shouldn't restrict
4083  // this frame's minimal height, because the rest will go to follow frame.
4084  else if ( !_pRow->IsInSplit() && rSz.GetHeightSizeType() == SwFrameSize::Minimum )
4085  {
4086  nHeight = rSz.GetHeight() - lcl_calcHeightOfRowBeforeThisFrame(*_pRow);
4087  }
4088  }
4089 
4090  SwRectFnSet aRectFnSet(_pRow);
4091  const SwCellFrame* pLow = static_cast<const SwCellFrame*>(_pRow->Lower());
4092  while ( pLow )
4093  {
4094  SwTwips nTmp = 0;
4095  const tools::Long nRowSpan = pLow->GetLayoutRowSpan();
4096  // --> NEW TABLES
4097  // Consider height of
4098  // 1. current cell if RowSpan == 1
4099  // 2. current cell if cell is "follow" cell of a cell with RowSpan == -1
4100  // 3. master cell if RowSpan == -1
4101  if ( 1 == nRowSpan )
4102  {
4103  nTmp = ::lcl_CalcMinCellHeight( pLow, _bConsiderObjs );
4104  }
4105  else if ( -1 == nRowSpan )
4106  {
4107  // Height of the last cell of a row span is height of master cell
4108  // minus the height of the other rows which are covered by the master
4109  // cell:
4110  const SwCellFrame& rMaster = pLow->FindStartEndOfRowSpanCell( true );
4111  nTmp = ::lcl_CalcMinCellHeight( &rMaster, _bConsiderObjs );
4112  const SwFrame* pMasterRow = rMaster.GetUpper();
4113  while ( pMasterRow && pMasterRow != _pRow )
4114  {
4115  nTmp -= aRectFnSet.GetHeight(pMasterRow->getFrameArea());
4116  pMasterRow = pMasterRow->GetNext();
4117  }
4118  }
4119  // <-- NEW TABLES
4120 
4121  // Do not consider rotated cells:
4122  if ( pLow->IsVertical() == aRectFnSet.IsVert() && nTmp > nHeight )
4123  nHeight = nTmp;
4124 
4125  pLow = static_cast<const SwCellFrame*>(pLow->GetNext());
4126  }
4127 
4128  return nHeight;
4129 }
4130 
4131 // #i29550#
4132 
4133 // Calculate the maximum of (TopLineSize + TopLineDist) over all lowers:
4134 static sal_uInt16 lcl_GetTopSpace( const SwRowFrame& rRow )
4135 {
4136  sal_uInt16 nTopSpace = 0;
4137  for ( const SwCellFrame* pCurrLower = static_cast<const SwCellFrame*>(rRow.Lower()); pCurrLower;
4138  pCurrLower = static_cast<const SwCellFrame*>(pCurrLower->GetNext()) )
4139  {
4140  sal_uInt16 nTmpTopSpace = 0;
4141  if ( pCurrLower->Lower() && pCurrLower->Lower()->IsRowFrame() )
4142  nTmpTopSpace = lcl_GetTopSpace( *static_cast<const SwRowFrame*>(pCurrLower->Lower()) );
4143  else
4144  {
4145  const SwAttrSet& rSet = const_cast<SwCellFrame*>(pCurrLower)->GetFormat()->GetAttrSet();
4146  const SvxBoxItem& rBoxItem = rSet.GetBox();
4147  nTmpTopSpace = rBoxItem.CalcLineSpace( SvxBoxItemLine::TOP, true );
4148  }
4149  nTopSpace = std::max( nTopSpace, nTmpTopSpace );
4150  }
4151  return nTopSpace;
4152 }
4153 
4154 // Calculate the maximum of TopLineDist over all lowers:
4155 static sal_uInt16 lcl_GetTopLineDist( const SwRowFrame& rRow )
4156 {
4157  sal_uInt16 nTopLineDist = 0;
4158  for ( const SwCellFrame* pCurrLower = static_cast<const SwCellFrame*>(rRow.Lower()); pCurrLower;
4159  pCurrLower = static_cast<const SwCellFrame*>(pCurrLower->GetNext()) )
4160  {
4161  sal_uInt16 nTmpTopLineDist = 0;
4162  if ( pCurrLower->Lower() && pCurrLower->Lower()->IsRowFrame() )
4163  nTmpTopLineDist = lcl_GetTopLineDist( *static_cast<const SwRowFrame*>(pCurrLower->Lower()) );
4164  else
4165  {
4166  const SwAttrSet& rSet = const_cast<SwCellFrame*>(pCurrLower)->GetFormat()->GetAttrSet();
4167  const SvxBoxItem& rBoxItem = rSet.GetBox();
4168  nTmpTopLineDist = rBoxItem.GetDistance( SvxBoxItemLine::TOP );
4169  }
4170  nTopLineDist = std::max( nTopLineDist, nTmpTopLineDist );
4171  }
4172  return nTopLineDist;
4173 }
4174 
4175 // Calculate the maximum of BottomLineSize over all lowers:
4176 static sal_uInt16 lcl_GetBottomLineSize( const SwRowFrame& rRow )
4177 {
4178  sal_uInt16 nBottomLineSize = 0;
4179  for ( const SwCellFrame* pCurrLower = static_cast<const SwCellFrame*>(rRow.Lower()); pCurrLower;
4180  pCurrLower = static_cast<const SwCellFrame*>(pCurrLower->GetNext()) )
4181  {
4182  sal_uInt16 nTmpBottomLineSize = 0;
4183  if ( pCurrLower->Lower() && pCurrLower->Lower()->IsRowFrame() )
4184  {
4185  const SwFrame* pRow = pCurrLower->GetLastLower();
4186  nTmpBottomLineSize = lcl_GetBottomLineSize( *static_cast<const SwRowFrame*>(pRow) );
4187  }
4188  else
4189  {
4190  const SwAttrSet& rSet = const_cast<SwCellFrame*>(pCurrLower)->GetFormat()->GetAttrSet();
4191  const SvxBoxItem& rBoxItem = rSet.GetBox();
4192  nTmpBottomLineSize = rBoxItem.CalcLineSpace( SvxBoxItemLine::BOTTOM, true ) -
4193  rBoxItem.GetDistance( SvxBoxItemLine::BOTTOM );
4194  }
4195  nBottomLineSize = std::max( nBottomLineSize, nTmpBottomLineSize );
4196  }
4197  return nBottomLineSize;
4198 }
4199 
4200 // Calculate the maximum of BottomLineDist over all lowers:
4201 static sal_uInt16 lcl_GetBottomLineDist( const SwRowFrame& rRow )
4202 {
4203  sal_uInt16 nBottomLineDist = 0;
4204  for ( const SwCellFrame* pCurrLower = static_cast<const SwCellFrame*>(rRow.Lower()); pCurrLower;
4205  pCurrLower = static_cast<const SwCellFrame*>(pCurrLower->GetNext()) )
4206  {
4207  sal_uInt16 nTmpBottomLineDist = 0;
4208  if ( pCurrLower->Lower() && pCurrLower->Lower()->IsRowFrame() )
4209  {
4210  const SwFrame* pRow = pCurrLower->GetLastLower();
4211  nTmpBottomLineDist = lcl_GetBottomLineDist( *static_cast<const SwRowFrame*>(pRow) );
4212  }
4213  else
4214  {
4215  const SwAttrSet& rSet = const_cast<SwCellFrame*>(pCurrLower)->GetFormat()->GetAttrSet();
4216  const SvxBoxItem& rBoxItem = rSet.GetBox();
4217  nTmpBottomLineDist = rBoxItem.GetDistance( SvxBoxItemLine::BOTTOM );
4218  }
4219  nBottomLineDist = std::max( nBottomLineDist, nTmpBottomLineDist );
4220  }
4221  return nBottomLineDist;
4222 }
4223 
4224 // tdf#104425: calculate the height of all row frames,
4225 // for which this frame is a follow.
4226 // When a row has fixed/minimum height, it may span over
4227 // several pages. The minimal height on this page should
4228 // take into account the sum of all the heights of previous
4229 // frames that constitute the table row on previous pages.
4230 // Otherwise, trying to split a too high row frame will
4231 // result in loop trying to create that too high row
4232 // on each following page
4234 {
4235  // We don't need to account for previous instances of repeated headlines
4236  if (rRow.IsRepeatedHeadline())
4237  return 0;
4238  SwRectFnSet aRectFnSet(&rRow);
4239  const SwTableLine* pLine = rRow.GetTabLine();
4240  const SwTabFrame* pTab = rRow.FindTabFrame();
4241  if (!pLine || !pTab || !pTab->IsFollow())
4242  return 0;
4243  SwTwips nResult = 0;
4245  for (const SwRowFrame* pCurRow = aIter.First(); pCurRow; pCurRow = aIter.Next())
4246  {
4247  if (pCurRow != &rRow && pCurRow->GetTabLine() == pLine)
4248  {
4249  // We've found another row frame that is part of the same table row
4250  const SwTabFrame* pCurTab = pCurRow->FindTabFrame();
4251  // A row frame may not belong to a table frame, when it is being cut, e.g., in
4252  // lcl_PostprocessRowsInCells().
4253  // Its SwRowFrame::Cut() has been called; it in turn called SwLayoutFrame::Cut(),
4254  // which nullified row's upper in RemoveFromLayout(), and then called Shrink()
4255  // for its former upper.
4256  // Regardless of whether it will be pasted back, or destroyed, currently it's not
4257  // part of layout, and its height does not count
4258  if (pCurTab && pCurTab->IsAnFollow(pTab))
4259  {
4260  // The found row frame belongs to a table frame that precedes
4261  // (above) this one in chain. So, include it in the sum
4262  nResult += aRectFnSet.GetHeight(pCurRow->getFrameArea());
4263  }
4264  }
4265  }
4266  return nResult;
4267 }
4268 
4269 void SwRowFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorderAttrs *pAttrs )
4270 {
4271  SwRectFnSet aRectFnSet(this);
4272  OSL_ENSURE( pAttrs, "SwRowFrame::Format without Attrs." );
4273 
4274  const bool bFix = mbFixSize;
4275 
4276  if ( !isFramePrintAreaValid() )
4277  {
4278  // RowFrames don't have borders/margins therefore the PrintArea always
4279  // matches the FrameArea.
4280  setFramePrintAreaValid(true);
4281 
4282  {
4284  aPrt.Left( 0 );
4285  aPrt.Top( 0 );
4286  aPrt.Width ( getFrameArea().Width() );
4287  aPrt.Height( getFrameArea().Height() );
4288  }
4289 
4290  // #i29550#
4291  // Here we calculate the top-printing area for the lower cell frames
4292  SwTabFrame* pTabFrame = FindTabFrame();
4293  if ( pTabFrame->IsCollapsingBorders() )
4294  {
4295  const sal_uInt16 nTopSpace = lcl_GetTopSpace( *this );
4296  const sal_uInt16 nTopLineDist = lcl_GetTopLineDist( *this );
4297  const sal_uInt16 nBottomLineSize = lcl_GetBottomLineSize( *this );
4298  const sal_uInt16 nBottomLineDist = lcl_GetBottomLineDist( *this );
4299 
4300  const SwRowFrame* pPreviousRow = nullptr;
4301 
4302  // #i32456#
4303  // In order to calculate the top printing area for the lower cell
4304  // frames, we have to find the 'previous' row frame and compare
4305  // the bottom values of the 'previous' row with the 'top' values
4306  // of this row. The best way to find the 'previous' row is to
4307  // use the table structure:
4308  const SwTable* pTable = pTabFrame->GetTable();
4309  const SwTableLine* pPrevTabLine = nullptr;
4310  const SwRowFrame* pTmpRow = this;
4311 
4312  while ( pTmpRow && !pPrevTabLine )
4313  {
4314  size_t nIdx = 0;
4315  const SwTableLines& rLines = pTmpRow->GetTabLine()->GetUpper() ?
4316  pTmpRow->GetTabLine()->GetUpper()->GetTabLines() :
4317  pTable->GetTabLines();
4318 
4319  while ( rLines[ nIdx ] != pTmpRow->GetTabLine() )
4320  ++nIdx;
4321 
4322  if ( nIdx > 0 )
4323  {
4324  // pTmpRow has a 'previous' row in the table structure:
4325  pPrevTabLine = rLines[ nIdx - 1 ];
4326  }
4327  else
4328  {
4329  // pTmpRow is a first row in the table structure.
4330  // We go up in the table structure:
4331  pTmpRow = pTmpRow->GetUpper()->GetUpper() &&
4332  pTmpRow->GetUpper()->GetUpper()->IsRowFrame() ?
4333  static_cast<const SwRowFrame*>( pTmpRow->GetUpper()->GetUpper() ) :
4334  nullptr;
4335  }
4336  }
4337 
4338  // If we found a 'previous' row, we look for the appropriate row frame:
4339  if ( pPrevTabLine )
4340  {
4341  SwIterator<SwRowFrame,SwFormat> aIter( *pPrevTabLine->GetFrameFormat() );
4342  for ( SwRowFrame* pRow = aIter.First(); pRow; pRow = aIter.Next() )
4343  {
4344  // #115759# - do *not* take repeated
4345  // headlines, because during split of table it can be
4346  // invalid and thus can't provide correct border values.
4347  if ( pRow->GetTabLine() == pPrevTabLine &&
4348  !pRow->IsRepeatedHeadline() )
4349  {
4350  pPreviousRow = pRow;
4351  break;
4352  }
4353  }
4354  }
4355 
4356  sal_uInt16 nTopPrtMargin = nTopSpace;
4357  if ( pPreviousRow )
4358  {
4359  const sal_uInt16 nTmpPrtMargin = pPreviousRow->GetBottomLineSize() + nTopLineDist;
4360  if ( nTmpPrtMargin > nTopPrtMargin )
4361  nTopPrtMargin = nTmpPrtMargin;
4362  }
4363 
4364  // table has to be notified if it has to change its lower
4365  // margin due to changes of nBottomLineSize:
4366  if ( !GetNext() && nBottomLineSize != GetBottomLineSize() )
4367  pTabFrame->InvalidatePrt_();
4368 
4369  // If there are rows nested inside this row, the nested rows
4370  // may not have been calculated yet. Therefore the
4371  // ::lcl_CalcMinRowHeight( this ) operation later in this
4372  // function cannot consider the correct border values. We
4373  // have to trigger the invalidation of the outer row frame
4374  // manually:
4375  // Note: If any further invalidations should be necessary, we
4376  // should consider moving the invalidation stuff to the
4377  // appropriate SwNotify object.
4378  if ( GetUpper()->GetUpper()->IsRowFrame() &&
4379  ( nBottomLineDist != GetBottomMarginForLowers() ||
4380  nTopPrtMargin != GetTopMarginForLowers() ) )
4382 
4383  SetBottomMarginForLowers( nBottomLineDist ); // 3.
4384  SetBottomLineSize( nBottomLineSize ); // 4.
4385  SetTopMarginForLowers( nTopPrtMargin ); // 5.
4386 
4387  }
4388  }
4389 
4390  while ( !isFrameAreaSizeValid() )
4391  {
4392  setFrameAreaSizeValid(true);
4393 
4394 #if OSL_DEBUG_LEVEL > 0
4395  if ( HasFixSize() )
4396  {
4397  const SwFormatFrameSize &rFrameSize = GetFormat()->GetFrameSize();
4398  OSL_ENSURE( rFrameSize.GetSize().Height() > 0, "Has it" );
4399  }
4400 #endif
4401  const SwTwips nDiff = aRectFnSet.GetHeight(getFrameArea()) -
4402  ( HasFixSize() && !IsRowSpanLine()
4403  ? pAttrs->GetSize().Height()
4404  // #i26945#
4405  : ::lcl_CalcMinRowHeight( this,
4406  FindTabFrame()->IsConsiderObjsForMinCellHeight() ) );
4407  if ( nDiff )
4408  {
4409  mbFixSize = false;
4410  if ( nDiff > 0 )
4411  Shrink( nDiff, false, true );
4412  else if ( nDiff < 0 )
4413  Grow( -nDiff );
4414  mbFixSize = bFix;
4415  }
4416  }
4417 
4418  // last row will fill the space in its upper.
4419  if ( GetNext() )
4420  return;
4421 
4422  //The last fills the remaining space in the upper.
4423  SwTwips nDiff = aRectFnSet.GetHeight(GetUpper()->getFramePrintArea());
4424  SwFrame *pSibling = GetUpper()->Lower();
4425  do
4426  { nDiff -= aRectFnSet.GetHeight(pSibling->getFrameArea());
4427  pSibling = pSibling->GetNext();
4428  } while ( pSibling );
4429  if ( nDiff > 0 )
4430  {
4431  mbFixSize = false;
4432  Grow( nDiff );
4433  mbFixSize = bFix;
4434  setFrameAreaSizeValid(true);
4435  }
4436 }
4437 
4438 void SwRowFrame::AdjustCells( const SwTwips nHeight, const bool bHeight )
4439 {
4440  SwFrame *pFrame = Lower();
4441  if ( bHeight )
4442  {
4443  SwRootFrame *pRootFrame = getRootFrame();
4444  SwRectFnSet aRectFnSet(this);
4445  SwRect aOldFrame;
4446 
4447  while ( pFrame )
4448  {
4449  SwFrame* pNotify = nullptr;
4450 
4451  SwCellFrame* pCellFrame = static_cast<SwCellFrame*>(pFrame);
4452 
4453  // NEW TABLES
4454  // Which cells need to be adjusted if the current row changes
4455  // its height?
4456 
4457  // Current frame is a covered frame:
4458  // Set new height for covered cell and adjust master cell:
4459  if ( pCellFrame->GetTabBox()->getRowSpan() < 1 )
4460  {
4461  // Set height of current (covered) cell to new line height.
4462  const tools::Long nDiff = nHeight - aRectFnSet.GetHeight(pCellFrame->getFrameArea());
4463  if ( nDiff )
4464  {
4465  {
4467  aRectFnSet.AddBottom( aFrm, nDiff );
4468  }
4469 
4470  pCellFrame->InvalidatePrt_();
4471  }
4472  }
4473 
4474  SwCellFrame* pToAdjust = nullptr;
4475  SwFrame* pToAdjustRow = nullptr;
4476 
4477  // If current frame is covered frame, we still want to adjust the
4478  // height of the cell starting the row span
4479  if ( pCellFrame->GetLayoutRowSpan() < 1 )
4480  {
4481  pToAdjust = const_cast< SwCellFrame*>(&pCellFrame->FindStartEndOfRowSpanCell( true ));
4482  pToAdjustRow = pToAdjust->GetUpper();
4483  }
4484  else
4485  {
4486  pToAdjust = pCellFrame;
4487  pToAdjustRow = this;
4488  }
4489 
4490  // Set height of master cell to height of all lines spanned by this line.
4491  tools::Long nRowSpan = pToAdjust->GetLayoutRowSpan();
4492  SwTwips nSumRowHeight = 0;
4493  while ( pToAdjustRow )
4494  {
4495  // Use new height for the current row:
4496  nSumRowHeight += pToAdjustRow == this ?
4497  nHeight :
4498  aRectFnSet.GetHeight(pToAdjustRow->getFrameArea());
4499 
4500  if ( nRowSpan-- == 1 )
4501  break;
4502 
4503  pToAdjustRow = pToAdjustRow->GetNext();
4504  }
4505 
4506  if ( pToAdjustRow && pToAdjustRow != this )
4507  pToAdjustRow->InvalidateSize_();
4508 
4509  const tools::Long nDiff = nSumRowHeight - aRectFnSet.GetHeight(pToAdjust->getFrameArea());
4510  if ( nDiff )
4511  {
4512  aOldFrame = pToAdjust->getFrameArea();
4514  aRectFnSet.AddBottom( aFrm, nDiff );
4515  pNotify = pToAdjust;
4516  }
4517 
4518  if ( pNotify )
4519  {
4520  if( pRootFrame && pRootFrame->IsAnyShellAccessible() && pRootFrame->GetCurrShell() )
4521  pRootFrame->GetCurrShell()->Imp()->MoveAccessibleFrame( pNotify, aOldFrame );
4522 
4523  pNotify->InvalidatePrt_();
4524  }
4525 
4526  pFrame = pFrame->GetNext();
4527  }
4528  }
4529  else
4530  { while ( pFrame )
4531  {
4532  pFrame->InvalidateAll_();
4533  pFrame = pFrame->GetNext();
4534  }
4535  }
4536  InvalidatePage();
4537 }
4538 
4540 {
4541  SwTabFrame *pTab = FindTabFrame();
4542  if ( pTab && pTab->IsFollow() && this == pTab->GetFirstNonHeadlineRow() )
4543  {
4544  pTab->FindMaster()->InvalidatePos();
4545  }
4546 
4548 }
4549 
4550 SwTwips SwRowFrame::GrowFrame( SwTwips nDist, bool bTst, bool bInfo )
4551 {
4552  SwTwips nReal = 0;
4553 
4554  SwTabFrame* pTab = FindTabFrame();
4555  SwRectFnSet aRectFnSet(pTab);
4556 
4557  bool bRestrictTableGrowth;
4558  bool bHasFollowFlowLine = pTab->HasFollowFlowLine();
4559 
4560  if ( GetUpper()->IsTabFrame() )
4561  {
4562  const SwRowFrame* pFollowFlowRow = IsInSplitTableRow();
4563  bRestrictTableGrowth = pFollowFlowRow && !pFollowFlowRow->IsRowSpanLine();
4564  }
4565  else
4566  {
4567  OSL_ENSURE( GetUpper()->IsCellFrame(), "RowFrame->GetUpper neither table nor cell" );
4568  bRestrictTableGrowth = GetFollowRow() && bHasFollowFlowLine;
4569  OSL_ENSURE( !bRestrictTableGrowth || !GetNext(),
4570  "GetFollowRow for row frame that has a Next" );
4571 
4572  // There may still be some space left in my direct upper:
4573  const SwTwips nAdditionalSpace =
4574  aRectFnSet.BottomDist( getFrameArea(), aRectFnSet.GetPrtBottom(*GetUpper()->GetUpper()) );
4575  if ( bRestrictTableGrowth && nAdditionalSpace > 0 )
4576  {
4577  nReal = std::min( nAdditionalSpace, nDist );
4578  nDist -= nReal;
4579  if ( !bTst )
4580  {
4582  aRectFnSet.AddBottom( aFrm, nReal );
4583  }
4584  }
4585  }
4586 
4587  if ( bRestrictTableGrowth )
4588  pTab->SetRestrictTableGrowth( true );
4589  else
4590  {
4591  // Ok, this looks like a hack, indeed, it is a hack.
4592  // If the current row frame is inside another cell frame,
4593  // and the current row frame has no follow, it should not
4594  // be allowed to grow. In fact, setting bRestrictTableGrowth
4595  // to 'false' does not work, because the surrounding RowFrame
4596  // would set this to 'true'.
4597  pTab->SetFollowFlowLine( false );
4598  }
4599 
4600  nReal += SwLayoutFrame::GrowFrame( nDist, bTst, bInfo);
4601 
4602  pTab->SetRestrictTableGrowth( false );
4603  pTab->SetFollowFlowLine( bHasFollowFlowLine );
4604 
4605  //Update the height of the cells to the newest value.
4606  if ( !bTst )
4607  {
4608  SwRectFnSet fnRectX(this);
4609  AdjustCells( fnRectX.GetHeight(getFramePrintArea()) + nReal, true );
4610  if ( nReal )
4611  SetCompletePaint();
4612  }
4613 
4614  return nReal;
4615 }
4616 
4617 SwTwips SwRowFrame::ShrinkFrame( SwTwips nDist, bool bTst, bool bInfo )
4618 {
4619  SwRectFnSet aRectFnSet(this);
4620  if( HasFixSize() )
4621  {
4622  AdjustCells( aRectFnSet.GetHeight(getFramePrintArea()), true );
4623  return 0;
4624  }
4625 
4626  // bInfo may be set to true by SwRowFrame::Format; we need to handle this
4627  // here accordingly
4628  const bool bShrinkAnyway = bInfo;
4629 
4630  //Only shrink as much as the content of the biggest cell allows.
4631  SwTwips nRealDist = nDist;
4632  SwFormat* pMod = GetFormat();
4633  if (pMod)
4634  {
4635  const SwFormatFrameSize &rSz = pMod->GetFrameSize();
4636  SwTwips nMinHeight = 0;
4638  nMinHeight = std::max(rSz.GetHeight() - lcl_calcHeightOfRowBeforeThisFrame(*this),
4639  0L);
4640 
4641  // Only necessary to calculate minimal row height if height
4642  // of pRow is at least nMinHeight. Otherwise nMinHeight is the
4643  // minimum height.
4644  if( nMinHeight < aRectFnSet.GetHeight(getFrameArea()) )
4645  {
4646  // #i26945#
4647  OSL_ENSURE( FindTabFrame(), "<SwRowFrame::ShrinkFrame(..)> - no table frame -> crash." );
4648  const bool bConsiderObjs( FindTabFrame()->IsConsiderObjsForMinCellHeight() );
4649  nMinHeight = lcl_CalcMinRowHeight( this, bConsiderObjs );
4650  }
4651 
4652  if ( (aRectFnSet.GetHeight(getFrameArea()) - nRealDist) < nMinHeight )
4653  nRealDist = aRectFnSet.GetHeight(getFrameArea()) - nMinHeight;
4654  }
4655  if ( nRealDist < 0 )
4656  nRealDist = 0;
4657 
4658  SwTwips nReal = nRealDist;
4659  if ( nReal )
4660  {
4661  if ( !bTst )
4662  {
4663  SwTwips nHeight = aRectFnSet.GetHeight(getFrameArea());
4665  aRectFnSet.SetHeight( aFrm, nHeight - nReal );
4666 
4667  if( IsVertical() && !IsVertLR() )
4668  {
4669  aFrm.Pos().AdjustX(nReal );
4670  }
4671  }
4672 
4673  SwLayoutFrame* pFrame = GetUpper();
4674  SwTwips nTmp = pFrame ? pFrame->Shrink(nReal, bTst) : 0;
4675  if ( !bShrinkAnyway && !GetNext() && nTmp != nReal )
4676  {
4677  //The last one gets the leftover in the upper and therefore takes
4678  //care (otherwise: endless loop)
4679  if ( !bTst )
4680  {
4681  nReal -= nTmp;
4682  SwTwips nHeight = aRectFnSet.GetHeight(getFrameArea());
4684  aRectFnSet.SetHeight( aFrm, nHeight + nReal );
4685 
4686  if( IsVertical() && !IsVertLR() )
4687  {
4688  aFrm.Pos().AdjustX( -nReal );
4689  }
4690  }
4691  nReal = nTmp;
4692  }
4693  }
4694 
4695  // Invalidate appropriately and update the height to the newest value.
4696  if ( !bTst )
4697  {
4698  if ( nReal )
4699  {
4700  if ( GetNext() )
4701  GetNext()->InvalidatePos_();
4702  InvalidateAll_();
4703  SetCompletePaint();
4704 
4705  SwTabFrame *pTab = FindTabFrame();
4706  if ( !pTab->IsRebuildLastLine()
4707  && pTab->IsFollow()
4708  && this == pTab->GetFirstNonHeadlineRow()
4709  && !pTab->IsInRecalcLowerRow() )
4710  {
4711  SwTabFrame* pMasterTab = pTab->FindMaster();
4712  pMasterTab->InvalidatePos();
4713  }
4714  }
4715  AdjustCells( aRectFnSet.GetHeight(getFramePrintArea()) - nReal, true );
4716  }
4717  return nReal;
4718 }
4719 
4721 {
4722  // Fixed size rows are never allowed to split:
4723  if ( HasFixSize() )
4724  {
4725  OSL_ENSURE( SwFrameSize::Fixed == GetFormat()->GetFrameSize().GetHeightSizeType(), "pRow claims to have fixed size" );
4726  return false;
4727  }
4728 
4729  // Repeated headlines are never allowed to split:
4730  const SwTabFrame* pTabFrame = FindTabFrame();
4731  if ( pTabFrame->GetTable()->GetRowsToRepeat() > 0 &&
4732  pTabFrame->IsInHeadline( *this ) )
4733  return false;
4734 
4735  if ( IsForceRowSplitAllowed() )
4736  return true;
4737 
4738  const SwTableLineFormat* pFrameFormat = static_cast<SwTableLineFormat*>(GetTabLine()->GetFrameFormat());
4739  const SwFormatRowSplit& rLP = pFrameFormat->GetRowSplit();
4740  return rLP.GetValue();
4741 }
4742 
4743 bool SwRowFrame::ShouldRowKeepWithNext( const bool bCheckParents ) const
4744 {
4745  // No KeepWithNext if nested in another table
4746  if ( GetUpper()->GetUpper()->IsCellFrame() )
4747  return false;
4748 
4749  const SwCellFrame* pCell = static_cast<const SwCellFrame*>(Lower());
4750  const SwFrame* pText = pCell->Lower();
4751 
4752  return pText && pText->IsTextFrame() &&
4753  static_cast<const SwTextFrame*>(pText)->GetTextNodeForParaProps()->GetSwAttrSet().GetKeep(bCheckParents).GetValue();
4754 }
4755 
4756 SwCellFrame::SwCellFrame(const SwTableBox &rBox, SwFrame* pSib, bool bInsertContent)
4757  : SwLayoutFrame( rBox.GetFrameFormat(), pSib )
4758  , m_pTabBox( &rBox )
4759 {
4761 
4762  if ( !bInsertContent )
4763  return;
4764 
4765  //If a StartIdx is available, ContentFrames are added in the cell, otherwise
4766  //Rows have to be present and those are added.
4767  if ( rBox.GetSttIdx() )
4768  {
4769  sal_uLong nIndex = rBox.GetSttIdx();
4770  ::InsertCnt_( this, rBox.GetFrameFormat()->GetDoc(), ++nIndex );
4771  }
4772  else
4773  {
4774  const SwTableLines &rLines = rBox.GetTabLines();
4775  SwFrame *pTmpPrev = nullptr;
4776  for ( size_t i = 0; i < rLines.size(); ++i )
4777  {
4778  SwRowFrame *pNew = new SwRowFrame( *rLines[i], this, bInsertContent );
4779  pNew->InsertBehind( this, pTmpPrev );
4780  pTmpPrev = pNew;
4781  }
4782  }
4783 }
4784 
4786 {
4787  SwModify* pMod = GetFormat();
4788  if( pMod )
4789  {
4790  // At this stage the lower frames aren't destroyed already,
4791  // therefore we have to do a recursive dispose.
4792  SwRootFrame *pRootFrame = getRootFrame();
4793  if( pRootFrame && pRootFrame->IsAnyShellAccessible() &&
4794  pRootFrame->GetCurrShell() )
4795  {
4796  pRootFrame->GetCurrShell()->Imp()->DisposeAccessibleFrame( this, true );
4797  }
4798 
4799  pMod->Remove( this );
4800  if( !pMod->HasWriterListeners() )
4801  delete pMod;
4802  }
4803 
4805 }
4806 
4808 {
4809 }
4810 
4811 static bool lcl_ArrangeLowers( SwLayoutFrame *pLay, tools::Long lYStart, bool bInva )
4812 {
4813  bool bRet = false;
4814  SwFrame *pFrame = pLay->Lower();
4815  SwRectFnSet aRectFnSet(pLay);
4816  while ( pFrame )
4817  {
4818  tools::Long nFrameTop = aRectFnSet.GetTop(pFrame->getFrameArea());
4819  if( nFrameTop != lYStart )
4820  {
4821  bRet = true;
4822  const tools::Long lDiff = aRectFnSet.YDiff( lYStart, nFrameTop );
4823  const tools::Long lDiffX = lYStart - nFrameTop;
4824 
4825  {
4827  aRectFnSet.SubTop( aFrm, -lDiff );
4828  aRectFnSet.AddBottom( aFrm, lDiff );
4829  }
4830 
4831  pFrame->SetCompletePaint();
4832 
4833  if ( !pFrame->GetNext() )
4834  pFrame->SetRetouche();
4835  if( bInva )
4837  if ( pFrame->IsLayoutFrame() && static_cast<SwLayoutFrame*>(pFrame)->Lower() )
4838  lcl_ArrangeLowers( static_cast<SwLayoutFrame*>(pFrame),
4839  aRectFnSet.GetTop(static_cast<SwLayoutFrame*>(pFrame)->Lower()->getFrameArea())
4840  + lDiffX, bInva );
4841  if ( pFrame->GetDrawObjs() )
4842  {
4843  for ( size_t i = 0; i < pFrame->GetDrawObjs()->size(); ++i )
4844  {
4845  SwAnchoredObject* pAnchoredObj = (*pFrame->GetDrawObjs())[i];
4846  // #i26945# - check, if anchored object
4847  // is lower of layout frame by checking, if the anchor
4848  // frame, which contains the anchor position, is a lower
4849  // of the layout frame.
4850  if ( !pLay->IsAnLower( pAnchoredObj->GetAnchorFrameContainingAnchPos() ) )
4851  {
4852  continue;
4853  }
4854  // #i52904# - distinguish between anchored
4855  // objects, whose vertical position depends on its anchor
4856  // frame and whose vertical position is independent
4857  // from its anchor frame.
4858  bool bVertPosDepOnAnchor( true );
4859  {
4860  SwFormatVertOrient aVert( pAnchoredObj->GetFrameFormat().GetVertOrient() );
4861  switch ( aVert.GetRelationOrient() )
4862  {
4863  case text::RelOrientation::PAGE_FRAME:
4864  case text::RelOrientation::PAGE_PRINT_AREA:
4865  bVertPosDepOnAnchor = false;
4866  break;
4867  default: break;
4868  }
4869  }
4870  if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
4871  {
4872 
4873  // OD 2004-05-18 #i28701# - no direct move of objects,
4874  // which are anchored to-paragraph/to-character, if
4875  // the wrapping style influence has to be considered
4876  // on the object positioning.
4877  // #i52904# - no direct move of objects,
4878  // whose vertical position doesn't depend on anchor frame.
4879  const bool bDirectMove =
4880  FAR_AWAY != pFly->getFrameArea().Top() &&
4881  bVertPosDepOnAnchor &&
4882  !pFly->ConsiderObjWrapInfluenceOnObjPos();
4883  if ( bDirectMove )
4884  {
4885  {
4887  aRectFnSet.SubTop( aFrm, -lDiff );
4888  aRectFnSet.AddBottom( aFrm, lDiff );
4889  }
4890 
4891  pFly->GetVirtDrawObj()->SetRectsDirty();
4892  // --> OD 2004-08-17 - also notify view of <SdrObject>
4893  // instance, which represents the Writer fly frame in
4894  // the drawing layer
4895  pFly->GetVirtDrawObj()->SetChanged();
4896  // #i58280#
4897  pFly->InvalidateObjRectWithSpaces();
4898  }
4899 
4900  if ( pFly->IsFlyInContentFrame() )
4901  {
4902  static_cast<SwFlyInContentFrame*>(pFly)->AddRefOfst( lDiff );
4903  // #115759# - reset current relative
4904  // position to get re-positioned, if not directly moved.
4905  if ( !bDirectMove )
4906  {
4907  pAnchoredObj->SetCurrRelPos( Point( 0, 0 ) );
4908  }
4909  }
4910  else if( pFly->IsAutoPos() )
4911  {
4912  pFly->AddLastCharY( lDiff );
4913  // OD 2004-05-18 #i28701# - follow-up of #i22341#
4914  // <mnLastTopOfLine> has also been adjusted.
4915  pFly->AddLastTopOfLineY( lDiff );
4916  }
4917  // #i26945# - re-registration at
4918  // page frame of anchor frame, if table frame isn't
4919  // a follow table and table frame isn't in its
4920  // rebuild of last line.
4921  const SwTabFrame* pTabFrame = pLay->FindTabFrame();
4922  // - save: check, if table frame is found.
4923  if ( pTabFrame &&
4924  !( pTabFrame->IsFollow() &&
4925  pTabFrame->FindMaster()->IsRebuildLastLine() ) &&
4926  pFly->IsFlyFreeFrame() )
4927  {
4928  SwPageFrame* pPageFrame = pFly->GetPageFrame();
4929  SwPageFrame* pPageOfAnchor = pFrame->FindPageFrame();
4930  if ( pPageFrame != pPageOfAnchor )
4931  {
4932  pFly->InvalidatePos();
4933  if ( pPageFrame )
4934  pPageFrame->MoveFly( pFly, pPageOfAnchor );
4935  else
4936  pPageOfAnchor->AppendFlyToPage( pFly );
4937  }
4938  }
4939  // OD 2004-05-11 #i28701# - Because of the introduction
4940  // of new positionings and alignments (e.g. aligned at
4941  // page area, but anchored at-character), the position
4942  // of the Writer fly frame has to be invalidated.
4943  pFly->InvalidatePos();
4944 
4945  // #i26945# - follow-up of #i3317#
4946  // No arrangement of lowers, if Writer fly frame isn't
4947  // moved
4948  if ( bDirectMove &&
4949  ::lcl_ArrangeLowers( pFly,
4950  aRectFnSet.GetPrtTop(*pFly),
4951  bInva ) )
4952  {
4953  pFly->SetCompletePaint();
4954  }
4955  }
4956  else if ( dynamic_cast< const SwAnchoredDrawObject *>( pAnchoredObj ) != nullptr )
4957  {
4958  // #i26945#
4959  const SwTabFrame* pTabFrame = pLay->FindTabFrame();
4960  if ( pTabFrame &&
4961  !( pTabFrame->IsFollow() &&
4962  pTabFrame->FindMaster()->IsRebuildLastLine() ) &&
4963  (pAnchoredObj->GetFrameFormat().GetAnchor().GetAnchorId()
4964  != RndStdIds::FLY_AS_CHAR))
4965  {
4966  SwPageFrame* pPageFrame = pAnchoredObj->GetPageFrame();
4967  SwPageFrame* pPageOfAnchor = pFrame->FindPageFrame();
4968  if ( pPageFrame != pPageOfAnchor )
4969  {
4970  pAnchoredObj->InvalidateObjPos();
4971  if ( pPageFrame )
4972  {
4973  pPageFrame->RemoveDrawObjFromPage( *pAnchoredObj );
4974  }
4975  pPageOfAnchor->AppendDrawObjToPage( *pAnchoredObj );
4976  }
4977  }
4978  // #i28701# - adjust last character
4979  // rectangle and last top of line.
4980  pAnchoredObj->AddLastCharY( lDiff );
4981  pAnchoredObj->AddLastTopOfLineY( lDiff );
4982  // #i52904# - re-introduce direct move
4983  // of drawing objects
4984  const bool bDirectMove =
4985  static_cast<const SwDrawFrameFormat&>(pAnchoredObj->GetFrameFormat()).IsPosAttrSet() &&
4986  bVertPosDepOnAnchor &&
4987  !pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos();
4988  if ( bDirectMove )
4989  {
4990  SwObjPositioningInProgress aObjPosInProgress( *pAnchoredObj );
4991  if ( aRectFnSet.IsVert() )
4992  {
4993  pAnchoredObj->DrawObj()->Move( Size( lDiff, 0 ) );
4994  }
4995  else
4996  {
4997  pAnchoredObj->DrawObj()->Move( Size( 0, lDiff ) );
4998  }
4999  // #i58280#
5000  pAnchoredObj->InvalidateObjRectWithSpaces();
5001  }
5002  pAnchoredObj->InvalidateObjPos();
5003  }
5004  else
5005  {
5006  OSL_FAIL( "<lcl_ArrangeLowers(..)> - unknown type of anchored object!" );
5007  }
5008  }
5009  }
5010  }
5011  // Columns and cells are ordered horizontal, not vertical
5012  if( !pFrame->IsColumnFrame() && !pFrame->IsCellFrame() )
5013  lYStart = aRectFnSet.YInc( lYStart,
5014  aRectFnSet.GetHeight(pFrame->getFrameArea()) );
5015 
5016  // Nowadays, the content inside a cell can flow into the follow table.
5017  // Thus, the cell may only grow up to the end of the environment.
5018  // So the content may have grown, but the cell could not grow.
5019  // Therefore we have to trigger a formatting for the frames, which do
5020  // not fit into the cell anymore:
5021  SwTwips nDistanceToUpperPrtBottom =
5022  aRectFnSet.BottomDist( pFrame->getFrameArea(), aRectFnSet.GetPrtBottom(*pLay) );
5023  // #i56146# - Revise fix of issue #i26945#
5024  // do *not* consider content inside fly frames, if it's an undersized paragraph.
5025  // #i26945# - consider content inside fly frames
5026  if ( nDistanceToUpperPrtBottom < 0 &&
5027  ( ( pFrame->IsInFly() &&
5028  ( !pFrame->IsTextFrame() ||
5029  !static_cast<SwTextFrame*>(pFrame)->IsUndersized() ) ) ||
5030  pFrame->IsInSplitTableRow() ) )
5031  {
5032  pFrame->InvalidatePos();
5033  }
5034 
5035  pFrame = pFrame->GetNext();
5036  }
5037  return bRet;
5038 }
5039 
5040 void SwCellFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorderAttrs *pAttrs )
5041 {
5042  OSL_ENSURE( pAttrs, "CellFrame::Format, pAttrs is 0." );
5043  const SwTabFrame* pTab = FindTabFrame();
5044  SwRectFnSet aRectFnSet(pTab);
5045 
5046  if ( !isFramePrintAreaValid() )
5047  {
5048  setFramePrintAreaValid(true);
5049 
5050  //Adjust position.
5051  if ( Lower() )
5052  {
5053  SwTwips nTopSpace, nBottomSpace, nLeftSpace, nRightSpace;
5054  // #i29550#
5055  if ( pTab->IsCollapsingBorders() && !Lower()->IsRowFrame() )
5056  {
5057  const SvxBoxItem& rBoxItem = pAttrs->GetBox();
5058  nLeftSpace = rBoxItem.GetDistance( SvxBoxItemLine::LEFT );
5059  nRightSpace = rBoxItem.GetDistance( SvxBoxItemLine::RIGHT );
5060  nTopSpace = static_cast<SwRowFrame*>(GetUpper())->GetTopMarginForLowers();
5061  nBottomSpace = static_cast<SwRowFrame*>(GetUpper())->GetBottomMarginForLowers();
5062  }
5063  else
5064  {
5065  // OD 23.01.2003 #106895# - add 1st param to <SwBorderAttrs::CalcRight(..)>
5066  nLeftSpace = pAttrs->CalcLeft( this );
5067  nRightSpace = pAttrs->CalcRight( this );
5068  nTopSpace = pAttrs->CalcTop();
5069  nBottomSpace = pAttrs->CalcBottom();
5070  }
5071  aRectFnSet.SetXMargins( *this, nLeftSpace, nRightSpace );
5072  aRectFnSet.SetYMargins( *this, nTopSpace, nBottomSpace );
5073  }
5074  }
5075  // #i26945#
5076  tools::Long nRemaining = GetTabBox()->getRowSpan() >= 1 ?
5077  ::lcl_CalcMinCellHeight( this, pTab->IsConsiderObjsForMinCellHeight(), pAttrs ) :
5078  0;
5079  if ( !isFrameAreaSizeValid() )
5080  {
5081  setFrameAreaSizeValid(true);
5082 
5083  //The VarSize of the CellFrames is always the width.
5084  //The width is not variable though, it is defined by the format.
5085  //This predefined value however does not necessary match the actual
5086  //width. The width is calculated based on the attribute, the value in
5087  //the attribute matches the desired value of the TabFrame. Changes which
5088  //were done there are taken into account here proportionately.
5089  //If the cell doesn't have a neighbour anymore, it does not take the
5090  //attribute into account and takes the rest of the upper instead.
5091  SwTwips nWidth;
5092  if ( GetNext() )
5093  {
5094  const SwTwips nWish = pTab->GetFormat()->GetFrameSize().GetWidth();
5095  nWidth = pAttrs->GetSize().Width();
5096 
5097  OSL_ENSURE( nWish, "Table without width?" );
5098  OSL_ENSURE( nWidth <= nWish, "Width of cell larger than table." );
5099  OSL_ENSURE( nWidth > 0, "Box without width" );
5100 
5101  const tools::Long nPrtWidth = aRectFnSet.GetWidth(pTab->getFramePrintArea());
5102  if ( nWish != nPrtWidth )
5103  {
5104  // Avoid rounding problems, at least for the new table model
5105  if ( pTab->GetTable()->IsNewModel() )
5106  {
5107  // 1. sum of widths of cells up to this cell (in model)
5108  const SwTableLine* pTabLine = GetTabBox()->GetUpper();
5109  const SwTableBoxes& rBoxes = pTabLine->GetTabBoxes();
5110  const SwTableBox* pTmpBox = nullptr;
5111 
5112  SwTwips nSumWidth = 0;
5113  size_t i = 0;
5114  do
5115  {
5116  pTmpBox = rBoxes[ i++ ];
5117  nSumWidth += pTmpBox->GetFrameFormat()->GetFrameSize().GetWidth();
5118  }
5119  while ( pTmpBox != GetTabBox() );
5120 
5121  // 2. calculate actual width of cells up to this one
5122  double nTmpWidth = nSumWidth;
5123  nTmpWidth *= nPrtWidth;
5124  nTmpWidth /= nWish;
5125  nWidth = static_cast<SwTwips>(nTmpWidth);
5126 
5127  // 3. calculate frame widths of cells up to this one:
5128  const SwFrame* pTmpCell = static_cast<const SwLayoutFrame*>(GetUpper())->Lower();
5129  SwTwips nSumFrameWidths = 0;
5130  while ( pTmpCell != this )
5131  {
5132  nSumFrameWidths += aRectFnSet.GetWidth(pTmpCell->getFrameArea());
5133  pTmpCell = pTmpCell->GetNext();
5134  }
5135 
5136  nWidth = nWidth - nSumFrameWidths;
5137  }
5138  else
5139  {
5140  // #i12092# use double instead of long,
5141  // otherwise this could lead to overflows
5142  double nTmpWidth = nWidth;
5143  nTmpWidth *= nPrtWidth;
5144  nTmpWidth /= nWish;
5145  nWidth = static_cast<SwTwips>(nTmpWidth);
5146  }
5147  }
5148  }
5149  else
5150  {
5151  OSL_ENSURE( pAttrs->GetSize().Width() > 0, "Box without width" );
5152  nWidth = aRectFnSet.GetWidth(GetUpper()->getFramePrintArea());
5153  SwFrame *pPre = GetUpper()->Lower();
5154  while ( pPre != this )
5155  {
5156  nWidth -= aRectFnSet.GetWidth(pPre->getFrameArea());
5157  pPre = pPre->GetNext();
5158  }
5159  }
5160 
5161  const tools::Long nDiff = nWidth - aRectFnSet.GetWidth(getFrameArea());
5162 
5163  {
5165 
5166  if( IsNeighbourFrame() && IsRightToLeft() )
5167  {
5168  aRectFnSet.SubLeft( aFrm, nDiff );
5169  }
5170  else
5171  {
5172  aRectFnSet.AddRight( aFrm, nDiff );
5173  }
5174  }
5175 
5176  {
5178  aRectFnSet.AddRight( aPrt, nDiff );
5179  }
5180 
5181  //Adjust the height, it's defined through the content and the margins.
5182  const tools::Long nDiffHeight = nRemaining - aRectFnSet.GetHeight(getFrameArea());
5183  if ( nDiffHeight )
5184  {
5185  if ( nDiffHeight > 0 )
5186  {
5187  //Validate again if no growth happened. Invalidation is done
5188  //through AdjustCells of the row.
5189  if ( !Grow( nDiffHeight ) )
5190  {
5191  setFrameAreaSizeValid(true);
5192  setFramePrintAreaValid(true);
5193  }
5194  }
5195  else
5196  {
5197  // Only keep invalidated if shrinking was actually done; the
5198  // attempt can be ignored because all horizontally adjoined
5199  // cells have to be the same height.
5200  if ( !Shrink( -nDiffHeight ) )
5201  {
5202  setFrameAreaSizeValid(true);
5203  setFramePrintAreaValid(true);
5204  }
5205  }
5206  }
5207  }
5208  const SwFormatVertOrient &rOri = pAttrs->GetAttrSet().GetVertOrient();
5209 
5210  if ( !Lower() )
5211  return;
5212 
5213  // From now on, all operations are related to the table cell.
5214  aRectFnSet.Refresh(this);
5215 
5216  SwPageFrame* pPg = nullptr;
5217  if ( !FindTabFrame()->IsRebuildLastLine() && text::VertOrientation::NONE != rOri.GetVertOrient() &&
5218  // #158225# no vertical alignment of covered cells
5219  !IsCoveredCell() &&
5220  (pPg = FindPageFrame())!=nullptr )
5221  {
5222  if ( !Lower()->IsContentFrame() && !Lower()->IsSctFrame() && !Lower()->IsTabFrame() )
5223  {
5224  // OSL_ENSURE(for HTML-import!
5225  OSL_ENSURE( false, "VAlign to cell without content" );
5226  return;
5227  }
5228  bool bVertDir = true;
5229  // #i43913# - no vertical alignment, if wrapping
5230  // style influence is considered on object positioning and
5231  // an object is anchored inside the cell.
5232  const bool bConsiderWrapOnObjPos( GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) );
5233  // No alignment if fly with wrap overlaps the cell.
5234  if ( pPg->GetSortedObjs() )
5235  {
5236  SwRect aRect( getFramePrintArea() ); aRect += getFrameArea().Pos();
5237  for (SwAnchoredObject* pAnchoredObj : *pPg->GetSortedObjs())
5238  {
5239  SwRect aTmp( pAnchoredObj->GetObjRect() );
5240  const SwFrame* pAnch = pAnchoredObj->GetAnchorFrame();
5241  if ( (bConsiderWrapOnObjPos && IsAnLower( pAnch )) || (!bConsiderWrapOnObjPos && aTmp.IsOver( aRect )) )
5242  {
5243  const SwFrameFormat& rAnchoredObjFrameFormat = pAnchoredObj->GetFrameFormat();
5244  const SwFormatSurround &rSur = rAnchoredObjFrameFormat.GetSurround();
5245 
5246  if ( bConsiderWrapOnObjPos || css::text::WrapTextMode_THROUGH != rSur.GetSurround() )
5247  {
5248  // frames, which the cell is a lower of, aren't relevant
5249  if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) )
5250  {
5251  if ( pFly->IsAnLower( this ) )
5252  continue;
5253  }
5254 
5255  // #i43913#
5256  // #i52904# - no vertical alignment,
5257  // if object, anchored inside cell, has temporarily
5258  // consider its wrapping style on object positioning.
5259  // #i58806# - no vertical alignment
5260  // if object does not follow the text flow.
5261  if ( bConsiderWrapOnObjPos ||
5262  !IsAnLower( pAnch ) ||
5263  pAnchoredObj->IsTmpConsiderWrapInfluence() ||
5264  !rAnchoredObjFrameFormat.GetFollowTextFlow().GetValue() )
5265  {
5266  bVertDir = false;
5267  break;
5268  }
5269  }
5270  }
5271  }
5272  }
5273 
5274  tools::Long nPrtHeight = aRectFnSet.GetHeight(getFramePrintArea());
5275  if( ( bVertDir && ( nRemaining -= lcl_CalcTopAndBottomMargin( *this, *pAttrs ) ) < nPrtHeight ) ||
5276  aRectFnSet.GetTop(Lower()->getFrameArea()) != aRectFnSet.GetPrtTop(*this) )
5277  {
5278  tools::Long nDiff = aRectFnSet.GetHeight(getFramePrintArea()) - nRemaining;
5279  if ( nDiff >= 0 )
5280  {
5281  tools::Long lTopOfst = 0;
5282  if ( bVertDir )
5283  {
5284  switch ( rOri.GetVertOrient() )
5285  {
5286  case text::VertOrientation::CENTER: lTopOfst = nDiff / 2; break;
5287  case text::VertOrientation::BOTTOM: lTopOfst = nDiff; break;
5288  default: break;
5289  }
5290  }
5291  tools::Long nTmp = aRectFnSet.YInc(
5292  aRectFnSet.GetPrtTop(*this), lTopOfst );
5293  if ( lcl_ArrangeLowers( this, nTmp, !bVertDir ) )
5294  SetCompletePaint();
5295  }
5296  }
5297  }
5298  else
5299  {
5300  //Was an old alignment taken into account?
5301  if ( Lower()->IsContentFrame() )
5302  {
5303  const tools::Long lYStart = aRectFnSet.GetPrtTop(*this);
5304  lcl_ArrangeLowers( this, lYStart, true );
5305  }
5306  }
5307 
5308  // Handle rotated portions of lowers: it's possible that we have changed amount of vertical
5309  // space since the last format, and this affects how many rotated portions we need. So throw
5310  // away the current portions to build them using the new line width.
5311  for (SwFrame* pFrame = Lower(); pFrame; pFrame = pFrame->GetNext())
5312  {
5313  if (!pFrame->IsTextFrame())
5314  {
5315  continue;
5316  }
5317 
5318  auto pTextFrame = static_cast<SwTextFrame*>(pFrame);
5319  if (!pTextFrame->GetHasRotatedPortions())
5320  {
5321  continue;
5322  }
5323 
5324  pTextFrame->Prepare();
5325  }
5326 }
5327 
5328 void SwCellFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem * pNew )
5329 {
5330  bool bAttrSetChg = pNew && RES_ATTRSET_CHG == pNew->Which();
5331  const SfxPoolItem *pItem = nullptr;
5332 
5333  if( bAttrSetChg )
5334  static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( RES_VERT_ORIENT, false, &pItem);
5335  else if (pNew && RES_VERT_ORIENT == pNew->Which())
5336  pItem = pNew;
5337 
5338  if ( pItem )
5339  {
5340  bool bInva = true;
5341  if ( text::VertOrientation::NONE == static_cast<const SwFormatVertOrient*>(pItem)->GetVertOrient() &&
5342  // OD 04.11.2003 #112910#
5343  Lower() && Lower()->IsContentFrame() )
5344  {
5345  SwRectFnSet aRectFnSet(this);
5346  const tools::Long lYStart = aRectFnSet.GetPrtTop(*this);
5347  bInva = lcl_ArrangeLowers( this, lYStart, false );
5348  }
5349  if ( bInva )
5350  {
5351  SetCompletePaint();
5352  InvalidatePrt();
5353  }
5354  }
5355 
5356  if ( ( bAttrSetChg &&
5357  SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( RES_PROTECT, false ) ) ||
5358  ( pNew && RES_PROTECT == pNew->Which()) )
5359  {
5361  if( pSh && pSh->GetLayout()->IsAnyShellAccessible() )
5362  pSh->Imp()->InvalidateAccessibleEditableState( true, this );
5363  }
5364 
5365  if ( bAttrSetChg &&
5366  SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( RES_FRAMEDIR, false, &pItem ) )
5367  {
5368  SetDerivedVert( false );
5369  CheckDirChange();
5370  }
5371 
5372  // #i29550#
5373  if ( bAttrSetChg &&
5374  SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( RES_BOX, false, &pItem ) )
5375  {
5376  SwFrame* pTmpUpper = GetUpper();
5377  while ( pTmpUpper->GetUpper() && !pTmpUpper->GetUpper()->IsTabFrame() )
5378  pTmpUpper = pTmpUpper->GetUpper();
5379 
5380  SwTabFrame* pTabFrame = static_cast<SwTabFrame*>(pTmpUpper->GetUpper());
5381  if ( pTabFrame->IsCollapsingBorders() )
5382  {
5383  // Invalidate lowers of this and next row:
5384  lcl_InvalidateAllLowersPrt( static_cast<SwRowFrame*>(pTmpUpper) );
5385  pTmpUpper = pTmpUpper->GetNext();
5386  if ( pTmpUpper )
5387  lcl_InvalidateAllLowersPrt( static_cast<SwRowFrame*>(pTmpUpper) );
5388  else
5389  pTabFrame->InvalidatePrt();
5390  }
5391  }
5392 
5393  SwLayoutFrame::Modify( pOld, pNew );
5394 }
5395 
5397 {
5398  const SwTableBox *pTabBox = GetTabBox();
5399  tools::Long nRet = pTabBox ? pTabBox->getRowSpan() : 0;
5400  if ( nRet < 1 )
5401  {
5402  const SwFrame* pRow = GetUpper();
5403  const SwTabFrame* pTab = pRow ? static_cast<const SwTabFrame*>(pRow->GetUpper()) : nullptr;
5404 
5405  if ( pTab && pTab->IsFollow() && pRow == pTab->GetFirstNonHeadlineRow() )
5406  nRet = -nRet;
5407  }
5408  return nRet;
5409 }
5410 
5412 {
5414  if (SwCellFrame* pFollow = GetFollowCell())
5415  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("follow"), "%" SAL_PRIuUINT32, pFollow->GetFrameId());
5416 
5417  if (SwCellFrame* pPrevious = GetPreviousCell())
5418  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("precede"), "%" SAL_PRIuUINT32, pPrevious->GetFrameId());
5419 }
5420 
5421 // #i103961#
5423 {
5424  // notification for accessibility
5425  {
5426  SwRootFrame *pRootFrame = getRootFrame();
5427  if( pRootFrame && pRootFrame->IsAnyShellAccessible() )
5428  {
5429  SwViewShell* pVSh = pRootFrame->GetCurrShell();
5430  if ( pVSh && pVSh->Imp() )
5431  {
5432  pVSh->Imp()->