update dev300-m58
[ooovba.git] / sc / source / ui / view / prevloc.cxx
blobfb6595579772be53d070860ddeacbade9b3758d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prevloc.cxx,v $
10 * $Revision: 1.16.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <vcl/outdev.hxx>
39 #include <tools/debug.hxx>
41 #include "prevloc.hxx"
42 #include "document.hxx"
44 //==================================================================
46 enum ScPreviewLocationType
48 SC_PLOC_CELLRANGE,
49 SC_PLOC_COLHEADER,
50 SC_PLOC_ROWHEADER,
51 SC_PLOC_LEFTHEADER,
52 SC_PLOC_RIGHTHEADER,
53 SC_PLOC_LEFTFOOTER,
54 SC_PLOC_RIGHTFOOTER,
55 SC_PLOC_NOTEMARK,
56 SC_PLOC_NOTETEXT
59 struct ScPreviewLocationEntry
61 ScPreviewLocationType eType;
62 Rectangle aPixelRect;
63 ScRange aCellRange;
64 BOOL bRepeatCol;
65 BOOL bRepeatRow;
67 ScPreviewLocationEntry( ScPreviewLocationType eNewType, const Rectangle& rPixel, const ScRange& rRange,
68 BOOL bRepCol, BOOL bRepRow ) :
69 eType( eNewType ),
70 aPixelRect( rPixel ),
71 aCellRange( rRange ),
72 bRepeatCol( bRepCol ),
73 bRepeatRow( bRepRow )
78 //==================================================================
80 ScPreviewTableInfo::ScPreviewTableInfo() :
81 nTab(0),
82 nCols(0),
83 nRows(0),
84 pColInfo(NULL),
85 pRowInfo(NULL)
89 ScPreviewTableInfo::~ScPreviewTableInfo()
91 delete[] pColInfo;
92 delete[] pRowInfo;
95 void ScPreviewTableInfo::SetTab( SCTAB nNewTab )
97 nTab = nNewTab;
100 void ScPreviewTableInfo::SetColInfo( SCCOL nCount, ScPreviewColRowInfo* pNewInfo )
102 delete[] pColInfo;
103 pColInfo = pNewInfo;
104 nCols = nCount;
107 void ScPreviewTableInfo::SetRowInfo( SCROW nCount, ScPreviewColRowInfo* pNewInfo )
109 delete[] pRowInfo;
110 pRowInfo = pNewInfo;
111 nRows = nCount;
114 void ScPreviewTableInfo::LimitToArea( const Rectangle& rPixelArea )
116 if ( pColInfo )
118 // cells completely left of the visible area
119 SCCOL nStart = 0;
120 while ( nStart < nCols && pColInfo[nStart].nPixelEnd < rPixelArea.Left() )
121 ++nStart;
123 // cells completely right of the visible area
124 SCCOL nEnd = nCols;
125 while ( nEnd > 0 && pColInfo[nEnd-1].nPixelStart > rPixelArea.Right() )
126 --nEnd;
128 if ( nStart > 0 || nEnd < nCols )
130 if ( nEnd > nStart )
132 SCCOL nNewCount = nEnd - nStart;
133 ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
134 for (SCCOL i=0; i<nNewCount; i++)
135 pNewInfo[i] = pColInfo[nStart + i];
136 SetColInfo( nNewCount, pNewInfo );
138 else
139 SetColInfo( 0, NULL ); // all invisible
143 if ( pRowInfo )
145 // cells completely above the visible area
146 SCROW nStart = 0;
147 while ( nStart < nRows && pRowInfo[nStart].nPixelEnd < rPixelArea.Top() )
148 ++nStart;
150 // cells completely below the visible area
151 SCROW nEnd = nRows;
152 while ( nEnd > 0 && pRowInfo[nEnd-1].nPixelStart > rPixelArea.Bottom() )
153 --nEnd;
155 if ( nStart > 0 || nEnd < nRows )
157 if ( nEnd > nStart )
159 SCROW nNewCount = nEnd - nStart;
160 ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
161 for (SCROW i=0; i<nNewCount; i++)
162 pNewInfo[i] = pRowInfo[nStart + i];
163 SetRowInfo( nNewCount, pNewInfo );
165 else
166 SetRowInfo( 0, NULL ); // all invisible
171 //------------------------------------------------------------------
173 ScPreviewLocationData::ScPreviewLocationData( ScDocument* pDocument, OutputDevice* pWin ) :
174 pWindow( pWin ),
175 pDoc( pDocument ),
176 nDrawRanges( 0 ),
177 nPrintTab( 0 )
181 ScPreviewLocationData::~ScPreviewLocationData()
183 Clear();
186 void ScPreviewLocationData::SetCellMapMode( const MapMode& rMapMode )
188 aCellMapMode = rMapMode;
191 void ScPreviewLocationData::SetPrintTab( SCTAB nNew )
193 nPrintTab = nNew;
196 void ScPreviewLocationData::Clear()
198 void* pEntry = aEntries.First();
199 while ( pEntry )
201 delete (ScPreviewLocationEntry*) pEntry;
202 pEntry = aEntries.Next();
204 aEntries.Clear();
206 nDrawRanges = 0;
209 void ScPreviewLocationData::AddCellRange( const Rectangle& rRect, const ScRange& rRange, BOOL bRepCol, BOOL bRepRow,
210 const MapMode& rDrawMap )
212 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
213 aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_CELLRANGE, aPixelRect, rRange, bRepCol, bRepRow ) );
215 DBG_ASSERT( nDrawRanges < SC_PREVIEW_MAXRANGES, "too many ranges" );
216 if ( nDrawRanges < SC_PREVIEW_MAXRANGES )
218 aDrawRectangle[nDrawRanges] = aPixelRect;
219 aDrawMapMode[nDrawRanges] = rDrawMap;
220 if (bRepCol)
221 if (bRepRow)
222 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_EDGE;
223 else
224 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPCOL;
225 else
226 if (bRepRow)
227 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPROW;
228 else
229 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_TAB;
230 ++nDrawRanges;
234 void ScPreviewLocationData::AddColHeaders( const Rectangle& rRect, SCCOL nStartCol, SCCOL nEndCol, BOOL bRepCol )
236 SCTAB nTab = 0; //! ?
237 ScRange aRange( nStartCol, 0, nTab, nEndCol, 0, nTab );
238 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
239 aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_COLHEADER, aPixelRect, aRange, bRepCol, FALSE ) );
242 void ScPreviewLocationData::AddRowHeaders( const Rectangle& rRect, SCROW nStartRow, SCROW nEndRow, BOOL bRepRow )
244 SCTAB nTab = 0; //! ?
245 ScRange aRange( 0, nStartRow, nTab, 0, nEndRow, nTab );
246 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
247 aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_ROWHEADER, aPixelRect, aRange, FALSE, bRepRow ) );
250 void ScPreviewLocationData::AddHeaderFooter( const Rectangle& rRect, BOOL bHeader, BOOL bLeft )
252 ScRange aRange; //! ?
253 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
255 ScPreviewLocationType eType = bHeader ?
256 ( bLeft ? SC_PLOC_LEFTHEADER : SC_PLOC_RIGHTHEADER ) :
257 ( bLeft ? SC_PLOC_LEFTFOOTER : SC_PLOC_RIGHTFOOTER );
258 aEntries.Insert( new ScPreviewLocationEntry( eType, aPixelRect, aRange, FALSE, FALSE ) );
261 void ScPreviewLocationData::AddNoteMark( const Rectangle& rRect, const ScAddress& rPos )
263 ScRange aRange( rPos );
264 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
265 aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_NOTEMARK, aPixelRect, aRange, FALSE, FALSE ) );
268 void ScPreviewLocationData::AddNoteText( const Rectangle& rRect, const ScAddress& rPos )
270 ScRange aRange( rPos );
271 Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
272 aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_NOTETEXT, aPixelRect, aRange, FALSE, FALSE ) );
275 //------------------------------------------------------------------
277 void ScPreviewLocationData::GetDrawRange( USHORT nPos, Rectangle& rPixelRect, MapMode& rMapMode, sal_uInt8& rRangeId ) const
279 DBG_ASSERT( nPos < nDrawRanges, "wrong position" );
280 if ( nPos < nDrawRanges )
282 rPixelRect = aDrawRectangle[nPos];
283 rMapMode = aDrawMapMode[nPos];
284 rRangeId = aDrawRangeId[nPos];
288 ScPreviewLocationEntry* lcl_GetEntryByAddress( const List& rEntries, const ScAddress& rPos, ScPreviewLocationType eType )
290 ULONG nCount = rEntries.Count();
291 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
293 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)rEntries.GetObject(nListPos);
294 if ( pEntry->eType == eType && pEntry->aCellRange.In( rPos ) )
295 return pEntry;
297 return NULL;
300 //UNUSED2008-05 ScAddress ScPreviewLocationData::GetCellFromRange( const Size& rOffsetPixel, const ScRange& rRange ) const
301 //UNUSED2008-05 {
302 //UNUSED2008-05 const double nScaleX = HMM_PER_TWIPS;
303 //UNUSED2008-05 const double nScaleY = HMM_PER_TWIPS;
304 //UNUSED2008-05
305 //UNUSED2008-05 Size aOffsetLogic = pWindow->PixelToLogic( rOffsetPixel, aCellMapMode );
306 //UNUSED2008-05 SCTAB nTab = rRange.aStart.Tab();
307 //UNUSED2008-05
308 //UNUSED2008-05 long nPosX = 0;
309 //UNUSED2008-05 SCCOL nCol = rRange.aStart.Col();
310 //UNUSED2008-05 SCCOL nEndCol = rRange.aEnd.Col();
311 //UNUSED2008-05 while ( nCol <= nEndCol && nPosX < aOffsetLogic.Width() )
312 //UNUSED2008-05 {
313 //UNUSED2008-05 USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
314 //UNUSED2008-05 if (nDocW)
315 //UNUSED2008-05 nPosX += (long) (nDocW * nScaleX);
316 //UNUSED2008-05 ++nCol;
317 //UNUSED2008-05 }
318 //UNUSED2008-05 if ( nCol > rRange.aStart.Col() )
319 //UNUSED2008-05 --nCol;
320 //UNUSED2008-05
321 //UNUSED2008-05 long nPosY = 0;
322 //UNUSED2008-05 ScCoupledCompressedArrayIterator< SCROW, BYTE, USHORT> aIter(
323 //UNUSED2008-05 pDoc->GetRowFlagsArray( nTab), rRange.aStart.Row(),
324 //UNUSED2008-05 rRange.aEnd.Row(), CR_HIDDEN, 0, pDoc->GetRowHeightArray( nTab));
325 //UNUSED2008-05 while ( aIter && nPosY < aOffsetLogic.Height() )
326 //UNUSED2008-05 {
327 //UNUSED2008-05 USHORT nDocH = *aIter;
328 //UNUSED2008-05 if (nDocH)
329 //UNUSED2008-05 nPosY += (long) (nDocH * nScaleY);
330 //UNUSED2008-05 ++aIter;
331 //UNUSED2008-05 }
332 //UNUSED2008-05 SCROW nRow = aIter.GetPos();
333 //UNUSED2008-05 if ( nRow > rRange.aStart.Row() )
334 //UNUSED2008-05 --nRow;
335 //UNUSED2008-05
336 //UNUSED2008-05 return ScAddress( nCol, nRow, nTab );
337 //UNUSED2008-05 }
339 Rectangle ScPreviewLocationData::GetOffsetPixel( const ScAddress& rCellPos, const ScRange& rRange ) const
341 const double nScaleX = HMM_PER_TWIPS;
342 const double nScaleY = HMM_PER_TWIPS;
343 SCTAB nTab = rRange.aStart.Tab();
345 long nPosX = 0;
346 SCCOL nEndCol = rCellPos.Col();
347 for (SCCOL nCol = rRange.aStart.Col(); nCol < nEndCol; nCol++)
349 USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
350 if (nDocW)
351 nPosX += (long) (nDocW * nScaleX);
353 long nSizeX = (long) ( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );
355 SCROW nEndRow = rCellPos.Row();
356 long nPosY = (long) pDoc->FastGetScaledRowHeight( rRange.aStart.Row(),
357 nEndRow, nTab, nScaleY);
358 long nSizeY = (long) ( pDoc->FastGetRowHeight( nEndRow, nTab ) * nScaleY );
360 Size aOffsetLogic( nPosX, nPosY );
361 Size aSizeLogic( nSizeX, nSizeY );
362 Size aOffsetPixel = pWindow->LogicToPixel( aOffsetLogic, aCellMapMode );
363 Size aSizePixel = pWindow->LogicToPixel( aSizeLogic, aCellMapMode );
365 return Rectangle( Point( aOffsetPixel.Width(), aOffsetPixel.Height() ), aSizePixel );
368 BOOL ScPreviewLocationData::GetCellPosition( const ScAddress& rCellPos, Rectangle& rCellRect ) const
370 ScPreviewLocationEntry* pEntry = lcl_GetEntryByAddress( aEntries, rCellPos, SC_PLOC_CELLRANGE );
371 if ( pEntry )
373 Rectangle aOffsetRect = GetOffsetPixel( rCellPos, pEntry->aCellRange );
374 rCellRect = Rectangle( aOffsetRect.Left() + pEntry->aPixelRect.Left(),
375 aOffsetRect.Top() + pEntry->aPixelRect.Top(),
376 aOffsetRect.Right() + pEntry->aPixelRect.Left(),
377 aOffsetRect.Bottom() + pEntry->aPixelRect.Top() );
378 return TRUE;
380 return FALSE;
383 BOOL ScPreviewLocationData::HasCellsInRange( const Rectangle& rVisiblePixel ) const
385 ULONG nCount = aEntries.Count();
386 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
388 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
389 ScPreviewLocationType eType = pEntry->eType;
390 if ( eType == SC_PLOC_CELLRANGE || eType == SC_PLOC_COLHEADER || eType == SC_PLOC_ROWHEADER )
391 if ( pEntry->aPixelRect.IsOver( rVisiblePixel ) )
392 return TRUE;
394 return FALSE;
397 BOOL ScPreviewLocationData::GetHeaderPosition( Rectangle& rRect ) const
399 ULONG nCount = aEntries.Count();
400 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
402 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
403 if ( pEntry->eType == SC_PLOC_LEFTHEADER || pEntry->eType == SC_PLOC_RIGHTHEADER )
405 rRect = pEntry->aPixelRect;
406 return TRUE;
409 return FALSE;
412 BOOL ScPreviewLocationData::GetFooterPosition( Rectangle& rRect ) const
414 ULONG nCount = aEntries.Count();
415 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
417 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
418 if ( pEntry->eType == SC_PLOC_LEFTFOOTER || pEntry->eType == SC_PLOC_RIGHTFOOTER )
420 rRect = pEntry->aPixelRect;
421 return TRUE;
424 return FALSE;
427 BOOL ScPreviewLocationData::IsHeaderLeft() const
429 ULONG nCount = aEntries.Count();
430 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
432 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
433 if ( pEntry->eType == SC_PLOC_LEFTHEADER )
434 return TRUE;
435 if ( pEntry->eType == SC_PLOC_RIGHTHEADER )
436 return FALSE;
438 return FALSE;
441 BOOL ScPreviewLocationData::IsFooterLeft() const
443 ULONG nCount = aEntries.Count();
444 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
446 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
447 if ( pEntry->eType == SC_PLOC_LEFTFOOTER )
448 return TRUE;
449 if ( pEntry->eType == SC_PLOC_RIGHTFOOTER )
450 return FALSE;
452 return FALSE;
455 long ScPreviewLocationData::GetNoteCountInRange( const Rectangle& rVisiblePixel, BOOL bNoteMarks ) const
457 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
459 ULONG nRet = 0;
460 ULONG nCount = aEntries.Count();
461 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
463 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
464 if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
465 ++nRet;
467 return nRet;
470 BOOL ScPreviewLocationData::GetNoteInRange( const Rectangle& rVisiblePixel, long nIndex, BOOL bNoteMarks,
471 ScAddress& rCellPos, Rectangle& rNoteRect ) const
473 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
475 ULONG nPos = 0;
476 ULONG nCount = aEntries.Count();
477 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
479 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
480 if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
482 if ( nPos == sal::static_int_cast<ULONG>(nIndex) )
484 rCellPos = pEntry->aCellRange.aStart;
485 rNoteRect = pEntry->aPixelRect;
486 return TRUE;
488 ++nPos;
491 return FALSE;
494 Rectangle ScPreviewLocationData::GetNoteInRangeOutputRect(const Rectangle& rVisiblePixel, BOOL bNoteMarks, const ScAddress& aCellPos) const
496 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
498 ULONG nPos = 0;
499 ULONG nCount = aEntries.Count();
500 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
502 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
503 if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
505 if ( aCellPos == pEntry->aCellRange.aStart )
506 return pEntry->aPixelRect;
507 ++nPos;
510 return Rectangle();
513 void ScPreviewLocationData::GetTableInfo( const Rectangle& rVisiblePixel, ScPreviewTableInfo& rInfo ) const
515 const double nScaleX = HMM_PER_TWIPS;
516 const double nScaleY = HMM_PER_TWIPS;
518 // from left to right:
519 BOOL bHasHeaderCol = FALSE;
520 BOOL bHasRepCols = FALSE;
521 BOOL bHasMainCols = FALSE;
522 SCCOL nRepeatColStart = 0;
523 SCCOL nRepeatColEnd = 0;
524 SCCOL nMainColStart = 0;
525 SCCOL nMainColEnd = 0;
527 // from top to bottom:
528 BOOL bHasHeaderRow = FALSE;
529 BOOL bHasRepRows = FALSE;
530 BOOL bHasMainRows = FALSE;
531 SCROW nRepeatRowStart = 0;
532 SCROW nRepeatRowEnd = 0;
533 SCROW nMainRowStart = 0;
534 SCROW nMainRowEnd = 0;
536 Rectangle aHeaderRect, aRepeatRect, aMainRect;
537 SCTAB nTab = 0;
539 ULONG nCount = aEntries.Count();
540 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
542 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
543 if ( pEntry->eType == SC_PLOC_CELLRANGE )
545 if ( pEntry->bRepeatCol )
547 bHasRepCols = TRUE;
548 nRepeatColStart = pEntry->aCellRange.aStart.Col();
549 nRepeatColEnd = pEntry->aCellRange.aEnd.Col();
550 aRepeatRect.Left() = pEntry->aPixelRect.Left();
551 aRepeatRect.Right() = pEntry->aPixelRect.Right();
553 else
555 bHasMainCols = TRUE;
556 nMainColStart = pEntry->aCellRange.aStart.Col();
557 nMainColEnd = pEntry->aCellRange.aEnd.Col();
558 aMainRect.Left() = pEntry->aPixelRect.Left();
559 aMainRect.Right() = pEntry->aPixelRect.Right();
561 if ( pEntry->bRepeatRow )
563 bHasRepRows = TRUE;
564 nRepeatRowStart = pEntry->aCellRange.aStart.Row();
565 nRepeatRowEnd = pEntry->aCellRange.aEnd.Row();
566 aRepeatRect.Top() = pEntry->aPixelRect.Top();
567 aRepeatRect.Bottom() = pEntry->aPixelRect.Bottom();
569 else
571 bHasMainRows = TRUE;
572 nMainRowStart = pEntry->aCellRange.aStart.Row();
573 nMainRowEnd = pEntry->aCellRange.aEnd.Row();
574 aMainRect.Top() = pEntry->aPixelRect.Top();
575 aMainRect.Bottom() = pEntry->aPixelRect.Bottom();
577 nTab = pEntry->aCellRange.aStart.Tab(); //! store separately?
579 else if ( pEntry->eType == SC_PLOC_ROWHEADER )
581 // row headers result in an additional column
582 bHasHeaderCol = TRUE;
583 aHeaderRect.Left() = pEntry->aPixelRect.Left();
584 aHeaderRect.Right() = pEntry->aPixelRect.Right();
586 else if ( pEntry->eType == SC_PLOC_COLHEADER )
588 // column headers result in an additional row
589 bHasHeaderRow = TRUE;
590 aHeaderRect.Top() = pEntry->aPixelRect.Top();
591 aHeaderRect.Bottom() = pEntry->aPixelRect.Bottom();
596 // get column info
599 SCCOL nColCount = 0;
600 SCCOL nCol;
601 if ( bHasHeaderCol )
602 ++nColCount;
603 if ( bHasRepCols )
604 for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
605 if (!pDoc->ColHidden(nCol, nTab))
606 ++nColCount;
607 if ( bHasMainCols )
608 for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
609 if (!pDoc->ColHidden(nCol, nTab))
610 ++nColCount;
612 if ( nColCount > 0 )
614 ScPreviewColRowInfo* pColInfo = new ScPreviewColRowInfo[ nColCount ];
615 SCCOL nColPos = 0;
617 if ( bHasHeaderCol )
619 pColInfo[nColPos].Set( TRUE, 0, aHeaderRect.Left(), aHeaderRect.Right() );
620 ++nColPos;
622 if ( bHasRepCols )
624 long nPosX = 0;
625 for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
626 if (!pDoc->ColHidden(nCol, nTab))
628 USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
629 long nNextX = nPosX + (long) (nDocW * nScaleX);
631 long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
632 long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
633 pColInfo[nColPos].Set( FALSE, nCol,
634 aRepeatRect.Left() + nPixelStart,
635 aRepeatRect.Left() + nPixelEnd );
637 nPosX = nNextX;
638 ++nColPos;
641 if ( bHasMainCols )
643 long nPosX = 0;
644 for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
645 if (!pDoc->ColHidden(nCol, nTab))
647 USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
648 long nNextX = nPosX + (long) (nDocW * nScaleX);
650 long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
651 long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
652 pColInfo[nColPos].Set( FALSE, nCol,
653 aMainRect.Left() + nPixelStart,
654 aMainRect.Left() + nPixelEnd );
656 nPosX = nNextX;
657 ++nColPos;
660 rInfo.SetColInfo( nColCount, pColInfo );
662 else
663 rInfo.SetColInfo( 0, NULL );
666 // get row info
669 SCROW nRowCount = 0;
670 if ( bHasHeaderRow )
671 ++nRowCount;
672 if ( bHasRepRows )
673 nRowCount += pDoc->CountVisibleRows(nRepeatRowStart, nRepeatRowEnd, nTab);
674 if ( bHasMainRows )
675 nRowCount += pDoc->CountVisibleRows(nMainRowStart, nMainRowEnd, nTab);
677 if ( nRowCount > 0 )
679 ScPreviewColRowInfo* pRowInfo = new ScPreviewColRowInfo[ nRowCount ];
680 SCROW nRowPos = 0;
682 if ( bHasHeaderRow )
684 pRowInfo[nRowPos].Set( TRUE, 0, aHeaderRect.Top(), aHeaderRect.Bottom() );
685 ++nRowPos;
687 if ( bHasRepRows )
689 long nPosY = 0;
690 for (SCROW nRow = nRepeatRowStart; nRow <= nRepeatRowEnd; ++nRow)
692 if (pDoc->RowHidden(nRow, nTab))
693 continue;
695 USHORT nDocH = pDoc->FastGetOriginalRowHeight( nRow, nTab );
696 long nNextY = nPosY + (long) (nDocH * nScaleY);
698 long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
699 long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
700 pRowInfo[nRowPos].Set( FALSE, nRow,
701 aRepeatRect.Top() + nPixelStart,
702 aRepeatRect.Top() + nPixelEnd );
704 nPosY = nNextY;
705 ++nRowPos;
708 if ( bHasMainRows )
710 long nPosY = 0;
711 for (SCROW nRow = nMainRowStart; nRow <= nMainRowEnd; ++nRow)
713 if (pDoc->RowHidden(nRow, nTab))
714 continue;
716 USHORT nDocH = pDoc->FastGetOriginalRowHeight( nRow, nTab );
717 long nNextY = nPosY + (long) (nDocH * nScaleY);
719 long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
720 long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
721 pRowInfo[nRowPos].Set( FALSE, nRow,
722 aMainRect.Top() + nPixelStart,
723 aMainRect.Top() + nPixelEnd );
725 nPosY = nNextY;
726 ++nRowPos;
729 rInfo.SetRowInfo( nRowCount, pRowInfo );
731 else
732 rInfo.SetRowInfo( 0, NULL );
735 // limit to visible area
738 rInfo.SetTab( nTab );
739 rInfo.LimitToArea( rVisiblePixel );
742 Rectangle ScPreviewLocationData::GetHeaderCellOutputRect(const Rectangle& rVisRect, const ScAddress& rCellPos, sal_Bool bColHeader) const
744 // first a stupid implementation
745 // NN says here should be done more
746 Rectangle aClipRect;
747 ScPreviewTableInfo aTableInfo;
748 GetTableInfo( rVisRect, aTableInfo );
750 if ( (rCellPos.Col() >= 0) &&
751 (rCellPos.Row() >= 0) && (rCellPos.Col() < aTableInfo.GetCols()) &&
752 (rCellPos.Row() < aTableInfo.GetRows()) )
754 SCCOL nCol(0);
755 SCROW nRow(0);
756 if (bColHeader)
757 nCol = rCellPos.Col();
758 else
759 nRow = rCellPos.Row();
760 const ScPreviewColRowInfo& rColInfo = aTableInfo.GetColInfo()[nCol];
761 const ScPreviewColRowInfo& rRowInfo = aTableInfo.GetRowInfo()[nRow];
763 if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
764 aClipRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
766 return aClipRect;
769 Rectangle ScPreviewLocationData::GetCellOutputRect(const ScAddress& rCellPos) const
771 // first a stupid implementation
772 // NN says here should be done more
773 Rectangle aRect;
774 GetCellPosition(rCellPos, aRect);
775 return aRect;
778 // GetMainCellRange is used for links in PDF export
780 BOOL ScPreviewLocationData::GetMainCellRange( ScRange& rRange, Rectangle& rPixRect ) const
782 ULONG nCount = aEntries.Count();
783 for (ULONG nListPos=0; nListPos<nCount; nListPos++)
785 ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
786 if ( pEntry->eType == SC_PLOC_CELLRANGE && !pEntry->bRepeatCol && !pEntry->bRepeatRow )
788 rRange = pEntry->aCellRange;
789 rPixRect = pEntry->aPixelRect;
790 return TRUE;
793 return FALSE; // not found