1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <vcl/outdev.hxx>
48 inline bool IsMerged() const { return mbMergeOrig
|| mbOverlapX
|| mbOverlapY
; }
50 void MirrorSelfX( bool bMirrorStyles
, bool bSwapDiag
);
53 typedef std::vector
< long > LongVec
;
54 typedef std::vector
< Cell
> CellVec
;
67 void Cell::MirrorSelfX( bool bMirrorStyles
, bool bSwapDiag
)
69 std::swap( maLeft
, maRight
);
70 std::swap( mnAddLeft
, mnAddRight
);
78 std::swap( maTLBR
, maBLTR
);
90 void lclRecalcCoordVec( LongVec
& rCoords
, const LongVec
& rSizes
)
92 DBG_ASSERT( rCoords
.size() == rSizes
.size() + 1, "lclRecalcCoordVec - inconsistent vectors" );
93 LongVec::iterator aCIt
= rCoords
.begin();
94 LongVec::const_iterator aSIt
= rSizes
.begin(), aSEnd
= rSizes
.end();
95 for( ; aSIt
!= aSEnd
; ++aCIt
, ++aSIt
)
96 *(aCIt
+ 1) = *aCIt
+ *aSIt
;
99 void lclSetMergedRange( CellVec
& rCells
, size_t nWidth
, size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
)
101 for( size_t nCol
= nFirstCol
; nCol
<= nLastCol
; ++nCol
)
103 for( size_t nRow
= nFirstRow
; nRow
<= nLastRow
; ++nRow
)
105 Cell
& rCell
= rCells
[ nRow
* nWidth
+ nCol
];
106 rCell
.mbMergeOrig
= false;
107 rCell
.mbOverlapX
= nCol
> nFirstCol
;
108 rCell
.mbOverlapY
= nRow
> nFirstRow
;
111 rCells
[ nFirstRow
* nWidth
+ nFirstCol
].mbMergeOrig
= true;
116 static const Style OBJ_STYLE_NONE
;
117 static const Cell OBJ_CELL_NONE
;
119 const bool DIAG_DBL_CLIP_DEFAULT
= false;
126 mutable LongVec maXCoords
;
127 mutable LongVec maYCoords
;
130 size_t mnFirstClipCol
;
131 size_t mnFirstClipRow
;
132 size_t mnLastClipCol
;
133 size_t mnLastClipRow
;
134 mutable bool mbXCoordsDirty
;
135 mutable bool mbYCoordsDirty
;
138 explicit ArrayImpl( size_t nWidth
, size_t nHeight
, bool bDiagDblClip
);
140 inline bool IsValidPos( size_t nCol
, size_t nRow
) const
141 { return (nCol
< mnWidth
) && (nRow
< mnHeight
); }
142 inline size_t GetIndex( size_t nCol
, size_t nRow
) const
143 { return nRow
* mnWidth
+ nCol
; }
145 const Cell
& GetCell( size_t nCol
, size_t nRow
) const;
146 Cell
& GetCellAcc( size_t nCol
, size_t nRow
);
148 size_t GetMergedFirstCol( size_t nCol
, size_t nRow
) const;
149 size_t GetMergedFirstRow( size_t nCol
, size_t nRow
) const;
150 size_t GetMergedLastCol( size_t nCol
, size_t nRow
) const;
151 size_t GetMergedLastRow( size_t nCol
, size_t nRow
) const;
153 const Cell
& GetMergedOriginCell( size_t nCol
, size_t nRow
) const;
155 bool IsMergedOverlappedLeft( size_t nCol
, size_t nRow
) const;
156 bool IsMergedOverlappedRight( size_t nCol
, size_t nRow
) const;
157 bool IsMergedOverlappedTop( size_t nCol
, size_t nRow
) const;
158 bool IsMergedOverlappedBottom( size_t nCol
, size_t nRow
) const;
160 bool IsInClipRange( size_t nCol
, size_t nRow
) const;
161 bool IsColInClipRange( size_t nCol
) const;
162 bool IsRowInClipRange( size_t nRow
) const;
164 inline size_t GetMirrorCol( size_t nCol
) const { return mnWidth
- nCol
- 1; }
166 long GetColPosition( size_t nCol
) const;
167 long GetRowPosition( size_t nRow
) const;
169 long GetColWidth( size_t nFirstCol
, size_t nLastCol
) const;
170 long GetRowHeight( size_t nFirstRow
, size_t nLastRow
) const;
172 double GetHorDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
= false ) const;
173 double GetVerDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
= false ) const;
176 ArrayImpl::ArrayImpl( size_t nWidth
, size_t nHeight
, bool bDiagDblClip
) :
181 mnLastClipCol( nWidth
- 1 ),
182 mnLastClipRow( nHeight
- 1 ),
183 mbXCoordsDirty( false ),
184 mbYCoordsDirty( false ),
185 mbDiagDblClip( bDiagDblClip
)
187 // default-construct all vectors
188 maCells
.resize( mnWidth
* mnHeight
);
189 maWidths
.resize( mnWidth
, 0L );
190 maHeights
.resize( mnHeight
, 0L );
191 maXCoords
.resize( mnWidth
+ 1, 0L );
192 maYCoords
.resize( mnHeight
+ 1, 0L );
195 const Cell
& ArrayImpl::GetCell( size_t nCol
, size_t nRow
) const
197 return IsValidPos( nCol
, nRow
) ? maCells
[ GetIndex( nCol
, nRow
) ] : OBJ_CELL_NONE
;
200 Cell
& ArrayImpl::GetCellAcc( size_t nCol
, size_t nRow
)
203 return IsValidPos( nCol
, nRow
) ? maCells
[ GetIndex( nCol
, nRow
) ] : aDummy
;
206 size_t ArrayImpl::GetMergedFirstCol( size_t nCol
, size_t nRow
) const
208 size_t nFirstCol
= nCol
;
209 while( (nFirstCol
> 0) && GetCell( nFirstCol
, nRow
).mbOverlapX
) --nFirstCol
;
213 size_t ArrayImpl::GetMergedFirstRow( size_t nCol
, size_t nRow
) const
215 size_t nFirstRow
= nRow
;
216 while( (nFirstRow
> 0) && GetCell( nCol
, nFirstRow
).mbOverlapY
) --nFirstRow
;
220 size_t ArrayImpl::GetMergedLastCol( size_t nCol
, size_t nRow
) const
222 size_t nLastCol
= nCol
+ 1;
223 while( (nLastCol
< mnWidth
) && GetCell( nLastCol
, nRow
).mbOverlapX
) ++nLastCol
;
227 size_t ArrayImpl::GetMergedLastRow( size_t nCol
, size_t nRow
) const
229 size_t nLastRow
= nRow
+ 1;
230 while( (nLastRow
< mnHeight
) && GetCell( nCol
, nLastRow
).mbOverlapY
) ++nLastRow
;
234 const Cell
& ArrayImpl::GetMergedOriginCell( size_t nCol
, size_t nRow
) const
236 return GetCell( GetMergedFirstCol( nCol
, nRow
), GetMergedFirstRow( nCol
, nRow
) );
239 bool ArrayImpl::IsMergedOverlappedLeft( size_t nCol
, size_t nRow
) const
241 const Cell
& rCell
= GetCell( nCol
, nRow
);
242 return rCell
.mbOverlapX
|| (rCell
.mnAddLeft
> 0);
245 bool ArrayImpl::IsMergedOverlappedRight( size_t nCol
, size_t nRow
) const
247 return GetCell( nCol
+ 1, nRow
).mbOverlapX
|| (GetCell( nCol
, nRow
).mnAddRight
> 0);
250 bool ArrayImpl::IsMergedOverlappedTop( size_t nCol
, size_t nRow
) const
252 const Cell
& rCell
= GetCell( nCol
, nRow
);
253 return rCell
.mbOverlapY
|| (rCell
.mnAddTop
> 0);
256 bool ArrayImpl::IsMergedOverlappedBottom( size_t nCol
, size_t nRow
) const
258 return GetCell( nCol
, nRow
+ 1 ).mbOverlapY
|| (GetCell( nCol
, nRow
).mnAddBottom
> 0);
261 bool ArrayImpl::IsColInClipRange( size_t nCol
) const
263 return (mnFirstClipCol
<= nCol
) && (nCol
<= mnLastClipCol
);
266 bool ArrayImpl::IsRowInClipRange( size_t nRow
) const
268 return (mnFirstClipRow
<= nRow
) && (nRow
<= mnLastClipRow
);
271 bool ArrayImpl::IsInClipRange( size_t nCol
, size_t nRow
) const
273 return IsColInClipRange( nCol
) && IsRowInClipRange( nRow
);
276 long ArrayImpl::GetColPosition( size_t nCol
) const
280 lclRecalcCoordVec( maXCoords
, maWidths
);
281 mbXCoordsDirty
= false;
283 return maXCoords
[ nCol
];
286 long ArrayImpl::GetRowPosition( size_t nRow
) const
290 lclRecalcCoordVec( maYCoords
, maHeights
);
291 mbYCoordsDirty
= false;
293 return maYCoords
[ nRow
];
296 long ArrayImpl::GetColWidth( size_t nFirstCol
, size_t nLastCol
) const
298 return GetColPosition( nLastCol
+ 1 ) - GetColPosition( nFirstCol
);
301 long ArrayImpl::GetRowHeight( size_t nFirstRow
, size_t nLastRow
) const
303 return GetRowPosition( nLastRow
+ 1 ) - GetRowPosition( nFirstRow
);
306 double ArrayImpl::GetHorDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
309 if( IsValidPos( nCol
, nRow
) )
311 if( bSimple
|| !GetCell( nCol
, nRow
).IsMerged() )
313 fAngle
= frame::GetHorDiagAngle( maWidths
[ nCol
] + 1, maHeights
[ nRow
] + 1 );
317 // return correct angle for each cell in the merged range
318 size_t nFirstCol
= GetMergedFirstCol( nCol
, nRow
);
319 size_t nFirstRow
= GetMergedFirstRow( nCol
, nRow
);
320 const Cell
& rCell
= GetCell( nFirstCol
, nFirstRow
);
321 long nWidth
= GetColWidth( nFirstCol
, GetMergedLastCol( nCol
, nRow
) ) + rCell
.mnAddLeft
+ rCell
.mnAddRight
;
322 long nHeight
= GetRowHeight( nFirstRow
, GetMergedLastRow( nCol
, nRow
) ) + rCell
.mnAddTop
+ rCell
.mnAddBottom
;
323 fAngle
= frame::GetHorDiagAngle( nWidth
+ 1, nHeight
+ 1 );
329 double ArrayImpl::GetVerDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
331 double fAngle
= GetHorDiagAngle( nCol
, nRow
, bSimple
);
332 return (fAngle
> 0.0) ? (F_PI2
- fAngle
) : 0.0;
337 class MergedCellIterator
340 explicit MergedCellIterator( const Array
& rArray
, size_t nCol
, size_t nRow
);
342 inline bool Is() const { return (mnCol
<= mnLastCol
) && (mnRow
<= mnLastRow
); }
343 inline size_t Col() const { return mnCol
; }
344 inline size_t Row() const { return mnRow
; }
346 MergedCellIterator
& operator++();
359 MergedCellIterator::MergedCellIterator( const Array
& rArray
, size_t nCol
, size_t nRow
)
361 DBG_ASSERT( rArray
.IsMerged( nCol
, nRow
), "svx::frame::MergedCellIterator::MergedCellIterator - not in merged range" );
362 rArray
.GetMergedRange( mnFirstCol
, mnFirstRow
, mnLastCol
, mnLastRow
, nCol
, nRow
);
367 MergedCellIterator
& MergedCellIterator::operator++()
369 DBG_ASSERT( Is(), "svx::frame::MergedCellIterator::operator++() - already invalid" );
370 if( ++mnCol
> mnLastCol
)
380 #define DBG_FRAME_CHECK( cond, funcname, error ) DBG_ASSERT( cond, "svx::frame::Array::" funcname " - " error )
381 #define DBG_FRAME_CHECK_COL( col, funcname ) DBG_FRAME_CHECK( (col) < GetColCount(), funcname, "invalid column index" )
382 #define DBG_FRAME_CHECK_ROW( row, funcname ) DBG_FRAME_CHECK( (row) < GetRowCount(), funcname, "invalid row index" )
383 #define DBG_FRAME_CHECK_COLROW( col, row, funcname ) DBG_FRAME_CHECK( ((col) < GetColCount()) && ((row) < GetRowCount()), funcname, "invalid cell index" )
384 #define DBG_FRAME_CHECK_COL_1( col, funcname ) DBG_FRAME_CHECK( (col) <= GetColCount(), funcname, "invalid column index" )
385 #define DBG_FRAME_CHECK_ROW_1( row, funcname ) DBG_FRAME_CHECK( (row) <= GetRowCount(), funcname, "invalid row index" )
389 #define CELL( col, row ) mxImpl->GetCell( col, row )
390 #define CELLACC( col, row ) mxImpl->GetCellAcc( col, row )
391 #define ORIGCELL( col, row ) mxImpl->GetMergedOriginCell( col, row )
404 // array size and column/row indexes
405 void Array::Initialize( size_t nWidth
, size_t nHeight
)
407 bool bDiagDblClip
= mxImpl
.get() ? mxImpl
->mbDiagDblClip
: DIAG_DBL_CLIP_DEFAULT
;
408 mxImpl
.reset( new ArrayImpl( nWidth
, nHeight
, bDiagDblClip
) );
411 size_t Array::GetColCount() const
413 return mxImpl
->mnWidth
;
416 size_t Array::GetRowCount() const
418 return mxImpl
->mnHeight
;
421 size_t Array::GetCellCount() const
423 return mxImpl
->maCells
.size();
426 size_t Array::GetCellIndex( size_t nCol
, size_t nRow
, bool bRTL
) const
428 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetCellIndex" );
430 nCol
= mxImpl
->GetMirrorCol(nCol
);
431 return mxImpl
->GetIndex( nCol
, nRow
);
434 // cell border styles
435 void Array::SetCellStyleLeft( size_t nCol
, size_t nRow
, const Style
& rStyle
)
437 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleLeft" );
438 CELLACC( nCol
, nRow
).maLeft
= rStyle
;
441 void Array::SetCellStyleRight( size_t nCol
, size_t nRow
, const Style
& rStyle
)
443 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleRight" );
444 CELLACC( nCol
, nRow
).maRight
= rStyle
;
447 void Array::SetCellStyleTop( size_t nCol
, size_t nRow
, const Style
& rStyle
)
449 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleTop" );
450 CELLACC( nCol
, nRow
).maTop
= rStyle
;
453 void Array::SetCellStyleBottom( size_t nCol
, size_t nRow
, const Style
& rStyle
)
455 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleBottom" );
456 CELLACC( nCol
, nRow
).maBottom
= rStyle
;
459 void Array::SetCellStyleTLBR( size_t nCol
, size_t nRow
, const Style
& rStyle
)
461 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleTLBR" );
462 CELLACC( nCol
, nRow
).maTLBR
= rStyle
;
465 void Array::SetCellStyleBLTR( size_t nCol
, size_t nRow
, const Style
& rStyle
)
467 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleBLTR" );
468 CELLACC( nCol
, nRow
).maBLTR
= rStyle
;
471 void Array::SetCellStyleDiag( size_t nCol
, size_t nRow
, const Style
& rTLBR
, const Style
& rBLTR
)
473 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleDiag" );
474 Cell
& rCell
= CELLACC( nCol
, nRow
);
475 rCell
.maTLBR
= rTLBR
;
476 rCell
.maBLTR
= rBLTR
;
479 void Array::SetColumnStyleLeft( size_t nCol
, const Style
& rStyle
)
481 DBG_FRAME_CHECK_COL( nCol
, "SetColumnStyleLeft" );
482 for( size_t nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
483 SetCellStyleLeft( nCol
, nRow
, rStyle
);
486 void Array::SetColumnStyleRight( size_t nCol
, const Style
& rStyle
)
488 DBG_FRAME_CHECK_COL( nCol
, "SetColumnStyleRight" );
489 for( size_t nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
490 SetCellStyleRight( nCol
, nRow
, rStyle
);
493 void Array::SetRowStyleTop( size_t nRow
, const Style
& rStyle
)
495 DBG_FRAME_CHECK_ROW( nRow
, "SetRowStyleTop" );
496 for( size_t nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
497 SetCellStyleTop( nCol
, nRow
, rStyle
);
500 void Array::SetRowStyleBottom( size_t nRow
, const Style
& rStyle
)
502 DBG_FRAME_CHECK_ROW( nRow
, "SetRowStyleBottom" );
503 for( size_t nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
504 SetCellStyleBottom( nCol
, nRow
, rStyle
);
507 const Style
& Array::GetCellStyleLeft( size_t nCol
, size_t nRow
, bool bSimple
) const
509 // simple: always return own left style
511 return CELL( nCol
, nRow
).maLeft
;
512 // outside clipping rows or overlapped in merged cells: invisible
513 if( !mxImpl
->IsRowInClipRange( nRow
) || mxImpl
->IsMergedOverlappedLeft( nCol
, nRow
) )
514 return OBJ_STYLE_NONE
;
515 // left clipping border: always own left style
516 if( nCol
== mxImpl
->mnFirstClipCol
)
517 return ORIGCELL( nCol
, nRow
).maLeft
;
518 // right clipping border: always right style of left neighbor cell
519 if( nCol
== mxImpl
->mnLastClipCol
+ 1 )
520 return ORIGCELL( nCol
- 1, nRow
).maRight
;
521 // outside clipping columns: invisible
522 if( !mxImpl
->IsColInClipRange( nCol
) )
523 return OBJ_STYLE_NONE
;
524 // inside clipping range: maximum of own left style and right style of left neighbor cell
525 return std::max( ORIGCELL( nCol
, nRow
).maLeft
, ORIGCELL( nCol
- 1, nRow
).maRight
);
528 const Style
& Array::GetCellStyleRight( size_t nCol
, size_t nRow
, bool bSimple
) const
530 // simple: always return own right style
532 return CELL( nCol
, nRow
).maRight
;
533 // outside clipping rows or overlapped in merged cells: invisible
534 if( !mxImpl
->IsRowInClipRange( nRow
) || mxImpl
->IsMergedOverlappedRight( nCol
, nRow
) )
535 return OBJ_STYLE_NONE
;
536 // left clipping border: always left style of right neighbor cell
537 if( nCol
+ 1 == mxImpl
->mnFirstClipCol
)
538 return ORIGCELL( nCol
+ 1, nRow
).maLeft
;
539 // right clipping border: always own right style
540 if( nCol
== mxImpl
->mnLastClipCol
)
541 return ORIGCELL( nCol
, nRow
).maRight
;
542 // outside clipping columns: invisible
543 if( !mxImpl
->IsColInClipRange( nCol
) )
544 return OBJ_STYLE_NONE
;
545 // inside clipping range: maximum of own right style and left style of right neighbor cell
546 return std::max( ORIGCELL( nCol
, nRow
).maRight
, ORIGCELL( nCol
+ 1, nRow
).maLeft
);
549 const Style
& Array::GetCellStyleTop( size_t nCol
, size_t nRow
, bool bSimple
) const
551 // simple: always return own top style
553 return CELL( nCol
, nRow
).maTop
;
554 // outside clipping columns or overlapped in merged cells: invisible
555 if( !mxImpl
->IsColInClipRange( nCol
) || mxImpl
->IsMergedOverlappedTop( nCol
, nRow
) )
556 return OBJ_STYLE_NONE
;
557 // top clipping border: always own top style
558 if( nRow
== mxImpl
->mnFirstClipRow
)
559 return ORIGCELL( nCol
, nRow
).maTop
;
560 // bottom clipping border: always bottom style of top neighbor cell
561 if( nRow
== mxImpl
->mnLastClipRow
+ 1 )
562 return ORIGCELL( nCol
, nRow
- 1 ).maBottom
;
563 // outside clipping rows: invisible
564 if( !mxImpl
->IsRowInClipRange( nRow
) )
565 return OBJ_STYLE_NONE
;
566 // inside clipping range: maximum of own top style and bottom style of top neighbor cell
567 return std::max( ORIGCELL( nCol
, nRow
).maTop
, ORIGCELL( nCol
, nRow
- 1 ).maBottom
);
570 const Style
& Array::GetCellStyleBottom( size_t nCol
, size_t nRow
, bool bSimple
) const
572 // simple: always return own bottom style
574 return CELL( nCol
, nRow
).maBottom
;
575 // outside clipping columns or overlapped in merged cells: invisible
576 if( !mxImpl
->IsColInClipRange( nCol
) || mxImpl
->IsMergedOverlappedBottom( nCol
, nRow
) )
577 return OBJ_STYLE_NONE
;
578 // top clipping border: always top style of bottom neighbor cell
579 if( nRow
+ 1 == mxImpl
->mnFirstClipRow
)
580 return ORIGCELL( nCol
, nRow
+ 1 ).maTop
;
581 // bottom clipping border: always own bottom style
582 if( nRow
== mxImpl
->mnLastClipRow
)
583 return ORIGCELL( nCol
, nRow
).maBottom
;
584 // outside clipping rows: invisible
585 if( !mxImpl
->IsRowInClipRange( nRow
) )
586 return OBJ_STYLE_NONE
;
587 // inside clipping range: maximum of own bottom style and top style of bottom neighbor cell
588 return std::max( ORIGCELL( nCol
, nRow
).maBottom
, ORIGCELL( nCol
, nRow
+ 1 ).maTop
);
591 const Style
& Array::GetCellStyleTLBR( size_t nCol
, size_t nRow
, bool bSimple
) const
593 return bSimple
? CELL( nCol
, nRow
).maTLBR
:
594 (mxImpl
->IsInClipRange( nCol
, nRow
) ? ORIGCELL( nCol
, nRow
).maTLBR
: OBJ_STYLE_NONE
);
597 const Style
& Array::GetCellStyleBLTR( size_t nCol
, size_t nRow
, bool bSimple
) const
599 return bSimple
? CELL( nCol
, nRow
).maBLTR
:
600 (mxImpl
->IsInClipRange( nCol
, nRow
) ? ORIGCELL( nCol
, nRow
).maBLTR
: OBJ_STYLE_NONE
);
603 const Style
& Array::GetCellStyleTL( size_t nCol
, size_t nRow
) const
605 // not in clipping range: always invisible
606 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
607 return OBJ_STYLE_NONE
;
608 // return style only for top-left cell
609 size_t nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
610 size_t nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
611 return ((nCol
== nFirstCol
) && (nRow
== nFirstRow
)) ?
612 CELL( nFirstCol
, nFirstRow
).maTLBR
: OBJ_STYLE_NONE
;
615 const Style
& Array::GetCellStyleBR( size_t nCol
, size_t nRow
) const
617 // not in clipping range: always invisible
618 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
619 return OBJ_STYLE_NONE
;
620 // return style only for bottom-right cell
621 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
622 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
623 return ((nCol
== nLastCol
) && (nRow
== nLastRow
)) ?
624 CELL( mxImpl
->GetMergedFirstCol( nCol
, nRow
), mxImpl
->GetMergedFirstRow( nCol
, nRow
) ).maTLBR
: OBJ_STYLE_NONE
;
627 const Style
& Array::GetCellStyleBL( size_t nCol
, size_t nRow
) const
629 // not in clipping range: always invisible
630 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
631 return OBJ_STYLE_NONE
;
632 // return style only for bottom-left cell
633 size_t nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
634 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
635 return ((nCol
== nFirstCol
) && (nRow
== nLastRow
)) ?
636 CELL( nFirstCol
, mxImpl
->GetMergedFirstRow( nCol
, nRow
) ).maBLTR
: OBJ_STYLE_NONE
;
639 const Style
& Array::GetCellStyleTR( size_t nCol
, size_t nRow
) const
641 // not in clipping range: always invisible
642 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
643 return OBJ_STYLE_NONE
;
644 // return style only for top-right cell
645 size_t nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
646 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
647 return ((nCol
== nLastCol
) && (nRow
== nFirstRow
)) ?
648 CELL( mxImpl
->GetMergedFirstCol( nCol
, nRow
), nFirstRow
).maBLTR
: OBJ_STYLE_NONE
;
652 void Array::SetMergedRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
)
654 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "SetMergedRange" );
655 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "SetMergedRange" );
656 #if OSL_DEBUG_LEVEL >= 2
659 for( size_t nCurrCol
= nFirstCol
; !bFound
&& (nCurrCol
<= nLastCol
); ++nCurrCol
)
660 for( size_t nCurrRow
= nFirstRow
; !bFound
&& (nCurrRow
<= nLastRow
); ++nCurrRow
)
661 bFound
= CELL( nCurrCol
, nCurrRow
).IsMerged();
662 DBG_FRAME_CHECK( !bFound
, "SetMergedRange", "overlapping merged ranges" );
665 if( mxImpl
->IsValidPos( nFirstCol
, nFirstRow
) && mxImpl
->IsValidPos( nLastCol
, nLastRow
) )
666 lclSetMergedRange( mxImpl
->maCells
, mxImpl
->mnWidth
, nFirstCol
, nFirstRow
, nLastCol
, nLastRow
);
669 void Array::SetAddMergedLeftSize( size_t nCol
, size_t nRow
, long nAddSize
)
671 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedLeftSize" );
672 DBG_FRAME_CHECK( mxImpl
->GetMergedFirstCol( nCol
, nRow
) == 0, "SetAddMergedLeftSize", "additional border inside array" );
673 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
674 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddLeft
= nAddSize
;
677 void Array::SetAddMergedRightSize( size_t nCol
, size_t nRow
, long nAddSize
)
679 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedRightSize" );
680 DBG_FRAME_CHECK( mxImpl
->GetMergedLastCol( nCol
, nRow
) + 1 == mxImpl
->mnWidth
, "SetAddMergedRightSize", "additional border inside array" );
681 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
682 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddRight
= nAddSize
;
685 void Array::SetAddMergedTopSize( size_t nCol
, size_t nRow
, long nAddSize
)
687 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedTopSize" );
688 DBG_FRAME_CHECK( mxImpl
->GetMergedFirstRow( nCol
, nRow
) == 0, "SetAddMergedTopSize", "additional border inside array" );
689 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
690 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddTop
= nAddSize
;
693 void Array::SetAddMergedBottomSize( size_t nCol
, size_t nRow
, long nAddSize
)
695 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedBottomSize" );
696 DBG_FRAME_CHECK( mxImpl
->GetMergedLastRow( nCol
, nRow
) + 1 == mxImpl
->mnHeight
, "SetAddMergedBottomSize", "additional border inside array" );
697 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
698 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddBottom
= nAddSize
;
701 bool Array::IsMerged( size_t nCol
, size_t nRow
) const
703 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMerged" );
704 return CELL( nCol
, nRow
).IsMerged();
707 bool Array::IsMergedOverlappedLeft( size_t nCol
, size_t nRow
) const
709 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMergedOverlappedLeft" );
710 return mxImpl
->IsMergedOverlappedLeft( nCol
, nRow
);
713 bool Array::IsMergedOverlappedRight( size_t nCol
, size_t nRow
) const
715 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMergedOverlappedRight" );
716 return mxImpl
->IsMergedOverlappedRight( nCol
, nRow
);
719 void Array::GetMergedOrigin( size_t& rnFirstCol
, size_t& rnFirstRow
, size_t nCol
, size_t nRow
) const
721 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetMergedOrigin" );
722 rnFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
723 rnFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
726 void Array::GetMergedRange( size_t& rnFirstCol
, size_t& rnFirstRow
,
727 size_t& rnLastCol
, size_t& rnLastRow
, size_t nCol
, size_t nRow
) const
729 GetMergedOrigin( rnFirstCol
, rnFirstRow
, nCol
, nRow
);
730 rnLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
731 rnLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
735 void Array::SetClipRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
)
737 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "SetClipRange" );
738 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "SetClipRange" );
739 mxImpl
->mnFirstClipCol
= nFirstCol
;
740 mxImpl
->mnFirstClipRow
= nFirstRow
;
741 mxImpl
->mnLastClipCol
= nLastCol
;
742 mxImpl
->mnLastClipRow
= nLastRow
;
745 Rectangle
Array::GetClipRangeRectangle() const
748 mxImpl
->GetColPosition( mxImpl
->mnFirstClipCol
),
749 mxImpl
->GetRowPosition( mxImpl
->mnFirstClipRow
),
750 mxImpl
->GetColPosition( mxImpl
->mnLastClipCol
+ 1 ),
751 mxImpl
->GetRowPosition( mxImpl
->mnLastClipRow
+ 1 ) );
755 void Array::SetXOffset( long nXOffset
)
757 mxImpl
->maXCoords
[ 0 ] = nXOffset
;
758 mxImpl
->mbXCoordsDirty
= true;
761 void Array::SetYOffset( long nYOffset
)
763 mxImpl
->maYCoords
[ 0 ] = nYOffset
;
764 mxImpl
->mbYCoordsDirty
= true;
767 void Array::SetColWidth( size_t nCol
, long nWidth
)
769 DBG_FRAME_CHECK_COL( nCol
, "SetColWidth" );
770 mxImpl
->maWidths
[ nCol
] = nWidth
;
771 mxImpl
->mbXCoordsDirty
= true;
774 void Array::SetRowHeight( size_t nRow
, long nHeight
)
776 DBG_FRAME_CHECK_ROW( nRow
, "SetRowHeight" );
777 mxImpl
->maHeights
[ nRow
] = nHeight
;
778 mxImpl
->mbYCoordsDirty
= true;
781 void Array::SetAllColWidths( long nWidth
)
783 std::fill( mxImpl
->maWidths
.begin(), mxImpl
->maWidths
.end(), nWidth
);
784 mxImpl
->mbXCoordsDirty
= true;
787 void Array::SetAllRowHeights( long nHeight
)
789 std::fill( mxImpl
->maHeights
.begin(), mxImpl
->maHeights
.end(), nHeight
);
790 mxImpl
->mbYCoordsDirty
= true;
793 long Array::GetColPosition( size_t nCol
) const
795 DBG_FRAME_CHECK_COL_1( nCol
, "GetColPosition" );
796 return mxImpl
->GetColPosition( nCol
);
799 long Array::GetRowPosition( size_t nRow
) const
801 DBG_FRAME_CHECK_ROW_1( nRow
, "GetRowPosition" );
802 return mxImpl
->GetRowPosition( nRow
);
805 long Array::GetColWidth( size_t nFirstCol
, size_t nLastCol
) const
807 DBG_FRAME_CHECK_COL( nFirstCol
, "GetColWidth" );
808 DBG_FRAME_CHECK_COL( nLastCol
, "GetColWidth" );
809 return GetColPosition( nLastCol
+ 1 ) - GetColPosition( nFirstCol
);
812 long Array::GetRowHeight( size_t nFirstRow
, size_t nLastRow
) const
814 DBG_FRAME_CHECK_ROW( nFirstRow
, "GetRowHeight" );
815 DBG_FRAME_CHECK_ROW( nLastRow
, "GetRowHeight" );
816 return GetRowPosition( nLastRow
+ 1 ) - GetRowPosition( nFirstRow
);
819 long Array::GetWidth() const
821 return GetColPosition( mxImpl
->mnWidth
) - GetColPosition( 0 );
824 long Array::GetHeight() const
826 return GetRowPosition( mxImpl
->mnHeight
) - GetRowPosition( 0 );
829 Point
Array::GetCellPosition( size_t nCol
, size_t nRow
, bool bSimple
) const
831 size_t nFirstCol
= bSimple
? nCol
: mxImpl
->GetMergedFirstCol( nCol
, nRow
);
832 size_t nFirstRow
= bSimple
? nRow
: mxImpl
->GetMergedFirstRow( nCol
, nRow
);
833 return Point( GetColPosition( nFirstCol
), GetRowPosition( nFirstRow
) );
836 Size
Array::GetCellSize( size_t nCol
, size_t nRow
, bool bSimple
) const
838 size_t nFirstCol
= bSimple
? nCol
: mxImpl
->GetMergedFirstCol( nCol
, nRow
);
839 size_t nFirstRow
= bSimple
? nRow
: mxImpl
->GetMergedFirstRow( nCol
, nRow
);
840 size_t nLastCol
= bSimple
? nCol
: mxImpl
->GetMergedLastCol( nCol
, nRow
);
841 size_t nLastRow
= bSimple
? nRow
: mxImpl
->GetMergedLastRow( nCol
, nRow
);
842 return Size( GetColWidth( nFirstCol
, nLastCol
) + 1, GetRowHeight( nFirstRow
, nLastRow
) + 1 );
845 Rectangle
Array::GetCellRect( size_t nCol
, size_t nRow
, bool bSimple
) const
847 Rectangle
aRect( GetCellPosition( nCol
, nRow
, bSimple
), GetCellSize( nCol
, nRow
, bSimple
) );
849 // adjust rectangle for partly visible merged cells
850 const Cell
& rCell
= CELL( nCol
, nRow
);
851 if( !bSimple
&& rCell
.IsMerged() )
853 aRect
.Left() -= rCell
.mnAddLeft
;
854 aRect
.Right() += rCell
.mnAddRight
;
855 aRect
.Top() -= rCell
.mnAddTop
;
856 aRect
.Bottom() += rCell
.mnAddBottom
;
861 // diagonal frame borders
862 double Array::GetHorDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
864 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetHorDiagAngle" );
865 return mxImpl
->GetHorDiagAngle( nCol
, nRow
, bSimple
);
868 double Array::GetVerDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
870 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetVerDiagAngle" );
871 return mxImpl
->GetVerDiagAngle( nCol
, nRow
, bSimple
);
874 void Array::SetUseDiagDoubleClipping( bool bSet
)
876 mxImpl
->mbDiagDblClip
= bSet
;
880 void Array::MirrorSelfX( bool bMirrorStyles
, bool bSwapDiag
)
883 aNewCells
.reserve( GetCellCount() );
886 for( nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
888 for( nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
890 aNewCells
.push_back( CELL( mxImpl
->GetMirrorCol( nCol
), nRow
) );
891 aNewCells
.back().MirrorSelfX( bMirrorStyles
, bSwapDiag
);
894 for( nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
896 for( nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
898 if( CELL( nCol
, nRow
).mbMergeOrig
)
900 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
901 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
902 lclSetMergedRange( aNewCells
, mxImpl
->mnWidth
,
903 mxImpl
->GetMirrorCol( nLastCol
), nRow
,
904 mxImpl
->GetMirrorCol( nCol
), nLastRow
);
908 mxImpl
->maCells
.swap( aNewCells
);
910 std::reverse( mxImpl
->maWidths
.begin(), mxImpl
->maWidths
.end() );
911 mxImpl
->mbXCoordsDirty
= true;
915 void Array::DrawRange( drawinglayer::processor2d::BaseProcessor2D
* pProcessor
,
916 size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
,
917 const Color
* pForceColor
) const
919 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "DrawRange" );
920 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "DrawRange" );
924 // *** diagonal frame borders ***
925 for( nRow
= nFirstRow
; nRow
<= nLastRow
; ++nRow
)
927 for( nCol
= nFirstCol
; nCol
<= nLastCol
; ++nCol
)
929 const Cell
& rCell
= CELL( nCol
, nRow
);
930 bool bOverlapX
= rCell
.mbOverlapX
;
931 bool bOverlapY
= rCell
.mbOverlapY
;
932 bool bFirstCol
= nCol
== nFirstCol
;
933 bool bFirstRow
= nRow
== nFirstRow
;
934 if( (!bOverlapX
&& !bOverlapY
) || (bFirstCol
&& bFirstRow
) ||
935 (!bOverlapY
&& bFirstCol
) || (!bOverlapX
&& bFirstRow
) )
937 Rectangle
aRect( GetCellRect( nCol
, nRow
) );
938 if( (aRect
.GetWidth() > 1) && (aRect
.GetHeight() > 1) )
940 size_t _nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
941 size_t _nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
943 const Style aTlbrStyle
= GetCellStyleTLBR( _nFirstCol
, _nFirstRow
, true );
944 if ( aTlbrStyle
.GetWidth( ) )
945 pProcessor
->process( CreateClippedBorderPrimitives(
946 aRect
.TopLeft(), aRect
.BottomRight(),
947 aTlbrStyle
, aRect
) );
949 const Style aBltrStyle
= GetCellStyleBLTR( _nFirstCol
, _nFirstRow
, true );
950 if ( aBltrStyle
.GetWidth( ) )
951 pProcessor
->process( CreateClippedBorderPrimitives(
952 aRect
.BottomLeft(), aRect
.TopRight(),
953 aBltrStyle
, aRect
) );
959 // *** horizontal frame borders ***
961 for( nRow
= nFirstRow
; nRow
<= nLastRow
+ 1; ++nRow
)
963 double fAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
);
964 double fTAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
- 1 );
966 // *Start*** variables store the data of the left end of the cached frame border
967 Point
aStartPos( mxImpl
->GetColPosition( nFirstCol
), mxImpl
->GetRowPosition( nRow
) );
968 const Style
* pStart
= &GetCellStyleTop( nFirstCol
, nRow
);
969 DiagStyle
aStartLFromTR( GetCellStyleBL( nFirstCol
, nRow
- 1 ), fTAngle
);
970 const Style
* pStartLFromT
= &GetCellStyleLeft( nFirstCol
, nRow
- 1 );
971 const Style
* pStartLFromL
= &GetCellStyleTop( nFirstCol
- 1, nRow
);
972 const Style
* pStartLFromB
= &GetCellStyleLeft( nFirstCol
, nRow
);
973 DiagStyle
aStartLFromBR( GetCellStyleTL( nFirstCol
, nRow
), fAngle
);
975 // *End*** variables store the data of the right end of the cached frame border
976 DiagStyle
aEndRFromTL( GetCellStyleBR( nFirstCol
, nRow
- 1 ), fTAngle
);
977 const Style
* pEndRFromT
= &GetCellStyleRight( nFirstCol
, nRow
- 1 );
978 const Style
* pEndRFromR
= &GetCellStyleTop( nFirstCol
+ 1, nRow
);
979 const Style
* pEndRFromB
= &GetCellStyleRight( nFirstCol
, nRow
);
980 DiagStyle
aEndRFromBL( GetCellStyleTR( nFirstCol
, nRow
), fAngle
);
982 for( nCol
= nFirstCol
+ 1; nCol
<= nLastCol
; ++nCol
)
984 fAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
);
985 fTAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
- 1 );
987 const Style
& rCurr
= *pEndRFromR
;
989 DiagStyle
aLFromTR( GetCellStyleBL( nCol
, nRow
- 1 ), fTAngle
);
990 const Style
& rLFromT
= *pEndRFromT
;
991 const Style
& rLFromL
= *pStart
;
992 const Style
& rLFromB
= *pEndRFromB
;
993 DiagStyle
aLFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
995 DiagStyle
aRFromTL( GetCellStyleBR( nCol
, nRow
- 1 ), fTAngle
);
996 const Style
& rRFromT
= GetCellStyleRight( nCol
, nRow
- 1 );
997 const Style
& rRFromR
= GetCellStyleTop( nCol
+ 1, nRow
);
998 const Style
& rRFromB
= GetCellStyleRight( nCol
, nRow
);
999 DiagStyle
aRFromBL( GetCellStyleTR( nCol
, nRow
), fAngle
);
1001 // check if current frame border can be connected to cached frame border
1002 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1003 aEndRFromTL
, rLFromT
, aLFromTR
, aEndRFromBL
, rLFromB
, aLFromBR
) )
1005 // draw previous frame border
1006 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1007 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1008 pProcessor
->process( CreateBorderPrimitives( aStartPos
, aEndPos
, *pStart
,
1009 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1010 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
) );
1012 // re-init "*Start***" variables
1013 aStartPos
= aEndPos
;
1015 aStartLFromTR
= aLFromTR
;
1016 pStartLFromT
= &rLFromT
;
1017 pStartLFromL
= &rLFromL
;
1018 pStartLFromB
= &rLFromB
;
1019 aStartLFromBR
= aLFromBR
;
1022 // store current styles in "*End***" variables
1023 aEndRFromTL
= aRFromTL
;
1024 pEndRFromT
= &rRFromT
;
1025 pEndRFromR
= &rRFromR
;
1026 pEndRFromB
= &rRFromB
;
1027 aEndRFromBL
= aRFromBL
;
1030 // draw last frame border
1031 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1032 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1033 pProcessor
->process( CreateBorderPrimitives( aStartPos
, aEndPos
, *pStart
,
1034 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1035 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
) );
1038 // *** vertical frame borders ***
1039 for( nCol
= nFirstCol
; nCol
<= nLastCol
+ 1; ++nCol
)
1041 double fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nFirstRow
);
1042 double fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nFirstRow
);
1044 // *Start*** variables store the data of the top end of the cached frame border
1045 Point
aStartPos( mxImpl
->GetColPosition( nCol
), mxImpl
->GetRowPosition( nFirstRow
) );
1046 const Style
* pStart
= &GetCellStyleLeft( nCol
, nFirstRow
);
1047 DiagStyle
aStartTFromBL( GetCellStyleTR( nCol
- 1, nFirstRow
), fLAngle
);
1048 const Style
* pStartTFromL
= &GetCellStyleTop( nCol
- 1, nFirstRow
);
1049 const Style
* pStartTFromT
= &GetCellStyleLeft( nCol
, nFirstRow
- 1 );
1050 const Style
* pStartTFromR
= &GetCellStyleTop( nCol
, nFirstRow
);
1051 DiagStyle
aStartTFromBR( GetCellStyleTL( nCol
, nFirstRow
), fAngle
);
1053 // *End*** variables store the data of the bottom end of the cached frame border
1054 DiagStyle
aEndBFromTL( GetCellStyleBR( nCol
- 1, nFirstRow
), fLAngle
);
1055 const Style
* pEndBFromL
= &GetCellStyleBottom( nCol
- 1, nFirstRow
);
1056 const Style
* pEndBFromB
= &GetCellStyleLeft( nCol
, nFirstRow
+ 1 );
1057 const Style
* pEndBFromR
= &GetCellStyleBottom( nCol
, nFirstRow
);
1058 DiagStyle
aEndBFromTR( GetCellStyleBL( nCol
, nFirstRow
), fAngle
);
1060 for( nRow
= nFirstRow
+ 1; nRow
<= nLastRow
; ++nRow
)
1062 fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nRow
);
1063 fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nRow
);
1065 const Style
& rCurr
= *pEndBFromB
;
1067 DiagStyle
aTFromBL( GetCellStyleTR( nCol
- 1, nRow
), fLAngle
);
1068 const Style
& rTFromL
= *pEndBFromL
;
1069 const Style
& rTFromT
= *pStart
;
1070 const Style
& rTFromR
= *pEndBFromR
;
1071 DiagStyle
aTFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1073 DiagStyle
aBFromTL( GetCellStyleBR( nCol
- 1, nRow
), fLAngle
);
1074 const Style
& rBFromL
= GetCellStyleBottom( nCol
- 1, nRow
);
1075 const Style
& rBFromB
= GetCellStyleLeft( nCol
, nRow
+ 1 );
1076 const Style
& rBFromR
= GetCellStyleBottom( nCol
, nRow
);
1077 DiagStyle
aBFromTR( GetCellStyleBL( nCol
, nRow
), fAngle
);
1079 // check if current frame border can be connected to cached frame border
1080 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1081 aEndBFromTL
, rTFromL
, aTFromBL
, aEndBFromTR
, rTFromR
, aTFromBR
) )
1083 // draw previous frame border
1084 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1085 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1086 pProcessor
->process( CreateBorderPrimitives( aEndPos
, aStartPos
, *pStart
,
1087 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
,
1088 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
, pForceColor
) );
1090 // re-init "*Start***" variables
1091 aStartPos
= aEndPos
;
1093 aStartTFromBL
= aTFromBL
;
1094 pStartTFromL
= &rTFromL
;
1095 pStartTFromT
= &rTFromT
;
1096 pStartTFromR
= &rTFromR
;
1097 aStartTFromBR
= aTFromBR
;
1100 // store current styles in "*End***" variables
1101 aEndBFromTL
= aBFromTL
;
1102 pEndBFromL
= &rBFromL
;
1103 pEndBFromB
= &rBFromB
;
1104 pEndBFromR
= &rBFromR
;
1105 aEndBFromTR
= aBFromTR
;
1108 // draw last frame border
1109 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1110 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1111 pProcessor
->process( CreateBorderPrimitives( aEndPos
, aStartPos
, *pStart
,
1112 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
,
1113 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
, pForceColor
) );
1117 void Array::DrawRange( OutputDevice
& rDev
,
1118 size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
,
1119 const Color
* pForceColor
) const
1121 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "DrawRange" );
1122 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "DrawRange" );
1126 // *** diagonal frame borders ***
1128 // set clipping region to clip partly visible merged cells
1129 rDev
.Push( PushFlags::CLIPREGION
);
1130 rDev
.IntersectClipRegion( GetClipRangeRectangle() );
1131 for( nRow
= nFirstRow
; nRow
<= nLastRow
; ++nRow
)
1133 for( nCol
= nFirstCol
; nCol
<= nLastCol
; ++nCol
)
1135 const Cell
& rCell
= CELL( nCol
, nRow
);
1136 bool bOverlapX
= rCell
.mbOverlapX
;
1137 bool bOverlapY
= rCell
.mbOverlapY
;
1138 bool bFirstCol
= nCol
== nFirstCol
;
1139 bool bFirstRow
= nRow
== nFirstRow
;
1140 if( (!bOverlapX
&& !bOverlapY
) || (bFirstCol
&& bFirstRow
) ||
1141 (!bOverlapY
&& bFirstCol
) || (!bOverlapX
&& bFirstRow
) )
1143 Rectangle
aRect( GetCellRect( nCol
, nRow
) );
1144 if( (aRect
.GetWidth() > 1) && (aRect
.GetHeight() > 1) )
1146 size_t _nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
1147 size_t _nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
1148 size_t _nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
1149 size_t _nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
1151 DrawDiagFrameBorders( rDev
, aRect
,
1152 GetCellStyleTLBR( _nFirstCol
, _nFirstRow
, true ), GetCellStyleBLTR( _nFirstCol
, _nFirstRow
, true ),
1153 GetCellStyleLeft( _nFirstCol
, _nFirstRow
), GetCellStyleTop( _nFirstCol
, _nFirstRow
),
1154 GetCellStyleRight( _nLastCol
, _nLastRow
), GetCellStyleBottom( _nLastCol
, _nLastRow
),
1155 GetCellStyleLeft( _nFirstCol
, _nLastRow
), GetCellStyleBottom( _nFirstCol
, _nLastRow
),
1156 GetCellStyleRight( _nLastCol
, _nFirstRow
), GetCellStyleTop( _nLastCol
, _nFirstRow
),
1157 pForceColor
, mxImpl
->mbDiagDblClip
);
1162 rDev
.Pop(); // clip region
1164 // *** horizontal frame borders ***
1166 for( nRow
= nFirstRow
; nRow
<= nLastRow
+ 1; ++nRow
)
1168 double fAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
);
1169 double fTAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
- 1 );
1171 // *Start*** variables store the data of the left end of the cached frame border
1172 Point
aStartPos( mxImpl
->GetColPosition( nFirstCol
), mxImpl
->GetRowPosition( nRow
) );
1173 const Style
* pStart
= &GetCellStyleTop( nFirstCol
, nRow
);
1174 DiagStyle
aStartLFromTR( GetCellStyleBL( nFirstCol
, nRow
- 1 ), fTAngle
);
1175 const Style
* pStartLFromT
= &GetCellStyleLeft( nFirstCol
, nRow
- 1 );
1176 const Style
* pStartLFromL
= &GetCellStyleTop( nFirstCol
- 1, nRow
);
1177 const Style
* pStartLFromB
= &GetCellStyleLeft( nFirstCol
, nRow
);
1178 DiagStyle
aStartLFromBR( GetCellStyleTL( nFirstCol
, nRow
), fAngle
);
1180 // *End*** variables store the data of the right end of the cached frame border
1181 DiagStyle
aEndRFromTL( GetCellStyleBR( nFirstCol
, nRow
- 1 ), fTAngle
);
1182 const Style
* pEndRFromT
= &GetCellStyleRight( nFirstCol
, nRow
- 1 );
1183 const Style
* pEndRFromR
= &GetCellStyleTop( nFirstCol
+ 1, nRow
);
1184 const Style
* pEndRFromB
= &GetCellStyleRight( nFirstCol
, nRow
);
1185 DiagStyle
aEndRFromBL( GetCellStyleTR( nFirstCol
, nRow
), fAngle
);
1187 for( nCol
= nFirstCol
+ 1; nCol
<= nLastCol
; ++nCol
)
1189 fAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
);
1190 fTAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
- 1 );
1192 const Style
& rCurr
= *pEndRFromR
;
1194 DiagStyle
aLFromTR( GetCellStyleBL( nCol
, nRow
- 1 ), fTAngle
);
1195 const Style
& rLFromT
= *pEndRFromT
;
1196 const Style
& rLFromL
= *pStart
;
1197 const Style
& rLFromB
= *pEndRFromB
;
1198 DiagStyle
aLFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1200 DiagStyle
aRFromTL( GetCellStyleBR( nCol
, nRow
- 1 ), fTAngle
);
1201 const Style
& rRFromT
= GetCellStyleRight( nCol
, nRow
- 1 );
1202 const Style
& rRFromR
= GetCellStyleTop( nCol
+ 1, nRow
);
1203 const Style
& rRFromB
= GetCellStyleRight( nCol
, nRow
);
1204 DiagStyle
aRFromBL( GetCellStyleTR( nCol
, nRow
), fAngle
);
1206 // check if current frame border can be connected to cached frame border
1207 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1208 aEndRFromTL
, rLFromT
, aLFromTR
, aEndRFromBL
, rLFromB
, aLFromBR
) )
1210 // draw previous frame border
1211 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1212 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1213 DrawHorFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1214 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1215 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
);
1217 // re-init "*Start***" variables
1218 aStartPos
= aEndPos
;
1220 aStartLFromTR
= aLFromTR
;
1221 pStartLFromT
= &rLFromT
;
1222 pStartLFromL
= &rLFromL
;
1223 pStartLFromB
= &rLFromB
;
1224 aStartLFromBR
= aLFromBR
;
1227 // store current styles in "*End***" variables
1228 aEndRFromTL
= aRFromTL
;
1229 pEndRFromT
= &rRFromT
;
1230 pEndRFromR
= &rRFromR
;
1231 pEndRFromB
= &rRFromB
;
1232 aEndRFromBL
= aRFromBL
;
1235 // draw last frame border
1236 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1237 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1238 DrawHorFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1239 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1240 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
);
1243 // *** vertical frame borders ***
1245 for( nCol
= nFirstCol
; nCol
<= nLastCol
+ 1; ++nCol
)
1247 double fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nFirstRow
);
1248 double fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nFirstRow
);
1250 // *Start*** variables store the data of the top end of the cached frame border
1251 Point
aStartPos( mxImpl
->GetColPosition( nCol
), mxImpl
->GetRowPosition( nFirstRow
) );
1252 const Style
* pStart
= &GetCellStyleLeft( nCol
, nFirstRow
);
1253 DiagStyle
aStartTFromBL( GetCellStyleTR( nCol
- 1, nFirstRow
), fLAngle
);
1254 const Style
* pStartTFromL
= &GetCellStyleTop( nCol
- 1, nFirstRow
);
1255 const Style
* pStartTFromT
= &GetCellStyleLeft( nCol
, nFirstRow
- 1 );
1256 const Style
* pStartTFromR
= &GetCellStyleTop( nCol
, nFirstRow
);
1257 DiagStyle
aStartTFromBR( GetCellStyleTL( nCol
, nFirstRow
), fAngle
);
1259 // *End*** variables store the data of the bottom end of the cached frame border
1260 DiagStyle
aEndBFromTL( GetCellStyleBR( nCol
- 1, nFirstRow
), fLAngle
);
1261 const Style
* pEndBFromL
= &GetCellStyleBottom( nCol
- 1, nFirstRow
);
1262 const Style
* pEndBFromB
= &GetCellStyleLeft( nCol
, nFirstRow
+ 1 );
1263 const Style
* pEndBFromR
= &GetCellStyleBottom( nCol
, nFirstRow
);
1264 DiagStyle
aEndBFromTR( GetCellStyleBL( nCol
, nFirstRow
), fAngle
);
1266 for( nRow
= nFirstRow
+ 1; nRow
<= nLastRow
; ++nRow
)
1268 fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nRow
);
1269 fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nRow
);
1271 const Style
& rCurr
= *pEndBFromB
;
1273 DiagStyle
aTFromBL( GetCellStyleTR( nCol
- 1, nRow
), fLAngle
);
1274 const Style
& rTFromL
= *pEndBFromL
;
1275 const Style
& rTFromT
= *pStart
;
1276 const Style
& rTFromR
= *pEndBFromR
;
1277 DiagStyle
aTFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1279 DiagStyle
aBFromTL( GetCellStyleBR( nCol
- 1, nRow
), fLAngle
);
1280 const Style
& rBFromL
= GetCellStyleBottom( nCol
- 1, nRow
);
1281 const Style
& rBFromB
= GetCellStyleLeft( nCol
, nRow
+ 1 );
1282 const Style
& rBFromR
= GetCellStyleBottom( nCol
, nRow
);
1283 DiagStyle
aBFromTR( GetCellStyleBL( nCol
, nRow
), fAngle
);
1285 // check if current frame border can be connected to cached frame border
1286 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1287 aEndBFromTL
, rTFromL
, aTFromBL
, aEndBFromTR
, rTFromR
, aTFromBR
) )
1289 // draw previous frame border
1290 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1291 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1292 DrawVerFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1293 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
,
1294 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
, pForceColor
);
1296 // re-init "*Start***" variables
1297 aStartPos
= aEndPos
;
1299 aStartTFromBL
= aTFromBL
;
1300 pStartTFromL
= &rTFromL
;
1301 pStartTFromT
= &rTFromT
;
1302 pStartTFromR
= &rTFromR
;
1303 aStartTFromBR
= aTFromBR
;
1306 // store current styles in "*End***" variables
1307 aEndBFromTL
= aBFromTL
;
1308 pEndBFromL
= &rBFromL
;
1309 pEndBFromB
= &rBFromB
;
1310 pEndBFromR
= &rBFromR
;
1311 aEndBFromTR
= aBFromTR
;
1314 // draw last frame border
1315 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1316 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1317 DrawVerFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1318 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
,
1319 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
, pForceColor
);
1323 void Array::DrawArray( OutputDevice
& rDev
, const Color
* pForceColor
) const
1325 if( mxImpl
->mnWidth
&& mxImpl
->mnHeight
)
1326 DrawRange( rDev
, 0, 0, mxImpl
->mnWidth
- 1, mxImpl
->mnHeight
- 1, pForceColor
);
1337 #undef DBG_FRAME_CHECK_ROW_1
1338 #undef DBG_FRAME_CHECK_COL_1
1339 #undef DBG_FRAME_CHECK_COLROW
1340 #undef DBG_FRAME_CHECK_ROW
1341 #undef DBG_FRAME_CHECK_COL
1342 #undef DBG_FRAME_CHECK
1349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */