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 .
22 #include <tools/solar.h>
23 #include <tools/color.hxx>
24 #include <boost/ptr_container/ptr_vector.hpp>
25 #include <o3tl/sorted_vector.hxx>
32 class SwHTMLTableLayout
;
35 namespace editeng
{ class SvxBorderLine
; }
37 //---------------------------------------------------------------------------
38 // Code aus dem HTML-Filter fuers schreiben von Tabellen
39 //---------------------------------------------------------------------------
43 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
44 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
47 //-----------------------------------------------------------------------
49 class SW_DLLPUBLIC SwWriteTableCell
51 const SwTableBox
*pBox
; // SwTableBox der Zelle
52 const SvxBrushItem
*pBackground
; // geerbter Hintergrund einer Zeile
54 long nHeight
; // fixe/Mindest-Hoehe der Zeile
56 sal_uInt32 nWidthOpt
; // Breite aus Option;
58 sal_uInt16 nRow
; // Start-Zeile
59 sal_uInt16 nCol
; // Start-Spalte
61 sal_uInt16 nRowSpan
; // ueberspannte Zeilen
62 sal_uInt16 nColSpan
; // ueberspannte Spalten
69 SwWriteTableCell(const SwTableBox
*pB
, sal_uInt16 nR
, sal_uInt16 nC
, sal_uInt16 nRSpan
,
70 sal_uInt16 nCSpan
, long nHght
, const SvxBrushItem
*pBGround
)
71 : pBox( pB
), pBackground( pBGround
), nHeight( nHght
), nWidthOpt( 0 ),
72 nRow( nR
), nCol( nC
), nRowSpan( nRSpan
), nColSpan( nCSpan
),
76 const SwTableBox
*GetBox() const { return pBox
; }
78 sal_uInt16
GetRow() const { return nRow
; }
79 sal_uInt16
GetCol() const { return nCol
; }
81 sal_uInt16
GetRowSpan() const { return nRowSpan
; }
82 sal_uInt16
GetColSpan() const { return nColSpan
; }
84 long GetHeight() const { return nHeight
; }
85 sal_Int16
GetVertOri() const;
87 const SvxBrushItem
*GetBackground() const { return pBackground
; }
89 void SetWidthOpt( sal_uInt16 nWidth
, bool bPrc
)
91 nWidthOpt
= nWidth
; bPrcWidthOpt
= bPrc
;
94 sal_uInt32
GetWidthOpt() const { return nWidthOpt
; }
95 bool HasPrcWidthOpt() const { return bPrcWidthOpt
; }
98 typedef boost::ptr_vector
<SwWriteTableCell
> SwWriteTableCells
;
101 //-----------------------------------------------------------------------
103 class SW_DLLPUBLIC SwWriteTableRow
105 SwWriteTableCells aCells
; // Alle Zellen der Rows
106 const SvxBrushItem
*pBackground
;// Hintergrund
108 long nPos
; // End-Position (twips) der Zeile
109 bool mbUseLayoutHeights
;
111 // Forbidden and not implemented.
114 SwWriteTableRow
& operator= (const SwWriteTableRow
&);
117 // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
118 SwWriteTableRow( const SwWriteTableRow
& );
122 sal_uInt16 nTopBorder
; // Dicke der oberen/unteren Umrandugen
123 sal_uInt16 nBottomBorder
;
125 bool bTopBorder
: 1; // Welche Umrandungen sind da?
126 bool bBottomBorder
: 1;
128 SwWriteTableRow( long nPos
, bool bUseLayoutHeights
);
130 SwWriteTableCell
*AddCell( const SwTableBox
*pBox
,
131 sal_uInt16 nRow
, sal_uInt16 nCol
,
132 sal_uInt16 nRowSpan
, sal_uInt16 nColSpan
,
134 const SvxBrushItem
*pBackground
);
136 void SetBackground( const SvxBrushItem
*pBGround
)
138 pBackground
= pBGround
;
140 const SvxBrushItem
*GetBackground() const { return pBackground
; }
142 bool HasTopBorder() const { return bTopBorder
; }
143 bool HasBottomBorder() const { return bBottomBorder
; }
145 long GetPos() const { return nPos
; }
146 const SwWriteTableCells
& GetCells() const { return aCells
; }
148 inline int operator==( const SwWriteTableRow
& rRow
) const;
149 inline int operator<( const SwWriteTableRow
& rRow2
) const;
152 inline int SwWriteTableRow::operator==( const SwWriteTableRow
& rRow
) const
154 // etwas Unschaerfe zulassen
155 return (nPos
>= rRow
.nPos
? nPos
- rRow
.nPos
: rRow
.nPos
- nPos
) <=
156 (mbUseLayoutHeights
? 0 : ROWFUZZY
);
159 inline int SwWriteTableRow::operator<( const SwWriteTableRow
& rRow
) const
161 // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
162 // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
163 return nPos
< rRow
.nPos
- (mbUseLayoutHeights
? 0 : ROWFUZZY
);
166 class SwWriteTableRows
: public o3tl::sorted_vector
<SwWriteTableRow
*, o3tl::less_ptr_to
<SwWriteTableRow
> > {
168 ~SwWriteTableRows() { DeleteAndDestroyAll(); }
172 //-----------------------------------------------------------------------
174 class SW_DLLPUBLIC SwWriteTableCol
176 sal_uInt32 nPos
; // End Position der Spalte
178 sal_uInt32 nWidthOpt
;
180 bool bRelWidthOpt
: 1;
181 bool bOutWidth
: 1; // Spaltenbreite ausgeben?
184 bool bLeftBorder
: 1; // Welche Umrandungen sind da?
185 bool bRightBorder
: 1;
187 SwWriteTableCol( sal_uInt32 nPosition
);
189 sal_uInt32
GetPos() const { return nPos
; }
191 bool HasLeftBorder() const { return bLeftBorder
; }
193 bool HasRightBorder() const { return bRightBorder
; }
195 void SetOutWidth( bool bSet
) { bOutWidth
= bSet
; }
197 inline int operator==( const SwWriteTableCol
& rCol
) const;
198 inline int operator<( const SwWriteTableCol
& rCol
) const;
200 void SetWidthOpt( sal_uInt32 nWidth
, bool bRel
)
202 nWidthOpt
= nWidth
; bRelWidthOpt
= bRel
;
204 sal_uInt32
GetWidthOpt() const { return nWidthOpt
; }
205 bool HasRelWidthOpt() const { return bRelWidthOpt
; }
208 inline int SwWriteTableCol::operator==( const SwWriteTableCol
& rCol
) const
210 // etwas Unschaerfe zulassen
211 return (nPos
>= rCol
.nPos
? nPos
- rCol
.nPos
212 : rCol
.nPos
- nPos
) <= COLFUZZY
;
215 inline int SwWriteTableCol::operator<( const SwWriteTableCol
& rCol
) const
217 // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
218 // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
219 return nPos
< rCol
.nPos
- COLFUZZY
;
223 class SwWriteTableCols
: public o3tl::sorted_vector
<SwWriteTableCol
*, o3tl::less_ptr_to
<SwWriteTableCol
> > {
225 ~SwWriteTableCols() { DeleteAndDestroyAll(); }
228 //-----------------------------------------------------------------------
230 class SW_DLLPUBLIC SwWriteTable
233 SwWriteTableCols aCols
; // alle Spalten
234 SwWriteTableRows aRows
; // alle Zellen
236 sal_uInt32 nBorderColor
; // Umrandungsfarbe
238 sal_uInt16 nCellSpacing
; // Dicke der inneren Umrandung
239 sal_uInt16 nCellPadding
; // Absatnd Umrandung-Inhalt
241 sal_uInt16 nBorder
; // Dicke der ausseren Umrandung
242 sal_uInt16 nInnerBorder
; // Dicke der inneren Umrandung
243 sal_uInt32 nBaseWidth
; // Bezugsgroesse fur Breiten SwFmtFrmSize
245 sal_uInt16 nHeadEndRow
; // letzte Zeile des Tabellen-Kopfes
248 sal_uInt16 nRightSub
;
250 sal_uInt32 nTabWidth
; // Absolute/Relative Breite der Tabelle
252 bool bRelWidths
: 1; // Breiten relativ ausgeben?
253 bool bUseLayoutHeights
: 1; // Layout zur Hoehenbestimmung nehmen?
255 bool m_bGetLineHeightCalled
: 1;
258 bool bColsOption
: 1;
260 bool bLayoutExport
: 1;
261 bool bCollectBorderWidth
: 1;
263 virtual sal_Bool
ShouldExpandSub( const SwTableBox
*pBox
,
264 sal_Bool bExpandedBefore
, sal_uInt16 nDepth
) const;
266 void CollectTableRowsCols( long nStartRPos
, sal_uInt32 nStartCPos
,
267 long nParentLineHeight
,
268 sal_uInt32 nParentLineWidth
,
269 const SwTableLines
& rLines
,
272 void FillTableRowsCols( long nStartRPos
, sal_uInt16 nStartRow
,
273 sal_uInt32 nStartCPos
, sal_uInt16 nStartCol
,
274 long nParentLineHeight
,
275 sal_uInt32 nParentLineWidth
,
276 const SwTableLines
& rLines
,
277 const SvxBrushItem
* pLineBrush
,
279 sal_uInt16 nNumOfHeaderRows
);
281 void MergeBorders( const editeng::SvxBorderLine
* pBorderLine
, bool bTable
);
283 sal_uInt16
MergeBoxBorders(const SwTableBox
*pBox
, size_t nRow
, size_t nCol
,
284 sal_uInt16 nRowSpan
, sal_uInt16 nColSpan
,
285 sal_uInt16
&rTopBorder
, sal_uInt16
&rBottomBorder
);
287 sal_uInt32
GetBaseWidth() const { return nBaseWidth
; }
289 bool HasRelWidths() const { return bRelWidths
; }
292 static sal_uInt32
GetBoxWidth( const SwTableBox
*pBox
);
294 sal_uInt32
GetRawWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
295 sal_uInt16
GetAbsWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
296 sal_uInt16
GetRelWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
297 sal_uInt16
GetPrcWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
299 long GetAbsHeight(long nRawWidth
, size_t nRow
, sal_uInt16 nRowSpan
) const;
302 long GetLineHeight( const SwTableLine
*pLine
);
303 long GetLineHeight( const SwTableBox
*pBox
) const;
304 const SvxBrushItem
*GetLineBrush( const SwTableBox
*pBox
,
305 SwWriteTableRow
*pRow
);
307 sal_uInt16
GetLeftSpace( sal_uInt16 nCol
) const;
308 sal_uInt16
GetRightSpace(size_t nCol
, sal_uInt16 nColSpan
) const;
312 SwWriteTable( const SwTableLines
& rLines
, long nWidth
, sal_uInt32 nBWidth
,
313 bool bRel
, sal_uInt16 nMaxDepth
= USHRT_MAX
,
314 sal_uInt16 nLeftSub
=0, sal_uInt16 nRightSub
=0, sal_uInt32 nNumOfRowsToRepeat
=0 );
315 SwWriteTable( const SwHTMLTableLayout
*pLayoutInfo
);
316 virtual ~SwWriteTable();
318 const SwWriteTableCols
& GetCols() const { return aCols
; }
319 const SwWriteTableRows
& GetRows() const { return aRows
; }
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */