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 .
20 #ifndef INCLUDED_SVX_FRAMELINKARRAY_HXX
21 #define INCLUDED_SVX_FRAMELINKARRAY_HXX
23 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
24 #include <svx/svxdllapi.h>
25 #include <svx/rotmodit.hxx>
30 namespace svx::frame
{
35 /** Stores frame styles of an array of cells, supports merged ranges.
37 This class is able to store the frame styles of an array of cells and to
38 draw the entire array or parts of it to any output device.
40 Every cell contains the style of the left, right, top, bottom, top-left to
41 bottom-right, and bottom-left to top-right frame border.
43 On drawing, the thicker frame border of neighbored cells is selected
44 automatically. All borders are drawn "connected", that means, the correct
45 start and end coordinates of all lines of the borders are calculated,
46 especially, if they are drawn together with diagonal frame borders.
48 This array fully supports merged cell ranges. In a merged range, the frame
49 borders of the top-left cell is extended to the entire range, and all other
50 cells in that range are overlapped. Again, all connected frame borders,
51 also diagonals and frame borders from adjacent merged ranges, are handled
54 Additionally, a clipping range can be set. If such a range is used, all
55 frame borders outside this range are completely ignored, and are not used
56 in the connected border calculation anymore.
58 The array can be mirrored in both directions. It is possible to specify,
59 whether to mirror the double frame styles, and whether to swap diagonal
62 class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC Array
65 /** Constructs an empty array. */
68 /** Destructs the array. */
71 // array size and column/row indexes
73 /** Reinitializes the array with the specified size. Clears all styles. */
74 void Initialize( size_t nWidth
, size_t nHeight
);
76 /** Returns the number of columns in the array. */
77 size_t GetColCount() const;
79 /** Returns the number of rows in the array. */
80 size_t GetRowCount() const;
82 /** Returns the number of cells in the array. */
83 size_t GetCellCount() const;
85 /** Returns the cell index from the cell address (nCol,nRow). */
86 size_t GetCellIndex( size_t nCol
, size_t nRow
, bool bRTL
) const;
90 /** Sets the left frame style of the cell (nCol,nRow). Ignores merged ranges. */
91 void SetCellStyleLeft( size_t nCol
, size_t nRow
, const Style
& rStyle
);
93 /** Sets the right frame style of the cell (nCol,nRow). Ignores merged ranges. */
94 void SetCellStyleRight( size_t nCol
, size_t nRow
, const Style
& rStyle
);
96 /** Sets the top frame style of the cell (nCol,nRow). Ignores merged ranges. */
97 void SetCellStyleTop( size_t nCol
, size_t nRow
, const Style
& rStyle
);
99 /** Sets the bottom frame style of the specified cell (nCol,nRow). Ignores merged ranges. */
100 void SetCellStyleBottom( size_t nCol
, size_t nRow
, const Style
& rStyle
);
102 /** Sets the top-left to bottom-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
103 void SetCellStyleTLBR( size_t nCol
, size_t nRow
, const Style
& rStyle
);
105 /** Sets the bottom-left to top-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
106 void SetCellStyleBLTR( size_t nCol
, size_t nRow
, const Style
& rStyle
);
108 /** Sets both diagonal frame styles of the specified cell (nCol,nRow). Ignores merged ranges. */
109 void SetCellStyleDiag( size_t nCol
, size_t nRow
, const Style
& rTLBR
, const Style
& rBLTR
);
111 /** Sets the left frame style of the specified column. Ignores merged ranges. */
112 void SetColumnStyleLeft( size_t nCol
, const Style
& rStyle
);
114 /** Sets the right frame style of the specified column. Ignores merged ranges. */
115 void SetColumnStyleRight( size_t nCol
, const Style
& rStyle
);
117 /** Sets the top frame style of the specified row. Ignores merged ranges. */
118 void SetRowStyleTop( size_t nRow
, const Style
& rStyle
);
120 /** Sets the bottom frame style of the specified row. Ignores merged ranges. */
121 void SetRowStyleBottom( size_t nRow
, const Style
& rStyle
);
123 /** Sets the rotation parameters of the cell (nCol,nRow). Ignores merged ranges. */
124 void SetCellRotation(size_t nCol
, size_t nRow
, SvxRotateMode eRotMode
, double fOrientation
);
126 /** Check if at least one cell is rotated */
127 bool HasCellRotation() const;
129 /** Returns the left frame style of the cell (nCol,nRow).
130 Returns thicker of own left style or right style of the cell to the left.
131 Returns the style only if visible (i.e. at left border of a merged range).
133 The left frame style or an invisible style for invalid cell addresses. */
134 const Style
& GetCellStyleLeft( size_t nCol
, size_t nRow
) const;
136 /** Returns the right frame style of the cell (nCol,nRow).
137 Returns thicker of own right style or left style of the cell to the right.
138 Returns the style only if visible (i.e. at right border of a merged range).
140 The left frame style or an invisible style for invalid cell addresses. */
141 const Style
& GetCellStyleRight( size_t nCol
, size_t nRow
) const;
143 /** Returns the top frame style of the cell (nCol,nRow).
144 Returns thicker of own top style or bottom style of the cell above.
145 Returns the style only if visible (i.e. at top border of a merged range).
147 The top frame style or an invisible style for invalid cell addresses. */
148 const Style
& GetCellStyleTop( size_t nCol
, size_t nRow
) const;
150 /** Returns the top frame style of the cell (nCol,nRow).
151 Returns thicker of own top style or bottom style of the cell above.
152 Returns the style only if visible (i.e. at top border of a merged range).
154 The top frame style or an invisible style for invalid cell addresses. */
155 const Style
& GetCellStyleBottom( size_t nCol
, size_t nRow
) const;
157 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
158 Ignores merged ranges;
160 The top-left to bottom-right frame style or an invisible style for invalid cell addresses. */
161 const Style
& GetCellStyleTLBR( size_t nCol
, size_t nRow
) const;
163 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
164 Ignores merged ranges;
166 The bottom-left to top-right frame style or an invisible style for invalid cell addresses. */
167 const Style
& GetCellStyleBLTR( size_t nCol
, size_t nRow
) const;
169 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
171 The top-left to bottom-right frame style, if the cell is not part of
172 a merged range, or if (nCol,nRow) is the top-left corner of a merged
173 range (useful to find connected frame styles).
174 An invisible style for invalid cell addresses. */
175 const Style
& GetCellStyleTL( size_t nCol
, size_t nRow
) const;
177 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
179 The top-left to bottom-right frame style, if the cell is not part of
180 a merged range, or if (nCol,nRow) is the bottom-right corner of a
181 merged range (useful to find connected frame styles).
182 An invisible style for invalid cell addresses. */
183 const Style
& GetCellStyleBR( size_t nCol
, size_t nRow
) const;
185 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
187 The bottom-left to top-right frame style, if the cell is not part of
188 a merged range, or if (nCol,nRow) is the bottom-left corner of a
189 merged range (useful to find connected frame styles).
190 An invisible style for invalid cell addresses. */
191 const Style
& GetCellStyleBL( size_t nCol
, size_t nRow
) const;
193 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
195 The bottom-left to top-right frame style, if the cell is not part of
196 a merged range, or if (nCol,nRow) is the top-right corner of a
197 merged range (useful to find connected frame styles).
198 An invisible style for invalid cell addresses. */
199 const Style
& GetCellStyleTR( size_t nCol
, size_t nRow
) const;
203 /** Inserts a new merged cell range.
204 @precond The range must not intersect other merged ranges. */
205 void SetMergedRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
);
207 /** Sets an additional left width for the merged range that contains (nCol,nRow).
208 @descr Useful to handle merged ranges that are not completely part of the array.
209 @precond The merged range must be at the left border of the array. */
210 void SetAddMergedLeftSize( size_t nCol
, size_t nRow
, tools::Long nAddSize
);
212 /** Sets an additional right width for the merged range that contains (nCol,nRow).
213 @descr Useful to handle merged ranges that are not completely part of the array.
214 @precond The merged range must be at the right border of the array. */
215 void SetAddMergedRightSize( size_t nCol
, size_t nRow
, tools::Long nAddSize
);
217 /** Sets an additional top height for the merged range that contains (nCol,nRow).
218 @descr Useful to handle merged ranges that are not completely part of the array.
219 @precond The merged range must be at the top border of the array. */
220 void SetAddMergedTopSize( size_t nCol
, size_t nRow
, tools::Long nAddSize
);
222 /** Sets an additional bottom height for the merged range that contains (nCol,nRow).
223 @descr Useful to handle merged ranges that are not completely part of the array.
224 @precond The merged range must be at the bottom border of the array. */
225 void SetAddMergedBottomSize( size_t nCol
, size_t nRow
, tools::Long nAddSize
);
227 /** Returns true, if the cell (nCol,nRow) is part of a merged range. */
228 bool IsMerged( size_t nCol
, size_t nRow
) const;
230 /** Returns the address of the top-left cell of the merged range that contains (nCol,nRow). */
231 void GetMergedOrigin( size_t& rnFirstCol
, size_t& rnFirstRow
, size_t nCol
, size_t nRow
) const;
233 /** Returns the top-left and bottom-right address of the merged range that contains (nCol,nRow). */
234 void GetMergedRange( size_t& rnFirstCol
, size_t& rnFirstRow
,
235 size_t& rnLastCol
, size_t& rnLastRow
, size_t nCol
, size_t nRow
) const;
239 /** Sets a clipping range.
241 No cell borders outside of this clipping range will be drawn. In
242 difference to simply using the CreateB2DPrimitiveRange() function with the same
243 range, a clipping range causes the drawing functions to completely
244 ignore the frame styles connected from outside. This is used i.e.
245 in Calc to print single pages and to draw the print preview.
246 Partly visible diagonal frame borders in merged ranges are correctly
247 clipped too. This array can handle only one clip range at a time. */
248 void SetClipRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
);
252 /** Sets the X output coordinate of the left column. */
253 void SetXOffset( tools::Long nXOffset
);
255 /** Sets the Y output coordinate of the top row. */
256 void SetYOffset( tools::Long nYOffset
);
258 /** Sets the output width of the specified column. */
259 void SetColWidth( size_t nCol
, tools::Long nWidth
);
261 /** Sets the output height of the specified row. */
262 void SetRowHeight( size_t nRow
, tools::Long nHeight
);
264 /** Sets the same output width for all columns. */
265 void SetAllColWidths( tools::Long nWidth
);
267 /** Sets the same output height for all rows. */
268 void SetAllRowHeights( tools::Long nHeight
);
270 /** Returns the X output coordinate of the left border of the specified column.
271 @descr The column index <array-width> returns the X output coordinate
272 of the right array border. */
273 tools::Long
GetColPosition( size_t nCol
) const;
275 /** Returns the Y output coordinate of the top border of the specified row.
276 @descr The row index <array-height> returns the Y output coordinate
277 of the bottom array border. */
278 tools::Long
GetRowPosition( size_t nRow
) const;
280 /** Returns the output width of the specified range of columns. */
281 tools::Long
GetColWidth( size_t nFirstCol
, size_t nLastCol
) const;
283 /** Returns the output height of the specified range of rows. */
284 tools::Long
GetRowHeight( size_t nFirstRow
, size_t nLastRow
) const;
286 /** Returns the output width of the entire array. */
287 tools::Long
GetWidth() const;
289 /** Returns the output height of the entire array. */
290 tools::Long
GetHeight() const;
292 /** Returns the output range of the cell (nCol,nRow).
293 Returns total output range of merged ranges, if bExpandMerged is true. */
294 basegfx::B2DRange
GetCellRange( size_t nCol
, size_t nRow
, bool bExpandMerged
) const;
296 // return output range of given row/col range in logical coordinates
297 basegfx::B2DRange
GetB2DRange( sal_Int32 nFirstCol
, sal_Int32 nFirstRow
, sal_Int32 nLastCol
, sal_Int32 nLastRow
) const;
301 /** Mirrors the entire array horizontally. */
306 /** Draws the part of the specified range, that is inside the clipping range.
308 If not NULL, only this color will be used to draw all frame borders. */
309 drawinglayer::primitive2d::Primitive2DContainer
CreateB2DPrimitiveRange(
310 size_t nFirstCol
, size_t nFirstRow
,
311 size_t nLastCol
, size_t nLastRow
,
312 const Color
* pForceColor
) const;
314 /** Draws the part of the array, that is inside the clipping range. */
315 drawinglayer::primitive2d::Primitive2DContainer
CreateB2DPrimitiveArray() const;
318 std::unique_ptr
<ArrayImpl
> mxImpl
;
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */