LibreOffice Module sw (master)  1
htmltbl.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 <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <algorithm>
24 #include <memory>
25 
26 #include <fmtornt.hxx>
27 #include <fmtfsize.hxx>
28 #include <frmfmt.hxx>
29 #include <ndtxt.hxx>
30 #include <doc.hxx>
32 #include <swtable.hxx>
33 #include <rootfrm.hxx>
34 #include <flyfrm.hxx>
35 #include <poolfmt.hxx>
36 #include <viewsh.hxx>
37 #include <tabfrm.hxx>
38 #include <viewopt.hxx>
39 #include <htmltbl.hxx>
40 #include <calbck.hxx>
41 #include <o3tl/numeric.hxx>
42 #include <osl/diagnose.h>
43 #ifdef DBG_UTIL
44 #include <tblrwcl.hxx>
45 #endif
46 
47 using namespace ::com::sun::star;
48 
49 #define COLFUZZY 20
50 #define MAX_TABWIDTH (USHRT_MAX - 2001)
51 
52 namespace {
53 
54 class SwHTMLTableLayoutConstraints
55 {
56  sal_uInt16 m_nRow; // start row
57  sal_uInt16 m_nCol; // start column
58  sal_uInt16 m_nColSpan; // the column's COLSPAN
59 
60  std::unique_ptr<SwHTMLTableLayoutConstraints> m_pNext; // the next constraint
61 
62  sal_uLong m_nMinNoAlign, m_nMaxNoAlign; // provisional result of AL-Pass 1
63 
64 public:
65  SwHTMLTableLayoutConstraints( sal_uLong nMin, sal_uLong nMax, sal_uInt16 nRow,
66  sal_uInt16 nCol, sal_uInt16 nColSp );
67 
68  sal_uLong GetMinNoAlign() const { return m_nMinNoAlign; }
69  sal_uLong GetMaxNoAlign() const { return m_nMaxNoAlign; }
70 
71  SwHTMLTableLayoutConstraints *InsertNext( SwHTMLTableLayoutConstraints *pNxt );
72  SwHTMLTableLayoutConstraints* GetNext() const { return m_pNext.get(); }
73 
74  sal_uInt16 GetColSpan() const { return m_nColSpan; }
75  sal_uInt16 GetColumn() const { return m_nCol; }
76 };
77 
78 }
79 
81  std::shared_ptr<SwHTMLTableLayout> const& rTab,
82  bool bNoBrTag,
83  std::shared_ptr<SwHTMLTableLayoutCnts> const& rNxt ) :
84  m_xNext( rNxt ), m_pBox( nullptr ), m_xTable( rTab ), m_pStartNode( pSttNd ),
85  m_nPass1Done( 0 ), m_nWidthSet( 0 ), m_bNoBreakTag( bNoBrTag )
86 {}
87 
89 {
90  return m_pBox ? m_pBox->GetSttNd() : m_pStartNode;
91 }
92 
93 SwHTMLTableLayoutCell::SwHTMLTableLayoutCell(std::shared_ptr<SwHTMLTableLayoutCnts> const& rCnts,
94  sal_uInt16 nRSpan, sal_uInt16 nCSpan,
95  sal_uInt16 nWidth, bool bPercentWidth,
96  bool bNWrapOpt ) :
97  m_xContents(rCnts),
98  m_nRowSpan( nRSpan ), m_nColSpan( nCSpan ),
99  m_nWidthOption( nWidth ), m_bPercentWidthOption( bPercentWidth ),
100  m_bNoWrapOption( bNWrapOpt )
101 {}
102 
104  bool bRelWidth,
105  bool bLBorder ) :
106  m_nMinNoAlign(MINLAY), m_nMaxNoAlign(MINLAY), m_nAbsMinNoAlign(MINLAY),
107  m_nMin(0), m_nMax(0),
108  m_nAbsColWidth(0), m_nRelColWidth(0),
109  m_nWidthOption( nWidth ), m_bRelWidthOption( bRelWidth ),
110  m_bLeftBorder( bLBorder )
111 {}
112 
113 SwHTMLTableLayoutConstraints::SwHTMLTableLayoutConstraints(sal_uLong nMin, sal_uLong nMax,
114  sal_uInt16 nRw, sal_uInt16 nColumn,
115  sal_uInt16 nColSp)
116  : m_nRow(nRw)
117  , m_nCol(nColumn)
118  , m_nColSpan(nColSp)
119  , m_nMinNoAlign(nMin)
120  , m_nMaxNoAlign(nMax)
121 {}
122 
123 SwHTMLTableLayoutConstraints *SwHTMLTableLayoutConstraints::InsertNext(
124  SwHTMLTableLayoutConstraints *pNxt )
125 {
126  SwHTMLTableLayoutConstraints *pPrev = nullptr;
127  SwHTMLTableLayoutConstraints *pConstr = this;
128  while( pConstr )
129  {
130  if (pConstr->m_nRow > pNxt->m_nRow || pConstr->GetColumn() > pNxt->GetColumn())
131  break;
132  pPrev = pConstr;
133  pConstr = pConstr->GetNext();
134  }
135 
136  if( pPrev )
137  {
138  pNxt->m_pNext = std::move(pPrev->m_pNext);
139  pPrev->m_pNext.reset(pNxt);
140  pConstr = this;
141  }
142  else
143  {
144  pNxt->m_pNext.reset(this);
145  pConstr = pNxt;
146  }
147 
148  return pConstr;
149 }
150 
152  sal_uInt16 nRws, sal_uInt16 nCls,
153  bool bColsOpt, bool bColTgs,
154  sal_uInt16 nWdth, bool bPercentWdth,
155  sal_uInt16 nBorderOpt, sal_uInt16 nCellPad,
156  sal_uInt16 nCellSp, SvxAdjust eAdjust,
157  sal_uInt16 nLMargin, sal_uInt16 nRMargin,
158  sal_uInt16 nBWidth, sal_uInt16 nLeftBWidth,
159  sal_uInt16 nRightBWidth )
160  : m_aColumns( nCls )
161  , m_aCells( static_cast<size_t>(nRws)*nCls )
162  , m_pSwTable( pTable )
163  , m_nMin( 0 )
164  , m_nMax( 0 )
165  , m_nRows( nRws )
166  , m_nCols( nCls )
167  , m_nLeftMargin( nLMargin )
168  , m_nRightMargin( nRMargin )
169  , m_nInhAbsLeftSpace( 0 )
170  , m_nInhAbsRightSpace( 0 )
171  , m_nRelLeftFill( 0 )
172  , m_nRelRightFill( 0 )
173  , m_nRelTabWidth( 0 )
174  , m_nWidthOption( nWdth )
175  , m_nCellPadding( nCellPad )
176  , m_nCellSpacing( nCellSp )
177  , m_nBorder( nBorderOpt )
178  , m_nLeftBorderWidth( nLeftBWidth )
179  , m_nRightBorderWidth( nRightBWidth )
180  , m_nInhLeftBorderWidth( 0 )
181  , m_nInhRightBorderWidth( 0 )
182  , m_nBorderWidth( nBWidth )
183  , m_nDelayedResizeAbsAvail( 0 )
184  , m_nLastResizeAbsAvail( 0 )
185  , m_nPass1Done( 0 )
186  , m_nWidthSet( 0 )
187  , m_eTableAdjust( eAdjust )
188  , m_bColsOption( bColsOpt )
189  , m_bColTags( bColTgs )
190  , m_bPercentWidthOption( bPercentWdth )
191  , m_bUseRelWidth( false )
192  , m_bMustResize( true )
193  , m_bExportable( true )
194  , m_bBordersChanged( false )
195  , m_bMayBeInFlyFrame( false )
196  , m_bDelayedResizeRecalc( false)
197  , m_bMustNotResize( false )
198  , m_bMustNotRecalc( false )
199 {
201  DelayedResize_Impl ) );
202 }
203 
205 {
206 }
207 
215 sal_uInt16 SwHTMLTableLayout::GetLeftCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
216  bool bSwBorders ) const
217 {
218  sal_uInt16 nSpace = m_nCellSpacing + m_nCellPadding;
219 
220  if( nCol == 0 )
221  {
222  nSpace = nSpace + m_nBorder;
223 
224  if( bSwBorders && nSpace < m_nLeftBorderWidth )
225  nSpace = m_nLeftBorderWidth;
226  }
227  else if( bSwBorders )
228  {
229  if( GetColumn(nCol)->HasLeftBorder() )
230  {
231  if( nSpace < m_nBorderWidth )
232  nSpace = m_nBorderWidth;
233  }
234  else if( nCol+nColSpan == m_nCols && m_nRightBorderWidth &&
235  nSpace < MIN_BORDER_DIST )
236  {
237  OSL_ENSURE( !m_nCellPadding, "GetLeftCellSpace: CELLPADDING!=0" );
238  // If the opposite side has a border we need to respect at
239  // least the minimum distance to the content.
240  // Additionally, we could also use nCellPadding for this.
241  nSpace = MIN_BORDER_DIST;
242  }
243  }
244 
245  return nSpace;
246 }
247 
248 sal_uInt16 SwHTMLTableLayout::GetRightCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
249  bool bSwBorders ) const
250 {
251  sal_uInt16 nSpace = m_nCellPadding;
252 
253  if( nCol+nColSpan == m_nCols )
254  {
255  nSpace += m_nBorder + m_nCellSpacing;
256  if( bSwBorders && nSpace < m_nRightBorderWidth )
257  nSpace = m_nRightBorderWidth;
258  }
259  else if( bSwBorders && GetColumn(nCol)->HasLeftBorder() &&
260  nSpace < MIN_BORDER_DIST )
261  {
262  OSL_ENSURE( !m_nCellPadding, "GetRightCellSpace: CELLPADDING!=0" );
263  // If the opposite side has a border we need to respect at
264  // least the minimum distance to the content.
265  // Additionally, we could also use nCellPadding for this.
266  nSpace = MIN_BORDER_DIST;
267  }
268 
269  return nSpace;
270 }
271 
273  sal_uLong &rAbsMin,
274  sal_uInt16 nCol, sal_uInt16 nColSpan,
275  bool bSwBorders ) const
276 {
277  sal_uLong nAdd = GetLeftCellSpace( nCol, nColSpan, bSwBorders ) +
278  GetRightCellSpace( nCol, nColSpan, bSwBorders );
279 
280  rMin += nAdd;
281  rMax += nAdd;
282  rAbsMin += nAdd;
283 }
284 
285 void SwHTMLTableLayout::SetBoxWidth( SwTableBox *pBox, sal_uInt16 nCol,
286  sal_uInt16 nColSpan ) const
287 {
288  SwFrameFormat *pFrameFormat = pBox->GetFrameFormat();
289 
290  // calculate the box's width
291  SwTwips nFrameWidth = 0;
292  while( nColSpan-- )
293  nFrameWidth += GetColumn( nCol++ )->GetRelColWidth();
294 
295  // and reset
296  pFrameFormat->SetFormatAttr( SwFormatFrameSize( SwFrameSize::Variable, nFrameWidth, 0 ));
297 }
298 
299 void SwHTMLTableLayout::GetAvail( sal_uInt16 nCol, sal_uInt16 nColSpan,
300  sal_uInt16& rAbsAvail, sal_uInt16& rRelAvail ) const
301 {
302  rAbsAvail = 0;
303  rRelAvail = 0;
304  for( sal_uInt16 i=nCol; i<nCol+nColSpan;i++ )
305  {
306  const SwHTMLTableLayoutColumn *pColumn = GetColumn(i);
307  rAbsAvail = rAbsAvail + pColumn->GetAbsColWidth();
308  rRelAvail = rRelAvail + pColumn->GetRelColWidth();
309  }
310 }
311 
313 {
315  if( pVSh )
316  {
317  return static_cast<sal_uInt16>(pVSh->GetBrowseWidth());
318  }
319 
320  return 0;
321 }
322 
323 sal_uInt16 SwHTMLTableLayout::GetBrowseWidth( const SwDoc& rDoc )
324 {
325  // If we have a layout, we can get the width from there.
326  const SwRootFrame *pRootFrame = rDoc.getIDocumentLayoutAccess().GetCurrentLayout();
327  if( pRootFrame )
328  {
329  const SwFrame *pPageFrame = pRootFrame->GetLower();
330  if( pPageFrame )
331  return static_cast<sal_uInt16>(pPageFrame->getFramePrintArea().Width());
332  }
333 
334  // #i91658#
335  // Assertion removed which state that no browse width is available.
336  // Investigation reveals that all calls can handle the case that no browse
337  // width is provided.
338  return GetBrowseWidthByVisArea( rDoc );
339 }
340 
342  const SwTabFrame& rTabFrame ) const
343 {
344  SwTwips nWidth = 0;
345 
346  const SwFrame *pUpper = rTabFrame.GetUpper();
347  if( MayBeInFlyFrame() && pUpper->IsFlyFrame() &&
348  static_cast<const SwFlyFrame *>(pUpper)->GetAnchorFrame() )
349  {
350  // If the table is located within a self-created frame, the anchor's
351  // width is relevant not the frame's width.
352  // For paragraph-bound frames we don't respect paragraph indents.
353  const SwFrame *pAnchor = static_cast<const SwFlyFrame *>(pUpper)->GetAnchorFrame();
354  if( pAnchor->IsTextFrame() )
355  nWidth = pAnchor->getFrameArea().Width();
356  else
357  nWidth = pAnchor->getFramePrintArea().Width();
358  }
359  else
360  {
361  nWidth = pUpper->getFramePrintArea().Width();
362  }
363 
364  SwTwips nUpperDummy = 0;
365  tools::Long nRightOffset = 0,
366  nLeftOffset = 0;
367  rTabFrame.CalcFlyOffsets( nUpperDummy, nLeftOffset, nRightOffset );
368  nWidth -= (nLeftOffset + nRightOffset);
369 
370  return static_cast<sal_uInt16>(std::min(nWidth, SwTwips(SAL_MAX_UINT16)));
371 }
372 
373 sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByTable( const SwDoc& rDoc ) const
374 {
375  sal_uInt16 nBrowseWidth = 0;
377  if( pFrame )
378  {
379  nBrowseWidth = GetBrowseWidthByTabFrame( *pFrame );
380  }
381  else
382  {
383  nBrowseWidth = SwHTMLTableLayout::GetBrowseWidth( rDoc );
384  }
385 
386  return nBrowseWidth;
387 }
388 
390 {
391  const SwStartNode *pBoxSttNd;
392 
393  const SwTableBox* pBox = m_pSwTable->GetTabLines()[0]->GetTabBoxes()[0];
394  while( nullptr == (pBoxSttNd = pBox->GetSttNd()) )
395  {
396  OSL_ENSURE( !pBox->GetTabLines().empty(),
397  "Box without start node and lines" );
398  OSL_ENSURE( !pBox->GetTabLines().front()->GetTabBoxes().empty(),
399  "Line without boxes" );
400  pBox = pBox->GetTabLines().front()->GetTabBoxes().front();
401  }
402 
403  return pBoxSttNd;
404 }
405 
407 {
408  const SwTableNode *pTableNd = GetAnyBoxStartNode()->FindTableNode();
409  OSL_ENSURE( pTableNd, "No Table-Node?" );
410  return pTableNd->GetFlyFormat();
411 }
412 
413 static void lcl_GetMinMaxSize( sal_uLong& rMinNoAlignCnts, sal_uLong& rMaxNoAlignCnts,
414  sal_uLong& rAbsMinNoAlignCnts,
415  SwTextNode const *pTextNd, sal_uLong nIdx, bool bNoBreak )
416 {
417  pTextNd->GetMinMaxSize( nIdx, rMinNoAlignCnts, rMaxNoAlignCnts,
418  rAbsMinNoAlignCnts );
419  OSL_ENSURE( rAbsMinNoAlignCnts <= rMinNoAlignCnts,
420  "GetMinMaxSize: absmin > min" );
421  OSL_ENSURE( rMinNoAlignCnts <= rMaxNoAlignCnts,
422  "GetMinMaxSize: max > min" );
423 
424  // The maximal width for a <PRE> paragraph is the minimal width
425  const SwFormatColl *pColl = &pTextNd->GetAnyFormatColl();
426  while( pColl && !pColl->IsDefault() &&
427  (USER_FMT & pColl->GetPoolFormatId()) )
428  {
429  pColl = static_cast<const SwFormatColl *>(pColl->DerivedFrom());
430  }
431 
432  // <NOBR> in the whole cell apply to text but not to tables.
433  // Netscape only considers this for graphics.
434  if( (pColl && RES_POOLCOLL_HTML_PRE==pColl->GetPoolFormatId()) || bNoBreak )
435  {
436  rMinNoAlignCnts = rMaxNoAlignCnts;
437  rAbsMinNoAlignCnts = rMaxNoAlignCnts;
438  }
439 }
440 
442 {
443  m_nPass1Done++;
444 
445  m_nMin = m_nMax = 0; // clear pass1 info
446 
447  bool bFixRelWidths = false;
448  sal_uInt16 i;
449 
450  std::unique_ptr<SwHTMLTableLayoutConstraints> xConstraints;
451 
452  for( i=0; i<m_nCols; i++ )
453  {
454  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
455  pColumn->ClearPass1Info( !HasColTags() );
456  sal_uInt16 nMinColSpan = USHRT_MAX; // Column count to which the calculated width refers to
457  sal_uInt16 nColSkip = USHRT_MAX; // How many columns need to be skipped
458 
459  for( sal_uInt16 j=0; j<m_nRows; j++ )
460  {
461  SwHTMLTableLayoutCell *pCell = GetCell(j,i);
462  SwHTMLTableLayoutCnts *pCnts = pCell->GetContents().get();
463 
464  // We need to examine all rows in order to
465  // get the column that should be calculated next.
466  sal_uInt16 nColSpan = pCell->GetColSpan();
467  if( nColSpan < nColSkip )
468  nColSkip = nColSpan;
469 
470  if( !pCnts || !pCnts->IsPass1Done(m_nPass1Done) )
471  {
472  // The cell is empty or it's content was not edited
473  if( nColSpan < nMinColSpan )
474  nMinColSpan = nColSpan;
475 
476  sal_uLong nMinNoAlignCell = 0;
477  sal_uLong nMaxNoAlignCell = 0;
478  sal_uLong nAbsMinNoAlignCell = 0;
479  sal_uLong nMaxTableCell = 0;
480  sal_uLong nAbsMinTableCell = 0;
481 
482  while( pCnts )
483  {
484  const SwStartNode *pSttNd = pCnts->GetStartNode();
485  if( pSttNd )
486  {
487  const SwDoc& rDoc = pSttNd->GetDoc();
488  sal_uLong nIdx = pSttNd->GetIndex();
489  while (!rDoc.GetNodes()[nIdx]->IsEndNode())
490  {
491  SwTextNode *pTextNd = (rDoc.GetNodes()[nIdx])->GetTextNode();
492  if( pTextNd )
493  {
494  sal_uLong nMinNoAlignCnts = 0;
495  sal_uLong nMaxNoAlignCnts = 0;
496  sal_uLong nAbsMinNoAlignCnts = 0;
497 
498  lcl_GetMinMaxSize( nMinNoAlignCnts,
499  nMaxNoAlignCnts,
500  nAbsMinNoAlignCnts,
501  pTextNd, nIdx,
502  pCnts->HasNoBreakTag() );
503 
504  if( nMinNoAlignCnts > nMinNoAlignCell )
505  nMinNoAlignCell = nMinNoAlignCnts;
506  if( nMaxNoAlignCnts > nMaxNoAlignCell )
507  nMaxNoAlignCell = nMaxNoAlignCnts;
508  if( nAbsMinNoAlignCnts > nAbsMinNoAlignCell )
509  nAbsMinNoAlignCell = nAbsMinNoAlignCnts;
510  }
511  else
512  {
513  SwTableNode *pTabNd = (rDoc.GetNodes()[nIdx])->GetTableNode();
514  if( pTabNd )
515  {
516  SwHTMLTableLayout *pChild = pTabNd->GetTable().GetHTMLTableLayout();
517  if( pChild )
518  {
519  pChild->AutoLayoutPass1();
520  sal_uLong nMaxTableCnts = pChild->m_nMax;
521  sal_uLong nAbsMinTableCnts = pChild->m_nMin;
522 
523  // A fixed table width is taken over as minimum and
524  // maximum at the same time
525  if( !pChild->m_bPercentWidthOption && pChild->m_nWidthOption )
526  {
527  sal_uLong nTabWidth = pChild->m_nWidthOption;
528  if( nTabWidth >= nAbsMinTableCnts )
529  {
530  nMaxTableCnts = nTabWidth;
531  nAbsMinTableCnts = nTabWidth;
532  }
533  else
534  {
535  nMaxTableCnts = nAbsMinTableCnts;
536  }
537  }
538 
539  if( nMaxTableCnts > nMaxTableCell )
540  nMaxTableCell = nMaxTableCnts;
541  if( nAbsMinTableCnts > nAbsMinTableCell )
542  nAbsMinTableCell = nAbsMinTableCnts;
543  }
544  nIdx = pTabNd->EndOfSectionNode()->GetIndex();
545  }
546  }
547  nIdx++;
548  }
549  }
550  else if (SwHTMLTableLayout *pChild = pCnts->GetTable())
551  {
552  OSL_ENSURE( false, "Sub tables in HTML import?" );
553  pChild->AutoLayoutPass1();
554  sal_uLong nMaxTableCnts = pChild->m_nMax;
555  sal_uLong nAbsMinTableCnts = pChild->m_nMin;
556 
557  // A fixed table width is taken over as minimum and
558  // maximum at the same time
559  if( !pChild->m_bPercentWidthOption && pChild->m_nWidthOption )
560  {
561  sal_uLong nTabWidth = pChild->m_nWidthOption;
562  if( nTabWidth >= nAbsMinTableCnts )
563  {
564  nMaxTableCnts = nTabWidth;
565  nAbsMinTableCnts = nTabWidth;
566  }
567  else
568  {
569  nMaxTableCnts = nAbsMinTableCnts;
570  }
571  }
572 
573  if( nMaxTableCnts > nMaxTableCell )
574  nMaxTableCell = nMaxTableCnts;
575  if( nAbsMinTableCnts > nAbsMinTableCell )
576  nAbsMinTableCell = nAbsMinTableCnts;
577  }
578  pCnts->SetPass1Done( m_nPass1Done );
579  pCnts = pCnts->GetNext().get();
580  }
581 
582 // This code previously came after AddBorderWidth
583  // If a table's width is wider in a cell than what we've calculated
584  // for the other content we need to use the table's width.
585  if( nMaxTableCell > nMaxNoAlignCell )
586  nMaxNoAlignCell = nMaxTableCell;
587  if( nAbsMinTableCell > nAbsMinNoAlignCell )
588  {
589  nAbsMinNoAlignCell = nAbsMinTableCell;
590  if( nMinNoAlignCell < nAbsMinNoAlignCell )
591  nMinNoAlignCell = nAbsMinNoAlignCell;
592  if( nMaxNoAlignCell < nMinNoAlignCell )
593  nMaxNoAlignCell = nMinNoAlignCell;
594  }
595 // This code previously came after AddBorderWidth
596 
597  bool bRelWidth = pCell->IsPercentWidthOption();
598  sal_uInt16 nWidth = pCell->GetWidthOption();
599 
600  // A NOWRAP option applies to text and tables, but is
601  // not applied for fixed cell width.
602  // Instead, the stated cell width behaves like a minimal
603  // width.
604  if( pCell->HasNoWrapOption() )
605  {
606  if( nWidth==0 || bRelWidth )
607  {
608  nMinNoAlignCell = nMaxNoAlignCell;
609  nAbsMinNoAlignCell = nMaxNoAlignCell;
610  }
611  else
612  {
613  if( nWidth>nMinNoAlignCell )
614  nMinNoAlignCell = nWidth;
615  if( nWidth>nAbsMinNoAlignCell )
616  nAbsMinNoAlignCell = nWidth;
617  }
618  }
619 
620  // Respect minimum width for content
621  if( nMinNoAlignCell < MINLAY )
622  nMinNoAlignCell = MINLAY;
623  if( nMaxNoAlignCell < MINLAY )
624  nMaxNoAlignCell = MINLAY;
625  if( nAbsMinNoAlignCell < MINLAY )
626  nAbsMinNoAlignCell = MINLAY;
627 
628  // Respect the border and distance to the content
629  AddBorderWidth( nMinNoAlignCell, nMaxNoAlignCell,
630  nAbsMinNoAlignCell, i, nColSpan );
631 
632  if( 1==nColSpan )
633  {
634  // take over the values directly
635  pColumn->MergeMinMaxNoAlign( nMinNoAlignCell,
636  nMaxNoAlignCell,
637  nAbsMinNoAlignCell );
638 
639  // the widest WIDTH wins
640  if( !HasColTags() )
641  pColumn->MergeCellWidthOption( nWidth, bRelWidth );
642  }
643  else
644  {
645  // Process the data line by line from left to right at the end
646 
647  // When which values is taken over will be explained further down.
648  if( !HasColTags() && nWidth && !bRelWidth )
649  {
650  sal_uLong nAbsWidth = nWidth, nDummy = 0, nDummy2 = 0;
651  AddBorderWidth( nAbsWidth, nDummy, nDummy2,
652  i, nColSpan, false );
653 
654  if( nAbsWidth >= nMinNoAlignCell )
655  {
656  nMaxNoAlignCell = nAbsWidth;
657  if( HasColsOption() )
658  nMinNoAlignCell = nAbsWidth;
659  }
660  else if( nAbsWidth >= nAbsMinNoAlignCell )
661  {
662  nMaxNoAlignCell = nAbsWidth;
663  nMinNoAlignCell = nAbsWidth;
664  }
665  else
666  {
667  nMaxNoAlignCell = nAbsMinNoAlignCell;
668  nMinNoAlignCell = nAbsMinNoAlignCell;
669  }
670  }
671  else if( HasColsOption() || HasColTags() )
672  nMinNoAlignCell = nAbsMinNoAlignCell;
673 
674  SwHTMLTableLayoutConstraints *pConstr =
675  new SwHTMLTableLayoutConstraints( nMinNoAlignCell,
676  nMaxNoAlignCell, j, i, nColSpan );
677  if (xConstraints)
678  {
679  SwHTMLTableLayoutConstraints* pConstraints = xConstraints->InsertNext(pConstr);
680  xConstraints.release();
681  xConstraints.reset(pConstraints);
682  }
683  else
684  xConstraints.reset(pConstr);
685  }
686  }
687  }
688 
689  OSL_ENSURE( nMinColSpan>0 && nColSkip>0 && nColSkip <= nMinColSpan,
690  "Layout pass 1: Columns are being forgotten!" );
691  OSL_ENSURE( nMinColSpan!=USHRT_MAX,
692  "Layout pass 1: unnecessary pass through the loop or a bug" );
693 
694  if( 1==nMinColSpan )
695  {
696  // There are cells with COLSPAN 1 and therefore also useful
697  // values in pColumn
698 
699  // Take over values according to the following table (Netscape 4.0 pv 3):
700 
701  // WIDTH: no COLS COLS
702 
703  // none min = min min = absmin
704  // max = max max = max
705 
706  // >= min min = min min = width
707  // max = width max = width
708 
709  // >= absmin min = width(*) min = width
710  // max = width max = width
711 
712  // < absmin min = absmin min = absmin
713  // max = absmin max = absmin
714 
715  // (*) Netscape uses the minimum width without a break before
716  // the last graphic here. We don't have that (yet?),
717  // so we leave it set to width.
718 
719  if( pColumn->GetWidthOption() && !pColumn->IsRelWidthOption() )
720  {
721  // Take over absolute widths as minimal and maximal widths.
722  sal_uLong nAbsWidth = pColumn->GetWidthOption();
723  sal_uLong nDummy = 0, nDummy2 = 0;
724  AddBorderWidth( nAbsWidth, nDummy, nDummy2, i, 1, false );
725 
726  if( nAbsWidth >= pColumn->GetMinNoAlign() )
727  {
728  pColumn->SetMinMax( HasColsOption() ? nAbsWidth
729  : pColumn->GetMinNoAlign(),
730  nAbsWidth );
731  }
732  else if( nAbsWidth >= pColumn->GetAbsMinNoAlign() )
733  {
734  pColumn->SetMinMax( nAbsWidth, nAbsWidth );
735  }
736  else
737  {
738  pColumn->SetMinMax( pColumn->GetAbsMinNoAlign(),
739  pColumn->GetAbsMinNoAlign() );
740  }
741  }
742  else
743  {
744  pColumn->SetMinMax( HasColsOption() ? pColumn->GetAbsMinNoAlign()
745  : pColumn->GetMinNoAlign(),
746  pColumn->GetMaxNoAlign() );
747  }
748  }
749  else if( USHRT_MAX!=nMinColSpan )
750  {
751  // Can be anything != 0, because it is altered by the constraints.
752  pColumn->SetMinMax( MINLAY, MINLAY );
753 
754  // the next columns need not to be processed
755  i += (nColSkip-1);
756  }
757 
758  m_nMin += pColumn->GetMin();
759  m_nMax += pColumn->GetMax();
760  if (pColumn->IsRelWidthOption()) bFixRelWidths = true;
761  }
762 
763  // Now process the constraints
764  SwHTMLTableLayoutConstraints *pConstr = xConstraints.get();
765  while( pConstr )
766  {
767  // At first we need to process the width in the same way
768  // as the column widths
769  sal_uInt16 nCol = pConstr->GetColumn();
770  sal_uInt16 nColSpan = pConstr->GetColSpan();
771  sal_uLong nConstrMin = pConstr->GetMinNoAlign();
772  sal_uLong nConstrMax = pConstr->GetMaxNoAlign();
773 
774  // We get the hitherto width of the spanned columns
775  sal_uLong nColsMin = 0;
776  sal_uLong nColsMax = 0;
777  for( sal_uInt16 j=nCol; j<nCol+nColSpan; j++ )
778  {
779  SwHTMLTableLayoutColumn *pColumn = GetColumn( j );
780  nColsMin += pColumn->GetMin();
781  nColsMax += pColumn->GetMax();
782  }
783 
784  if( nColsMin<nConstrMin )
785  {
786  // Proportionately distribute the minimum value to the columns
787  sal_uLong nMinD = nConstrMin-nColsMin;
788 
789  if( nConstrMin > nColsMax )
790  {
791  // Proportional according to the minimum widths
792  sal_uInt16 nEndCol = nCol+nColSpan;
793  sal_uLong nDiff = nMinD;
794  for( sal_uInt16 ic=nCol; ic<nEndCol; ic++ )
795  {
796  SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
797 
798  sal_uLong nColMin = pColumn->GetMin();
799  sal_uLong nColMax = pColumn->GetMax();
800 
801  m_nMin -= nColMin;
802  sal_uLong nAdd;
803  if (ic < nEndCol-1)
804  {
805  if (nColsMin == 0)
806  throw o3tl::divide_by_zero();
807  nAdd = (nColMin * nMinD) / nColsMin;
808  }
809  else
810  {
811  nAdd = nDiff;
812  }
813  nColMin += nAdd;
814  m_nMin += nColMin;
815  OSL_ENSURE( nDiff >= nAdd, "Ooops: nDiff is not correct anymore" );
816  nDiff -= nAdd;
817 
818  if( nColMax < nColMin )
819  {
820  m_nMax -= nColMax;
821  nColsMax -= nColMax;
822  nColMax = nColMin;
823  m_nMax += nColMax;
824  nColsMax += nColMax;
825  }
826 
827  pColumn->SetMinMax( nColMin, nColMax );
828  }
829  }
830  else
831  {
832  // Proportional according to the difference of max and min
833  for( sal_uInt16 ic=nCol; ic<nCol+nColSpan; ic++ )
834  {
835  SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
836 
837  sal_uLong nDiff = pColumn->GetMax()-pColumn->GetMin();
838  if( nMinD < nDiff )
839  nDiff = nMinD;
840 
841  pColumn->AddToMin( nDiff );
842 
843  OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
844  "Why is the Column suddenly too narrow?" );
845 
846  m_nMin += nDiff;
847  nMinD -= nDiff;
848  }
849  }
850  }
851 
852  if( !HasColTags() && nColsMax<nConstrMax )
853  {
854  sal_uLong nMaxD = nConstrMax-nColsMax;
855 
856  for( sal_uInt16 ic=nCol; ic<nCol+nColSpan; ic++ )
857  {
858  SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
859 
860  m_nMax -= pColumn->GetMax();
861 
862  pColumn->AddToMax( (pColumn->GetMax() * nMaxD) / nColsMax );
863 
864  m_nMax += pColumn->GetMax();
865  }
866  }
867 
868  pConstr = pConstr->GetNext();
869  }
870 
871  if( !bFixRelWidths )
872  return;
873 
874  if( HasColTags() )
875  {
876  // To adapt the relative widths, in a first step we multiply the
877  // minimum width of all affected cells with the relative width
878  // of the column.
879  // Thus, the width ratio among the columns is correct.
880 
881  // Furthermore, a factor is calculated that says by how much the
882  // cell has gotten wider than the minimum width.
883 
884  // In the second step the calculated widths are divided by this
885  // factor. Thereby a cell's width is preserved and serves as a
886  // basis for the other cells.
887  // We only change the maximum widths here!
888 
889  sal_uLong nAbsMin = 0; // absolute minimum width of all widths with relative width
890  sal_uLong nRel = 0; // sum of all relative widths of all columns
891  for( i=0; i<m_nCols; i++ )
892  {
893  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
894  if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
895  {
896  nAbsMin += pColumn->GetMin();
897  nRel += pColumn->GetWidthOption();
898  }
899  }
900 
901  sal_uLong nQuot = ULONG_MAX;
902  for( i=0; i<m_nCols; i++ )
903  {
904  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
905  if( pColumn->IsRelWidthOption() )
906  {
907  m_nMax -= pColumn->GetMax();
908  if( pColumn->GetWidthOption() && pColumn->GetMin() )
909  {
910  pColumn->SetMax( nAbsMin * pColumn->GetWidthOption() );
911  sal_uLong nColQuot = pColumn->GetMax() / pColumn->GetMin();
912  if( nColQuot<nQuot )
913  nQuot = nColQuot;
914  }
915  }
916  }
917  OSL_ENSURE( 0==nRel || nQuot!=ULONG_MAX,
918  "Where did the relative columns go?" );
919  for( i=0; i<m_nCols; i++ )
920  {
921  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
922  if( pColumn->IsRelWidthOption() )
923  {
924  if( pColumn->GetWidthOption() )
925  pColumn->SetMax( pColumn->GetMax() / nQuot );
926  else
927  pColumn->SetMax( pColumn->GetMin() );
928  OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
929  "Maximum column width is lower than the minimum column width" );
930  m_nMax += pColumn->GetMax();
931  }
932  }
933  }
934  else
935  {
936  sal_uInt16 nRel = 0; // sum of the relative widths of all columns
937  sal_uInt16 nRelCols = 0; // count of the columns with a relative setting
938  sal_uLong nRelMax = 0; // fraction of the maximum of this column
939  for( i=0; i<m_nCols; i++ )
940  {
941  OSL_ENSURE( nRel<=100, "relative width of all columns > 100%" );
942  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
943  if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
944  {
945  // Make sure that the relative widths don't go above 100%
946  sal_uInt16 nColWidth = pColumn->GetWidthOption();
947  if( nRel+nColWidth > 100 )
948  {
949  nColWidth = 100 - nRel;
950  pColumn->SetWidthOption( nColWidth );
951  }
952  nRelMax += pColumn->GetMax();
953  nRel = nRel + nColWidth;
954  nRelCols++;
955  }
956  else if( !pColumn->GetMin() )
957  {
958  // The column is empty (so it was solely created by
959  // COLSPAN) and therefore must not be assigned a % width.
960  nRelCols++;
961  }
962  }
963 
964  // If there are percentages left we distribute them to the columns
965  // that don't have a width setting. Like in Netscape we distribute
966  // the remaining percentages according to the ratio of the maximum
967  // width of the affected columns.
968  // For the maximum widths we also take the fixed-width columns
969  // into account. Is that correct?
970  sal_uLong nFixMax = 0;
971  if( nRel < 100 && nRelCols < m_nCols )
972  {
973  nFixMax = m_nMax - nRelMax;
974  SAL_WARN_IF(!nFixMax, "sw.core", "bad fixed width max");
975  }
976  if (nFixMax)
977  {
978  sal_uInt16 nRelLeft = 100 - nRel;
979  for( i=0; i<m_nCols; i++ )
980  {
981  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
982  if( !pColumn->IsRelWidthOption() &&
983  !pColumn->GetWidthOption() &&
984  pColumn->GetMin() )
985  {
986  // the next column gets the rest
987  sal_uInt16 nColWidth =
988  static_cast<sal_uInt16>((pColumn->GetMax() * nRelLeft) / nFixMax);
989  pColumn->SetWidthOption( nColWidth );
990  }
991  }
992  }
993 
994  // adjust the maximum widths now accordingly
995  sal_uLong nQuotMax = ULONG_MAX;
996  sal_uLong nOldMax = m_nMax;
997  m_nMax = 0;
998  for( i=0; i<m_nCols; i++ )
999  {
1000  // Columns with a % setting are adapted accordingly.
1001  // Columns, that
1002  // - do not have a % setting and are located within a tables
1003  // with COLS and WIDTH, or
1004  // - their width is 0%
1005  // get set to the minimum width.
1006  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
1007  if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
1008  {
1009  sal_uLong nNewMax;
1010  sal_uLong nColQuotMax;
1011  if( !m_nWidthOption )
1012  {
1013  nNewMax = nOldMax * pColumn->GetWidthOption();
1014  nColQuotMax = nNewMax / pColumn->GetMax();
1015  }
1016  else
1017  {
1018  nNewMax = m_nMin * pColumn->GetWidthOption();
1019  nColQuotMax = nNewMax / pColumn->GetMin();
1020  }
1021  pColumn->SetMax( nNewMax );
1022  if( nColQuotMax < nQuotMax )
1023  nQuotMax = nColQuotMax;
1024  }
1025  else if( HasColsOption() || m_nWidthOption ||
1026  (pColumn->IsRelWidthOption() &&
1027  !pColumn->GetWidthOption()) )
1028  pColumn->SetMax( pColumn->GetMin() );
1029  }
1030  // and divide by the quotient
1031  SAL_WARN_IF(!nQuotMax, "sw.core", "Where did the relative columns go?");
1032  for (i = 0; i < m_nCols; ++i)
1033  {
1034  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
1035  if (pColumn->IsRelWidthOption() && pColumn->GetWidthOption() && nQuotMax)
1036  {
1037  pColumn->SetMax( pColumn->GetMax() / nQuotMax );
1038  OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
1039  "Minimum width is one column bigger than maximum" );
1040  if( pColumn->GetMax() < pColumn->GetMin() )
1041  pColumn->SetMax( pColumn->GetMin() );
1042  }
1043  m_nMax += pColumn->GetMax();
1044  }
1045  }
1046 }
1047 
1048 //TODO: provide documentation
1056 void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAvail,
1057  sal_uInt16 nAbsLeftSpace,
1058  sal_uInt16 nAbsRightSpace,
1059  sal_uInt16 nParentInhAbsSpace )
1060 {
1061  // For a start we do a lot of plausibility tests
1062 
1063  // An absolute width always has to be passed
1064  OSL_ENSURE( nAbsAvail, "AutoLayout pass 2: No absolute width given" );
1065 
1066  // A relative width must only be passed for tables within tables (?)
1067  OSL_ENSURE( IsTopTable() == (nRelAvail==0),
1068  "AutoLayout pass 2: Relative width at table in table or the other way around" );
1069 
1070  // The table's minimum width must not be bigger than its maximum width
1071  OSL_ENSURE( m_nMin<=m_nMax, "AutoLayout pass 2: nMin > nMax" );
1072 
1073  // Remember the available width for which the table was calculated.
1074  // This is a good place as we pass by here for the initial calculation
1075  // of the table in the parser and for each Resize_ call.
1076  m_nLastResizeAbsAvail = nAbsAvail;
1077 
1078  // Step 1: The available space is readjusted for the left/right border,
1079  // possibly existing filler cells and distances.
1080 
1081  // Distance to the content and border
1082  sal_uInt16 nAbsLeftFill = 0, nAbsRightFill = 0;
1083  if( !IsTopTable() &&
1084  GetMin() + nAbsLeftSpace + nAbsRightSpace <= nAbsAvail )
1085  {
1086  nAbsLeftFill = nAbsLeftSpace;
1087  nAbsRightFill = nAbsRightSpace;
1088  }
1089 
1090  // Left and right distance
1091  if( m_nLeftMargin || m_nRightMargin )
1092  {
1093  if( IsTopTable() )
1094  {
1095  // For the top table we always respect the borders, because we
1096  // never go below the table's minimum width.
1097  nAbsAvail -= (m_nLeftMargin + m_nRightMargin);
1098  }
1099  else if( GetMin() + m_nLeftMargin + m_nRightMargin <= nAbsAvail )
1100  {
1101  // Else, we only respect the borders if there's space available
1102  // for them (nMin has already been calculated!)
1103  nAbsLeftFill = nAbsLeftFill + m_nLeftMargin;
1104  nAbsRightFill = nAbsRightFill + m_nRightMargin;
1105  }
1106  }
1107 
1108  // Read just the available space
1109  m_nRelLeftFill = 0;
1110  m_nRelRightFill = 0;
1111  if( !IsTopTable() && (nAbsLeftFill>0 || nAbsRightFill) )
1112  {
1113  sal_uLong nAbsLeftFillL = nAbsLeftFill, nAbsRightFillL = nAbsRightFill;
1114 
1115  m_nRelLeftFill = static_cast<sal_uInt16>((nAbsLeftFillL * nRelAvail) / nAbsAvail);
1116  m_nRelRightFill = static_cast<sal_uInt16>((nAbsRightFillL * nRelAvail) / nAbsAvail);
1117 
1118  nAbsAvail -= (nAbsLeftFill + nAbsRightFill);
1119  if( nRelAvail )
1120  nRelAvail -= (m_nRelLeftFill + m_nRelRightFill);
1121  }
1122 
1123  // Step 2: Calculate the absolute table width.
1124  sal_uInt16 nAbsTabWidth = 0;
1125  m_bUseRelWidth = false;
1126  if( m_nWidthOption )
1127  {
1128  if( m_bPercentWidthOption )
1129  {
1130  OSL_ENSURE( m_nWidthOption<=100, "Percentage value too high" );
1131  if( m_nWidthOption > 100 )
1132  m_nWidthOption = 100;
1133 
1134  // The absolute width is equal to the given percentage of
1135  // the available width.
1136  // Top tables only get a relative width if the available space
1137  // is *strictly larger* than the minimum width.
1138 
1139  // CAUTION: We need the "strictly larger" because changing from a
1140  // relative width to an absolute width by resizing would lead
1141  // to an infinite loop.
1142 
1143  // Because we do not call resize for tables in frames if the
1144  // frame has a non-relative width, we cannot play such games.
1145 
1146  // Let's play such games now anyway. We had a graphic in a 1% wide
1147  // table and it didn't fit in of course.
1148  nAbsTabWidth = static_cast<sal_uInt16>( (static_cast<sal_uLong>(nAbsAvail) * m_nWidthOption) / 100 );
1149  if( IsTopTable() &&
1150  ( /*MayBeInFlyFrame() ||*/ static_cast<sal_uLong>(nAbsTabWidth) > m_nMin ) )
1151  {
1152  nRelAvail = USHRT_MAX;
1153  m_bUseRelWidth = true;
1154  }
1155  }
1156  else
1157  {
1158  nAbsTabWidth = m_nWidthOption;
1159  if( nAbsTabWidth > MAX_TABWIDTH )
1160  nAbsTabWidth = MAX_TABWIDTH;
1161 
1162  // Tables within tables must never get wider than the available
1163  // space.
1164  if( !IsTopTable() && nAbsTabWidth > nAbsAvail )
1165  nAbsTabWidth = nAbsAvail;
1166  }
1167  }
1168 
1169  OSL_ENSURE( IsTopTable() || nAbsTabWidth<=nAbsAvail,
1170  "AutoLayout pass 2: nAbsTabWidth > nAbsAvail for table in table" );
1171  OSL_ENSURE( !nRelAvail || nAbsTabWidth<=nAbsAvail,
1172  "AutoLayout pass 2: nAbsTabWidth > nAbsAvail for relative width" );
1173 
1174  // Catch for the two asserts above (we never know!)
1175  if( (!IsTopTable() || nRelAvail>0) && nAbsTabWidth>nAbsAvail )
1176  nAbsTabWidth = nAbsAvail;
1177 
1178  // Step 3: Identify the column width and, if applicable, the absolute
1179  // and relative table widths.
1180  if( (!IsTopTable() && m_nMin > static_cast<sal_uLong>(nAbsAvail)) ||
1181  m_nMin > MAX_TABWIDTH )
1182  {
1183  // If
1184  // - an inner table's minimum is larger than the available space, or
1185  // - a top table's minimum is larger than USHORT_MAX the table
1186  // has to be adapted to the available space or USHORT_MAX.
1187  // We preserve the widths' ratio amongst themselves, however.
1188 
1189  nAbsTabWidth = IsTopTable() ? MAX_TABWIDTH : nAbsAvail;
1190  m_nRelTabWidth = (nRelAvail ? nRelAvail : nAbsTabWidth );
1191 
1192  // First of all, we check whether we can fit the layout constrains,
1193  // which are: Every cell's width excluding the borders must be at least
1194  // MINLAY:
1195 
1196  sal_uLong nRealMin = 0;
1197  for( sal_uInt16 i=0; i<m_nCols; i++ )
1198  {
1199  sal_uLong nRealColMin = MINLAY, nDummy1 = 0, nDummy2 = 0;
1200  AddBorderWidth( nRealColMin, nDummy1, nDummy2, i, 1 );
1201  nRealMin += nRealColMin;
1202  }
1203  if( (nRealMin >= nAbsTabWidth) || (nRealMin >= m_nMin) )
1204  {
1205  // "Rien ne va plus": we cannot get the minimum column widths
1206  // the layout wants to have.
1207 
1208  sal_uInt16 nAbs = 0, nRel = 0;
1209  SwHTMLTableLayoutColumn *pColumn;
1210  for( sal_uInt16 i=0; i<m_nCols-1; i++ )
1211  {
1212  pColumn = GetColumn( i );
1213  sal_uLong nColMin = pColumn->GetMin();
1214  if( nColMin <= USHRT_MAX )
1215  {
1216  pColumn->SetAbsColWidth(
1217  static_cast<sal_uInt16>((nColMin * nAbsTabWidth) / m_nMin) );
1218  pColumn->SetRelColWidth(
1219  static_cast<sal_uInt16>((nColMin * m_nRelTabWidth) / m_nMin) );
1220  }
1221  else
1222  {
1223  double nColMinD = nColMin;
1224  pColumn->SetAbsColWidth(
1225  static_cast<sal_uInt16>((nColMinD * nAbsTabWidth) / m_nMin) );
1226  pColumn->SetRelColWidth(
1227  static_cast<sal_uInt16>((nColMinD * m_nRelTabWidth) / m_nMin) );
1228  }
1229 
1230  nAbs = nAbs + pColumn->GetAbsColWidth();
1231  nRel = nRel + pColumn->GetRelColWidth();
1232  }
1233  pColumn = GetColumn( m_nCols-1 );
1234  pColumn->SetAbsColWidth( nAbsTabWidth - nAbs );
1235  pColumn->SetRelColWidth( m_nRelTabWidth - nRel );
1236  }
1237  else
1238  {
1239  sal_uLong nDistAbs = nAbsTabWidth - nRealMin;
1240  sal_uLong nDistRel = m_nRelTabWidth - nRealMin;
1241  sal_uLong nDistMin = m_nMin - nRealMin;
1242  sal_uInt16 nAbs = 0, nRel = 0;
1243  SwHTMLTableLayoutColumn *pColumn;
1244  for( sal_uInt16 i=0; i<m_nCols-1; i++ )
1245  {
1246  pColumn = GetColumn( i );
1247  sal_uLong nColMin = pColumn->GetMin();
1248  sal_uLong nRealColMin = MINLAY, nDummy1 = 0, nDummy2 = 0;
1249  AddBorderWidth( nRealColMin, nDummy1, nDummy2, i, 1 );
1250 
1251  if( nColMin <= USHRT_MAX )
1252  {
1253  pColumn->SetAbsColWidth(
1254  static_cast<sal_uInt16>((((nColMin-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) );
1255  pColumn->SetRelColWidth(
1256  static_cast<sal_uInt16>((((nColMin-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) );
1257  }
1258  else
1259  {
1260  double nColMinD = nColMin;
1261  pColumn->SetAbsColWidth(
1262  static_cast<sal_uInt16>((((nColMinD-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) );
1263  pColumn->SetRelColWidth(
1264  static_cast<sal_uInt16>((((nColMinD-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) );
1265  }
1266 
1267  nAbs = nAbs + pColumn->GetAbsColWidth();
1268  nRel = nRel + pColumn->GetRelColWidth();
1269  }
1270  pColumn = GetColumn( m_nCols-1 );
1271  pColumn->SetAbsColWidth( nAbsTabWidth - nAbs );
1272  pColumn->SetRelColWidth( m_nRelTabWidth - nRel );
1273  }
1274  }
1275  else if( m_nMax <= static_cast<sal_uLong>(nAbsTabWidth ? nAbsTabWidth : nAbsAvail) )
1276  {
1277  // If
1278  // - the table has a fixed width and the table's maximum is
1279  // smaller, or
1280  //- the maximum is smaller than the available space,
1281  // we can take over the maximum as it is. Respectively
1282  // the table can only be adapted to the fixed width by
1283  // respecting the maximum.
1284 
1285  // No fixed width, use the maximum.
1286  if( !nAbsTabWidth )
1287  nAbsTabWidth = static_cast<sal_uInt16>(m_nMax);
1288 
1289  // A top table may also get wider then the available space.
1290  if( nAbsTabWidth > nAbsAvail )
1291  {
1292  OSL_ENSURE( IsTopTable(),
1293  "Table in table should get wider than the surrounding cell." );
1294  nAbsAvail = nAbsTabWidth;
1295  }
1296 
1297  // Only use the relative widths' fraction, that is used for the
1298  // absolute width.
1299  sal_uLong nAbsTabWidthL = nAbsTabWidth;
1300  if (nRelAvail)
1301  {
1302  if (nAbsAvail == 0)
1303  throw o3tl::divide_by_zero();
1304  m_nRelTabWidth = static_cast<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail);
1305  }
1306  else
1307  m_nRelTabWidth = nAbsTabWidth;
1308 
1309  // Are there columns width a percentage setting and some without one?
1310  sal_uLong nFixMax = m_nMax;
1311  for( sal_uInt16 i=0; i<m_nCols; i++ )
1312  {
1313  const SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
1314  if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption()>0 )
1315  nFixMax -= pColumn->GetMax();
1316  }
1317 
1318  if( nFixMax > 0 && nFixMax < m_nMax )
1319  {
1320  // Yes, distribute the to-be-distributed space only to the
1321  // columns with a percentage setting.
1322 
1323  // In this case (and in this case only) there are columns
1324  // that exactly keep their maximum width, that is they neither
1325  // get smaller nor wider. When calculating the absolute width
1326  // from the relative width we can get rounding errors.
1327  // To correct this, we first make the fixed widths compensate for
1328  // this error. We then fix the relative widths the same way.
1329 
1330  sal_uInt16 nAbs = 0, nRel = 0;
1331  sal_uInt16 nFixedCols = 0;
1332  sal_uInt16 i;
1333 
1334  for( i = 0; i < m_nCols; i++ )
1335  {
1336  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
1337  if( !pColumn->IsRelWidthOption() || !pColumn->GetWidthOption() )
1338  {
1339  // The column keeps its width.
1340  nFixedCols++;
1341  sal_uLong nColMax = pColumn->GetMax();
1342  pColumn->SetAbsColWidth( static_cast<sal_uInt16>(nColMax) );
1343 
1344  sal_uLong nRelColWidth =
1345  (nColMax * m_nRelTabWidth) / nAbsTabWidth;
1346  sal_uLong nChkWidth =
1347  (nRelColWidth * nAbsTabWidth) / m_nRelTabWidth;
1348  if( nChkWidth < nColMax )
1349  nRelColWidth++;
1350  else if( nChkWidth > nColMax )
1351  nRelColWidth--;
1352  pColumn->SetRelColWidth( static_cast<sal_uInt16>(nRelColWidth) );
1353 
1354  nAbs = nAbs + static_cast<sal_uInt16>(nColMax);
1355  nRel = nRel + static_cast<sal_uInt16>(nRelColWidth);
1356  }
1357  }
1358 
1359  // The to-be-distributed percentage of the maximum, the
1360  // relative and absolute widths. Here, nFixMax corresponds
1361  // to nAbs, so that we could've called it nAbs.
1362  // The code is, however, more readable like that.
1363  OSL_ENSURE( nFixMax == nAbs, "Two loops, two sums?" );
1364  sal_uLong nDistMax = m_nMax - nFixMax;
1365  sal_uInt16 nDistAbsTabWidth = nAbsTabWidth - nAbs;
1366  sal_uInt16 nDistRelTabWidth = m_nRelTabWidth - nRel;
1367 
1368  for( i=0; i<m_nCols; i++ )
1369  {
1370  SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
1371  if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() > 0 )
1372  {
1373  // The column gets proportionately wider.
1374  nFixedCols++;
1375  if( nFixedCols == m_nCols )
1376  {
1377  pColumn->SetAbsColWidth( nAbsTabWidth-nAbs );
1378  pColumn->SetRelColWidth( m_nRelTabWidth-nRel );
1379  }
1380  else
1381  {
1382  sal_uLong nColMax = pColumn->GetMax();
1383  pColumn->SetAbsColWidth(
1384  static_cast<sal_uInt16>((nColMax * nDistAbsTabWidth) / nDistMax) );
1385  pColumn->SetRelColWidth(
1386  static_cast<sal_uInt16>((nColMax * nDistRelTabWidth) / nDistMax) );
1387  }
1388  nAbs = nAbs + pColumn->GetAbsColWidth();
1389  nRel = nRel + pColumn->GetRelColWidth();
1390  }
1391  }
1392  OSL_ENSURE( m_nCols==nFixedCols, "Missed a column!" );
1393  }
1394  else if (m_nCols > 0)
1395  {
1396  if (m_nMax == 0)
1397  throw o3tl::divide_by_zero();
1398  // No. So distribute the space regularly among all columns.
1399  for (sal_uInt16 i=0; i < m_nCols; ++i)
1400  {
1401  sal_uLong nColMax = GetColumn( i )->GetMax();
1402  GetColumn( i )->SetAbsColWidth(
1403  static_cast<sal_uInt16>((nColMax * nAbsTabWidth) / m_nMax) );
1404  GetColumn( i )->SetRelColWidth(
1405  static_cast<sal_uInt16>((nColMax * m_nRelTabWidth) / m_nMax) );
1406  }
1407  }
1408  }
1409  else
1410  {
1411  // Proportionately distribute the space that extends over the minimum
1412  // width among the columns.
1413  if( !nAbsTabWidth )
1414  nAbsTabWidth = nAbsAvail;
1415  if( nAbsTabWidth < m_nMin )
1416  nAbsTabWidth = static_cast<sal_uInt16>(m_nMin);
1417 
1418  if( nAbsTabWidth > nAbsAvail )
1419  {
1420  OSL_ENSURE( IsTopTable(),
1421  "A nested table should become wider than the available space." );
1422  nAbsAvail = nAbsTabWidth;
1423  }
1424 
1425  sal_uLong nAbsTabWidthL = nAbsTabWidth;
1426  if (nRelAvail)
1427  {
1428  if (nAbsAvail == 0)
1429  throw o3tl::divide_by_zero();
1430  m_nRelTabWidth = static_cast<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail);
1431  }
1432  else
1433  m_nRelTabWidth = nAbsTabWidth;
1434  double nW = nAbsTabWidth - m_nMin;
1435  double nD = (m_nMax==m_nMin ? 1 : m_nMax-m_nMin);
1436  sal_uInt16 nAbs = 0, nRel = 0;
1437  for( sal_uInt16 i=0; i<m_nCols-1; i++ )
1438  {
1439  double nd = GetColumn( i )->GetMax() - GetColumn( i )->GetMin();
1440  sal_uLong nAbsColWidth = GetColumn( i )->GetMin() + static_cast<sal_uLong>((nd*nW)/nD);
1441  sal_uLong nRelColWidth = nRelAvail
1442  ? (nAbsColWidth * m_nRelTabWidth) / nAbsTabWidth
1443  : nAbsColWidth;
1444 
1445  GetColumn( i )->SetAbsColWidth( static_cast<sal_uInt16>(nAbsColWidth) );
1446  GetColumn( i )->SetRelColWidth( static_cast<sal_uInt16>(nRelColWidth) );
1447  nAbs = nAbs + static_cast<sal_uInt16>(nAbsColWidth);
1448  nRel = nRel + static_cast<sal_uInt16>(nRelColWidth);
1449  }
1450  GetColumn( m_nCols-1 )->SetAbsColWidth( nAbsTabWidth - nAbs );
1451  GetColumn( m_nCols-1 )->SetRelColWidth( m_nRelTabWidth - nRel );
1452 
1453  }
1454 
1455  // Step 4: For nested tables we can have balancing cells on the
1456  // left or right. Here we calculate their width.
1457  m_nInhAbsLeftSpace = 0;
1458  m_nInhAbsRightSpace = 0;
1459  if( IsTopTable() ||
1460  !(m_nRelLeftFill>0 || m_nRelRightFill>0 || nAbsTabWidth<nAbsAvail) )
1461  return;
1462 
1463  // Calculate the width of additional cells we use for
1464  // aligning inner tables.
1465  sal_uInt16 nAbsDist = static_cast<sal_uInt16>(nAbsAvail-nAbsTabWidth);
1466  sal_uInt16 nRelDist = static_cast<sal_uInt16>(nRelAvail-m_nRelTabWidth);
1467  sal_uInt16 nParentInhAbsLeftSpace = 0, nParentInhAbsRightSpace = 0;
1468 
1469  // Calculate the size and position of the additional cells.
1470  switch( m_eTableAdjust )
1471  {
1472  case SvxAdjust::Right:
1473  nAbsLeftFill = nAbsLeftFill + nAbsDist;
1474  m_nRelLeftFill = m_nRelLeftFill + nRelDist;
1475  nParentInhAbsLeftSpace = nParentInhAbsSpace;
1476  break;
1477  case SvxAdjust::Center:
1478  {
1479  sal_uInt16 nAbsLeftDist = nAbsDist / 2;
1480  nAbsLeftFill = nAbsLeftFill + nAbsLeftDist;
1481  nAbsRightFill += nAbsDist - nAbsLeftDist;
1482  sal_uInt16 nRelLeftDist = nRelDist / 2;
1483  m_nRelLeftFill = m_nRelLeftFill + nRelLeftDist;
1484  m_nRelRightFill += nRelDist - nRelLeftDist;
1485  nParentInhAbsLeftSpace = nParentInhAbsSpace / 2;
1486  nParentInhAbsRightSpace = nParentInhAbsSpace -
1487  nParentInhAbsLeftSpace;
1488  }
1489  break;
1490  case SvxAdjust::Left:
1491  default:
1492  nAbsRightFill = nAbsRightFill + nAbsDist;
1493  m_nRelRightFill = m_nRelRightFill + nRelDist;
1494  nParentInhAbsRightSpace = nParentInhAbsSpace;
1495  break;
1496  }
1497 
1498  // Filler widths are added to the outer columns, if there are no boxes
1499  // for them after the first pass (nWidth>0) or their width would become
1500  // too small or if there are COL tags and the filler width corresponds
1501  // to the border width.
1502  // In the last case we probably exported the table ourselves.
1503  if( m_nRelLeftFill &&
1504  ( m_nWidthSet>0 || nAbsLeftFill<MINLAY+m_nInhLeftBorderWidth ||
1505  (HasColTags() && nAbsLeftFill < nAbsLeftSpace+nParentInhAbsLeftSpace+20) ) )
1506  {
1507  SwHTMLTableLayoutColumn *pColumn = GetColumn( 0 );
1508  pColumn->SetAbsColWidth( pColumn->GetAbsColWidth()+nAbsLeftFill );
1509  pColumn->SetRelColWidth( pColumn->GetRelColWidth()+m_nRelLeftFill );
1510  m_nRelLeftFill = 0;
1511  m_nInhAbsLeftSpace = nAbsLeftSpace + nParentInhAbsLeftSpace;
1512  }
1513  if( m_nRelRightFill &&
1514  ( m_nWidthSet>0 || nAbsRightFill<MINLAY+m_nInhRightBorderWidth ||
1515  (HasColTags() && nAbsRightFill < nAbsRightSpace+nParentInhAbsRightSpace+20) ) )
1516  {
1517  SwHTMLTableLayoutColumn *pColumn = GetColumn( m_nCols-1 );
1518  pColumn->SetAbsColWidth( pColumn->GetAbsColWidth()+nAbsRightFill );
1519  pColumn->SetRelColWidth( pColumn->GetRelColWidth()+m_nRelRightFill );
1520  m_nRelRightFill = 0;
1521  m_nInhAbsRightSpace = nAbsRightSpace + nParentInhAbsRightSpace;
1522  }
1523 }
1524 
1525 static void lcl_ResizeLine( const SwTableLine* pLine, SwTwips *pWidth );
1526 
1527 static void lcl_ResizeBox( const SwTableBox* pBox, SwTwips* pWidth )
1528 {
1529  if( !pBox->GetSttNd() )
1530  {
1531  SwTwips nWidth = 0;
1532  for( const SwTableLine *pLine : pBox->GetTabLines() )
1533  lcl_ResizeLine( pLine, &nWidth );
1534  pBox->GetFrameFormat()->SetFormatAttr( SwFormatFrameSize( SwFrameSize::Variable, nWidth, 0 ));
1535  *pWidth = *pWidth + nWidth;
1536  }
1537  else
1538  {
1539  *pWidth = *pWidth + pBox->GetFrameFormat()->GetFrameSize().GetSize().Width();
1540  }
1541 }
1542 
1543 static void lcl_ResizeLine( const SwTableLine* pLine, SwTwips *pWidth )
1544 {
1545  SwTwips nOldWidth = *pWidth;
1546  *pWidth = 0;
1547  for( const SwTableBox* pBox : pLine->GetTabBoxes() )
1548  lcl_ResizeBox(pBox, pWidth );
1549 
1550  SAL_WARN_IF( nOldWidth && std::abs(*pWidth-nOldWidth) >= COLFUZZY, "sw.core",
1551  "A box's rows have all a different length" );
1552 }
1553 
1554 void SwHTMLTableLayout::SetWidths( bool bCallPass2, sal_uInt16 nAbsAvail,
1555  sal_uInt16 nRelAvail, sal_uInt16 nAbsLeftSpace,
1556  sal_uInt16 nAbsRightSpace,
1557  sal_uInt16 nParentInhAbsSpace )
1558 {
1559  // SetWidth must have been passed through once more for every cell in the
1560  // end.
1561  m_nWidthSet++;
1562 
1563  // Step 0: If necessary, we call the layout algorithm of Pass2.
1564  if( bCallPass2 )
1565  AutoLayoutPass2( nAbsAvail, nRelAvail, nAbsLeftSpace, nAbsRightSpace,
1566  nParentInhAbsSpace );
1567 
1568  // Step 1: Set the new width in all content boxes.
1569  // Because the boxes don't know anything about the HTML table structure,
1570  // we iterate over the HTML table structure.
1571  // For tables in tables in tables we call SetWidth recursively.
1572  for( sal_uInt16 i=0; i<m_nRows; i++ )
1573  {
1574  for( sal_uInt16 j=0; j<m_nCols; j++ )
1575  {
1576  SwHTMLTableLayoutCell *pCell = GetCell( i, j );
1577 
1578  SwHTMLTableLayoutCnts* pContents = pCell->GetContents().get();
1579  while( pContents && !pContents->IsWidthSet(m_nWidthSet) )
1580  {
1581  SwTableBox *pBox = pContents->GetTableBox();
1582  if( pBox )
1583  {
1584  SetBoxWidth( pBox, j, pCell->GetColSpan() );
1585  }
1586  else if (SwHTMLTableLayout *pTable = pContents->GetTable())
1587  {
1588  sal_uInt16 nAbs = 0, nRel = 0, nLSpace = 0, nRSpace = 0,
1589  nInhSpace = 0;
1590  if( bCallPass2 )
1591  {
1592  sal_uInt16 nColSpan = pCell->GetColSpan();
1593  GetAvail( j, nColSpan, nAbs, nRel );
1594  nLSpace = GetLeftCellSpace( j, nColSpan );
1595  nRSpace = GetRightCellSpace( j, nColSpan );
1596  nInhSpace = GetInhCellSpace( j, nColSpan );
1597  }
1598  pTable->SetWidths( bCallPass2, nAbs, nRel,
1599  nLSpace, nRSpace,
1600  nInhSpace );
1601  }
1602 
1603  pContents->SetWidthSet( m_nWidthSet );
1604  pContents = pContents->GetNext().get();
1605  }
1606  }
1607  }
1608 
1609  // Step 2: If we have a top table, we adapt the formats of the
1610  // non-content-boxes. Because they are not known in the HTML table
1611  // due to garbage collection there, we need the iterate over the
1612  // whole table.
1613  // We also adapt the table frame format. For nested tables we set the
1614  // filler cell's width instead.
1615  if( !IsTopTable() )
1616  return;
1617 
1618  SwTwips nCalcTabWidth = 0;
1619  for( const SwTableLine *pLine : m_pSwTable->GetTabLines() )
1620  lcl_ResizeLine( pLine, &nCalcTabWidth );
1621  SAL_WARN_IF( std::abs( m_nRelTabWidth-nCalcTabWidth ) >= COLFUZZY, "sw.core",
1622  "Table width is not equal to the row width" );
1623 
1624  // Lock the table format when altering it, or else the box formats
1625  // are altered again.
1626  // Also, we need to preserve a percent setting if it exists.
1627  SwFrameFormat *pFrameFormat = m_pSwTable->GetFrameFormat();
1628  const_cast<SwTable *>(m_pSwTable)->LockModify();
1629  SwFormatFrameSize aFrameSize( pFrameFormat->GetFrameSize() );
1630  aFrameSize.SetWidth( m_nRelTabWidth );
1631  bool bRel = m_bUseRelWidth &&
1632  text::HoriOrientation::FULL!=pFrameFormat->GetHoriOrient().GetHoriOrient();
1633  aFrameSize.SetWidthPercent( static_cast<sal_uInt8>(bRel ? m_nWidthOption : 0) );
1634  pFrameFormat->SetFormatAttr( aFrameSize );
1635  const_cast<SwTable *>(m_pSwTable)->UnlockModify();
1636 
1637  // If the table is located in a frame, we also need to adapt the
1638  // frame's width.
1639  if( MayBeInFlyFrame() )
1640  {
1641  SwFrameFormat *pFlyFrameFormat = FindFlyFrameFormat();
1642  if( pFlyFrameFormat )
1643  {
1645 
1646  if( m_bUseRelWidth )
1647  {
1648  // For percentage settings we set the width to the minimum.
1649  aFlyFrameSize.SetWidth( m_nMin > USHRT_MAX ? USHRT_MAX
1650  : m_nMin );
1651  aFlyFrameSize.SetWidthPercent( static_cast<sal_uInt8>(m_nWidthOption) );
1652  }
1653  pFlyFrameFormat->SetFormatAttr( aFlyFrameSize );
1654  }
1655  }
1656 
1657 #ifdef DBG_UTIL
1658  {
1659  // check if the tables have correct widths
1661  const SwTableLines& rLines = m_pSwTable->GetTabLines();
1662  for (size_t n = 0; n < rLines.size(); ++n)
1663  {
1664  CheckBoxWidth( *rLines[ n ], nSize );
1665  }
1666  }
1667 #endif
1668 }
1669 
1670 void SwHTMLTableLayout::Resize_( sal_uInt16 nAbsAvail, bool bRecalc )
1671 {
1672  // If bRecalc is set, the table's content changed.
1673  // We need to execute pass 1 again.
1674  if( bRecalc )
1675  AutoLayoutPass1();
1676 
1678  if ( pRoot && pRoot->IsCallbackActionEnabled() )
1679  pRoot->StartAllAction();
1680 
1681  // Else we can set the widths, in which we have to run Pass 2 in each case.
1682  SetWidths( true, nAbsAvail );
1683 
1684  if ( pRoot && pRoot->IsCallbackActionEnabled() )
1685  pRoot->EndAllAction( true ); //True per VirDev (browsing is calmer)
1686 }
1687 
1688 IMPL_LINK_NOARG( SwHTMLTableLayout, DelayedResize_Impl, Timer*, void )
1689 {
1690  m_aResizeTimer.Stop();
1692 }
1693 
1694 bool SwHTMLTableLayout::Resize( sal_uInt16 nAbsAvail, bool bRecalc,
1695  bool bForce, sal_uLong nDelay )
1696 {
1697  if( 0 == nAbsAvail )
1698  return false;
1699  OSL_ENSURE( IsTopTable(), "Resize must only be called for top tables!" );
1700 
1701  // May the table be resized at all? Or is it forced?
1702  if( m_bMustNotResize && !bForce )
1703  return false;
1704 
1705  // May the table be recalculated? Or is it forced?
1706  if( m_bMustNotRecalc && !bForce )
1707  bRecalc = false;
1708 
1709  const SwDoc& rDoc = GetDoc();
1710 
1711  // If there is a layout, the root frame's size instead of the
1712  // VisArea's size was potentially passed.
1713  // If we're not in a frame we need to calculate the table for the VisArea,
1714  // because switching from relative to absolute wouldn't work.
1716  {
1717  const sal_uInt16 nVisAreaWidth = GetBrowseWidthByVisArea( rDoc );
1718  if( nVisAreaWidth < nAbsAvail && !FindFlyFrameFormat() )
1719  nAbsAvail = nVisAreaWidth;
1720  }
1721 
1722  if( nDelay==0 && m_aResizeTimer.IsActive() )
1723  {
1724  m_nDelayedResizeAbsAvail = nAbsAvail;
1725  return false;
1726  }
1727 
1728  // Optimisation:
1729  // If the minimum or maximum should not be recalculated and
1730  // - the table's width never needs to be recalculated, or
1731  // - the table was already calculated for the passed width, or
1732  // - the available space is less or equal to the minimum width
1733  // and the table already has the minimum width, or
1734  // - the available space is larger than the maximum width and
1735  // the table already has the maximum width
1736  // nothing will happen to the table.
1737  if( !bRecalc && ( !m_bMustResize ||
1738  (m_nLastResizeAbsAvail==nAbsAvail) ||
1739  (nAbsAvail<=m_nMin && m_nRelTabWidth==m_nMin) ||
1740  (!m_bPercentWidthOption && nAbsAvail>=m_nMax && m_nRelTabWidth==m_nMax) ) )
1741  return false;
1742 
1743  if( nDelay==HTMLTABLE_RESIZE_NOW )
1744  {
1745  if( m_aResizeTimer.IsActive() )
1746  m_aResizeTimer.Stop();
1747  Resize_( nAbsAvail, bRecalc );
1748  }
1749  else if( nDelay > 0 )
1750  {
1751  m_nDelayedResizeAbsAvail = nAbsAvail;
1752  m_bDelayedResizeRecalc = bRecalc;
1753  m_aResizeTimer.SetTimeout( nDelay );
1755  }
1756  else
1757  {
1758  Resize_( nAbsAvail, bRecalc );
1759  }
1760 
1761  return true;
1762 }
1763 
1764 void SwHTMLTableLayout::BordersChanged( sal_uInt16 nAbsAvail )
1765 {
1766  m_bBordersChanged = true;
1767 
1768  Resize( nAbsAvail, true/*bRecalc*/ );
1769 }
1770 
1771 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwHTMLTableLayoutColumn(sal_uInt16 nColWidthOpt, bool bRelColWidthOpt, bool bLBorder)
Definition: htmltbl.cxx:103
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:685
Starts a section of nodes in the document model.
Definition: node.hxx:311
Base class of the Writer layout elements.
Definition: frame.hxx:298
const SwStartNode * GetStartNode() const
Definition: htmltbl.cxx:88
tools::Long GetWidth() const
void AddBorderWidth(sal_uLong &rMin, sal_uLong &rMax, sal_uLong &rAbsMin, sal_uInt16 nCol, sal_uInt16 nColSpan, bool bSwBorders=true) const
Definition: htmltbl.cxx:272
sal_uLong GetMin() const
Definition: htmltbl.hxx:157
bool m_bUseRelWidth
SwTable gets relative width.
Definition: htmltbl.hxx:218
sal_uLong GetIndex() const
Definition: node.hxx:290
sal_uInt16 GetLeftCellSpace(sal_uInt16 nCol, sal_uInt16 nColSpan, bool bSwBorders=true) const
The border widths are calculated like in Netscape: Outer border: BORDER + CELLSPACING + CELLPADDING I...
Definition: htmltbl.cxx:215
bool HasColTags() const
Definition: htmltbl.hxx:286
SwHTMLTableLayoutCnts(const SwStartNode *pSttNd, std::shared_ptr< SwHTMLTableLayout > const &rTab, bool bNoBreakTag, std::shared_ptr< SwHTMLTableLayoutCnts > const &rNxt)
Definition: htmltbl.cxx:80
const SwTable * m_pSwTable
SwTable (Top-Table only).
Definition: htmltbl.hxx:176
void AutoLayoutPass1()
Definition: htmltbl.cxx:441
bool IsDefault() const
Definition: format.hxx:109
sal_uInt16 m_nWidthOption
Width of table (in Twips or %).
Definition: htmltbl.hxx:195
virtual const SwRootFrame * GetCurrentLayout() const =0
bool IsTopTable() const
Definition: htmltbl.hxx:288
void SetBoxWidth(SwTableBox *pBox, sal_uInt16 nCol, sal_uInt16 nColSpan) const
Definition: htmltbl.cxx:285
bool HasNoWrapOption() const
Definition: htmltbl.hxx:115
bool m_bPercentWidthOption
Width is given in percent.
Definition: htmltbl.hxx:217
sal_uIntPtr sal_uLong
const SwStartNode * m_pStartNode
During first run there are still no boxes.
Definition: htmltbl.hxx:48
long Long
const SwRect & getFramePrintArea() const
Definition: frame.hxx:179
#define MINLAY
Definition: swtypes.hxx:66
SwFrameFormat * FindFlyFrameFormat() const
Definition: htmltbl.cxx:406
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:30
sal_Int64 n
Definition: doc.hxx:186
#define max(a, b)
SwTableLine is one table row in the document model.
Definition: swtable.hxx:351
SwHTMLTableLayout * GetTable() const
Definition: htmltbl.hxx:67
SwTwips m_nBorderWidth
Definition: htmltbl.hxx:205
Dialog to specify the properties of date form field.
bool MayBeInFlyFrame() const
Definition: htmltbl.hxx:338
SwTableLine * front() const
Definition: swtable.hxx:80
sal_uLong GetAbsMinNoAlign() const
Definition: htmltbl.hxx:150
SwHTMLTableLayoutCell(std::shared_ptr< SwHTMLTableLayoutCnts > const &rCnts, sal_uInt16 nRSpan, sal_uInt16 nCSpan, sal_uInt16 nWidthOpt, bool bPercentWidthOpt, bool bNWrapOpt)
Definition: htmltbl.cxx:93
#define MIN_BORDER_DIST
Definition: swtypes.hxx:74
void MergeMinMaxNoAlign(sal_uLong nMin, sal_uLong nMax, sal_uLong nAbsMin)
Definition: htmltbl.hxx:348
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
sal_Int32 GetBrowseWidth() const
Definition: viewsh.cxx:2000
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:203
AutoLayout
Value in Var-direction gives minimum (can be exceeded but not be less).
bool HasNoBreakTag() const
Definition: htmltbl.hxx:80
size_type size() const
Definition: swtable.hxx:75
static void lcl_GetMinMaxSize(sal_uLong &rMinNoAlignCnts, sal_uLong &rMaxNoAlignCnts, sal_uLong &rAbsMinNoAlignCnts, SwTextNode const *pTextNd, sal_uLong nIdx, bool bNoBreak)
Definition: htmltbl.cxx:413
bool IsActive() const
static sal_uInt16 GetBrowseWidthByVisArea(const SwDoc &rDoc)
Definition: htmltbl.cxx:312
bool CalcFlyOffsets(SwTwips &rUpper, tools::Long &rLeftOffset, tools::Long &rRightOffset) const
Calculate the offsets arising because of FlyFrames.
Definition: tabfrm.cxx:2732
bool IsFlyFrame() const
Definition: frame.hxx:1191
sal_uInt16 GetRelColWidth() const
Definition: htmltbl.hxx:164
static sal_uInt16 GetBrowseWidth(const SwDoc &rDoc)
Calculate available width.
Definition: htmltbl.cxx:323
void SetWidths(bool bCallPass2=false, sal_uInt16 nAbsAvail=0, sal_uInt16 nRelAvail=0, sal_uInt16 nAbsLeftSpace=0, sal_uInt16 nAbsRightSpace=0, sal_uInt16 nParentInhSpace=0)
Definition: htmltbl.cxx:1554
sal_uInt16 GetColSpan() const
Definition: htmltbl.hxx:110
const SwRect & getFrameArea() const
Definition: frame.hxx:178
void MergeCellWidthOption(sal_uInt16 nWidth, bool bPercent)
Definition: htmltbl.hxx:370
#define SAL_MAX_UINT16
bool getBrowseMode() const
Definition: viewopt.hxx:458
sal_uInt16 GetWidthOption() const
Definition: htmltbl.hxx:144
bool IsTextFrame() const
Definition: frame.hxx:1215
void Width(tools::Long nNew)
Definition: swrect.hxx:187
void Resize_(sal_uInt16 nAbsAvail, bool bRecalc)
Definition: htmltbl.cxx:1670
const SwTable & GetTable() const
Definition: node.hxx:500
bool m_bMustResize
Table width must be defined.
Definition: htmltbl.hxx:220
sal_uInt16 GetPoolFormatId() const
Get and set Pool style IDs.
Definition: format.hxx:143
SwFormatColl & GetAnyFormatColl() const
Definition: node.hxx:710
void SetPass1Done(sal_uInt8 nRef)
Definition: htmltbl.hxx:77
sal_uInt16 GetBrowseWidthByTable(const SwDoc &rDoc) const
Calculates available width by the table-frame or static GetBrowseWidth if no layout exists...
Definition: htmltbl.cxx:373
const SwStartNode * GetAnyBoxStartNode() const
Definition: htmltbl.cxx:389
SwHTMLTableLayoutCell * GetCell(sal_uInt16 nRow, sal_uInt16 nCol) const
Definition: htmltbl.hxx:415
Style of a layout element.
Definition: frmfmt.hxx:58
SwTwips m_nLeftBorderWidth
Line strength of outer border, or rather the space needed for it as calculated by Netscape...
Definition: htmltbl.hxx:201
sal_uInt16 GetRightCellSpace(sal_uInt16 nCol, sal_uInt16 nColSpan, bool bSwBorders=true) const
Definition: htmltbl.cxx:248
bool IsPercentWidthOption() const
Definition: htmltbl.hxx:113
bool IsRelWidthOption() const
Definition: htmltbl.hxx:145
SvxAdjust
int i
SwDoc & GetDoc()
Definition: node.hxx:211
bool empty() const
Definition: swtable.hxx:74
sal_uInt8 m_nPass1Done
Reference-values for.
Definition: htmltbl.hxx:210
void CheckBoxWidth(const SwTableLine &rLine, SwTwips nSize)
Definition: tblrwcl.cxx:2569
const SwFormatHoriOrient & GetHoriOrient(bool=true) const
Definition: fmtornt.hxx:108
SwHTMLTableLayout(const SwTable *pSwTable, sal_uInt16 nRows, sal_uInt16 nCols, bool bColsOpt, bool ColTgs, sal_uInt16 nWidth, bool bPercentWidth, sal_uInt16 nBorderOpt, sal_uInt16 nCellPad, sal_uInt16 nCellSp, SvxAdjust eAdjust, sal_uInt16 nLMargin, sal_uInt16 nRMargin, sal_uInt16 nBWidth, sal_uInt16 nLeftBWidth, sal_uInt16 nRightBWidth)
Definition: htmltbl.cxx:151
sal_uInt16 m_nDelayedResizeAbsAvail
Param for delayed Resize.
Definition: htmltbl.hxx:207
bool m_bMustNotResize
Table may not be resized.
Definition: htmltbl.hxx:226
sal_uInt16 m_nCellSpacing
Cell spacing (in Twips).
Definition: htmltbl.hxx:197
SwLayoutFrame * GetUpper()
Definition: frame.hxx:661
void SetMax(sal_uLong nVal)
Definition: htmltbl.hxx:154
#define COLFUZZY
Definition: htmltbl.cxx:49
const std::shared_ptr< SwHTMLTableLayoutCnts > & GetContents() const
Definition: htmltbl.hxx:103
void BordersChanged(sal_uInt16 nAbsAvail)
Definition: htmltbl.cxx:1764
sal_Int16 GetHoriOrient() const
Definition: fmtornt.hxx:87
virtual void Start() override
bool Resize(sal_uInt16 nAbsAvail, bool bRecalc=false, bool bForce=false, sal_uLong nDelay=0)
Recalculation of table widths for available width that has been passed.
Definition: htmltbl.cxx:1694
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:432
IMPL_LINK_NOARG(SwHTMLTableLayout, DelayedResize_Impl, Timer *, void)
Definition: htmltbl.cxx:1688
void SetTimeout(sal_uInt64 nTimeoutMs)
sal_uInt16 m_nRelTabWidth
Relative width of table.
Definition: htmltbl.hxx:193
SwTableLines & GetTabLines()
Definition: swtable.hxx:200
tools::Long SwTwips
Definition: swtypes.hxx:49
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:111
void SetWidth(tools::Long n)
SwTableLines & GetTabLines()
Definition: swtable.hxx:425
bool m_bMustNotRecalc
Table may not be adapted to its contents.
Definition: htmltbl.hxx:227
bool m_bDelayedResizeRecalc
Param for delayed Resize.
Definition: htmltbl.hxx:225
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:462
const sal_uInt16 USER_FMT
POLLCOLL-groups:
Definition: poolfmt.hxx:63
void ClearPass1Info(bool bWidthOpt)
Definition: htmltbl.hxx:359
sal_uInt16 m_nCols
Column count.
Definition: htmltbl.hxx:182
SwFormat * DerivedFrom() const
Definition: format.hxx:108
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
bool HasColsOption() const
Definition: htmltbl.hxx:285
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:361
const std::shared_ptr< SwHTMLTableLayoutCnts > & GetNext() const
Calculation of next node.
Definition: htmltbl.hxx:72
void GetMinMaxSize(sal_uLong nIndex, sal_uLong &rMin, sal_uLong &rMax, sal_uLong &rAbs) const
Is in itratr.
Definition: itratr.cxx:995
sal_uInt16 m_nLastResizeAbsAvail
Definition: htmltbl.hxx:208
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:446
SwTableBox * m_pBox
Only one of the following two pointers may be set!
Definition: htmltbl.hxx:43
void Stop()
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
#define SAL_WARN_IF(condition, area, stream)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:423
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
SwTwips m_nRightBorderWidth
Definition: htmltbl.hxx:202
SwHTMLTableLayout * GetHTMLTableLayout()
Definition: swtable.hxx:176
void SetMinMax(sal_uLong nMin, sal_uLong nMax)
Definition: htmltbl.hxx:381
void AddToMin(sal_uLong nVal)
Definition: htmltbl.hxx:155
void GetAvail(sal_uInt16 nCol, sal_uInt16 nColSpan, sal_uInt16 &rAbsAvail, sal_uInt16 &rRelAvail) const
Definition: htmltbl.cxx:299
SwNodes & GetNodes()
Definition: doc.hxx:405
Timer m_aResizeTimer
Timer for DelayedResize.
Definition: htmltbl.hxx:171
sal_uLong m_nMin
Minimal width of table (Twips).
Definition: htmltbl.hxx:178
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:393
SwFrame * GetLower()
Definition: findfrm.cxx:170
void SetInvokeHandler(const Link< Timer *, void > &rLink)
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:355
sal_uInt16 m_nBorder
Definition: htmltbl.hxx:198
const SwDoc & GetDoc() const
Definition: htmltbl.hxx:236
sal_uLong m_nMax
Maximal width of table (Twips).
Definition: htmltbl.hxx:179
sal_uLong GetMinNoAlign() const
Definition: htmltbl.hxx:148
sal_uInt16 GetAbsColWidth() const
Definition: htmltbl.hxx:161
void AddToMax(sal_uLong nVal)
Definition: htmltbl.hxx:156
void StartAllAction()
Set up Start-/EndAction for all Shells on an as high as possible (Shell section) level.
Definition: pagechg.cxx:1889
bool m_bBordersChanged
Borders have been changed.
Definition: htmltbl.hxx:222
bool IsPass1Done(sal_uInt8 nRef) const
Definition: htmltbl.hxx:78
sal_Int32 one
sal_uInt16 GetBrowseWidthByTabFrame(const SwTabFrame &rTabFrame) const
Calculates available width by table-frame.
Definition: htmltbl.cxx:341
SwHTMLTableLayoutColumn * GetColumn(sal_uInt16 nCol) const
Definition: htmltbl.hxx:399
sal_uInt16 GetWidthOption() const
Definition: htmltbl.hxx:112
Frame is variable in Var-direction.
void EndAllAction(bool bVirDev=false)
Definition: pagechg.cxx:1901
static void lcl_ResizeLine(const SwTableLine *pLine, SwTwips *pWidth)
Definition: htmltbl.cxx:1543
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:717
#define HTMLTABLE_RESIZE_NOW
Definition: htmltbl.hxx:36
sal_uInt16 m_nCellPadding
Space to contents (in Twips).
Definition: htmltbl.hxx:196
sal_uInt16 m_nRows
Row count.
Definition: htmltbl.hxx:181
bool IsCallbackActionEnabled() const
Definition: rootfrm.hxx:386
sal_uLong GetMax() const
Definition: htmltbl.hxx:158
sal_uLong GetMaxNoAlign() const
Definition: htmltbl.hxx:149