Revert "reduce symbol visibility in sw"
[LibreOffice.git] / sw / source / filter / inc / wrtswtbl.hxx
blob83a40c0f681d96aebf6980885bf7a137b0054bca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
22 #include <tools/color.hxx>
23 #include <tools/long.hxx>
24 #include <o3tl/sorted_vector.hxx>
26 #include <swdllapi.h>
28 #include <memory>
29 #include <vector>
30 #include <climits>
32 class SwTableBox;
33 class SwTableLine;
34 class SwTableLines;
35 class SwHTMLTableLayout;
36 class SvxBrushItem;
38 namespace editeng { class SvxBorderLine; }
40 // Code from the HTML filter for writing of tables
42 #define COLFUZZY 20
43 #define ROWFUZZY 20
44 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
45 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
47 class SW_DLLPUBLIC SwWriteTableCell
49 const SwTableBox *m_pBox; // SwTableBox of the cell
50 const SvxBrushItem *m_pBackground; // inherited background of a row
52 tools::Long m_nHeight; // fix/minimum height of a row
54 sal_uInt32 m_nWidthOpt; // width from option;
56 sal_uInt16 m_nRow; // start row
57 sal_uInt16 m_nCol; // start column
59 sal_uInt16 m_nRowSpan; // spanned rows
60 sal_uInt16 m_nColSpan; // spanned columns
62 bool m_bPercentWidthOpt;
64 public:
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 )
73 const SwTableBox *GetBox() const { return m_pBox; }
75 sal_uInt16 GetRow() const { return m_nRow; }
76 sal_uInt16 GetCol() const { return m_nCol; }
78 sal_uInt16 GetRowSpan() const { return m_nRowSpan; }
79 sal_uInt16 GetColSpan() const { return m_nColSpan; }
81 tools::Long GetHeight() const { return m_nHeight; }
82 sal_Int16 GetVertOri() const;
84 const SvxBrushItem *GetBackground() const { return m_pBackground; }
86 void SetWidthOpt( sal_uInt16 nWidth, bool bPercent )
88 m_nWidthOpt = nWidth; m_bPercentWidthOpt = bPercent;
91 sal_uInt32 GetWidthOpt() const { return m_nWidthOpt; }
92 bool HasPercentWidthOpt() const { return m_bPercentWidthOpt; }
95 typedef std::vector<std::unique_ptr<SwWriteTableCell>> SwWriteTableCells;
97 class SwWriteTableRow final
99 SwWriteTableCells m_Cells; ///< all cells of the rows
100 const SvxBrushItem *m_pBackground; // background
102 tools::Long m_nPos; // end position (twips) of the row
103 bool mbUseLayoutHeights;
104 bool m_bTopBorder; // which borders are there?
105 bool m_bBottomBorder;
107 SwWriteTableRow & operator= (const SwWriteTableRow &) = delete;
109 // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
110 SwWriteTableRow( const SwWriteTableRow & );
112 public:
114 SwWriteTableRow( tools::Long nPos, bool bUseLayoutHeights );
116 SwWriteTableCell *AddCell( const SwTableBox *pBox,
117 sal_uInt16 nRow, sal_uInt16 nCol,
118 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
119 tools::Long nHeight,
120 const SvxBrushItem *pBackground );
122 void SetBackground( const SvxBrushItem *pBGround )
124 m_pBackground = pBGround;
126 const SvxBrushItem *GetBackground() const { return m_pBackground; }
128 bool HasTopBorder() const { return m_bTopBorder; }
129 void SetTopBorder(bool value) { m_bTopBorder = value; }
130 bool HasBottomBorder() const { return m_bBottomBorder; }
131 void SetBottomBorder(bool value) { m_bBottomBorder = value; }
133 const SwWriteTableCells& GetCells() const { return m_Cells; }
135 inline bool operator==( const SwWriteTableRow& rRow ) const;
136 inline bool operator<( const SwWriteTableRow& rRow2 ) const;
139 inline bool SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
141 // allow for some fuzzyness
142 return (m_nPos >= rRow.m_nPos ? m_nPos - rRow.m_nPos : rRow.m_nPos - m_nPos ) <=
143 (mbUseLayoutHeights ? 0 : ROWFUZZY);
146 inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
148 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
149 // not let x==y and x<y at the same time ;-)
150 return m_nPos < rRow.m_nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
153 using SwWriteTableRows
154 = o3tl::sorted_vector< std::unique_ptr<SwWriteTableRow>, o3tl::less_ptr_to >;
156 class SwWriteTableCol
158 sal_uInt32 m_nPos; // end position of the column
160 sal_uInt32 m_nWidthOpt;
162 bool m_bRelWidthOpt : 1;
164 public:
165 bool m_bLeftBorder : 1; // which borders are there?
166 bool m_bRightBorder : 1;
168 SwWriteTableCol( sal_uInt32 nPosition );
170 sal_uInt32 GetPos() const { return m_nPos; }
172 bool HasLeftBorder() const { return m_bLeftBorder; }
174 bool HasRightBorder() const { return m_bRightBorder; }
176 inline bool operator==( const SwWriteTableCol& rCol ) const;
177 inline bool operator<( const SwWriteTableCol& rCol ) const;
179 void SetWidthOpt( sal_uInt32 nWidth, bool bRel )
181 m_nWidthOpt = nWidth; m_bRelWidthOpt = bRel;
183 sal_uInt32 GetWidthOpt() const { return m_nWidthOpt; }
184 bool HasRelWidthOpt() const { return m_bRelWidthOpt; }
187 inline bool SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
189 // allow for some fuzzyness
190 return (m_nPos >= rCol.m_nPos ? m_nPos - rCol.m_nPos
191 : rCol.m_nPos - m_nPos ) <= COLFUZZY;
194 inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
196 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
197 // not let x==y and x<y at the same time ;-)
198 return m_nPos + COLFUZZY < rCol.m_nPos;
201 struct SwWriteTableColLess {
202 template <typename T1, typename T2>
203 requires o3tl::is_reference_to<T1, SwWriteTableCol>
204 && o3tl::is_reference_to<T2, SwWriteTableCol>
205 bool operator()(T1 const& lhs, T2 const& rhs) const {
206 return lhs->GetPos() < rhs->GetPos();
210 class SwWriteTableCols : public o3tl::sorted_vector<std::unique_ptr<SwWriteTableCol>, SwWriteTableColLess> {
213 class SwTable;
215 class SW_DLLPUBLIC SwWriteTable
217 private:
218 const SwTable* m_pTable;
219 protected:
220 SwWriteTableCols m_aCols; // all columns
221 SwWriteTableRows m_aRows; // all rows
223 Color m_nBorderColor; // border color
225 sal_uInt16 m_nCellSpacing; // thickness of the inner border
226 sal_uInt16 m_nCellPadding; // distance of border to content
228 sal_uInt16 m_nBorder; // thickness of the outer border
229 sal_uInt16 m_nInnerBorder; // thickness of the inner border
230 sal_uInt32 m_nBaseWidth; // reference value for SwFormatFrameSize width
232 sal_uInt16 m_nHeadEndRow; // last row of the table heading
234 sal_uInt16 m_nLeftSub;
235 sal_uInt16 m_nRightSub;
237 sal_uInt32 m_nTabWidth; // absolute/relative width of the table
239 bool m_bRelWidths : 1; // generate relative widths?
240 bool m_bUseLayoutHeights : 1; // use layout to determine the height?
241 #ifdef DBG_UTIL
242 bool m_bGetLineHeightCalled : 1;
243 #endif
245 bool m_bColTags : 1;
246 bool m_bLayoutExport : 1;
247 bool m_bCollectBorderWidth : 1;
249 virtual bool ShouldExpandSub( const SwTableBox *pBox,
250 bool bExpandedBefore, sal_uInt16 nDepth ) const;
252 void CollectTableRowsCols( tools::Long nStartRPos, sal_uInt32 nStartCPos,
253 tools::Long nParentLineHeight,
254 sal_uInt32 nParentLineWidth,
255 const SwTableLines& rLines,
256 sal_uInt16 nDepth );
258 void FillTableRowsCols( tools::Long nStartRPos, sal_uInt16 nStartRow,
259 sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
260 tools::Long nParentLineHeight,
261 sal_uInt32 nParentLineWidth,
262 const SwTableLines& rLines,
263 const SvxBrushItem* pLineBrush,
264 sal_uInt16 nDepth,
265 sal_uInt16 nNumOfHeaderRows );
267 void MergeBorders( const editeng::SvxBorderLine* pBorderLine, bool bTable );
269 sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol,
270 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
271 sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
273 sal_uInt32 GetBaseWidth() const { return m_nBaseWidth; }
275 bool HasRelWidths() const { return m_bRelWidths; }
277 public:
278 static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
280 sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
281 sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
282 sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
283 sal_uInt16 GetPercentWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
285 tools::Long GetAbsHeight(tools::Long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const;
287 double GetAbsWidthRatio() const { return m_nTabWidth == m_nBaseWidth ? 1.0 : double(m_nTabWidth) / m_nBaseWidth; }
288 protected:
289 tools::Long GetLineHeight( const SwTableLine *pLine );
290 static tools::Long GetLineHeight( const SwTableBox *pBox );
291 static const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
292 SwWriteTableRow *pRow );
294 sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
295 sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const;
297 public:
298 SwWriteTable(const SwTable* pTable, const SwTableLines& rLines, tools::Long nWidth, sal_uInt32 nBWidth,
299 bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
300 sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0);
301 SwWriteTable(const SwTable* pTable, const SwHTMLTableLayout *pLayoutInfo);
302 virtual ~SwWriteTable();
304 const SwWriteTableRows& GetRows() const { return m_aRows; }
306 const SwTable* GetTable() const { return m_pTable; }
309 #endif
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */