Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
20 : #define INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
21 :
22 : #include <tools/solar.h>
23 : #include <tools/color.hxx>
24 : #include <boost/ptr_container/ptr_vector.hpp>
25 : #include <o3tl/sorted_vector.hxx>
26 :
27 : #include <swdllapi.h>
28 :
29 : class SwTableBox;
30 : class SwTableLine;
31 : class SwTableLines;
32 : class SwHTMLTableLayout;
33 : class SvxBrushItem;
34 :
35 : namespace editeng { class SvxBorderLine; }
36 :
37 : // Code aus dem HTML-Filter fuers schreiben von Tabellen
38 :
39 : #define COLFUZZY 20
40 : #define ROWFUZZY 20
41 : #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
42 : #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
43 :
44 : class SW_DLLPUBLIC SwWriteTableCell
45 : {
46 : const SwTableBox *pBox; // SwTableBox der Zelle
47 : const SvxBrushItem *pBackground; // geerbter Hintergrund einer Zeile
48 :
49 : long nHeight; // fixe/Mindest-Hoehe der Zeile
50 :
51 : sal_uInt32 nWidthOpt; // Breite aus Option;
52 :
53 : sal_uInt16 nRow; // Start-Zeile
54 : sal_uInt16 nCol; // Start-Spalte
55 :
56 : sal_uInt16 nRowSpan; // ueberspannte Zeilen
57 : sal_uInt16 nColSpan; // ueberspannte Spalten
58 :
59 : bool bPrcWidthOpt;
60 :
61 : public:
62 :
63 3906 : SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan,
64 : sal_uInt16 nCSpan, long nHght, const SvxBrushItem *pBGround)
65 : : pBox( pB ), pBackground( pBGround ), nHeight( nHght ), nWidthOpt( 0 ),
66 : nRow( nR ), nCol( nC ), nRowSpan( nRSpan ), nColSpan( nCSpan ),
67 3906 : bPrcWidthOpt( false )
68 3906 : {}
69 :
70 2096 : const SwTableBox *GetBox() const { return pBox; }
71 :
72 520 : sal_uInt16 GetRow() const { return nRow; }
73 520 : sal_uInt16 GetCol() const { return nCol; }
74 :
75 1308 : sal_uInt16 GetRowSpan() const { return nRowSpan; }
76 3522 : sal_uInt16 GetColSpan() const { return nColSpan; }
77 :
78 520 : long GetHeight() const { return nHeight; }
79 : sal_Int16 GetVertOri() const;
80 :
81 0 : const SvxBrushItem *GetBackground() const { return pBackground; }
82 :
83 0 : void SetWidthOpt( sal_uInt16 nWidth, bool bPrc )
84 : {
85 0 : nWidthOpt = nWidth; bPrcWidthOpt = bPrc;
86 0 : }
87 :
88 0 : sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
89 0 : bool HasPrcWidthOpt() const { return bPrcWidthOpt; }
90 : };
91 :
92 : typedef boost::ptr_vector<SwWriteTableCell> SwWriteTableCells;
93 :
94 2940 : class SW_DLLPUBLIC SwWriteTableRow
95 : {
96 : SwWriteTableCells aCells; // Alle Zellen der Rows
97 : const SvxBrushItem *pBackground;// Hintergrund
98 :
99 : long nPos; // End-Position (twips) der Zeile
100 : bool mbUseLayoutHeights;
101 :
102 : // Forbidden and not implemented.
103 : SwWriteTableRow();
104 :
105 : SwWriteTableRow & operator= (const SwWriteTableRow &);
106 :
107 : protected:
108 : // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
109 : SwWriteTableRow( const SwWriteTableRow & );
110 :
111 : public:
112 :
113 : sal_uInt16 nTopBorder; // Dicke der oberen/unteren Umrandugen
114 : sal_uInt16 nBottomBorder;
115 :
116 : bool bTopBorder : 1; // Welche Umrandungen sind da?
117 : bool bBottomBorder : 1;
118 :
119 : SwWriteTableRow( long nPos, bool bUseLayoutHeights );
120 :
121 : SwWriteTableCell *AddCell( const SwTableBox *pBox,
122 : sal_uInt16 nRow, sal_uInt16 nCol,
123 : sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
124 : long nHeight,
125 : const SvxBrushItem *pBackground );
126 :
127 1490 : void SetBackground( const SvxBrushItem *pBGround )
128 : {
129 1490 : pBackground = pBGround;
130 1490 : }
131 104 : const SvxBrushItem *GetBackground() const { return pBackground; }
132 :
133 0 : bool HasTopBorder() const { return bTopBorder; }
134 0 : bool HasBottomBorder() const { return bBottomBorder; }
135 :
136 : long GetPos() const { return nPos; }
137 13806 : const SwWriteTableCells& GetCells() const { return aCells; }
138 :
139 : inline bool operator==( const SwWriteTableRow& rRow ) const;
140 : inline bool operator<( const SwWriteTableRow& rRow2 ) const;
141 : };
142 :
143 : inline bool SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
144 : {
145 : // etwas Unschaerfe zulassen
146 : return (nPos >= rRow.nPos ? nPos - rRow.nPos : rRow.nPos - nPos ) <=
147 : (mbUseLayoutHeights ? 0 : ROWFUZZY);
148 : }
149 :
150 12304 : inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
151 : {
152 : // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
153 : // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
154 12304 : return nPos < rRow.nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
155 : }
156 :
157 316 : class SwWriteTableRows : public o3tl::sorted_vector<SwWriteTableRow*, o3tl::less_ptr_to<SwWriteTableRow> > {
158 : public:
159 292 : ~SwWriteTableRows() { DeleteAndDestroyAll(); }
160 : };
161 :
162 : class SW_DLLPUBLIC SwWriteTableCol
163 : {
164 : sal_uInt32 nPos; // End Position der Spalte
165 :
166 : sal_uInt32 nWidthOpt;
167 :
168 : bool bRelWidthOpt : 1;
169 : bool bOutWidth : 1; // Spaltenbreite ausgeben?
170 :
171 : public:
172 : bool bLeftBorder : 1; // Welche Umrandungen sind da?
173 : bool bRightBorder : 1;
174 :
175 : SwWriteTableCol( sal_uInt32 nPosition );
176 :
177 42638 : sal_uInt32 GetPos() const { return nPos; }
178 :
179 0 : bool HasLeftBorder() const { return bLeftBorder; }
180 :
181 0 : bool HasRightBorder() const { return bRightBorder; }
182 :
183 520 : void SetOutWidth( bool bSet ) { bOutWidth = bSet; }
184 :
185 : inline bool operator==( const SwWriteTableCol& rCol ) const;
186 : inline bool operator<( const SwWriteTableCol& rCol ) const;
187 :
188 8 : void SetWidthOpt( sal_uInt32 nWidth, bool bRel )
189 : {
190 8 : nWidthOpt = nWidth; bRelWidthOpt = bRel;
191 8 : }
192 32 : sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
193 0 : bool HasRelWidthOpt() const { return bRelWidthOpt; }
194 : };
195 :
196 : inline bool SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
197 : {
198 : // etwas Unschaerfe zulassen
199 : return (nPos >= rCol.nPos ? nPos - rCol.nPos
200 : : rCol.nPos - nPos ) <= COLFUZZY;
201 : }
202 :
203 88 : inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
204 : {
205 : // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
206 : // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
207 88 : return nPos < rCol.nPos - COLFUZZY;
208 : }
209 :
210 : struct SwWriteTableColLess {
211 20838 : bool operator()(SwWriteTableCol const * lhs, SwWriteTableCol const * rhs) {
212 20838 : return lhs->GetPos() < rhs->GetPos();
213 : }
214 : };
215 :
216 316 : class SwWriteTableCols : public o3tl::sorted_vector<SwWriteTableCol*, SwWriteTableColLess> {
217 : public:
218 292 : ~SwWriteTableCols() { DeleteAndDestroyAll(); }
219 : };
220 :
221 : class SW_DLLPUBLIC SwWriteTable
222 : {
223 : protected:
224 : SwWriteTableCols aCols; // alle Spalten
225 : SwWriteTableRows aRows; // alle Zellen
226 :
227 : sal_uInt32 nBorderColor; // Umrandungsfarbe
228 :
229 : sal_uInt16 nCellSpacing; // Dicke der inneren Umrandung
230 : sal_uInt16 nCellPadding; // Absatnd Umrandung-Inhalt
231 :
232 : sal_uInt16 nBorder; // Dicke der ausseren Umrandung
233 : sal_uInt16 nInnerBorder; // Dicke der inneren Umrandung
234 : sal_uInt32 nBaseWidth; // Bezugsgroesse fur Breiten SwFmtFrmSize
235 :
236 : sal_uInt16 nHeadEndRow; // letzte Zeile des Tabellen-Kopfes
237 :
238 : sal_uInt16 nLeftSub;
239 : sal_uInt16 nRightSub;
240 :
241 : sal_uInt32 nTabWidth; // Absolute/Relative Breite der Tabelle
242 :
243 : bool bRelWidths : 1; // Breiten relativ ausgeben?
244 : bool bUseLayoutHeights : 1; // Layout zur Hoehenbestimmung nehmen?
245 : #ifdef DBG_UTIL
246 : bool m_bGetLineHeightCalled : 1;
247 : #endif
248 :
249 : bool bColsOption : 1;
250 : bool bColTags : 1;
251 : bool bLayoutExport : 1;
252 : bool bCollectBorderWidth : 1;
253 :
254 : virtual bool ShouldExpandSub( const SwTableBox *pBox,
255 : bool bExpandedBefore, sal_uInt16 nDepth ) const;
256 :
257 : void CollectTableRowsCols( long nStartRPos, sal_uInt32 nStartCPos,
258 : long nParentLineHeight,
259 : sal_uInt32 nParentLineWidth,
260 : const SwTableLines& rLines,
261 : sal_uInt16 nDepth );
262 :
263 : void FillTableRowsCols( long nStartRPos, sal_uInt16 nStartRow,
264 : sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
265 : long nParentLineHeight,
266 : sal_uInt32 nParentLineWidth,
267 : const SwTableLines& rLines,
268 : const SvxBrushItem* pLineBrush,
269 : sal_uInt16 nDepth,
270 : sal_uInt16 nNumOfHeaderRows );
271 :
272 : void MergeBorders( const editeng::SvxBorderLine* pBorderLine, bool bTable );
273 :
274 : sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol,
275 : sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
276 : sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
277 :
278 1060 : sal_uInt32 GetBaseWidth() const { return nBaseWidth; }
279 :
280 532 : bool HasRelWidths() const { return bRelWidths; }
281 :
282 : public:
283 : static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
284 :
285 : sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
286 : sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
287 : sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
288 : sal_uInt16 GetPrcWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
289 :
290 : long GetAbsHeight(long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const;
291 :
292 : protected:
293 : long GetLineHeight( const SwTableLine *pLine );
294 : long GetLineHeight( const SwTableBox *pBox ) const;
295 : const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
296 : SwWriteTableRow *pRow );
297 :
298 : sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
299 : sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const;
300 :
301 : public:
302 : SwWriteTable( const SwTableLines& rLines, long nWidth, sal_uInt32 nBWidth,
303 : bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
304 : sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0 );
305 : SwWriteTable( const SwHTMLTableLayout *pLayoutInfo );
306 : virtual ~SwWriteTable();
307 :
308 : const SwWriteTableCols& GetCols() const { return aCols; }
309 7304 : const SwWriteTableRows& GetRows() const { return aRows; }
310 : };
311 :
312 : #endif
313 :
314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|