Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svx / framelinkarray.hxx
blob10c8f4da2d1ccda5e1f056d7fa4ebd91f0662305
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 .
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>
26 #include <memory>
28 class Color;
30 namespace svx::frame {
32 struct ArrayImpl;
33 class Style;
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
52 automatically.
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
60 frame borders.
62 class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC Array
64 public:
65 /** Constructs an empty array. */
66 explicit Array();
68 /** Destructs the array. */
69 ~Array();
71 // array size and column/row indexes
73 /** Reinitializes the array with the specified size. Clears all styles. */
74 void Initialize( sal_Int32 nWidth, sal_Int32 nHeight );
76 /** Returns the number of columns in the array. */
77 sal_Int32 GetColCount() const;
79 /** Returns the number of rows in the array. */
80 sal_Int32 GetRowCount() const;
82 /** Returns the number of cells in the array. */
83 sal_Int32 GetCellCount() const;
85 /** Returns the cell index from the cell address (nCol,nRow). */
86 sal_Int32 GetCellIndex( sal_Int32 nCol, sal_Int32 nRow, bool bRTL) const;
88 // cell border styles
90 /** Sets the left frame style of the cell (nCol,nRow). Ignores merged ranges. */
91 void SetCellStyleLeft( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle );
93 /** Sets the right frame style of the cell (nCol,nRow). Ignores merged ranges. */
94 void SetCellStyleRight( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle );
96 /** Sets the top frame style of the cell (nCol,nRow). Ignores merged ranges. */
97 void SetCellStyleTop( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle );
99 /** Sets the bottom frame style of the specified cell (nCol,nRow). Ignores merged ranges. */
100 void SetCellStyleBottom( sal_Int32 nCol, sal_Int32 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( sal_Int32 nCol, sal_Int32 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( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle );
108 /** Sets both diagonal frame styles of the specified cell (nCol,nRow). Ignores merged ranges. */
109 void SetCellStyleDiag( sal_Int32 nCol, sal_Int32 nRow, const Style& rTLBR, const Style& rBLTR );
111 /** Sets the left frame style of the specified column. Ignores merged ranges. */
112 void SetColumnStyleLeft( sal_Int32 nCol, const Style& rStyle );
114 /** Sets the right frame style of the specified column. Ignores merged ranges. */
115 void SetColumnStyleRight( sal_Int32 nCol, const Style& rStyle );
117 /** Sets the top frame style of the specified row. Ignores merged ranges. */
118 void SetRowStyleTop( sal_Int32 nRow, const Style& rStyle );
120 /** Sets the bottom frame style of the specified row. Ignores merged ranges. */
121 void SetRowStyleBottom( sal_Int32 nRow, const Style& rStyle );
123 /** Sets the rotation parameters of the cell (nCol,nRow). Ignores merged ranges. */
124 void SetCellRotation(sal_Int32 nCol, sal_Int32 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).
132 @return
133 The left frame style or an invisible style for invalid cell addresses. */
134 const Style& GetCellStyleLeft( sal_Int32 nCol, sal_Int32 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).
139 @return
140 The left frame style or an invisible style for invalid cell addresses. */
141 const Style& GetCellStyleRight( sal_Int32 nCol, sal_Int32 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).
146 @return
147 The top frame style or an invisible style for invalid cell addresses. */
148 const Style& GetCellStyleTop( sal_Int32 nCol, sal_Int32 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).
153 @return
154 The top frame style or an invisible style for invalid cell addresses. */
155 const Style& GetCellStyleBottom( sal_Int32 nCol, sal_Int32 nRow ) const;
157 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
158 Ignores merged ranges;
159 @return
160 The top-left to bottom-right frame style or an invisible style for invalid cell addresses. */
161 const Style& GetCellStyleTLBR( sal_Int32 nCol, sal_Int32 nRow ) const;
163 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
164 Ignores merged ranges;
165 @return
166 The bottom-left to top-right frame style or an invisible style for invalid cell addresses. */
167 const Style& GetCellStyleBLTR( sal_Int32 nCol, sal_Int32 nRow ) const;
169 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
170 @return
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( sal_Int32 nCol, sal_Int32 nRow ) const;
177 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
178 @return
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( sal_Int32 nCol, sal_Int32 nRow ) const;
185 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
186 @return
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( sal_Int32 nCol, sal_Int32 nRow ) const;
193 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
194 @return
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( sal_Int32 nCol, sal_Int32 nRow ) const;
201 // cell merging
203 /** Inserts a new merged cell range.
204 @precond The range must not intersect other merged ranges. */
205 void SetMergedRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 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( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 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( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 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( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 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( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nAddSize );
227 /** Returns true, if the cell (nCol,nRow) is part of a merged range. */
228 bool IsMerged( sal_Int32 nCol, sal_Int32 nRow ) const;
230 /** Returns the address of the top-left cell of the merged range that contains (nCol,nRow). */
231 void GetMergedOrigin( sal_Int32& rnFirstCol, sal_Int32& rnFirstRow, sal_Int32 nCol, sal_Int32 nRow ) const;
233 /** Returns the top-left and bottom-right address of the merged range that contains (nCol,nRow). */
234 void GetMergedRange( sal_Int32& rnFirstCol, sal_Int32& rnFirstRow,
235 sal_Int32& rnLastCol, sal_Int32& rnLastRow, sal_Int32 nCol, sal_Int32 nRow ) const;
237 // clipping
239 /** Sets a clipping range.
240 @descr
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( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow );
250 // cell coordinates
252 /** Sets the X output coordinate of the left column. */
253 void SetXOffset( sal_Int32 nXOffset );
255 /** Sets the Y output coordinate of the top row. */
256 void SetYOffset( sal_Int32 nYOffset );
258 /** Sets the output width of the specified column. */
259 void SetColWidth( sal_Int32 nCol, sal_Int32 nWidth );
261 /** Sets the output height of the specified row. */
262 void SetRowHeight( sal_Int32 nRow, sal_Int32 nHeight );
264 /** Sets the same output width for all columns. */
265 void SetAllColWidths( sal_Int32 nWidth );
267 /** Sets the same output height for all rows. */
268 void SetAllRowHeights( sal_Int32 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 sal_Int32 GetColPosition( sal_Int32 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 sal_Int32 GetRowPosition( sal_Int32 nRow ) const;
280 /** Returns the output width of the specified range of columns. */
281 sal_Int32 GetColWidth( sal_Int32 nFirstCol, sal_Int32 nLastCol ) const;
283 /** Returns the output height of the specified range of rows. */
284 sal_Int32 GetRowHeight( sal_Int32 nFirstRow, sal_Int32 nLastRow ) const;
286 /** Returns the output width of the entire array. */
287 sal_Int32 GetWidth() const;
289 /** Returns the output height of the entire array. */
290 sal_Int32 GetHeight() const;
292 /** Returns the output range of the cell (nCol,nRow).
293 Returns total output range of merged ranges. */
294 basegfx::B2DRange GetCellRange( sal_Int32 nCol, sal_Int32 nRow ) 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;
299 // mirroring
301 /** Mirrors the entire array horizontally. */
302 void MirrorSelfX();
304 // drawing
306 /** Draws the part of the specified range, that is inside the clipping range.
307 @param pForceColor
308 If not NULL, only this color will be used to draw all frame borders. */
309 drawinglayer::primitive2d::Primitive2DContainer CreateB2DPrimitiveRange(
310 sal_Int32 nFirstCol, sal_Int32 nFirstRow,
311 sal_Int32 nLastCol, sal_Int32 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;
317 private:
318 std::unique_ptr<ArrayImpl> mxImpl;
324 #endif
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */