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 ------------------------------------------
406 void Array::Initialize( size_t nWidth
, size_t nHeight
)
408 bool bDiagDblClip
= mxImpl
.get() ? mxImpl
->mbDiagDblClip
: DIAG_DBL_CLIP_DEFAULT
;
409 mxImpl
.reset( new ArrayImpl( nWidth
, nHeight
, bDiagDblClip
) );
412 size_t Array::GetColCount() const
414 return mxImpl
->mnWidth
;
417 size_t Array::GetRowCount() const
419 return mxImpl
->mnHeight
;
422 size_t Array::GetCellCount() const
424 return mxImpl
->maCells
.size();
427 size_t Array::GetCellIndex( size_t nCol
, size_t nRow
, bool bRTL
) const
429 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetCellIndex" );
431 nCol
= mxImpl
->GetMirrorCol(nCol
);
432 return mxImpl
->GetIndex( nCol
, nRow
);
435 // cell border styles ---------------------------------------------------------
437 void Array::SetCellStyleLeft( size_t nCol
, size_t nRow
, const Style
& rStyle
)
439 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleLeft" );
440 CELLACC( nCol
, nRow
).maLeft
= rStyle
;
443 void Array::SetCellStyleRight( size_t nCol
, size_t nRow
, const Style
& rStyle
)
445 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleRight" );
446 CELLACC( nCol
, nRow
).maRight
= rStyle
;
449 void Array::SetCellStyleTop( size_t nCol
, size_t nRow
, const Style
& rStyle
)
451 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleTop" );
452 CELLACC( nCol
, nRow
).maTop
= rStyle
;
455 void Array::SetCellStyleBottom( size_t nCol
, size_t nRow
, const Style
& rStyle
)
457 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleBottom" );
458 CELLACC( nCol
, nRow
).maBottom
= rStyle
;
461 void Array::SetCellStyleTLBR( size_t nCol
, size_t nRow
, const Style
& rStyle
)
463 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleTLBR" );
464 CELLACC( nCol
, nRow
).maTLBR
= rStyle
;
467 void Array::SetCellStyleBLTR( size_t nCol
, size_t nRow
, const Style
& rStyle
)
469 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleBLTR" );
470 CELLACC( nCol
, nRow
).maBLTR
= rStyle
;
473 void Array::SetCellStyleDiag( size_t nCol
, size_t nRow
, const Style
& rTLBR
, const Style
& rBLTR
)
475 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetCellStyleDiag" );
476 Cell
& rCell
= CELLACC( nCol
, nRow
);
477 rCell
.maTLBR
= rTLBR
;
478 rCell
.maBLTR
= rBLTR
;
481 void Array::SetColumnStyleLeft( size_t nCol
, const Style
& rStyle
)
483 DBG_FRAME_CHECK_COL( nCol
, "SetColumnStyleLeft" );
484 for( size_t nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
485 SetCellStyleLeft( nCol
, nRow
, rStyle
);
488 void Array::SetColumnStyleRight( size_t nCol
, const Style
& rStyle
)
490 DBG_FRAME_CHECK_COL( nCol
, "SetColumnStyleRight" );
491 for( size_t nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
492 SetCellStyleRight( nCol
, nRow
, rStyle
);
495 void Array::SetRowStyleTop( size_t nRow
, const Style
& rStyle
)
497 DBG_FRAME_CHECK_ROW( nRow
, "SetRowStyleTop" );
498 for( size_t nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
499 SetCellStyleTop( nCol
, nRow
, rStyle
);
502 void Array::SetRowStyleBottom( size_t nRow
, const Style
& rStyle
)
504 DBG_FRAME_CHECK_ROW( nRow
, "SetRowStyleBottom" );
505 for( size_t nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
506 SetCellStyleBottom( nCol
, nRow
, rStyle
);
509 const Style
& Array::GetCellStyleLeft( size_t nCol
, size_t nRow
, bool bSimple
) const
511 // simple: always return own left style
513 return CELL( nCol
, nRow
).maLeft
;
514 // outside clipping rows or overlapped in merged cells: invisible
515 if( !mxImpl
->IsRowInClipRange( nRow
) || mxImpl
->IsMergedOverlappedLeft( nCol
, nRow
) )
516 return OBJ_STYLE_NONE
;
517 // left clipping border: always own left style
518 if( nCol
== mxImpl
->mnFirstClipCol
)
519 return ORIGCELL( nCol
, nRow
).maLeft
;
520 // right clipping border: always right style of left neighbor cell
521 if( nCol
== mxImpl
->mnLastClipCol
+ 1 )
522 return ORIGCELL( nCol
- 1, nRow
).maRight
;
523 // outside clipping columns: invisible
524 if( !mxImpl
->IsColInClipRange( nCol
) )
525 return OBJ_STYLE_NONE
;
526 // inside clipping range: maximum of own left style and right style of left neighbor cell
527 return std::max( ORIGCELL( nCol
, nRow
).maLeft
, ORIGCELL( nCol
- 1, nRow
).maRight
);
530 const Style
& Array::GetCellStyleRight( size_t nCol
, size_t nRow
, bool bSimple
) const
532 // simple: always return own right style
534 return CELL( nCol
, nRow
).maRight
;
535 // outside clipping rows or overlapped in merged cells: invisible
536 if( !mxImpl
->IsRowInClipRange( nRow
) || mxImpl
->IsMergedOverlappedRight( nCol
, nRow
) )
537 return OBJ_STYLE_NONE
;
538 // left clipping border: always left style of right neighbor cell
539 if( nCol
+ 1 == mxImpl
->mnFirstClipCol
)
540 return ORIGCELL( nCol
+ 1, nRow
).maLeft
;
541 // right clipping border: always own right style
542 if( nCol
== mxImpl
->mnLastClipCol
)
543 return ORIGCELL( nCol
, nRow
).maRight
;
544 // outside clipping columns: invisible
545 if( !mxImpl
->IsColInClipRange( nCol
) )
546 return OBJ_STYLE_NONE
;
547 // inside clipping range: maximum of own right style and left style of right neighbor cell
548 return std::max( ORIGCELL( nCol
, nRow
).maRight
, ORIGCELL( nCol
+ 1, nRow
).maLeft
);
551 const Style
& Array::GetCellStyleTop( size_t nCol
, size_t nRow
, bool bSimple
) const
553 // simple: always return own top style
555 return CELL( nCol
, nRow
).maTop
;
556 // outside clipping columns or overlapped in merged cells: invisible
557 if( !mxImpl
->IsColInClipRange( nCol
) || mxImpl
->IsMergedOverlappedTop( nCol
, nRow
) )
558 return OBJ_STYLE_NONE
;
559 // top clipping border: always own top style
560 if( nRow
== mxImpl
->mnFirstClipRow
)
561 return ORIGCELL( nCol
, nRow
).maTop
;
562 // bottom clipping border: always bottom style of top neighbor cell
563 if( nRow
== mxImpl
->mnLastClipRow
+ 1 )
564 return ORIGCELL( nCol
, nRow
- 1 ).maBottom
;
565 // outside clipping rows: invisible
566 if( !mxImpl
->IsRowInClipRange( nRow
) )
567 return OBJ_STYLE_NONE
;
568 // inside clipping range: maximum of own top style and bottom style of top neighbor cell
569 return std::max( ORIGCELL( nCol
, nRow
).maTop
, ORIGCELL( nCol
, nRow
- 1 ).maBottom
);
572 const Style
& Array::GetCellStyleBottom( size_t nCol
, size_t nRow
, bool bSimple
) const
574 // simple: always return own bottom style
576 return CELL( nCol
, nRow
).maBottom
;
577 // outside clipping columns or overlapped in merged cells: invisible
578 if( !mxImpl
->IsColInClipRange( nCol
) || mxImpl
->IsMergedOverlappedBottom( nCol
, nRow
) )
579 return OBJ_STYLE_NONE
;
580 // top clipping border: always top style of bottom neighbor cell
581 if( nRow
+ 1 == mxImpl
->mnFirstClipRow
)
582 return ORIGCELL( nCol
, nRow
+ 1 ).maTop
;
583 // bottom clipping border: always own bottom style
584 if( nRow
== mxImpl
->mnLastClipRow
)
585 return ORIGCELL( nCol
, nRow
).maBottom
;
586 // outside clipping rows: invisible
587 if( !mxImpl
->IsRowInClipRange( nRow
) )
588 return OBJ_STYLE_NONE
;
589 // inside clipping range: maximum of own bottom style and top style of bottom neighbor cell
590 return std::max( ORIGCELL( nCol
, nRow
).maBottom
, ORIGCELL( nCol
, nRow
+ 1 ).maTop
);
593 const Style
& Array::GetCellStyleTLBR( size_t nCol
, size_t nRow
, bool bSimple
) const
595 return bSimple
? CELL( nCol
, nRow
).maTLBR
:
596 (mxImpl
->IsInClipRange( nCol
, nRow
) ? ORIGCELL( nCol
, nRow
).maTLBR
: OBJ_STYLE_NONE
);
599 const Style
& Array::GetCellStyleBLTR( size_t nCol
, size_t nRow
, bool bSimple
) const
601 return bSimple
? CELL( nCol
, nRow
).maBLTR
:
602 (mxImpl
->IsInClipRange( nCol
, nRow
) ? ORIGCELL( nCol
, nRow
).maBLTR
: OBJ_STYLE_NONE
);
605 const Style
& Array::GetCellStyleTL( size_t nCol
, size_t nRow
) const
607 // not in clipping range: always invisible
608 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
609 return OBJ_STYLE_NONE
;
610 // return style only for top-left cell
611 size_t nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
612 size_t nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
613 return ((nCol
== nFirstCol
) && (nRow
== nFirstRow
)) ?
614 CELL( nFirstCol
, nFirstRow
).maTLBR
: OBJ_STYLE_NONE
;
617 const Style
& Array::GetCellStyleBR( size_t nCol
, size_t nRow
) const
619 // not in clipping range: always invisible
620 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
621 return OBJ_STYLE_NONE
;
622 // return style only for bottom-right cell
623 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
624 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
625 return ((nCol
== nLastCol
) && (nRow
== nLastRow
)) ?
626 CELL( mxImpl
->GetMergedFirstCol( nCol
, nRow
), mxImpl
->GetMergedFirstRow( nCol
, nRow
) ).maTLBR
: OBJ_STYLE_NONE
;
629 const Style
& Array::GetCellStyleBL( size_t nCol
, size_t nRow
) const
631 // not in clipping range: always invisible
632 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
633 return OBJ_STYLE_NONE
;
634 // return style only for bottom-left cell
635 size_t nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
636 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
637 return ((nCol
== nFirstCol
) && (nRow
== nLastRow
)) ?
638 CELL( nFirstCol
, mxImpl
->GetMergedFirstRow( nCol
, nRow
) ).maBLTR
: OBJ_STYLE_NONE
;
641 const Style
& Array::GetCellStyleTR( size_t nCol
, size_t nRow
) const
643 // not in clipping range: always invisible
644 if( !mxImpl
->IsInClipRange( nCol
, nRow
) )
645 return OBJ_STYLE_NONE
;
646 // return style only for top-right cell
647 size_t nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
648 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
649 return ((nCol
== nLastCol
) && (nRow
== nFirstRow
)) ?
650 CELL( mxImpl
->GetMergedFirstCol( nCol
, nRow
), nFirstRow
).maBLTR
: OBJ_STYLE_NONE
;
653 // cell merging ---------------------------------------------------------------
655 void Array::SetMergedRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
)
657 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "SetMergedRange" );
658 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "SetMergedRange" );
659 #if OSL_DEBUG_LEVEL >= 2
662 for( size_t nCurrCol
= nFirstCol
; !bFound
&& (nCurrCol
<= nLastCol
); ++nCurrCol
)
663 for( size_t nCurrRow
= nFirstRow
; !bFound
&& (nCurrRow
<= nLastRow
); ++nCurrRow
)
664 bFound
= CELL( nCurrCol
, nCurrRow
).IsMerged();
665 DBG_FRAME_CHECK( !bFound
, "SetMergedRange", "overlapping merged ranges" );
668 if( mxImpl
->IsValidPos( nFirstCol
, nFirstRow
) && mxImpl
->IsValidPos( nLastCol
, nLastRow
) )
669 lclSetMergedRange( mxImpl
->maCells
, mxImpl
->mnWidth
, nFirstCol
, nFirstRow
, nLastCol
, nLastRow
);
672 void Array::SetAddMergedLeftSize( size_t nCol
, size_t nRow
, long nAddSize
)
674 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedLeftSize" );
675 DBG_FRAME_CHECK( mxImpl
->GetMergedFirstCol( nCol
, nRow
) == 0, "SetAddMergedLeftSize", "additional border inside array" );
676 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
677 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddLeft
= nAddSize
;
680 void Array::SetAddMergedRightSize( size_t nCol
, size_t nRow
, long nAddSize
)
682 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedRightSize" );
683 DBG_FRAME_CHECK( mxImpl
->GetMergedLastCol( nCol
, nRow
) + 1 == mxImpl
->mnWidth
, "SetAddMergedRightSize", "additional border inside array" );
684 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
685 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddRight
= nAddSize
;
688 void Array::SetAddMergedTopSize( size_t nCol
, size_t nRow
, long nAddSize
)
690 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedTopSize" );
691 DBG_FRAME_CHECK( mxImpl
->GetMergedFirstRow( nCol
, nRow
) == 0, "SetAddMergedTopSize", "additional border inside array" );
692 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
693 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddTop
= nAddSize
;
696 void Array::SetAddMergedBottomSize( size_t nCol
, size_t nRow
, long nAddSize
)
698 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "SetAddMergedBottomSize" );
699 DBG_FRAME_CHECK( mxImpl
->GetMergedLastRow( nCol
, nRow
) + 1 == mxImpl
->mnHeight
, "SetAddMergedBottomSize", "additional border inside array" );
700 for( MergedCellIterator
aIt( *this, nCol
, nRow
); aIt
.Is(); ++aIt
)
701 CELLACC( aIt
.Col(), aIt
.Row() ).mnAddBottom
= nAddSize
;
704 bool Array::IsMerged( size_t nCol
, size_t nRow
) const
706 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMerged" );
707 return CELL( nCol
, nRow
).IsMerged();
710 bool Array::IsMergedOverlappedLeft( size_t nCol
, size_t nRow
) const
712 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMergedOverlappedLeft" );
713 return mxImpl
->IsMergedOverlappedLeft( nCol
, nRow
);
716 bool Array::IsMergedOverlappedRight( size_t nCol
, size_t nRow
) const
718 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "IsMergedOverlappedRight" );
719 return mxImpl
->IsMergedOverlappedRight( nCol
, nRow
);
722 void Array::GetMergedOrigin( size_t& rnFirstCol
, size_t& rnFirstRow
, size_t nCol
, size_t nRow
) const
724 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetMergedOrigin" );
725 rnFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
726 rnFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
729 void Array::GetMergedRange( size_t& rnFirstCol
, size_t& rnFirstRow
,
730 size_t& rnLastCol
, size_t& rnLastRow
, size_t nCol
, size_t nRow
) const
732 GetMergedOrigin( rnFirstCol
, rnFirstRow
, nCol
, nRow
);
733 rnLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
734 rnLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
737 // clipping -------------------------------------------------------------------
739 void Array::SetClipRange( size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
)
741 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "SetClipRange" );
742 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "SetClipRange" );
743 mxImpl
->mnFirstClipCol
= nFirstCol
;
744 mxImpl
->mnFirstClipRow
= nFirstRow
;
745 mxImpl
->mnLastClipCol
= nLastCol
;
746 mxImpl
->mnLastClipRow
= nLastRow
;
749 Rectangle
Array::GetClipRangeRectangle() const
752 mxImpl
->GetColPosition( mxImpl
->mnFirstClipCol
),
753 mxImpl
->GetRowPosition( mxImpl
->mnFirstClipRow
),
754 mxImpl
->GetColPosition( mxImpl
->mnLastClipCol
+ 1 ),
755 mxImpl
->GetRowPosition( mxImpl
->mnLastClipRow
+ 1 ) );
758 // cell coordinates -----------------------------------------------------------
760 void Array::SetXOffset( long nXOffset
)
762 mxImpl
->maXCoords
[ 0 ] = nXOffset
;
763 mxImpl
->mbXCoordsDirty
= true;
766 void Array::SetYOffset( long nYOffset
)
768 mxImpl
->maYCoords
[ 0 ] = nYOffset
;
769 mxImpl
->mbYCoordsDirty
= true;
772 void Array::SetColWidth( size_t nCol
, long nWidth
)
774 DBG_FRAME_CHECK_COL( nCol
, "SetColWidth" );
775 mxImpl
->maWidths
[ nCol
] = nWidth
;
776 mxImpl
->mbXCoordsDirty
= true;
779 void Array::SetRowHeight( size_t nRow
, long nHeight
)
781 DBG_FRAME_CHECK_ROW( nRow
, "SetRowHeight" );
782 mxImpl
->maHeights
[ nRow
] = nHeight
;
783 mxImpl
->mbYCoordsDirty
= true;
786 void Array::SetAllColWidths( long nWidth
)
788 std::fill( mxImpl
->maWidths
.begin(), mxImpl
->maWidths
.end(), nWidth
);
789 mxImpl
->mbXCoordsDirty
= true;
792 void Array::SetAllRowHeights( long nHeight
)
794 std::fill( mxImpl
->maHeights
.begin(), mxImpl
->maHeights
.end(), nHeight
);
795 mxImpl
->mbYCoordsDirty
= true;
798 long Array::GetColPosition( size_t nCol
) const
800 DBG_FRAME_CHECK_COL_1( nCol
, "GetColPosition" );
801 return mxImpl
->GetColPosition( nCol
);
804 long Array::GetRowPosition( size_t nRow
) const
806 DBG_FRAME_CHECK_ROW_1( nRow
, "GetRowPosition" );
807 return mxImpl
->GetRowPosition( nRow
);
810 long Array::GetColWidth( size_t nFirstCol
, size_t nLastCol
) const
812 DBG_FRAME_CHECK_COL( nFirstCol
, "GetColWidth" );
813 DBG_FRAME_CHECK_COL( nLastCol
, "GetColWidth" );
814 return GetColPosition( nLastCol
+ 1 ) - GetColPosition( nFirstCol
);
817 long Array::GetRowHeight( size_t nFirstRow
, size_t nLastRow
) const
819 DBG_FRAME_CHECK_ROW( nFirstRow
, "GetRowHeight" );
820 DBG_FRAME_CHECK_ROW( nLastRow
, "GetRowHeight" );
821 return GetRowPosition( nLastRow
+ 1 ) - GetRowPosition( nFirstRow
);
824 long Array::GetWidth() const
826 return GetColPosition( mxImpl
->mnWidth
) - GetColPosition( 0 );
829 long Array::GetHeight() const
831 return GetRowPosition( mxImpl
->mnHeight
) - GetRowPosition( 0 );
834 Point
Array::GetCellPosition( size_t nCol
, size_t nRow
, bool bSimple
) const
836 size_t nFirstCol
= bSimple
? nCol
: mxImpl
->GetMergedFirstCol( nCol
, nRow
);
837 size_t nFirstRow
= bSimple
? nRow
: mxImpl
->GetMergedFirstRow( nCol
, nRow
);
838 return Point( GetColPosition( nFirstCol
), GetRowPosition( nFirstRow
) );
841 Size
Array::GetCellSize( size_t nCol
, size_t nRow
, bool bSimple
) const
843 size_t nFirstCol
= bSimple
? nCol
: mxImpl
->GetMergedFirstCol( nCol
, nRow
);
844 size_t nFirstRow
= bSimple
? nRow
: mxImpl
->GetMergedFirstRow( nCol
, nRow
);
845 size_t nLastCol
= bSimple
? nCol
: mxImpl
->GetMergedLastCol( nCol
, nRow
);
846 size_t nLastRow
= bSimple
? nRow
: mxImpl
->GetMergedLastRow( nCol
, nRow
);
847 return Size( GetColWidth( nFirstCol
, nLastCol
) + 1, GetRowHeight( nFirstRow
, nLastRow
) + 1 );
850 Rectangle
Array::GetCellRect( size_t nCol
, size_t nRow
, bool bSimple
) const
852 Rectangle
aRect( GetCellPosition( nCol
, nRow
, bSimple
), GetCellSize( nCol
, nRow
, bSimple
) );
854 // adjust rectangle for partly visible merged cells
855 const Cell
& rCell
= CELL( nCol
, nRow
);
856 if( !bSimple
&& rCell
.IsMerged() )
858 aRect
.Left() -= rCell
.mnAddLeft
;
859 aRect
.Right() += rCell
.mnAddRight
;
860 aRect
.Top() -= rCell
.mnAddTop
;
861 aRect
.Bottom() += rCell
.mnAddBottom
;
866 // diagonal frame borders -----------------------------------------------------
868 double Array::GetHorDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
870 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetHorDiagAngle" );
871 return mxImpl
->GetHorDiagAngle( nCol
, nRow
, bSimple
);
874 double Array::GetVerDiagAngle( size_t nCol
, size_t nRow
, bool bSimple
) const
876 DBG_FRAME_CHECK_COLROW( nCol
, nRow
, "GetVerDiagAngle" );
877 return mxImpl
->GetVerDiagAngle( nCol
, nRow
, bSimple
);
880 void Array::SetUseDiagDoubleClipping( bool bSet
)
882 mxImpl
->mbDiagDblClip
= bSet
;
885 // mirroring ------------------------------------------------------------------
887 void Array::MirrorSelfX( bool bMirrorStyles
, bool bSwapDiag
)
890 aNewCells
.reserve( GetCellCount() );
893 for( nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
895 for( nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
897 aNewCells
.push_back( CELL( mxImpl
->GetMirrorCol( nCol
), nRow
) );
898 aNewCells
.back().MirrorSelfX( bMirrorStyles
, bSwapDiag
);
901 for( nRow
= 0; nRow
< mxImpl
->mnHeight
; ++nRow
)
903 for( nCol
= 0; nCol
< mxImpl
->mnWidth
; ++nCol
)
905 if( CELL( nCol
, nRow
).mbMergeOrig
)
907 size_t nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
908 size_t nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
909 lclSetMergedRange( aNewCells
, mxImpl
->mnWidth
,
910 mxImpl
->GetMirrorCol( nLastCol
), nRow
,
911 mxImpl
->GetMirrorCol( nCol
), nLastRow
);
915 mxImpl
->maCells
.swap( aNewCells
);
917 std::reverse( mxImpl
->maWidths
.begin(), mxImpl
->maWidths
.end() );
918 mxImpl
->mbXCoordsDirty
= true;
921 // drawing --------------------------------------------------------------------
923 void Array::DrawRange( drawinglayer::processor2d::BaseProcessor2D
* pProcessor
,
924 size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
,
925 const Color
* pForceColor
) const
927 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "DrawRange" );
928 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "DrawRange" );
932 // *** diagonal frame borders ***
933 for( nRow
= nFirstRow
; nRow
<= nLastRow
; ++nRow
)
935 for( nCol
= nFirstCol
; nCol
<= nLastCol
; ++nCol
)
937 const Cell
& rCell
= CELL( nCol
, nRow
);
938 bool bOverlapX
= rCell
.mbOverlapX
;
939 bool bOverlapY
= rCell
.mbOverlapY
;
940 bool bFirstCol
= nCol
== nFirstCol
;
941 bool bFirstRow
= nRow
== nFirstRow
;
942 if( (!bOverlapX
&& !bOverlapY
) || (bFirstCol
&& bFirstRow
) ||
943 (!bOverlapY
&& bFirstCol
) || (!bOverlapX
&& bFirstRow
) )
945 Rectangle
aRect( GetCellRect( nCol
, nRow
) );
946 if( (aRect
.GetWidth() > 1) && (aRect
.GetHeight() > 1) )
948 size_t _nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
949 size_t _nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
951 const Style aTlbrStyle
= GetCellStyleTLBR( _nFirstCol
, _nFirstRow
, true );
952 if ( aTlbrStyle
.GetWidth( ) )
953 pProcessor
->process( CreateClippedBorderPrimitives(
954 aRect
.TopLeft(), aRect
.BottomRight(),
955 aTlbrStyle
, aRect
) );
957 const Style aBltrStyle
= GetCellStyleBLTR( _nFirstCol
, _nFirstRow
, true );
958 if ( aBltrStyle
.GetWidth( ) )
959 pProcessor
->process( CreateClippedBorderPrimitives(
960 aRect
.BottomLeft(), aRect
.TopRight(),
961 aBltrStyle
, aRect
) );
967 // *** horizontal frame borders ***
969 for( nRow
= nFirstRow
; nRow
<= nLastRow
+ 1; ++nRow
)
971 double fAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
);
972 double fTAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
- 1 );
974 // *Start*** variables store the data of the left end of the cached frame border
975 Point
aStartPos( mxImpl
->GetColPosition( nFirstCol
), mxImpl
->GetRowPosition( nRow
) );
976 const Style
* pStart
= &GetCellStyleTop( nFirstCol
, nRow
);
977 DiagStyle
aStartLFromTR( GetCellStyleBL( nFirstCol
, nRow
- 1 ), fTAngle
);
978 const Style
* pStartLFromT
= &GetCellStyleLeft( nFirstCol
, nRow
- 1 );
979 const Style
* pStartLFromL
= &GetCellStyleTop( nFirstCol
- 1, nRow
);
980 const Style
* pStartLFromB
= &GetCellStyleLeft( nFirstCol
, nRow
);
981 DiagStyle
aStartLFromBR( GetCellStyleTL( nFirstCol
, nRow
), fAngle
);
983 // *End*** variables store the data of the right end of the cached frame border
984 DiagStyle
aEndRFromTL( GetCellStyleBR( nFirstCol
, nRow
- 1 ), fTAngle
);
985 const Style
* pEndRFromT
= &GetCellStyleRight( nFirstCol
, nRow
- 1 );
986 const Style
* pEndRFromR
= &GetCellStyleTop( nFirstCol
+ 1, nRow
);
987 const Style
* pEndRFromB
= &GetCellStyleRight( nFirstCol
, nRow
);
988 DiagStyle
aEndRFromBL( GetCellStyleTR( nFirstCol
, nRow
), fAngle
);
990 for( nCol
= nFirstCol
+ 1; nCol
<= nLastCol
; ++nCol
)
992 fAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
);
993 fTAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
- 1 );
995 const Style
& rCurr
= *pEndRFromR
;
997 DiagStyle
aLFromTR( GetCellStyleBL( nCol
, nRow
- 1 ), fTAngle
);
998 const Style
& rLFromT
= *pEndRFromT
;
999 const Style
& rLFromL
= *pStart
;
1000 const Style
& rLFromB
= *pEndRFromB
;
1001 DiagStyle
aLFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1003 DiagStyle
aRFromTL( GetCellStyleBR( nCol
, nRow
- 1 ), fTAngle
);
1004 const Style
& rRFromT
= GetCellStyleRight( nCol
, nRow
- 1 );
1005 const Style
& rRFromR
= GetCellStyleTop( nCol
+ 1, nRow
);
1006 const Style
& rRFromB
= GetCellStyleRight( nCol
, nRow
);
1007 DiagStyle
aRFromBL( GetCellStyleTR( nCol
, nRow
), fAngle
);
1009 // check if current frame border can be connected to cached frame border
1010 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1011 aEndRFromTL
, rLFromT
, aLFromTR
, aEndRFromBL
, rLFromB
, aLFromBR
) )
1013 // draw previous frame border
1014 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1015 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1016 pProcessor
->process( CreateBorderPrimitives( aStartPos
, aEndPos
, *pStart
,
1017 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1018 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
) );
1020 // re-init "*Start***" variables
1021 aStartPos
= aEndPos
;
1023 aStartLFromTR
= aLFromTR
;
1024 pStartLFromT
= &rLFromT
;
1025 pStartLFromL
= &rLFromL
;
1026 pStartLFromB
= &rLFromB
;
1027 aStartLFromBR
= aLFromBR
;
1030 // store current styles in "*End***" variables
1031 aEndRFromTL
= aRFromTL
;
1032 pEndRFromT
= &rRFromT
;
1033 pEndRFromR
= &rRFromR
;
1034 pEndRFromB
= &rRFromB
;
1035 aEndRFromBL
= aRFromBL
;
1038 // draw last frame border
1039 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1040 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1041 pProcessor
->process( CreateBorderPrimitives( aStartPos
, aEndPos
, *pStart
,
1042 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1043 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
) );
1046 // *** vertical frame borders ***
1047 for( nCol
= nFirstCol
; nCol
<= nLastCol
+ 1; ++nCol
)
1049 double fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nFirstRow
);
1050 double fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nFirstRow
);
1052 // *Start*** variables store the data of the top end of the cached frame border
1053 Point
aStartPos( mxImpl
->GetColPosition( nCol
), mxImpl
->GetRowPosition( nFirstRow
) );
1054 const Style
* pStart
= &GetCellStyleLeft( nCol
, nFirstRow
);
1055 DiagStyle
aStartTFromBL( GetCellStyleTR( nCol
- 1, nFirstRow
), fLAngle
);
1056 const Style
* pStartTFromL
= &GetCellStyleTop( nCol
- 1, nFirstRow
);
1057 const Style
* pStartTFromT
= &GetCellStyleLeft( nCol
, nFirstRow
- 1 );
1058 const Style
* pStartTFromR
= &GetCellStyleTop( nCol
, nFirstRow
);
1059 DiagStyle
aStartTFromBR( GetCellStyleTL( nCol
, nFirstRow
), fAngle
);
1061 // *End*** variables store the data of the bottom end of the cached frame border
1062 DiagStyle
aEndBFromTL( GetCellStyleBR( nCol
- 1, nFirstRow
), fLAngle
);
1063 const Style
* pEndBFromL
= &GetCellStyleBottom( nCol
- 1, nFirstRow
);
1064 const Style
* pEndBFromB
= &GetCellStyleLeft( nCol
, nFirstRow
+ 1 );
1065 const Style
* pEndBFromR
= &GetCellStyleBottom( nCol
, nFirstRow
);
1066 DiagStyle
aEndBFromTR( GetCellStyleBL( nCol
, nFirstRow
), fAngle
);
1068 for( nRow
= nFirstRow
+ 1; nRow
<= nLastRow
; ++nRow
)
1070 fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nRow
);
1071 fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nRow
);
1073 const Style
& rCurr
= *pEndBFromB
;
1075 DiagStyle
aTFromBL( GetCellStyleTR( nCol
- 1, nRow
), fLAngle
);
1076 const Style
& rTFromL
= *pEndBFromL
;
1077 const Style
& rTFromT
= *pStart
;
1078 const Style
& rTFromR
= *pEndBFromR
;
1079 DiagStyle
aTFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1081 DiagStyle
aBFromTL( GetCellStyleBR( nCol
- 1, nRow
), fLAngle
);
1082 const Style
& rBFromL
= GetCellStyleBottom( nCol
- 1, nRow
);
1083 const Style
& rBFromB
= GetCellStyleLeft( nCol
, nRow
+ 1 );
1084 const Style
& rBFromR
= GetCellStyleBottom( nCol
, nRow
);
1085 DiagStyle
aBFromTR( GetCellStyleBL( nCol
, nRow
), fAngle
);
1087 // check if current frame border can be connected to cached frame border
1088 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1089 aEndBFromTL
, rTFromL
, aTFromBL
, aEndBFromTR
, rTFromR
, aTFromBR
) )
1091 // draw previous frame border
1092 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1093 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1094 pProcessor
->process( CreateBorderPrimitives( aEndPos
, aStartPos
, *pStart
,
1095 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
,
1096 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
, pForceColor
) );
1098 // re-init "*Start***" variables
1099 aStartPos
= aEndPos
;
1101 aStartTFromBL
= aTFromBL
;
1102 pStartTFromL
= &rTFromL
;
1103 pStartTFromT
= &rTFromT
;
1104 pStartTFromR
= &rTFromR
;
1105 aStartTFromBR
= aTFromBR
;
1108 // store current styles in "*End***" variables
1109 aEndBFromTL
= aBFromTL
;
1110 pEndBFromL
= &rBFromL
;
1111 pEndBFromB
= &rBFromB
;
1112 pEndBFromR
= &rBFromR
;
1113 aEndBFromTR
= aBFromTR
;
1116 // draw last frame border
1117 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1118 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1119 pProcessor
->process( CreateBorderPrimitives( aEndPos
, aStartPos
, *pStart
,
1120 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
,
1121 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
, pForceColor
) );
1125 void Array::DrawRange( OutputDevice
& rDev
,
1126 size_t nFirstCol
, size_t nFirstRow
, size_t nLastCol
, size_t nLastRow
,
1127 const Color
* pForceColor
) const
1129 DBG_FRAME_CHECK_COLROW( nFirstCol
, nFirstRow
, "DrawRange" );
1130 DBG_FRAME_CHECK_COLROW( nLastCol
, nLastRow
, "DrawRange" );
1134 // *** diagonal frame borders ***
1136 // set clipping region to clip partly visible merged cells
1137 rDev
.Push( PUSH_CLIPREGION
);
1138 rDev
.IntersectClipRegion( GetClipRangeRectangle() );
1139 for( nRow
= nFirstRow
; nRow
<= nLastRow
; ++nRow
)
1141 for( nCol
= nFirstCol
; nCol
<= nLastCol
; ++nCol
)
1143 const Cell
& rCell
= CELL( nCol
, nRow
);
1144 bool bOverlapX
= rCell
.mbOverlapX
;
1145 bool bOverlapY
= rCell
.mbOverlapY
;
1146 bool bFirstCol
= nCol
== nFirstCol
;
1147 bool bFirstRow
= nRow
== nFirstRow
;
1148 if( (!bOverlapX
&& !bOverlapY
) || (bFirstCol
&& bFirstRow
) ||
1149 (!bOverlapY
&& bFirstCol
) || (!bOverlapX
&& bFirstRow
) )
1151 Rectangle
aRect( GetCellRect( nCol
, nRow
) );
1152 if( (aRect
.GetWidth() > 1) && (aRect
.GetHeight() > 1) )
1154 size_t _nFirstCol
= mxImpl
->GetMergedFirstCol( nCol
, nRow
);
1155 size_t _nFirstRow
= mxImpl
->GetMergedFirstRow( nCol
, nRow
);
1156 size_t _nLastCol
= mxImpl
->GetMergedLastCol( nCol
, nRow
);
1157 size_t _nLastRow
= mxImpl
->GetMergedLastRow( nCol
, nRow
);
1159 DrawDiagFrameBorders( rDev
, aRect
,
1160 GetCellStyleTLBR( _nFirstCol
, _nFirstRow
, true ), GetCellStyleBLTR( _nFirstCol
, _nFirstRow
, true ),
1161 GetCellStyleLeft( _nFirstCol
, _nFirstRow
), GetCellStyleTop( _nFirstCol
, _nFirstRow
),
1162 GetCellStyleRight( _nLastCol
, _nLastRow
), GetCellStyleBottom( _nLastCol
, _nLastRow
),
1163 GetCellStyleLeft( _nFirstCol
, _nLastRow
), GetCellStyleBottom( _nFirstCol
, _nLastRow
),
1164 GetCellStyleRight( _nLastCol
, _nFirstRow
), GetCellStyleTop( _nLastCol
, _nFirstRow
),
1165 pForceColor
, mxImpl
->mbDiagDblClip
);
1170 rDev
.Pop(); // clip region
1172 // *** horizontal frame borders ***
1174 for( nRow
= nFirstRow
; nRow
<= nLastRow
+ 1; ++nRow
)
1176 double fAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
);
1177 double fTAngle
= mxImpl
->GetHorDiagAngle( nFirstCol
, nRow
- 1 );
1179 // *Start*** variables store the data of the left end of the cached frame border
1180 Point
aStartPos( mxImpl
->GetColPosition( nFirstCol
), mxImpl
->GetRowPosition( nRow
) );
1181 const Style
* pStart
= &GetCellStyleTop( nFirstCol
, nRow
);
1182 DiagStyle
aStartLFromTR( GetCellStyleBL( nFirstCol
, nRow
- 1 ), fTAngle
);
1183 const Style
* pStartLFromT
= &GetCellStyleLeft( nFirstCol
, nRow
- 1 );
1184 const Style
* pStartLFromL
= &GetCellStyleTop( nFirstCol
- 1, nRow
);
1185 const Style
* pStartLFromB
= &GetCellStyleLeft( nFirstCol
, nRow
);
1186 DiagStyle
aStartLFromBR( GetCellStyleTL( nFirstCol
, nRow
), fAngle
);
1188 // *End*** variables store the data of the right end of the cached frame border
1189 DiagStyle
aEndRFromTL( GetCellStyleBR( nFirstCol
, nRow
- 1 ), fTAngle
);
1190 const Style
* pEndRFromT
= &GetCellStyleRight( nFirstCol
, nRow
- 1 );
1191 const Style
* pEndRFromR
= &GetCellStyleTop( nFirstCol
+ 1, nRow
);
1192 const Style
* pEndRFromB
= &GetCellStyleRight( nFirstCol
, nRow
);
1193 DiagStyle
aEndRFromBL( GetCellStyleTR( nFirstCol
, nRow
), fAngle
);
1195 for( nCol
= nFirstCol
+ 1; nCol
<= nLastCol
; ++nCol
)
1197 fAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
);
1198 fTAngle
= mxImpl
->GetHorDiagAngle( nCol
, nRow
- 1 );
1200 const Style
& rCurr
= *pEndRFromR
;
1202 DiagStyle
aLFromTR( GetCellStyleBL( nCol
, nRow
- 1 ), fTAngle
);
1203 const Style
& rLFromT
= *pEndRFromT
;
1204 const Style
& rLFromL
= *pStart
;
1205 const Style
& rLFromB
= *pEndRFromB
;
1206 DiagStyle
aLFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1208 DiagStyle
aRFromTL( GetCellStyleBR( nCol
, nRow
- 1 ), fTAngle
);
1209 const Style
& rRFromT
= GetCellStyleRight( nCol
, nRow
- 1 );
1210 const Style
& rRFromR
= GetCellStyleTop( nCol
+ 1, nRow
);
1211 const Style
& rRFromB
= GetCellStyleRight( nCol
, nRow
);
1212 DiagStyle
aRFromBL( GetCellStyleTR( nCol
, nRow
), fAngle
);
1214 // check if current frame border can be connected to cached frame border
1215 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1216 aEndRFromTL
, rLFromT
, aLFromTR
, aEndRFromBL
, rLFromB
, aLFromBR
) )
1218 // draw previous frame border
1219 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1220 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1221 DrawHorFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1222 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1223 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
);
1225 // re-init "*Start***" variables
1226 aStartPos
= aEndPos
;
1228 aStartLFromTR
= aLFromTR
;
1229 pStartLFromT
= &rLFromT
;
1230 pStartLFromL
= &rLFromL
;
1231 pStartLFromB
= &rLFromB
;
1232 aStartLFromBR
= aLFromBR
;
1235 // store current styles in "*End***" variables
1236 aEndRFromTL
= aRFromTL
;
1237 pEndRFromT
= &rRFromT
;
1238 pEndRFromR
= &rRFromR
;
1239 pEndRFromB
= &rRFromB
;
1240 aEndRFromBL
= aRFromBL
;
1243 // draw last frame border
1244 Point
aEndPos( mxImpl
->GetColPosition( nCol
), aStartPos
.Y() );
1245 if( pStart
->Prim() && (aStartPos
.X() <= aEndPos
.X()) )
1246 DrawHorFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1247 aStartLFromTR
, *pStartLFromT
, *pStartLFromL
, *pStartLFromB
, aStartLFromBR
,
1248 aEndRFromTL
, *pEndRFromT
, *pEndRFromR
, *pEndRFromB
, aEndRFromBL
, pForceColor
);
1251 // *** vertical frame borders ***
1253 for( nCol
= nFirstCol
; nCol
<= nLastCol
+ 1; ++nCol
)
1255 double fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nFirstRow
);
1256 double fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nFirstRow
);
1258 // *Start*** variables store the data of the top end of the cached frame border
1259 Point
aStartPos( mxImpl
->GetColPosition( nCol
), mxImpl
->GetRowPosition( nFirstRow
) );
1260 const Style
* pStart
= &GetCellStyleLeft( nCol
, nFirstRow
);
1261 DiagStyle
aStartTFromBL( GetCellStyleTR( nCol
- 1, nFirstRow
), fLAngle
);
1262 const Style
* pStartTFromL
= &GetCellStyleTop( nCol
- 1, nFirstRow
);
1263 const Style
* pStartTFromT
= &GetCellStyleLeft( nCol
, nFirstRow
- 1 );
1264 const Style
* pStartTFromR
= &GetCellStyleTop( nCol
, nFirstRow
);
1265 DiagStyle
aStartTFromBR( GetCellStyleTL( nCol
, nFirstRow
), fAngle
);
1267 // *End*** variables store the data of the bottom end of the cached frame border
1268 DiagStyle
aEndBFromTL( GetCellStyleBR( nCol
- 1, nFirstRow
), fLAngle
);
1269 const Style
* pEndBFromL
= &GetCellStyleBottom( nCol
- 1, nFirstRow
);
1270 const Style
* pEndBFromB
= &GetCellStyleLeft( nCol
, nFirstRow
+ 1 );
1271 const Style
* pEndBFromR
= &GetCellStyleBottom( nCol
, nFirstRow
);
1272 DiagStyle
aEndBFromTR( GetCellStyleBL( nCol
, nFirstRow
), fAngle
);
1274 for( nRow
= nFirstRow
+ 1; nRow
<= nLastRow
; ++nRow
)
1276 fAngle
= mxImpl
->GetVerDiagAngle( nCol
, nRow
);
1277 fLAngle
= mxImpl
->GetVerDiagAngle( nCol
- 1, nRow
);
1279 const Style
& rCurr
= *pEndBFromB
;
1281 DiagStyle
aTFromBL( GetCellStyleTR( nCol
- 1, nRow
), fLAngle
);
1282 const Style
& rTFromL
= *pEndBFromL
;
1283 const Style
& rTFromT
= *pStart
;
1284 const Style
& rTFromR
= *pEndBFromR
;
1285 DiagStyle
aTFromBR( GetCellStyleTL( nCol
, nRow
), fAngle
);
1287 DiagStyle
aBFromTL( GetCellStyleBR( nCol
- 1, nRow
), fLAngle
);
1288 const Style
& rBFromL
= GetCellStyleBottom( nCol
- 1, nRow
);
1289 const Style
& rBFromB
= GetCellStyleLeft( nCol
, nRow
+ 1 );
1290 const Style
& rBFromR
= GetCellStyleBottom( nCol
, nRow
);
1291 DiagStyle
aBFromTR( GetCellStyleBL( nCol
, nRow
), fAngle
);
1293 // check if current frame border can be connected to cached frame border
1294 if( !CheckFrameBorderConnectable( *pStart
, rCurr
,
1295 aEndBFromTL
, rTFromL
, aTFromBL
, aEndBFromTR
, rTFromR
, aTFromBR
) )
1297 // draw previous frame border
1298 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1299 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1300 DrawVerFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1301 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
,
1302 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
, pForceColor
);
1304 // re-init "*Start***" variables
1305 aStartPos
= aEndPos
;
1307 aStartTFromBL
= aTFromBL
;
1308 pStartTFromL
= &rTFromL
;
1309 pStartTFromT
= &rTFromT
;
1310 pStartTFromR
= &rTFromR
;
1311 aStartTFromBR
= aTFromBR
;
1314 // store current styles in "*End***" variables
1315 aEndBFromTL
= aBFromTL
;
1316 pEndBFromL
= &rBFromL
;
1317 pEndBFromB
= &rBFromB
;
1318 pEndBFromR
= &rBFromR
;
1319 aEndBFromTR
= aBFromTR
;
1322 // draw last frame border
1323 Point
aEndPos( aStartPos
.X(), mxImpl
->GetRowPosition( nRow
) );
1324 if( pStart
->Prim() && (aStartPos
.Y() <= aEndPos
.Y()) )
1325 DrawVerFrameBorder( rDev
, aStartPos
, aEndPos
, *pStart
,
1326 aStartTFromBL
, *pStartTFromL
, *pStartTFromT
, *pStartTFromR
, aStartTFromBR
,
1327 aEndBFromTL
, *pEndBFromL
, *pEndBFromB
, *pEndBFromR
, aEndBFromTR
, pForceColor
);
1331 void Array::DrawArray( OutputDevice
& rDev
, const Color
* pForceColor
) const
1333 if( mxImpl
->mnWidth
&& mxImpl
->mnHeight
)
1334 DrawRange( rDev
, 0, 0, mxImpl
->mnWidth
- 1, mxImpl
->mnHeight
- 1, pForceColor
);
1345 #undef DBG_FRAME_CHECK_ROW_1
1346 #undef DBG_FRAME_CHECK_COL_1
1347 #undef DBG_FRAME_CHECK_COLROW
1348 #undef DBG_FRAME_CHECK_ROW
1349 #undef DBG_FRAME_CHECK_COL
1350 #undef DBG_FRAME_CHECK
1354 } // namespace frame
1357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */