Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / svx / framelinkarray.hxx
blobf177215ed8c7a434f3452803ef075e58ca3b5182
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 <svx/framelink.hxx>
24 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
26 #include <vector>
27 #include <svx/svxdllapi.h>
29 #include <boost/scoped_ptr.hpp>
31 namespace svx {
32 namespace frame {
34 struct ArrayImpl;
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 especaially, 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 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 = false) 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 /** Returns the left frame style of the cell (nCol,nRow).
125 @param bSimple
126 true = Ignores merged ranges and neighbor cells;
127 false = Returns thicker of own left style or right style of the cell to the left.
128 Returns the style only if visible (i.e. at left border of a merged range).
129 @return
130 The left frame style or an invisible style for invalid cell addresses. */
131 const Style& GetCellStyleLeft( size_t nCol, size_t nRow, bool bSimple = false ) const;
133 /** Returns the right frame style of the cell (nCol,nRow).
134 @param bSimple
135 true = Ignores merged ranges and neighbor cells;
136 false = Returns thicker of own right style or left style of the cell to the right.
137 Returns the style only if visible (i.e. at right border of a merged range).
138 @return
139 The left frame style or an invisible style for invalid cell addresses. */
140 const Style& GetCellStyleRight( size_t nCol, size_t nRow, bool bSimple = false ) const;
142 /** Returns the top frame style of the cell (nCol,nRow).
143 @param bSimple
144 true = Ignores merged ranges and neighbor cells;
145 false = 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, bool bSimple = false ) const;
151 /** Returns the top frame style of the cell (nCol,nRow).
152 @param bSimple
153 true = Ignores merged ranges and neighbor cells;
154 false = Returns thicker of own top style or bottom style of the cell above.
155 Returns the style only if visible (i.e. at top border of a merged range).
156 @return
157 The top frame style or an invisible style for invalid cell addresses. */
158 const Style& GetCellStyleBottom( size_t nCol, size_t nRow, bool bSimple = false ) const;
160 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
161 @param bSimple
162 true = Ignores merged ranges;
163 false = Returns the visible style (i.e. from top-left corner of a merged range).
164 @return
165 The top-left to bottom-right frame style or an invisible style for invalid cell addresses. */
166 const Style& GetCellStyleTLBR( size_t nCol, size_t nRow, bool bSimple = false ) const;
168 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
169 @param bSimple
170 true = Ignores merged ranges;
171 false = Returns the visible style (i.e. from top-left corner of a merged range).
172 @return
173 The bottom-left to top-right frame style or an invisible style for invalid cell addresses. */
174 const Style& GetCellStyleBLTR( size_t nCol, size_t nRow, bool bSimple = false ) const;
176 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
177 @return
178 The top-left to bottom-right frame style, if the cell is not part of
179 a merged range, or if (nCol,nRow) is the top-left corner of a merged
180 range (useful to find connected frame styles).
181 An invisible style for invalid cell addresses. */
182 const Style& GetCellStyleTL( size_t nCol, size_t nRow ) const;
184 /** Returns the top-left to bottom-right frame style of the cell (nCol,nRow).
185 @return
186 The top-left to bottom-right frame style, if the cell is not part of
187 a merged range, or if (nCol,nRow) is the bottom-right corner of a
188 merged range (useful to find connected frame styles).
189 An invisible style for invalid cell addresses. */
190 const Style& GetCellStyleBR( size_t nCol, size_t nRow ) const;
192 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
193 @return
194 The bottom-left to top-right frame style, if the cell is not part of
195 a merged range, or if (nCol,nRow) is the bottom-left corner of a
196 merged range (useful to find connected frame styles).
197 An invisible style for invalid cell addresses. */
198 const Style& GetCellStyleBL( size_t nCol, size_t nRow ) const;
200 /** Returns the bottom-left to top-right frame style of the cell (nCol,nRow).
201 @return
202 The bottom-left to top-right frame style, if the cell is not part of
203 a merged range, or if (nCol,nRow) is the top-right corner of a
204 merged range (useful to find connected frame styles).
205 An invisible style for invalid cell addresses. */
206 const Style& GetCellStyleTR( size_t nCol, size_t nRow ) const;
208 // cell merging -----------------------------------------------------------
210 /** Inserts a new merged cell range.
211 @precond The range must not intersect other merged ranges. */
212 void SetMergedRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
214 /** Sets an additional left width for the merged range that contains (nCol,nRow).
215 @descr Useful to handle merged ranges that are not completely part of the array.
216 @precond The merged range must be at the left border of the array. */
217 void SetAddMergedLeftSize( size_t nCol, size_t nRow, long nAddSize );
219 /** Sets an additional right width for the merged range that contains (nCol,nRow).
220 @descr Useful to handle merged ranges that are not completely part of the array.
221 @precond The merged range must be at the right border of the array. */
222 void SetAddMergedRightSize( size_t nCol, size_t nRow, long nAddSize );
224 /** Sets an additional top height for the merged range that contains (nCol,nRow).
225 @descr Useful to handle merged ranges that are not completely part of the array.
226 @precond The merged range must be at the top border of the array. */
227 void SetAddMergedTopSize( size_t nCol, size_t nRow, long nAddSize );
229 /** Sets an additional bottom height for the merged range that contains (nCol,nRow).
230 @descr Useful to handle merged ranges that are not completely part of the array.
231 @precond The merged range must be at the bottom border of the array. */
232 void SetAddMergedBottomSize( size_t nCol, size_t nRow, long nAddSize );
234 /** Returns true, if the cell (nCol,nRow) is part of a merged range. */
235 bool IsMerged( size_t nCol, size_t nRow ) const;
237 /** Returns true, if the left border of the cell (nCol,nRow) is overlapped by a merged range. */
238 bool IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const;
240 /** Returns true, if the right border of the cell (nCol,nRow) is overlapped by a merged range. */
241 bool IsMergedOverlappedRight( size_t nCol, size_t nRow ) const;
243 /** Returns the address of the top-left cell of the merged range that contains (nCol,nRow). */
244 void GetMergedOrigin( size_t& rnFirstCol, size_t& rnFirstRow, size_t nCol, size_t nRow ) const;
246 /** Returns the top-left and bottom-right address of the merged range that contains (nCol,nRow). */
247 void GetMergedRange( size_t& rnFirstCol, size_t& rnFirstRow,
248 size_t& rnLastCol, size_t& rnLastRow, size_t nCol, size_t nRow ) const;
250 // clipping ---------------------------------------------------------------
252 /** Sets a clipping range.
253 @descr
254 No cell borders outside of this clipping range will be drawn. In
255 difference to simply using the DrawRange() function with the same
256 range, a clipping range causes the drawing functions to completely
257 ignore the frame styles connected from outside. This is used i.e.
258 in Calc to print single pages and to draw the print preview.
259 Partly visible diagonal frame borders in merged ranges are correctly
260 clipped too. This array can handle only one clip range at a time. */
261 void SetClipRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow );
263 /** Returns the rectangle (output coordinates) of the current clipping range. */
264 Rectangle GetClipRangeRectangle() const;
266 // cell coordinates -------------------------------------------------------
268 /** Sets the X output coordinate of the left column. */
269 void SetXOffset( long nXOffset );
271 /** Sets the Y output coordinate of the top row. */
272 void SetYOffset( long nYOffset );
274 /** Sets the output width of the specified column. */
275 void SetColWidth( size_t nCol, long nWidth );
277 /** Sets the output height of the specified row. */
278 void SetRowHeight( size_t nRow, long nHeight );
280 /** Sets the same output width for all columns. */
281 void SetAllColWidths( long nWidth );
283 /** Sets the same output height for all rows. */
284 void SetAllRowHeights( long nHeight );
286 /** Returns the X output coordinate of the left border of the specified column.
287 @descr The column index <array-width> returns the X output coordinate
288 of the right array border. */
289 long GetColPosition( size_t nCol ) const;
291 /** Returns the Y output coordinate of the top border of the specified row.
292 @descr The row index <array-height> returns the Y output coordinate
293 of the bottom array border. */
294 long GetRowPosition( size_t nRow ) const;
296 /** Returns the output width of the specified range of columns. */
297 long GetColWidth( size_t nFirstCol, size_t nLastCol ) const;
299 /** Returns the output height of the specified range of rows. */
300 long GetRowHeight( size_t nFirstRow, size_t nLastRow ) const;
302 /** Returns the output width of the entire array. */
303 long GetWidth() const;
305 /** Returns the output height of the entire array. */
306 long GetHeight() const;
308 /** Returns the top-left output position of the cell (nCol,nRow).
309 @param bSimple
310 true = Ignores merged ranges;
311 false = Returns output position of top-left corner of merged ranges. */
312 Point GetCellPosition( size_t nCol, size_t nRow, bool bSimple = false ) const;
314 /** Returns the output size of the cell (nCol,nRow).
315 @param bSimple
316 true = Ignores merged ranges;
317 false = Returns total output size of merged ranges. */
318 Size GetCellSize( size_t nCol, size_t nRow, bool bSimple = false ) const;
320 /** Returns the output rectangle of the cell (nCol,nRow).
321 @param bSimple
322 true = Ignores merged ranges;
323 false = Returns total output rectangle of merged ranges. */
324 Rectangle GetCellRect( size_t nCol, size_t nRow, bool bSimple = false ) const;
326 // diagonal frame borders -------------------------------------------------
328 /** Returns the angle between horizontal and diagonal border of the cell (nCol,nRow).
329 @param bSimple
330 true = Ignores merged ranges;
331 false = Returns the horizontal angle of merged ranges. */
332 double GetHorDiagAngle( size_t nCol, size_t nRow, bool bSimple = false ) const;
334 /** Returns the angle between vertical and diagonal border of the cell (nCol,nRow).
335 @param bSimple
336 true = Ignores merged ranges;
337 false = Returns the vertical angle of merged ranges. */
338 double GetVerDiagAngle( size_t nCol, size_t nRow, bool bSimple = false ) const;
340 /** Specifies whether to use polygon clipping to draw diagonal frame borders.
341 @descr
342 If enabled, diagonal frame borders are drawn interrupted, if they are
343 crossed by a double frame border. Polygon clipping is very expensive
344 and should only be used for very small output devices (i.e. in the
345 Border tab page). Default after construction is OFF. */
346 void SetUseDiagDoubleClipping( bool bSet );
348 // mirroring --------------------------------------------------------------
350 /** Mirrors the entire array horizontally.
351 @param bMirrorStyles
352 true = Swap primary and secondary line of all vertical double frame borders.
353 @param bSwapDiag
354 true = Swap top-left to bottom-right and bottom-left to top-right frame borders. */
355 void MirrorSelfX( bool bMirrorStyles, bool bSwapDiag );
357 // drawing ----------------------------------------------------------------
359 /** Draws the part of the specified range, that is inside the clipping range.
360 @param pForceColor
361 If not NULL, only this color will be used to draw all frame borders. */
362 void DrawRange( drawinglayer::processor2d::BaseProcessor2D* rDev,
363 size_t nFirstCol, size_t nFirstRow,
364 size_t nLastCol, size_t nLastRow,
365 const Color* pForceColor = 0 ) const;
367 /** Draws the part of the specified range, that is inside the clipping range.
368 @param pForceColor
369 If not NULL, only this color will be used to draw all frame borders. */
370 void DrawRange( OutputDevice& rDev,
371 size_t nFirstCol, size_t nFirstRow,
372 size_t nLastCol, size_t nLastRow,
373 const Color* pForceColor = 0 ) const;
375 /** Draws the part of the array, that is inside the clipping range.
376 @param pForceColor
377 If not NULL, only this color will be used to draw all frame borders. */
378 void DrawArray( OutputDevice& rDev, const Color* pForceColor = 0 ) const;
382 private:
383 typedef boost::scoped_ptr<ArrayImpl> ArrayImplPtr;
385 ArrayImplPtr mxImpl;
390 } // namespace frame
391 } // namespace svx
393 #endif
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */