fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / dialog / framelinkarray.cxx
blobd82b959d686ababc920e3d7350663bfe8ad57568
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 <algorithm>
25 #include <vcl/outdev.hxx>
27 namespace svx {
28 namespace frame {
30 // ============================================================================
33 Cell::Cell() :
34 mnAddLeft( 0 ),
35 mnAddRight( 0 ),
36 mnAddTop( 0 ),
37 mnAddBottom( 0 ),
38 mbMergeOrig( false ),
39 mbOverlapX( false ),
40 mbOverlapY( false )
44 void Cell::MirrorSelfX( bool bMirrorStyles, bool bSwapDiag )
46 std::swap( maLeft, maRight );
47 std::swap( mnAddLeft, mnAddRight );
48 if( bMirrorStyles )
50 maLeft.MirrorSelf();
51 maRight.MirrorSelf();
53 if( bSwapDiag )
55 std::swap( maTLBR, maBLTR );
56 if( bMirrorStyles )
58 maTLBR.MirrorSelf();
59 maBLTR.MirrorSelf();
64 // ----------------------------------------------------------------------------
67 void lclRecalcCoordVec( LongVec& rCoords, const LongVec& rSizes )
69 DBG_ASSERT( rCoords.size() == rSizes.size() + 1, "lclRecalcCoordVec - inconsistent vectors" );
70 LongVec::iterator aCIt = rCoords.begin();
71 LongVec::const_iterator aSIt = rSizes.begin(), aSEnd = rSizes.end();
72 for( ; aSIt != aSEnd; ++aCIt, ++aSIt )
73 *(aCIt + 1) = *aCIt + *aSIt;
76 void lclSetMergedRange( CellVec& rCells, size_t nWidth, size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow )
78 for( size_t nCol = nFirstCol; nCol <= nLastCol; ++nCol )
80 for( size_t nRow = nFirstRow; nRow <= nLastRow; ++nRow )
82 Cell& rCell = rCells[ nRow * nWidth + nCol ];
83 rCell.mbMergeOrig = false;
84 rCell.mbOverlapX = nCol > nFirstCol;
85 rCell.mbOverlapY = nRow > nFirstRow;
88 rCells[ nFirstRow * nWidth + nFirstCol ].mbMergeOrig = true;
91 // ----------------------------------------------------------------------------
93 static const Style OBJ_STYLE_NONE;
94 static const Cell OBJ_CELL_NONE;
96 const bool DIAG_DBL_CLIP_DEFAULT = false;
98 // ============================================================================
100 ArrayImpl::ArrayImpl( size_t nWidth, size_t nHeight, bool bDiagDblClip ) :
101 mnWidth( nWidth ),
102 mnHeight( nHeight ),
103 mnFirstClipCol( 0 ),
104 mnFirstClipRow( 0 ),
105 mnLastClipCol( nWidth - 1 ),
106 mnLastClipRow( nHeight - 1 ),
107 mbXCoordsDirty( false ),
108 mbYCoordsDirty( false ),
109 mbDiagDblClip( bDiagDblClip )
111 // default-construct all vectors
112 maCells.resize( mnWidth * mnHeight );
113 maWidths.resize( mnWidth, 0L );
114 maHeights.resize( mnHeight, 0L );
115 maXCoords.resize( mnWidth + 1, 0L );
116 maYCoords.resize( mnHeight + 1, 0L );
119 const Cell& ArrayImpl::GetCell( size_t nCol, size_t nRow ) const
121 return IsValidPos( nCol, nRow ) ? maCells[ GetIndex( nCol, nRow ) ] : OBJ_CELL_NONE;
124 Cell& ArrayImpl::GetCellAcc( size_t nCol, size_t nRow )
126 static Cell aDummy;
127 return IsValidPos( nCol, nRow ) ? maCells[ GetIndex( nCol, nRow ) ] : aDummy;
130 size_t ArrayImpl::GetMergedFirstCol( size_t nCol, size_t nRow ) const
132 size_t nFirstCol = nCol;
133 while( (nFirstCol > 0) && GetCell( nFirstCol, nRow ).mbOverlapX ) --nFirstCol;
134 return nFirstCol;
137 size_t ArrayImpl::GetMergedFirstRow( size_t nCol, size_t nRow ) const
139 size_t nFirstRow = nRow;
140 while( (nFirstRow > 0) && GetCell( nCol, nFirstRow ).mbOverlapY ) --nFirstRow;
141 return nFirstRow;
144 size_t ArrayImpl::GetMergedLastCol( size_t nCol, size_t nRow ) const
146 size_t nLastCol = nCol + 1;
147 while( (nLastCol < mnWidth) && GetCell( nLastCol, nRow ).mbOverlapX ) ++nLastCol;
148 return nLastCol - 1;
151 size_t ArrayImpl::GetMergedLastRow( size_t nCol, size_t nRow ) const
153 size_t nLastRow = nRow + 1;
154 while( (nLastRow < mnHeight) && GetCell( nCol, nLastRow ).mbOverlapY ) ++nLastRow;
155 return nLastRow - 1;
158 const Cell& ArrayImpl::GetMergedOriginCell( size_t nCol, size_t nRow ) const
160 return GetCell( GetMergedFirstCol( nCol, nRow ), GetMergedFirstRow( nCol, nRow ) );
163 bool ArrayImpl::IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const
165 const Cell& rCell = GetCell( nCol, nRow );
166 return rCell.mbOverlapX || (rCell.mnAddLeft > 0);
169 bool ArrayImpl::IsMergedOverlappedRight( size_t nCol, size_t nRow ) const
171 return GetCell( nCol + 1, nRow ).mbOverlapX || (GetCell( nCol, nRow ).mnAddRight > 0);
174 bool ArrayImpl::IsMergedOverlappedTop( size_t nCol, size_t nRow ) const
176 const Cell& rCell = GetCell( nCol, nRow );
177 return rCell.mbOverlapY || (rCell.mnAddTop > 0);
180 bool ArrayImpl::IsMergedOverlappedBottom( size_t nCol, size_t nRow ) const
182 return GetCell( nCol, nRow + 1 ).mbOverlapY || (GetCell( nCol, nRow ).mnAddBottom > 0);
185 bool ArrayImpl::IsColInClipRange( size_t nCol ) const
187 return (mnFirstClipCol <= nCol) && (nCol <= mnLastClipCol);
190 bool ArrayImpl::IsRowInClipRange( size_t nRow ) const
192 return (mnFirstClipRow <= nRow) && (nRow <= mnLastClipRow);
195 bool ArrayImpl::IsInClipRange( size_t nCol, size_t nRow ) const
197 return IsColInClipRange( nCol ) && IsRowInClipRange( nRow );
200 long ArrayImpl::GetColPosition( size_t nCol ) const
202 if( mbXCoordsDirty )
204 lclRecalcCoordVec( maXCoords, maWidths );
205 mbXCoordsDirty = false;
207 return maXCoords[ nCol ];
210 long ArrayImpl::GetRowPosition( size_t nRow ) const
212 if( mbYCoordsDirty )
214 lclRecalcCoordVec( maYCoords, maHeights );
215 mbYCoordsDirty = false;
217 return maYCoords[ nRow ];
220 long ArrayImpl::GetColWidth( size_t nFirstCol, size_t nLastCol ) const
222 return GetColPosition( nLastCol + 1 ) - GetColPosition( nFirstCol );
225 long ArrayImpl::GetRowHeight( size_t nFirstRow, size_t nLastRow ) const
227 return GetRowPosition( nLastRow + 1 ) - GetRowPosition( nFirstRow );
230 double ArrayImpl::GetHorDiagAngle( size_t nCol, size_t nRow, bool bSimple ) const
232 double fAngle = 0.0;
233 if( IsValidPos( nCol, nRow ) )
235 if( bSimple || !GetCell( nCol, nRow ).IsMerged() )
237 fAngle = frame::GetHorDiagAngle( maWidths[ nCol ] + 1, maHeights[ nRow ] + 1 );
239 else
241 // return correct angle for each cell in the merged range
242 size_t nFirstCol = GetMergedFirstCol( nCol, nRow );
243 size_t nFirstRow = GetMergedFirstRow( nCol, nRow );
244 const Cell& rCell = GetCell( nFirstCol, nFirstRow );
245 long nWidth = GetColWidth( nFirstCol, GetMergedLastCol( nCol, nRow ) ) + rCell.mnAddLeft + rCell.mnAddRight;
246 long nHeight = GetRowHeight( nFirstRow, GetMergedLastRow( nCol, nRow ) ) + rCell.mnAddTop + rCell.mnAddBottom;
247 fAngle = frame::GetHorDiagAngle( nWidth + 1, nHeight + 1 );
250 return fAngle;
253 double ArrayImpl::GetVerDiagAngle( size_t nCol, size_t nRow, bool bSimple ) const
255 double fAngle = GetHorDiagAngle( nCol, nRow, bSimple );
256 return (fAngle > 0.0) ? (F_PI2 - fAngle) : 0.0;
259 // ============================================================================
261 class MergedCellIterator
263 public:
264 explicit MergedCellIterator( const Array& rArray, size_t nCol, size_t nRow );
266 inline bool Is() const { return (mnCol <= mnLastCol) && (mnRow <= mnLastRow); }
267 inline size_t Col() const { return mnCol; }
268 inline size_t Row() const { return mnRow; }
270 MergedCellIterator& operator++();
272 private:
273 size_t mnFirstCol;
274 size_t mnFirstRow;
275 size_t mnLastCol;
276 size_t mnLastRow;
277 size_t mnCol;
278 size_t mnRow;
281 // ----------------------------------------------------------------------------
283 MergedCellIterator::MergedCellIterator( const Array& rArray, size_t nCol, size_t nRow )
285 DBG_ASSERT( rArray.IsMerged( nCol, nRow ), "svx::frame::MergedCellIterator::MergedCellIterator - not in merged range" );
286 rArray.GetMergedRange( mnFirstCol, mnFirstRow, mnLastCol, mnLastRow, nCol, nRow );
287 mnCol = mnFirstCol;
288 mnRow = mnFirstRow;
291 MergedCellIterator& MergedCellIterator::operator++()
293 DBG_ASSERT( Is(), "svx::frame::MergedCellIterator::operator++() - already invalid" );
294 if( ++mnCol > mnLastCol )
296 mnCol = mnFirstCol;
297 ++mnRow;
299 return *this;
302 // ============================================================================
304 #define DBG_FRAME_CHECK( cond, funcname, error ) DBG_ASSERT( cond, "svx::frame::Array::" funcname " - " error )
305 #define DBG_FRAME_CHECK_COL( col, funcname ) DBG_FRAME_CHECK( (col) < GetColCount(), funcname, "invalid column index" )
306 #define DBG_FRAME_CHECK_ROW( row, funcname ) DBG_FRAME_CHECK( (row) < GetRowCount(), funcname, "invalid row index" )
307 #define DBG_FRAME_CHECK_COLROW( col, row, funcname ) DBG_FRAME_CHECK( ((col) < GetColCount()) && ((row) < GetRowCount()), funcname, "invalid cell index" )
308 #define DBG_FRAME_CHECK_COL_1( col, funcname ) DBG_FRAME_CHECK( (col) <= GetColCount(), funcname, "invalid column index" )
309 #define DBG_FRAME_CHECK_ROW_1( row, funcname ) DBG_FRAME_CHECK( (row) <= GetRowCount(), funcname, "invalid row index" )
311 // ----------------------------------------------------------------------------
313 #define CELL( col, row ) mxImpl->GetCell( col, row )
314 #define CELLACC( col, row ) mxImpl->GetCellAcc( col, row )
315 #define ORIGCELL( col, row ) mxImpl->GetMergedOriginCell( col, row )
317 // ----------------------------------------------------------------------------
319 Array::Array()
321 Initialize( 0, 0 );
324 Array::~Array()
328 // array size and column/row indexes ------------------------------------------
330 void Array::Initialize( size_t nWidth, size_t nHeight )
332 bool bDiagDblClip = mxImpl.get() ? mxImpl->mbDiagDblClip : DIAG_DBL_CLIP_DEFAULT;
333 mxImpl.reset( new ArrayImpl( nWidth, nHeight, bDiagDblClip ) );
336 size_t Array::GetColCount() const
338 return mxImpl->mnWidth;
341 size_t Array::GetRowCount() const
343 return mxImpl->mnHeight;
346 size_t Array::GetCellCount() const
348 return mxImpl->maCells.size();
351 size_t Array::GetCellIndex( size_t nCol, size_t nRow, bool bRTL ) const
353 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetCellIndex" );
354 if (bRTL)
355 nCol = mxImpl->GetMirrorCol(nCol);
356 return mxImpl->GetIndex( nCol, nRow );
359 // cell border styles ---------------------------------------------------------
361 void Array::SetCellStyleLeft( size_t nCol, size_t nRow, const Style& rStyle )
363 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleLeft" );
364 CELLACC( nCol, nRow ).maLeft = rStyle;
367 void Array::SetCellStyleRight( size_t nCol, size_t nRow, const Style& rStyle )
369 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleRight" );
370 CELLACC( nCol, nRow ).maRight = rStyle;
373 void Array::SetCellStyleTop( size_t nCol, size_t nRow, const Style& rStyle )
375 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleTop" );
376 CELLACC( nCol, nRow ).maTop = rStyle;
379 void Array::SetCellStyleBottom( size_t nCol, size_t nRow, const Style& rStyle )
381 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleBottom" );
382 CELLACC( nCol, nRow ).maBottom = rStyle;
385 void Array::SetCellStyleTLBR( size_t nCol, size_t nRow, const Style& rStyle )
387 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleTLBR" );
388 CELLACC( nCol, nRow ).maTLBR = rStyle;
391 void Array::SetCellStyleBLTR( size_t nCol, size_t nRow, const Style& rStyle )
393 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleBLTR" );
394 CELLACC( nCol, nRow ).maBLTR = rStyle;
397 void Array::SetCellStyleDiag( size_t nCol, size_t nRow, const Style& rTLBR, const Style& rBLTR )
399 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetCellStyleDiag" );
400 Cell& rCell = CELLACC( nCol, nRow );
401 rCell.maTLBR = rTLBR;
402 rCell.maBLTR = rBLTR;
405 void Array::SetColumnStyleLeft( size_t nCol, const Style& rStyle )
407 DBG_FRAME_CHECK_COL( nCol, "SetColumnStyleLeft" );
408 for( size_t nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
409 SetCellStyleLeft( nCol, nRow, rStyle );
412 void Array::SetColumnStyleRight( size_t nCol, const Style& rStyle )
414 DBG_FRAME_CHECK_COL( nCol, "SetColumnStyleRight" );
415 for( size_t nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
416 SetCellStyleRight( nCol, nRow, rStyle );
419 void Array::SetRowStyleTop( size_t nRow, const Style& rStyle )
421 DBG_FRAME_CHECK_ROW( nRow, "SetRowStyleTop" );
422 for( size_t nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
423 SetCellStyleTop( nCol, nRow, rStyle );
426 void Array::SetRowStyleBottom( size_t nRow, const Style& rStyle )
428 DBG_FRAME_CHECK_ROW( nRow, "SetRowStyleBottom" );
429 for( size_t nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
430 SetCellStyleBottom( nCol, nRow, rStyle );
433 const Style& Array::GetCellStyleLeft( size_t nCol, size_t nRow, bool bSimple ) const
435 // simple: always return own left style
436 if( bSimple )
437 return CELL( nCol, nRow ).maLeft;
438 // outside clipping rows or overlapped in merged cells: invisible
439 if( !mxImpl->IsRowInClipRange( nRow ) || mxImpl->IsMergedOverlappedLeft( nCol, nRow ) )
440 return OBJ_STYLE_NONE;
441 // left clipping border: always own left style
442 if( nCol == mxImpl->mnFirstClipCol )
443 return ORIGCELL( nCol, nRow ).maLeft;
444 // right clipping border: always right style of left neighbor cell
445 if( nCol == mxImpl->mnLastClipCol + 1 )
446 return ORIGCELL( nCol - 1, nRow ).maRight;
447 // outside clipping columns: invisible
448 if( !mxImpl->IsColInClipRange( nCol ) )
449 return OBJ_STYLE_NONE;
450 // inside clipping range: maximum of own left style and right style of left neighbor cell
451 return std::max( ORIGCELL( nCol, nRow ).maLeft, ORIGCELL( nCol - 1, nRow ).maRight );
454 const Style& Array::GetCellStyleRight( size_t nCol, size_t nRow, bool bSimple ) const
456 // simple: always return own right style
457 if( bSimple )
458 return CELL( nCol, nRow ).maRight;
459 // outside clipping rows or overlapped in merged cells: invisible
460 if( !mxImpl->IsRowInClipRange( nRow ) || mxImpl->IsMergedOverlappedRight( nCol, nRow ) )
461 return OBJ_STYLE_NONE;
462 // left clipping border: always left style of right neighbor cell
463 if( nCol + 1 == mxImpl->mnFirstClipCol )
464 return ORIGCELL( nCol + 1, nRow ).maLeft;
465 // right clipping border: always own right style
466 if( nCol == mxImpl->mnLastClipCol )
467 return ORIGCELL( nCol, nRow ).maRight;
468 // outside clipping columns: invisible
469 if( !mxImpl->IsColInClipRange( nCol ) )
470 return OBJ_STYLE_NONE;
471 // inside clipping range: maximum of own right style and left style of right neighbor cell
472 return std::max( ORIGCELL( nCol, nRow ).maRight, ORIGCELL( nCol + 1, nRow ).maLeft );
475 const Style& Array::GetCellStyleTop( size_t nCol, size_t nRow, bool bSimple ) const
477 // simple: always return own top style
478 if( bSimple )
479 return CELL( nCol, nRow ).maTop;
480 // outside clipping columns or overlapped in merged cells: invisible
481 if( !mxImpl->IsColInClipRange( nCol ) || mxImpl->IsMergedOverlappedTop( nCol, nRow ) )
482 return OBJ_STYLE_NONE;
483 // top clipping border: always own top style
484 if( nRow == mxImpl->mnFirstClipRow )
485 return ORIGCELL( nCol, nRow ).maTop;
486 // bottom clipping border: always bottom style of top neighbor cell
487 if( nRow == mxImpl->mnLastClipRow + 1 )
488 return ORIGCELL( nCol, nRow - 1 ).maBottom;
489 // outside clipping rows: invisible
490 if( !mxImpl->IsRowInClipRange( nRow ) )
491 return OBJ_STYLE_NONE;
492 // inside clipping range: maximum of own top style and bottom style of top neighbor cell
493 return std::max( ORIGCELL( nCol, nRow ).maTop, ORIGCELL( nCol, nRow - 1 ).maBottom );
496 const Style& Array::GetCellStyleBottom( size_t nCol, size_t nRow, bool bSimple ) const
498 // simple: always return own bottom style
499 if( bSimple )
500 return CELL( nCol, nRow ).maBottom;
501 // outside clipping columns or overlapped in merged cells: invisible
502 if( !mxImpl->IsColInClipRange( nCol ) || mxImpl->IsMergedOverlappedBottom( nCol, nRow ) )
503 return OBJ_STYLE_NONE;
504 // top clipping border: always top style of bottom neighbor cell
505 if( nRow + 1 == mxImpl->mnFirstClipRow )
506 return ORIGCELL( nCol, nRow + 1 ).maTop;
507 // bottom clipping border: always own bottom style
508 if( nRow == mxImpl->mnLastClipRow )
509 return ORIGCELL( nCol, nRow ).maBottom;
510 // outside clipping rows: invisible
511 if( !mxImpl->IsRowInClipRange( nRow ) )
512 return OBJ_STYLE_NONE;
513 // inside clipping range: maximum of own bottom style and top style of bottom neighbor cell
514 return std::max( ORIGCELL( nCol, nRow ).maBottom, ORIGCELL( nCol, nRow + 1 ).maTop );
517 const Style& Array::GetCellStyleTLBR( size_t nCol, size_t nRow, bool bSimple ) const
519 return bSimple ? CELL( nCol, nRow ).maTLBR :
520 (mxImpl->IsInClipRange( nCol, nRow ) ? ORIGCELL( nCol, nRow ).maTLBR : OBJ_STYLE_NONE);
523 const Style& Array::GetCellStyleBLTR( size_t nCol, size_t nRow, bool bSimple ) const
525 return bSimple ? CELL( nCol, nRow ).maBLTR :
526 (mxImpl->IsInClipRange( nCol, nRow ) ? ORIGCELL( nCol, nRow ).maBLTR : OBJ_STYLE_NONE);
529 const Style& Array::GetCellStyleTL( size_t nCol, size_t nRow ) const
531 // not in clipping range: always invisible
532 if( !mxImpl->IsInClipRange( nCol, nRow ) )
533 return OBJ_STYLE_NONE;
534 // return style only for top-left cell
535 size_t nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
536 size_t nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
537 return ((nCol == nFirstCol) && (nRow == nFirstRow)) ?
538 CELL( nFirstCol, nFirstRow ).maTLBR : OBJ_STYLE_NONE;
541 const Style& Array::GetCellStyleBR( size_t nCol, size_t nRow ) const
543 // not in clipping range: always invisible
544 if( !mxImpl->IsInClipRange( nCol, nRow ) )
545 return OBJ_STYLE_NONE;
546 // return style only for bottom-right cell
547 size_t nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
548 size_t nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
549 return ((nCol == nLastCol) && (nRow == nLastRow)) ?
550 CELL( mxImpl->GetMergedFirstCol( nCol, nRow ), mxImpl->GetMergedFirstRow( nCol, nRow ) ).maTLBR : OBJ_STYLE_NONE;
553 const Style& Array::GetCellStyleBL( size_t nCol, size_t nRow ) const
555 // not in clipping range: always invisible
556 if( !mxImpl->IsInClipRange( nCol, nRow ) )
557 return OBJ_STYLE_NONE;
558 // return style only for bottom-left cell
559 size_t nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
560 size_t nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
561 return ((nCol == nFirstCol) && (nRow == nLastRow)) ?
562 CELL( nFirstCol, mxImpl->GetMergedFirstRow( nCol, nRow ) ).maBLTR : OBJ_STYLE_NONE;
565 const Style& Array::GetCellStyleTR( size_t nCol, size_t nRow ) const
567 // not in clipping range: always invisible
568 if( !mxImpl->IsInClipRange( nCol, nRow ) )
569 return OBJ_STYLE_NONE;
570 // return style only for top-right cell
571 size_t nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
572 size_t nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
573 return ((nCol == nLastCol) && (nRow == nFirstRow)) ?
574 CELL( mxImpl->GetMergedFirstCol( nCol, nRow ), nFirstRow ).maBLTR : OBJ_STYLE_NONE;
577 // cell merging ---------------------------------------------------------------
579 void Array::SetMergedRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow )
581 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "SetMergedRange" );
582 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "SetMergedRange" );
583 #if OSL_DEBUG_LEVEL >= 2
585 bool bFound = false;
586 for( size_t nCurrCol = nFirstCol; !bFound && (nCurrCol <= nLastCol); ++nCurrCol )
587 for( size_t nCurrRow = nFirstRow; !bFound && (nCurrRow <= nLastRow); ++nCurrRow )
588 bFound = CELL( nCurrCol, nCurrRow ).IsMerged();
589 DBG_FRAME_CHECK( !bFound, "SetMergedRange", "overlapping merged ranges" );
591 #endif
592 if( mxImpl->IsValidPos( nFirstCol, nFirstRow ) && mxImpl->IsValidPos( nLastCol, nLastRow ) )
593 lclSetMergedRange( mxImpl->maCells, mxImpl->mnWidth, nFirstCol, nFirstRow, nLastCol, nLastRow );
596 void Array::SetAddMergedLeftSize( size_t nCol, size_t nRow, long nAddSize )
598 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedLeftSize" );
599 DBG_FRAME_CHECK( mxImpl->GetMergedFirstCol( nCol, nRow ) == 0, "SetAddMergedLeftSize", "additional border inside array" );
600 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
601 CELLACC( aIt.Col(), aIt.Row() ).mnAddLeft = nAddSize;
604 void Array::SetAddMergedRightSize( size_t nCol, size_t nRow, long nAddSize )
606 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedRightSize" );
607 DBG_FRAME_CHECK( mxImpl->GetMergedLastCol( nCol, nRow ) + 1 == mxImpl->mnWidth, "SetAddMergedRightSize", "additional border inside array" );
608 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
609 CELLACC( aIt.Col(), aIt.Row() ).mnAddRight = nAddSize;
612 void Array::SetAddMergedTopSize( size_t nCol, size_t nRow, long nAddSize )
614 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedTopSize" );
615 DBG_FRAME_CHECK( mxImpl->GetMergedFirstRow( nCol, nRow ) == 0, "SetAddMergedTopSize", "additional border inside array" );
616 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
617 CELLACC( aIt.Col(), aIt.Row() ).mnAddTop = nAddSize;
620 void Array::SetAddMergedBottomSize( size_t nCol, size_t nRow, long nAddSize )
622 DBG_FRAME_CHECK_COLROW( nCol, nRow, "SetAddMergedBottomSize" );
623 DBG_FRAME_CHECK( mxImpl->GetMergedLastRow( nCol, nRow ) + 1 == mxImpl->mnHeight, "SetAddMergedBottomSize", "additional border inside array" );
624 for( MergedCellIterator aIt( *this, nCol, nRow ); aIt.Is(); ++aIt )
625 CELLACC( aIt.Col(), aIt.Row() ).mnAddBottom = nAddSize;
628 bool Array::IsMerged( size_t nCol, size_t nRow ) const
630 DBG_FRAME_CHECK_COLROW( nCol, nRow, "IsMerged" );
631 return CELL( nCol, nRow ).IsMerged();
634 bool Array::IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const
636 DBG_FRAME_CHECK_COLROW( nCol, nRow, "IsMergedOverlappedLeft" );
637 return mxImpl->IsMergedOverlappedLeft( nCol, nRow );
640 bool Array::IsMergedOverlappedRight( size_t nCol, size_t nRow ) const
642 DBG_FRAME_CHECK_COLROW( nCol, nRow, "IsMergedOverlappedRight" );
643 return mxImpl->IsMergedOverlappedRight( nCol, nRow );
646 void Array::GetMergedOrigin( size_t& rnFirstCol, size_t& rnFirstRow, size_t nCol, size_t nRow ) const
648 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetMergedOrigin" );
649 rnFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
650 rnFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
653 void Array::GetMergedRange( size_t& rnFirstCol, size_t& rnFirstRow,
654 size_t& rnLastCol, size_t& rnLastRow, size_t nCol, size_t nRow ) const
656 GetMergedOrigin( rnFirstCol, rnFirstRow, nCol, nRow );
657 rnLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
658 rnLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
661 // clipping -------------------------------------------------------------------
663 void Array::SetClipRange( size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow )
665 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "SetClipRange" );
666 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "SetClipRange" );
667 mxImpl->mnFirstClipCol = nFirstCol;
668 mxImpl->mnFirstClipRow = nFirstRow;
669 mxImpl->mnLastClipCol = nLastCol;
670 mxImpl->mnLastClipRow = nLastRow;
673 Rectangle Array::GetClipRangeRectangle() const
675 return Rectangle(
676 mxImpl->GetColPosition( mxImpl->mnFirstClipCol ),
677 mxImpl->GetRowPosition( mxImpl->mnFirstClipRow ),
678 mxImpl->GetColPosition( mxImpl->mnLastClipCol + 1 ),
679 mxImpl->GetRowPosition( mxImpl->mnLastClipRow + 1 ) );
682 // cell coordinates -----------------------------------------------------------
684 void Array::SetXOffset( long nXOffset )
686 mxImpl->maXCoords[ 0 ] = nXOffset;
687 mxImpl->mbXCoordsDirty = true;
690 void Array::SetYOffset( long nYOffset )
692 mxImpl->maYCoords[ 0 ] = nYOffset;
693 mxImpl->mbYCoordsDirty = true;
696 void Array::SetColWidth( size_t nCol, long nWidth )
698 DBG_FRAME_CHECK_COL( nCol, "SetColWidth" );
699 mxImpl->maWidths[ nCol ] = nWidth;
700 mxImpl->mbXCoordsDirty = true;
703 void Array::SetRowHeight( size_t nRow, long nHeight )
705 DBG_FRAME_CHECK_ROW( nRow, "SetRowHeight" );
706 mxImpl->maHeights[ nRow ] = nHeight;
707 mxImpl->mbYCoordsDirty = true;
710 void Array::SetAllColWidths( long nWidth )
712 std::fill( mxImpl->maWidths.begin(), mxImpl->maWidths.end(), nWidth );
713 mxImpl->mbXCoordsDirty = true;
716 void Array::SetAllRowHeights( long nHeight )
718 std::fill( mxImpl->maHeights.begin(), mxImpl->maHeights.end(), nHeight );
719 mxImpl->mbYCoordsDirty = true;
722 long Array::GetColPosition( size_t nCol ) const
724 DBG_FRAME_CHECK_COL_1( nCol, "GetColPosition" );
725 return mxImpl->GetColPosition( nCol );
728 long Array::GetRowPosition( size_t nRow ) const
730 DBG_FRAME_CHECK_ROW_1( nRow, "GetRowPosition" );
731 return mxImpl->GetRowPosition( nRow );
734 long Array::GetColWidth( size_t nFirstCol, size_t nLastCol ) const
736 DBG_FRAME_CHECK_COL( nFirstCol, "GetColWidth" );
737 DBG_FRAME_CHECK_COL( nLastCol, "GetColWidth" );
738 return GetColPosition( nLastCol + 1 ) - GetColPosition( nFirstCol );
741 long Array::GetRowHeight( size_t nFirstRow, size_t nLastRow ) const
743 DBG_FRAME_CHECK_ROW( nFirstRow, "GetRowHeight" );
744 DBG_FRAME_CHECK_ROW( nLastRow, "GetRowHeight" );
745 return GetRowPosition( nLastRow + 1 ) - GetRowPosition( nFirstRow );
748 long Array::GetWidth() const
750 return GetColPosition( mxImpl->mnWidth ) - GetColPosition( 0 );
753 long Array::GetHeight() const
755 return GetRowPosition( mxImpl->mnHeight ) - GetRowPosition( 0 );
758 Point Array::GetCellPosition( size_t nCol, size_t nRow, bool bSimple ) const
760 size_t nFirstCol = bSimple ? nCol : mxImpl->GetMergedFirstCol( nCol, nRow );
761 size_t nFirstRow = bSimple ? nRow : mxImpl->GetMergedFirstRow( nCol, nRow );
762 return Point( GetColPosition( nFirstCol ), GetRowPosition( nFirstRow ) );
765 Size Array::GetCellSize( size_t nCol, size_t nRow, bool bSimple ) const
767 size_t nFirstCol = bSimple ? nCol : mxImpl->GetMergedFirstCol( nCol, nRow );
768 size_t nFirstRow = bSimple ? nRow : mxImpl->GetMergedFirstRow( nCol, nRow );
769 size_t nLastCol = bSimple ? nCol : mxImpl->GetMergedLastCol( nCol, nRow );
770 size_t nLastRow = bSimple ? nRow : mxImpl->GetMergedLastRow( nCol, nRow );
771 return Size( GetColWidth( nFirstCol, nLastCol ) + 1, GetRowHeight( nFirstRow, nLastRow ) + 1 );
774 Rectangle Array::GetCellRect( size_t nCol, size_t nRow, bool bSimple ) const
776 Rectangle aRect( GetCellPosition( nCol, nRow, bSimple ), GetCellSize( nCol, nRow, bSimple ) );
778 // adjust rectangle for partly visible merged cells
779 const Cell& rCell = CELL( nCol, nRow );
780 if( !bSimple && rCell.IsMerged() )
782 aRect.Left() -= rCell.mnAddLeft;
783 aRect.Right() += rCell.mnAddRight;
784 aRect.Top() -= rCell.mnAddTop;
785 aRect.Bottom() += rCell.mnAddBottom;
787 return aRect;
790 // diagonal frame borders -----------------------------------------------------
792 double Array::GetHorDiagAngle( size_t nCol, size_t nRow, bool bSimple ) const
794 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetHorDiagAngle" );
795 return mxImpl->GetHorDiagAngle( nCol, nRow, bSimple );
798 double Array::GetVerDiagAngle( size_t nCol, size_t nRow, bool bSimple ) const
800 DBG_FRAME_CHECK_COLROW( nCol, nRow, "GetVerDiagAngle" );
801 return mxImpl->GetVerDiagAngle( nCol, nRow, bSimple );
804 void Array::SetUseDiagDoubleClipping( bool bSet )
806 mxImpl->mbDiagDblClip = bSet;
809 // mirroring ------------------------------------------------------------------
811 void Array::MirrorSelfX( bool bMirrorStyles, bool bSwapDiag )
813 CellVec aNewCells;
814 aNewCells.reserve( GetCellCount() );
816 size_t nCol, nRow;
817 for( nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
819 for( nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
821 aNewCells.push_back( CELL( mxImpl->GetMirrorCol( nCol ), nRow ) );
822 aNewCells.back().MirrorSelfX( bMirrorStyles, bSwapDiag );
825 for( nRow = 0; nRow < mxImpl->mnHeight; ++nRow )
827 for( nCol = 0; nCol < mxImpl->mnWidth; ++nCol )
829 if( CELL( nCol, nRow ).mbMergeOrig )
831 size_t nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
832 size_t nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
833 lclSetMergedRange( aNewCells, mxImpl->mnWidth,
834 mxImpl->GetMirrorCol( nLastCol ), nRow,
835 mxImpl->GetMirrorCol( nCol ), nLastRow );
839 mxImpl->maCells.swap( aNewCells );
841 std::reverse( mxImpl->maWidths.begin(), mxImpl->maWidths.end() );
842 mxImpl->mbXCoordsDirty = true;
845 // drawing --------------------------------------------------------------------
847 void Array::DrawRange( drawinglayer::processor2d::BaseProcessor2D* pProcessor,
848 size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow,
849 const Color* pForceColor ) const
851 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "DrawRange" );
852 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "DrawRange" );
854 size_t nCol, nRow;
856 // *** diagonal frame borders ***
857 for( nRow = nFirstRow; nRow <= nLastRow; ++nRow )
859 for( nCol = nFirstCol; nCol <= nLastCol; ++nCol )
861 const Cell& rCell = CELL( nCol, nRow );
862 bool bOverlapX = rCell.mbOverlapX;
863 bool bOverlapY = rCell.mbOverlapY;
864 bool bFirstCol = nCol == nFirstCol;
865 bool bFirstRow = nRow == nFirstRow;
866 if( (!bOverlapX && !bOverlapY) || (bFirstCol && bFirstRow) ||
867 (!bOverlapY && bFirstCol) || (!bOverlapX && bFirstRow) )
869 Rectangle aRect( GetCellRect( nCol, nRow ) );
870 if( (aRect.GetWidth() > 1) && (aRect.GetHeight() > 1) )
872 size_t _nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
873 size_t _nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
875 const Style aTlbrStyle = GetCellStyleTLBR( _nFirstCol, _nFirstRow, true );
876 if ( aTlbrStyle.GetWidth( ) )
877 pProcessor->process( CreateClippedBorderPrimitives(
878 aRect.TopLeft(), aRect.BottomRight(),
879 aTlbrStyle, aRect ) );
881 const Style aBltrStyle = GetCellStyleBLTR( _nFirstCol, _nFirstRow, true );
882 if ( aBltrStyle.GetWidth( ) )
883 pProcessor->process( CreateClippedBorderPrimitives(
884 aRect.BottomLeft(), aRect.TopRight(),
885 aBltrStyle, aRect ) );
891 // *** horizontal frame borders ***
893 for( nRow = nFirstRow; nRow <= nLastRow + 1; ++nRow )
895 double fAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow );
896 double fTAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow - 1 );
898 // *Start*** variables store the data of the left end of the cached frame border
899 Point aStartPos( mxImpl->GetColPosition( nFirstCol ), mxImpl->GetRowPosition( nRow ) );
900 const Style* pStart = &GetCellStyleTop( nFirstCol, nRow );
901 DiagStyle aStartLFromTR( GetCellStyleBL( nFirstCol, nRow - 1 ), fTAngle );
902 const Style* pStartLFromT = &GetCellStyleLeft( nFirstCol, nRow - 1 );
903 const Style* pStartLFromL = &GetCellStyleTop( nFirstCol - 1, nRow );
904 const Style* pStartLFromB = &GetCellStyleLeft( nFirstCol, nRow );
905 DiagStyle aStartLFromBR( GetCellStyleTL( nFirstCol, nRow ), fAngle );
907 // *End*** variables store the data of the right end of the cached frame border
908 DiagStyle aEndRFromTL( GetCellStyleBR( nFirstCol, nRow - 1 ), fTAngle );
909 const Style* pEndRFromT = &GetCellStyleRight( nFirstCol, nRow - 1 );
910 const Style* pEndRFromR = &GetCellStyleTop( nFirstCol + 1, nRow );
911 const Style* pEndRFromB = &GetCellStyleRight( nFirstCol, nRow );
912 DiagStyle aEndRFromBL( GetCellStyleTR( nFirstCol, nRow ), fAngle );
914 for( nCol = nFirstCol + 1; nCol <= nLastCol; ++nCol )
916 fAngle = mxImpl->GetHorDiagAngle( nCol, nRow );
917 fTAngle = mxImpl->GetHorDiagAngle( nCol, nRow - 1 );
919 const Style& rCurr = *pEndRFromR;
921 DiagStyle aLFromTR( GetCellStyleBL( nCol, nRow - 1 ), fTAngle );
922 const Style& rLFromT = *pEndRFromT;
923 const Style& rLFromL = *pStart;
924 const Style& rLFromB = *pEndRFromB;
925 DiagStyle aLFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
927 DiagStyle aRFromTL( GetCellStyleBR( nCol, nRow - 1 ), fTAngle );
928 const Style& rRFromT = GetCellStyleRight( nCol, nRow - 1 );
929 const Style& rRFromR = GetCellStyleTop( nCol + 1, nRow );
930 const Style& rRFromB = GetCellStyleRight( nCol, nRow );
931 DiagStyle aRFromBL( GetCellStyleTR( nCol, nRow ), fAngle );
933 // check if current frame border can be connected to cached frame border
934 if( !CheckFrameBorderConnectable( *pStart, rCurr,
935 aEndRFromTL, rLFromT, aLFromTR, aEndRFromBL, rLFromB, aLFromBR ) )
937 // draw previous frame border
938 Point aEndPos( mxImpl->GetColPosition( nCol ), aStartPos.Y() );
939 if( pStart->Prim() && (aStartPos.X() <= aEndPos.X()) )
940 pProcessor->process( CreateBorderPrimitives( aStartPos, aEndPos, *pStart,
941 aStartLFromTR, *pStartLFromT, *pStartLFromL, *pStartLFromB, aStartLFromBR,
942 aEndRFromTL, *pEndRFromT, *pEndRFromR, *pEndRFromB, aEndRFromBL, pForceColor ) );
944 // re-init "*Start***" variables
945 aStartPos = aEndPos;
946 pStart = &rCurr;
947 aStartLFromTR = aLFromTR;
948 pStartLFromT = &rLFromT;
949 pStartLFromL = &rLFromL;
950 pStartLFromB = &rLFromB;
951 aStartLFromBR = aLFromBR;
954 // store current styles in "*End***" variables
955 aEndRFromTL = aRFromTL;
956 pEndRFromT = &rRFromT;
957 pEndRFromR = &rRFromR;
958 pEndRFromB = &rRFromB;
959 aEndRFromBL = aRFromBL;
962 // draw last frame border
963 Point aEndPos( mxImpl->GetColPosition( nCol ), aStartPos.Y() );
964 if( pStart->Prim() && (aStartPos.X() <= aEndPos.X()) )
965 pProcessor->process( CreateBorderPrimitives( aStartPos, aEndPos, *pStart,
966 aStartLFromTR, *pStartLFromT, *pStartLFromL, *pStartLFromB, aStartLFromBR,
967 aEndRFromTL, *pEndRFromT, *pEndRFromR, *pEndRFromB, aEndRFromBL, pForceColor ) );
970 // *** vertical frame borders ***
971 for( nCol = nFirstCol; nCol <= nLastCol + 1; ++nCol )
973 double fAngle = mxImpl->GetVerDiagAngle( nCol, nFirstRow );
974 double fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nFirstRow );
976 // *Start*** variables store the data of the top end of the cached frame border
977 Point aStartPos( mxImpl->GetColPosition( nCol ), mxImpl->GetRowPosition( nFirstRow ) );
978 const Style* pStart = &GetCellStyleLeft( nCol, nFirstRow );
979 DiagStyle aStartTFromBL( GetCellStyleTR( nCol - 1, nFirstRow ), fLAngle );
980 const Style* pStartTFromL = &GetCellStyleTop( nCol - 1, nFirstRow );
981 const Style* pStartTFromT = &GetCellStyleLeft( nCol, nFirstRow - 1 );
982 const Style* pStartTFromR = &GetCellStyleTop( nCol, nFirstRow );
983 DiagStyle aStartTFromBR( GetCellStyleTL( nCol, nFirstRow ), fAngle );
985 // *End*** variables store the data of the bottom end of the cached frame border
986 DiagStyle aEndBFromTL( GetCellStyleBR( nCol - 1, nFirstRow ), fLAngle );
987 const Style* pEndBFromL = &GetCellStyleBottom( nCol - 1, nFirstRow );
988 const Style* pEndBFromB = &GetCellStyleLeft( nCol, nFirstRow + 1 );
989 const Style* pEndBFromR = &GetCellStyleBottom( nCol, nFirstRow );
990 DiagStyle aEndBFromTR( GetCellStyleBL( nCol, nFirstRow ), fAngle );
992 for( nRow = nFirstRow + 1; nRow <= nLastRow; ++nRow )
994 fAngle = mxImpl->GetVerDiagAngle( nCol, nRow );
995 fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nRow );
997 const Style& rCurr = *pEndBFromB;
999 DiagStyle aTFromBL( GetCellStyleTR( nCol - 1, nRow ), fLAngle );
1000 const Style& rTFromL = *pEndBFromL;
1001 const Style& rTFromT = *pStart;
1002 const Style& rTFromR = *pEndBFromR;
1003 DiagStyle aTFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
1005 DiagStyle aBFromTL( GetCellStyleBR( nCol - 1, nRow ), fLAngle );
1006 const Style& rBFromL = GetCellStyleBottom( nCol - 1, nRow );
1007 const Style& rBFromB = GetCellStyleLeft( nCol, nRow + 1 );
1008 const Style& rBFromR = GetCellStyleBottom( nCol, nRow );
1009 DiagStyle aBFromTR( GetCellStyleBL( nCol, nRow ), fAngle );
1011 // check if current frame border can be connected to cached frame border
1012 if( !CheckFrameBorderConnectable( *pStart, rCurr,
1013 aEndBFromTL, rTFromL, aTFromBL, aEndBFromTR, rTFromR, aTFromBR ) )
1015 // draw previous frame border
1016 Point aEndPos( aStartPos.X(), mxImpl->GetRowPosition( nRow ) );
1017 if( pStart->Prim() && (aStartPos.Y() <= aEndPos.Y()) )
1018 pProcessor->process( CreateBorderPrimitives( aEndPos, aStartPos, *pStart,
1019 aEndBFromTL, *pEndBFromL, *pEndBFromB, *pEndBFromR, aEndBFromTR,
1020 aStartTFromBL, *pStartTFromL, *pStartTFromT, *pStartTFromR, aStartTFromBR, pForceColor ) );
1022 // re-init "*Start***" variables
1023 aStartPos = aEndPos;
1024 pStart = &rCurr;
1025 aStartTFromBL = aTFromBL;
1026 pStartTFromL = &rTFromL;
1027 pStartTFromT = &rTFromT;
1028 pStartTFromR = &rTFromR;
1029 aStartTFromBR = aTFromBR;
1032 // store current styles in "*End***" variables
1033 aEndBFromTL = aBFromTL;
1034 pEndBFromL = &rBFromL;
1035 pEndBFromB = &rBFromB;
1036 pEndBFromR = &rBFromR;
1037 aEndBFromTR = aBFromTR;
1040 // draw last frame border
1041 Point aEndPos( aStartPos.X(), mxImpl->GetRowPosition( nRow ) );
1042 if( pStart->Prim() && (aStartPos.Y() <= aEndPos.Y()) )
1043 pProcessor->process( CreateBorderPrimitives( aEndPos, aStartPos, *pStart,
1044 aEndBFromTL, *pEndBFromL, *pEndBFromB, *pEndBFromR, aEndBFromTR,
1045 aStartTFromBL, *pStartTFromL, *pStartTFromT, *pStartTFromR, aStartTFromBR, pForceColor ) );
1049 void Array::DrawRange( OutputDevice& rDev,
1050 size_t nFirstCol, size_t nFirstRow, size_t nLastCol, size_t nLastRow,
1051 const Color* pForceColor ) const
1053 DBG_FRAME_CHECK_COLROW( nFirstCol, nFirstRow, "DrawRange" );
1054 DBG_FRAME_CHECK_COLROW( nLastCol, nLastRow, "DrawRange" );
1056 size_t nCol, nRow;
1058 // *** diagonal frame borders ***
1060 // set clipping region to clip partly visible merged cells
1061 rDev.Push( PUSH_CLIPREGION );
1062 rDev.IntersectClipRegion( GetClipRangeRectangle() );
1063 for( nRow = nFirstRow; nRow <= nLastRow; ++nRow )
1065 for( nCol = nFirstCol; nCol <= nLastCol; ++nCol )
1067 const Cell& rCell = CELL( nCol, nRow );
1068 bool bOverlapX = rCell.mbOverlapX;
1069 bool bOverlapY = rCell.mbOverlapY;
1070 bool bFirstCol = nCol == nFirstCol;
1071 bool bFirstRow = nRow == nFirstRow;
1072 if( (!bOverlapX && !bOverlapY) || (bFirstCol && bFirstRow) ||
1073 (!bOverlapY && bFirstCol) || (!bOverlapX && bFirstRow) )
1075 Rectangle aRect( GetCellRect( nCol, nRow ) );
1076 if( (aRect.GetWidth() > 1) && (aRect.GetHeight() > 1) )
1078 size_t _nFirstCol = mxImpl->GetMergedFirstCol( nCol, nRow );
1079 size_t _nFirstRow = mxImpl->GetMergedFirstRow( nCol, nRow );
1080 size_t _nLastCol = mxImpl->GetMergedLastCol( nCol, nRow );
1081 size_t _nLastRow = mxImpl->GetMergedLastRow( nCol, nRow );
1083 DrawDiagFrameBorders( rDev, aRect,
1084 GetCellStyleTLBR( _nFirstCol, _nFirstRow, true ), GetCellStyleBLTR( _nFirstCol, _nFirstRow, true ),
1085 GetCellStyleLeft( _nFirstCol, _nFirstRow ), GetCellStyleTop( _nFirstCol, _nFirstRow ),
1086 GetCellStyleRight( _nLastCol, _nLastRow ), GetCellStyleBottom( _nLastCol, _nLastRow ),
1087 GetCellStyleLeft( _nFirstCol, _nLastRow ), GetCellStyleBottom( _nFirstCol, _nLastRow ),
1088 GetCellStyleRight( _nLastCol, _nFirstRow ), GetCellStyleTop( _nLastCol, _nFirstRow ),
1089 pForceColor, mxImpl->mbDiagDblClip );
1094 rDev.Pop(); // clip region
1096 // *** horizontal frame borders ***
1098 for( nRow = nFirstRow; nRow <= nLastRow + 1; ++nRow )
1100 double fAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow );
1101 double fTAngle = mxImpl->GetHorDiagAngle( nFirstCol, nRow - 1 );
1103 // *Start*** variables store the data of the left end of the cached frame border
1104 Point aStartPos( mxImpl->GetColPosition( nFirstCol ), mxImpl->GetRowPosition( nRow ) );
1105 const Style* pStart = &GetCellStyleTop( nFirstCol, nRow );
1106 DiagStyle aStartLFromTR( GetCellStyleBL( nFirstCol, nRow - 1 ), fTAngle );
1107 const Style* pStartLFromT = &GetCellStyleLeft( nFirstCol, nRow - 1 );
1108 const Style* pStartLFromL = &GetCellStyleTop( nFirstCol - 1, nRow );
1109 const Style* pStartLFromB = &GetCellStyleLeft( nFirstCol, nRow );
1110 DiagStyle aStartLFromBR( GetCellStyleTL( nFirstCol, nRow ), fAngle );
1112 // *End*** variables store the data of the right end of the cached frame border
1113 DiagStyle aEndRFromTL( GetCellStyleBR( nFirstCol, nRow - 1 ), fTAngle );
1114 const Style* pEndRFromT = &GetCellStyleRight( nFirstCol, nRow - 1 );
1115 const Style* pEndRFromR = &GetCellStyleTop( nFirstCol + 1, nRow );
1116 const Style* pEndRFromB = &GetCellStyleRight( nFirstCol, nRow );
1117 DiagStyle aEndRFromBL( GetCellStyleTR( nFirstCol, nRow ), fAngle );
1119 for( nCol = nFirstCol + 1; nCol <= nLastCol; ++nCol )
1121 fAngle = mxImpl->GetHorDiagAngle( nCol, nRow );
1122 fTAngle = mxImpl->GetHorDiagAngle( nCol, nRow - 1 );
1124 const Style& rCurr = *pEndRFromR;
1126 DiagStyle aLFromTR( GetCellStyleBL( nCol, nRow - 1 ), fTAngle );
1127 const Style& rLFromT = *pEndRFromT;
1128 const Style& rLFromL = *pStart;
1129 const Style& rLFromB = *pEndRFromB;
1130 DiagStyle aLFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
1132 DiagStyle aRFromTL( GetCellStyleBR( nCol, nRow - 1 ), fTAngle );
1133 const Style& rRFromT = GetCellStyleRight( nCol, nRow - 1 );
1134 const Style& rRFromR = GetCellStyleTop( nCol + 1, nRow );
1135 const Style& rRFromB = GetCellStyleRight( nCol, nRow );
1136 DiagStyle aRFromBL( GetCellStyleTR( nCol, nRow ), fAngle );
1138 // check if current frame border can be connected to cached frame border
1139 if( !CheckFrameBorderConnectable( *pStart, rCurr,
1140 aEndRFromTL, rLFromT, aLFromTR, aEndRFromBL, rLFromB, aLFromBR ) )
1142 // draw previous frame border
1143 Point aEndPos( mxImpl->GetColPosition( nCol ), aStartPos.Y() );
1144 if( pStart->Prim() && (aStartPos.X() <= aEndPos.X()) )
1145 DrawHorFrameBorder( rDev, aStartPos, aEndPos, *pStart,
1146 aStartLFromTR, *pStartLFromT, *pStartLFromL, *pStartLFromB, aStartLFromBR,
1147 aEndRFromTL, *pEndRFromT, *pEndRFromR, *pEndRFromB, aEndRFromBL, pForceColor );
1149 // re-init "*Start***" variables
1150 aStartPos = aEndPos;
1151 pStart = &rCurr;
1152 aStartLFromTR = aLFromTR;
1153 pStartLFromT = &rLFromT;
1154 pStartLFromL = &rLFromL;
1155 pStartLFromB = &rLFromB;
1156 aStartLFromBR = aLFromBR;
1159 // store current styles in "*End***" variables
1160 aEndRFromTL = aRFromTL;
1161 pEndRFromT = &rRFromT;
1162 pEndRFromR = &rRFromR;
1163 pEndRFromB = &rRFromB;
1164 aEndRFromBL = aRFromBL;
1167 // draw last frame border
1168 Point aEndPos( mxImpl->GetColPosition( nCol ), aStartPos.Y() );
1169 if( pStart->Prim() && (aStartPos.X() <= aEndPos.X()) )
1170 DrawHorFrameBorder( rDev, aStartPos, aEndPos, *pStart,
1171 aStartLFromTR, *pStartLFromT, *pStartLFromL, *pStartLFromB, aStartLFromBR,
1172 aEndRFromTL, *pEndRFromT, *pEndRFromR, *pEndRFromB, aEndRFromBL, pForceColor );
1175 // *** vertical frame borders ***
1177 for( nCol = nFirstCol; nCol <= nLastCol + 1; ++nCol )
1179 double fAngle = mxImpl->GetVerDiagAngle( nCol, nFirstRow );
1180 double fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nFirstRow );
1182 // *Start*** variables store the data of the top end of the cached frame border
1183 Point aStartPos( mxImpl->GetColPosition( nCol ), mxImpl->GetRowPosition( nFirstRow ) );
1184 const Style* pStart = &GetCellStyleLeft( nCol, nFirstRow );
1185 DiagStyle aStartTFromBL( GetCellStyleTR( nCol - 1, nFirstRow ), fLAngle );
1186 const Style* pStartTFromL = &GetCellStyleTop( nCol - 1, nFirstRow );
1187 const Style* pStartTFromT = &GetCellStyleLeft( nCol, nFirstRow - 1 );
1188 const Style* pStartTFromR = &GetCellStyleTop( nCol, nFirstRow );
1189 DiagStyle aStartTFromBR( GetCellStyleTL( nCol, nFirstRow ), fAngle );
1191 // *End*** variables store the data of the bottom end of the cached frame border
1192 DiagStyle aEndBFromTL( GetCellStyleBR( nCol - 1, nFirstRow ), fLAngle );
1193 const Style* pEndBFromL = &GetCellStyleBottom( nCol - 1, nFirstRow );
1194 const Style* pEndBFromB = &GetCellStyleLeft( nCol, nFirstRow + 1 );
1195 const Style* pEndBFromR = &GetCellStyleBottom( nCol, nFirstRow );
1196 DiagStyle aEndBFromTR( GetCellStyleBL( nCol, nFirstRow ), fAngle );
1198 for( nRow = nFirstRow + 1; nRow <= nLastRow; ++nRow )
1200 fAngle = mxImpl->GetVerDiagAngle( nCol, nRow );
1201 fLAngle = mxImpl->GetVerDiagAngle( nCol - 1, nRow );
1203 const Style& rCurr = *pEndBFromB;
1205 DiagStyle aTFromBL( GetCellStyleTR( nCol - 1, nRow ), fLAngle );
1206 const Style& rTFromL = *pEndBFromL;
1207 const Style& rTFromT = *pStart;
1208 const Style& rTFromR = *pEndBFromR;
1209 DiagStyle aTFromBR( GetCellStyleTL( nCol, nRow ), fAngle );
1211 DiagStyle aBFromTL( GetCellStyleBR( nCol - 1, nRow ), fLAngle );
1212 const Style& rBFromL = GetCellStyleBottom( nCol - 1, nRow );
1213 const Style& rBFromB = GetCellStyleLeft( nCol, nRow + 1 );
1214 const Style& rBFromR = GetCellStyleBottom( nCol, nRow );
1215 DiagStyle aBFromTR( GetCellStyleBL( nCol, nRow ), fAngle );
1217 // check if current frame border can be connected to cached frame border
1218 if( !CheckFrameBorderConnectable( *pStart, rCurr,
1219 aEndBFromTL, rTFromL, aTFromBL, aEndBFromTR, rTFromR, aTFromBR ) )
1221 // draw previous frame border
1222 Point aEndPos( aStartPos.X(), mxImpl->GetRowPosition( nRow ) );
1223 if( pStart->Prim() && (aStartPos.Y() <= aEndPos.Y()) )
1224 DrawVerFrameBorder( rDev, aStartPos, aEndPos, *pStart,
1225 aStartTFromBL, *pStartTFromL, *pStartTFromT, *pStartTFromR, aStartTFromBR,
1226 aEndBFromTL, *pEndBFromL, *pEndBFromB, *pEndBFromR, aEndBFromTR, pForceColor );
1228 // re-init "*Start***" variables
1229 aStartPos = aEndPos;
1230 pStart = &rCurr;
1231 aStartTFromBL = aTFromBL;
1232 pStartTFromL = &rTFromL;
1233 pStartTFromT = &rTFromT;
1234 pStartTFromR = &rTFromR;
1235 aStartTFromBR = aTFromBR;
1238 // store current styles in "*End***" variables
1239 aEndBFromTL = aBFromTL;
1240 pEndBFromL = &rBFromL;
1241 pEndBFromB = &rBFromB;
1242 pEndBFromR = &rBFromR;
1243 aEndBFromTR = aBFromTR;
1246 // draw last frame border
1247 Point aEndPos( aStartPos.X(), mxImpl->GetRowPosition( nRow ) );
1248 if( pStart->Prim() && (aStartPos.Y() <= aEndPos.Y()) )
1249 DrawVerFrameBorder( rDev, aStartPos, aEndPos, *pStart,
1250 aStartTFromBL, *pStartTFromL, *pStartTFromT, *pStartTFromR, aStartTFromBR,
1251 aEndBFromTL, *pEndBFromL, *pEndBFromB, *pEndBFromR, aEndBFromTR, pForceColor );
1255 void Array::DrawArray( OutputDevice& rDev, const Color* pForceColor ) const
1257 if( mxImpl->mnWidth && mxImpl->mnHeight )
1258 DrawRange( rDev, 0, 0, mxImpl->mnWidth - 1, mxImpl->mnHeight - 1, pForceColor );
1261 // ----------------------------------------------------------------------------
1263 #undef ORIGCELL
1264 #undef CELLACC
1265 #undef CELL
1267 // ----------------------------------------------------------------------------
1269 #undef DBG_FRAME_CHECK_ROW_1
1270 #undef DBG_FRAME_CHECK_COL_1
1271 #undef DBG_FRAME_CHECK_COLROW
1272 #undef DBG_FRAME_CHECK_ROW
1273 #undef DBG_FRAME_CHECK_COL
1274 #undef DBG_FRAME_CHECK
1276 // ============================================================================
1278 } // namespace frame
1279 } // namespace svx
1281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */