1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrtswtbl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <tools/solar.h>
34 #include <tools/color.hxx>
35 #include <svtools/svarray.hxx>
44 class SwHTMLTableLayout
;
48 //---------------------------------------------------------------------------
49 // Code aus dem HTML-Filter fuers schreiben von Tabellen
50 //---------------------------------------------------------------------------
54 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
55 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
58 //-----------------------------------------------------------------------
60 class SwWriteTableCell
62 const SwTableBox
*pBox
; // SwTableBox der Zelle
63 const SvxBrushItem
*pBackground
; // geerbter Hintergrund einer Zeile
65 long nHeight
; // fixe/Mindest-Hoehe der Zeile
67 USHORT nWidthOpt
; // Breite aus Option;
69 USHORT nRow
; // Start-Zeile
70 USHORT nCol
; // Start-Spalte
72 USHORT nRowSpan
; // ueberspannte Zeilen
73 USHORT nColSpan
; // ueberspannte Spalten
80 SwWriteTableCell(const SwTableBox
*pB
, USHORT nR
, USHORT nC
, USHORT nRSpan
,
81 USHORT nCSpan
, long nHght
, const SvxBrushItem
*pBGround
)
82 : pBox( pB
), pBackground( pBGround
), nHeight( nHght
), nWidthOpt( 0 ),
83 nRow( nR
), nCol( nC
), nRowSpan( nRSpan
), nColSpan( nCSpan
),
87 const SwTableBox
*GetBox() const { return pBox
; }
89 USHORT
GetRow() const { return nRow
; }
90 USHORT
GetCol() const { return nCol
; }
92 USHORT
GetRowSpan() const { return nRowSpan
; }
93 USHORT
GetColSpan() const { return nColSpan
; }
95 long GetHeight() const { return nHeight
; }
96 sal_Int16
GetVertOri() const;
98 const SvxBrushItem
*GetBackground() const { return pBackground
; }
100 void SetWidthOpt( USHORT nWidth
, BOOL bPrc
)
102 nWidthOpt
= nWidth
; bPrcWidthOpt
= bPrc
;
105 USHORT
GetWidthOpt() const { return nWidthOpt
; }
106 BOOL
HasPrcWidthOpt() const { return bPrcWidthOpt
; }
109 typedef SwWriteTableCell
*SwWriteTableCellPtr
;
110 SV_DECL_PTRARR_DEL( SwWriteTableCells
, SwWriteTableCellPtr
, 5, 5 )
113 //-----------------------------------------------------------------------
115 class SwWriteTableRow
117 SwWriteTableCells aCells
; // Alle Zellen der Rows
118 const SvxBrushItem
*pBackground
;// Hintergrund
120 long nPos
; // End-Position (twips) der Zeile
121 BOOL mbUseLayoutHeights
;
123 // Forbidden and not implemented.
126 SwWriteTableRow
& operator= (const SwWriteTableRow
&);
129 // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
130 SwWriteTableRow( const SwWriteTableRow
& );
134 USHORT nTopBorder
; // Dicke der oberen/unteren Umrandugen
135 USHORT nBottomBorder
;
137 BOOL bTopBorder
: 1; // Welche Umrandungen sind da?
138 BOOL bBottomBorder
: 1;
140 SwWriteTableRow( long nPos
, BOOL bUseLayoutHeights
);
142 SwWriteTableCell
*AddCell( const SwTableBox
*pBox
,
143 USHORT nRow
, USHORT nCol
,
144 USHORT nRowSpan
, USHORT nColSpan
,
146 const SvxBrushItem
*pBackground
);
148 void SetBackground( const SvxBrushItem
*pBGround
)
150 pBackground
= pBGround
;
152 const SvxBrushItem
*GetBackground() const { return pBackground
; }
154 BOOL
HasTopBorder() const { return bTopBorder
; }
155 BOOL
HasBottomBorder() const { return bBottomBorder
; }
157 long GetPos() const { return nPos
; }
158 const SwWriteTableCells
& GetCells() const { return aCells
; }
160 inline int operator==( const SwWriteTableRow
& rRow
) const;
161 inline int operator<( const SwWriteTableRow
& rRow2
) const;
164 inline int SwWriteTableRow::operator==( const SwWriteTableRow
& rRow
) const
166 // etwas Unschaerfe zulassen
167 return (nPos
>= rRow
.nPos
? nPos
- rRow
.nPos
: rRow
.nPos
- nPos
) <=
168 (mbUseLayoutHeights
? 0 : ROWFUZZY
);
171 inline int SwWriteTableRow::operator<( const SwWriteTableRow
& rRow
) const
173 // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
174 // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
175 return nPos
< rRow
.nPos
- (mbUseLayoutHeights
? 0 : ROWFUZZY
);
178 typedef SwWriteTableRow
*SwWriteTableRowPtr
;
179 SV_DECL_PTRARR_SORT_DEL( SwWriteTableRows
, SwWriteTableRowPtr
, 5, 5 )
182 //-----------------------------------------------------------------------
184 class SwWriteTableCol
186 USHORT nPos
; // End Position der Spalte
190 BOOL bRelWidthOpt
: 1;
191 BOOL bOutWidth
: 1; // Spaltenbreite ausgeben?
194 BOOL bLeftBorder
: 1; // Welche Umrandungen sind da?
195 BOOL bRightBorder
: 1;
197 SwWriteTableCol( USHORT nPosition
);
199 USHORT
GetPos() const { return nPos
; }
201 void SetLeftBorder( BOOL bBorder
) { bLeftBorder
= bBorder
; }
202 BOOL
HasLeftBorder() const { return bLeftBorder
; }
204 void SetRightBorder( BOOL bBorder
) { bRightBorder
= bBorder
; }
205 BOOL
HasRightBorder() const { return bRightBorder
; }
207 void SetOutWidth( BOOL bSet
) { bOutWidth
= bSet
; }
208 BOOL
GetOutWidth() const { return bOutWidth
; }
210 inline int operator==( const SwWriteTableCol
& rCol
) const;
211 inline int operator<( const SwWriteTableCol
& rCol
) const;
213 void SetWidthOpt( USHORT nWidth
, BOOL bRel
)
215 nWidthOpt
= nWidth
; bRelWidthOpt
= bRel
;
217 USHORT
GetWidthOpt() const { return nWidthOpt
; }
218 BOOL
HasRelWidthOpt() const { return bRelWidthOpt
; }
221 inline int SwWriteTableCol::operator==( const SwWriteTableCol
& rCol
) const
223 // etwas Unschaerfe zulassen
224 return (nPos
>= rCol
.nPos
? nPos
- rCol
.nPos
225 : rCol
.nPos
- nPos
) <= COLFUZZY
;
228 inline int SwWriteTableCol::operator<( const SwWriteTableCol
& rCol
) const
230 // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
231 // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
232 return nPos
< rCol
.nPos
- COLFUZZY
;
236 typedef SwWriteTableCol
*SwWriteTableColPtr
;
237 SV_DECL_PTRARR_SORT_DEL( SwWriteTableCols
, SwWriteTableColPtr
, 5, 5 )
239 //-----------------------------------------------------------------------
241 class SW_DLLPUBLIC SwWriteTable
244 SwWriteTableCols aCols
; // alle Spalten
245 SwWriteTableRows aRows
; // alle Zellen
247 UINT32 nBorderColor
; // Umrandungsfarbe
249 USHORT nCellSpacing
; // Dicke der inneren Umrandung
250 USHORT nCellPadding
; // Absatnd Umrandung-Inhalt
252 USHORT nBorder
; // Dicke der ausseren Umrandung
253 USHORT nInnerBorder
; // Dicke der inneren Umrandung
254 USHORT nBaseWidth
; // Bezugsgroesse fur Breiten SwFmtFrmSize
256 USHORT nHeadEndRow
; // letzte Zeile des Tabellen-Kopfes
261 long nTabWidth
; // Absolute/Relative Breite der Tabelle
263 BOOL bRelWidths
: 1; // Breiten relativ ausgeben?
264 BOOL bUseLayoutHeights
: 1; // Layout zur Hoehenbestimmung nehmen?
266 BOOL bGetLineHeightCalled
: 1;
269 BOOL bColsOption
: 1;
271 BOOL bLayoutExport
: 1;
272 BOOL bCollectBorderWidth
: 1;
274 virtual BOOL
ShouldExpandSub( const SwTableBox
*pBox
,
275 BOOL bExpandedBefore
, USHORT nDepth
) const;
277 void CollectTableRowsCols( long nStartRPos
, USHORT nStartCPos
,
278 long nParentLineHeight
,
279 USHORT nParentLineWidth
,
280 const SwTableLines
& rLines
,
283 void FillTableRowsCols( long nStartRPos
, USHORT nStartRow
,
284 USHORT nStartCPos
, USHORT nStartCol
,
285 long nParentLineHeight
,
286 USHORT nParentLineWidth
,
287 const SwTableLines
& rLines
,
288 const SvxBrushItem
* pLineBrush
,
290 sal_uInt16 nNumOfHeaderRows
);
292 void MergeBorders( const SvxBorderLine
* pBorderLine
, BOOL bTable
);
294 USHORT
MergeBoxBorders( const SwTableBox
*pBox
, USHORT nRow
, USHORT nCol
,
295 USHORT nRowSpan
, USHORT nColSpan
,
296 USHORT
&rTopBorder
, USHORT
&rBottomBorder
);
298 USHORT
GetBaseWidth() const { return nBaseWidth
; }
300 BOOL
HasRelWidths() const { return bRelWidths
; }
303 static long GetBoxWidth( const SwTableBox
*pBox
);
305 USHORT
GetRawWidth( USHORT nCol
, USHORT nColSpan
) const;
306 USHORT
GetAbsWidth( USHORT nCol
, USHORT nColSpan
) const;
307 USHORT
GetRelWidth( USHORT nCol
, USHORT nColSpan
) const;
308 USHORT
GetPrcWidth( USHORT nCol
, USHORT nColSpan
) const;
310 long GetAbsHeight( long nRawWidth
, USHORT nRow
, USHORT nRowSpan
) const;
313 long GetLineHeight( const SwTableLine
*pLine
);
314 long GetLineHeight( const SwTableBox
*pBox
) const;
315 const SvxBrushItem
*GetLineBrush( const SwTableBox
*pBox
,
316 SwWriteTableRow
*pRow
);
318 USHORT
GetLeftSpace( USHORT nCol
) const;
319 USHORT
GetRightSpace( USHORT nCol
, USHORT nColSpan
) const;
323 SwWriteTable( const SwTableLines
& rLines
, long nWidth
, USHORT nBWidth
,
324 BOOL bRel
, USHORT nMaxDepth
= USHRT_MAX
,
325 USHORT nLeftSub
=0, USHORT nRightSub
=0, sal_uInt32 nNumOfRowsToRepeat
=0 );
326 SwWriteTable( const SwHTMLTableLayout
*pLayoutInfo
);
327 virtual ~SwWriteTable();
329 const SwWriteTableCols
& GetCols() const { return aCols
; }
330 const SwWriteTableRows
& GetRows() const { return aRows
; }