lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / svx / framelinkarray.hxx
blob55938bde7ec6e6145e9597ba5fa948fb11ae876f
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/baseprimitive2d.hxx>
24 #include <svx/svxdllapi.h>
25 #include <svx/rotmodit.hxx>
26 #include <memory>
28 class Color;
30 namespace svx {
31 namespace frame {
33 struct ArrayImpl;
34 class Style;
36 /** Stores frame styles of an array of cells, supports merged ranges.
38 This class is able to store the frame styles of an array of cells and to
39 draw the entire array or parts of it to any output device.
41 Every cell contains the style of the left, right, top, bottom, top-left to
42 bottom-right, and bottom-left to top-right frame border.
44 On drawing, the thicker frame border of neighbored cells is selected
45 automatically. All borders are drawn "connected", that means, the correct
46 start and end coordinates of all lines of the borders are calculated,
47 especially, if they are drawn together with diagonal frame borders.
49 This array fully supports merged cell ranges. In a merged range, the frame
50 borders of the top-left cell is extended to the entire range, and all other
51 cells in that range are overlapped. Again, all connected frame borders,
52 also diagonals and frame borders from adjacent merged ranges, are handled
53 automatically.
55 Additionally, a clipping range can be set. If such a range is used, all
56 frame borders outside this range are completely ignored, and are not used
57 in the connected border calculation anymore.
59 The array can be mirrored in both directions. It is possible to specify,
60 whether to mirror the double frame styles, and whether to swap diagonal
61 frame borders.
63 class SAL_WARN_UNUSED SVX_DLLPUBLIC Array
65 public:
66 /** Constructs an empty array. */
67 explicit Array();
69 /** Destructs the array. */
70 ~Array();
72 // array size and column/row indexes
74 /** Reinitializes the array with the specified size. Clears all styles. */
75 void Initialize( size_t nWidth, size_t nHeight );
77 /** Returns the number of columns in the array. */
78 size_t GetColCount() const;
80 /** Returns the number of rows in the array. */
81 size_t GetRowCount() const;
83 /** Returns the number of cells in the array. */
84 size_t GetCellCount() const;
86 /** Returns the cell index from the cell address (nCol,nRow). */
87 size_t GetCellIndex( size_t nCol, size_t nRow, bool bRTL) const;
89 // cell border styles
91 /** Sets the left frame style of the cell (nCol,nRow). Ignores merged ranges. */
92 void SetCellStyleLeft( size_t nCol, size_t nRow, const Style& rStyle );
94 /** Sets the right frame style of the cell (nCol,nRow). Ignores merged ranges. */
95 void SetCellStyleRight( size_t nCol, size_t nRow, const Style& rStyle );
97 /** Sets the top frame style of the cell (nCol,nRow). Ignores merged ranges. */
98 void SetCellStyleTop( size_t nCol, size_t nRow, const Style& rStyle );
100 /** Sets the bottom frame style of the specified cell (nCol,nRow). Ignores merged ranges. */
101 void SetCellStyleBottom( size_t nCol, size_t nRow, const Style& rStyle );
103 /** Sets the top-left to bottom-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
104 void SetCellStyleTLBR( size_t nCol, size_t nRow, const Style& rStyle );
106 /** Sets the bottom-left to top-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
107 void SetCellStyleBLTR( size_t nCol, size_t nRow, const Style& rStyle );
109 /** Sets both diagonal frame styles of the specified cell (nCol,nRow). Ignores merged ranges. */
110 void SetCellStyleDiag( size_t nCol, size_t nRow, const Style& rTLBR, const Style& rBLTR );
112 /** Sets the left frame style of the specified column. Ignores merged ranges. */
113 void SetColumnStyleLeft( size_t nCol, const Style& rStyle );
115 /** Sets the right frame style of the specified column. Ignores merged ranges. */
116 void SetColumnStyleRight( size_t nCol, const Style& rStyle );
118 /** Sets the top frame style of the specified row. Ignores merged ranges. */
119 void SetRowStyleTop( size_t nRow, const Style& rStyle );
121 /** Sets the bottom frame style of the specified row. Ignores merged ranges. */
122 void SetRowStyleBottom( size_t nRow, const Style& rStyle );
124 /** Sets the rotation parameters of the cell (nCol,nRow). Ignores merged ranges. */
125 void SetCellRotation(size_t nCol, size_t nRow, SvxRotateMode eRotMode, double fOrientation);
127 /** Check if at least one cell is rotated */
128 bool HasCellRotation() const;
130 /** Returns the left frame style of the cell (nCol,nRow).
131 Returns thicker of own left style or right style of the cell to the left.
132 Returns the style only if visible (i.e. at left border of a merged range).
133 @return
134 The left frame style or an invisible style for invalid cell addresses. */
135 const Style& GetCellStyleLeft( size_t nCol, size_t nRow ) const;
137 /** Returns the right frame style of the cell (nCol,nRow).
138 Returns thicker of own right style or left style of the cell to the right.
139 Returns the style only if visible (i.e. at right border of a merged range).
140 @return
141 The left frame style or an invisible style for invalid cell addresses. */
142 const Style& GetCellStyleRight( size_t nCol, size_t nRow ) const;
144 /** Returns the top frame style of the cell (nCol,nRow).
145 Returns thicker of own top style or bottom style of the cell above.
146 Returns the style only if visible (i.e. at top border of a merged range).
147 @return
148 The top frame style or an invisible style for invalid cell addresses. */
149 const Style& GetCellStyleTop( size_t nCol, size_t nRow ) const;
151 /** Returns the top frame style of the cell (nCol,nRow).
152 Returns thicker of own top style or bottom style of the cell above.
153 Returns the style only if visible (i.e. at top border of a merged range).
154 @return
155 The top frame style or an invisible style for invalid cell addresses. */
156 const Style& GetCellStyleBottom( size_t nCol, size_t nRow ) const;
158 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
159 Ignores merged ranges;
160 @return
161 The top-left to bottom-right frame style or an invisible style for invalid cell addresses. */
162 const Style& GetCellStyleTLBR( size_t nCol, size_t nRow ) const;
164 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
165 Ignores merged ranges;
166 @return
167 The bottom-left to top-right frame style or an invisible style for invalid cell addresses. */
168 const Style& GetCellStyleBLTR( size_t nCol, size_t nRow ) const;
170 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
171 @return
172 The top-left to bottom-right frame style, if the cell is not part of
173 a merged range, or if (nCol,nRow) is the top-left corner of a merged
174 range (useful to find connected frame styles).
175 An invisible style for invalid cell addresses. */
176 const Style& GetCellStyleTL( size_t nCol, size_t nRow ) const;
178 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
179 @return
180 The top-left to bottom-right frame style, if the cell is not part of
181 a merged range, or if (nCol,nRow) is the bottom-right corner of a
182 merged range (useful to find connected frame styles).
183 An invisible style for invalid cell addresses. */
184 const Style& GetCellStyleBR( size_t nCol, size_t nRow ) const;
186 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
187 @return
188 The bottom-left to top-right frame style, if the cell is not part of
189 a merged range, or if (nCol,nRow) is the bottom-left corner of a
190 merged range (useful to find connected frame styles).
191 An invisible style for invalid cell addresses. */
192 const Style& GetCellStyleBL( size_t nCol, size_t nRow ) const;
194 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
195 @return
196 The bottom-left to top-right frame style, if the cell is not part of
197 a merged range, or if (nCol,nRow) is the top-right corner of a
198 merged range (useful to find connected frame styles).
199 An invisible style for invalid cell addresses. */
200 const Style& GetCellStyleTR( size_t nCol, size_t nRow ) const;
202 // cell merging
204 /** Inserts a new merged cell range.
205 @precond The range must not intersect other merged ranges. */
206 void SetMergedRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
208 /** Sets an additional left width for the merged range that contains (nCol,nRow).
209 @descr Useful to handle merged ranges that are not completely part of the array.
210 @precond The merged range must be at the left border of the array. */
211 void SetAddMergedLeftSize( size_t nCol, size_t nRow, long nAddSize );
213 /** Sets an additional right width for the merged range that contains (nCol,nRow).
214 @descr Useful to handle merged ranges that are not completely part of the array.
215 @precond The merged range must be at the right border of the array. */
216 void SetAddMergedRightSize( size_t nCol, size_t nRow, long nAddSize );
218 /** Sets an additional top height for the merged range that contains (nCol,nRow).
219 @descr Useful to handle merged ranges that are not completely part of the array.
220 @precond The merged range must be at the top border of the array. */
221 void SetAddMergedTopSize( size_t nCol, size_t nRow, long nAddSize );
223 /** Sets an additional bottom height for the merged range that contains (nCol,nRow).
224 @descr Useful to handle merged ranges that are not completely part of the array.
225 @precond The merged range must be at the bottom border of the array. */
226 void SetAddMergedBottomSize( size_t nCol, size_t nRow, long nAddSize );
228 /** Returns true, if the cell (nCol,nRow) is part of a merged range. */
229 bool IsMerged( size_t nCol, size_t nRow ) const;
231 /** Returns the address of the top-left cell of the merged range that contains (nCol,nRow). */
232 void GetMergedOrigin( size_t& rnFirstCol, size_t& rnFirstRow, size_t nCol, size_t nRow ) const;
234 /** Returns the top-left and bottom-right address of the merged range that contains (nCol,nRow). */
235 void GetMergedRange( size_t& rnFirstCol, size_t& rnFirstRow,
236 size_t& rnLastCol, size_t& rnLastRow, size_t nCol, size_t nRow ) const;
238 // clipping
240 /** Sets a clipping range.
241 @descr
242 No cell borders outside of this clipping range will be drawn. In
243 difference to simply using the CreateB2DPrimitiveRange() function with the same
244 range, a clipping range causes the drawing functions to completely
245 ignore the frame styles connected from outside. This is used i.e.
246 in Calc to print single pages and to draw the print preview.
247 Partly visible diagonal frame borders in merged ranges are correctly
248 clipped too. This array can handle only one clip range at a time. */
249 void SetClipRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
251 // cell coordinates
253 /** Sets the X output coordinate of the left column. */
254 void SetXOffset( long nXOffset );
256 /** Sets the Y output coordinate of the top row. */
257 void SetYOffset( long nYOffset );
259 /** Sets the output width of the specified column. */
260 void SetColWidth( size_t nCol, long nWidth );
262 /** Sets the output height of the specified row. */
263 void SetRowHeight( size_t nRow, long nHeight );
265 /** Sets the same output width for all columns. */
266 void SetAllColWidths( long nWidth );
268 /** Sets the same output height for all rows. */
269 void SetAllRowHeights( long nHeight );
271 /** Returns the X output coordinate of the left border of the specified column.
272 @descr The column index <array-width> returns the X output coordinate
273 of the right array border. */
274 long GetColPosition( size_t nCol ) const;
276 /** Returns the Y output coordinate of the top border of the specified row.
277 @descr The row index <array-height> returns the Y output coordinate
278 of the bottom array border. */
279 long GetRowPosition( size_t nRow ) const;
281 /** Returns the output width of the specified range of columns. */
282 long GetColWidth( size_t nFirstCol, size_t nLastCol ) const;
284 /** Returns the output height of the specified range of rows. */
285 long GetRowHeight( size_t nFirstRow, size_t nLastRow ) const;
287 /** Returns the output width of the entire array. */
288 long GetWidth() const;
290 /** Returns the output height of the entire array. */
291 long GetHeight() const;
293 /** Returns the output range of the cell (nCol,nRow).
294 Returns total output range of merged ranges, if bExpandMerged is true. */
295 basegfx::B2DRange GetCellRange( size_t nCol, size_t nRow, bool bExpandMerged ) const;
297 // mirroring
299 /** Mirrors the entire array horizontally. */
300 void MirrorSelfX();
302 // drawing
304 /** Draws the part of the specified range, that is inside the clipping range.
305 @param pForceColor
306 If not NULL, only this color will be used to draw all frame borders. */
307 drawinglayer::primitive2d::Primitive2DContainer CreateB2DPrimitiveRange(
308 size_t nFirstCol, size_t nFirstRow,
309 size_t nLastCol, size_t nLastRow,
310 const Color* pForceColor ) const;
312 /** Draws the part of the array, that is inside the clipping range. */
313 drawinglayer::primitive2d::Primitive2DContainer CreateB2DPrimitiveArray() const;
315 private:
316 std::unique_ptr<ArrayImpl> mxImpl;
322 #endif
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */