bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / htmltbl.hxx
blobfe855242f0cfcc7ff0372ac04d6d17744cd5a212
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 _HTMLTBL_HXX
21 #define _HTMLTBL_HXX
24 #include <vcl/timer.hxx>
25 #include <editeng/svxenum.hxx>
27 #include "swtypes.hxx"
28 #include "node.hxx" ///< For SwStartNode
31 class SwTableBox;
32 class SwTable;
33 class SwHTMLTableLayout;
34 class SwDoc;
35 class SwFrmFmt;
37 #define HTMLTABLE_RESIZE_NOW (ULONG_MAX)
39 class SwHTMLTableLayoutCnts
41 SwHTMLTableLayoutCnts *pNext; ///< The next content.
43 /// Only one of the following two pointers may be set!
44 SwTableBox *pBox; ///< A Box.
45 SwHTMLTableLayout *pTable; ///< A "table within a table".
47 /** During first run there are still no boxes. In this case
48 pStartNode is used instead of pBox. */
49 const SwStartNode *pStartNode;
51 /** The following counters indicate how often a pass has been
52 done for this content. Therefore they are compared against
53 a reference value. If 255 is reached the continue with 0.
54 This avoids reinitialization on every resize. */
55 sal_uInt8 nPass1Done; ///< How many times has Pass 1 been called?
56 sal_uInt8 nWidthSet; ///< How many times has the width been set?
58 bool bNoBreakTag; ///< <NOBR>-Tag over complete content.
60 public:
62 SwHTMLTableLayoutCnts( const SwStartNode* pSttNd, SwHTMLTableLayout* pTab,
63 bool bNoBreakTag, SwHTMLTableLayoutCnts* pNxt );
65 ~SwHTMLTableLayoutCnts();
67 void SetTableBox( SwTableBox *pBx ) { pBox = pBx; }
68 SwTableBox *GetTableBox() const { return pBox; }
70 SwHTMLTableLayout *GetTable() const { return pTable; }
72 const SwStartNode *GetStartNode() const;
74 /// Calculation of next node.
75 SwHTMLTableLayoutCnts *GetNext() const { return pNext; }
77 void SetWidthSet( sal_uInt8 nRef ) { nWidthSet = nRef; }
78 sal_Bool IsWidthSet( sal_uInt8 nRef ) const { return nRef==nWidthSet; }
80 void SetPass1Done( sal_uInt8 nRef ) { nPass1Done = nRef; }
81 sal_Bool IsPass1Done( sal_uInt8 nRef ) const { return nRef==nPass1Done; }
83 bool HasNoBreakTag() const { return bNoBreakTag; }
86 class SwHTMLTableLayoutCell
88 SwHTMLTableLayoutCnts *pContents; ///< Content of cell.
90 sal_uInt16 nRowSpan; ///< ROWSPAN of cell.
91 sal_uInt16 nColSpan; ///< COLSPAN of cell.
92 sal_uInt16 nWidthOption; ///< Given width of cell in Twip or %.
94 bool bPrcWidthOption : 1; ///< nWidth is %-value.
95 bool bNoWrapOption : 1; ///< NOWRAP-option.
97 public:
99 SwHTMLTableLayoutCell( SwHTMLTableLayoutCnts *pCnts,
100 sal_uInt16 nRSpan, sal_uInt16 nCSpan,
101 sal_uInt16 nWidthOpt, bool bPrcWdthOpt,
102 bool nNWrapOpt );
104 ~SwHTMLTableLayoutCell();
106 /// Set or get content of a cell.
107 void SetContents( SwHTMLTableLayoutCnts *pCnts ) { pContents = pCnts; }
108 SwHTMLTableLayoutCnts *GetContents() const { return pContents; }
110 inline void SetProtected();
112 /// Set or get ROWSPAN/COLSPAN of cell.
113 void SetRowSpan( sal_uInt16 nRSpan ) { nRowSpan = nRSpan; }
114 sal_uInt16 GetRowSpan() const { return nRowSpan; }
115 sal_uInt16 GetColSpan() const { return nColSpan; }
117 sal_uInt16 GetWidthOption() const { return nWidthOption; }
118 bool IsPrcWidthOption() const { return bPrcWidthOption; }
120 bool HasNoWrapOption() const { return bNoWrapOption; }
123 class SwHTMLTableLayoutColumn
126 /// Interim values of AutoLayoutPass1,
127 sal_uLong nMinNoAlign, nMaxNoAlign, nAbsMinNoAlign;
129 /// Results of AutoLayoutPass1
130 sal_uLong nMin, nMax;
132 /// Results of Pass 2.
133 sal_uInt16 nAbsColWidth; ///< In Twips.
134 sal_uInt16 nRelColWidth; ///< In Twips or relative to USHRT_MAX.
136 sal_uInt16 nWidthOption; ///< Options of <COL> or <TD>/<TH>.
138 bool bRelWidthOption : 1;
139 bool bLeftBorder : 1;
141 public:
143 SwHTMLTableLayoutColumn( sal_uInt16 nColWidthOpt, bool bRelColWidthOpt,
144 bool bLBorder );
146 ~SwHTMLTableLayoutColumn() {}
148 inline void MergeCellWidthOption( sal_uInt16 nWidth, bool bPrc );
149 inline void SetWidthOption( sal_uInt16 nWidth, bool bRelWidth, bool bTest );
151 sal_uInt16 GetWidthOption() const { return nWidthOption; }
152 bool IsRelWidthOption() const { return bRelWidthOption; }
154 inline void MergeMinMaxNoAlign( sal_uLong nMin, sal_uLong nMax, sal_uLong nAbsMin );
155 sal_uLong GetMinNoAlign() const { return nMinNoAlign; }
156 sal_uLong GetMaxNoAlign() const { return nMaxNoAlign; }
157 sal_uLong GetAbsMinNoAlign() const { return nAbsMinNoAlign; }
158 inline void ClearPass1Info( bool bWidthOpt );
160 inline void SetMinMax( sal_uLong nMin, sal_uLong nMax );
161 void SetMax( sal_uLong nVal ) { nMax = nVal; }
162 void AddToMin( sal_uLong nVal ) { nMin += nVal; }
163 void AddToMax( sal_uLong nVal ) { nMax += nVal; }
164 sal_uLong GetMin() const { return nMin; }
165 sal_uLong GetMax() const { return nMax; }
167 void SetAbsColWidth( sal_uInt16 nWidth ) { nAbsColWidth = nWidth; }
168 sal_uInt16 GetAbsColWidth() const { return nAbsColWidth; }
170 void SetRelColWidth( sal_uInt16 nWidth ) { nRelColWidth = nWidth; }
171 sal_uInt16 GetRelColWidth() const { return nRelColWidth; }
173 bool HasLeftBorder() const { return bLeftBorder; }
176 class SwHTMLTableLayout
178 Timer aResizeTimer; ///< Timer for DelayedResize.
180 SwHTMLTableLayoutColumn **aColumns;
181 SwHTMLTableLayoutCell **aCells;
183 const SwTable *pSwTable; ///< SwTable (Top-Table only).
184 SwTableBox *pLeftFillerBox; ///< Left filler-box (table in table only).
185 SwTableBox *pRightFillerBox; ///< Right filler-box (table in Table only).
187 sal_uLong nMin; ///< Minimal width of table (Twips).
188 sal_uLong nMax; ///< Maximal width of table (Twips).
190 sal_uInt16 nRows; ///< Row count.
191 sal_uInt16 nCols; ///< Column count.
193 sal_uInt16 nLeftMargin; ///< Space to left margin (from paragraph).
194 sal_uInt16 nRightMargin; ///< Space to left margin (from paragraph).
196 sal_uInt16 nInhAbsLeftSpace; ///< Space inherited from surrounding box
197 sal_uInt16 nInhAbsRightSpace; ///< that was added to boxes.
199 sal_uInt16 nRelLeftFill; ///< Width of boxes relative to alignment
200 sal_uInt16 nRelRightFill; ///< of tables in tables.
202 sal_uInt16 nRelTabWidth; ///< Relative width of table.
204 sal_uInt16 nWidthOption; ///< Width of table (in Twips oder %).
205 sal_uInt16 nCellPadding; ///< Space to contents (in Twips).
206 sal_uInt16 nCellSpacing; ///< Cell spacing (in Twips).
207 sal_uInt16 nBorder; /** Line strength of outer border, or rather the
208 space needed for it as calculated by Netscape. */
210 sal_uInt16 nLeftBorderWidth;
211 sal_uInt16 nRightBorderWidth;
212 sal_uInt16 nInhLeftBorderWidth;
213 sal_uInt16 nInhRightBorderWidth;
214 sal_uInt16 nBorderWidth;
216 sal_uInt16 nDelayedResizeAbsAvail; ///< Param for delayed Resize.
217 sal_uInt16 nLastResizeAbsAvail;
219 sal_uInt8 nPass1Done; ///< Reference-values for
220 sal_uInt8 nWidthSet; ///< the runs through loop.
222 SvxAdjust eTableAdjust; ///< Alignment of table.
224 bool bColsOption : 1; ///< Table has a COLS-option.
225 bool bColTags : 1; ///< Tabelle has COL/COLGRP-tags.
226 bool bPrcWidthOption : 1; ///< Width is given in percent.
227 bool bUseRelWidth : 1; ///< SwTable gets relative width.
229 sal_Bool bMustResize : 1; ///< Table width must be defined.
230 sal_Bool bExportable : 1; ///< Layout may be used for export.
231 sal_Bool bBordersChanged : 1; ///< Borders have been changed.
232 sal_Bool bMayBeInFlyFrame : 1; ///< Table could be within frame.
234 sal_Bool bDelayedResizeRecalc : 1; ///< Param for delayed Resize.
235 sal_Bool bMustNotResize : 1; ///< Table may not be resized.
236 sal_Bool bMustNotRecalc : 1; ///< Table may not be adapted to its contents.
238 void AddBorderWidth( sal_uLong &rMin, sal_uLong &rMax, sal_uLong& rAbsMin,
239 sal_uInt16 nCol, sal_uInt16 nColSpan,
240 sal_Bool bSwBorders=sal_True ) const;
241 void SetBoxWidth( SwTableBox *pBox, sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
243 const SwStartNode *GetAnyBoxStartNode() const;
244 SwFrmFmt *FindFlyFrmFmt() const;
245 const SwDoc *GetDoc() const { return GetAnyBoxStartNode()->GetDoc(); }
247 void ClearPass1Info() { nMin = nMax = 0; }
249 void _Resize( sal_uInt16 nAbsAvail, sal_Bool bRecalc=sal_False );
251 DECL_STATIC_LINK( SwHTMLTableLayout, DelayedResize_Impl, void* );
253 static sal_uInt16 GetBrowseWidthByVisArea( const SwDoc& rDoc );
254 public:
256 SwHTMLTableLayout( const SwTable *pSwTbl,
257 sal_uInt16 nRows, sal_uInt16 nCols, bool bColsOpt, bool ColTgs,
258 sal_uInt16 nWidth, bool bPrcWidth, sal_uInt16 nBorderOpt,
259 sal_uInt16 nCellPad, sal_uInt16 nCellSp, SvxAdjust eAdjust,
260 sal_uInt16 nLMargin, sal_uInt16 nRMargin, sal_uInt16 nBWidth,
261 sal_uInt16 nLeftBWidth, sal_uInt16 nRightBWidth,
262 sal_uInt16 nInhLeftBWidth, sal_uInt16 nInhRightBWidth );
264 ~SwHTMLTableLayout();
266 sal_uInt16 GetLeftCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
267 sal_Bool bSwBorders=sal_True ) const;
268 sal_uInt16 GetRightCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
269 sal_Bool bSwBorders=sal_True ) const;
270 inline sal_uInt16 GetInhCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
272 inline void SetInhBorderWidths( sal_uInt16 nLeft, sal_uInt16 nRight );
275 void GetAvail( sal_uInt16 nCol, sal_uInt16 nColSpan, sal_uInt16& rAbsAvail,
276 sal_uInt16& rRelAvail ) const;
278 void AutoLayoutPass1();
279 void AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAvail,
280 sal_uInt16 nAbsLeftSpace, sal_uInt16 nAbsRightSpace,
281 sal_uInt16 nParentInhSpace );
282 void SetWidths( sal_Bool bCallPass2=sal_False, sal_uInt16 nAbsAvail=0,
283 sal_uInt16 nRelAvail=0, sal_uInt16 nAbsLeftSpace=0,
284 sal_uInt16 nAbsRightSpace=0,
285 sal_uInt16 nParentInhSpace=0 );
287 inline SwHTMLTableLayoutColumn *GetColumn( sal_uInt16 nCol ) const;
288 inline void SetColumn( SwHTMLTableLayoutColumn *pCol, sal_uInt16 nCol );
290 inline SwHTMLTableLayoutCell *GetCell( sal_uInt16 nRow, sal_uInt16 nCol ) const;
291 inline void SetCell( SwHTMLTableLayoutCell *pCell, sal_uInt16 nRow, sal_uInt16 nCol );
293 void SetLeftFillerBox( SwTableBox *pBox ) { pLeftFillerBox = pBox; }
294 void SetRightFillerBox( SwTableBox *pBox ) { pRightFillerBox = pBox; }
296 sal_uLong GetMin() const { return nMin; }
297 sal_uLong GetMax() const { return nMax; }
298 sal_uInt16 GetRelLeftFill() const { return nRelLeftFill; }
299 sal_uInt16 GetRelRightFill() const { return nRelRightFill; }
301 inline long GetBrowseWidthMin() const;
303 bool HasColsOption() const { return bColsOption; }
304 bool HasColTags() const { return bColTags; }
306 sal_Bool IsTopTable() const { return pSwTable != 0; }
308 void SetMustResize( sal_Bool bSet ) { bMustResize = bSet; }
309 void SetMustNotResize( sal_Bool bSet ) { bMustNotResize = bSet; }
310 void SetMustNotRecalc( sal_Bool bSet ) { bMustNotRecalc = bSet; }
312 /** Recalculation of table widths for available width that has been passed.
313 - If bRecalc is set, contents of boxes are included into calculation.
314 - If bForce is set, table will be recalculated even if this was
315 disallowed by SetMustNotResize.
316 - If nDelay > 0 the calculation is delayed accordingly. Resizing calls
317 occuring during delay-time are ignored, but the delay may be counted
318 under certain circumstances.
319 - If nDelay == HTMLTABLE_RESIZE_NOW, resize immediately and do not
320 consider any resize-calls that might possibly be in order.
321 - The return value indicates whether the table has been changed. */
322 sal_Bool Resize( sal_uInt16 nAbsAvail, sal_Bool bRecalc=sal_False, sal_Bool bForce=sal_False,
323 sal_uLong nDelay=0 );
325 void BordersChanged( sal_uInt16 nAbsAvail, sal_Bool bRecalc=sal_False );
327 /** Calculate available width. This works only if a layout or a
328 ViewShell exists. Otherwise returns 0.
329 This is needed by HTML-filter because it doesn't have access to the layout.) */
330 static sal_uInt16 GetBrowseWidth( const SwDoc& rDoc );
332 /// Calculates available width by table-frame.
333 sal_uInt16 GetBrowseWidthByTabFrm( const SwTabFrm& rTabFrm ) const;
335 /** Calculates available width by the table-frame or
336 static GetBrowseWidth if no layout exists. */
337 sal_uInt16 GetBrowseWidthByTable( const SwDoc& rDoc ) const;
339 /// For Export.
340 sal_uInt16 GetWidthOption() const { return nWidthOption; }
341 bool HasPrcWidthOption() const { return bPrcWidthOption; }
343 sal_uInt16 GetCellPadding() const { return nCellPadding; }
344 sal_uInt16 GetCellSpacing() const { return nCellSpacing; }
345 sal_uInt16 GetBorder() const { return nBorder; }
347 sal_uInt16 GetRowCount() const { return nRows; }
348 sal_uInt16 GetColCount() const { return nCols; }
350 void SetExportable( sal_Bool bSet ) { bExportable = bSet; }
351 sal_Bool IsExportable() const { return bExportable; }
353 sal_Bool HaveBordersChanged() const { return bBordersChanged; }
355 void SetMayBeInFlyFrame( sal_Bool bSet ) { bMayBeInFlyFrame = bSet; }
356 sal_Bool MayBeInFlyFrame() const { return bMayBeInFlyFrame; }
359 inline void SwHTMLTableLayoutCell::SetProtected()
361 nRowSpan = 1;
362 nColSpan = 1;
364 pContents = 0;
367 inline void SwHTMLTableLayoutColumn::MergeMinMaxNoAlign( sal_uLong nCMin,
368 sal_uLong nCMax, sal_uLong nAbsMin )
370 if( nCMin > nMinNoAlign )
371 nMinNoAlign = nCMin;
372 if( nCMax > nMaxNoAlign )
373 nMaxNoAlign = nCMax;
374 if( nAbsMin > nAbsMinNoAlign )
375 nAbsMinNoAlign = nAbsMin;
378 inline void SwHTMLTableLayoutColumn::ClearPass1Info( bool bWidthOpt )
380 nMinNoAlign = nMaxNoAlign = nAbsMinNoAlign = MINLAY;
381 nMin = nMax = 0;
382 if( bWidthOpt )
384 nWidthOption = 0;
385 bRelWidthOption = false;
389 inline void SwHTMLTableLayoutColumn::MergeCellWidthOption(
390 sal_uInt16 nWidth, bool bRel )
392 if( !nWidthOption ||
393 (bRel==bRelWidthOption && nWidthOption < nWidth) )
395 nWidthOption = nWidth;
396 bRelWidthOption = bRel;
400 inline void SwHTMLTableLayoutColumn::SetMinMax( sal_uLong nMn, sal_uLong nMx )
402 nMin = nMn;
403 nMax = nMx;
406 inline sal_uInt16 SwHTMLTableLayout::GetInhCellSpace( sal_uInt16 nCol,
407 sal_uInt16 nColSpan ) const
409 sal_uInt16 nSpace = 0;
410 if( nCol==0 )
411 nSpace = nSpace + sal::static_int_cast< sal_uInt16 >(nInhAbsLeftSpace);
412 if( nCol+nColSpan==nCols )
413 nSpace = nSpace + sal::static_int_cast< sal_uInt16 >(nInhAbsRightSpace);
415 return nSpace;
418 inline SwHTMLTableLayoutColumn *SwHTMLTableLayout::GetColumn( sal_uInt16 nCol ) const
420 return aColumns[nCol];
423 inline void SwHTMLTableLayoutColumn::SetWidthOption(
424 sal_uInt16 nWidth, bool bRelWidth, bool bTest )
426 if( bTest && bRelWidthOption==bRelWidth )
428 if( nWidth > nWidthOption )
429 nWidthOption = nWidth;
431 else
432 nWidthOption = nWidth;
433 bRelWidthOption = bRelWidth;
436 inline void SwHTMLTableLayout::SetColumn( SwHTMLTableLayoutColumn *pCol, sal_uInt16 nCol )
438 aColumns[nCol] = pCol;
441 inline SwHTMLTableLayoutCell *SwHTMLTableLayout::GetCell( sal_uInt16 nRow, sal_uInt16 nCol ) const
443 return aCells[nRow*nCols+nCol];
446 inline void SwHTMLTableLayout::SetCell( SwHTMLTableLayoutCell *pCell,
447 sal_uInt16 nRow, sal_uInt16 nCol )
449 aCells[nRow*nCols+nCol] = pCell;
452 inline long SwHTMLTableLayout::GetBrowseWidthMin() const
454 return (long)( (!nWidthOption || bPrcWidthOption) ? nMin : nRelTabWidth );
457 void SwHTMLTableLayout::SetInhBorderWidths( sal_uInt16 nLeft, sal_uInt16 nRight )
459 nInhLeftBorderWidth = nLeft;
460 nInhRightBorderWidth = nRight;
464 #endif
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */