Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / htmltbl.hxx
blobdc263e378d6245cfedb9de81dbe3e2832f98ed5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_INC_HTMLTBL_HXX
21 #define INCLUDED_SW_INC_HTMLTBL_HXX
23 #include <memory>
24 #include <vcl/timer.hxx>
25 #include <editeng/svxenum.hxx>
27 #include "swtypes.hxx"
28 #include "node.hxx"
30 class SwTableBox;
31 class SwTable;
32 class SwHTMLTableLayout;
33 class SwDoc;
34 class SwFrameFormat;
36 #define HTMLTABLE_RESIZE_NOW (ULONG_MAX)
38 class SwHTMLTableLayoutCnts
40 SwHTMLTableLayoutCnts *pNext; ///< The next content.
42 /// Only one of the following two pointers may be set!
43 SwTableBox *pBox; ///< A Box.
44 SwHTMLTableLayout *pTable; ///< A "table within a table".
46 /** During first run there are still no boxes. In this case
47 pStartNode is used instead of pBox. */
48 const SwStartNode *pStartNode;
50 /** The following counters indicate how often a pass has been
51 done for this content. Therefore they are compared against
52 a reference value. If 255 is reached the continue with 0.
53 This avoids reinitialization on every resize. */
54 sal_uInt8 nPass1Done; ///< How many times has Pass 1 been called?
55 sal_uInt8 nWidthSet; ///< How many times has the width been set?
57 bool bNoBreakTag; ///< <NOBR>-Tag over complete content.
59 public:
61 SwHTMLTableLayoutCnts( const SwStartNode* pSttNd, SwHTMLTableLayout* pTab,
62 bool bNoBreakTag, SwHTMLTableLayoutCnts* pNxt );
64 ~SwHTMLTableLayoutCnts();
66 void SetTableBox( SwTableBox *pBx ) { pBox = pBx; }
67 SwTableBox *GetTableBox() const { return pBox; }
69 SwHTMLTableLayout *GetTable() const { return pTable; }
71 const SwStartNode *GetStartNode() const;
73 /// Calculation of next node.
74 SwHTMLTableLayoutCnts *GetNext() const { return pNext; }
76 void SetWidthSet( sal_uInt8 nRef ) { nWidthSet = nRef; }
77 bool IsWidthSet( sal_uInt8 nRef ) const { return nRef==nWidthSet; }
79 void SetPass1Done( sal_uInt8 nRef ) { nPass1Done = nRef; }
80 bool IsPass1Done( sal_uInt8 nRef ) const { return nRef==nPass1Done; }
82 bool HasNoBreakTag() const { return bNoBreakTag; }
85 class SwHTMLTableLayoutCell
87 SwHTMLTableLayoutCnts *pContents; ///< Content of cell.
89 sal_uInt16 nRowSpan; ///< ROWSPAN of cell.
90 sal_uInt16 nColSpan; ///< COLSPAN of cell.
91 sal_uInt16 nWidthOption; ///< Given width of cell in Twip or %.
93 bool bPrcWidthOption : 1; ///< nWidth is %-value.
94 bool bNoWrapOption : 1; ///< NOWRAP-option.
96 public:
98 SwHTMLTableLayoutCell( SwHTMLTableLayoutCnts *pCnts,
99 sal_uInt16 nRSpan, sal_uInt16 nCSpan,
100 sal_uInt16 nWidthOpt, bool bPrcWdthOpt,
101 bool bNWrapOpt );
103 ~SwHTMLTableLayoutCell();
105 /// Set or get content of a cell.
106 void SetContents( SwHTMLTableLayoutCnts *pCnts ) { pContents = pCnts; }
107 SwHTMLTableLayoutCnts *GetContents() const { return pContents; }
109 inline void SetProtected();
111 /// Set or get ROWSPAN/COLSPAN of cell.
112 void SetRowSpan( sal_uInt16 nRSpan ) { nRowSpan = nRSpan; }
113 sal_uInt16 GetRowSpan() const { return nRowSpan; }
114 sal_uInt16 GetColSpan() const { return nColSpan; }
116 sal_uInt16 GetWidthOption() const { return nWidthOption; }
117 bool IsPrcWidthOption() const { return bPrcWidthOption; }
119 bool HasNoWrapOption() const { return bNoWrapOption; }
122 class SwHTMLTableLayoutColumn
125 /// Interim values of AutoLayoutPass1,
126 sal_uLong nMinNoAlign, nMaxNoAlign, nAbsMinNoAlign;
128 /// Results of AutoLayoutPass1
129 sal_uLong nMin, nMax;
131 /// Results of Pass 2.
132 sal_uInt16 nAbsColWidth; ///< In Twips.
133 sal_uInt16 nRelColWidth; ///< In Twips or relative to USHRT_MAX.
135 sal_uInt16 nWidthOption; ///< Options of <COL> or <TD>/<TH>.
137 bool bRelWidthOption : 1;
138 bool bLeftBorder : 1;
140 public:
142 SwHTMLTableLayoutColumn( sal_uInt16 nColWidthOpt, bool bRelColWidthOpt,
143 bool bLBorder );
145 inline void MergeCellWidthOption( sal_uInt16 nWidth, bool bPrc );
146 inline void SetWidthOption( sal_uInt16 nWidth );
148 sal_uInt16 GetWidthOption() const { return nWidthOption; }
149 bool IsRelWidthOption() const { return bRelWidthOption; }
151 inline void MergeMinMaxNoAlign( sal_uLong nMin, sal_uLong nMax, sal_uLong nAbsMin );
152 sal_uLong GetMinNoAlign() const { return nMinNoAlign; }
153 sal_uLong GetMaxNoAlign() const { return nMaxNoAlign; }
154 sal_uLong GetAbsMinNoAlign() const { return nAbsMinNoAlign; }
155 inline void ClearPass1Info( bool bWidthOpt );
157 inline void SetMinMax( sal_uLong nMin, sal_uLong nMax );
158 void SetMax( sal_uLong nVal ) { nMax = nVal; }
159 void AddToMin( sal_uLong nVal ) { nMin += nVal; }
160 void AddToMax( sal_uLong nVal ) { nMax += nVal; }
161 sal_uLong GetMin() const { return nMin; }
162 sal_uLong GetMax() const { return nMax; }
164 void SetAbsColWidth( sal_uInt16 nWidth ) { nAbsColWidth = nWidth; }
165 sal_uInt16 GetAbsColWidth() const { return nAbsColWidth; }
167 void SetRelColWidth( sal_uInt16 nWidth ) { nRelColWidth = nWidth; }
168 sal_uInt16 GetRelColWidth() const { return nRelColWidth; }
170 bool HasLeftBorder() const { return bLeftBorder; }
173 class SwHTMLTableLayout
175 Timer m_aResizeTimer; ///< Timer for DelayedResize.
177 std::vector<std::unique_ptr<SwHTMLTableLayoutColumn>> m_aColumns;
178 std::vector<std::unique_ptr<SwHTMLTableLayoutCell>> m_aCells;
180 const SwTable *m_pSwTable; ///< SwTable (Top-Table only).
181 SwTableBox *m_pLeftFillerBox; ///< Left filler-box (table in table only).
182 SwTableBox *m_pRightFillerBox; ///< Right filler-box (table in Table only).
184 sal_uLong m_nMin; ///< Minimal width of table (Twips).
185 sal_uLong m_nMax; ///< Maximal width of table (Twips).
187 sal_uInt16 m_nRows; ///< Row count.
188 sal_uInt16 m_nCols; ///< Column count.
190 sal_uInt16 m_nLeftMargin; ///< Space to left margin (from paragraph).
191 sal_uInt16 m_nRightMargin; ///< Space to left margin (from paragraph).
193 sal_uInt16 m_nInhAbsLeftSpace; ///< Space inherited from surrounding box
194 sal_uInt16 m_nInhAbsRightSpace; ///< that was added to boxes.
196 sal_uInt16 m_nRelLeftFill; ///< Width of boxes relative to alignment
197 sal_uInt16 m_nRelRightFill; ///< of tables in tables.
199 sal_uInt16 m_nRelTabWidth; ///< Relative width of table.
201 sal_uInt16 m_nWidthOption; ///< Width of table (in Twips or %).
202 sal_uInt16 m_nCellPadding; ///< Space to contents (in Twips).
203 sal_uInt16 m_nCellSpacing; ///< Cell spacing (in Twips).
204 sal_uInt16 m_nBorder; /** Line strength of outer border, or rather the
205 space needed for it as calculated by Netscape. */
207 sal_uInt16 m_nLeftBorderWidth;
208 sal_uInt16 m_nRightBorderWidth;
209 sal_uInt16 m_nInhLeftBorderWidth;
210 sal_uInt16 m_nInhRightBorderWidth;
211 sal_uInt16 m_nBorderWidth;
213 sal_uInt16 m_nDelayedResizeAbsAvail; ///< Param for delayed Resize.
214 sal_uInt16 m_nLastResizeAbsAvail;
216 sal_uInt8 m_nPass1Done; ///< Reference-values for
217 sal_uInt8 m_nWidthSet; ///< the runs through loop.
219 SvxAdjust m_eTableAdjust; ///< Alignment of table.
221 bool m_bColsOption : 1; ///< Table has a COLS-option.
222 bool m_bColTags : 1; ///< Tabelle has COL/COLGRP-tags.
223 bool m_bPrcWidthOption : 1; ///< Width is given in percent.
224 bool m_bUseRelWidth : 1; ///< SwTable gets relative width.
226 bool m_bMustResize : 1; ///< Table width must be defined.
227 bool m_bExportable : 1; ///< Layout may be used for export.
228 bool m_bBordersChanged : 1; ///< Borders have been changed.
229 bool m_bMayBeInFlyFrame : 1; ///< Table could be within frame.
231 bool m_bDelayedResizeRecalc : 1; ///< Param for delayed Resize.
232 bool m_bMustNotResize : 1; ///< Table may not be resized.
233 bool m_bMustNotRecalc : 1; ///< Table may not be adapted to its contents.
235 void AddBorderWidth( sal_uLong &rMin, sal_uLong &rMax, sal_uLong& rAbsMin,
236 sal_uInt16 nCol, sal_uInt16 nColSpan,
237 bool bSwBorders=true ) const;
238 void SetBoxWidth( SwTableBox *pBox, sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
240 const SwStartNode *GetAnyBoxStartNode() const;
241 SwFrameFormat *FindFlyFrameFormat() const;
242 const SwDoc *GetDoc() const { return GetAnyBoxStartNode()->GetDoc(); }
244 void Resize_( sal_uInt16 nAbsAvail, bool bRecalc );
246 DECL_LINK( DelayedResize_Impl, Timer*, void );
248 static sal_uInt16 GetBrowseWidthByVisArea( const SwDoc& rDoc );
249 public:
251 SwHTMLTableLayout( const SwTable *pSwTable,
252 sal_uInt16 nRows, sal_uInt16 nCols, bool bColsOpt, bool ColTgs,
253 sal_uInt16 nWidth, bool bPrcWidth, sal_uInt16 nBorderOpt,
254 sal_uInt16 nCellPad, sal_uInt16 nCellSp, SvxAdjust eAdjust,
255 sal_uInt16 nLMargin, sal_uInt16 nRMargin, sal_uInt16 nBWidth,
256 sal_uInt16 nLeftBWidth, sal_uInt16 nRightBWidth,
257 sal_uInt16 nInhLeftBWidth, sal_uInt16 nInhRightBWidth );
259 ~SwHTMLTableLayout();
261 sal_uInt16 GetLeftCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
262 bool bSwBorders=true ) const;
263 sal_uInt16 GetRightCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
264 bool bSwBorders=true ) const;
265 inline sal_uInt16 GetInhCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
267 inline void SetInhBorderWidths( sal_uInt16 nLeft, sal_uInt16 nRight );
269 void GetAvail( sal_uInt16 nCol, sal_uInt16 nColSpan, sal_uInt16& rAbsAvail,
270 sal_uInt16& rRelAvail ) const;
272 void AutoLayoutPass1();
273 void AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAvail,
274 sal_uInt16 nAbsLeftSpace, sal_uInt16 nAbsRightSpace,
275 sal_uInt16 nParentInhSpace );
276 void SetWidths( bool bCallPass2=false, sal_uInt16 nAbsAvail=0,
277 sal_uInt16 nRelAvail=0, sal_uInt16 nAbsLeftSpace=0,
278 sal_uInt16 nAbsRightSpace=0,
279 sal_uInt16 nParentInhSpace=0 );
281 inline SwHTMLTableLayoutColumn *GetColumn( sal_uInt16 nCol ) const;
282 inline void SetColumn( std::unique_ptr<SwHTMLTableLayoutColumn> pCol, sal_uInt16 nCol );
284 inline SwHTMLTableLayoutCell *GetCell( sal_uInt16 nRow, sal_uInt16 nCol ) const;
285 inline void SetCell( std::unique_ptr<SwHTMLTableLayoutCell> pCell, sal_uInt16 nRow, sal_uInt16 nCol );
287 void SetLeftFillerBox( SwTableBox *pBox ) { m_pLeftFillerBox = pBox; }
288 void SetRightFillerBox( SwTableBox *pBox ) { m_pRightFillerBox = pBox; }
290 sal_uLong GetMin() const { return m_nMin; }
291 sal_uLong GetMax() const { return m_nMax; }
292 sal_uInt16 GetRelLeftFill() const { return m_nRelLeftFill; }
293 sal_uInt16 GetRelRightFill() const { return m_nRelRightFill; }
295 inline long GetBrowseWidthMin() const;
297 bool HasColsOption() const { return m_bColsOption; }
298 bool HasColTags() const { return m_bColTags; }
300 bool IsTopTable() const { return m_pSwTable != nullptr; }
302 void SetMustResize( bool bSet ) { m_bMustResize = bSet; }
303 void SetMustNotResize( bool bSet ) { m_bMustNotResize = bSet; }
304 void SetMustNotRecalc( bool bSet ) { m_bMustNotRecalc = bSet; }
306 /** Recalculation of table widths for available width that has been passed.
307 - If bRecalc is set, contents of boxes are included into calculation.
308 - If bForce is set, table will be recalculated even if this was
309 disallowed by SetMustNotResize.
310 - If nDelay > 0 the calculation is delayed accordingly. Resizing calls
311 occurring during delay-time are ignored, but the delay may be counted
312 under certain circumstances.
313 - If nDelay == HTMLTABLE_RESIZE_NOW, resize immediately and do not
314 consider any resize-calls that might possibly be in order.
315 - The return value indicates whether the table has been changed. */
316 bool Resize( sal_uInt16 nAbsAvail, bool bRecalc=false, bool bForce=false,
317 sal_uLong nDelay=0 );
319 void BordersChanged( sal_uInt16 nAbsAvail );
321 /** Calculate available width. This works only if a layout or a
322 SwViewShell exists. Otherwise returns 0.
323 This is needed by HTML-filter because it doesn't have access to the layout.) */
324 static sal_uInt16 GetBrowseWidth( const SwDoc& rDoc );
326 /// Calculates available width by table-frame.
327 sal_uInt16 GetBrowseWidthByTabFrame( const SwTabFrame& rTabFrame ) const;
329 /** Calculates available width by the table-frame or
330 static GetBrowseWidth if no layout exists. */
331 sal_uInt16 GetBrowseWidthByTable( const SwDoc& rDoc ) const;
333 /// For Export.
334 sal_uInt16 GetWidthOption() const { return m_nWidthOption; }
335 bool HasPrcWidthOption() const { return m_bPrcWidthOption; }
337 sal_uInt16 GetCellPadding() const { return m_nCellPadding; }
338 sal_uInt16 GetCellSpacing() const { return m_nCellSpacing; }
339 sal_uInt16 GetBorder() const { return m_nBorder; }
341 sal_uInt16 GetRowCount() const { return m_nRows; }
342 sal_uInt16 GetColCount() const { return m_nCols; }
344 void SetExportable( bool bSet ) { m_bExportable = bSet; }
345 bool IsExportable() const { return m_bExportable; }
347 bool HaveBordersChanged() const { return m_bBordersChanged; }
349 void SetMayBeInFlyFrame( bool bSet ) { m_bMayBeInFlyFrame = bSet; }
350 bool MayBeInFlyFrame() const { return m_bMayBeInFlyFrame; }
353 inline void SwHTMLTableLayoutCell::SetProtected()
355 nRowSpan = 1;
356 nColSpan = 1;
358 pContents = nullptr;
361 inline void SwHTMLTableLayoutColumn::MergeMinMaxNoAlign( sal_uLong nCMin,
362 sal_uLong nCMax, sal_uLong nAbsMin )
364 if( nCMin > nMinNoAlign )
365 nMinNoAlign = nCMin;
366 if( nCMax > nMaxNoAlign )
367 nMaxNoAlign = nCMax;
368 if( nAbsMin > nAbsMinNoAlign )
369 nAbsMinNoAlign = nAbsMin;
372 inline void SwHTMLTableLayoutColumn::ClearPass1Info( bool bWidthOpt )
374 nMinNoAlign = nMaxNoAlign = nAbsMinNoAlign = MINLAY;
375 nMin = nMax = 0;
376 if( bWidthOpt )
378 nWidthOption = 0;
379 bRelWidthOption = false;
383 inline void SwHTMLTableLayoutColumn::MergeCellWidthOption(
384 sal_uInt16 nWidth, bool bRel )
386 if( !nWidthOption ||
387 (bRel==bRelWidthOption && nWidthOption < nWidth) )
389 nWidthOption = nWidth;
390 bRelWidthOption = bRel;
394 inline void SwHTMLTableLayoutColumn::SetMinMax( sal_uLong nMn, sal_uLong nMx )
396 nMin = nMn;
397 nMax = nMx;
400 inline sal_uInt16 SwHTMLTableLayout::GetInhCellSpace( sal_uInt16 nCol,
401 sal_uInt16 nColSpan ) const
403 sal_uInt16 nSpace = 0;
404 if( nCol==0 )
405 nSpace = nSpace + m_nInhAbsLeftSpace;
406 if( nCol+nColSpan==m_nCols )
407 nSpace = nSpace + m_nInhAbsRightSpace;
409 return nSpace;
412 inline SwHTMLTableLayoutColumn *SwHTMLTableLayout::GetColumn( sal_uInt16 nCol ) const
414 return m_aColumns[nCol].get();
417 inline void SwHTMLTableLayoutColumn::SetWidthOption( sal_uInt16 nWidth )
419 nWidthOption = nWidth;
420 bRelWidthOption = true;
423 inline void SwHTMLTableLayout::SetColumn( std::unique_ptr<SwHTMLTableLayoutColumn> pCol, sal_uInt16 nCol )
425 m_aColumns[nCol] = std::move(pCol);
428 inline SwHTMLTableLayoutCell *SwHTMLTableLayout::GetCell( sal_uInt16 nRow, sal_uInt16 nCol ) const
430 return m_aCells[static_cast<size_t>(nRow)*m_nCols+nCol].get();
433 inline void SwHTMLTableLayout::SetCell( std::unique_ptr<SwHTMLTableLayoutCell> pCell,
434 sal_uInt16 nRow, sal_uInt16 nCol )
436 m_aCells[static_cast<size_t>(nRow)*m_nCols+nCol] = std::move(pCell);
439 inline long SwHTMLTableLayout::GetBrowseWidthMin() const
441 return (long)( (!m_nWidthOption || m_bPrcWidthOption) ? m_nMin : m_nRelTabWidth );
444 void SwHTMLTableLayout::SetInhBorderWidths( sal_uInt16 nLeft, sal_uInt16 nRight )
446 m_nInhLeftBorderWidth = nLeft;
447 m_nInhRightBorderWidth = nRight;
450 #endif
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */