LibreOffice Module sw (master)  1
swtable.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 <float.h>
21 #include <hintids.hxx>
22 #include <hints.hxx>
23 #include <editeng/lrspitem.hxx>
24 #include <editeng/shaditem.hxx>
25 #include <editeng/adjustitem.hxx>
26 #include <editeng/colritem.hxx>
27 #include <sfx2/linkmgr.hxx>
28 #include <fmtfsize.hxx>
29 #include <fmtornt.hxx>
30 #include <fmtpdsc.hxx>
31 #include <fldbas.hxx>
32 #include <fmtfld.hxx>
33 #include <frmatr.hxx>
34 #include <doc.hxx>
38 #include <docary.hxx>
39 #include <frame.hxx>
40 #include <swtable.hxx>
41 #include <ndtxt.hxx>
42 #include <tabcol.hxx>
43 #include <tabfrm.hxx>
44 #include <cellfrm.hxx>
45 #include <rowfrm.hxx>
46 #include <swserv.hxx>
47 #include <expfld.hxx>
48 #include <mdiexp.hxx>
49 #include <cellatr.hxx>
50 #include <txatbase.hxx>
51 #include <htmltbl.hxx>
52 #include <swtblfmt.hxx>
53 #include <ndindex.hxx>
54 #include <tblrwcl.hxx>
55 #include <shellres.hxx>
56 #include <viewsh.hxx>
57 #include <redline.hxx>
58 #include <list>
59 #include <calbck.hxx>
60 
61 #ifdef DBG_UTIL
62 #define CHECK_TABLE(t) (t).CheckConsistency();
63 #else
64 #define CHECK_TABLE(t)
65 #endif
66 
67 using namespace com::sun::star;
68 
69 
70 #define COLFUZZY 20
71 
72 static void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol,
73  bool bChgAlign, sal_uLong nNdPos );
74 
75 inline const Color* SwTableBox::GetSaveUserColor() const
76 {
77  return mpUserColor.get();
78 }
79 
81 {
82  return mpNumFormatColor.get();
83 }
84 
85 inline void SwTableBox::SetSaveUserColor(const Color* p )
86 {
87  if (p)
88  mpUserColor.reset(new Color(*p));
89  else
90  mpUserColor.reset();
91 }
92 
94 {
95  if (p)
96  mpNumFormatColor.reset(new Color(*p));
97  else
98  mpNumFormatColor.reset();
99 }
100 
102 {
103  return mnRowSpan;
104 }
105 
106 void SwTableBox::setRowSpan( long nNewRowSpan )
107 {
108  mnRowSpan = nNewRowSpan;
109 }
110 
112 {
113  return mbDummyFlag;
114 }
115 
116 void SwTableBox::setDummyFlag( bool bDummy )
117 {
118  mbDummyFlag = bDummy;
119 }
120 
121 //JP 15.09.98: Bug 55741 - Keep tabs (front and rear)
122 static OUString& lcl_TabToBlankAtSttEnd( OUString& rText )
123 {
124  sal_Unicode c;
125  sal_Int32 n;
126 
127  for( n = 0; n < rText.getLength() && ' ' >= ( c = rText[n] ); ++n )
128  if( '\x9' == c )
129  rText = rText.replaceAt( n, 1, " " );
130  for( n = rText.getLength(); n && ' ' >= ( c = rText[--n] ); )
131  if( '\x9' == c )
132  rText = rText.replaceAt( n, 1, " " );
133  return rText;
134 }
135 
136 static OUString& lcl_DelTabsAtSttEnd( OUString& rText )
137 {
138  sal_Unicode c;
139  sal_Int32 n;
140  OUStringBuffer sBuff(rText);
141 
142  for( n = 0; n < sBuff.getLength() && ' ' >= ( c = sBuff[ n ]); ++n )
143  {
144  if( '\x9' == c )
145  sBuff.remove( n--, 1 );
146  }
147  for( n = sBuff.getLength(); n && ' ' >= ( c = sBuff[ --n ]); )
148  {
149  if( '\x9' == c )
150  sBuff.remove( n, 1 );
151  }
152  rText = sBuff.makeStringAndClear();
153  return rText;
154 }
155 
156 void InsTableBox( SwDoc* pDoc, SwTableNode* pTableNd,
157  SwTableLine* pLine, SwTableBoxFormat* pBoxFrameFormat,
158  SwTableBox* pBox,
159  sal_uInt16 nInsPos, sal_uInt16 nCnt )
160 {
161  OSL_ENSURE( pBox->GetSttNd(), "Box with no start node" );
162  SwNodeIndex aIdx( *pBox->GetSttNd(), +1 );
163  SwContentNode* pCNd = aIdx.GetNode().GetContentNode();
164  if( !pCNd )
165  pCNd = pDoc->GetNodes().GoNext( &aIdx );
166  OSL_ENSURE( pCNd, "Box with no content node" );
167 
168  if( pCNd->IsTextNode() )
169  {
170  if( pBox->GetSaveNumFormatColor() && pCNd->GetpSwAttrSet() )
171  {
172  SwAttrSet aAttrSet( *pCNd->GetpSwAttrSet() );
173  if( pBox->GetSaveUserColor() )
174  aAttrSet.Put( SvxColorItem( *pBox->GetSaveUserColor(), RES_CHRATR_COLOR ));
175  else
176  aAttrSet.ClearItem( RES_CHRATR_COLOR );
177  pDoc->GetNodes().InsBoxen( pTableNd, pLine, pBoxFrameFormat,
178  static_cast<SwTextNode*>(pCNd)->GetTextColl(),
179  &aAttrSet, nInsPos, nCnt );
180  }
181  else
182  pDoc->GetNodes().InsBoxen( pTableNd, pLine, pBoxFrameFormat,
183  static_cast<SwTextNode*>(pCNd)->GetTextColl(),
184  pCNd->GetpSwAttrSet(),
185  nInsPos, nCnt );
186  }
187  else
188  pDoc->GetNodes().InsBoxen( pTableNd, pLine, pBoxFrameFormat,
189  pDoc->GetDfltTextFormatColl(), nullptr,
190  nInsPos, nCnt );
191 
192  long nRowSpan = pBox->getRowSpan();
193  if( nRowSpan != 1 )
194  {
195  SwTableBoxes& rTableBoxes = pLine->GetTabBoxes();
196  for( sal_uInt16 i = 0; i < nCnt; ++i )
197  {
198  pBox = rTableBoxes[ i + nInsPos ];
199  pBox->setRowSpan( nRowSpan );
200  }
201  }
202 }
203 
205  : SwClient( nullptr ),
206  m_pTableNode( nullptr ),
207  m_nGraphicsThatResize( 0 ),
208  m_nRowsToRepeat( 1 ),
209  m_bModifyLocked( false ),
210  m_bNewModel( true )
211 {
212  // default value set in the options
214 }
215 
216 SwTable::SwTable( const SwTable& rTable )
217  : SwClient( rTable.GetFrameFormat() ),
218  m_pTableNode( nullptr ),
219  m_eTableChgMode( rTable.m_eTableChgMode ),
220  m_nGraphicsThatResize( 0 ),
221  m_nRowsToRepeat( rTable.GetRowsToRepeat() ),
222  maTableStyleName(rTable.maTableStyleName),
223  m_bModifyLocked( false ),
224  m_bNewModel( rTable.m_bNewModel )
225 {
226 }
227 
228 void DelBoxNode( SwTableSortBoxes const & rSortCntBoxes )
229 {
230  for (size_t n = 0; n < rSortCntBoxes.size(); ++n)
231  {
232  rSortCntBoxes[ n ]->m_pStartNode = nullptr;
233  }
234 }
235 
237 {
238  if( m_xRefObj.is() )
239  {
240  SwDoc* pDoc = GetFrameFormat()->GetDoc();
241  if( !pDoc->IsInDtor() ) // then remove from the list
243 
244  m_xRefObj->Closed();
245  }
246 
247  // the table can be deleted if it's the last client of the FrameFormat
248  SwTableFormat* pFormat = GetFrameFormat();
249  pFormat->Remove( this ); // remove
250 
251  if( !pFormat->HasWriterListeners() )
252  pFormat->GetDoc()->DelTableFrameFormat( pFormat ); // and delete
253 
254  // Delete the pointers from the SortArray of the boxes. The objects
255  // are preserved and are deleted by the lines/boxes arrays dtor.
256  // Note: unfortunately not enough, pointers to the StartNode of the
257  // section need deletion.
260 }
261 
262 namespace
263 {
264 
265 template<class T>
266 T lcl_MulDiv64(sal_uInt64 nA, sal_uInt64 nM, sal_uInt64 nD)
267 {
268  return static_cast<T>((nA*nM)/nD);
269 }
270 
271 }
272 
273 static void FormatInArr( std::vector<SwFormat*>& rFormatArr, SwFormat* pBoxFormat )
274 {
275  std::vector<SwFormat*>::const_iterator it = std::find( rFormatArr.begin(), rFormatArr.end(), pBoxFormat );
276  if ( it == rFormatArr.end() )
277  rFormatArr.push_back( pBoxFormat );
278 }
279 
280 static void lcl_ModifyBoxes( SwTableBoxes &rBoxes, const long nOld,
281  const long nNew, std::vector<SwFormat*>& rFormatArr );
282 
283 static void lcl_ModifyLines( SwTableLines &rLines, const long nOld,
284  const long nNew, std::vector<SwFormat*>& rFormatArr, const bool bCheckSum )
285 {
286  for ( size_t i = 0; i < rLines.size(); ++i )
287  ::lcl_ModifyBoxes( rLines[i]->GetTabBoxes(), nOld, nNew, rFormatArr );
288  if( bCheckSum )
289  {
290  for(SwFormat* pFormat : rFormatArr)
291  {
292  const SwTwips nBox = lcl_MulDiv64<SwTwips>(pFormat->GetFrameSize().GetWidth(), nNew, nOld);
293  SwFormatFrameSize aNewBox( SwFrameSize::Variable, nBox, 0 );
294  pFormat->LockModify();
295  pFormat->SetFormatAttr( aNewBox );
296  pFormat->UnlockModify();
297  }
298  }
299 }
300 
301 static void lcl_ModifyBoxes( SwTableBoxes &rBoxes, const long nOld,
302  const long nNew, std::vector<SwFormat*>& rFormatArr )
303 {
304  sal_uInt64 nSum = 0; // To avoid rounding errors we summarize all box widths
305  sal_uInt64 nOriginalSum = 0; // Sum of original widths
306  for ( size_t i = 0; i < rBoxes.size(); ++i )
307  {
308  SwTableBox &rBox = *rBoxes[i];
309  if ( !rBox.GetTabLines().empty() )
310  {
311  // For SubTables the rounding problem will not be solved :-(
312  ::lcl_ModifyLines( rBox.GetTabLines(), nOld, nNew, rFormatArr, false );
313  }
314  // Adjust the box
315  SwFrameFormat *pFormat = rBox.GetFrameFormat();
316  sal_uInt64 nBox = pFormat->GetFrameSize().GetWidth();
317  nOriginalSum += nBox;
318  nBox *= nNew;
319  nBox /= nOld;
320  const sal_uInt64 nWishedSum = lcl_MulDiv64<sal_uInt64>(nOriginalSum, nNew, nOld) - nSum;
321  if( nWishedSum > 0 )
322  {
323  if( nBox == nWishedSum )
324  FormatInArr( rFormatArr, pFormat );
325  else
326  {
327  nBox = nWishedSum;
328  pFormat = rBox.ClaimFrameFormat();
329  SwFormatFrameSize aNewBox( SwFrameSize::Variable, static_cast< SwTwips >(nBox), 0 );
330  pFormat->LockModify();
331  pFormat->SetFormatAttr( aNewBox );
332  pFormat->UnlockModify();
333  }
334  }
335  else {
336  OSL_FAIL( "Rounding error" );
337  }
338  nSum += nBox;
339  }
340 }
341 
342 void SwTable::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
343 {
344  // catch SSize changes, to adjust the lines/boxes
345  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
346  const SwFormatFrameSize* pNewSize = nullptr, *pOldSize = nullptr;
347 
348  if( RES_ATTRSET_CHG == nWhich )
349  {
350  if (pOld && pNew && SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState(
351  RES_FRM_SIZE, false, reinterpret_cast<const SfxPoolItem**>(&pNewSize)))
352  {
353  pOldSize = &static_cast<const SwAttrSetChg*>(pOld)->GetChgSet()->GetFrameSize();
354  }
355  }
356  else if( RES_FRM_SIZE == nWhich )
357  {
358  pOldSize = static_cast<const SwFormatFrameSize*>(pOld);
359  pNewSize = static_cast<const SwFormatFrameSize*>(pNew);
360  }
361  else
362  CheckRegistration( pOld );
363 
364  if (pOldSize && pNewSize && !m_bModifyLocked)
365  AdjustWidths( pOldSize->GetWidth(), pNewSize->GetWidth() );
366 }
367 
368 void SwTable::AdjustWidths( const long nOld, const long nNew )
369 {
370  std::vector<SwFormat*> aFormatArr;
371  aFormatArr.reserve( m_aLines[0]->GetTabBoxes().size() );
372  ::lcl_ModifyLines( m_aLines, nOld, nNew, aFormatArr, true );
373 }
374 
375 static void lcl_RefreshHidden( SwTabCols &rToFill, size_t nPos )
376 {
377  for ( size_t i = 0; i < rToFill.Count(); ++i )
378  {
379  if ( std::abs(static_cast<long>(nPos) - rToFill[i]) <= COLFUZZY )
380  {
381  rToFill.SetHidden( i, false );
382  break;
383  }
384  }
385 }
386 
387 static void lcl_SortedTabColInsert( SwTabCols &rToFill, const SwTableBox *pBox,
388  const SwFrameFormat *pTabFormat, const bool bHidden,
389  const bool bRefreshHidden )
390 {
391  const long nWish = pTabFormat->GetFrameSize().GetWidth();
392  OSL_ENSURE(nWish, "weird <= 0 width frmfrm");
393 
394  // The value for the left edge of the box is calculated from the
395  // widths of the previous boxes.
396  long nPos = 0;
397  long nLeftMin = 0;
398  long nRightMax = 0;
399  if (nWish != 0) //fdo#33012 0 width frmfmt
400  {
401  SwTwips nSum = 0;
402  const SwTableBox *pCur = pBox;
403  const SwTableLine *pLine = pBox->GetUpper();
404  const long nAct = rToFill.GetRight() - rToFill.GetLeft(); // +1 why?
405 
406  while ( pLine )
407  {
408  const SwTableBoxes &rBoxes = pLine->GetTabBoxes();
409  for ( size_t i = 0; i < rBoxes.size(); ++i )
410  {
411  const SwTwips nWidth = rBoxes[i]->GetFrameFormat()->GetFrameSize().GetWidth();
412  nSum += nWidth;
413  const long nTmp = lcl_MulDiv64<long>(nSum, nAct, nWish);
414 
415  if (rBoxes[i] != pCur)
416  {
417  if ( pLine == pBox->GetUpper() || 0 == nLeftMin )
418  nLeftMin = nTmp - nPos;
419  nPos = nTmp;
420  }
421  else
422  {
423  nSum -= nWidth;
424  if ( 0 == nRightMax )
425  nRightMax = nTmp - nPos;
426  break;
427  }
428  }
429  pCur = pLine->GetUpper();
430  pLine = pCur ? pCur->GetUpper() : nullptr;
431  }
432  }
433 
434  bool bInsert = !bRefreshHidden;
435  for ( size_t j = 0; bInsert && (j < rToFill.Count()); ++j )
436  {
437  long nCmp = rToFill[j];
438  if ( (nPos >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
439  (nPos <= (nCmp + COLFUZZY)) )
440  {
441  bInsert = false; // Already has it.
442  }
443  else if ( nPos < nCmp )
444  {
445  bInsert = false;
446  rToFill.Insert( nPos, bHidden, j );
447  }
448  }
449  if ( bInsert )
450  rToFill.Insert( nPos, bHidden, rToFill.Count() );
451  else if ( bRefreshHidden )
452  ::lcl_RefreshHidden( rToFill, nPos );
453 
454  if ( bHidden && !bRefreshHidden )
455  {
456  // calculate minimum/maximum values for the existing entries:
457  nLeftMin = nPos - nLeftMin;
458  nRightMax = nPos + nRightMax;
459 
460  // check if nPos is entry:
461  bool bFoundPos = false;
462  bool bFoundMax = false;
463  for ( size_t j = 0; !(bFoundPos && bFoundMax ) && j < rToFill.Count(); ++j )
464  {
465  SwTabColsEntry& rEntry = rToFill.GetEntry( j );
466  long nCmp = rToFill[j];
467 
468  if ( (nPos >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
469  (nPos <= (nCmp + COLFUZZY)) )
470  {
471  // check if nLeftMin is > old minimum for entry nPos:
472  const long nOldMin = rEntry.nMin;
473  if ( nLeftMin > nOldMin )
474  rEntry.nMin = nLeftMin;
475  // check if nRightMin is < old maximum for entry nPos:
476  const long nOldMax = rEntry.nMax;
477  if ( nRightMax < nOldMax )
478  rEntry.nMax = nRightMax;
479 
480  bFoundPos = true;
481  }
482  else if ( (nRightMax >= ((nCmp >= COLFUZZY) ? nCmp - COLFUZZY : nCmp)) &&
483  (nRightMax <= (nCmp + COLFUZZY)) )
484  {
485  // check if nPos is > old minimum for entry nRightMax:
486  const long nOldMin = rEntry.nMin;
487  if ( nPos > nOldMin )
488  rEntry.nMin = nPos;
489 
490  bFoundMax = true;
491  }
492  }
493  }
494 }
495 
496 static void lcl_ProcessBoxGet( const SwTableBox *pBox, SwTabCols &rToFill,
497  const SwFrameFormat *pTabFormat, bool bRefreshHidden )
498 {
499  if ( !pBox->GetTabLines().empty() )
500  {
501  const SwTableLines &rLines = pBox->GetTabLines();
502  for ( size_t i = 0; i < rLines.size(); ++i )
503  {
504  const SwTableBoxes &rBoxes = rLines[i]->GetTabBoxes();
505  for ( size_t j = 0; j < rBoxes.size(); ++j )
506  ::lcl_ProcessBoxGet( rBoxes[j], rToFill, pTabFormat, bRefreshHidden);
507  }
508  }
509  else
510  ::lcl_SortedTabColInsert( rToFill, pBox, pTabFormat, false, bRefreshHidden );
511 }
512 
513 static void lcl_ProcessLineGet( const SwTableLine *pLine, SwTabCols &rToFill,
514  const SwFrameFormat *pTabFormat )
515 {
516  for ( size_t i = 0; i < pLine->GetTabBoxes().size(); ++i )
517  {
518  const SwTableBox *pBox = pLine->GetTabBoxes()[i];
519  if ( pBox->GetSttNd() )
520  ::lcl_SortedTabColInsert( rToFill, pBox, pTabFormat, true, false );
521  else
522  for ( size_t j = 0; j < pBox->GetTabLines().size(); ++j )
523  ::lcl_ProcessLineGet( pBox->GetTabLines()[j], rToFill, pTabFormat );
524  }
525 }
526 
527 void SwTable::GetTabCols( SwTabCols &rToFill, const SwTableBox *pStart,
528  bool bRefreshHidden, bool bCurRowOnly ) const
529 {
530  // Optimization: if bHidden is set, we only update the Hidden Array.
531  if ( bRefreshHidden )
532  {
533  // remove corrections
534  for ( size_t i = 0; i < rToFill.Count(); ++i )
535  {
536  SwTabColsEntry& rEntry = rToFill.GetEntry( i );
537  rEntry.nPos -= rToFill.GetLeft();
538  rEntry.nMin -= rToFill.GetLeft();
539  rEntry.nMax -= rToFill.GetLeft();
540  }
541 
542  // All are hidden, so add the visible ones.
543  for ( size_t i = 0; i < rToFill.Count(); ++i )
544  rToFill.SetHidden( i, true );
545  }
546  else
547  {
548  rToFill.Remove( 0, rToFill.Count() );
549  }
550 
551  // Insertion cases:
552  // 1. All boxes which are inferior to Line which is superior to the Start,
553  // as well as their inferior boxes if present.
554  // 2. Starting from the Line, the superior box plus its neighbours; but no inferiors.
555  // 3. Apply 2. to the Line superior to the chain of boxes,
556  // until the Line's superior is not a box but the table.
557  // Only those boxes are inserted that don't contain further rows. The insertion
558  // function takes care to avoid duplicates. In order to achieve this, we work
559  // with some degree of fuzzyness (to avoid rounding errors).
560  // Only the left edge of the boxes are inserted.
561  // Finally, the first entry is removed again, because it's already
562  // covered by the border.
563  // 4. Scan the table again and insert _all_ boxes, this time as hidden.
564 
565  const SwFrameFormat *pTabFormat = GetFrameFormat();
566 
567  // 1.
568  const SwTableBoxes &rBoxes = pStart->GetUpper()->GetTabBoxes();
569 
570  for ( size_t i = 0; i < rBoxes.size(); ++i )
571  ::lcl_ProcessBoxGet( rBoxes[i], rToFill, pTabFormat, bRefreshHidden );
572 
573  // 2. and 3.
574  const SwTableLine *pLine = pStart->GetUpper()->GetUpper() ?
575  pStart->GetUpper()->GetUpper()->GetUpper() : nullptr;
576  while ( pLine )
577  {
578  const SwTableBoxes &rBoxes2 = pLine->GetTabBoxes();
579  for ( size_t k = 0; k < rBoxes2.size(); ++k )
580  ::lcl_SortedTabColInsert( rToFill, rBoxes2[k],
581  pTabFormat, false, bRefreshHidden );
582  pLine = pLine->GetUpper() ? pLine->GetUpper()->GetUpper() : nullptr;
583  }
584 
585  if ( !bRefreshHidden )
586  {
587  // 4.
588  if ( !bCurRowOnly )
589  {
590  for ( size_t i = 0; i < m_aLines.size(); ++i )
591  ::lcl_ProcessLineGet( m_aLines[i], rToFill, pTabFormat );
592  }
593 
594  rToFill.Remove( 0 );
595  }
596 
597  // Now the coordinates are relative to the left table border - i.e.
598  // relative to SwTabCols.nLeft. However, they are expected
599  // relative to the left document border, i.e. SwTabCols.nLeftMin.
600  // So all values need to be extended by nLeft.
601  for ( size_t i = 0; i < rToFill.Count(); ++i )
602  {
603  SwTabColsEntry& rEntry = rToFill.GetEntry( i );
604  rEntry.nPos += rToFill.GetLeft();
605  rEntry.nMin += rToFill.GetLeft();
606  rEntry.nMax += rToFill.GetLeft();
607  }
608 }
609 
610 // Structure for parameter passing
611 struct Parm
612 {
613  const SwTabCols &rNew;
614  const SwTabCols &rOld;
615  long nNewWish,
616  nOldWish;
617  std::deque<SwTableBox*> aBoxArr;
619 
620  Parm( const SwTabCols &rN, const SwTabCols &rO )
621  : rNew( rN ), rOld( rO ), nNewWish(0), nOldWish(0)
622  {}
623 };
624 
625 static void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm );
626 
627 static void lcl_ProcessLine( SwTableLine *pLine, Parm &rParm )
628 {
629  SwTableBoxes &rBoxes = pLine->GetTabBoxes();
630  for ( size_t i = rBoxes.size(); i > 0; )
631  {
632  --i;
633  ::lcl_ProcessBoxSet( rBoxes[i], rParm );
634  }
635 }
636 
637 static void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm )
638 {
639  if ( !pBox->GetTabLines().empty() )
640  {
641  SwTableLines &rLines = pBox->GetTabLines();
642  for ( size_t i = rLines.size(); i > 0; )
643  {
644  --i;
645  lcl_ProcessLine( rLines[i], rParm );
646  }
647  }
648  else
649  {
650  // Search the old TabCols for the current position (calculate from
651  // left and right edge). Adjust the box if the values differ from
652  // the new TabCols. If the adjusted edge has no neighbour we also
653  // adjust all superior boxes.
654 
655  const long nOldAct = rParm.rOld.GetRight() -
656  rParm.rOld.GetLeft(); // +1 why?
657 
658  // The value for the left edge of the box is calculated from the
659  // widths of the previous boxes plus the left edge.
660  long nLeft = rParm.rOld.GetLeft();
661  const SwTableBox *pCur = pBox;
662  const SwTableLine *pLine = pBox->GetUpper();
663 
664  while ( pLine )
665  {
666  const SwTableBoxes &rBoxes = pLine->GetTabBoxes();
667  for ( size_t i = 0; (i < rBoxes.size()) && (rBoxes[i] != pCur); ++i)
668  {
669  nLeft += lcl_MulDiv64<long>(
670  rBoxes[i]->GetFrameFormat()->GetFrameSize().GetWidth(),
671  nOldAct, rParm.nOldWish);
672  }
673  pCur = pLine->GetUpper();
674  pLine = pCur ? pCur->GetUpper() : nullptr;
675  }
676  long nLeftDiff = 0;
677  long nRightDiff = 0;
678  if ( nLeft != rParm.rOld.GetLeft() ) // There are still boxes before this.
679  {
680  // Right edge is left edge plus width.
681  const long nWidth = lcl_MulDiv64<long>(
682  pBox->GetFrameFormat()->GetFrameSize().GetWidth(),
683  nOldAct, rParm.nOldWish);
684  const long nRight = nLeft + nWidth;
685  size_t nLeftPos = 0;
686  size_t nRightPos = 0;
687  bool bFoundLeftPos = false;
688  bool bFoundRightPos = false;
689  for ( size_t i = 0; i < rParm.rOld.Count(); ++i )
690  {
691  if ( nLeft >= (rParm.rOld[i] - COLFUZZY) &&
692  nLeft <= (rParm.rOld[i] + COLFUZZY) )
693  {
694  nLeftPos = i;
695  bFoundLeftPos = true;
696  }
697  else if ( nRight >= (rParm.rOld[i] - COLFUZZY) &&
698  nRight <= (rParm.rOld[i] + COLFUZZY) )
699  {
700  nRightPos = i;
701  bFoundRightPos = true;
702  }
703  }
704  nLeftDiff = bFoundLeftPos ?
705  rParm.rOld[nLeftPos] - rParm.rNew[nLeftPos] : 0;
706  nRightDiff= bFoundRightPos ?
707  rParm.rNew[nRightPos] - rParm.rOld[nRightPos] : 0;
708  }
709  else // The first box.
710  {
711  nLeftDiff = rParm.rOld.GetLeft() - rParm.rNew.GetLeft();
712  if ( rParm.rOld.Count() )
713  {
714  // Calculate the difference to the edge touching the first box.
715  const long nWidth = lcl_MulDiv64<long>(
716  pBox->GetFrameFormat()->GetFrameSize().GetWidth(),
717  nOldAct, rParm.nOldWish);
718  const long nTmp = nWidth + rParm.rOld.GetLeft();
719  for ( size_t i = 0; i < rParm.rOld.Count(); ++i )
720  {
721  if ( nTmp >= (rParm.rOld[i] - COLFUZZY) &&
722  nTmp <= (rParm.rOld[i] + COLFUZZY) )
723  {
724  nRightDiff = rParm.rNew[i] - rParm.rOld[i];
725  break;
726  }
727  }
728  }
729  }
730 
731  if( pBox->getRowSpan() == 1 )
732  {
733  const sal_uInt16 nPos = pBox->GetUpper()->GetBoxPos( pBox );
734  SwTableBoxes& rTableBoxes = pBox->GetUpper()->GetTabBoxes();
735  if( nPos && rTableBoxes[ nPos - 1 ]->getRowSpan() != 1 )
736  nLeftDiff = 0;
737  if( nPos + 1 < static_cast<sal_uInt16>(rTableBoxes.size()) &&
738  rTableBoxes[ nPos + 1 ]->getRowSpan() != 1 )
739  nRightDiff = 0;
740  }
741  else
742  nLeftDiff = nRightDiff = 0;
743 
744  if ( nLeftDiff || nRightDiff )
745  {
746  // The difference is the actual difference amount. For stretched
747  // tables, it does not make sense to adjust the attributes of the
748  // boxes by this amount. The difference amount needs to be converted
749  // accordingly.
750  long nTmp = rParm.rNew.GetRight() - rParm.rNew.GetLeft(); // +1 why?
751  nLeftDiff *= rParm.nNewWish;
752  nLeftDiff /= nTmp;
753  nRightDiff *= rParm.nNewWish;
754  nRightDiff /= nTmp;
755  long nDiff = nLeftDiff + nRightDiff;
756 
757  // Adjust the box and all superiors by the difference amount.
758  while ( pBox )
759  {
760  SwFormatFrameSize aFormatFrameSize( pBox->GetFrameFormat()->GetFrameSize() );
761  aFormatFrameSize.SetWidth( aFormatFrameSize.GetWidth() + nDiff );
762  if ( aFormatFrameSize.GetWidth() < 0 )
763  aFormatFrameSize.SetWidth( -aFormatFrameSize.GetWidth() );
764  rParm.aShareFormats.SetSize( *pBox, aFormatFrameSize );
765 
766  // The outer cells of the last row are responsible to adjust a surrounding cell.
767  // Last line check:
768  if ( pBox->GetUpper()->GetUpper() &&
769  pBox->GetUpper() != pBox->GetUpper()->GetUpper()->GetTabLines().back())
770  {
771  pBox = nullptr;
772  }
773  else
774  {
775  // Middle cell check:
776  if ( pBox != pBox->GetUpper()->GetTabBoxes().front() )
777  nDiff = nRightDiff;
778 
779  if ( pBox != pBox->GetUpper()->GetTabBoxes().back() )
780  nDiff -= nRightDiff;
781 
782  pBox = nDiff ? pBox->GetUpper()->GetUpper() : nullptr;
783  }
784  }
785  }
786  }
787 }
788 
789 static void lcl_ProcessBoxPtr( SwTableBox *pBox, std::deque<SwTableBox*> &rBoxArr,
790  bool bBefore )
791 {
792  if ( !pBox->GetTabLines().empty() )
793  {
794  const SwTableLines &rLines = pBox->GetTabLines();
795  for ( size_t i = 0; i < rLines.size(); ++i )
796  {
797  const SwTableBoxes &rBoxes = rLines[i]->GetTabBoxes();
798  for ( size_t j = 0; j < rBoxes.size(); ++j )
799  ::lcl_ProcessBoxPtr( rBoxes[j], rBoxArr, bBefore );
800  }
801  }
802  else if ( bBefore )
803  rBoxArr.push_front( pBox );
804  else
805  rBoxArr.push_back( pBox );
806 }
807 
808 static void lcl_AdjustBox( SwTableBox *pBox, const long nDiff, Parm &rParm );
809 
810 static void lcl_AdjustLines( SwTableLines &rLines, const long nDiff, Parm &rParm )
811 {
812  for ( size_t i = 0; i < rLines.size(); ++i )
813  {
814  SwTableBox *pBox = rLines[i]->GetTabBoxes()
815  [rLines[i]->GetTabBoxes().size()-1];
816  lcl_AdjustBox( pBox, nDiff, rParm );
817  }
818 }
819 
820 static void lcl_AdjustBox( SwTableBox *pBox, const long nDiff, Parm &rParm )
821 {
822  if ( !pBox->GetTabLines().empty() )
823  ::lcl_AdjustLines( pBox->GetTabLines(), nDiff, rParm );
824 
825  // Adjust the size of the box.
826  SwFormatFrameSize aFormatFrameSize( pBox->GetFrameFormat()->GetFrameSize() );
827  aFormatFrameSize.SetWidth( aFormatFrameSize.GetWidth() + nDiff );
828 
829  rParm.aShareFormats.SetSize( *pBox, aFormatFrameSize );
830 }
831 
832 void SwTable::SetTabCols( const SwTabCols &rNew, const SwTabCols &rOld,
833  const SwTableBox *pStart, bool bCurRowOnly )
834 {
835  CHECK_TABLE( *this )
836 
837  SetHTMLTableLayout(std::shared_ptr<SwHTMLTableLayout>()); // delete HTML-Layout
838 
839  // FME: Made rOld const. The caller is responsible for passing correct
840  // values of rOld. Therefore we do not have to call GetTabCols anymore:
841  //GetTabCols( rOld, pStart );
842 
843  Parm aParm( rNew, rOld );
844 
845  OSL_ENSURE( rOld.Count() == rNew.Count(), "Number of columns changed.");
846 
847  // Convert the edges. We need to adjust the size of the table and some boxes.
848  // For the size adjustment, we must not make use of the Modify, since that'd
849  // adjust all boxes, which we really don't want.
850  SwFrameFormat *pFormat = GetFrameFormat();
851  aParm.nOldWish = aParm.nNewWish = pFormat->GetFrameSize().GetWidth();
852  if ( (rOld.GetLeft() != rNew.GetLeft()) ||
853  (rOld.GetRight()!= rNew.GetRight()) )
854  {
855  LockModify();
856  {
857  SvxLRSpaceItem aLR( pFormat->GetLRSpace() );
858  SvxShadowItem aSh( pFormat->GetShadow() );
859 
860  SwTwips nShRight = aSh.CalcShadowSpace( SvxShadowItemSide::RIGHT );
861  SwTwips nShLeft = aSh.CalcShadowSpace( SvxShadowItemSide::LEFT );
862 
863  aLR.SetLeft ( rNew.GetLeft() - nShLeft );
864  aLR.SetRight( rNew.GetRightMax() - rNew.GetRight() - nShRight );
865  pFormat->SetFormatAttr( aLR );
866 
867  // The alignment of the table needs to be adjusted accordingly.
868  // This is done by preserving the exact positions that have been
869  // set by the user.
870  SwFormatHoriOrient aOri( pFormat->GetHoriOrient() );
871  if(text::HoriOrientation::NONE != aOri.GetHoriOrient())
872  {
873  const bool bLeftDist = rNew.GetLeft() != nShLeft;
874  const bool bRightDist = rNew.GetRight() + nShRight != rNew.GetRightMax();
875  if(!bLeftDist && !bRightDist)
876  aOri.SetHoriOrient( text::HoriOrientation::FULL );
877  else if(!bRightDist && rNew.GetLeft() > nShLeft )
878  aOri.SetHoriOrient( text::HoriOrientation::RIGHT );
879  else if(!bLeftDist && rNew.GetRight() + nShRight < rNew.GetRightMax())
880  aOri.SetHoriOrient( text::HoriOrientation::LEFT );
881  else
882  aOri.SetHoriOrient( text::HoriOrientation::LEFT_AND_WIDTH );
883  }
884  pFormat->SetFormatAttr( aOri );
885  }
886  const long nAct = rOld.GetRight() - rOld.GetLeft(); // +1 why?
887  long nTabDiff = 0;
888 
889  if ( rOld.GetLeft() != rNew.GetLeft() )
890  {
891  nTabDiff = rOld.GetLeft() - rNew.GetLeft();
892  nTabDiff *= aParm.nOldWish;
893  nTabDiff /= nAct;
894  }
895  if ( rOld.GetRight() != rNew.GetRight() )
896  {
897  long nDiff = rNew.GetRight() - rOld.GetRight();
898  nDiff *= aParm.nOldWish;
899  nDiff /= nAct;
900  nTabDiff += nDiff;
901  if( !IsNewModel() )
902  ::lcl_AdjustLines( GetTabLines(), nDiff, aParm );
903  }
904 
905  // Adjust the size of the table, watch out for stretched tables.
906  if ( nTabDiff )
907  {
908  aParm.nNewWish += nTabDiff;
909  if ( aParm.nNewWish < 0 )
910  aParm.nNewWish = USHRT_MAX; // Oops! Have to roll back.
911  SwFormatFrameSize aSz( pFormat->GetFrameSize() );
912  if ( aSz.GetWidth() != aParm.nNewWish )
913  {
914  aSz.SetWidth( aParm.nNewWish );
915  aSz.SetWidthPercent( 0 );
916  pFormat->SetFormatAttr( aSz );
917  }
918  }
919  UnlockModify();
920  }
921 
922  if( IsNewModel() )
923  NewSetTabCols( aParm, rNew, rOld, pStart, bCurRowOnly );
924  else
925  {
926  if ( bCurRowOnly )
927  {
928  // To adjust the current row, we need to process all its boxes,
929  // similar to the filling of the TabCols (see GetTabCols()).
930  // Unfortunately we again have to take care to adjust the boxes
931  // from back to front, respectively from outer to inner.
932  // The best way to achieve this is probably to track the boxes
933  // in a PtrArray.
934  const SwTableBoxes &rBoxes = pStart->GetUpper()->GetTabBoxes();
935  for ( size_t i = 0; i < rBoxes.size(); ++i )
936  ::lcl_ProcessBoxPtr( rBoxes[i], aParm.aBoxArr, false );
937 
938  const SwTableLine *pLine = pStart->GetUpper()->GetUpper() ?
939  pStart->GetUpper()->GetUpper()->GetUpper() : nullptr;
940  const SwTableBox *pExcl = pStart->GetUpper()->GetUpper();
941  while ( pLine )
942  {
943  const SwTableBoxes &rBoxes2 = pLine->GetTabBoxes();
944  bool bBefore = true;
945  for ( size_t i = 0; i < rBoxes2.size(); ++i )
946  {
947  if ( rBoxes2[i] != pExcl )
948  ::lcl_ProcessBoxPtr( rBoxes2[i], aParm.aBoxArr, bBefore );
949  else
950  bBefore = false;
951  }
952  pExcl = pLine->GetUpper();
953  pLine = pLine->GetUpper() ? pLine->GetUpper()->GetUpper() : nullptr;
954  }
955  // After we've inserted a bunch of boxes (hopefully all and in
956  // correct order), we just need to process them in reverse order.
957  for ( int j = aParm.aBoxArr.size()-1; j >= 0; --j )
958  {
959  SwTableBox *pBox = aParm.aBoxArr[j];
960  ::lcl_ProcessBoxSet( pBox, aParm );
961  }
962  }
963  else
964  {
965  // Adjusting the entire table is 'easy'. All boxes without lines are
966  // adjusted, as are their superiors. Of course we need to process
967  // in reverse order to prevent fooling ourselves!
968  SwTableLines &rLines = GetTabLines();
969  for ( size_t i = rLines.size(); i > 0; )
970  {
971  --i;
972  ::lcl_ProcessLine( rLines[i], aParm );
973  }
974  }
975  }
976 
977 #ifdef DBG_UTIL
978  {
979  // do some checking for correct table widths
981  for (size_t n = 0; n < m_aLines.size(); ++n)
982  {
983  CheckBoxWidth( *m_aLines[ n ], nSize );
984  }
985  }
986 #endif
987 }
988 
989 typedef std::pair<sal_uInt16, sal_uInt16> ColChange;
990 typedef std::list< ColChange > ChangeList;
991 
992 static void lcl_AdjustWidthsInLine( SwTableLine* pLine, ChangeList& rOldNew,
993  Parm& rParm, sal_uInt16 nColFuzzy )
994 {
995  ChangeList::iterator pCurr = rOldNew.begin();
996  if( pCurr == rOldNew.end() )
997  return;
998  const size_t nCount = pLine->GetTabBoxes().size();
999  SwTwips nBorder = 0;
1000  SwTwips nRest = 0;
1001  for( size_t i = 0; i < nCount; ++i )
1002  {
1003  SwTableBox* pBox = pLine->GetTabBoxes()[i];
1004  SwTwips nWidth = pBox->GetFrameFormat()->GetFrameSize().GetWidth();
1005  SwTwips nNewWidth = nWidth - nRest;
1006  nRest = 0;
1007  nBorder += nWidth;
1008  if( pCurr != rOldNew.end() && nBorder + nColFuzzy >= pCurr->first )
1009  {
1010  nBorder -= nColFuzzy;
1011  while( pCurr != rOldNew.end() && nBorder > pCurr->first )
1012  ++pCurr;
1013  if( pCurr != rOldNew.end() )
1014  {
1015  nBorder += nColFuzzy;
1016  if( nBorder + nColFuzzy >= pCurr->first )
1017  {
1018  if( pCurr->second == pCurr->first )
1019  nRest = 0;
1020  else
1021  nRest = pCurr->second - nBorder;
1022  nNewWidth += nRest;
1023  ++pCurr;
1024  }
1025  }
1026  }
1027  if( nNewWidth != nWidth )
1028  {
1029  if( nNewWidth < 0 )
1030  {
1031  nRest += 1 - nNewWidth;
1032  nNewWidth = 1;
1033  }
1034  SwFormatFrameSize aFormatFrameSize( pBox->GetFrameFormat()->GetFrameSize() );
1035  aFormatFrameSize.SetWidth( nNewWidth );
1036  rParm.aShareFormats.SetSize( *pBox, aFormatFrameSize );
1037  }
1038  }
1039 }
1040 
1041 static void lcl_CalcNewWidths( std::list<sal_uInt16> &rSpanPos, ChangeList& rChanges,
1042  SwTableLine* pLine, long nWish, long nWidth, bool bTop )
1043 {
1044  if( rChanges.empty() )
1045  {
1046  rSpanPos.clear();
1047  return;
1048  }
1049  if( rSpanPos.empty() )
1050  {
1051  rChanges.clear();
1052  return;
1053  }
1054  std::list<sal_uInt16> aNewSpanPos;
1055  ChangeList aNewChanges;
1056  ChangeList::iterator pCurr = rChanges.begin();
1057  aNewChanges.push_back( *pCurr ); // Nullposition
1058  std::list<sal_uInt16>::iterator pSpan = rSpanPos.begin();
1059  sal_uInt16 nCurr = 0;
1060  SwTwips nOrgSum = 0;
1061  bool bRowSpan = false;
1062  sal_uInt16 nRowSpanCount = 0;
1063  const size_t nCount = pLine->GetTabBoxes().size();
1064  for( size_t nCurrBox = 0; nCurrBox < nCount; ++nCurrBox )
1065  {
1066  SwTableBox* pBox = pLine->GetTabBoxes()[nCurrBox];
1067  SwTwips nCurrWidth = pBox->GetFrameFormat()->GetFrameSize().GetWidth();
1068  const long nRowSpan = pBox->getRowSpan();
1069  const bool bCurrRowSpan = bTop ? nRowSpan < 0 :
1070  ( nRowSpan > 1 || nRowSpan < -1 );
1071  if( bRowSpan || bCurrRowSpan )
1072  aNewSpanPos.push_back( nRowSpanCount );
1073  bRowSpan = bCurrRowSpan;
1074  nOrgSum += nCurrWidth;
1075  const sal_uInt16 nPos = lcl_MulDiv64<sal_uInt16>(
1076  lcl_MulDiv64<sal_uInt64>(nOrgSum, nWidth, nWish),
1077  nWish, nWidth);
1078  while( pCurr != rChanges.end() && pCurr->first < nPos )
1079  {
1080  ++nCurr;
1081  ++pCurr;
1082  }
1083  bool bNew = true;
1084  if( pCurr != rChanges.end() && pCurr->first <= nPos &&
1085  pCurr->first != pCurr->second )
1086  {
1087  pSpan = std::find_if(pSpan, rSpanPos.end(),
1088  [nCurr](const sal_uInt16 nSpan) { return nSpan >= nCurr; });
1089  if( pSpan != rSpanPos.end() && *pSpan == nCurr )
1090  {
1091  aNewChanges.push_back( *pCurr );
1092  ++nRowSpanCount;
1093  bNew = false;
1094  }
1095  }
1096  if( bNew )
1097  {
1098  ColChange aTmp( nPos, nPos );
1099  aNewChanges.push_back( aTmp );
1100  ++nRowSpanCount;
1101  }
1102  }
1103 
1104  pCurr = aNewChanges.begin();
1105  ChangeList::iterator pLast = pCurr;
1106  ChangeList::iterator pLeftMove = pCurr;
1107  while( pCurr != aNewChanges.end() )
1108  {
1109  if( pLeftMove == pCurr )
1110  {
1111  while( ++pLeftMove != aNewChanges.end() && pLeftMove->first <= pLeftMove->second )
1112  ;
1113  }
1114  if( pCurr->second == pCurr->first )
1115  {
1116  if( pLeftMove != aNewChanges.end() && pCurr->second > pLeftMove->second )
1117  {
1118  if( pLeftMove->first == pLast->first )
1119  pCurr->second = pLeftMove->second;
1120  else
1121  {
1122  pCurr->second = lcl_MulDiv64<sal_uInt16>(
1123  pCurr->first - pLast->first,
1124  pLeftMove->second - pLast->second,
1125  pLeftMove->first - pLast->first) + pLast->second;
1126  }
1127  }
1128  pLast = pCurr;
1129  ++pCurr;
1130  }
1131  else if( pCurr->second > pCurr->first )
1132  {
1133  pLast = pCurr;
1134  ++pCurr;
1135  ChangeList::iterator pNext = pCurr;
1136  while( pNext != pLeftMove && pNext->second == pNext->first &&
1137  pNext->second < pLast->second )
1138  ++pNext;
1139  while( pCurr != pNext )
1140  {
1141  if( pNext == aNewChanges.end() || pNext->first == pLast->first )
1142  pCurr->second = pLast->second;
1143  else
1144  {
1145  pCurr->second = lcl_MulDiv64<sal_uInt16>(
1146  pCurr->first - pLast->first,
1147  pNext->second - pLast->second,
1148  pNext->first - pLast->first) + pLast->second;
1149  }
1150  ++pCurr;
1151  }
1152  pLast = pCurr;
1153  }
1154  else
1155  {
1156  pLast = pCurr;
1157  ++pCurr;
1158  }
1159  }
1160 
1161  rChanges.swap(aNewChanges);
1162  rSpanPos.swap(aNewSpanPos);
1163 }
1164 
1165 void SwTable::NewSetTabCols( Parm &rParm, const SwTabCols &rNew,
1166  const SwTabCols &rOld, const SwTableBox *pStart, bool bCurRowOnly )
1167 {
1168 #if OSL_DEBUG_LEVEL > 1
1169  static int nCallCount = 0;
1170  ++nCallCount;
1171 #endif
1172  // First step: evaluate which lines have been moved/which widths changed
1173  ChangeList aOldNew;
1174  const long nNewWidth = rParm.rNew.GetRight() - rParm.rNew.GetLeft();
1175  const long nOldWidth = rParm.rOld.GetRight() - rParm.rOld.GetLeft();
1176  if( nNewWidth < 1 || nOldWidth < 1 )
1177  return;
1178  for( size_t i = 0; i <= rOld.Count(); ++i )
1179  {
1180  long nNewPos;
1181  long nOldPos;
1182  if( i == rOld.Count() )
1183  {
1184  nOldPos = rParm.rOld.GetRight() - rParm.rOld.GetLeft();
1185  nNewPos = rParm.rNew.GetRight() - rParm.rNew.GetLeft();
1186  }
1187  else
1188  {
1189  nOldPos = rOld[i] - rParm.rOld.GetLeft();
1190  nNewPos = rNew[i] - rParm.rNew.GetLeft();
1191  }
1192  nNewPos = lcl_MulDiv64<long>(nNewPos, rParm.nNewWish, nNewWidth);
1193  nOldPos = lcl_MulDiv64<long>(nOldPos, rParm.nOldWish, nOldWidth);
1194  if( nOldPos != nNewPos && nNewPos > 0 && nOldPos > 0 )
1195  {
1196  ColChange aChg( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
1197  aOldNew.push_back( aChg );
1198  }
1199  }
1200  // Finished first step
1201  int nCount = aOldNew.size();
1202  if( !nCount )
1203  return; // no change, nothing to do
1204  SwTableLines &rLines = GetTabLines();
1205  if( bCurRowOnly )
1206  {
1207  const SwTableLine* pCurrLine = pStart->GetUpper();
1208  sal_uInt16 nCurr = rLines.GetPos( pCurrLine );
1209  if( nCurr >= USHRT_MAX )
1210  return;
1211 
1212  ColChange aChg( 0, 0 );
1213  aOldNew.push_front( aChg );
1214  std::list<sal_uInt16> aRowSpanPos;
1215  if( nCurr )
1216  {
1217  ChangeList aCopy;
1218  sal_uInt16 nPos = 0;
1219  for( const auto& rCop : aOldNew )
1220  {
1221  aCopy.push_back( rCop );
1222  aRowSpanPos.push_back( nPos++ );
1223  }
1224  lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[nCurr],
1225  rParm.nOldWish, nOldWidth, true );
1226  bool bGoOn = !aRowSpanPos.empty();
1227  sal_uInt16 j = nCurr;
1228  while( bGoOn )
1229  {
1230  lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[--j],
1231  rParm.nOldWish, nOldWidth, true );
1232  lcl_AdjustWidthsInLine( rLines[j], aCopy, rParm, 0 );
1233  bGoOn = !aRowSpanPos.empty() && j > 0;
1234  }
1235  aRowSpanPos.clear();
1236  }
1237  if( nCurr+1 < static_cast<sal_uInt16>(rLines.size()) )
1238  {
1239  ChangeList aCopy;
1240  sal_uInt16 nPos = 0;
1241  for( const auto& rCop : aOldNew )
1242  {
1243  aCopy.push_back( rCop );
1244  aRowSpanPos.push_back( nPos++ );
1245  }
1246  lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[nCurr],
1247  rParm.nOldWish, nOldWidth, false );
1248  bool bGoOn = !aRowSpanPos.empty();
1249  sal_uInt16 j = nCurr;
1250  while( bGoOn )
1251  {
1252  lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[++j],
1253  rParm.nOldWish, nOldWidth, false );
1254  lcl_AdjustWidthsInLine( rLines[j], aCopy, rParm, 0 );
1255  bGoOn = !aRowSpanPos.empty() && j+1 < static_cast<sal_uInt16>(rLines.size());
1256  }
1257  }
1258  ::lcl_AdjustWidthsInLine( rLines[nCurr], aOldNew, rParm, COLFUZZY );
1259  }
1260  else
1261  {
1262  for( size_t i = 0; i < rLines.size(); ++i )
1263  ::lcl_AdjustWidthsInLine( rLines[i], aOldNew, rParm, COLFUZZY );
1264  }
1265  CHECK_TABLE( *this )
1266 }
1267 
1268 // return the pointer of the box specified.
1269 static bool lcl_IsValidRowName( const OUString& rStr )
1270 {
1271  bool bIsValid = true;
1272  sal_Int32 nLen = rStr.getLength();
1273  for( sal_Int32 i = 0; i < nLen && bIsValid; ++i )
1274  {
1275  const sal_Unicode cChar = rStr[i];
1276  if (cChar < '0' || cChar > '9')
1277  bIsValid = false;
1278  }
1279  return bIsValid;
1280 }
1281 
1282 // #i80314#
1283 // add 3rd parameter and its handling
1284 sal_uInt16 SwTable::GetBoxNum( OUString& rStr, bool bFirstPart,
1285  const bool bPerformValidCheck )
1286 {
1287  sal_uInt16 nRet = 0;
1288  if( bFirstPart ) // true == column; false == row
1289  {
1290  sal_Int32 nPos = 0;
1291  // the first one uses letters for addressing!
1292  bool bFirst = true;
1293  sal_uInt32 num = 0;
1294  bool overflow = false;
1295  while (nPos<rStr.getLength())
1296  {
1297  sal_Unicode cChar = rStr[nPos];
1298  if ((cChar<'A' || cChar>'Z') && (cChar<'a' || cChar>'z'))
1299  break;
1300  cChar -= 'A';
1301  if( cChar >= 26 )
1302  cChar -= 'a' - '[';
1303  if( bFirst )
1304  bFirst = false;
1305  else
1306  ++num;
1307  num = num * 52 + cChar;
1308  if (num > SAL_MAX_UINT16) {
1309  overflow = true;
1310  }
1311  ++nPos;
1312  }
1313  nRet = overflow ? SAL_MAX_UINT16 : num;
1314  rStr = rStr.copy( nPos ); // Remove char from String
1315  }
1316  else
1317  {
1318  const sal_Int32 nPos = rStr.indexOf( "." );
1319  if ( nPos<0 )
1320  {
1321  nRet = 0;
1322  if ( !bPerformValidCheck || lcl_IsValidRowName( rStr ) )
1323  {
1324  nRet = static_cast<sal_uInt16>(rStr.toInt32());
1325  }
1326  rStr.clear();
1327  }
1328  else
1329  {
1330  nRet = 0;
1331  const OUString aText( rStr.copy( 0, nPos ) );
1332  if ( !bPerformValidCheck || lcl_IsValidRowName( aText ) )
1333  {
1334  nRet = static_cast<sal_uInt16>(aText.toInt32());
1335  }
1336  rStr = rStr.copy( nPos+1 );
1337  }
1338  }
1339  return nRet;
1340 }
1341 
1342 // #i80314#
1343 // add 2nd parameter and its handling
1344 const SwTableBox* SwTable::GetTableBox( const OUString& rName,
1345  const bool bPerformValidCheck ) const
1346 {
1347  const SwTableBox* pBox = nullptr;
1348  const SwTableLine* pLine;
1349  const SwTableLines* pLines;
1350 
1351  sal_uInt16 nLine, nBox;
1352  OUString aNm( rName );
1353  while( !aNm.isEmpty() )
1354  {
1355  nBox = SwTable::GetBoxNum( aNm, nullptr == pBox, bPerformValidCheck );
1356  // first box ?
1357  if( !pBox )
1358  pLines = &GetTabLines();
1359  else
1360  {
1361  pLines = &pBox->GetTabLines();
1362  if( nBox )
1363  --nBox;
1364  }
1365 
1366  nLine = SwTable::GetBoxNum( aNm, false, bPerformValidCheck );
1367 
1368  // determine line
1369  if( !nLine || nLine > pLines->size() )
1370  return nullptr;
1371  pLine = (*pLines)[ nLine-1 ];
1372 
1373  // determine box
1374  const SwTableBoxes* pBoxes = &pLine->GetTabBoxes();
1375  if( nBox >= pBoxes->size() )
1376  return nullptr;
1377  pBox = (*pBoxes)[ nBox ];
1378  }
1379 
1380  // check if the box found has any contents
1381  if( pBox && !pBox->GetSttNd() )
1382  {
1383  OSL_FAIL( "Box without content, looking for the next one!" );
1384  // "drop this" until the first box
1385  while( !pBox->GetTabLines().empty() )
1386  pBox = pBox->GetTabLines().front()->GetTabBoxes().front();
1387  }
1388  return pBox;
1389 }
1390 
1392 {
1393  // For optimizations, don't always process the entire SortArray.
1394  // Converting text to table, tries certain conditions
1395  // to ask for a table box of a table that is not yet having a format
1396  if(!GetFrameFormat())
1397  return nullptr;
1398  SwTableBox* pRet = nullptr;
1399  SwNodes& rNds = GetFrameFormat()->GetDoc()->GetNodes();
1400  sal_uLong nIndex = nSttIdx + 1;
1401  SwContentNode* pCNd = nullptr;
1402  SwTableNode* pTableNd = nullptr;
1403 
1404  while ( nIndex < rNds.Count() )
1405  {
1406  pTableNd = rNds[ nIndex ]->GetTableNode();
1407  if ( pTableNd )
1408  break;
1409 
1410  pCNd = rNds[ nIndex ]->GetContentNode();
1411  if ( pCNd )
1412  break;
1413 
1414  ++nIndex;
1415  }
1416 
1417  if ( pCNd || pTableNd )
1418  {
1419  SwModify* pModify = pCNd;
1420  // #144862# Better handling of table in table
1421  if ( pTableNd && pTableNd->GetTable().GetFrameFormat() )
1422  pModify = pTableNd->GetTable().GetFrameFormat();
1423 
1424  SwFrame* pFrame = pModify ? SwIterator<SwFrame,SwModify>(*pModify).First() : nullptr;
1425  while ( pFrame && !pFrame->IsCellFrame() )
1426  pFrame = pFrame->GetUpper();
1427  if ( pFrame )
1428  pRet = const_cast<SwTableBox*>(static_cast<SwCellFrame*>(pFrame)->GetTabBox());
1429  }
1430 
1431  // In case the layout doesn't exist yet or anything else goes wrong.
1432  if ( !pRet )
1433  {
1434  for (size_t n = m_TabSortContentBoxes.size(); n; )
1435  {
1436  if (m_TabSortContentBoxes[ --n ]->GetSttIdx() == nSttIdx)
1437  {
1438  return m_TabSortContentBoxes[ n ];
1439  }
1440  }
1441  }
1442  return pRet;
1443 }
1444 
1446 {
1447  // Returns true for complex tables, i.e. tables that contain nestings,
1448  // like containing boxes not part of the first line, e.g. results of
1449  // splits/merges which lead to more complex structures.
1450  for (size_t n = 0; n < m_TabSortContentBoxes.size(); ++n)
1451  {
1452  if (m_TabSortContentBoxes[ n ]->GetUpper()->GetUpper())
1453  {
1454  return true;
1455  }
1456  }
1457  return false;
1458 }
1459 
1460 SwTableLine::SwTableLine( SwTableLineFormat *pFormat, sal_uInt16 nBoxes,
1461  SwTableBox *pUp )
1462  : SwClient( pFormat ),
1463  m_aBoxes(),
1464  m_pUpper( pUp )
1465 {
1466  m_aBoxes.reserve( nBoxes );
1467 }
1468 
1470 {
1471  for (size_t i = 0; i < m_aBoxes.size(); ++i)
1472  {
1473  delete m_aBoxes[i];
1474  }
1475  // the TabelleLine can be deleted if it's the last client of the FrameFormat
1476  SwModify* pMod = GetFrameFormat();
1477  pMod->Remove( this ); // remove,
1478  if( !pMod->HasWriterListeners() )
1479  delete pMod; // and delete
1480 }
1481 
1483 {
1484  // This method makes sure that this object is an exclusive SwTableLine client
1485  // of an SwTableLineFormat object
1486  // If other SwTableLine objects currently listen to the same SwTableLineFormat as
1487  // this one, something needs to be done
1488  SwTableLineFormat *pRet = static_cast<SwTableLineFormat*>(GetFrameFormat());
1489  SwIterator<SwTableLine,SwFormat> aIter( *pRet );
1490  for( SwTableLine* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1491  {
1492  if ( pLast != this )
1493  {
1494  // found another SwTableLine that is a client of the current Format
1495  // create a new Format as a copy and use it for this object
1496  SwTableLineFormat *pNewFormat = pRet->GetDoc()->MakeTableLineFormat();
1497  *pNewFormat = *pRet;
1498 
1499  // register SwRowFrames that know me as clients at the new Format
1500  SwIterator<SwRowFrame,SwFormat> aFrameIter( *pRet );
1501  for( SwRowFrame* pFrame = aFrameIter.First(); pFrame; pFrame = aFrameIter.Next() )
1502  if( pFrame->GetTabLine() == this )
1503  pFrame->RegisterToFormat( *pNewFormat );
1504 
1505  // register myself
1506  pNewFormat->Add( this );
1507  pRet = pNewFormat;
1508  break;
1509  }
1510  }
1511 
1512  return pRet;
1513 }
1514 
1516 {
1517  SwFrameFormat *pOld = GetFrameFormat();
1518  SwIterator<SwRowFrame,SwFormat> aIter( *pOld );
1519 
1520  // First, re-register the Frames.
1521  for( SwRowFrame* pRow = aIter.First(); pRow; pRow = aIter.Next() )
1522  {
1523  if( pRow->GetTabLine() == this )
1524  {
1525  pRow->RegisterToFormat( *pNewFormat );
1526 
1527  pRow->InvalidateSize();
1528  pRow->InvalidatePrt_();
1529  pRow->SetCompletePaint();
1530  pRow->ReinitializeFrameSizeAttrFlags();
1531 
1532  // #i35063#
1533  // consider 'split row allowed' attribute
1534  SwTabFrame* pTab = pRow->FindTabFrame();
1535  bool bInFollowFlowRow = false;
1536  const bool bInFirstNonHeadlineRow = pTab->IsFollow() &&
1537  pRow == pTab->GetFirstNonHeadlineRow();
1538  if ( bInFirstNonHeadlineRow ||
1539  !pRow->GetNext() ||
1540  ( bInFollowFlowRow = pRow->IsInFollowFlowRow() ) ||
1541  nullptr != pRow->IsInSplitTableRow() )
1542  {
1543  if ( bInFirstNonHeadlineRow || bInFollowFlowRow )
1544  pTab = pTab->FindMaster();
1545 
1546  pTab->SetRemoveFollowFlowLinePending( true );
1547  pTab->InvalidatePos();
1548  }
1549  }
1550  }
1551 
1552  // Now, re-register self.
1553  pNewFormat->Add( this );
1554 
1555  if ( !pOld->HasWriterListeners() )
1556  delete pOld;
1557 }
1558 
1559 SwTwips SwTableLine::GetTableLineHeight( bool& bLayoutAvailable ) const
1560 {
1561  SwTwips nRet = 0;
1562  bLayoutAvailable = false;
1564  // A row could appear several times in headers/footers so only one chain of master/follow tables
1565  // will be accepted...
1566  const SwTabFrame* pChain = nullptr; // My chain
1567  for( SwRowFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1568  {
1569  if( pLast->GetTabLine() == this )
1570  {
1571  const SwTabFrame* pTab = pLast->FindTabFrame();
1572  bLayoutAvailable = ( pTab && pTab->IsVertical() ) ?
1573  ( 0 < pTab->getFrameArea().Height() ) :
1574  ( 0 < pTab->getFrameArea().Width() );
1575 
1576  // The first one defines the chain, if a chain is defined, only members of the chain
1577  // will be added.
1578  if (pTab && (!pChain || pChain->IsAnFollow( pTab ) || pTab->IsAnFollow(pChain)))
1579  {
1580  pChain = pTab; // defines my chain (even it is already)
1581  if( pTab->IsVertical() )
1582  nRet += pLast->getFrameArea().Width();
1583  else
1584  nRet += pLast->getFrameArea().Height();
1585  // Optimization, if there are no master/follows in my chain, nothing more to add
1586  if( !pTab->HasFollow() && !pTab->IsFollow() )
1587  break;
1588  // This is not an optimization, this is necessary to avoid double additions of
1589  // repeating rows
1590  if( pTab->IsInHeadline(*pLast) )
1591  break;
1592  }
1593  }
1594  }
1595  return nRet;
1596 }
1597 
1598 SwTableBox::SwTableBox( SwTableBoxFormat* pFormat, sal_uInt16 nLines, SwTableLine *pUp )
1599  : SwClient(nullptr)
1600  , m_aLines()
1601  , m_pStartNode(nullptr)
1602  , m_pUpper(pUp)
1603  , mnRowSpan(1)
1604  , mbDummyFlag(false)
1605  , mbDirectFormatting(false)
1606 {
1607  m_aLines.reserve( nLines );
1608  CheckBoxFormat( pFormat )->Add( this );
1609 }
1610 
1612  SwTableLine *pUp )
1613  : SwClient(nullptr)
1614  , m_aLines()
1615  , m_pUpper(pUp)
1616  , mnRowSpan(1)
1617  , mbDummyFlag(false)
1618  , mbDirectFormatting(false)
1619 {
1620  CheckBoxFormat( pFormat )->Add( this );
1621 
1622  m_pStartNode = rIdx.GetNode().GetStartNode();
1623 
1624  // insert into the table
1625  const SwTableNode* pTableNd = m_pStartNode->FindTableNode();
1626  assert(pTableNd && "In which table is that box?");
1627  SwTableSortBoxes& rSrtArr = const_cast<SwTableSortBoxes&>(pTableNd->GetTable().
1628  GetTabSortBoxes());
1629  SwTableBox* p = this; // error: &this
1630  rSrtArr.insert( p ); // insert
1631 }
1632 
1634  : SwClient(nullptr)
1635  , m_aLines()
1636  , m_pStartNode(&rSttNd)
1637  , m_pUpper(pUp)
1638  , mnRowSpan(1)
1639  , mbDummyFlag(false)
1640  , mbDirectFormatting(false)
1641 {
1642  CheckBoxFormat( pFormat )->Add( this );
1643 
1644  // insert into the table
1645  const SwTableNode* pTableNd = m_pStartNode->FindTableNode();
1646  OSL_ENSURE( pTableNd, "In which table is the box?" );
1647  SwTableSortBoxes& rSrtArr = const_cast<SwTableSortBoxes&>(pTableNd->GetTable().
1648  GetTabSortBoxes());
1649  SwTableBox* p = this; // error: &this
1650  rSrtArr.insert( p ); // insert
1651 }
1652 
1654 {
1655  if (m_pStartNode) // box containing contents?
1656  {
1657  // remove from table
1658  const SwTableNode* pTableNd = m_pStartNode->FindTableNode();
1659  assert(pTableNd && "In which table is that box?");
1660  SwTableSortBoxes& rSrtArr = const_cast<SwTableSortBoxes&>(pTableNd->GetTable().
1661  GetTabSortBoxes());
1662  SwTableBox *p = this; // error: &this
1663  rSrtArr.erase( p ); // remove
1664  m_pStartNode = nullptr; // clear it so this is only run once
1665  }
1666 }
1667 
1669 {
1670  if (!GetFrameFormat()->GetDoc()->IsInDtor())
1671  {
1672  RemoveFromTable();
1673  }
1674 
1675  // the TabelleBox can be deleted if it's the last client of the FrameFormat
1676  SwModify* pMod = GetFrameFormat();
1677  pMod->Remove( this ); // remove,
1678  if( !pMod->HasWriterListeners() )
1679  delete pMod; // and delete
1680 }
1681 
1683 {
1684  // We might need to create a new format here, because the box must be
1685  // added to the format solely if pFormat has a value or form.
1686  if( SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_VALUE, false ) ||
1687  SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_FORMULA, false ) )
1688  {
1689  SwTableBox* pOther = SwIterator<SwTableBox,SwFormat>( *pFormat ).First();
1690  if( pOther )
1691  {
1692  SwTableBoxFormat* pNewFormat = pFormat->GetDoc()->MakeTableBoxFormat();
1693  pNewFormat->LockModify();
1694  *pNewFormat = *pFormat;
1695 
1696  // Remove values and formulas
1698  pNewFormat->UnlockModify();
1699 
1700  pFormat = pNewFormat;
1701  }
1702  }
1703  return pFormat;
1704 }
1705 
1707 {
1708  // This method makes sure that this object is an exclusive SwTableBox client
1709  // of an SwTableBoxFormat object
1710  // If other SwTableBox objects currently listen to the same SwTableBoxFormat as
1711  // this one, something needs to be done
1712  SwTableBoxFormat *pRet = static_cast<SwTableBoxFormat*>(GetFrameFormat());
1713  SwIterator<SwTableBox,SwFormat> aIter( *pRet );
1714  for( SwTableBox* pLast = aIter.First(); pLast; pLast = aIter.Next() )
1715  {
1716  if ( pLast != this )
1717  {
1718  // Found another SwTableBox object
1719  // create a new Format as a copy and assign me to it
1720  // don't copy values and formulas
1721  SwTableBoxFormat* pNewFormat = pRet->GetDoc()->MakeTableBoxFormat();
1722  pNewFormat->LockModify();
1723  *pNewFormat = *pRet;
1725  pNewFormat->UnlockModify();
1726 
1727  // re-register SwCellFrame objects that know me
1728  SwIterator<SwCellFrame,SwFormat> aFrameIter( *pRet );
1729  for( SwCellFrame* pCell = aFrameIter.First(); pCell; pCell = aFrameIter.Next() )
1730  if( pCell->GetTabBox() == this )
1731  pCell->RegisterToFormat( *pNewFormat );
1732 
1733  // re-register myself
1734  pNewFormat->Add( this );
1735  pRet = pNewFormat;
1736  break;
1737  }
1738  }
1739  return pRet;
1740 }
1741 
1742 void SwTableBox::ChgFrameFormat( SwTableBoxFormat* pNewFormat, bool bNeedToReregister )
1743 {
1744  SwFrameFormat *pOld = GetFrameFormat();
1745  SwIterator<SwCellFrame,SwFormat> aIter( *pOld );
1746 
1747  // tdf#84635 We set bNeedToReregister=false to avoid a quadratic slowdown on loading large tables,
1748  // and since we are creating the table for the first time, no re-registration is necessary.
1749 
1750  // First, re-register the Frames.
1751  if (bNeedToReregister)
1752  for( SwCellFrame* pCell = aIter.First(); pCell; pCell = aIter.Next() )
1753  {
1754  if( pCell->GetTabBox() == this )
1755  {
1756  pCell->RegisterToFormat( *pNewFormat );
1757  pCell->InvalidateSize();
1758  pCell->InvalidatePrt_();
1759  pCell->SetCompletePaint();
1760  pCell->SetDerivedVert( false );
1761  pCell->CheckDirChange();
1762 
1763  // #i47489#
1764  // make sure that the row will be formatted, in order
1765  // to have the correct Get(Top|Bottom)MarginForLowers values
1766  // set at the row.
1767  const SwTabFrame* pTab = pCell->FindTabFrame();
1768  if ( pTab && pTab->IsCollapsingBorders() )
1769  {
1770  SwFrame* pRow = pCell->GetUpper();
1771  pRow->InvalidateSize_();
1772  pRow->InvalidatePrt_();
1773  }
1774  }
1775  }
1776 
1777  // Now, re-register self.
1778  pNewFormat->Add( this );
1779 
1780  if( !pOld->HasWriterListeners() )
1781  delete pOld;
1782 }
1783 
1784 // Return the name of this box. This is determined dynamically
1785 // resulting from the position in the lines/boxes/tables.
1786 void sw_GetTableBoxColStr( sal_uInt16 nCol, OUString& rNm )
1787 {
1788  const sal_uInt16 coDiff = 52; // 'A'-'Z' 'a' - 'z'
1789 
1790  do {
1791  const sal_uInt16 nCalc = nCol % coDiff;
1792  if( nCalc >= 26 )
1793  rNm = OUStringChar( sal_Unicode('a' - 26 + nCalc) ) + rNm;
1794  else
1795  rNm = OUStringChar( sal_Unicode('A' + nCalc) ) + rNm;
1796 
1797  nCol = nCol - nCalc;
1798  if( 0 == nCol )
1799  break;
1800  nCol /= coDiff;
1801  --nCol;
1802  } while( true );
1803 }
1804 
1806 {
1807  if( !m_pStartNode ) // box without content?
1808  {
1809  // search for the next first box?
1810  return Point( 0, 0 );
1811  }
1812 
1813  const SwTable& rTable = m_pStartNode->FindTableNode()->GetTable();
1814  sal_uInt16 nX, nY;
1815  const SwTableBox* pBox = this;
1816  do {
1817  const SwTableLine* pLine = pBox->GetUpper();
1818  // at the first level?
1819  const SwTableLines* pLines = pLine->GetUpper()
1820  ? &pLine->GetUpper()->GetTabLines() : &rTable.GetTabLines();
1821 
1822  nY = pLines->GetPos( pLine ) + 1 ;
1823  nX = pBox->GetUpper()->GetBoxPos( pBox ) + 1;
1824  pBox = pLine->GetUpper();
1825  } while( pBox );
1826  return Point( nX, nY );
1827 }
1828 
1829 OUString SwTableBox::GetName() const
1830 {
1831  if( !m_pStartNode ) // box without content?
1832  {
1833  // search for the next first box?
1834  return OUString();
1835  }
1836 
1837  const SwTable& rTable = m_pStartNode->FindTableNode()->GetTable();
1838  sal_uInt16 nPos;
1839  OUString sNm, sTmp;
1840  const SwTableBox* pBox = this;
1841  do {
1842  const SwTableLine* pLine = pBox->GetUpper();
1843  // at the first level?
1844  const SwTableLines* pLines = pLine->GetUpper()
1845  ? &pLine->GetUpper()->GetTabLines() : &rTable.GetTabLines();
1846 
1847  nPos = pLines->GetPos( pLine ) + 1;
1848  sTmp = OUString::number( nPos );
1849  if( !sNm.isEmpty() )
1850  sNm = sTmp + "." + sNm;
1851  else
1852  sNm = sTmp;
1853 
1854  nPos = pBox->GetUpper()->GetBoxPos( pBox );
1855  sTmp = OUString::number(nPos + 1);
1856  pBox = pLine->GetUpper();
1857  if( nullptr != pBox )
1858  sNm = sTmp + "." + sNm;
1859  else
1860  sw_GetTableBoxColStr( nPos, sNm );
1861 
1862  } while( pBox );
1863  return sNm;
1864 }
1865 
1866 bool SwTableBox::IsInHeadline( const SwTable* pTable ) const
1867 {
1868  if( !GetUpper() ) // should only happen upon merge.
1869  return false;
1870 
1871  if( !pTable )
1872  pTable = &m_pStartNode->FindTableNode()->GetTable();
1873 
1874  const SwTableLine* pLine = GetUpper();
1875  while( pLine->GetUpper() )
1876  pLine = pLine->GetUpper()->GetUpper();
1877 
1878  // Headerline?
1879  return pTable->GetTabLines()[ 0 ] == pLine;
1880 }
1881 
1883 {
1884  return m_pStartNode ? m_pStartNode->GetIndex() : 0;
1885 }
1886 
1887  // retrieve information from the client
1888 bool SwTable::GetInfo( SfxPoolItem& rInfo ) const
1889 {
1890  switch( rInfo.Which() )
1891  {
1892  case RES_AUTOFMT_DOCNODE:
1893  {
1894  const SwTableNode* pNode = GetTableNode();
1895  if (pNode && &pNode->GetNodes() == static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes)
1896  {
1898  {
1899  SwNodeIndex aIdx( *m_TabSortContentBoxes[0]->GetSttNd() );
1900  GetFrameFormat()->GetDoc()->GetNodes().GoNext( &aIdx );
1901  }
1902  return false;
1903  }
1904  break;
1905  }
1906  case RES_FINDNEARESTNODE:
1907  if( GetFrameFormat() &&
1908  GetFrameFormat()->GetFormatAttr( RES_PAGEDESC ).GetPageDesc() &&
1910  m_TabSortContentBoxes[0]->GetSttNd()->GetNodes().IsDocNodes() )
1911  static_cast<SwFindNearestNode&>(rInfo).CheckNode( *
1912  m_TabSortContentBoxes[0]->GetSttNd()->FindTableNode() );
1913  break;
1914 
1915  case RES_CONTENT_VISIBLE:
1917  return false;
1918  }
1919  return true;
1920 }
1921 
1922 SwTable * SwTable::FindTable( SwFrameFormat const*const pFormat )
1923 {
1924  return pFormat
1925  ? SwIterator<SwTable,SwFormat>(*pFormat).First()
1926  : nullptr;
1927 }
1928 
1930 {
1931  return !GetTabSortBoxes().empty() ?
1932  const_cast<SwTableNode*>(GetTabSortBoxes()[ 0 ]->GetSttNd()->FindTableNode()) :
1933  m_pTableNode;
1934 }
1935 
1937 {
1938  if( m_xRefObj.is() )
1939  m_xRefObj->Closed();
1940 
1941  m_xRefObj = pObj;
1942 }
1943 
1944 void SwTable::SetHTMLTableLayout(std::shared_ptr<SwHTMLTableLayout> const& r)
1945 {
1946  m_xHTMLLayout = r;
1947 }
1948 
1949 static void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol,
1950  bool bChgAlign )
1951 {
1952  sal_uLong nNdPos = rBox.IsValidNumTextNd();
1953  ChgTextToNum( rBox,rText,pCol,bChgAlign,nNdPos);
1954 }
1955 void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol,
1956  bool bChgAlign,sal_uLong nNdPos )
1957 {
1958 
1959  if( ULONG_MAX == nNdPos )
1960  return;
1961 
1962  SwDoc* pDoc = rBox.GetFrameFormat()->GetDoc();
1963  SwTextNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTextNode();
1964  const SfxPoolItem* pItem;
1965 
1966  // assign adjustment
1967  if( bChgAlign )
1968  {
1969  pItem = &pTNd->SwContentNode::GetAttr( RES_PARATR_ADJUST );
1970  SvxAdjust eAdjust = static_cast<const SvxAdjustItem*>(pItem)->GetAdjust();
1971  if( SvxAdjust::Left == eAdjust || SvxAdjust::Block == eAdjust )
1972  {
1973  SvxAdjustItem aAdjust( *static_cast<const SvxAdjustItem*>(pItem) );
1974  aAdjust.SetAdjust( SvxAdjust::Right );
1975  pTNd->SetAttr( aAdjust );
1976  }
1977  }
1978 
1979  // assign color or save "user color"
1980  if( !pTNd->GetpSwAttrSet() || SfxItemState::SET != pTNd->GetpSwAttrSet()->
1981  GetItemState( RES_CHRATR_COLOR, false, &pItem ))
1982  pItem = nullptr;
1983 
1984  const Color* pOldNumFormatColor = rBox.GetSaveNumFormatColor();
1985  const Color* pNewUserColor = pItem ? &static_cast<const SvxColorItem*>(pItem)->GetValue() : nullptr;
1986 
1987  if( ( pNewUserColor && pOldNumFormatColor &&
1988  *pNewUserColor == *pOldNumFormatColor ) ||
1989  ( !pNewUserColor && !pOldNumFormatColor ))
1990  {
1991  // Keep the user color, set updated values, delete old NumFormatColor if needed
1992  if( pCol )
1993  // if needed, set the color
1994  pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
1995  else if( pItem )
1996  {
1997  pNewUserColor = rBox.GetSaveUserColor();
1998  if( pNewUserColor )
1999  pTNd->SetAttr( SvxColorItem( *pNewUserColor, RES_CHRATR_COLOR ));
2000  else
2001  pTNd->ResetAttr( RES_CHRATR_COLOR );
2002  }
2003  }
2004  else
2005  {
2006  // Save user color, set NumFormat color if needed, but never reset the color
2007  rBox.SetSaveUserColor( pNewUserColor );
2008 
2009  if( pCol )
2010  // if needed, set the color
2011  pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2012 
2013  }
2014  rBox.SetSaveNumFormatColor( pCol );
2015 
2016  if( pTNd->GetText() != rText )
2017  {
2018  // Exchange text. Bugfix to keep Tabs (front and back!) and annotations (inword comment anchors)
2019  const OUString& rOrig = pTNd->GetText();
2020  sal_Int32 n;
2021 
2022  for( n = 0; n < rOrig.getLength() && ('\x9' == rOrig[n] || CH_TXTATR_INWORD == rOrig[n]); ++n )
2023  ;
2024  for( ; n < rOrig.getLength() && '\x01' == rOrig[n]; ++n )
2025  ;
2026  SwIndex aIdx( pTNd, n );
2027  for( n = rOrig.getLength(); n && ('\x9' == rOrig[--n] || CH_TXTATR_INWORD == rOrig[n]); )
2028  ;
2029  sal_Int32 nEndPos = n;
2030  n -= aIdx.GetIndex() - 1;
2031 
2032  // Reset DontExpand-Flags before exchange, to retrigger expansion
2033  {
2034  SwIndex aResetIdx( aIdx, n );
2035  pTNd->DontExpandFormat( aResetIdx, false, false );
2036  }
2037 
2039  {
2040  SwPaM aTemp(*pTNd, 0, *pTNd, rOrig.getLength());
2041  pDoc->getIDocumentRedlineAccess().DeleteRedline(aTemp, true, RedlineType::Any);
2042  }
2043 
2044  // preserve comments inside of the number by deleting number portions starting from the back
2045  sal_Int32 nCommentPos = pTNd->GetText().lastIndexOf( CH_TXTATR_INWORD, nEndPos );
2046  while( nCommentPos > aIdx.GetIndex() )
2047  {
2048  pTNd->EraseText( SwIndex(pTNd, nCommentPos+1), nEndPos - nCommentPos, SwInsertFlags::EMPTYEXPAND );
2049  // find the next non-sequential comment anchor
2050  do
2051  {
2052  nEndPos = nCommentPos;
2053  n = nEndPos - aIdx.GetIndex();
2054  nCommentPos = pTNd->GetText().lastIndexOf( CH_TXTATR_INWORD, nEndPos );
2055  --nEndPos;
2056  }
2057  while( nCommentPos > aIdx.GetIndex() && nCommentPos == nEndPos );
2058  }
2059 
2060  pTNd->EraseText( aIdx, n, SwInsertFlags::EMPTYEXPAND );
2061  pTNd->InsertText( rText, aIdx, SwInsertFlags::EMPTYEXPAND );
2062 
2063  if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
2064  {
2065  SwPaM aTemp(*pTNd, 0, *pTNd, rText.getLength());
2066  pDoc->getIDocumentRedlineAccess().AppendRedline(new SwRangeRedline(RedlineType::Insert, aTemp), true);
2067  }
2068  }
2069 
2070  // assign vertical orientation
2071  if( bChgAlign &&
2072  ( SfxItemState::SET != rBox.GetFrameFormat()->GetItemState(
2073  RES_VERT_ORIENT, true, &pItem ) ||
2074  text::VertOrientation::TOP == static_cast<const SwFormatVertOrient*>(pItem)->GetVertOrient() ))
2075  {
2076  rBox.GetFrameFormat()->SetFormatAttr( SwFormatVertOrient( 0, text::VertOrientation::BOTTOM ));
2077  }
2078 
2079 }
2080 
2081 static void ChgNumToText( SwTableBox& rBox, sal_uLong nFormat )
2082 {
2083  sal_uLong nNdPos = rBox.IsValidNumTextNd( false );
2084  if( ULONG_MAX == nNdPos )
2085  return;
2086 
2087  SwDoc* pDoc = rBox.GetFrameFormat()->GetDoc();
2088  SwTextNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTextNode();
2089  bool bChgAlign = pDoc->IsInsTableAlignNum();
2090  const SfxPoolItem* pItem;
2091 
2092  Color* pCol = nullptr;
2093  if( getSwDefaultTextFormat() != nFormat )
2094  {
2095  // special text format:
2096  OUString sTmp;
2097  const OUString sText( pTNd->GetText() );
2098  pDoc->GetNumberFormatter()->GetOutputString( sText, nFormat, sTmp, &pCol );
2099  if( sText != sTmp )
2100  {
2101  // exchange text
2102  SwIndex aIdx( pTNd, sText.getLength() );
2103  // Reset DontExpand-Flags before exchange, to retrigger expansion
2104  pTNd->DontExpandFormat( aIdx, false, false );
2105  aIdx = 0;
2107  pTNd->InsertText( sTmp, aIdx, SwInsertFlags::EMPTYEXPAND );
2108  }
2109  }
2110 
2111  const SfxItemSet* pAttrSet = pTNd->GetpSwAttrSet();
2112 
2113  // assign adjustment
2114  if( bChgAlign && pAttrSet && SfxItemState::SET == pAttrSet->GetItemState(
2115  RES_PARATR_ADJUST, false, &pItem ) &&
2116  SvxAdjust::Right == static_cast<const SvxAdjustItem*>(pItem)->GetAdjust() )
2117  {
2118  pTNd->SetAttr( SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ) );
2119  }
2120 
2121  // assign color or save "user color"
2122  if( !pAttrSet || SfxItemState::SET != pAttrSet->
2123  GetItemState( RES_CHRATR_COLOR, false, &pItem ))
2124  pItem = nullptr;
2125 
2126  const Color* pOldNumFormatColor = rBox.GetSaveNumFormatColor();
2127  const Color* pNewUserColor = pItem ? &static_cast<const SvxColorItem*>(pItem)->GetValue() : nullptr;
2128 
2129  if( ( pNewUserColor && pOldNumFormatColor &&
2130  *pNewUserColor == *pOldNumFormatColor ) ||
2131  ( !pNewUserColor && !pOldNumFormatColor ))
2132  {
2133  // Keep the user color, set updated values, delete old NumFormatColor if needed
2134  if( pCol )
2135  // if needed, set the color
2136  pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2137  else if( pItem )
2138  {
2139  pNewUserColor = rBox.GetSaveUserColor();
2140  if( pNewUserColor )
2141  pTNd->SetAttr( SvxColorItem( *pNewUserColor, RES_CHRATR_COLOR ));
2142  else
2143  pTNd->ResetAttr( RES_CHRATR_COLOR );
2144  }
2145  }
2146  else
2147  {
2148  // Save user color, set NumFormat color if needed, but never reset the color
2149  rBox.SetSaveUserColor( pNewUserColor );
2150 
2151  if( pCol )
2152  // if needed, set the color
2153  pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
2154 
2155  }
2156  rBox.SetSaveNumFormatColor( pCol );
2157 
2158  // assign vertical orientation
2159  if( bChgAlign &&
2160  SfxItemState::SET == rBox.GetFrameFormat()->GetItemState(
2161  RES_VERT_ORIENT, false, &pItem ) &&
2162  text::VertOrientation::BOTTOM == static_cast<const SwFormatVertOrient*>(pItem)->GetVertOrient() )
2163  {
2164  rBox.GetFrameFormat()->SetFormatAttr( SwFormatVertOrient( 0, text::VertOrientation::TOP ));
2165  }
2166 
2167 }
2168 
2169 // for detection of modifications (mainly TableBoxAttribute)
2170 void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2171 {
2172  if( !IsModifyLocked() && GetDoc() && !GetDoc()->IsInDtor())
2173  {
2174  const SwTableBoxNumFormat *pNewFormat = nullptr;
2175  const SwTableBoxFormula *pNewFormula = nullptr;
2176  const SwTableBoxValue *pNewVal = nullptr;
2177  sal_uLong nOldFormat = getSwDefaultTextFormat();
2178 
2179  switch( pNew ? pNew->Which() : 0 )
2180  {
2181  case RES_ATTRSET_CHG:
2182  {
2183  const SfxItemSet& rSet = *static_cast<const SwAttrSetChg*>(pNew)->GetChgSet();
2184  if( SfxItemState::SET == rSet.GetItemState( RES_BOXATR_FORMAT,
2185  false, reinterpret_cast<const SfxPoolItem**>(&pNewFormat) ) )
2186  nOldFormat = static_cast<const SwAttrSetChg*>(pOld)->
2187  GetChgSet()->Get( RES_BOXATR_FORMAT ).GetValue();
2188  rSet.GetItemState( RES_BOXATR_FORMULA, false,
2189  reinterpret_cast<const SfxPoolItem**>(&pNewFormula) );
2190  rSet.GetItemState( RES_BOXATR_VALUE, false,
2191  reinterpret_cast<const SfxPoolItem**>(&pNewVal) );
2192  break;
2193  }
2194  case RES_BOXATR_FORMAT:
2195  pNewFormat = static_cast<const SwTableBoxNumFormat*>(pNew);
2196  nOldFormat = static_cast<const SwTableBoxNumFormat*>(pOld)->GetValue();
2197  break;
2198  case RES_BOXATR_FORMULA:
2199  pNewFormula = static_cast<const SwTableBoxFormula*>(pNew);
2200  break;
2201  case RES_BOXATR_VALUE:
2202  pNewVal = static_cast<const SwTableBoxValue*>(pNew);
2203  break;
2204  }
2205 
2206  // something changed and some BoxAttribut remained in the set!
2207  if( pNewFormat || pNewFormula || pNewVal )
2208  {
2209  GetDoc()->getIDocumentFieldsAccess().SetFieldsDirty(true, nullptr, 0);
2210 
2211  if( SfxItemState::SET == GetItemState( RES_BOXATR_FORMAT, false ) ||
2212  SfxItemState::SET == GetItemState( RES_BOXATR_VALUE, false ) ||
2213  SfxItemState::SET == GetItemState( RES_BOXATR_FORMULA, false ) )
2214  {
2215  // fetch the box
2216  SwIterator<SwTableBox,SwFormat> aIter( *this );
2217  SwTableBox* pBox = aIter.First();
2218  if( pBox )
2219  {
2220  OSL_ENSURE( !aIter.Next(), "zero or more than one box at format" );
2221 
2222  sal_uLong nNewFormat;
2223  if( pNewFormat )
2224  {
2225  nNewFormat = pNewFormat->GetValue();
2226  // new formatting
2227  // is it newer or has the current been removed?
2228  if( SfxItemState::SET != GetItemState( RES_BOXATR_VALUE, false ))
2229  pNewFormat = nullptr;
2230  }
2231  else
2232  {
2233  // fetch the current Item
2234  (void)GetItemState(RES_BOXATR_FORMAT, false, reinterpret_cast<const SfxPoolItem**>(&pNewFormat));
2235  nOldFormat = GetTableBoxNumFormat().GetValue();
2236  nNewFormat = pNewFormat ? pNewFormat->GetValue() : nOldFormat;
2237  }
2238 
2239  // is it newer or has the current been removed?
2240  if( pNewVal )
2241  {
2242  if( GetDoc()->GetNumberFormatter()->IsTextFormat(nNewFormat) )
2243  nOldFormat = 0;
2244  else
2245  {
2246  if( SfxItemState::SET == GetItemState( RES_BOXATR_VALUE, false ))
2247  nOldFormat = getSwDefaultTextFormat();
2248  else
2249  nNewFormat = getSwDefaultTextFormat();
2250  }
2251  }
2252 
2253  // Logic:
2254  // Value change: -> "simulate" a format change!
2255  // Format change:
2256  // Text -> !Text or format change:
2257  // - align right for horizontal alignment, if LEFT or JUSTIFIED
2258  // - align bottom for vertical alignment, if TOP is set, or default
2259  // - replace text (color? negative numbers RED?)
2260  // !Text -> Text:
2261  // - align left for horizontal alignment, if RIGHT
2262  // - align top for vertical alignment, if BOTTOM is set
2263  SvNumberFormatter* pNumFormatr = GetDoc()->GetNumberFormatter();
2264  bool bNewIsTextFormat = pNumFormatr->IsTextFormat( nNewFormat );
2265 
2266  if( (!bNewIsTextFormat && nOldFormat != nNewFormat) || pNewFormula )
2267  {
2268  bool bIsNumFormat = false;
2269  OUString aOrigText;
2270  bool bChgText = true;
2271  double fVal = 0;
2272  if( !pNewVal && SfxItemState::SET != GetItemState(
2273  RES_BOXATR_VALUE, false, reinterpret_cast<const SfxPoolItem**>(&pNewVal) ))
2274  {
2275  // so far, no value has been set, so try to evaluate the content
2276  sal_uLong nNdPos = pBox->IsValidNumTextNd();
2277  if( ULONG_MAX != nNdPos )
2278  {
2279  sal_uInt32 nTmpFormatIdx = nNewFormat;
2280  OUString aText( GetDoc()->GetNodes()[ nNdPos ]
2281  ->GetTextNode()->GetRedlineText());
2282  aOrigText = aText;
2283  if( aText.isEmpty() )
2284  bChgText = false;
2285  else
2286  {
2287  // Keep Tabs
2288  lcl_TabToBlankAtSttEnd( aText );
2289 
2290  // JP 22.04.98: Bug 49659 -
2291  // Special casing for percent
2292  if( SvNumFormatType::PERCENT ==
2293  pNumFormatr->GetType( nNewFormat ))
2294  {
2295  sal_uInt32 nTmpFormat = 0;
2296  if( GetDoc()->IsNumberFormat(
2297  aText, nTmpFormat, fVal ))
2298  {
2299  if( SvNumFormatType::NUMBER ==
2300  pNumFormatr->GetType( nTmpFormat ))
2301  aText += "%";
2302 
2303  bIsNumFormat = GetDoc()->IsNumberFormat(
2304  aText, nTmpFormatIdx, fVal );
2305  }
2306  }
2307  else
2308  bIsNumFormat = GetDoc()->IsNumberFormat(
2309  aText, nTmpFormatIdx, fVal );
2310 
2311  if( bIsNumFormat )
2312  {
2313  // directly assign value - without Modify
2314  bool bIsLockMod = IsModifyLocked();
2315  LockModify();
2316  SetFormatAttr( SwTableBoxValue( fVal ));
2317  if( !bIsLockMod )
2318  UnlockModify();
2319  }
2320  }
2321  }
2322  }
2323  else
2324  {
2325  fVal = pNewVal->GetValue();
2326  bIsNumFormat = true;
2327  }
2328 
2329  // format contents with the new value assigned and write to paragraph
2330  Color* pCol = nullptr;
2331  OUString sNewText;
2332  if( DBL_MAX == fVal )
2333  {
2334  sNewText = SwViewShell::GetShellRes()->aCalc_Error;
2335  }
2336  else
2337  {
2338  if (bIsNumFormat)
2339  pNumFormatr->GetOutputString( fVal, nNewFormat, sNewText, &pCol );
2340  else
2341  {
2342  // Original text could not be parsed as
2343  // number/date/time/..., so keep the text.
2344 #if 0
2345  // Actually the text should be formatted
2346  // according to the format, which may include
2347  // additional text from the format, for example
2348  // in {0;-0;"BAD: "@}. But other places when
2349  // entering a new value or changing text or
2350  // changing to a different format of type Text
2351  // don't do this (yet?).
2352  pNumFormatr->GetOutputString( aOrigText, nNewFormat, sNewText, &pCol );
2353 #else
2354  sNewText = aOrigText;
2355 #endif
2356  }
2357 
2358  if( !bChgText )
2359  {
2360  sNewText.clear();
2361  }
2362  }
2363 
2364  // across all boxes
2365  ChgTextToNum( *pBox, sNewText, pCol,
2366  GetDoc()->IsInsTableAlignNum() );
2367 
2368  }
2369  else if( bNewIsTextFormat && nOldFormat != nNewFormat )
2370  {
2371  ChgNumToText( *pBox, nNewFormat );
2372  }
2373  }
2374  }
2375  }
2376  }
2377  // call base class
2378  SwFrameFormat::Modify( pOld, pNew );
2379 }
2380 
2382 {
2383  return false;
2384 }
2385 
2387 {
2388  return false;
2389 }
2390 
2392 {
2393  return false;
2394 }
2395 
2396 bool SwTableBox::HasNumContent( double& rNum, sal_uInt32& rFormatIndex,
2397  bool& rIsEmptyTextNd ) const
2398 {
2399  bool bRet = false;
2400  sal_uLong nNdPos = IsValidNumTextNd();
2401  if( ULONG_MAX != nNdPos )
2402  {
2403  OUString aText( m_pStartNode->GetNodes()[ nNdPos ]->GetTextNode()->GetRedlineText() );
2404  // Keep Tabs
2405  lcl_TabToBlankAtSttEnd( aText );
2406  rIsEmptyTextNd = aText.isEmpty();
2408 
2409  const SfxPoolItem* pItem;
2410  if( SfxItemState::SET == GetFrameFormat()->GetItemState( RES_BOXATR_FORMAT, false, &pItem ))
2411  {
2412  rFormatIndex = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue();
2413  // Special casing for percent
2414  if( !rIsEmptyTextNd && SvNumFormatType::PERCENT == pNumFormatr->GetType( rFormatIndex ))
2415  {
2416  sal_uInt32 nTmpFormat = 0;
2417  if( GetFrameFormat()->GetDoc()->IsNumberFormat( aText, nTmpFormat, rNum ) &&
2418  SvNumFormatType::NUMBER == pNumFormatr->GetType( nTmpFormat ))
2419  aText += "%";
2420  }
2421  }
2422  else
2423  rFormatIndex = 0;
2424 
2425  bRet = GetFrameFormat()->GetDoc()->IsNumberFormat( aText, rFormatIndex, rNum );
2426  }
2427  else
2428  rIsEmptyTextNd = false;
2429  return bRet;
2430 }
2431 
2433 {
2434  bool bRet = true;
2435 
2436  if( SfxItemState::SET == GetFrameFormat()->GetItemState( RES_BOXATR_FORMULA, false ))
2437  {
2438  const SwTableBoxNumFormat *pNumFormat;
2439  const SwTableBoxValue *pValue;
2440 
2441  if( SfxItemState::SET != GetFrameFormat()->GetItemState( RES_BOXATR_VALUE, false,
2442  reinterpret_cast<const SfxPoolItem**>(&pValue) ))
2443  pValue = nullptr;
2444  if( SfxItemState::SET != GetFrameFormat()->GetItemState( RES_BOXATR_FORMAT, false,
2445  reinterpret_cast<const SfxPoolItem**>(&pNumFormat) ))
2446  pNumFormat = nullptr;
2447 
2448  sal_uLong nNdPos;
2449  if( pNumFormat && pValue && ULONG_MAX != ( nNdPos = IsValidNumTextNd() ) )
2450  {
2451  OUString sNewText, sOldText( m_pStartNode->GetNodes()[ nNdPos ]->
2452  GetTextNode()->GetRedlineText() );
2453  lcl_DelTabsAtSttEnd( sOldText );
2454 
2455  Color* pCol = nullptr;
2457  pValue->GetValue(), pNumFormat->GetValue(), sNewText, &pCol );
2458 
2459  bRet = sNewText != sOldText ||
2460  !( ( !pCol && !GetSaveNumFormatColor() ) ||
2461  ( pCol && GetSaveNumFormatColor() &&
2462  *pCol == *GetSaveNumFormatColor() ));
2463  }
2464  }
2465  return bRet;
2466 }
2467 
2468 sal_uLong SwTableBox::IsValidNumTextNd( bool bCheckAttr ) const
2469 {
2470  sal_uLong nPos = ULONG_MAX;
2471  if( m_pStartNode )
2472  {
2473  SwNodeIndex aIdx( *m_pStartNode );
2474  sal_uLong nIndex = aIdx.GetIndex();
2475  const sal_uLong nIndexEnd = m_pStartNode->GetNodes()[ nIndex ]->EndOfSectionIndex();
2476  const SwTextNode *pTextNode = nullptr;
2477  while( ++nIndex < nIndexEnd )
2478  {
2479  const SwNode* pNode = m_pStartNode->GetNodes()[nIndex];
2480  if( pNode->IsTableNode() )
2481  {
2482  pTextNode = nullptr;
2483  break;
2484  }
2485  if( pNode->IsTextNode() )
2486  {
2487  if( pTextNode )
2488  {
2489  pTextNode = nullptr;
2490  break;
2491  }
2492  else
2493  {
2494  pTextNode = pNode->GetTextNode();
2495  nPos = nIndex;
2496  }
2497  }
2498  }
2499  if( pTextNode )
2500  {
2501  if( bCheckAttr )
2502  {
2503  const SwpHints* pHts = pTextNode->GetpSwpHints();
2504  // do some tests if there's only text in the node!
2505  // Flys/fields/...
2506  if( pHts )
2507  {
2508  sal_Int32 nNextSetField = 0;
2509  for( size_t n = 0; n < pHts->Count(); ++n )
2510  {
2511  const SwTextAttr* pAttr = pHts->Get(n);
2512  if( RES_TXTATR_NOEND_BEGIN <= pAttr->Which() )
2513  {
2514  if ( (pAttr->GetStart() == nNextSetField)
2515  && (pAttr->Which() == RES_TXTATR_FIELD))
2516  {
2517  // #i104949# hideous hack for report builder:
2518  // it inserts hidden variable-set fields at
2519  // the beginning of para in cell, but they
2520  // should not turn cell into text cell
2521  const SwField* pField = pAttr->GetFormatField().GetField();
2522  if (pField &&
2523  (pField->GetTypeId() == SwFieldTypesEnum::Set) &&
2524  (0 != (static_cast<SwSetExpField const*>
2525  (pField)->GetSubType() &
2527  {
2528  nNextSetField = pAttr->GetStart() + 1;
2529  continue;
2530  }
2531  }
2532  else if( RES_TXTATR_ANNOTATION == pAttr->Which() )
2533  {
2534  continue;
2535  }
2536  nPos = ULONG_MAX;
2537  break;
2538  }
2539  }
2540  }
2541  }
2542  }
2543  else
2544  nPos = ULONG_MAX;
2545  }
2546  return nPos;
2547 }
2548 
2549 // is this a Formula box or one with numeric content (AutoSum)
2551 {
2552  sal_uInt16 nWhich = 0;
2553  const SwTextNode* pTNd;
2554  SwFrameFormat* pFormat = GetFrameFormat();
2555  if( SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_FORMULA, false ))
2556  nWhich = RES_BOXATR_FORMULA;
2557  else if( SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_VALUE, false ) &&
2558  !pFormat->GetDoc()->GetNumberFormatter()->IsTextFormat(
2559  pFormat->GetTableBoxNumFormat().GetValue() ))
2560  nWhich = RES_BOXATR_VALUE;
2562  && nullptr != ( pTNd = m_pStartNode->GetNodes()[ m_pStartNode->GetIndex() + 1 ]
2563  ->GetTextNode() ) && pTNd->GetText().isEmpty())
2564  nWhich = USHRT_MAX;
2565 
2566  return nWhich;
2567 }
2568 
2570 {
2571  const SfxPoolItem *pFormatItem, *pValItem;
2572  SwFrameFormat* pFormat = GetFrameFormat();
2573  if( SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_FORMAT, true, &pFormatItem )
2574  && SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_VALUE, true, &pValItem ))
2575  {
2576  const sal_uLong nFormatId = static_cast<const SwTableBoxNumFormat*>(pFormatItem)->GetValue();
2577  sal_uLong nNdPos = ULONG_MAX;
2578  SvNumberFormatter* pNumFormatr = pFormat->GetDoc()->GetNumberFormatter();
2579 
2580  if( !pNumFormatr->IsTextFormat( nFormatId ) &&
2581  ULONG_MAX != (nNdPos = IsValidNumTextNd()) )
2582  {
2583  double fVal = static_cast<const SwTableBoxValue*>(pValItem)->GetValue();
2584  Color* pCol = nullptr;
2585  OUString sNewText;
2586  pNumFormatr->GetOutputString( fVal, nFormatId, sNewText, &pCol );
2587 
2588  const OUString& rText = m_pStartNode->GetNodes()[ nNdPos ]->GetTextNode()->GetText();
2589  if( rText != sNewText )
2590  ChgTextToNum( *this, sNewText, pCol, false ,nNdPos);
2591  }
2592  }
2593 }
2594 
2596 {
2601  TableBoxes_t m_HandledTableBoxes;
2602 
2603 public:
2605  : m_pTable(nullptr), m_pCellFrame(nullptr), m_pTabFrame(nullptr)
2606  {
2607  }
2608 
2609  void setTable(const SwTable * pTable)
2610  {
2611  m_pTable = pTable;
2612  SwFrameFormat * pFrameFormat = m_pTable->GetFrameFormat();
2613  m_pTabFrame = SwIterator<SwTabFrame,SwFormat>(*pFrameFormat).First();
2614  if (m_pTabFrame && m_pTabFrame->IsFollow())
2615  m_pTabFrame = m_pTabFrame->FindMaster(true);
2616  }
2617 
2618  const SwCellFrame * getCellFrame() const { return m_pCellFrame; }
2619 
2620  const SwFrame * getNextFrameInTable(const SwFrame * pFrame);
2621  const SwCellFrame * getNextCellFrame(const SwFrame * pFrame);
2622  const SwCellFrame * getNextTableBoxsCellFrame(const SwFrame * pFrame);
2623  bool getNext();
2624 };
2625 
2627 {
2628  const SwFrame * pResult = nullptr;
2629 
2630  if (((! pFrame->IsTabFrame()) || pFrame == m_pTabFrame) && pFrame->GetLower())
2631  pResult = pFrame->GetLower();
2632  else if (pFrame->GetNext())
2633  pResult = pFrame->GetNext();
2634  else
2635  {
2636  while (pFrame->GetUpper() != nullptr)
2637  {
2638  pFrame = pFrame->GetUpper();
2639 
2640  if (pFrame->IsTabFrame())
2641  {
2642  m_pTabFrame = static_cast<const SwTabFrame *>(pFrame)->GetFollow();
2643  pResult = m_pTabFrame;
2644  break;
2645  }
2646  else if (pFrame->GetNext())
2647  {
2648  pResult = pFrame->GetNext();
2649  break;
2650  }
2651  }
2652  }
2653 
2654  return pResult;
2655 }
2656 
2658 {
2659  const SwCellFrame * pResult = nullptr;
2660 
2661  while ((pFrame = getNextFrameInTable(pFrame)) != nullptr)
2662  {
2663  if (pFrame->IsCellFrame())
2664  {
2665  pResult = static_cast<const SwCellFrame *>(pFrame);
2666  break;
2667  }
2668  }
2669 
2670  return pResult;
2671 }
2672 
2674 {
2675  const SwCellFrame * pResult = nullptr;
2676 
2677  while ((pFrame = getNextCellFrame(pFrame)) != nullptr)
2678  {
2679  const SwCellFrame * pCellFrame = static_cast<const SwCellFrame *>(pFrame);
2680  const SwTableBox * pTabBox = pCellFrame->GetTabBox();
2681  auto aIt = m_HandledTableBoxes.insert(pTabBox);
2682  if (aIt.second)
2683  {
2684  pResult = pCellFrame;
2685  break;
2686  }
2687  }
2688 
2689  return pResult;
2690 }
2691 
2693 {
2694  return m_pImpl->getCellFrame();
2695 }
2696 
2698 {
2699  if (m_pCellFrame == nullptr)
2700  {
2701  if (m_pTabFrame != nullptr)
2702  m_pCellFrame = Impl::getNextTableBoxsCellFrame(m_pTabFrame);
2703  }
2704  else
2705  m_pCellFrame = Impl::getNextTableBoxsCellFrame(m_pCellFrame);
2706 
2707  return m_pCellFrame != nullptr;
2708 }
2709 
2711  : m_pImpl(std::make_unique<Impl>())
2712 {
2713  m_pImpl->setTable(pTable);
2714 }
2715 
2717 {
2718 }
2719 
2721 {
2722  return m_pImpl->getNext();
2723 }
2724 
2726 {
2727  SwRect aRet;
2728 
2729  if (getCellFrame() != nullptr)
2730  aRet = getCellFrame()->getFrameArea();
2731 
2732  return aRet;
2733 }
2734 
2736 {
2737  const SwTableBox * pRet = nullptr;
2738 
2739  if (getCellFrame() != nullptr)
2740  pRet = getCellFrame()->GetTabBox();
2741 
2742  return pRet;
2743 }
2744 
2746 {
2747  rFormat.Add( this );
2748 }
2749 
2751 {
2752  const SwFrameFormat* pFrameFormat = GetFrameFormat();
2753  //a table in a clipboard document doesn't have any layout information
2754  return pFrameFormat && SwIterator<SwTabFrame,SwFormat>(*pFrameFormat).First();
2755 }
2756 
2758 {
2759  rFormat.Add( this );
2760 }
2761 
2763 {
2764  rFormat.Add( this );
2765 }
2766 
2767 // free's any remaining child objects
2769 {
2770  for ( const_iterator it = begin(); it != end(); ++it )
2771  delete *it;
2772 }
2773 
2774 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTableLine(SwTableLineFormat *, sal_uInt16 nBoxes, SwTableBox *pUp)
Definition: swtable.cxx:1460
std::list< ColChange > ChangeList
Definition: swtable.cxx:990
SwTableNode * m_pTableNode
Definition: swtable.hxx:124
virtual ~SwTable() override
Definition: swtable.cxx:236
bool IsTableComplex() const
Definition: swtable.cxx:1445
const SwTableBoxNumFormat & GetTableBoxNumFormat(bool=true) const
TableBox attributes - implemented in cellatr.hxx.
Definition: cellatr.hxx:105
bool is() const
Starts a section of nodes in the document model.
Definition: node.hxx:303
Base class of the Writer layout elements.
Definition: frame.hxx:297
SwTwips GetTableLineHeight(bool &bLayoutAvailable) const
Definition: swtable.cxx:1559
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
sal_uLong GetIndex() const
Definition: node.hxx:282
const SwTabCols & rOld
Definition: swtable.cxx:614
SwTableLineFormat * MakeTableLineFormat()
Definition: docfmt.cxx:1712
sal_Int32 nIndex
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
bool IsFollow() const
Definition: flowfrm.hxx:166
sal_uLong Count() const
Definition: ndarr.hxx:142
void RegisterToFormat(SwFormat &rFormat)
Definition: swtable.cxx:2745
static OUString & lcl_DelTabsAtSttEnd(OUString &rText)
Definition: swtable.cxx:136
const SwField * GetField() const
Definition: fmtfld.hxx:111
static void lcl_AdjustBox(SwTableBox *pBox, const long nDiff, Parm &rParm)
Definition: swtable.cxx:820
const SwTableBox * GetTableBox(const OUString &rName, const bool bPerformValidCheck=false) const
Definition: swtable.cxx:1344
bool HasLayout() const
Definition: swtable.cxx:2750
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
const OUString & GetText() const
Definition: ndtxt.hxx:211
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2485
sal_uLong GetSttIdx() const
Definition: swtable.cxx:1882
o3tl::sorted_vector< const SwTableBox * > TableBoxes_t
Definition: swtable.cxx:2600
virtual bool SetAttr(const SfxPoolItem &) override
overriding to handle change of certain paragraph attributes
Definition: ndtxt.cxx:4884
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
std::string GetValue
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1407
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(150)
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:212
virtual AppendResult AppendRedline(SwRangeRedline *pNewRedl, bool bCallDelete)=0
Append a new redline.
const SwTabCols & rNew
Definition: swtable.cxx:613
bool IsInsTableAlignNum() const
Definition: doc.cxx:1690
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
long GetWidth() const
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, Color **ppColor, bool bUseStarFormat=false)
void SetSaveUserColor(const Color *p)
Definition: swtable.cxx:85
sal_uIntPtr sal_uLong
Base class of all fields.
Definition: fldbas.hxx:293
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:30
void RegisterToFormat(SwFormat &rFormat)
Definition: swtable.cxx:2757
bool DontExpandFormat(const SwIndex &rIdx, bool bFlag=true, bool bFormatToTextAttributes=true)
When appropriate set DontExpand-flag at INet or character styles respectively.
Definition: ndtxt.cxx:1600
sal_Int64 n
bool IsCollapsingBorders() const
Definition: tabfrm.cxx:5491
void InvalidateSize_()
Definition: frame.hxx:751
Definition: doc.hxx:184
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1482
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNewValue) override
Definition: atrfrm.cxx:2527
long GetRightMax() const
Definition: tabcol.hxx:79
TElementType * Next()
Definition: calbck.hxx:351
bool HasFollow() const
Definition: flowfrm.hxx:165
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:259
void setDummyFlag(bool bDummy)
Definition: swtable.cxx:116
SvNumFormatType GetType(sal_uInt32 nFIndex) const
void Height(long nNew)
Definition: swrect.hxx:191
void InvalidatePos()
Definition: frame.hxx:1021
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
long nOldWish
Definition: swtable.cxx:615
SwNode & GetNode() const
Definition: ndindex.hxx:119
void SetRefObject(SwServerObject *)
Definition: swtable.cxx:1936
long SwTwips
Definition: swtypes.hxx:49
OUString aCalc_Error
Definition: shellres.hxx:40
virtual bool supportsFullDrawingLayerFillAttributeSet() const override
Definition: swtable.cxx:2386
double GetValue() const
Definition: cellatr.hxx:95
bool IsInHeadline(const SwTable *pTable) const
Definition: swtable.cxx:1866
bool IsCellFrame() const
Definition: frame.hxx:1204
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
iterator begin()
Definition: swtable.hxx:75
sal_uInt16 Which() const
Definition: txatbase.hxx:110
SwClient * Remove(SwClient *pDepend)
Definition: calbck.cxx:259
SwTableLine * front() const
Definition: swtable.hxx:79
bool HasWriterListeners() const
Definition: calbck.hxx:208
EmbeddedObjectRef * pObject
static void lcl_RefreshHidden(SwTabCols &rToFill, size_t nPos)
Definition: swtable.cxx:375
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(59)
void setRowSpan(long nNewRowSpan)
Definition: swtable.cxx:106
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
void RemoveFromTable()
Definition: swtable.cxx:1653
const SwTabColsEntry & GetEntry(size_t nPos) const
Definition: tabcol.hxx:73
void Insert(long nValue, bool bValue, size_t nPos)
Definition: tabcol.cxx:69
size_type size() const
Definition: swtable.hxx:74
const SwCellFrame * getCellFrame() const
Definition: swtable.cxx:2692
void RegisterToFormat(SwFormat &rFormat)
Definition: swtable.cxx:2762
long GetRight() const
Definition: tabcol.hxx:78
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_CONTENT_VISIBLE(183)
SwTableBoxes m_aBoxes
Definition: swtable.hxx:346
static void lcl_CalcNewWidths(std::list< sal_uInt16 > &rSpanPos, ChangeList &rChanges, SwTableLine *pLine, long nWish, long nWidth, bool bTop)
Definition: swtable.cxx:1041
void DelTableFrameFormat(SwTableFormat *pFormat)
Definition: docfmt.cxx:726
SwTableLine * back() const
Definition: swtable.hxx:80
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(102)
void sw_GetTableBoxColStr(sal_uInt16 nCol, OUString &rNm)
Definition: swtable.cxx:1786
SwTableLines m_aLines
Definition: swtable.hxx:114
sal_uInt16 IsFormulaOrValueBox() const
Definition: swtable.cxx:2550
void ChgFrameFormat(SwTableLineFormat *pNewFormat)
Definition: swtable.cxx:1515
SwShareBoxFormats aShareFormats
Definition: swtable.cxx:618
sal_uInt16 sal_Unicode
void GetTabCols(SwTabCols &rToFill, const SwTableBox *pStart, bool bHidden=false, bool bCurRowOnly=false) const
Definition: swtable.cxx:527
#define CH_TXTATR_INWORD
Definition: hintids.hxx:171
const Color * GetSaveUserColor() const
Definition: swtable.cxx:75
const SwTableBox * GetTabBox() const
Definition: cellfrm.hxx:52
static void lcl_ProcessBoxSet(SwTableBox *pBox, Parm &rParm)
Definition: swtable.cxx:637
bool empty() const
Definition: docary.hxx:265
const SwRect & getFrameArea() const
Definition: frame.hxx:177
#define SAL_MAX_UINT16
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:773
static bool IsRedlineOn(const RedlineFlags eM)
const SwTabFrame * m_pTabFrame
Definition: swtable.cxx:2599
bool InsBoxen(SwTableNode *, SwTableLine *, SwTableBoxFormat *, SwTextFormatColl *, const SfxItemSet *pAutoAttr, sal_uInt16 nInsPos, sal_uInt16 nCnt=1)
Insert a new box in the line before InsPos.
Definition: ndtbl.cxx:230
virtual ~SwTableBox() override
Definition: swtable.cxx:1668
int nCount
void RemoveServer(SvLinkSource *rObj)
void UnlockModify()
Definition: swtable.hxx:182
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
TableChgMode m_eTableChgMode
Definition: swtable.hxx:127
SwTableBox(const SwTableBox &)=delete
void SetTabCols(const SwTabCols &rNew, const SwTabCols &rOld, const SwTableBox *pStart, bool bCurRowOnly)
Definition: swtable.cxx:832
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(161)
virtual bool SetFieldsDirty(bool b, const SwNode *pChk, sal_uLong nLen)=0
void SetHTMLTableLayout(std::shared_ptr< SwHTMLTableLayout > const &r)
Definition: swtable.cxx:1944
const SwTable & GetTable() const
Definition: node.hxx:497
SwTableCellInfo(SwTableCellInfo const &)=delete
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
SwTable()
Definition: swtable.cxx:204
void NewSetTabCols(Parm &rP, const SwTabCols &rNew, const SwTabCols &rOld, const SwTableBox *pStart, bool bCurRowOnly)
Definition: swtable.cxx:1165
size_type size() const
constexpr TypedWhichId< SwFindNearestNode > RES_FINDNEARESTNODE(182)
virtual bool GetInfo(SfxPoolItem &) const override
Definition: swtable.cxx:1888
std::vector< SwTableLine * >::const_iterator const_iterator
Definition: swtable.hxx:68
sal_uLong IsValidNumTextNd(bool bCheckAttr=true) const
Definition: swtable.cxx:2468
void ActualiseValueBox()
Definition: swtable.cxx:2569
static void ChgNumToText(SwTableBox &rBox, sal_uLong nFormat)
Definition: swtable.cxx:2081
const SwCellFrame * getCellFrame() const
Definition: swtable.cxx:2618
void SetWidth(long n)
const SwStartNode * m_pStartNode
Definition: swtable.hxx:396
tools::SvRef< SwServerObject > m_xRefObj
Definition: swtable.hxx:116
Base class for various Writer styles.
Definition: format.hxx:43
SwTableSortBoxes m_TabSortContentBoxes
Definition: swtable.hxx:115
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:259
double GetValue(SwTableCalcPara &rPara) const
Get value of this box.
Definition: cellfml.cxx:80
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
OUString GetName() const
Definition: swtable.cxx:1829
TableChgMode GetTableChgDefaultMode()
Definition: edtwin3.cxx:104
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1922
T * get() const
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
void SetSize(SwTableBox &rBox, const SwFormatFrameSize &rSz)
Definition: tblrwcl.cxx:3316
Style of a layout element.
Definition: frmfmt.hxx:57
size_t Count() const
Definition: ndhints.hxx:142
SwTabFrame * FindMaster(bool bFirstMaster=false) const
Definition: flowfrm.cxx:717
#define SAL_MAX_INT32
std::unique_ptr< sw::ModifyChangedHint > CheckRegistration(const SfxPoolItem *pOldValue)
Definition: calbck.cxx:78
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
const Color * GetSaveNumFormatColor() const
Definition: swtable.cxx:80
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void SetRemoveFollowFlowLinePending(bool bNew)
Definition: tabfrm.hxx:170
SvxAdjust
int i
virtual bool supportsFullDrawingLayerFillAttributeSet() const override
Definition: swtable.cxx:2381
bool empty() const
Definition: swtable.hxx:73
void CheckBoxWidth(const SwTableLine &rLine, SwTwips nSize)
Definition: tblrwcl.cxx:2569
sal_uInt16 CalcShadowSpace(SvxShadowItemSide nShadow) const
void LockModify()
Definition: swtable.hxx:181
bool IsTextFormat(sal_uInt32 nFIndex) const
TElementType * First()
Definition: calbck.hxx:343
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
SwContentNode * GetContentNode()
Definition: node.hxx:615
SwLayoutFrame * GetUpper()
Definition: frame.hxx:658
bool getDummyFlag() const
Definition: swtable.cxx:111
Marks a character position inside a document model node.
Definition: index.hxx:37
void UnlockModify()
Definition: calbck.hxx:214
std::deque< SwTableBox * > aBoxArr
Definition: swtable.cxx:617
long const nBorder
std::pair< sal_uInt16, sal_uInt16 > ColChange
Definition: swtable.cxx:989
void LockModify()
Definition: calbck.hxx:213
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:366
size
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:396
SwTableLines m_aLines
Definition: swtable.hxx:395
Marks a node in the document model.
Definition: ndindex.hxx:31
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:425
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
std::shared_ptr< SwHTMLTableLayout > m_xHTMLLayout
Definition: swtable.hxx:118
bool empty() const
void SetAdjust(const SvxAdjust eType)
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
static sal_uInt16 GetBoxNum(OUString &rStr, bool bFirst=false, const bool bPerformValidCheck=false)
Definition: swtable.cxx:1284
void Remove(size_t nPos, size_t nCount=1)
Definition: tabcol.cxx:86
SwStartNode * GetStartNode()
Definition: node.hxx:591
sal_uInt16 GetBoxPos(const SwTableBox *pBox) const
Definition: swtable.hxx:356
const SwTableBox * getTableBox() const
Definition: swtable.cxx:2735
void DelBoxNode(SwTableSortBoxes const &rSortCntBoxes)
Definition: swtable.cxx:228
SwTableLines & GetTabLines()
Definition: swtable.hxx:198
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
SwTableLines & GetTabLines()
Definition: swtable.hxx:418
void reserve(size_type nSize)
Definition: swtable.hxx:91
virtual bool IsIgnoreRedline() const =0
Parm(const SwTabCols &rN, const SwTabCols &rO)
Definition: swtable.cxx:620
static void lcl_AdjustLines(SwTableLines &rLines, const long nDiff, Parm &rParm)
Definition: swtable.cxx:810
TableBoxes_t m_HandledTableBoxes
Definition: swtable.cxx:2601
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
#define CHECK_TABLE(t)
Definition: swtable.cxx:62
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
static OUString & lcl_TabToBlankAtSttEnd(OUString &rText)
Definition: swtable.cxx:122
void EraseText(const SwIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
Definition: ndtxt.cxx:2660
Point GetCoordinates() const
Definition: swtable.cxx:1805
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2277
long nNewWish
Definition: swtable.cxx:615
static void lcl_ProcessLineGet(const SwTableLine *pLine, SwTabCols &rToFill, const SwFrameFormat *pTabFormat)
Definition: swtable.cxx:513
bool IsModifyLocked() const
Definition: calbck.hxx:218
virtual bool supportsFullDrawingLayerFillAttributeSet() const override
Definition: swtable.cxx:2391
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:238
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
static SwTableBoxFormat * CheckBoxFormat(SwTableBoxFormat *)
Definition: swtable.cxx:1682
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:354
static void lcl_SortedTabColInsert(SwTabCols &rToFill, const SwTableBox *pBox, const SwFrameFormat *pTabFormat, const bool bHidden, const bool bRefreshHidden)
Definition: swtable.cxx:387
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: format.cxx:650
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:103
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(149)
sal_Int32 mnRowSpan
SwRowFrame * GetFirstNonHeadlineRow() const
Definition: tabfrm.cxx:5436
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:439
static void lcl_ProcessLine(SwTableLine *pLine, Parm &rParm)
Definition: swtable.cxx:627
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
void ChgFrameFormat(SwTableBoxFormat *pNewFormat, bool bNeedToReregister=true)
Definition: swtable.cxx:1742
bool IsTabFrame() const
Definition: frame.hxx:1196
void AdjustWidths(const long nOld, const long nNew)
Definition: swtable.cxx:368
long getRowSpan() const
Definition: swtable.cxx:101
void SetHidden(size_t nPos, bool bValue)
Definition: tabcol.hxx:67
void Width(long nNew)
Definition: swrect.hxx:187
const SwFrame * getNextFrameInTable(const SwFrame *pFrame)
Definition: swtable.cxx:2626
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:253
SwRect getRect() const
Definition: swtable.cxx:2725
sal_Int32 GetIndex() const
Definition: index.hxx:95
void InsTableBox(SwDoc *pDoc, SwTableNode *pTableNd, SwTableLine *pLine, SwTableBoxFormat *pBoxFrameFormat, SwTableBox *pBox, sal_uInt16 nInsPos, sal_uInt16 nCnt)
Definition: swtable.cxx:156
SwNodes & GetNodes()
Definition: doc.hxx:403
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNewValue) override
Definition: swtable.cxx:2170
void SetSaveNumFormatColor(const Color *p)
Definition: swtable.cxx:93
static void lcl_ProcessBoxGet(const SwTableBox *pBox, SwTabCols &rToFill, const SwFrameFormat *pTabFormat, bool bRefreshHidden)
Definition: swtable.cxx:496
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
SwFrame * GetLower()
Definition: findfrm.cxx:169
void * p
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(171)
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1706
bool IsAnFollow(const SwFlowFrame *pFlow) const
Definition: flowfrm.cxx:670
static void lcl_ModifyBoxes(SwTableBoxes &rBoxes, const long nOld, const long nNew, std::vector< SwFormat * > &rFormatArr)
Definition: swtable.cxx:301
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:352
SwTableBox * GetUpper()
Definition: swtable.hxx:362
bool IsNumberFormat(const OUString &rString, sal_uInt32 &F_Index, double &fOutNumber)
Definition: ndtbl.cxx:4006
virtual sfx2::LinkManager & GetLinkManager()=0
sal_uInt32 GetValue() const
const SwCellFrame * m_pCellFrame
Definition: swtable.cxx:2598
bool IsVertical() const
Definition: frame.hxx:951
bool IsInDtor() const
Definition: doc.hxx:398
#define COLFUZZY
Definition: swtable.cxx:70
void InvalidatePrt_()
Definition: frame.hxx:759
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: swtable.cxx:342
bool IsTableNode() const
Definition: node.hxx:640
sal_uInt16 GetPos(const SwTableLine *pBox) const
Definition: swtable.hxx:96
static bool lcl_IsValidRowName(const OUString &rStr)
Definition: swtable.cxx:1269
const SwCellFrame * getNextTableBoxsCellFrame(const SwFrame *pFrame)
Definition: swtable.cxx:2673
void setTable(const SwTable *pTable)
Definition: swtable.cxx:2609
iterator end()
Definition: swtable.hxx:77
Frame is variable in Var-direction.
virtual const SwRedlineTable & GetRedlineTable() const =0
bool HasNumContent(double &rNum, sal_uInt32 &rFormatIndex, bool &rIsEmptyTextNd) const
Definition: swtable.cxx:2396
std::pair< const_iterator, bool > insert(Value &&x)
static void ChgTextToNum(SwTableBox &rBox, const OUString &rText, const Color *pCol, bool bChgAlign, sal_uLong nNdPos)
Definition: swtable.cxx:1955
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: ndtxt.cxx:5114
bool IsNewModel() const
Definition: swtable.hxx:185
static void lcl_AdjustWidthsInLine(SwTableLine *pLine, ChangeList &rOldNew, Parm &rParm, sal_uInt16 nColFuzzy)
Definition: swtable.cxx:992
SwTableLine * GetUpper()
Definition: swtable.hxx:421
const SwCellFrame * getNextCellFrame(const SwFrame *pFrame)
Definition: swtable.cxx:2657
static void lcl_ModifyLines(SwTableLines &rLines, const long nOld, const long nNew, std::vector< SwFormat * > &rFormatArr, const bool bCheckSum)
Definition: swtable.cxx:283
static void lcl_ProcessBoxPtr(SwTableBox *pBox, std::deque< SwTableBox * > &rBoxArr, bool bBefore)
Definition: swtable.cxx:789
bool IsTextNode() const
Definition: node.hxx:636
bool IsNumberChanged() const
Definition: swtable.cxx:2432
bool m_bModifyLocked
Definition: swtable.hxx:136
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1281
virtual ~SwTableLine() override
Definition: swtable.cxx:1469
constexpr sal_uInt32 getSwDefaultTextFormat()
The number formatter's default locale's @ Text format.
Definition: cellatr.hxx:34
sal_uInt16 Which() const
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
static void FormatInArr(std::vector< SwFormat * > &rFormatArr, SwFormat *pBoxFormat)
Definition: swtable.cxx:273
const SwTable * m_pTable
Definition: swtable.cxx:2597
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:30
SwTableBoxFormat * MakeTableBoxFormat()
Definition: docfmt.cxx:1705
sal_uInt16 nPos
long GetLeft() const
Definition: tabcol.hxx:77
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
size_type erase(const Value &x)
size_t Count() const
Definition: tabcol.hxx:64
SwRowFrame is one table row in the document layout.
Definition: rowfrm.hxx:28
bool IsInHeadline(const SwFrame &rFrame) const
Definition: tabfrm.cxx:5417
std::unique_ptr< Impl > m_pImpl
Definition: swtable.hxx:500
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1077
SwTableNode * GetTableNode() const
Definition: swtable.cxx:1929
SwFrame * GetNext()
Definition: frame.hxx:656
Base class of the Writer document model elements.
Definition: node.hxx:79
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo