LibreOffice Module sw (master) 1
wrtswtbl.hxx
Go to the documentation of this file.
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/color.hxx>
23#include <tools/long.hxx>
25
26#include <swdllapi.h>
27
28#include <memory>
29#include <vector>
30#include <climits>
31
32class SwTableBox;
33class SwTableLine;
34class SwTableLines;
36class SvxBrushItem;
37
38namespace editeng { class SvxBorderLine; }
39
40// Code from the HTML filter for writing of tables
41
42#define COLFUZZY 20
43#define ROWFUZZY 20
44#define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
45#define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
46
48{
49 const SwTableBox *m_pBox; // SwTableBox of the cell
50 const SvxBrushItem *m_pBackground; // inherited background of a row
51
52 tools::Long m_nHeight; // fix/minimum height of a row
53
54 sal_uInt32 m_nWidthOpt; // width from option;
55
56 sal_uInt16 m_nRow; // start row
57 sal_uInt16 m_nCol; // start column
58
59 sal_uInt16 m_nRowSpan; // spanned rows
60 sal_uInt16 m_nColSpan; // spanned columns
61
63
64public:
65
66 SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan,
67 sal_uInt16 nCSpan, tools::Long nHght, const SvxBrushItem *pBGround)
68 : m_pBox( pB ), m_pBackground( pBGround ), m_nHeight( nHght ), m_nWidthOpt( 0 ),
69 m_nRow( nR ), m_nCol( nC ), m_nRowSpan( nRSpan ), m_nColSpan( nCSpan ),
70 m_bPercentWidthOpt( false )
71 {}
72
73 const SwTableBox *GetBox() const { return m_pBox; }
74
75 sal_uInt16 GetRow() const { return m_nRow; }
76 sal_uInt16 GetCol() const { return m_nCol; }
77
78 sal_uInt16 GetRowSpan() const { return m_nRowSpan; }
79 sal_uInt16 GetColSpan() const { return m_nColSpan; }
80
81 tools::Long GetHeight() const { return m_nHeight; }
82 sal_Int16 GetVertOri() const;
83
84 const SvxBrushItem *GetBackground() const { return m_pBackground; }
85
86 void SetWidthOpt( sal_uInt16 nWidth, bool bPercent )
87 {
88 m_nWidthOpt = nWidth; m_bPercentWidthOpt = bPercent;
89 }
90
91 sal_uInt32 GetWidthOpt() const { return m_nWidthOpt; }
92 bool HasPercentWidthOpt() const { return m_bPercentWidthOpt; }
93};
94
95typedef std::vector<std::unique_ptr<SwWriteTableCell>> SwWriteTableCells;
96
97class SwWriteTableRow final
98{
100 const SvxBrushItem *m_pBackground; // background
101
102 tools::Long m_nPos; // end position (twips) of the row
104
106
107 // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
109
110public:
111
112 sal_uInt16 m_nTopBorder; // thickness of upper/lower border
113 sal_uInt16 m_nBottomBorder;
114
115 bool m_bTopBorder : 1; // which borders are there?
117
118 SwWriteTableRow( tools::Long nPos, bool bUseLayoutHeights );
119
120 SwWriteTableCell *AddCell( const SwTableBox *pBox,
121 sal_uInt16 nRow, sal_uInt16 nCol,
122 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
123 tools::Long nHeight,
124 const SvxBrushItem *pBackground );
125
126 void SetBackground( const SvxBrushItem *pBGround )
127 {
128 m_pBackground = pBGround;
129 }
130 const SvxBrushItem *GetBackground() const { return m_pBackground; }
131
132 bool HasTopBorder() const { return m_bTopBorder; }
133 bool HasBottomBorder() const { return m_bBottomBorder; }
134
135 const SwWriteTableCells& GetCells() const { return m_Cells; }
136
137 inline bool operator==( const SwWriteTableRow& rRow ) const;
138 inline bool operator<( const SwWriteTableRow& rRow2 ) const;
139};
140
141inline bool SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
142{
143 // allow for some fuzzyness
144 return (m_nPos >= rRow.m_nPos ? m_nPos - rRow.m_nPos : rRow.m_nPos - m_nPos ) <=
146}
147
148inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
149{
150 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
151 // not let x==y and x<y at the same time ;-)
152 return m_nPos < rRow.m_nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
153}
154
157
159{
160 sal_uInt32 m_nPos; // end position of the column
161
162 sal_uInt32 m_nWidthOpt;
163
165
166public:
167 bool m_bLeftBorder : 1; // which borders are there?
169
170 SwWriteTableCol( sal_uInt32 nPosition );
171
172 sal_uInt32 GetPos() const { return m_nPos; }
173
174 bool HasLeftBorder() const { return m_bLeftBorder; }
175
176 bool HasRightBorder() const { return m_bRightBorder; }
177
178 inline bool operator==( const SwWriteTableCol& rCol ) const;
179 inline bool operator<( const SwWriteTableCol& rCol ) const;
180
181 void SetWidthOpt( sal_uInt32 nWidth, bool bRel )
182 {
183 m_nWidthOpt = nWidth; m_bRelWidthOpt = bRel;
184 }
185 sal_uInt32 GetWidthOpt() const { return m_nWidthOpt; }
186 bool HasRelWidthOpt() const { return m_bRelWidthOpt; }
187};
188
189inline bool SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
190{
191 // allow for some fuzzyness
192 return (m_nPos >= rCol.m_nPos ? m_nPos - rCol.m_nPos
193 : rCol.m_nPos - m_nPos ) <= COLFUZZY;
194}
195
196inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
197{
198 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
199 // not let x==y and x<y at the same time ;-)
200 return m_nPos + COLFUZZY < rCol.m_nPos;
201}
202
204 bool operator()(std::unique_ptr<SwWriteTableCol> const & lhs, std::unique_ptr<SwWriteTableCol> const & rhs) {
205 return lhs->GetPos() < rhs->GetPos();
206 }
207};
208
209class SwWriteTableCols : public o3tl::sorted_vector<std::unique_ptr<SwWriteTableCol>, SwWriteTableColLess> {
210};
211
212class SwTable;
213
215{
216private:
218protected:
219 SwWriteTableCols m_aCols; // all columns
221
222 Color m_nBorderColor; // border color
223
224 sal_uInt16 m_nCellSpacing; // thickness of the inner border
225 sal_uInt16 m_nCellPadding; // distance of border to content
226
227 sal_uInt16 m_nBorder; // thickness of the outer border
228 sal_uInt16 m_nInnerBorder; // thickness of the inner border
229 sal_uInt32 m_nBaseWidth; // reference value for SwFormatFrameSize width
230
231 sal_uInt16 m_nHeadEndRow; // last row of the table heading
232
233 sal_uInt16 m_nLeftSub;
234 sal_uInt16 m_nRightSub;
235
236 sal_uInt32 m_nTabWidth; // absolute/relative width of the table
237
238 bool m_bRelWidths : 1; // generate relative widths?
239 bool m_bUseLayoutHeights : 1; // use layout to determine the height?
240#ifdef DBG_UTIL
242#endif
243
244 bool m_bColTags : 1;
247
248 virtual bool ShouldExpandSub( const SwTableBox *pBox,
249 bool bExpandedBefore, sal_uInt16 nDepth ) const;
250
251 void CollectTableRowsCols( tools::Long nStartRPos, sal_uInt32 nStartCPos,
252 tools::Long nParentLineHeight,
253 sal_uInt32 nParentLineWidth,
254 const SwTableLines& rLines,
255 sal_uInt16 nDepth );
256
257 void FillTableRowsCols( tools::Long nStartRPos, sal_uInt16 nStartRow,
258 sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
259 tools::Long nParentLineHeight,
260 sal_uInt32 nParentLineWidth,
261 const SwTableLines& rLines,
262 const SvxBrushItem* pLineBrush,
263 sal_uInt16 nDepth,
264 sal_uInt16 nNumOfHeaderRows );
265
266 void MergeBorders( const editeng::SvxBorderLine* pBorderLine, bool bTable );
267
268 sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol,
269 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
270 sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
271
272 sal_uInt32 GetBaseWidth() const { return m_nBaseWidth; }
273
274 bool HasRelWidths() const { return m_bRelWidths; }
275
276public:
277 static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
278
279 sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
280 sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
281 sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
282 sal_uInt16 GetPercentWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
283
284 tools::Long GetAbsHeight(tools::Long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const;
285
286 double GetAbsWidthRatio() const { return m_nTabWidth == m_nBaseWidth ? 1.0 : double(m_nTabWidth) / m_nBaseWidth; }
287protected:
288 tools::Long GetLineHeight( const SwTableLine *pLine );
289 static tools::Long GetLineHeight( const SwTableBox *pBox );
290 static const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
291 SwWriteTableRow *pRow );
292
293 sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
294 sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const;
295
296public:
297 SwWriteTable(const SwTable* pTable, const SwTableLines& rLines, tools::Long nWidth, sal_uInt32 nBWidth,
298 bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
299 sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0);
300 SwWriteTable(const SwTable* pTable, const SwHTMLTableLayout *pLayoutInfo);
301 virtual ~SwWriteTable();
302
303 const SwWriteTableRows& GetRows() const { return m_aRows; }
304
305 const SwTable* GetTable() const { return m_pTable; }
306};
307
308#endif
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:419
SwTableLine is one table row in the document model.
Definition: swtable.hxx:358
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
tools::Long GetHeight() const
Definition: wrtswtbl.hxx:81
sal_uInt32 GetWidthOpt() const
Definition: wrtswtbl.hxx:91
sal_uInt16 GetRowSpan() const
Definition: wrtswtbl.hxx:78
SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan, sal_uInt16 nCSpan, tools::Long nHght, const SvxBrushItem *pBGround)
Definition: wrtswtbl.hxx:66
bool HasPercentWidthOpt() const
Definition: wrtswtbl.hxx:92
const SwTableBox * GetBox() const
Definition: wrtswtbl.hxx:73
const SvxBrushItem * GetBackground() const
Definition: wrtswtbl.hxx:84
sal_uInt16 m_nRowSpan
Definition: wrtswtbl.hxx:59
tools::Long m_nHeight
Definition: wrtswtbl.hxx:52
sal_uInt16 GetRow() const
Definition: wrtswtbl.hxx:75
sal_uInt16 GetCol() const
Definition: wrtswtbl.hxx:76
sal_uInt16 m_nRow
Definition: wrtswtbl.hxx:56
const SvxBrushItem * m_pBackground
Definition: wrtswtbl.hxx:50
bool m_bPercentWidthOpt
Definition: wrtswtbl.hxx:62
sal_uInt32 m_nWidthOpt
Definition: wrtswtbl.hxx:54
sal_uInt16 m_nCol
Definition: wrtswtbl.hxx:57
sal_uInt16 GetColSpan() const
Definition: wrtswtbl.hxx:79
sal_uInt16 m_nColSpan
Definition: wrtswtbl.hxx:60
const SwTableBox * m_pBox
Definition: wrtswtbl.hxx:49
void SetWidthOpt(sal_uInt16 nWidth, bool bPercent)
Definition: wrtswtbl.hxx:86
bool operator<(const SwWriteTableCol &rCol) const
Definition: wrtswtbl.hxx:196
sal_uInt32 m_nPos
Definition: wrtswtbl.hxx:160
bool HasRelWidthOpt() const
Definition: wrtswtbl.hxx:186
bool operator==(const SwWriteTableCol &rCol) const
Definition: wrtswtbl.hxx:189
sal_uInt32 GetWidthOpt() const
Definition: wrtswtbl.hxx:185
sal_uInt32 m_nWidthOpt
Definition: wrtswtbl.hxx:162
SwWriteTableCol(sal_uInt32 nPosition)
Definition: wrtswtbl.cxx:76
bool HasLeftBorder() const
Definition: wrtswtbl.hxx:174
void SetWidthOpt(sal_uInt32 nWidth, bool bRel)
Definition: wrtswtbl.hxx:181
bool HasRightBorder() const
Definition: wrtswtbl.hxx:176
sal_uInt32 GetPos() const
Definition: wrtswtbl.hxx:172
sal_uInt16 m_nBottomBorder
Definition: wrtswtbl.hxx:113
const SvxBrushItem * m_pBackground
Definition: wrtswtbl.hxx:100
tools::Long m_nPos
Definition: wrtswtbl.hxx:102
const SvxBrushItem * GetBackground() const
Definition: wrtswtbl.hxx:130
SwWriteTableRow & operator=(const SwWriteTableRow &)=delete
SwWriteTableCell * AddCell(const SwTableBox *pBox, sal_uInt16 nRow, sal_uInt16 nCol, sal_uInt16 nRowSpan, sal_uInt16 nColSpan, tools::Long nHeight, const SvxBrushItem *pBackground)
Definition: wrtswtbl.cxx:62
bool HasBottomBorder() const
Definition: wrtswtbl.hxx:133
SwWriteTableCells m_Cells
all cells of the rows
Definition: wrtswtbl.hxx:99
bool mbUseLayoutHeights
Definition: wrtswtbl.hxx:103
bool operator<(const SwWriteTableRow &rRow2) const
Definition: wrtswtbl.hxx:148
const SwWriteTableCells & GetCells() const
Definition: wrtswtbl.hxx:135
SwWriteTableRow(const SwWriteTableRow &)
sal_uInt16 m_nTopBorder
Definition: wrtswtbl.hxx:112
void SetBackground(const SvxBrushItem *pBGround)
Definition: wrtswtbl.hxx:126
bool operator==(const SwWriteTableRow &rRow) const
Definition: wrtswtbl.hxx:141
bool m_bBottomBorder
Definition: wrtswtbl.hxx:116
bool HasTopBorder() const
Definition: wrtswtbl.hxx:132
bool m_bCollectBorderWidth
Definition: wrtswtbl.hxx:246
bool HasRelWidths() const
Definition: wrtswtbl.hxx:274
sal_uInt16 m_nLeftSub
Definition: wrtswtbl.hxx:233
Color m_nBorderColor
Definition: wrtswtbl.hxx:222
bool m_bLayoutExport
Definition: wrtswtbl.hxx:245
sal_uInt16 m_nHeadEndRow
Definition: wrtswtbl.hxx:231
bool m_bRelWidths
Definition: wrtswtbl.hxx:238
sal_uInt16 m_nRightSub
Definition: wrtswtbl.hxx:234
const SwWriteTableRows & GetRows() const
Definition: wrtswtbl.hxx:303
bool m_bColTags
Definition: wrtswtbl.hxx:244
const SwTable * GetTable() const
Definition: wrtswtbl.hxx:305
sal_uInt32 m_nBaseWidth
Definition: wrtswtbl.hxx:229
SwWriteTableRows m_aRows
Definition: wrtswtbl.hxx:220
bool m_bUseLayoutHeights
Definition: wrtswtbl.hxx:239
sal_uInt32 m_nTabWidth
Definition: wrtswtbl.hxx:236
sal_uInt32 GetBaseWidth() const
Definition: wrtswtbl.hxx:272
sal_uInt16 m_nCellPadding
Definition: wrtswtbl.hxx:225
const SwTable * m_pTable
Definition: wrtswtbl.hxx:217
sal_uInt16 m_nBorder
Definition: wrtswtbl.hxx:227
double GetAbsWidthRatio() const
Definition: wrtswtbl.hxx:286
sal_uInt16 m_nInnerBorder
Definition: wrtswtbl.hxx:228
SwWriteTableCols m_aCols
Definition: wrtswtbl.hxx:219
sal_uInt16 m_nCellSpacing
Definition: wrtswtbl.hxx:224
bool m_bGetLineHeightCalled
Definition: wrtswtbl.hxx:241
long Long
bool operator()(std::unique_ptr< SwWriteTableCol > const &lhs, std::unique_ptr< SwWriteTableCol > const &rhs)
Definition: wrtswtbl.hxx:204
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define COLFUZZY
Definition: wrtswtbl.hxx:42
#define ROWFUZZY
Definition: wrtswtbl.hxx:43
std::vector< std::unique_ptr< SwWriteTableCell > > SwWriteTableCells
Definition: wrtswtbl.hxx:95