1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/timer.hxx>
24 #include <editeng/svxenum.hxx>
26 #include "swtypes.hxx"
31 class SwHTMLTableLayout
;
35 #define HTMLTABLE_RESIZE_NOW (ULONG_MAX)
37 class SwHTMLTableLayoutCnts
39 SwHTMLTableLayoutCnts
*pNext
; ///< The next content.
41 /// Only one of the following two pointers may be set!
42 SwTableBox
*pBox
; ///< A Box.
43 SwHTMLTableLayout
*pTable
; ///< A "table within a table".
45 /** During first run there are still no boxes. In this case
46 pStartNode is used instead of pBox. */
47 const SwStartNode
*pStartNode
;
49 /** The following counters indicate how often a pass has been
50 done for this content. Therefore they are compared against
51 a reference value. If 255 is reached the continue with 0.
52 This avoids reinitialization on every resize. */
53 sal_uInt8 nPass1Done
; ///< How many times has Pass 1 been called?
54 sal_uInt8 nWidthSet
; ///< How many times has the width been set?
56 bool bNoBreakTag
; ///< <NOBR>-Tag over complete content.
60 SwHTMLTableLayoutCnts( const SwStartNode
* pSttNd
, SwHTMLTableLayout
* pTab
,
61 bool bNoBreakTag
, SwHTMLTableLayoutCnts
* pNxt
);
63 ~SwHTMLTableLayoutCnts();
65 void SetTableBox( SwTableBox
*pBx
) { pBox
= pBx
; }
66 SwTableBox
*GetTableBox() const { return pBox
; }
68 SwHTMLTableLayout
*GetTable() const { return pTable
; }
70 const SwStartNode
*GetStartNode() const;
72 /// Calculation of next node.
73 SwHTMLTableLayoutCnts
*GetNext() const { return pNext
; }
75 void SetWidthSet( sal_uInt8 nRef
) { nWidthSet
= nRef
; }
76 bool IsWidthSet( sal_uInt8 nRef
) const { return nRef
==nWidthSet
; }
78 void SetPass1Done( sal_uInt8 nRef
) { nPass1Done
= nRef
; }
79 bool IsPass1Done( sal_uInt8 nRef
) const { return nRef
==nPass1Done
; }
81 bool HasNoBreakTag() const { return bNoBreakTag
; }
84 class SwHTMLTableLayoutCell
86 SwHTMLTableLayoutCnts
*pContents
; ///< Content of cell.
88 sal_uInt16 nRowSpan
; ///< ROWSPAN of cell.
89 sal_uInt16 nColSpan
; ///< COLSPAN of cell.
90 sal_uInt16 nWidthOption
; ///< Given width of cell in Twip or %.
92 bool bPrcWidthOption
: 1; ///< nWidth is %-value.
93 bool bNoWrapOption
: 1; ///< NOWRAP-option.
97 SwHTMLTableLayoutCell( SwHTMLTableLayoutCnts
*pCnts
,
98 sal_uInt16 nRSpan
, sal_uInt16 nCSpan
,
99 sal_uInt16 nWidthOpt
, bool bPrcWdthOpt
,
102 ~SwHTMLTableLayoutCell();
104 /// Set or get content of a cell.
105 void SetContents( SwHTMLTableLayoutCnts
*pCnts
) { pContents
= pCnts
; }
106 SwHTMLTableLayoutCnts
*GetContents() const { return pContents
; }
108 inline void SetProtected();
110 /// Set or get ROWSPAN/COLSPAN of cell.
111 void SetRowSpan( sal_uInt16 nRSpan
) { nRowSpan
= nRSpan
; }
112 sal_uInt16
GetRowSpan() const { return nRowSpan
; }
113 sal_uInt16
GetColSpan() const { return nColSpan
; }
115 sal_uInt16
GetWidthOption() const { return nWidthOption
; }
116 bool IsPrcWidthOption() const { return bPrcWidthOption
; }
118 bool HasNoWrapOption() const { return bNoWrapOption
; }
121 class SwHTMLTableLayoutColumn
124 /// Interim values of AutoLayoutPass1,
125 sal_uLong nMinNoAlign
, nMaxNoAlign
, nAbsMinNoAlign
;
127 /// Results of AutoLayoutPass1
128 sal_uLong nMin
, nMax
;
130 /// Results of Pass 2.
131 sal_uInt16 nAbsColWidth
; ///< In Twips.
132 sal_uInt16 nRelColWidth
; ///< In Twips or relative to USHRT_MAX.
134 sal_uInt16 nWidthOption
; ///< Options of <COL> or <TD>/<TH>.
136 bool bRelWidthOption
: 1;
137 bool bLeftBorder
: 1;
141 SwHTMLTableLayoutColumn( sal_uInt16 nColWidthOpt
, bool bRelColWidthOpt
,
144 ~SwHTMLTableLayoutColumn() {}
146 inline void MergeCellWidthOption( sal_uInt16 nWidth
, bool bPrc
);
147 inline void SetWidthOption( sal_uInt16 nWidth
, bool bRelWidth
, bool bTest
);
149 sal_uInt16
GetWidthOption() const { return nWidthOption
; }
150 bool IsRelWidthOption() const { return bRelWidthOption
; }
152 inline void MergeMinMaxNoAlign( sal_uLong nMin
, sal_uLong nMax
, sal_uLong nAbsMin
);
153 sal_uLong
GetMinNoAlign() const { return nMinNoAlign
; }
154 sal_uLong
GetMaxNoAlign() const { return nMaxNoAlign
; }
155 sal_uLong
GetAbsMinNoAlign() const { return nAbsMinNoAlign
; }
156 inline void ClearPass1Info( bool bWidthOpt
);
158 inline void SetMinMax( sal_uLong nMin
, sal_uLong nMax
);
159 void SetMax( sal_uLong nVal
) { nMax
= nVal
; }
160 void AddToMin( sal_uLong nVal
) { nMin
+= nVal
; }
161 void AddToMax( sal_uLong nVal
) { nMax
+= nVal
; }
162 sal_uLong
GetMin() const { return nMin
; }
163 sal_uLong
GetMax() const { return nMax
; }
165 void SetAbsColWidth( sal_uInt16 nWidth
) { nAbsColWidth
= nWidth
; }
166 sal_uInt16
GetAbsColWidth() const { return nAbsColWidth
; }
168 void SetRelColWidth( sal_uInt16 nWidth
) { nRelColWidth
= nWidth
; }
169 sal_uInt16
GetRelColWidth() const { return nRelColWidth
; }
171 bool HasLeftBorder() const { return bLeftBorder
; }
174 class SwHTMLTableLayout
176 Timer aResizeTimer
; ///< Timer for DelayedResize.
178 SwHTMLTableLayoutColumn
**aColumns
;
179 SwHTMLTableLayoutCell
**aCells
;
181 const SwTable
*pSwTable
; ///< SwTable (Top-Table only).
182 SwTableBox
*pLeftFillerBox
; ///< Left filler-box (table in table only).
183 SwTableBox
*pRightFillerBox
; ///< Right filler-box (table in Table only).
185 sal_uLong nMin
; ///< Minimal width of table (Twips).
186 sal_uLong nMax
; ///< Maximal width of table (Twips).
188 sal_uInt16 nRows
; ///< Row count.
189 sal_uInt16 nCols
; ///< Column count.
191 sal_uInt16 nLeftMargin
; ///< Space to left margin (from paragraph).
192 sal_uInt16 nRightMargin
; ///< Space to left margin (from paragraph).
194 sal_uInt16 nInhAbsLeftSpace
; ///< Space inherited from surrounding box
195 sal_uInt16 nInhAbsRightSpace
; ///< that was added to boxes.
197 sal_uInt16 nRelLeftFill
; ///< Width of boxes relative to alignment
198 sal_uInt16 nRelRightFill
; ///< of tables in tables.
200 sal_uInt16 nRelTabWidth
; ///< Relative width of table.
202 sal_uInt16 nWidthOption
; ///< Width of table (in Twips oder %).
203 sal_uInt16 nCellPadding
; ///< Space to contents (in Twips).
204 sal_uInt16 nCellSpacing
; ///< Cell spacing (in Twips).
205 sal_uInt16 nBorder
; /** Line strength of outer border, or rather the
206 space needed for it as calculated by Netscape. */
208 sal_uInt16 nLeftBorderWidth
;
209 sal_uInt16 nRightBorderWidth
;
210 sal_uInt16 nInhLeftBorderWidth
;
211 sal_uInt16 nInhRightBorderWidth
;
212 sal_uInt16 nBorderWidth
;
214 sal_uInt16 nDelayedResizeAbsAvail
; ///< Param for delayed Resize.
215 sal_uInt16 nLastResizeAbsAvail
;
217 sal_uInt8 nPass1Done
; ///< Reference-values for
218 sal_uInt8 nWidthSet
; ///< the runs through loop.
220 SvxAdjust eTableAdjust
; ///< Alignment of table.
222 bool bColsOption
: 1; ///< Table has a COLS-option.
223 bool bColTags
: 1; ///< Tabelle has COL/COLGRP-tags.
224 bool bPrcWidthOption
: 1; ///< Width is given in percent.
225 bool bUseRelWidth
: 1; ///< SwTable gets relative width.
227 bool bMustResize
: 1; ///< Table width must be defined.
228 bool bExportable
: 1; ///< Layout may be used for export.
229 bool bBordersChanged
: 1; ///< Borders have been changed.
230 bool bMayBeInFlyFrame
: 1; ///< Table could be within frame.
232 bool bDelayedResizeRecalc
: 1; ///< Param for delayed Resize.
233 bool bMustNotResize
: 1; ///< Table may not be resized.
234 bool bMustNotRecalc
: 1; ///< Table may not be adapted to its contents.
236 void AddBorderWidth( sal_uLong
&rMin
, sal_uLong
&rMax
, sal_uLong
& rAbsMin
,
237 sal_uInt16 nCol
, sal_uInt16 nColSpan
,
238 bool bSwBorders
=true ) const;
239 void SetBoxWidth( SwTableBox
*pBox
, sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
241 const SwStartNode
*GetAnyBoxStartNode() const;
242 SwFrameFormat
*FindFlyFrameFormat() const;
243 const SwDoc
*GetDoc() const { return GetAnyBoxStartNode()->GetDoc(); }
245 void ClearPass1Info() { nMin
= nMax
= 0; }
247 void _Resize( sal_uInt16 nAbsAvail
, bool bRecalc
=false );
249 DECL_LINK_TYPED( DelayedResize_Impl
, Timer
*, void );
251 static sal_uInt16
GetBrowseWidthByVisArea( const SwDoc
& rDoc
);
254 SwHTMLTableLayout( const SwTable
*pSwTable
,
255 sal_uInt16 nRows
, sal_uInt16 nCols
, bool bColsOpt
, bool ColTgs
,
256 sal_uInt16 nWidth
, bool bPrcWidth
, sal_uInt16 nBorderOpt
,
257 sal_uInt16 nCellPad
, sal_uInt16 nCellSp
, SvxAdjust eAdjust
,
258 sal_uInt16 nLMargin
, sal_uInt16 nRMargin
, sal_uInt16 nBWidth
,
259 sal_uInt16 nLeftBWidth
, sal_uInt16 nRightBWidth
,
260 sal_uInt16 nInhLeftBWidth
, sal_uInt16 nInhRightBWidth
);
262 ~SwHTMLTableLayout();
264 sal_uInt16
GetLeftCellSpace( sal_uInt16 nCol
, sal_uInt16 nColSpan
,
265 bool bSwBorders
=true ) const;
266 sal_uInt16
GetRightCellSpace( sal_uInt16 nCol
, sal_uInt16 nColSpan
,
267 bool bSwBorders
=true ) const;
268 inline sal_uInt16
GetInhCellSpace( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
270 inline void SetInhBorderWidths( sal_uInt16 nLeft
, sal_uInt16 nRight
);
272 void GetAvail( sal_uInt16 nCol
, sal_uInt16 nColSpan
, sal_uInt16
& rAbsAvail
,
273 sal_uInt16
& rRelAvail
) const;
275 void AutoLayoutPass1();
276 void AutoLayoutPass2( sal_uInt16 nAbsAvail
, sal_uInt16 nRelAvail
,
277 sal_uInt16 nAbsLeftSpace
, sal_uInt16 nAbsRightSpace
,
278 sal_uInt16 nParentInhSpace
);
279 void SetWidths( bool bCallPass2
=false, sal_uInt16 nAbsAvail
=0,
280 sal_uInt16 nRelAvail
=0, sal_uInt16 nAbsLeftSpace
=0,
281 sal_uInt16 nAbsRightSpace
=0,
282 sal_uInt16 nParentInhSpace
=0 );
284 inline SwHTMLTableLayoutColumn
*GetColumn( sal_uInt16 nCol
) const;
285 inline void SetColumn( SwHTMLTableLayoutColumn
*pCol
, sal_uInt16 nCol
);
287 inline SwHTMLTableLayoutCell
*GetCell( sal_uInt16 nRow
, sal_uInt16 nCol
) const;
288 inline void SetCell( SwHTMLTableLayoutCell
*pCell
, sal_uInt16 nRow
, sal_uInt16 nCol
);
290 void SetLeftFillerBox( SwTableBox
*pBox
) { pLeftFillerBox
= pBox
; }
291 void SetRightFillerBox( SwTableBox
*pBox
) { pRightFillerBox
= pBox
; }
293 sal_uLong
GetMin() const { return nMin
; }
294 sal_uLong
GetMax() const { return nMax
; }
295 sal_uInt16
GetRelLeftFill() const { return nRelLeftFill
; }
296 sal_uInt16
GetRelRightFill() const { return nRelRightFill
; }
298 inline long GetBrowseWidthMin() const;
300 bool HasColsOption() const { return bColsOption
; }
301 bool HasColTags() const { return bColTags
; }
303 bool IsTopTable() const { return pSwTable
!= 0; }
305 void SetMustResize( bool bSet
) { bMustResize
= bSet
; }
306 void SetMustNotResize( bool bSet
) { bMustNotResize
= bSet
; }
307 void SetMustNotRecalc( bool bSet
) { bMustNotRecalc
= bSet
; }
309 /** Recalculation of table widths for available width that has been passed.
310 - If bRecalc is set, contents of boxes are included into calculation.
311 - If bForce is set, table will be recalculated even if this was
312 disallowed by SetMustNotResize.
313 - If nDelay > 0 the calculation is delayed accordingly. Resizing calls
314 occurring during delay-time are ignored, but the delay may be counted
315 under certain circumstances.
316 - If nDelay == HTMLTABLE_RESIZE_NOW, resize immediately and do not
317 consider any resize-calls that might possibly be in order.
318 - The return value indicates whether the table has been changed. */
319 bool Resize( sal_uInt16 nAbsAvail
, bool bRecalc
=false, bool bForce
=false,
320 sal_uLong nDelay
=0 );
322 void BordersChanged( sal_uInt16 nAbsAvail
, bool bRecalc
=false );
324 /** Calculate available width. This works only if a layout or a
325 SwViewShell exists. Otherwise returns 0.
326 This is needed by HTML-filter because it doesn't have access to the layout.) */
327 static sal_uInt16
GetBrowseWidth( const SwDoc
& rDoc
);
329 /// Calculates available width by table-frame.
330 sal_uInt16
GetBrowseWidthByTabFrm( const SwTabFrm
& rTabFrm
) const;
332 /** Calculates available width by the table-frame or
333 static GetBrowseWidth if no layout exists. */
334 sal_uInt16
GetBrowseWidthByTable( const SwDoc
& rDoc
) const;
337 sal_uInt16
GetWidthOption() const { return nWidthOption
; }
338 bool HasPrcWidthOption() const { return bPrcWidthOption
; }
340 sal_uInt16
GetCellPadding() const { return nCellPadding
; }
341 sal_uInt16
GetCellSpacing() const { return nCellSpacing
; }
342 sal_uInt16
GetBorder() const { return nBorder
; }
344 sal_uInt16
GetRowCount() const { return nRows
; }
345 sal_uInt16
GetColCount() const { return nCols
; }
347 void SetExportable( bool bSet
) { bExportable
= bSet
; }
348 bool IsExportable() const { return bExportable
; }
350 bool HaveBordersChanged() const { return bBordersChanged
; }
352 void SetMayBeInFlyFrame( bool bSet
) { bMayBeInFlyFrame
= bSet
; }
353 bool MayBeInFlyFrame() const { return bMayBeInFlyFrame
; }
356 inline void SwHTMLTableLayoutCell::SetProtected()
364 inline void SwHTMLTableLayoutColumn::MergeMinMaxNoAlign( sal_uLong nCMin
,
365 sal_uLong nCMax
, sal_uLong nAbsMin
)
367 if( nCMin
> nMinNoAlign
)
369 if( nCMax
> nMaxNoAlign
)
371 if( nAbsMin
> nAbsMinNoAlign
)
372 nAbsMinNoAlign
= nAbsMin
;
375 inline void SwHTMLTableLayoutColumn::ClearPass1Info( bool bWidthOpt
)
377 nMinNoAlign
= nMaxNoAlign
= nAbsMinNoAlign
= MINLAY
;
382 bRelWidthOption
= false;
386 inline void SwHTMLTableLayoutColumn::MergeCellWidthOption(
387 sal_uInt16 nWidth
, bool bRel
)
390 (bRel
==bRelWidthOption
&& nWidthOption
< nWidth
) )
392 nWidthOption
= nWidth
;
393 bRelWidthOption
= bRel
;
397 inline void SwHTMLTableLayoutColumn::SetMinMax( sal_uLong nMn
, sal_uLong nMx
)
403 inline sal_uInt16
SwHTMLTableLayout::GetInhCellSpace( sal_uInt16 nCol
,
404 sal_uInt16 nColSpan
) const
406 sal_uInt16 nSpace
= 0;
408 nSpace
= nSpace
+ nInhAbsLeftSpace
;
409 if( nCol
+nColSpan
==nCols
)
410 nSpace
= nSpace
+ nInhAbsRightSpace
;
415 inline SwHTMLTableLayoutColumn
*SwHTMLTableLayout::GetColumn( sal_uInt16 nCol
) const
417 return aColumns
[nCol
];
420 inline void SwHTMLTableLayoutColumn::SetWidthOption(
421 sal_uInt16 nWidth
, bool bRelWidth
, bool bTest
)
423 if( bTest
&& bRelWidthOption
==bRelWidth
)
425 if( nWidth
> nWidthOption
)
426 nWidthOption
= nWidth
;
429 nWidthOption
= nWidth
;
430 bRelWidthOption
= bRelWidth
;
433 inline void SwHTMLTableLayout::SetColumn( SwHTMLTableLayoutColumn
*pCol
, sal_uInt16 nCol
)
435 aColumns
[nCol
] = pCol
;
438 inline SwHTMLTableLayoutCell
*SwHTMLTableLayout::GetCell( sal_uInt16 nRow
, sal_uInt16 nCol
) const
440 return aCells
[nRow
*nCols
+nCol
];
443 inline void SwHTMLTableLayout::SetCell( SwHTMLTableLayoutCell
*pCell
,
444 sal_uInt16 nRow
, sal_uInt16 nCol
)
446 aCells
[nRow
*nCols
+nCol
] = pCell
;
449 inline long SwHTMLTableLayout::GetBrowseWidthMin() const
451 return (long)( (!nWidthOption
|| bPrcWidthOption
) ? nMin
: nRelTabWidth
);
454 void SwHTMLTableLayout::SetInhBorderWidths( sal_uInt16 nLeft
, sal_uInt16 nRight
)
456 nInhLeftBorderWidth
= nLeft
;
457 nInhRightBorderWidth
= nRight
;
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */