xref: /trunk/main/sw/source/filter/inc/wrtswtbl.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef  _WRTSWTBL_HXX
24 #define  _WRTSWTBL_HXX
25 
26 #include <tools/solar.h>
27 #include <tools/color.hxx>
28 #include <svl/svarray.hxx>
29 
30 #include <swdllapi.h>
31 
32 class Color;
33 class SwTableBox;
34 class SwTableLine;
35 class SwTableLines;
36 class SwTable;
37 class SwHTMLTableLayout;
38 class SvxBrushItem;
39 class SvxBorderLine;
40 
41 //---------------------------------------------------------------------------
42 // 		 Code aus dem HTML-Filter fuers schreiben von Tabellen
43 //---------------------------------------------------------------------------
44 
45 #define COLFUZZY 20
46 #define ROWFUZZY 20
47 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
48 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
49 
50 
51 //-----------------------------------------------------------------------
52 
53 class SwWriteTableCell
54 {
55 	const SwTableBox *pBox;		// SwTableBox der Zelle
56 	const SvxBrushItem *pBackground;	// geerbter Hintergrund einer Zeile
57 
58 	long nHeight;				// fixe/Mindest-Hoehe der Zeile
59 
60     sal_uInt32 nWidthOpt;          // Breite aus Option;
61 
62 	sal_uInt16 nRow;				// Start-Zeile
63 	sal_uInt16 nCol;				// Start-Spalte
64 
65 	sal_uInt16 nRowSpan;			// ueberspannte Zeilen
66 	sal_uInt16 nColSpan;			// ueberspannte Spalten
67 
68 
69 	sal_Bool bPrcWidthOpt;
70 
71 public:
72 
SwWriteTableCell(const SwTableBox * pB,sal_uInt16 nR,sal_uInt16 nC,sal_uInt16 nRSpan,sal_uInt16 nCSpan,long nHght,const SvxBrushItem * pBGround)73 	SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan,
74         sal_uInt16 nCSpan, long nHght, const SvxBrushItem *pBGround)
75     : pBox( pB ), pBackground( pBGround ), nHeight( nHght ), nWidthOpt( 0 ),
76     nRow( nR ), nCol( nC ), nRowSpan( nRSpan ), nColSpan( nCSpan ),
77     bPrcWidthOpt( sal_False )
78 	{}
79 
GetBox() const80 	const SwTableBox *GetBox() const { return pBox; }
81 
GetRow() const82 	sal_uInt16 GetRow() const { return nRow; }
GetCol() const83 	sal_uInt16 GetCol() const { return nCol; }
84 
GetRowSpan() const85 	sal_uInt16 GetRowSpan() const { return nRowSpan; }
GetColSpan() const86 	sal_uInt16 GetColSpan() const { return nColSpan; }
87 
GetHeight() const88 	long GetHeight() const { return nHeight; }
89     sal_Int16 GetVertOri() const;
90 
GetBackground() const91 	const SvxBrushItem *GetBackground() const { return pBackground; }
92 
SetWidthOpt(sal_uInt16 nWidth,sal_Bool bPrc)93 	void SetWidthOpt( sal_uInt16 nWidth, sal_Bool bPrc )
94 	{
95 		nWidthOpt = nWidth; bPrcWidthOpt = bPrc;
96 	}
97 
GetWidthOpt() const98     sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
HasPrcWidthOpt() const99 	sal_Bool HasPrcWidthOpt() const { return bPrcWidthOpt; }
100 };
101 
102 typedef SwWriteTableCell *SwWriteTableCellPtr;
103 SV_DECL_PTRARR_DEL( SwWriteTableCells, SwWriteTableCellPtr, 5, 5 )
104 
105 
106 //-----------------------------------------------------------------------
107 
108 class SwWriteTableRow
109 {
110 	SwWriteTableCells aCells;		// Alle Zellen der Rows
111 	const SvxBrushItem *pBackground;// Hintergrund
112 
113 	long nPos;					// End-Position (twips) der Zeile
114     sal_Bool mbUseLayoutHeights;
115 
116     // Forbidden and not implemented.
117     SwWriteTableRow();
118 
119     SwWriteTableRow & operator= (const SwWriteTableRow &);
120 
121 protected:
122     // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
123     SwWriteTableRow( const SwWriteTableRow & );
124 
125 public:
126 
127 	sal_uInt16 nTopBorder;				// Dicke der oberen/unteren Umrandugen
128 	sal_uInt16 nBottomBorder;
129 
130 	sal_Bool bTopBorder : 1;			// Welche Umrandungen sind da?
131 	sal_Bool bBottomBorder : 1;
132 
133 	SwWriteTableRow( long nPos, sal_Bool bUseLayoutHeights );
134 
135 	SwWriteTableCell *AddCell( const SwTableBox *pBox,
136 								 sal_uInt16 nRow, sal_uInt16 nCol,
137 								 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
138 								 long nHeight,
139 								 const SvxBrushItem *pBackground );
140 
SetBackground(const SvxBrushItem * pBGround)141 	void SetBackground( const SvxBrushItem *pBGround )
142 	{
143 		pBackground = pBGround;
144 	}
GetBackground() const145 	const SvxBrushItem *GetBackground() const { return pBackground; }
146 
HasTopBorder() const147 	sal_Bool HasTopBorder() const 					{ return bTopBorder; }
HasBottomBorder() const148 	sal_Bool HasBottomBorder() const 				{ return bBottomBorder; }
149 
GetPos() const150 	long GetPos() const							{ return nPos; }
GetCells() const151 	const SwWriteTableCells& GetCells() const	{ return aCells; }
152 
153 	inline int operator==( const SwWriteTableRow& rRow ) const;
154 	inline int operator<( const SwWriteTableRow& rRow2 ) const;
155 };
156 
operator ==(const SwWriteTableRow & rRow) const157 inline int SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
158 {
159 	// etwas Unschaerfe zulassen
160 	return (nPos >= rRow.nPos ?  nPos - rRow.nPos : rRow.nPos - nPos ) <=
161         (mbUseLayoutHeights ? 0 : ROWFUZZY);
162 }
163 
operator <(const SwWriteTableRow & rRow) const164 inline int SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
165 {
166 	// Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
167 	// auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
168 	return nPos < rRow.nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
169 }
170 
171 typedef SwWriteTableRow *SwWriteTableRowPtr;
172 SV_DECL_PTRARR_SORT_DEL( SwWriteTableRows, SwWriteTableRowPtr, 5, 5 )
173 
174 
175 //-----------------------------------------------------------------------
176 
177 class SwWriteTableCol
178 {
179 	sal_uInt32 nPos;						// End Position der Spalte
180 
181     sal_uInt32 nWidthOpt;
182 
183 	sal_Bool bRelWidthOpt : 1;
184 	sal_Bool bOutWidth : 1;					// Spaltenbreite ausgeben?
185 
186 public:
187 	sal_Bool bLeftBorder : 1;				// Welche Umrandungen sind da?
188 	sal_Bool bRightBorder : 1;
189 
190 	SwWriteTableCol( sal_uInt32 nPosition );
191 
GetPos() const192 	sal_uInt32 GetPos() const 						{ return nPos; }
193 
SetLeftBorder(sal_Bool bBorder)194 	void SetLeftBorder( sal_Bool bBorder ) 			{ bLeftBorder = bBorder; }
HasLeftBorder() const195 	sal_Bool HasLeftBorder() const 					{ return bLeftBorder; }
196 
SetRightBorder(sal_Bool bBorder)197 	void SetRightBorder( sal_Bool bBorder )			{ bRightBorder = bBorder; }
HasRightBorder() const198 	sal_Bool HasRightBorder() const					{ return bRightBorder; }
199 
SetOutWidth(sal_Bool bSet)200 	void SetOutWidth( sal_Bool bSet ) 				{ bOutWidth = bSet; }
GetOutWidth() const201 	sal_Bool GetOutWidth() const 					{ return bOutWidth; }
202 
203 	inline int operator==( const SwWriteTableCol& rCol ) const;
204 	inline int operator<( const SwWriteTableCol& rCol ) const;
205 
SetWidthOpt(sal_uInt32 nWidth,sal_Bool bRel)206 	void SetWidthOpt( sal_uInt32 nWidth, sal_Bool bRel )
207 	{
208 		nWidthOpt = nWidth; bRelWidthOpt = bRel;
209 	}
GetWidthOpt() const210     sal_uInt32 GetWidthOpt() const                 { return nWidthOpt; }
HasRelWidthOpt() const211 	sal_Bool HasRelWidthOpt() const 				{ return bRelWidthOpt; }
212 };
213 
operator ==(const SwWriteTableCol & rCol) const214 inline int SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
215 {
216 	// etwas Unschaerfe zulassen
217 	return (nPos >= rCol.nPos ? nPos - rCol.nPos
218 									 : rCol.nPos - nPos ) <= COLFUZZY;
219 }
220 
operator <(const SwWriteTableCol & rCol) const221 inline int SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
222 {
223 	// Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
224 	// auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
225 	return nPos < rCol.nPos - COLFUZZY;
226 }
227 
228 
229 typedef SwWriteTableCol *SwWriteTableColPtr;
230 SV_DECL_PTRARR_SORT_DEL( SwWriteTableCols, SwWriteTableColPtr, 5, 5 )
231 
232 //-----------------------------------------------------------------------
233 
234 class SW_DLLPUBLIC SwWriteTable
235 {
236 protected:
237 	SwWriteTableCols aCols;	// alle Spalten
238 	SwWriteTableRows aRows;	// alle Zellen
239 
240 	sal_uInt32 nBorderColor;		// Umrandungsfarbe
241 
242 	sal_uInt16 nCellSpacing;		// Dicke der inneren Umrandung
243 	sal_uInt16 nCellPadding;		// Absatnd Umrandung-Inhalt
244 
245 	sal_uInt16 nBorder;				// Dicke der ausseren Umrandung
246 	sal_uInt16 nInnerBorder;		// Dicke der inneren Umrandung
247     sal_uInt32 nBaseWidth;            // Bezugsgroesse fur Breiten SwFmtFrmSize
248 
249 	sal_uInt16 nHeadEndRow;			// letzte Zeile des Tabellen-Kopfes
250 
251 	sal_uInt16 nLeftSub;
252 	sal_uInt16 nRightSub;
253 
254     sal_uInt32 nTabWidth;              // Absolute/Relative Breite der Tabelle
255 
256 	sal_Bool bRelWidths : 1;		// Breiten relativ ausgeben?
257 	sal_Bool bUseLayoutHeights : 1;	// Layout zur Hoehenbestimmung nehmen?
258 #ifdef DBG_UTIL
259 	sal_Bool bGetLineHeightCalled : 1;
260 #endif
261 
262 	sal_Bool bColsOption : 1;
263 	sal_Bool bColTags : 1;
264 	sal_Bool bLayoutExport : 1;
265 	sal_Bool bCollectBorderWidth : 1;
266 
267 	virtual sal_Bool ShouldExpandSub( const SwTableBox *pBox,
268 								sal_Bool bExpandedBefore, sal_uInt16 nDepth ) const;
269 
270 	void CollectTableRowsCols( long nStartRPos, sal_uInt32 nStartCPos,
271 							   long nParentLineHeight,
272 							   sal_uInt32 nParentLineWidth,
273 							   const SwTableLines& rLines,
274 							   sal_uInt16 nDepth );
275 
276 	void FillTableRowsCols( long nStartRPos, sal_uInt16 nStartRow,
277 							sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
278 							long nParentLineHeight,
279 							sal_uInt32 nParentLineWidth,
280 							const SwTableLines& rLines,
281 							const SvxBrushItem* pLineBrush,
282 							sal_uInt16 nDepth,
283 							sal_uInt16 nNumOfHeaderRows );
284 
285 	void MergeBorders( const SvxBorderLine* pBorderLine, sal_Bool bTable );
286 
287 	sal_uInt16 MergeBoxBorders( const SwTableBox *pBox, sal_uInt16 nRow, sal_uInt16 nCol,
288 							sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
289 							sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
290 
GetBaseWidth() const291     sal_uInt32 GetBaseWidth() const { return nBaseWidth; }
292 
HasRelWidths() const293 	sal_Bool HasRelWidths() const { return bRelWidths; }
294 
295 public:
296     static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
297 
298     sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
299 	sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
300 	sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
301 	sal_uInt16 GetPrcWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
302 
303 	long GetAbsHeight( long nRawWidth, sal_uInt16 nRow, sal_uInt16 nRowSpan ) const;
304 protected:
305 
306 	long GetLineHeight( const SwTableLine *pLine );
307 	long GetLineHeight( const SwTableBox *pBox ) const;
308 	const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
309 									  SwWriteTableRow *pRow );
310 
311 	sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
312 	sal_uInt16 GetRightSpace( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
313 
314 
315 public:
316     SwWriteTable( const SwTableLines& rLines, long nWidth, sal_uInt32 nBWidth,
317 					sal_Bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
318 					sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0 );
319 	SwWriteTable( const SwHTMLTableLayout *pLayoutInfo );
320 	virtual ~SwWriteTable();
321 
GetCols() const322 	const SwWriteTableCols& GetCols() const { return aCols; }
GetRows() const323 	const SwWriteTableRows& GetRows() const { return aRows; }
324 };
325 
326 
327 
328 
329 #endif
330 
331