bump product version to 5.0.4.1
[LibreOffice.git] / include / svx / framelinkarray.hxx
blob5b60d70ff4f3e9b5bb70efec355b0483e8f310d6
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/processor2d/baseprocessor2d.hxx>
24 #include <svx/framelink.hxx>
25 #include <svx/svxdllapi.h>
26 #include <memory>
27 #include <vector>
29 namespace svx {
30 namespace frame {
32 struct ArrayImpl;
34 /** Stores frame styles of an array of cells, supports merged ranges.
36 This class is able to store the frame styles of an array of cells and to
37 draw the entire array or parts of it to any output device.
39 Every cell contains the style of the left, right, top, bottom, top-left to
40 bottom-right, and bottom-left to top-right frame border.
42 On drawing, the thicker frame border of neighbored cells is selected
43 automatically. All borders are drawn "connected", that means, the correct
44 start and end coordinates of all lines of the borders are calculated,
45 especaially, if they are drawn together with diagonal frame borders.
47 This array fully supports merged cell ranges. In a merged range, the frame
48 borders of the top-left cell is extended to the entire range, and all other
49 cells in that range are overlapped. Again, all connected frame borders,
50 also diagonals and frame borders from adjacent merged ranges, are handled
51 automatically.
53 Additionally, a clipping range can be set. If such a range is used, all
54 frame borders outside this range are completely ignored, and are not used
55 in the connected border calculation anymore.
57 The array can be mirrored in both directions. It is possible to specify,
58 whether to mirror the double frame styles, and whether to swap diagonal
59 frame borders.
61 class SVX_DLLPUBLIC SAL_WARN_UNUSED Array
63 public:
64 /** Constructs an empty array. */
65 explicit Array();
67 /** Destructs the array. */
68 ~Array();
70 // array size and column/row indexes --------------------------------------
72 /** Reinitializes the array with the specified size. Clears all styles. */
73 void Initialize( size_t nWidth, size_t nHeight );
75 /** Returns the number of columns in the array. */
76 size_t GetColCount() const;
78 /** Returns the number of rows in the array. */
79 size_t GetRowCount() const;
81 /** Returns the number of cells in the array. */
82 size_t GetCellCount() const;
84 /** Returns the cell index from the cell address (nCol,nRow). */
85 size_t GetCellIndex( size_t nCol, size_t nRow, bool bRTL = false) const;
87 // cell border styles -----------------------------------------------------
89 /** Sets the left frame style of the cell (nCol,nRow). Ignores merged ranges. */
90 void SetCellStyleLeft( size_t nCol, size_t nRow, const Style& rStyle );
92 /** Sets the right frame style of the cell (nCol,nRow). Ignores merged ranges. */
93 void SetCellStyleRight( size_t nCol, size_t nRow, const Style& rStyle );
95 /** Sets the top frame style of the cell (nCol,nRow). Ignores merged ranges. */
96 void SetCellStyleTop( size_t nCol, size_t nRow, const Style& rStyle );
98 /** Sets the bottom frame style of the specified cell (nCol,nRow). Ignores merged ranges. */
99 void SetCellStyleBottom( size_t nCol, size_t nRow, const Style& rStyle );
101 /** Sets the top-left to bottom-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
102 void SetCellStyleTLBR( size_t nCol, size_t nRow, const Style& rStyle );
104 /** Sets the bottom-left to top-right frame style of the cell (nCol,nRow). Ignores merged ranges. */
105 void SetCellStyleBLTR( size_t nCol, size_t nRow, const Style& rStyle );
107 /** Sets both diagonal frame styles of the specified cell (nCol,nRow). Ignores merged ranges. */
108 void SetCellStyleDiag( size_t nCol, size_t nRow, const Style& rTLBR, const Style& rBLTR );
110 /** Sets the left frame style of the specified column. Ignores merged ranges. */
111 void SetColumnStyleLeft( size_t nCol, const Style& rStyle );
113 /** Sets the right frame style of the specified column. Ignores merged ranges. */
114 void SetColumnStyleRight( size_t nCol, const Style& rStyle );
116 /** Sets the top frame style of the specified row. Ignores merged ranges. */
117 void SetRowStyleTop( size_t nRow, const Style& rStyle );
119 /** Sets the bottom frame style of the specified row. Ignores merged ranges. */
120 void SetRowStyleBottom( size_t nRow, const Style& rStyle );
122 /** Returns the left frame style of the cell (nCol,nRow).
123 @param bSimple
124 true = Ignores merged ranges and neighbor cells;
125 false = Returns thicker of own left style or right style of the cell to the left.
126 Returns the style only if visible (i.e. at left border of a merged range).
127 @return
128 The left frame style or an invisible style for invalid cell addresses. */
129 const Style& GetCellStyleLeft( size_t nCol, size_t nRow, bool bSimple = false ) const;
131 /** Returns the right frame style of the cell (nCol,nRow).
132 @param bSimple
133 true = Ignores merged ranges and neighbor cells;
134 false = Returns thicker of own right style or left style of the cell to the right.
135 Returns the style only if visible (i.e. at right border of a merged range).
136 @return
137 The left frame style or an invisible style for invalid cell addresses. */
138 const Style& GetCellStyleRight( size_t nCol, size_t nRow, bool bSimple = false ) const;
140 /** Returns the top frame style of the cell (nCol,nRow).
141 @param bSimple
142 true = Ignores merged ranges and neighbor cells;
143 false = Returns thicker of own top style or bottom style of the cell above.
144 Returns the style only if visible (i.e. at top border of a merged range).
145 @return
146 The top frame style or an invisible style for invalid cell addresses. */
147 const Style& GetCellStyleTop( size_t nCol, size_t nRow, bool bSimple = false ) const;
149 /** Returns the top frame style of the cell (nCol,nRow).
150 @param bSimple
151 true = Ignores merged ranges and neighbor cells;
152 false = 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, bool bSimple = false ) const;
158 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
159 @param bSimple
160 true = Ignores merged ranges;
161 false = Returns the visible style (i.e. from top-left corner of a merged range).
162 @return
163 The top-left to bottom-right frame style or an invisible style for invalid cell addresses. */
164 const Style& GetCellStyleTLBR( size_t nCol, size_t nRow, bool bSimple = false ) const;
166 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
167 @param bSimple
168 true = Ignores merged ranges;
169 false = Returns the visible style (i.e. from top-left corner of a merged range).
170 @return
171 The bottom-left to top-right frame style or an invisible style for invalid cell addresses. */
172 const Style& GetCellStyleBLTR( size_t nCol, size_t nRow, bool bSimple = false ) const;
174 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
175 @return
176 The top-left to bottom-right frame style, if the cell is not part of
177 a merged range, or if (nCol,nRow) is the top-left corner of a merged
178 range (useful to find connected frame styles).
179 An invisible style for invalid cell addresses. */
180 const Style& GetCellStyleTL( size_t nCol, size_t nRow ) const;
182 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
183 @return
184 The top-left to bottom-right frame style, if the cell is not part of
185 a merged range, or if (nCol,nRow) is the bottom-right corner of a
186 merged range (useful to find connected frame styles).
187 An invisible style for invalid cell addresses. */
188 const Style& GetCellStyleBR( size_t nCol, size_t nRow ) const;
190 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
191 @return
192 The bottom-left to top-right frame style, if the cell is not part of
193 a merged range, or if (nCol,nRow) is the bottom-left corner of a
194 merged range (useful to find connected frame styles).
195 An invisible style for invalid cell addresses. */
196 const Style& GetCellStyleBL( size_t nCol, size_t nRow ) const;
198 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
199 @return
200 The bottom-left to top-right frame style, if the cell is not part of
201 a merged range, or if (nCol,nRow) is the top-right corner of a
202 merged range (useful to find connected frame styles).
203 An invisible style for invalid cell addresses. */
204 const Style& GetCellStyleTR( size_t nCol, size_t nRow ) const;
206 // cell merging -----------------------------------------------------------
208 /** Inserts a new merged cell range.
209 @precond The range must not intersect other merged ranges. */
210 void SetMergedRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
212 /** Sets an additional left 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 left border of the array. */
215 void SetAddMergedLeftSize( size_t nCol, size_t nRow, long nAddSize );
217 /** Sets an additional right width 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 right border of the array. */
220 void SetAddMergedRightSize( size_t nCol, size_t nRow, long nAddSize );
222 /** Sets an additional top 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 top border of the array. */
225 void SetAddMergedTopSize( size_t nCol, size_t nRow, long nAddSize );
227 /** Sets an additional bottom height for the merged range that contains (nCol,nRow).
228 @descr Useful to handle merged ranges that are not completely part of the array.
229 @precond The merged range must be at the bottom border of the array. */
230 void SetAddMergedBottomSize( size_t nCol, size_t nRow, long nAddSize );
232 /** Returns true, if the cell (nCol,nRow) is part of a merged range. */
233 bool IsMerged( size_t nCol, size_t nRow ) const;
235 /** Returns true, if the left border of the cell (nCol,nRow) is overlapped by a merged range. */
236 bool IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const;
238 /** Returns true, if the right border of the cell (nCol,nRow) is overlapped by a merged range. */
239 bool IsMergedOverlappedRight( size_t nCol, size_t nRow ) const;
241 /** Returns the address of the top-left cell of the merged range that contains (nCol,nRow). */
242 void GetMergedOrigin( size_t& rnFirstCol, size_t& rnFirstRow, size_t nCol, size_t nRow ) const;
244 /** Returns the top-left and bottom-right address of the merged range that contains (nCol,nRow). */
245 void GetMergedRange( size_t& rnFirstCol, size_t& rnFirstRow,
246 size_t& rnLastCol, size_t& rnLastRow, size_t nCol, size_t nRow ) const;
248 // clipping ---------------------------------------------------------------
250 /** Sets a clipping range.
251 @descr
252 No cell borders outside of this clipping range will be drawn. In
253 difference to simply using the DrawRange() function with the same
254 range, a clipping range causes the drawing functions to completely
255 ignore the frame styles connected from outside. This is used i.e.
256 in Calc to print single pages and to draw the print preview.
257 Partly visible diagonal frame borders in merged ranges are correctly
258 clipped too. This array can handle only one clip range at a time. */
259 void SetClipRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
261 /** Returns the rectangle (output coordinates) of the current clipping range. */
262 Rectangle GetClipRangeRectangle() const;
264 // cell coordinates -------------------------------------------------------
266 /** Sets the X output coordinate of the left column. */
267 void SetXOffset( long nXOffset );
269 /** Sets the Y output coordinate of the top row. */
270 void SetYOffset( long nYOffset );
272 /** Sets the output width of the specified column. */
273 void SetColWidth( size_t nCol, long nWidth );
275 /** Sets the output height of the specified row. */
276 void SetRowHeight( size_t nRow, long nHeight );
278 /** Sets the same output width for all columns. */
279 void SetAllColWidths( long nWidth );
281 /** Sets the same output height for all rows. */
282 void SetAllRowHeights( long nHeight );
284 /** Returns the X output coordinate of the left border of the specified column.
285 @descr The column index <array-width> returns the X output coordinate
286 of the right array border. */
287 long GetColPosition( size_t nCol ) const;
289 /** Returns the Y output coordinate of the top border of the specified row.
290 @descr The row index <array-height> returns the Y output coordinate
291 of the bottom array border. */
292 long GetRowPosition( size_t nRow ) const;
294 /** Returns the output width of the specified range of columns. */
295 long GetColWidth( size_t nFirstCol, size_t nLastCol ) const;
297 /** Returns the output height of the specified range of rows. */
298 long GetRowHeight( size_t nFirstRow, size_t nLastRow ) const;
300 /** Returns the output width of the entire array. */
301 long GetWidth() const;
303 /** Returns the output height of the entire array. */
304 long GetHeight() const;
306 /** Returns the top-left output position of the cell (nCol,nRow).
307 @param bSimple
308 true = Ignores merged ranges;
309 false = Returns output position of top-left corner of merged ranges. */
310 Point GetCellPosition( size_t nCol, size_t nRow, bool bSimple = false ) const;
312 /** Returns the output size of the cell (nCol,nRow).
313 @param bSimple
314 true = Ignores merged ranges;
315 false = Returns total output size of merged ranges. */
316 Size GetCellSize( size_t nCol, size_t nRow, bool bSimple = false ) const;
318 /** Returns the output rectangle of the cell (nCol,nRow).
319 @param bSimple
320 true = Ignores merged ranges;
321 false = Returns total output rectangle of merged ranges. */
322 Rectangle GetCellRect( size_t nCol, size_t nRow, bool bSimple = false ) const;
324 // diagonal frame borders -------------------------------------------------
326 /** Returns the angle between horizontal and diagonal border of the cell (nCol,nRow).
327 @param bSimple
328 true = Ignores merged ranges;
329 false = Returns the horizontal angle of merged ranges. */
330 double GetHorDiagAngle( size_t nCol, size_t nRow, bool bSimple = false ) const;
332 /** Returns the angle between vertical and diagonal border of the cell (nCol,nRow).
333 @param bSimple
334 true = Ignores merged ranges;
335 false = Returns the vertical angle of merged ranges. */
336 double GetVerDiagAngle( size_t nCol, size_t nRow, bool bSimple = false ) const;
338 /** Specifies whether to use polygon clipping to draw diagonal frame borders.
339 @descr
340 If enabled, diagonal frame borders are drawn interrupted, if they are
341 crossed by a double frame border. Polygon clipping is very expensive
342 and should only be used for very small output devices (i.e. in the
343 Border tab page). Default after construction is OFF. */
344 void SetUseDiagDoubleClipping( bool bSet );
346 // mirroring --------------------------------------------------------------
348 /** Mirrors the entire array horizontally.
349 @param bMirrorStyles
350 true = Swap primary and secondary line of all vertical double frame borders.
351 @param bSwapDiag
352 true = Swap top-left to bottom-right and bottom-left to top-right frame borders. */
353 void MirrorSelfX( bool bMirrorStyles, bool bSwapDiag );
355 // drawing ----------------------------------------------------------------
357 /** Draws the part of the specified range, that is inside the clipping range.
358 @param pForceColor
359 If not NULL, only this color will be used to draw all frame borders. */
360 void DrawRange( drawinglayer::processor2d::BaseProcessor2D* rDev,
361 size_t nFirstCol, size_t nFirstRow,
362 size_t nLastCol, size_t nLastRow,
363 const Color* pForceColor = 0 ) const;
365 /** Draws the part of the specified range, that is inside the clipping range.
366 @param pForceColor
367 If not NULL, only this color will be used to draw all frame borders. */
368 void DrawRange( OutputDevice& rDev,
369 size_t nFirstCol, size_t nFirstRow,
370 size_t nLastCol, size_t nLastRow,
371 const Color* pForceColor = 0 ) const;
373 /** Draws the part of the array, that is inside the clipping range.
374 @param pForceColor
375 If not NULL, only this color will be used to draw all frame borders. */
376 void DrawArray( OutputDevice& rDev, const Color* pForceColor = 0 ) const;
380 private:
381 typedef std::unique_ptr<ArrayImpl> ArrayImplPtr;
383 ArrayImplPtr mxImpl;
389 #endif
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */