a11y: Simplify OCommonAccessibleComponent::getAccessibleIndexInParent
[LibreOffice.git] / svx / source / dialog / framelinkarray.cxx
blob02332d5e6de841c2655652a3f5abdc596ef30847
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 #include <svx/framelinkarray.hxx>
22 #include <math.h>
23 #include <vector>
24 #include <unordered_set>
25 #include <algorithm>
26 #include <o3tl/hash_combine.hxx>
27 #include <tools/debug.hxx>
28 #include <tools/gen.hxx>
29 #include <vcl/canvastools.hxx>
30 #include <svx/sdr/primitive2d/sdrframeborderprimitive2d.hxx>
31 #include <basegfx/matrix/b2dhommatrixtools.hxx>
32 #include <basegfx/polygon/b2dpolygonclipper.hxx>
34 //#define OPTICAL_CHECK_CLIPRANGE_FOR_MERGED_CELL
35 #ifdef OPTICAL_CHECK_CLIPRANGE_FOR_MERGED_CELL
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
38 #endif
40 namespace svx::frame {
42 namespace {
44 class Cell final
46 private:
47 Style maLeft;
48 Style maRight;
49 Style maTop;
50 Style maBottom;
51 Style maTLBR;
52 Style maBLTR;
54 basegfx::B2DHomMatrix HelperCreateB2DHomMatrixFromB2DRange(
55 const basegfx::B2DRange& rRange ) const;
57 public:
58 sal_Int32 mnAddLeft;
59 sal_Int32 mnAddRight;
60 sal_Int32 mnAddTop;
61 sal_Int32 mnAddBottom;
63 SvxRotateMode meRotMode;
64 double mfOrientation;
66 bool mbMergeOrig;
67 bool mbOverlapX;
68 bool mbOverlapY;
70 public:
71 explicit Cell();
72 explicit Cell(const Cell&) = default;
74 bool operator==( const Cell& ) const;
75 size_t hashCode() const;
77 void SetStyleLeft(const Style& rStyle) { maLeft = rStyle; }
78 void SetStyleRight(const Style& rStyle) { maRight = rStyle; }
79 void SetStyleTop(const Style& rStyle) { maTop = rStyle; }
80 void SetStyleBottom(const Style& rStyle) { maBottom = rStyle; }
81 void SetStyleTLBR(const Style& rStyle) { maTLBR = rStyle; }
82 void SetStyleBLTR(const Style& rStyle) { maBLTR = rStyle; }
84 const Style& GetStyleLeft() const { return maLeft; }
85 const Style& GetStyleRight() const { return maRight; }
86 const Style& GetStyleTop() const { return maTop; }
87 const Style& GetStyleBottom() const { return maBottom; }
88 const Style& GetStyleTLBR() const { return maTLBR; }
89 const Style& GetStyleBLTR() const { return maBLTR; }
91 bool IsMerged() const { return mbMergeOrig || mbOverlapX || mbOverlapY; }
92 bool IsRotated() const { return mfOrientation != 0.0; }
94 void MirrorSelfX();
96 basegfx::B2DHomMatrix CreateCoordinateSystemSingleCell(
97 const Array& rArray, sal_Int32 nCol, sal_Int32 nRow ) const;
98 basegfx::B2DHomMatrix CreateCoordinateSystemMergedCell(
99 const Array& rArray, sal_Int32 nColLeft, sal_Int32 nRowTop, sal_Int32 nColRight, sal_Int32 nRowBottom ) const;
104 typedef std::vector< const Cell* > CellVec;
106 basegfx::B2DHomMatrix Cell::HelperCreateB2DHomMatrixFromB2DRange(
107 const basegfx::B2DRange& rRange ) const
109 if( rRange.isEmpty() )
110 return basegfx::B2DHomMatrix();
112 basegfx::B2DPoint aOrigin(rRange.getMinimum());
113 basegfx::B2DVector aX(rRange.getWidth(), 0.0);
114 basegfx::B2DVector aY(0.0, rRange.getHeight());
116 if (IsRotated() && SvxRotateMode::SVX_ROTATE_MODE_STANDARD != meRotMode )
118 // tdf#143377 We need to limit applying Skew to geometry since the closer
119 // we get to 0.0 or PI the more sin(mfOrientation) will get to zero and the
120 // huger the Skew effect will be. For that, use an epsilon-radius of 1/2
121 // degree around the dangerous points 0.0 and PI.
123 // Snap to modulo to [0.0 .. 2PI[ to make compare easier
124 const double fSnapped(::basegfx::snapToZeroRange(mfOrientation, M_PI * 2.0));
126 // As a compromise, allow up to 1/2 degree
127 static const double fMinAng(M_PI/360.0);
129 // Check if Skew makes sense or would be too huge
130 const bool bForbidSkew(
131 fSnapped < fMinAng || // range [0.0 .. fMinAng]
132 fSnapped > (M_PI * 2.0) - fMinAng || // range [PI-fMinAng .. 2PI[
133 fabs(fSnapped - M_PI) < fMinAng); // range [PI-fMinAng .. PI+fMinAng]
135 if(!bForbidSkew)
137 // when rotated, adapt values. Get Skew (cos/sin == 1/tan)
138 const double fSkew(aY.getY() * (cos(mfOrientation) / sin(mfOrientation)));
140 switch (meRotMode)
142 case SvxRotateMode::SVX_ROTATE_MODE_TOP:
143 // shear Y-Axis
144 aY.setX(-fSkew);
145 break;
146 case SvxRotateMode::SVX_ROTATE_MODE_CENTER:
147 // shear origin half, Y full
148 aOrigin.setX(aOrigin.getX() + (fSkew * 0.5));
149 aY.setX(-fSkew);
150 break;
151 case SvxRotateMode::SVX_ROTATE_MODE_BOTTOM:
152 // shear origin full, Y full
153 aOrigin.setX(aOrigin.getX() + fSkew);
154 aY.setX(-fSkew);
155 break;
156 default: // SvxRotateMode::SVX_ROTATE_MODE_STANDARD, already excluded above
157 break;
162 // use column vectors as coordinate axes, homogen column for translation
163 return basegfx::utils::createCoordinateSystemTransform( aOrigin, aX, aY );
166 basegfx::B2DHomMatrix Cell::CreateCoordinateSystemSingleCell(
167 const Array& rArray, sal_Int32 nCol, sal_Int32 nRow) const
169 const Point aPoint( rArray.GetColPosition( nCol ), rArray.GetRowPosition( nRow ) );
170 const Size aSize( rArray.GetColWidth( nCol, nCol ) + 1, rArray.GetRowHeight( nRow, nRow ) + 1 );
171 const basegfx::B2DRange aRange( vcl::unotools::b2DRectangleFromRectangle( tools::Rectangle( aPoint, aSize ) ) );
173 return HelperCreateB2DHomMatrixFromB2DRange( aRange );
176 basegfx::B2DHomMatrix Cell::CreateCoordinateSystemMergedCell(
177 const Array& rArray, sal_Int32 nColLeft, sal_Int32 nRowTop, sal_Int32 nColRight, sal_Int32 nRowBottom) const
179 basegfx::B2DRange aRange( rArray.GetB2DRange(
180 nColLeft, nRowTop, nColRight, nRowBottom ) );
182 // adjust rectangle for partly visible merged cells
183 if( IsMerged() )
185 // not *sure* what exactly this is good for,
186 // it is just a hard set extension at merged cells,
187 // probably *should* be included in the above extended
188 // GetColPosition/GetColWidth already. This might be
189 // added due to GetColPosition/GetColWidth not working
190 // correctly over PageChanges (if used), but not sure.
191 aRange.expand(
192 basegfx::B2DRange(
193 aRange.getMinX() - mnAddLeft,
194 aRange.getMinY() - mnAddTop,
195 aRange.getMaxX() + mnAddRight,
196 aRange.getMaxY() + mnAddBottom ) );
199 return HelperCreateB2DHomMatrixFromB2DRange( aRange );
202 Cell::Cell() :
203 mnAddLeft( 0 ),
204 mnAddRight( 0 ),
205 mnAddTop( 0 ),
206 mnAddBottom( 0 ),
207 meRotMode(SvxRotateMode::SVX_ROTATE_MODE_STANDARD ),
208 mfOrientation( 0.0 ),
209 mbMergeOrig( false ),
210 mbOverlapX( false ),
211 mbOverlapY( false )
215 bool Cell::operator==(const Cell& rOther) const
217 if (this == &rOther)
218 // ptr compare (same instance)
219 return true;
221 return maLeft == rOther.maLeft
222 && maRight == rOther.maRight
223 && maTop == rOther.maTop
224 && maBottom == rOther.maBottom
225 && maTLBR == rOther.maTLBR
226 && maBLTR == rOther.maBLTR
227 && mnAddLeft == rOther.mnAddLeft
228 && mnAddRight == rOther.mnAddRight
229 && mnAddTop == rOther.mnAddTop
230 && mnAddBottom == rOther.mnAddBottom
231 && meRotMode == rOther.meRotMode
232 && mfOrientation == rOther.mfOrientation
233 && mbMergeOrig == rOther.mbMergeOrig
234 && mbOverlapX == rOther.mbOverlapX
235 && mbOverlapY == rOther.mbOverlapY;
238 size_t Cell::hashCode() const
240 std::size_t seed = 0;
241 o3tl::hash_combine(seed, maLeft.hashCode());
242 o3tl::hash_combine(seed, maRight.hashCode());
243 o3tl::hash_combine(seed, maTop.hashCode());
244 o3tl::hash_combine(seed, maBottom.hashCode());
245 o3tl::hash_combine(seed, maTLBR.hashCode());
246 o3tl::hash_combine(seed, maBLTR.hashCode());
247 o3tl::hash_combine(seed, mnAddLeft);
248 o3tl::hash_combine(seed, mnAddRight);
249 o3tl::hash_combine(seed, mnAddTop);
250 o3tl::hash_combine(seed, mnAddBottom);
251 o3tl::hash_combine(seed, meRotMode);
252 o3tl::hash_combine(seed, mfOrientation);
253 o3tl::hash_combine(seed, mbMergeOrig);
254 o3tl::hash_combine(seed, mbOverlapX);
255 o3tl::hash_combine(seed, mbOverlapY);
256 return seed;
259 void Cell::MirrorSelfX()
261 std::swap( maLeft, maRight );
262 std::swap( mnAddLeft, mnAddRight );
263 maLeft.MirrorSelf();
264 maRight.MirrorSelf();
265 mfOrientation = -mfOrientation;
269 static void lclRecalcCoordVec( std::vector<sal_Int32>& rCoords, const std::vector<sal_Int32>& rSizes )
271 DBG_ASSERT( rCoords.size() == rSizes.size() + 1, "lclRecalcCoordVec - inconsistent vectors" );
272 auto aCIt = rCoords.begin();
273 for( const auto& rSize : rSizes )
275 *(aCIt + 1) = *aCIt + rSize;
276 ++aCIt;
280 const Style OBJ_STYLE_NONE;
281 const Cell OBJ_CELL_NONE;
283 /** use hashing to speed up finding duplicates */
284 namespace
286 struct RegisteredCellHash
288 size_t operator()(Cell* const pCell) const
290 return pCell->hashCode();
294 struct RegisteredCellEquals
296 bool operator()(Cell* const pCell1, Cell* const pCell2) const
298 return *pCell1 == *pCell2;
303 struct ArrayImpl
305 std::unordered_set<Cell*, RegisteredCellHash, RegisteredCellEquals> maRegisteredCells;
306 CellVec maCells;
307 std::vector<sal_Int32> maWidths;
308 std::vector<sal_Int32> maHeights;
309 mutable std::vector<sal_Int32> maXCoords;
310 mutable std::vector<sal_Int32> maYCoords;
311 sal_Int32 mnWidth;
312 sal_Int32 mnHeight;
313 sal_Int32 mnFirstClipCol;
314 sal_Int32 mnFirstClipRow;
315 sal_Int32 mnLastClipCol;
316 sal_Int32 mnLastClipRow;
317 mutable bool mbXCoordsDirty;
318 mutable bool mbYCoordsDirty;
319 bool mbMayHaveCellRotation;
321 explicit ArrayImpl( sal_Int32 nWidth, sal_Int32 nHeight );
322 ~ArrayImpl();
324 bool IsValidPos( sal_Int32 nCol, sal_Int32 nRow ) const
325 { return (nCol < mnWidth) && (nRow < mnHeight); }
326 sal_Int32 GetIndex( sal_Int32 nCol, sal_Int32 nRow ) const
327 { return nRow * mnWidth + nCol; }
329 const Cell* GetCell( sal_Int32 nCol, sal_Int32 nRow ) const;
330 void PutCell( sal_Int32 nCol, sal_Int32 nRow, const Cell& );
332 sal_Int32 GetMergedFirstCol( sal_Int32 nCol, sal_Int32 nRow ) const;
333 sal_Int32 GetMergedFirstRow( sal_Int32 nCol, sal_Int32 nRow ) const;
334 sal_Int32 GetMergedLastCol( sal_Int32 nCol, sal_Int32 nRow ) const;
335 sal_Int32 GetMergedLastRow( sal_Int32 nCol, sal_Int32 nRow ) const;
337 const Cell* GetMergedOriginCell( sal_Int32 nCol, sal_Int32 nRow ) const;
338 const Cell* GetMergedLastCell( sal_Int32 nCol, sal_Int32 nRow ) const;
340 bool IsMergedOverlappedLeft( sal_Int32 nCol, sal_Int32 nRow ) const;
341 bool IsMergedOverlappedRight( sal_Int32 nCol, sal_Int32 nRow ) const;
342 bool IsMergedOverlappedTop( sal_Int32 nCol, sal_Int32 nRow ) const;
343 bool IsMergedOverlappedBottom( sal_Int32 nCol, sal_Int32 nRow ) const;
345 bool IsInClipRange( sal_Int32 nCol, sal_Int32 nRow ) const;
346 bool IsColInClipRange( sal_Int32 nCol ) const;
347 bool IsRowInClipRange( sal_Int32 nRow ) const;
349 bool OverlapsClipRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow ) const;
351 sal_Int32 GetMirrorCol( sal_Int32 nCol ) const { return mnWidth - nCol - 1; }
353 sal_Int32 GetColPosition( sal_Int32 nCol ) const;
354 sal_Int32 GetRowPosition( sal_Int32 nRow ) const;
356 bool HasCellRotation() const;
358 const Cell* createOrFind(const Cell& rCell);
361 static void lclSetMergedRange( ArrayImpl& rImpl, CellVec& rCells, sal_Int32 nWidth, sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow )
363 for( sal_Int32 nCol = nFirstCol; nCol <= nLastCol; ++nCol )
365 for( sal_Int32 nRow = nFirstRow; nRow <= nLastRow; ++nRow )
367 const Cell* pCell = rCells[ nRow * nWidth + nCol ];
368 Cell aTempCell(*pCell);
369 aTempCell.mbMergeOrig = false;
370 aTempCell.mbOverlapX = nCol > nFirstCol;
371 aTempCell.mbOverlapY = nRow > nFirstRow;
372 rCells[ nRow * nWidth + nCol ] = rImpl.createOrFind(aTempCell);
375 Cell aTempCell(*rCells[ nFirstRow * nWidth + nFirstCol ]);
376 aTempCell.mbMergeOrig = true;
377 rCells[ nFirstRow * nWidth + nFirstCol ] = rImpl.createOrFind(aTempCell);
380 ArrayImpl::ArrayImpl( sal_Int32 nWidth, sal_Int32 nHeight ) :
381 maRegisteredCells(),
382 mnWidth( nWidth ),
383 mnHeight( nHeight ),
384 mnFirstClipCol( 0 ),
385 mnFirstClipRow( 0 ),
386 mnLastClipCol( nWidth - 1 ),
387 mnLastClipRow( nHeight - 1 ),
388 mbXCoordsDirty( false ),
389 mbYCoordsDirty( false ),
390 mbMayHaveCellRotation( false )
392 const Cell* pDefaultCell = createOrFind(Cell());
393 // default-construct all vectors
394 maCells.resize( mnWidth * mnHeight, pDefaultCell );
395 maWidths.resize( mnWidth, 0 );
396 maHeights.resize( mnHeight, 0 );
397 maXCoords.resize( mnWidth + 1, 0 );
398 maYCoords.resize( mnHeight + 1, 0 );
401 ArrayImpl::~ArrayImpl()
403 for (auto* pCell : maRegisteredCells)
404 delete pCell;
407 const Cell* ArrayImpl::createOrFind(const Cell& rCell)
409 auto it = maRegisteredCells.find(const_cast<Cell*>(&rCell));
410 if (it != maRegisteredCells.end())
411 return *it;
413 Cell* pRetval(new Cell(rCell));
414 maRegisteredCells.insert(pRetval);
415 return pRetval;
418 const Cell* ArrayImpl::GetCell( sal_Int32 nCol, sal_Int32 nRow ) const
420 return IsValidPos( nCol, nRow ) ? maCells[ GetIndex( nCol, nRow ) ] : &OBJ_CELL_NONE;
423 void ArrayImpl::PutCell( sal_Int32 nCol, sal_Int32 nRow, const Cell & rCell )
425 if (IsValidPos( nCol, nRow ))
426 maCells[ GetIndex( nCol, nRow ) ] = createOrFind(rCell);
429 sal_Int32 ArrayImpl::GetMergedFirstCol( sal_Int32 nCol, sal_Int32 nRow ) const
431 sal_Int32 nFirstCol = nCol;
432 while( (nFirstCol > 0) && GetCell( nFirstCol, nRow )->mbOverlapX ) --nFirstCol;
433 return nFirstCol;
436 sal_Int32 ArrayImpl::GetMergedFirstRow( sal_Int32 nCol, sal_Int32 nRow ) const
438 sal_Int32 nFirstRow = nRow;
439 while( (nFirstRow > 0) && GetCell( nCol, nFirstRow )->mbOverlapY ) --nFirstRow;
440 return nFirstRow;
443 sal_Int32 ArrayImpl::GetMergedLastCol( sal_Int32 nCol, sal_Int32 nRow ) const
445 sal_Int32 nLastCol = nCol + 1;
446 while( (nLastCol < mnWidth) && GetCell( nLastCol, nRow )->mbOverlapX ) ++nLastCol;
447 return nLastCol - 1;
450 sal_Int32 ArrayImpl::GetMergedLastRow( sal_Int32 nCol, sal_Int32 nRow ) const
452 sal_Int32 nLastRow = nRow + 1;
453 while( (nLastRow < mnHeight) && GetCell( nCol, nLastRow )->mbOverlapY ) ++nLastRow;
454 return nLastRow - 1;
457 const Cell* ArrayImpl::GetMergedOriginCell( sal_Int32 nCol, sal_Int32 nRow ) const
459 return GetCell( GetMergedFirstCol( nCol, nRow ), GetMergedFirstRow( nCol, nRow ) );
462 const Cell* ArrayImpl::GetMergedLastCell( sal_Int32 nCol, sal_Int32 nRow ) const
464 return GetCell( GetMergedLastCol( nCol, nRow ), GetMergedLastRow( nCol, nRow ) );
467 bool ArrayImpl::IsMergedOverlappedLeft( sal_Int32 nCol, sal_Int32 nRow ) const
469 const Cell* pCell(GetCell( nCol, nRow ));
470 return pCell->mbOverlapX || (pCell->mnAddLeft > 0);
473 bool ArrayImpl::IsMergedOverlappedRight( sal_Int32 nCol, sal_Int32 nRow ) const
475 return GetCell( nCol + 1, nRow )->mbOverlapX || (GetCell( nCol, nRow )->mnAddRight > 0);
478 bool ArrayImpl::IsMergedOverlappedTop( sal_Int32 nCol, sal_Int32 nRow ) const
480 const Cell* pCell(GetCell( nCol, nRow ));
481 return pCell->mbOverlapY || (pCell->mnAddTop > 0);
484 bool ArrayImpl::IsMergedOverlappedBottom( sal_Int32 nCol, sal_Int32 nRow ) const
486 return GetCell( nCol, nRow + 1 )->mbOverlapY || (GetCell( nCol, nRow )->mnAddBottom > 0);
489 bool ArrayImpl::IsColInClipRange( sal_Int32 nCol ) const
491 return (mnFirstClipCol <= nCol) && (nCol <= mnLastClipCol);
494 bool ArrayImpl::IsRowInClipRange( sal_Int32 nRow ) const
496 return (mnFirstClipRow <= nRow) && (nRow <= mnLastClipRow);
499 bool ArrayImpl::OverlapsClipRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow ) const
501 if(nLastCol < mnFirstClipCol)
502 return false;
504 if(nFirstCol > mnLastClipCol)
505 return false;
507 if(nLastRow < mnFirstClipRow)
508 return false;
510 if(nFirstRow > mnLastClipRow)
511 return false;
513 return true;
516 bool ArrayImpl::IsInClipRange( sal_Int32 nCol, sal_Int32 nRow ) const
518 return IsColInClipRange( nCol ) && IsRowInClipRange( nRow );
521 sal_Int32 ArrayImpl::GetColPosition( sal_Int32 nCol ) const
523 if( mbXCoordsDirty )
525 lclRecalcCoordVec( maXCoords, maWidths );
526 mbXCoordsDirty = false;
528 return maXCoords[ nCol ];
531 sal_Int32 ArrayImpl::GetRowPosition( sal_Int32 nRow ) const
533 if( mbYCoordsDirty )
535 lclRecalcCoordVec( maYCoords, maHeights );
536 mbYCoordsDirty = false;
538 return maYCoords[ nRow ];
541 bool ArrayImpl::HasCellRotation() const
543 // check cell array
544 for (const auto& aCell : maCells)
546 if (aCell->IsRotated())
548 return true;
552 return false;
555 namespace {
557 class MergedCellIterator
559 public:
560 explicit MergedCellIterator( const Array& rArray, sal_Int32 nCol, sal_Int32 nRow );
562 bool Is() const { return (mnCol <= mnLastCol) && (mnRow <= mnLastRow); }
563 sal_Int32 Col() const { return mnCol; }
564 sal_Int32 Row() const { return mnRow; }
566 MergedCellIterator& operator++();
568 private:
569 sal_Int32 mnFirstCol;
570 sal_Int32 mnFirstRow;
571 sal_Int32 mnLastCol;
572 sal_Int32 mnLastRow;
573 sal_Int32 mnCol;
574 sal_Int32 mnRow;
579 MergedCellIterator::MergedCellIterator( const Array& rArray, sal_Int32 nCol, sal_Int32 nRow )
581 rArray.GetMergedRange( mnFirstCol, mnFirstRow, mnLastCol, mnLastRow, nCol, nRow );
582 mnCol = mnFirstCol;
583 mnRow = mnFirstRow;
586 MergedCellIterator& MergedCellIterator::operator++()
588 DBG_ASSERT( Is(), "svx::frame::MergedCellIterator::operator++() - already invalid" );
589 if( ++mnCol > mnLastCol )
591 mnCol = mnFirstCol;
592 ++mnRow;
594 return *this;
597 #define DBG_FRAME_CHECK( cond, funcname, error ) DBG_ASSERT( cond, "svx::frame::Array::" funcname " - " error )
598 #define DBG_FRAME_CHECK_COL( col, funcname ) DBG_FRAME_CHECK( (col) < GetColCount(), funcname, "invalid column index" )
599 #define DBG_FRAME_CHECK_ROW( row, funcname ) DBG_FRAME_CHECK( (row) < GetRowCount(), funcname, "invalid row index" )
600 #define DBG_FRAME_CHECK_COLROW( col, row, funcname ) DBG_FRAME_CHECK( ((col) < GetColCount()) && ((row) < GetRowCount()), funcname, "invalid cell index" )
601 #define DBG_FRAME_CHECK_COL_1( col, funcname ) DBG_FRAME_CHECK( (col) <= GetColCount(), funcname, "invalid column index" )
602 #define DBG_FRAME_CHECK_ROW_1( row, funcname ) DBG_FRAME_CHECK( (row) <= GetRowCount(), funcname, "invalid row index" )
604 Array::Array()
606 Initialize( 0, 0 );
609 Array::~Array()
613 // array size and column/row indexes
614 void Array::Initialize( sal_Int32 nWidth, sal_Int32 nHeight )
616 mxImpl.reset( new ArrayImpl( nWidth, nHeight ) );
619 sal_Int32 Array::GetColCount() const
621 return mxImpl->mnWidth;
624 sal_Int32 Array::GetRowCount() const
626 return mxImpl->mnHeight;
629 sal_Int32 Array::GetCellCount() const
631 return mxImpl->maCells.size();
634 sal_Int32 Array::GetCellIndex( sal_Int32 nCol, sal_Int32 nRow, bool bRTL ) const
636 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetCellIndex" );
637 if (bRTL)
638 nCol = mxImpl->GetMirrorCol(nCol);
639 return mxImpl->GetIndex( nCol, nRow );
642 // cell border styles
643 void Array::SetCellStyleLeft( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
645 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleLeft" );
646 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
647 if (pTempCell->GetStyleLeft() == rStyle)
648 return;
649 Cell aTempCell(*pTempCell);
650 aTempCell.SetStyleLeft(rStyle);
651 mxImpl->PutCell( nCol, nRow, aTempCell );
654 void Array::SetCellStyleRight( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
656 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleRight" );
657 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
658 if (pTempCell->GetStyleRight() == rStyle)
659 return;
660 Cell aTempCell(*pTempCell);
661 aTempCell.SetStyleRight(rStyle);
662 mxImpl->PutCell( nCol, nRow, aTempCell );
665 void Array::SetCellStyleTop( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
667 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleTop" );
668 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
669 if (pTempCell->GetStyleTop() == rStyle)
670 return;
671 Cell aTempCell(*pTempCell);
672 aTempCell.SetStyleTop(rStyle);
673 mxImpl->PutCell( nCol, nRow, aTempCell );
676 void Array::SetCellStyleBottom( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
678 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleBottom" );
679 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
680 if (pTempCell->GetStyleBottom() == rStyle)
681 return;
682 Cell aTempCell(*pTempCell);
683 aTempCell.SetStyleBottom(rStyle);
684 mxImpl->PutCell( nCol, nRow, aTempCell );
687 void Array::SetCellStyleTLBR( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
689 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleTLBR" );
690 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
691 if (pTempCell->GetStyleTLBR() == rStyle)
692 return;
693 Cell aTempCell(*pTempCell);
694 aTempCell.SetStyleTLBR(rStyle);
695 mxImpl->PutCell( nCol, nRow, aTempCell );
698 void Array::SetCellStyleBLTR( sal_Int32 nCol, sal_Int32 nRow, const Style& rStyle )
700 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleBLTR" );
701 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
702 if (pTempCell->GetStyleBLTR() == rStyle)
703 return;
704 Cell aTempCell(*pTempCell);
705 aTempCell.SetStyleBLTR(rStyle);
706 mxImpl->PutCell( nCol, nRow, aTempCell );
709 void Array::SetCellStyleDiag( sal_Int32 nCol, sal_Int32 nRow, const Style& rTLBR, const Style& rBLTR )
711 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleDiag" );
712 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
713 if (pTempCell->GetStyleTLBR() == rTLBR && pTempCell->GetStyleBLTR() == rBLTR)
714 return;
715 Cell aTempCell(*pTempCell);
716 aTempCell.SetStyleTLBR(rTLBR);
717 aTempCell.SetStyleBLTR(rBLTR);
718 mxImpl->PutCell( nCol, nRow, aTempCell );
721 void Array::SetColumnStyleLeft( sal_Int32 nCol, const Style& rStyle )
723 DBG_FRAME_CHECK_COL( nCol, "SetColumnStyleLeft" );
724 for( sal_Int32 nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
725 SetCellStyleLeft( nCol, nRow, rStyle );
728 void Array::SetColumnStyleRight( sal_Int32 nCol, const Style& rStyle )
730 DBG_FRAME_CHECK_COL( nCol, "SetColumnStyleRight" );
731 for( sal_Int32 nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
732 SetCellStyleRight( nCol, nRow, rStyle );
735 void Array::SetRowStyleTop( sal_Int32 nRow, const Style& rStyle )
737 DBG_FRAME_CHECK_ROW( nRow, "SetRowStyleTop" );
738 for( sal_Int32 nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
739 SetCellStyleTop( nCol, nRow, rStyle );
742 void Array::SetRowStyleBottom( sal_Int32 nRow, const Style& rStyle )
744 DBG_FRAME_CHECK_ROW( nRow, "SetRowStyleBottom" );
745 for( sal_Int32 nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
746 SetCellStyleBottom( nCol, nRow, rStyle );
749 void Array::SetCellRotation(sal_Int32 nCol, sal_Int32 nRow, SvxRotateMode eRotMode, double fOrientation)
751 DBG_FRAME_CHECK_COLROW(nCol, nRow, "SetCellRotation");
752 const Cell* pTempCell(mxImpl->GetCell(nCol, nRow));
753 if (pTempCell->meRotMode == eRotMode && pTempCell->mfOrientation == fOrientation)
754 return;
755 Cell aTempCell(*pTempCell);
756 aTempCell.meRotMode = eRotMode;
757 aTempCell.mfOrientation = fOrientation;
758 mxImpl->PutCell( nCol, nRow, aTempCell );
760 if (!mxImpl->mbMayHaveCellRotation)
762 // activate once when a cell gets actually rotated to allow fast
763 // answering HasCellRotation() calls
764 mxImpl->mbMayHaveCellRotation = aTempCell.IsRotated();
768 bool Array::HasCellRotation() const
770 if (!mxImpl->mbMayHaveCellRotation)
772 // never set, no need to check
773 return false;
776 return mxImpl->HasCellRotation();
779 const Style& Array::GetCellStyleLeft( sal_Int32 nCol, sal_Int32 nRow ) const
781 // outside clipping rows or overlapped in merged cells: invisible
782 if( !mxImpl->IsRowInClipRange( nRow ) || mxImpl->IsMergedOverlappedLeft( nCol, nRow ) )
783 return OBJ_STYLE_NONE;
784 // left clipping border: always own left style
785 if( nCol == mxImpl->mnFirstClipCol )
786 return mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleLeft();
787 // right clipping border: always right style of left neighbor cell
788 if( nCol == mxImpl->mnLastClipCol + 1 )
789 return mxImpl->GetMergedOriginCell( nCol - 1, nRow )->GetStyleRight();
790 // outside clipping columns: invisible
791 if( !mxImpl->IsColInClipRange( nCol ) )
792 return OBJ_STYLE_NONE;
793 // inside clipping range: maximum of own left style and right style of left neighbor cell
794 return std::max( mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleLeft(), mxImpl->GetMergedOriginCell( nCol - 1, nRow )->GetStyleRight() );
797 const Style& Array::GetCellStyleRight( sal_Int32 nCol, sal_Int32 nRow ) const
799 // outside clipping rows or overlapped in merged cells: invisible
800 if( !mxImpl->IsRowInClipRange( nRow ) || mxImpl->IsMergedOverlappedRight( nCol, nRow ) )
801 return OBJ_STYLE_NONE;
802 // left clipping border: always left style of right neighbor cell
803 if( nCol + 1 == mxImpl->mnFirstClipCol )
804 return mxImpl->GetMergedOriginCell( nCol + 1, nRow )->GetStyleLeft();
805 // right clipping border: always own right style
806 if( nCol == mxImpl->mnLastClipCol )
807 return mxImpl->GetMergedLastCell( nCol, nRow )->GetStyleRight();
808 // outside clipping columns: invisible
809 if( !mxImpl->IsColInClipRange( nCol ) )
810 return OBJ_STYLE_NONE;
811 // inside clipping range: maximum of own right style and left style of right neighbor cell
812 return std::max( mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleRight(), mxImpl->GetMergedOriginCell( nCol + 1, nRow )->GetStyleLeft() );
815 const Style& Array::GetCellStyleTop( sal_Int32 nCol, sal_Int32 nRow ) const
817 // outside clipping columns or overlapped in merged cells: invisible
818 if( !mxImpl->IsColInClipRange( nCol ) || mxImpl->IsMergedOverlappedTop( nCol, nRow ) )
819 return OBJ_STYLE_NONE;
820 // top clipping border: always own top style
821 if( nRow == mxImpl->mnFirstClipRow )
822 return mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleTop();
823 // bottom clipping border: always bottom style of top neighbor cell
824 if( nRow == mxImpl->mnLastClipRow + 1 )
825 return mxImpl->GetMergedOriginCell( nCol, nRow - 1 )->GetStyleBottom();
826 // outside clipping rows: invisible
827 if( !mxImpl->IsRowInClipRange( nRow ) )
828 return OBJ_STYLE_NONE;
829 // inside clipping range: maximum of own top style and bottom style of top neighbor cell
830 return std::max( mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleTop(), mxImpl->GetMergedOriginCell( nCol, nRow - 1 )->GetStyleBottom() );
833 const Style& Array::GetCellStyleBottom( sal_Int32 nCol, sal_Int32 nRow ) const
835 // outside clipping columns or overlapped in merged cells: invisible
836 if( !mxImpl->IsColInClipRange( nCol ) || mxImpl->IsMergedOverlappedBottom( nCol, nRow ) )
837 return OBJ_STYLE_NONE;
838 // top clipping border: always top style of bottom neighbor cell
839 if( nRow + 1 == mxImpl->mnFirstClipRow )
840 return mxImpl->GetMergedOriginCell( nCol, nRow + 1 )->GetStyleTop();
841 // bottom clipping border: always own bottom style
842 if( nRow == mxImpl->mnLastClipRow )
843 return mxImpl->GetMergedLastCell( nCol, nRow )->GetStyleBottom();
844 // outside clipping rows: invisible
845 if( !mxImpl->IsRowInClipRange( nRow ) )
846 return OBJ_STYLE_NONE;
847 // inside clipping range: maximum of own bottom style and top style of bottom neighbor cell
848 return std::max( mxImpl->GetMergedOriginCell( nCol, nRow )->GetStyleBottom(), mxImpl->GetMergedOriginCell( nCol, nRow + 1 )->GetStyleTop() );
851 const Style& Array::GetCellStyleTLBR( sal_Int32 nCol, sal_Int32 nRow ) const
853 return mxImpl->GetCell( nCol, nRow )->GetStyleTLBR();
856 const Style& Array::GetCellStyleBLTR( sal_Int32 nCol, sal_Int32 nRow ) const
858 return mxImpl->GetCell( nCol, nRow )->GetStyleBLTR();
861 const Style& Array::GetCellStyleTL( sal_Int32 nCol, sal_Int32 nRow ) const
863 // not in clipping range: always invisible
864 if( !mxImpl->IsInClipRange( nCol, nRow ) )
865 return OBJ_STYLE_NONE;
866 // return style only for top-left cell
867 sal_Int32 nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
868 sal_Int32 nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
869 return ((nCol == nFirstCol) && (nRow == nFirstRow)) ?
870 mxImpl->GetCell( nFirstCol, nFirstRow )->GetStyleTLBR() : OBJ_STYLE_NONE;
873 const Style& Array::GetCellStyleBR( sal_Int32 nCol, sal_Int32 nRow ) const
875 // not in clipping range: always invisible
876 if( !mxImpl->IsInClipRange( nCol, nRow ) )
877 return OBJ_STYLE_NONE;
878 // return style only for bottom-right cell
879 sal_Int32 nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
880 sal_Int32 nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
881 return ((nCol == nLastCol) && (nRow == nLastRow)) ?
882 mxImpl->GetCell( mxImpl->GetMergedFirstCol( nCol, nRow ), mxImpl->GetMergedFirstRow( nCol, nRow ) )->GetStyleTLBR() : OBJ_STYLE_NONE;
885 const Style& Array::GetCellStyleBL( sal_Int32 nCol, sal_Int32 nRow ) const
887 // not in clipping range: always invisible
888 if( !mxImpl->IsInClipRange( nCol, nRow ) )
889 return OBJ_STYLE_NONE;
890 // return style only for bottom-left cell
891 sal_Int32 nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
892 sal_Int32 nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
893 return ((nCol == nFirstCol) && (nRow == nLastRow)) ?
894 mxImpl->GetCell( nFirstCol, mxImpl->GetMergedFirstRow( nCol, nRow ) )->GetStyleBLTR() : OBJ_STYLE_NONE;
897 const Style& Array::GetCellStyleTR( sal_Int32 nCol, sal_Int32 nRow ) const
899 // not in clipping range: always invisible
900 if( !mxImpl->IsInClipRange( nCol, nRow ) )
901 return OBJ_STYLE_NONE;
902 // return style only for top-right cell
903 sal_Int32 nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
904 sal_Int32 nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
905 return ((nCol == nLastCol) && (nRow == nFirstRow)) ?
906 mxImpl->GetCell( mxImpl->GetMergedFirstCol( nCol, nRow ), nFirstRow )->GetStyleBLTR() : OBJ_STYLE_NONE;
909 // cell merging
910 void Array::SetMergedRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow )
912 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "SetMergedRange" );
913 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "SetMergedRange" );
914 #if OSL_DEBUG_LEVEL >= 2
916 bool bFound = false;
917 for( sal_Int32 nCurrCol = nFirstCol; !bFound && (nCurrCol <= nLastCol); ++nCurrCol )
918 for( sal_Int32 nCurrRow = nFirstRow; !bFound && (nCurrRow <= nLastRow); ++nCurrRow )
919 bFound = mxImpl->GetCell( nCurrCol, nCurrRow )->IsMerged();
920 DBG_FRAME_CHECK( !bFound, "SetMergedRange", "overlapping merged ranges" );
922 #endif
923 if( mxImpl->IsValidPos( nFirstCol, nFirstRow ) && mxImpl->IsValidPos( nLastCol, nLastRow ) )
924 lclSetMergedRange( *mxImpl, mxImpl->maCells, mxImpl->mnWidth, nFirstCol, nFirstRow, nLastCol, nLastRow );
927 void Array::SetAddMergedLeftSize( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nAddSize )
929 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedLeftSize" );
930 DBG_FRAME_CHECK( mxImpl->GetMergedFirstCol( nCol, nRow ) == 0, "SetAddMergedLeftSize", "additional border inside array" );
931 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
933 const Cell* pTempCell(mxImpl->GetCell(aIt.Col(), aIt.Row()));
934 if (pTempCell->mnAddLeft == nAddSize)
935 return;
936 Cell aTempCell(*pTempCell);
937 aTempCell.mnAddLeft = nAddSize;
938 mxImpl->PutCell( aIt.Col(), aIt.Row(), aTempCell );
942 void Array::SetAddMergedRightSize( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nAddSize )
944 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedRightSize" );
945 DBG_FRAME_CHECK( mxImpl->GetMergedLastCol( nCol, nRow ) + 1 == mxImpl->mnWidth, "SetAddMergedRightSize", "additional border inside array" );
946 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
948 const Cell* pTempCell(mxImpl->GetCell(aIt.Col(), aIt.Row()));
949 if (pTempCell->mnAddRight == nAddSize)
950 return;
951 Cell aTempCell(*pTempCell);
952 aTempCell.mnAddRight = nAddSize;
953 mxImpl->PutCell( aIt.Col(), aIt.Row(), aTempCell );
957 void Array::SetAddMergedTopSize( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nAddSize )
959 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedTopSize" );
960 DBG_FRAME_CHECK( mxImpl->GetMergedFirstRow( nCol, nRow ) == 0, "SetAddMergedTopSize", "additional border inside array" );
961 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
963 const Cell* pTempCell(mxImpl->GetCell(aIt.Col(), aIt.Row()));
964 if (pTempCell->mnAddTop == nAddSize)
965 return;
966 Cell aTempCell(*pTempCell);
967 aTempCell.mnAddTop = nAddSize;
968 mxImpl->PutCell( aIt.Col(), aIt.Row(), aTempCell );
972 void Array::SetAddMergedBottomSize( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nAddSize )
974 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedBottomSize" );
975 DBG_FRAME_CHECK( mxImpl->GetMergedLastRow( nCol, nRow ) + 1 == mxImpl->mnHeight, "SetAddMergedBottomSize", "additional border inside array" );
976 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
978 const Cell* pTempCell(mxImpl->GetCell(aIt.Col(), aIt.Row()));
979 if (pTempCell->mnAddBottom == nAddSize)
980 return;
981 Cell aTempCell(*pTempCell);
982 aTempCell.mnAddBottom = nAddSize;
983 mxImpl->PutCell( aIt.Col(), aIt.Row(), aTempCell );
987 bool Array::IsMerged( sal_Int32 nCol, sal_Int32 nRow ) const
989 DBG_FRAME_CHECK_COLROW( nCol, nRow, "IsMerged" );
990 return mxImpl->GetCell( nCol, nRow )->IsMerged();
993 void Array::GetMergedOrigin( sal_Int32& rnFirstCol, sal_Int32& rnFirstRow, sal_Int32 nCol, sal_Int32 nRow ) const
995 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetMergedOrigin" );
996 rnFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
997 rnFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
1000 void Array::GetMergedRange( sal_Int32& rnFirstCol, sal_Int32& rnFirstRow,
1001 sal_Int32& rnLastCol, sal_Int32& rnLastRow, sal_Int32 nCol, sal_Int32 nRow ) const
1003 GetMergedOrigin( rnFirstCol, rnFirstRow, nCol, nRow );
1004 rnLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
1005 rnLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
1008 // clipping
1009 void Array::SetClipRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow )
1011 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "SetClipRange" );
1012 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "SetClipRange" );
1013 mxImpl->mnFirstClipCol = nFirstCol;
1014 mxImpl->mnFirstClipRow = nFirstRow;
1015 mxImpl->mnLastClipCol = nLastCol;
1016 mxImpl->mnLastClipRow = nLastRow;
1019 // cell coordinates
1020 void Array::SetXOffset( sal_Int32 nXOffset )
1022 mxImpl->maXCoords[ 0 ] = nXOffset;
1023 mxImpl->mbXCoordsDirty = true;
1026 void Array::SetYOffset( sal_Int32 nYOffset )
1028 mxImpl->maYCoords[ 0 ] = nYOffset;
1029 mxImpl->mbYCoordsDirty = true;
1032 void Array::SetColWidth( sal_Int32 nCol, sal_Int32 nWidth )
1034 DBG_FRAME_CHECK_COL( nCol, "SetColWidth" );
1035 mxImpl->maWidths[ nCol ] = nWidth;
1036 mxImpl->mbXCoordsDirty = true;
1039 void Array::SetRowHeight( sal_Int32 nRow, sal_Int32 nHeight )
1041 DBG_FRAME_CHECK_ROW( nRow, "SetRowHeight" );
1042 mxImpl->maHeights[ nRow ] = nHeight;
1043 mxImpl->mbYCoordsDirty = true;
1046 void Array::SetAllColWidths( sal_Int32 nWidth )
1048 std::fill( mxImpl->maWidths.begin(), mxImpl->maWidths.end(), nWidth );
1049 mxImpl->mbXCoordsDirty = true;
1052 void Array::SetAllRowHeights( sal_Int32 nHeight )
1054 std::fill( mxImpl->maHeights.begin(), mxImpl->maHeights.end(), nHeight );
1055 mxImpl->mbYCoordsDirty = true;
1058 sal_Int32 Array::GetColPosition( sal_Int32 nCol ) const
1060 DBG_FRAME_CHECK_COL_1( nCol, "GetColPosition" );
1061 return mxImpl->GetColPosition( nCol );
1064 sal_Int32 Array::GetRowPosition( sal_Int32 nRow ) const
1066 DBG_FRAME_CHECK_ROW_1( nRow, "GetRowPosition" );
1067 return mxImpl->GetRowPosition( nRow );
1070 sal_Int32 Array::GetColWidth( sal_Int32 nFirstCol, sal_Int32 nLastCol ) const
1072 DBG_FRAME_CHECK_COL( nFirstCol, "GetColWidth" );
1073 DBG_FRAME_CHECK_COL( nLastCol, "GetColWidth" );
1074 return GetColPosition( nLastCol + 1 ) - GetColPosition( nFirstCol );
1077 sal_Int32 Array::GetRowHeight( sal_Int32 nFirstRow, sal_Int32 nLastRow ) const
1079 DBG_FRAME_CHECK_ROW( nFirstRow, "GetRowHeight" );
1080 DBG_FRAME_CHECK_ROW( nLastRow, "GetRowHeight" );
1081 return GetRowPosition( nLastRow + 1 ) - GetRowPosition( nFirstRow );
1084 sal_Int32 Array::GetWidth() const
1086 return GetColPosition( mxImpl->mnWidth ) - GetColPosition( 0 );
1089 sal_Int32 Array::GetHeight() const
1091 return GetRowPosition( mxImpl->mnHeight ) - GetRowPosition( 0 );
1094 basegfx::B2DRange Array::GetCellRange( sal_Int32 nCol, sal_Int32 nRow ) const
1096 // get the Range of the fully expanded cell (if merged)
1097 const sal_Int32 nFirstCol(mxImpl->GetMergedFirstCol( nCol, nRow ));
1098 const sal_Int32 nFirstRow(mxImpl->GetMergedFirstRow( nCol, nRow ));
1099 const sal_Int32 nLastCol(mxImpl->GetMergedLastCol( nCol, nRow ));
1100 const sal_Int32 nLastRow(mxImpl->GetMergedLastRow( nCol, nRow ));
1101 const Point aPoint( GetColPosition( nFirstCol ), GetRowPosition( nFirstRow ) );
1102 const Size aSize( GetColWidth( nFirstCol, nLastCol ) + 1, GetRowHeight( nFirstRow, nLastRow ) + 1 );
1103 tools::Rectangle aRect(aPoint, aSize);
1105 // adjust rectangle for partly visible merged cells
1106 const Cell* pCell(mxImpl->GetCell( nCol, nRow ));
1108 if( pCell->IsMerged() )
1110 // not *sure* what exactly this is good for,
1111 // it is just a hard set extension at merged cells,
1112 // probably *should* be included in the above extended
1113 // GetColPosition/GetColWidth already. This might be
1114 // added due to GetColPosition/GetColWidth not working
1115 // correctly over PageChanges (if used), but not sure.
1116 aRect.AdjustLeft( -(pCell->mnAddLeft) );
1117 aRect.AdjustRight(pCell->mnAddRight );
1118 aRect.AdjustTop( -(pCell->mnAddTop) );
1119 aRect.AdjustBottom(pCell->mnAddBottom );
1122 return vcl::unotools::b2DRectangleFromRectangle(aRect);
1125 // return output range of given row/col range in logical coordinates
1126 basegfx::B2DRange Array::GetB2DRange(sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow) const
1128 const Point aPoint( GetColPosition( nFirstCol ), GetRowPosition( nFirstRow ) );
1129 const Size aSize( GetColWidth( nFirstCol, nLastCol ) + 1, GetRowHeight( nFirstRow, nLastRow ) + 1 );
1131 return vcl::unotools::b2DRectangleFromRectangle(tools::Rectangle(aPoint, aSize));
1134 // mirroring
1135 void Array::MirrorSelfX()
1137 CellVec aNewCells;
1138 aNewCells.reserve( GetCellCount() );
1140 sal_Int32 nCol, nRow;
1141 for( nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
1143 for( nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
1145 Cell aTempCell(*mxImpl->GetCell(mxImpl->GetMirrorCol( nCol ), nRow));
1146 aTempCell.MirrorSelfX();
1147 aNewCells.push_back( mxImpl->createOrFind(aTempCell) );
1150 for( nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
1152 for( nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
1154 if( mxImpl->GetCell( nCol, nRow )->mbMergeOrig )
1156 sal_Int32 nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
1157 sal_Int32 nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
1158 lclSetMergedRange( *mxImpl, aNewCells, mxImpl->mnWidth,
1159 mxImpl->GetMirrorCol( nLastCol ), nRow,
1160 mxImpl->GetMirrorCol( nCol ), nLastRow );
1164 mxImpl->maCells.swap( aNewCells );
1166 std::reverse( mxImpl->maWidths.begin(), mxImpl->maWidths.end() );
1167 mxImpl->mbXCoordsDirty = true;
1170 // drawing
1171 static void HelperCreateHorizontalEntry(
1172 const Array& rArray,
1173 const Style& rStyle,
1174 sal_Int32 col,
1175 sal_Int32 row,
1176 const basegfx::B2DPoint& rOrigin,
1177 const basegfx::B2DVector& rX,
1178 const basegfx::B2DVector& rY,
1179 drawinglayer::primitive2d::SdrFrameBorderDataVector& rData,
1180 bool bUpper,
1181 const Color* pForceColor)
1183 // prepare SdrFrameBorderData
1184 rData.emplace_back(
1185 bUpper ? rOrigin : basegfx::B2DPoint(rOrigin + rY),
1187 rStyle,
1188 pForceColor);
1189 drawinglayer::primitive2d::SdrFrameBorderData& rInstance(rData.back());
1191 // get involved styles at start
1192 const Style& rStartFromTR(rArray.GetCellStyleBL( col, row - 1 ));
1193 const Style& rStartLFromT(rArray.GetCellStyleLeft( col, row - 1 ));
1194 const Style& rStartLFromL(rArray.GetCellStyleTop( col - 1, row ));
1195 const Style& rStartLFromB(rArray.GetCellStyleLeft( col, row ));
1196 const Style& rStartFromBR(rArray.GetCellStyleTL( col, row ));
1198 rInstance.addSdrConnectStyleData(true, rStartFromTR, rX - rY, false);
1199 rInstance.addSdrConnectStyleData(true, rStartLFromT, -rY, true);
1200 rInstance.addSdrConnectStyleData(true, rStartLFromL, -rX, true);
1201 rInstance.addSdrConnectStyleData(true, rStartLFromB, rY, false);
1202 rInstance.addSdrConnectStyleData(true, rStartFromBR, rX + rY, false);
1204 // get involved styles at end
1205 const Style& rEndFromTL(rArray.GetCellStyleBR( col, row - 1 ));
1206 const Style& rEndRFromT(rArray.GetCellStyleRight( col, row - 1 ));
1207 const Style& rEndRFromR(rArray.GetCellStyleTop( col + 1, row ));
1208 const Style& rEndRFromB(rArray.GetCellStyleRight( col, row ));
1209 const Style& rEndFromBL(rArray.GetCellStyleTR( col, row ));
1211 rInstance.addSdrConnectStyleData(false, rEndFromTL, -rX - rY, true);
1212 rInstance.addSdrConnectStyleData(false, rEndRFromT, -rY, true);
1213 rInstance.addSdrConnectStyleData(false, rEndRFromR, rX, false);
1214 rInstance.addSdrConnectStyleData(false, rEndRFromB, rY, false);
1215 rInstance.addSdrConnectStyleData(false, rEndFromBL, rY - rX, true);
1218 static void HelperCreateVerticalEntry(
1219 const Array& rArray,
1220 const Style& rStyle,
1221 sal_Int32 col,
1222 sal_Int32 row,
1223 const basegfx::B2DPoint& rOrigin,
1224 const basegfx::B2DVector& rX,
1225 const basegfx::B2DVector& rY,
1226 drawinglayer::primitive2d::SdrFrameBorderDataVector& rData,
1227 bool bLeft,
1228 const Color* pForceColor)
1230 // prepare SdrFrameBorderData
1231 rData.emplace_back(
1232 bLeft ? rOrigin : basegfx::B2DPoint(rOrigin + rX),
1234 rStyle,
1235 pForceColor);
1236 drawinglayer::primitive2d::SdrFrameBorderData& rInstance(rData.back());
1238 // get involved styles at start
1239 const Style& rStartFromBL(rArray.GetCellStyleTR( col - 1, row ));
1240 const Style& rStartTFromL(rArray.GetCellStyleTop( col - 1, row ));
1241 const Style& rStartTFromT(rArray.GetCellStyleLeft( col, row - 1 ));
1242 const Style& rStartTFromR(rArray.GetCellStyleTop( col, row ));
1243 const Style& rStartFromBR(rArray.GetCellStyleTL( col, row ));
1245 rInstance.addSdrConnectStyleData(true, rStartFromBR, rX + rY, false);
1246 rInstance.addSdrConnectStyleData(true, rStartTFromR, rX, false);
1247 rInstance.addSdrConnectStyleData(true, rStartTFromT, -rY, true);
1248 rInstance.addSdrConnectStyleData(true, rStartTFromL, -rX, true);
1249 rInstance.addSdrConnectStyleData(true, rStartFromBL, rY - rX, true);
1251 // get involved styles at end
1252 const Style& rEndFromTL(rArray.GetCellStyleBR( col - 1, row ));
1253 const Style& rEndBFromL(rArray.GetCellStyleBottom( col - 1, row ));
1254 const Style& rEndBFromB(rArray.GetCellStyleLeft( col, row + 1 ));
1255 const Style& rEndBFromR(rArray.GetCellStyleBottom( col, row ));
1256 const Style& rEndFromTR(rArray.GetCellStyleBL( col, row ));
1258 rInstance.addSdrConnectStyleData(false, rEndFromTR, rX - rY, false);
1259 rInstance.addSdrConnectStyleData(false, rEndBFromR, rX, false);
1260 rInstance.addSdrConnectStyleData(false, rEndBFromB, rY, false);
1261 rInstance.addSdrConnectStyleData(false, rEndBFromL, -rX, true);
1262 rInstance.addSdrConnectStyleData(false, rEndFromTL, -rY - rX, true);
1265 static void HelperClipLine(
1266 basegfx::B2DPoint& rStart,
1267 basegfx::B2DVector& rDirection,
1268 const basegfx::B2DRange& rClipRange)
1270 basegfx::B2DPolygon aLine({rStart, rStart + rDirection});
1271 const basegfx::B2DPolyPolygon aResultPP(
1272 basegfx::utils::clipPolygonOnRange(
1273 aLine,
1274 rClipRange,
1275 true, // bInside
1276 true)); // bStroke
1278 if(aResultPP.count() > 0)
1280 const basegfx::B2DPolygon& aResultP(aResultPP.getB2DPolygon(0));
1282 if(aResultP.count() > 0)
1284 const basegfx::B2DPoint aResultStart(aResultP.getB2DPoint(0));
1285 const basegfx::B2DPoint aResultEnd(aResultP.getB2DPoint(aResultP.count() - 1));
1287 if(aResultStart != aResultEnd)
1289 rStart = aResultStart;
1290 rDirection = aResultEnd - aResultStart;
1296 static void HelperCreateTLBREntry(
1297 const Array& rArray,
1298 const Style& rStyle,
1299 drawinglayer::primitive2d::SdrFrameBorderDataVector& rData,
1300 const basegfx::B2DPoint& rOrigin,
1301 const basegfx::B2DVector& rX,
1302 const basegfx::B2DVector& rY,
1303 sal_Int32 nColLeft,
1304 sal_Int32 nColRight,
1305 sal_Int32 nRowTop,
1306 sal_Int32 nRowBottom,
1307 const Color* pForceColor,
1308 const basegfx::B2DRange* pClipRange)
1310 if(rStyle.IsUsed())
1312 /// prepare geometry line data
1313 basegfx::B2DPoint aStart(rOrigin);
1314 basegfx::B2DVector aDirection(rX + rY);
1316 /// check if we need to clip geometry line data and do it
1317 if(nullptr != pClipRange)
1319 HelperClipLine(aStart, aDirection, *pClipRange);
1322 /// top-left and bottom-right Style Tables
1323 rData.emplace_back(
1324 aStart,
1325 aDirection,
1326 rStyle,
1327 pForceColor);
1328 drawinglayer::primitive2d::SdrFrameBorderData& rInstance(rData.back());
1330 /// Fill top-left Style Table
1331 const Style& rTLFromRight(rArray.GetCellStyleTop(nColLeft, nRowTop));
1332 const Style& rTLFromBottom(rArray.GetCellStyleLeft(nColLeft, nRowTop));
1334 rInstance.addSdrConnectStyleData(true, rTLFromRight, rX, false);
1335 rInstance.addSdrConnectStyleData(true, rTLFromBottom, rY, false);
1337 /// Fill bottom-right Style Table
1338 const Style& rBRFromBottom(rArray.GetCellStyleRight(nColRight, nRowBottom));
1339 const Style& rBRFromLeft(rArray.GetCellStyleBottom(nColRight, nRowBottom));
1341 rInstance.addSdrConnectStyleData(false, rBRFromBottom, -rY, true);
1342 rInstance.addSdrConnectStyleData(false, rBRFromLeft, -rX, true);
1346 static void HelperCreateBLTREntry(
1347 const Array& rArray,
1348 const Style& rStyle,
1349 drawinglayer::primitive2d::SdrFrameBorderDataVector& rData,
1350 const basegfx::B2DPoint& rOrigin,
1351 const basegfx::B2DVector& rX,
1352 const basegfx::B2DVector& rY,
1353 sal_Int32 nColLeft,
1354 sal_Int32 nColRight,
1355 sal_Int32 nRowTop,
1356 sal_Int32 nRowBottom,
1357 const Color* pForceColor,
1358 const basegfx::B2DRange* pClipRange)
1360 if(rStyle.IsUsed())
1362 /// prepare geometry line data
1363 basegfx::B2DPoint aStart(rOrigin + rY);
1364 basegfx::B2DVector aDirection(rX - rY);
1366 /// check if we need to clip geometry line data and do it
1367 if(nullptr != pClipRange)
1369 HelperClipLine(aStart, aDirection, *pClipRange);
1372 /// bottom-left and top-right Style Tables
1373 rData.emplace_back(
1374 aStart,
1375 aDirection,
1376 rStyle,
1377 pForceColor);
1378 drawinglayer::primitive2d::SdrFrameBorderData& rInstance(rData.back());
1380 /// Fill bottom-left Style Table
1381 const Style& rBLFromTop(rArray.GetCellStyleLeft(nColLeft, nRowBottom));
1382 const Style& rBLFromBottom(rArray.GetCellStyleBottom(nColLeft, nRowBottom));
1384 rInstance.addSdrConnectStyleData(true, rBLFromTop, -rY, true);
1385 rInstance.addSdrConnectStyleData(true, rBLFromBottom, rX, false);
1387 /// Fill top-right Style Table
1388 const Style& rTRFromLeft(rArray.GetCellStyleTop(nColRight, nRowTop));
1389 const Style& rTRFromBottom(rArray.GetCellStyleRight(nColRight, nRowTop));
1391 rInstance.addSdrConnectStyleData(false, rTRFromLeft, -rX, true);
1392 rInstance.addSdrConnectStyleData(false, rTRFromBottom, rY, false);
1396 drawinglayer::primitive2d::Primitive2DContainer Array::CreateB2DPrimitiveRange(
1397 sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow,
1398 const Color* pForceColor ) const
1400 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "CreateB2DPrimitiveRange" );
1401 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "CreateB2DPrimitiveRange" );
1403 #ifdef OPTICAL_CHECK_CLIPRANGE_FOR_MERGED_CELL
1404 std::vector<basegfx::B2DRange> aClipRanges;
1405 #endif
1407 // It may be necessary to extend the loop ranges by one cell to the outside,
1408 // when possible. This is needed e.g. when there is in Calc a Cell with an
1409 // upper CellBorder using DoubleLine and that is right/left connected upwards
1410 // to also DoubleLine. These upper DoubleLines will be extended to meet the
1411 // lower of the upper CellBorder and thus have graphical parts that are
1412 // displayed one cell below and right/left of the target cell - analog to
1413 // other examples in all other directions.
1414 // It would be possible to explicitly test this (if possible by indices at all)
1415 // looping and testing the styles in the outer cells to detect this, but since
1416 // for other usages (e.g. UI) usually nFirstRow==0 and nLastRow==GetRowCount()-1
1417 // (and analog for Col) it is okay to just expand the range when available.
1418 // Do *not* change nFirstRow/nLastRow due to these needed to the boolean tests
1419 // below (!)
1420 // Checked usages, this method is used in Calc EditView/Print/Export stuff and
1421 // in UI (Dialog), not for Writer Tables and Draw/Impress tables. All usages
1422 // seem okay with this change, so I will add it.
1423 const sal_Int32 nStartRow(nFirstRow > 0 ? nFirstRow - 1 : nFirstRow);
1424 const sal_Int32 nEndRow(nLastRow < GetRowCount() - 1 ? nLastRow + 1 : nLastRow);
1425 const sal_Int32 nStartCol(nFirstCol > 0 ? nFirstCol - 1 : nFirstCol);
1426 const sal_Int32 nEndCol(nLastCol < GetColCount() - 1 ? nLastCol + 1 : nLastCol);
1428 // prepare SdrFrameBorderDataVector
1429 drawinglayer::primitive2d::SdrFrameBorderDataVector aData;
1431 // remember for which merged cells crossed lines were already created. To
1432 // do so, hold the sal_Int32 cell index in a set for fast check
1433 std::unordered_set< sal_Int32 > aMergedCells;
1435 for (sal_Int32 nRow(nStartRow); nRow <= nEndRow; ++nRow)
1437 for (sal_Int32 nCol(nStartCol); nCol <= nEndCol; ++nCol)
1439 // get Cell and CoordinateSystem (*only* for this Cell, do *not* expand for
1440 // merged cells (!)), check if used (non-empty vectors)
1441 const Cell* pCell(mxImpl->GetCell(nCol, nRow));
1442 basegfx::B2DHomMatrix aCoordinateSystem(pCell->CreateCoordinateSystemSingleCell(*this, nCol, nRow));
1443 basegfx::B2DVector aX(basegfx::utils::getColumn(aCoordinateSystem, 0));
1444 basegfx::B2DVector aY(basegfx::utils::getColumn(aCoordinateSystem, 1));
1446 // get needed local values
1447 basegfx::B2DPoint aOrigin(basegfx::utils::getColumn(aCoordinateSystem, 2));
1448 const bool bOverlapX(pCell->mbOverlapX);
1449 const bool bFirstCol(nCol == nFirstCol);
1451 // handle rotation: If cell is rotated, handle lower/right edge inside
1452 // this local geometry due to the created CoordinateSystem already representing
1453 // the needed transformations.
1454 const bool bRotated(pCell->IsRotated());
1456 // Additionally avoid double-handling by suppressing handling when self not rotated,
1457 // but above/left is rotated and thus already handled. Two directly connected
1458 // rotated will paint/create both edges, they might be rotated differently.
1459 const bool bSuppressLeft(!bRotated && nCol > nFirstCol && mxImpl->GetCell(nCol - 1, nRow)->IsRotated());
1460 const bool bSuppressAbove(!bRotated && nRow > nFirstRow && mxImpl->GetCell(nCol, nRow - 1)->IsRotated());
1462 if(!aX.equalZero() && !aY.equalZero())
1464 // additionally needed local values
1465 const bool bOverlapY(pCell->mbOverlapY);
1466 const bool bLastCol(nCol == nLastCol);
1467 const bool bFirstRow(nRow == nFirstRow);
1468 const bool bLastRow(nRow == nLastRow);
1470 // create upper line for this Cell
1471 if ((!bOverlapY // true for first line in merged cells or cells
1472 || bFirstRow) // true for non_Calc usages of this tooling
1473 && !bSuppressAbove) // true when above is not rotated, so edge is already handled (see bRotated)
1475 // get CellStyle - method will take care to get the correct one, e.g.
1476 // for merged cells (it uses mxImpl->GetMergedOriginCell that works with topLeft's of these)
1477 const Style& rTop(GetCellStyleTop(nCol, nRow));
1479 if(rTop.IsUsed())
1481 HelperCreateHorizontalEntry(*this, rTop, nCol, nRow, aOrigin, aX, aY, aData, true, pForceColor);
1485 // create lower line for this Cell
1486 if (bLastRow // true for non_Calc usages of this tooling
1487 || bRotated) // true if cell is rotated, handle lower edge in local geometry
1489 const Style& rBottom(GetCellStyleBottom(nCol, nRow));
1491 if(rBottom.IsUsed())
1493 HelperCreateHorizontalEntry(*this, rBottom, nCol, nRow + 1, aOrigin, aX, aY, aData, false, pForceColor);
1497 // create left line for this Cell
1498 if ((!bOverlapX // true for first column in merged cells or cells
1499 || bFirstCol) // true for non_Calc usages of this tooling
1500 && !bSuppressLeft) // true when left is not rotated, so edge is already handled (see bRotated)
1502 const Style& rLeft(GetCellStyleLeft(nCol, nRow));
1504 if(rLeft.IsUsed())
1506 HelperCreateVerticalEntry(*this, rLeft, nCol, nRow, aOrigin, aX, aY, aData, true, pForceColor);
1510 // create right line for this Cell
1511 if (bLastCol // true for non_Calc usages of this tooling
1512 || bRotated) // true if cell is rotated, handle right edge in local geometry
1514 const Style& rRight(GetCellStyleRight(nCol, nRow));
1516 if(rRight.IsUsed())
1518 HelperCreateVerticalEntry(*this, rRight, nCol + 1, nRow, aOrigin, aX, aY, aData, false, pForceColor);
1522 // tdf#126269 check for crossed lines, these need special treatment, especially
1523 // for merged cells (see comments in task). Separate treatment of merged and
1524 // non-merged cells to allow better handling of both types
1525 if(pCell->IsMerged())
1527 // first check if this merged cell was already handled. To do so,
1528 // calculate and use the index of the TopLeft cell
1529 sal_Int32 nColLeft(nCol), nRowTop(nRow), nColRight(nCol), nRowBottom(nRow);
1530 GetMergedRange(nColLeft, nRowTop, nColRight, nRowBottom, nCol, nRow);
1531 const sal_Int32 nIndexOfMergedCell(mxImpl->GetIndex(nColLeft, nRowTop));
1533 auto aItInsertedPair = aMergedCells.insert(nIndexOfMergedCell);
1534 if(aItInsertedPair.second)
1536 // not found, so not yet handled.
1538 // Get and check if diagonal styles are used
1539 // Note: For GetCellStyleBLTR below I tried to use nRowBottom
1540 // as Y-value what seemed more logical, but that
1541 // is wrong. Despite defining a line starting at
1542 // bottom-left, the Style is defined in the cell at top-left
1543 const Style& rTLBR(GetCellStyleTLBR(nColLeft, nRowTop));
1544 const Style& rBLTR(GetCellStyleBLTR(nColLeft, nRowTop));
1546 if(rTLBR.IsUsed() || rBLTR.IsUsed())
1548 // test if merged cell overlaps ClipRange at all (needs visualization)
1549 if(mxImpl->OverlapsClipRange(nColLeft, nRowTop, nColRight, nRowBottom))
1551 // when merged, get extended coordinate system and derived values
1552 // for the full range of this merged cell. Only work with rMergedCell
1553 // (which is the top-left single cell of the merged cell) from here on
1554 aCoordinateSystem = mxImpl->GetCell(nColLeft, nRowTop)->CreateCoordinateSystemMergedCell(
1555 *this, nColLeft, nRowTop, nColRight, nRowBottom);
1556 aX = basegfx::utils::getColumn(aCoordinateSystem, 0);
1557 aY = basegfx::utils::getColumn(aCoordinateSystem, 1);
1558 aOrigin = basegfx::utils::getColumn(aCoordinateSystem, 2);
1560 // check if clip is needed
1561 basegfx::B2DRange aClipRange;
1563 // first use row/col ClipTest for raw check
1564 bool bNeedToClip(
1565 !mxImpl->IsColInClipRange(nColLeft) ||
1566 !mxImpl->IsRowInClipRange(nRowTop) ||
1567 !mxImpl->IsColInClipRange(nColRight) ||
1568 !mxImpl->IsRowInClipRange(nRowBottom));
1570 if(bNeedToClip)
1572 // now get ClipRange and CellRange in logical coordinates
1573 aClipRange = GetB2DRange(
1574 mxImpl->mnFirstClipCol, mxImpl->mnFirstClipRow,
1575 mxImpl->mnLastClipCol, mxImpl->mnLastClipRow);
1577 basegfx::B2DRange aCellRange(
1578 GetB2DRange(
1579 nColLeft, nRowTop,
1580 nColRight, nRowBottom));
1582 // intersect these to get the target ClipRange, ensure
1583 // that clip is needed
1584 aClipRange.intersect(aCellRange);
1585 bNeedToClip = !aClipRange.isEmpty();
1587 #ifdef OPTICAL_CHECK_CLIPRANGE_FOR_MERGED_CELL
1588 aClipRanges.push_back(aClipRange);
1589 #endif
1592 // create top-left to bottom-right geometry
1593 HelperCreateTLBREntry(*this, rTLBR, aData, aOrigin, aX, aY,
1594 nColLeft, nRowTop, nColRight, nRowBottom, pForceColor,
1595 bNeedToClip ? &aClipRange : nullptr);
1597 // create bottom-left to top-right geometry
1598 HelperCreateBLTREntry(*this, rBLTR, aData, aOrigin, aX, aY,
1599 nColLeft, nRowTop, nColRight, nRowBottom, pForceColor,
1600 bNeedToClip ? &aClipRange : nullptr);
1605 else
1607 // must be in clipping range: else not visible. This
1608 // already clips completely for non-merged cells
1609 if( mxImpl->IsInClipRange( nCol, nRow ) )
1611 // get and check if diagonal styles are used
1612 const Style& rTLBR(GetCellStyleTLBR(nCol, nRow));
1613 const Style& rBLTR(GetCellStyleBLTR(nCol, nRow));
1615 if(rTLBR.IsUsed() || rBLTR.IsUsed())
1617 HelperCreateTLBREntry(*this, rTLBR, aData, aOrigin, aX, aY,
1618 nCol, nRow, nCol, nRow, pForceColor, nullptr);
1620 HelperCreateBLTREntry(*this, rBLTR, aData, aOrigin, aX, aY,
1621 nCol, nRow, nCol, nRow, pForceColor, nullptr);
1626 else if(!aY.equalZero())
1628 // cell has height, but no width. Create left vertical line for this Cell
1629 if ((!bOverlapX // true for first column in merged cells or cells
1630 || bFirstCol) // true for non_Calc usages of this tooling
1631 && !bSuppressLeft) // true when left is not rotated, so edge is already handled (see bRotated)
1633 const Style& rLeft(GetCellStyleLeft(nCol, nRow));
1635 if (rLeft.IsUsed())
1637 HelperCreateVerticalEntry(*this, rLeft, nCol, nRow, aOrigin, aX, aY, aData, true, pForceColor);
1641 else
1643 // Cell has *no* size, thus no visualization
1648 // create instance of SdrFrameBorderPrimitive2D if
1649 // SdrFrameBorderDataVector is used
1650 drawinglayer::primitive2d::Primitive2DContainer aSequence;
1652 if(!aData.empty())
1654 aSequence.append(
1655 new drawinglayer::primitive2d::SdrFrameBorderPrimitive2D(
1656 std::move(aData),
1657 true)); // force visualization to minimal one discrete unit (pixel)
1660 #ifdef OPTICAL_CHECK_CLIPRANGE_FOR_MERGED_CELL
1661 for(auto const& rClipRange : aClipRanges)
1663 // draw ClipRange in yellow to allow simple interactive optical control in office
1664 aSequence.append(
1665 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
1666 basegfx::utils::createPolygonFromRect(rClipRange),
1667 basegfx::BColor(1.0, 1.0, 0.0)));
1669 #endif
1671 return aSequence;
1674 drawinglayer::primitive2d::Primitive2DContainer Array::CreateB2DPrimitiveArray() const
1676 drawinglayer::primitive2d::Primitive2DContainer aPrimitives;
1678 if (mxImpl->mnWidth && mxImpl->mnHeight)
1680 aPrimitives = CreateB2DPrimitiveRange(0, 0, mxImpl->mnWidth - 1, mxImpl->mnHeight - 1, nullptr);
1683 return aPrimitives;
1686 #undef DBG_FRAME_CHECK_ROW_1
1687 #undef DBG_FRAME_CHECK_COL_1
1688 #undef DBG_FRAME_CHECK_COLROW
1689 #undef DBG_FRAME_CHECK_ROW
1690 #undef DBG_FRAME_CHECK_COL
1691 #undef DBG_FRAME_CHECK
1695 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */