lok: calc: fix needed when position caching is disabled
[LibreOffice.git] / sc / source / ui / view / prevloc.cxx
blob5bc32e70242795a5cf31e3cba26fc738ad81473f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <prevloc.hxx>
21 #include <document.hxx>
23 #include <vcl/outdev.hxx>
25 #include <o3tl/make_unique.hxx>
27 enum ScPreviewLocationType
29 SC_PLOC_CELLRANGE,
30 SC_PLOC_COLHEADER,
31 SC_PLOC_ROWHEADER,
32 SC_PLOC_LEFTHEADER,
33 SC_PLOC_RIGHTHEADER,
34 SC_PLOC_LEFTFOOTER,
35 SC_PLOC_RIGHTFOOTER,
36 SC_PLOC_NOTEMARK,
37 SC_PLOC_NOTETEXT
40 struct ScPreviewLocationEntry
42 ScPreviewLocationType eType;
43 tools::Rectangle aPixelRect;
44 ScRange aCellRange;
45 bool bRepeatCol;
46 bool bRepeatRow;
48 ScPreviewLocationEntry( ScPreviewLocationType eNewType, const tools::Rectangle& rPixel, const ScRange& rRange,
49 bool bRepCol, bool bRepRow ) :
50 eType( eNewType ),
51 aPixelRect( rPixel ),
52 aCellRange( rRange ),
53 bRepeatCol( bRepCol ),
54 bRepeatRow( bRepRow )
59 ScPreviewTableInfo::ScPreviewTableInfo() :
60 nTab(0),
61 nCols(0),
62 nRows(0),
63 pColInfo(nullptr),
64 pRowInfo(nullptr)
68 ScPreviewTableInfo::~ScPreviewTableInfo()
72 void ScPreviewTableInfo::SetTab( SCTAB nNewTab )
74 nTab = nNewTab;
77 void ScPreviewTableInfo::SetColInfo( SCCOL nCount, ScPreviewColRowInfo* pNewInfo )
79 pColInfo.reset(pNewInfo);
80 nCols = nCount;
83 void ScPreviewTableInfo::SetRowInfo( SCROW nCount, ScPreviewColRowInfo* pNewInfo )
85 pRowInfo.reset(pNewInfo);
86 nRows = nCount;
89 void ScPreviewTableInfo::LimitToArea( const tools::Rectangle& rPixelArea )
91 if ( pColInfo )
93 // cells completely left of the visible area
94 SCCOL nStart = 0;
95 while ( nStart < nCols && pColInfo[nStart].nPixelEnd < rPixelArea.Left() )
96 ++nStart;
98 // cells completely right of the visible area
99 SCCOL nEnd = nCols;
100 while ( nEnd > 0 && pColInfo[nEnd-1].nPixelStart > rPixelArea.Right() )
101 --nEnd;
103 if ( nStart > 0 || nEnd < nCols )
105 if ( nEnd > nStart )
107 SCCOL nNewCount = nEnd - nStart;
108 ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
109 for (SCCOL i=0; i<nNewCount; i++)
110 pNewInfo[i] = pColInfo[nStart + i];
111 SetColInfo( nNewCount, pNewInfo );
113 else
114 SetColInfo( 0, nullptr ); // all invisible
118 if ( pRowInfo )
120 // cells completely above the visible area
121 SCROW nStart = 0;
122 while ( nStart < nRows && pRowInfo[nStart].nPixelEnd < rPixelArea.Top() )
123 ++nStart;
125 // cells completely below the visible area
126 SCROW nEnd = nRows;
127 while ( nEnd > 0 && pRowInfo[nEnd-1].nPixelStart > rPixelArea.Bottom() )
128 --nEnd;
130 if ( nStart > 0 || nEnd < nRows )
132 if ( nEnd > nStart )
134 SCROW nNewCount = nEnd - nStart;
135 ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
136 for (SCROW i=0; i<nNewCount; i++)
137 pNewInfo[i] = pRowInfo[nStart + i];
138 SetRowInfo( nNewCount, pNewInfo );
140 else
141 SetRowInfo( 0, nullptr ); // all invisible
146 ScPreviewLocationData::ScPreviewLocationData( ScDocument* pDocument, OutputDevice* pWin ) :
147 pWindow( pWin ),
148 pDoc( pDocument ),
149 nDrawRanges( 0 ),
150 nPrintTab( 0 )
154 ScPreviewLocationData::~ScPreviewLocationData()
156 Clear();
159 void ScPreviewLocationData::SetCellMapMode( const MapMode& rMapMode )
161 aCellMapMode = rMapMode;
164 void ScPreviewLocationData::SetPrintTab( SCTAB nNew )
166 nPrintTab = nNew;
169 void ScPreviewLocationData::Clear()
171 m_Entries.clear();
173 nDrawRanges = 0;
176 void ScPreviewLocationData::AddCellRange( const tools::Rectangle& rRect, const ScRange& rRange, bool bRepCol, bool bRepRow,
177 const MapMode& rDrawMap )
179 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
180 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(SC_PLOC_CELLRANGE, aPixelRect, rRange, bRepCol, bRepRow) );
182 OSL_ENSURE( nDrawRanges < SC_PREVIEW_MAXRANGES, "too many ranges" );
184 if ( nDrawRanges < SC_PREVIEW_MAXRANGES )
186 aDrawRectangle[nDrawRanges] = aPixelRect;
187 aDrawMapMode[nDrawRanges] = rDrawMap;
189 if (bRepCol)
191 if (bRepRow)
192 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_EDGE;
193 else
194 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPCOL;
196 else
198 if (bRepRow)
199 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPROW;
200 else
201 aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_TAB;
204 ++nDrawRanges;
208 void ScPreviewLocationData::AddColHeaders( const tools::Rectangle& rRect, SCCOL nStartCol, SCCOL nEndCol, bool bRepCol )
210 SCTAB nTab = 0; //! ?
211 ScRange aRange( nStartCol, 0, nTab, nEndCol, 0, nTab );
212 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
214 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(SC_PLOC_COLHEADER, aPixelRect, aRange, bRepCol, false) );
217 void ScPreviewLocationData::AddRowHeaders( const tools::Rectangle& rRect, SCROW nStartRow, SCROW nEndRow, bool bRepRow )
219 SCTAB nTab = 0; //! ?
220 ScRange aRange( 0, nStartRow, nTab, 0, nEndRow, nTab );
221 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
223 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(SC_PLOC_ROWHEADER, aPixelRect, aRange, false, bRepRow) );
226 void ScPreviewLocationData::AddHeaderFooter( const tools::Rectangle& rRect, bool bHeader, bool bLeft )
228 ScRange aRange; //! ?
229 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
231 ScPreviewLocationType eType = bHeader ?
232 ( bLeft ? SC_PLOC_LEFTHEADER : SC_PLOC_RIGHTHEADER ) :
233 ( bLeft ? SC_PLOC_LEFTFOOTER : SC_PLOC_RIGHTFOOTER );
235 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(eType, aPixelRect, aRange, false, false) );
238 void ScPreviewLocationData::AddNoteMark( const tools::Rectangle& rRect, const ScAddress& rPos )
240 ScRange aRange( rPos );
241 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
243 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(SC_PLOC_NOTEMARK, aPixelRect, aRange, false, false) );
246 void ScPreviewLocationData::AddNoteText( const tools::Rectangle& rRect, const ScAddress& rPos )
248 ScRange aRange( rPos );
249 tools::Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
251 m_Entries.push_front( o3tl::make_unique<ScPreviewLocationEntry>(SC_PLOC_NOTETEXT, aPixelRect, aRange, false, false) );
254 void ScPreviewLocationData::GetDrawRange( sal_uInt16 nPos, tools::Rectangle& rPixelRect, MapMode& rMapMode, sal_uInt8& rRangeId ) const
256 OSL_ENSURE( nPos < nDrawRanges, "wrong position" );
257 if ( nPos < nDrawRanges )
259 rPixelRect = aDrawRectangle[nPos];
260 rMapMode = aDrawMapMode[nPos];
261 rRangeId = aDrawRangeId[nPos];
265 static ScPreviewLocationEntry* lcl_GetEntryByAddress(
266 ScPreviewLocationData::Entries_t const& rEntries,
267 const ScAddress& rPos, ScPreviewLocationType const eType)
269 for (auto const& it : rEntries)
271 if ( it->eType == eType && it->aCellRange.In( rPos ) )
272 return it.get();
275 return nullptr;
278 tools::Rectangle ScPreviewLocationData::GetOffsetPixel( const ScAddress& rCellPos, const ScRange& rRange ) const
280 const double nScaleX = HMM_PER_TWIPS;
281 const double nScaleY = HMM_PER_TWIPS;
282 SCTAB nTab = rRange.aStart.Tab();
284 long nPosX = 0;
285 SCCOL nEndCol = rCellPos.Col();
286 for (SCCOL nCol = rRange.aStart.Col(); nCol < nEndCol; nCol++)
288 sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
289 if (nDocW)
290 nPosX += (long) (nDocW * nScaleX);
292 long nSizeX = (long) ( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );
294 SCROW nEndRow = rCellPos.Row();
295 long nPosY = (long) pDoc->GetScaledRowHeight( rRange.aStart.Row(),
296 nEndRow, nTab, nScaleY);
297 long nSizeY = (long) ( pDoc->GetRowHeight( nEndRow, nTab ) * nScaleY );
299 Size aOffsetLogic( nPosX, nPosY );
300 Size aSizeLogic( nSizeX, nSizeY );
301 Size aOffsetPixel = pWindow->LogicToPixel( aOffsetLogic, aCellMapMode );
302 Size aSizePixel = pWindow->LogicToPixel( aSizeLogic, aCellMapMode );
304 return tools::Rectangle( Point( aOffsetPixel.Width(), aOffsetPixel.Height() ), aSizePixel );
307 void ScPreviewLocationData::GetCellPosition( const ScAddress& rCellPos, tools::Rectangle& rCellRect ) const
309 ScPreviewLocationEntry* pEntry = lcl_GetEntryByAddress( m_Entries, rCellPos, SC_PLOC_CELLRANGE );
310 if ( pEntry )
312 tools::Rectangle aOffsetRect = GetOffsetPixel( rCellPos, pEntry->aCellRange );
313 rCellRect = tools::Rectangle( aOffsetRect.Left() + pEntry->aPixelRect.Left(),
314 aOffsetRect.Top() + pEntry->aPixelRect.Top(),
315 aOffsetRect.Right() + pEntry->aPixelRect.Left(),
316 aOffsetRect.Bottom() + pEntry->aPixelRect.Top() );
320 bool ScPreviewLocationData::HasCellsInRange( const tools::Rectangle& rVisiblePixel ) const
322 for (auto const& it : m_Entries)
324 if ( it->eType == SC_PLOC_CELLRANGE || it->eType == SC_PLOC_COLHEADER || it->eType == SC_PLOC_ROWHEADER )
325 if ( it->aPixelRect.IsOver( rVisiblePixel ) )
326 return true;
329 return false;
332 bool ScPreviewLocationData::GetHeaderPosition( tools::Rectangle& rRect ) const
334 for (auto const& it : m_Entries)
336 if ( it->eType == SC_PLOC_LEFTHEADER || it->eType == SC_PLOC_RIGHTHEADER )
338 rRect = it->aPixelRect;
339 return true;
343 return false;
346 bool ScPreviewLocationData::GetFooterPosition( tools::Rectangle& rRect ) const
348 for (auto const& it : m_Entries)
350 if ( it->eType == SC_PLOC_LEFTFOOTER || it->eType == SC_PLOC_RIGHTFOOTER )
352 rRect = it->aPixelRect;
353 return true;
357 return false;
360 bool ScPreviewLocationData::IsHeaderLeft() const
362 for (auto const& it : m_Entries)
364 if ( it->eType == SC_PLOC_LEFTHEADER )
365 return true;
367 if ( it->eType == SC_PLOC_RIGHTHEADER )
368 return false;
371 return false;
374 bool ScPreviewLocationData::IsFooterLeft() const
376 for (auto const& it : m_Entries)
378 if ( it->eType == SC_PLOC_LEFTFOOTER )
379 return true;
381 if ( it->eType == SC_PLOC_RIGHTFOOTER )
382 return false;
385 return false;
388 long ScPreviewLocationData::GetNoteCountInRange( const tools::Rectangle& rVisiblePixel, bool bNoteMarks ) const
390 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
392 sal_uLong nRet = 0;
393 for (auto const& it : m_Entries)
395 if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
396 ++nRet;
399 return nRet;
402 bool ScPreviewLocationData::GetNoteInRange( const tools::Rectangle& rVisiblePixel, long nIndex, bool bNoteMarks,
403 ScAddress& rCellPos, tools::Rectangle& rNoteRect ) const
405 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
407 sal_uLong nPos = 0;
408 for (auto const& it : m_Entries)
410 if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
412 if ( nPos == sal::static_int_cast<sal_uLong>(nIndex) )
414 rCellPos = it->aCellRange.aStart;
415 rNoteRect = it->aPixelRect;
416 return true;
418 ++nPos;
422 return false;
425 tools::Rectangle ScPreviewLocationData::GetNoteInRangeOutputRect(const tools::Rectangle& rVisiblePixel, bool bNoteMarks, const ScAddress& aCellPos) const
427 ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
429 sal_uLong nPos = 0;
430 for (auto const& it : m_Entries)
432 if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
434 if ( aCellPos == it->aCellRange.aStart )
435 return it->aPixelRect;
436 ++nPos;
440 return tools::Rectangle();
443 void ScPreviewLocationData::GetTableInfo( const tools::Rectangle& rVisiblePixel, ScPreviewTableInfo& rInfo ) const
445 const double nScaleX = HMM_PER_TWIPS;
446 const double nScaleY = HMM_PER_TWIPS;
448 // from left to right:
449 bool bHasHeaderCol = false;
450 bool bHasRepCols = false;
451 bool bHasMainCols = false;
452 SCCOL nRepeatColStart = 0;
453 SCCOL nRepeatColEnd = 0;
454 SCCOL nMainColStart = 0;
455 SCCOL nMainColEnd = 0;
457 // from top to bottom:
458 bool bHasHeaderRow = false;
459 bool bHasRepRows = false;
460 bool bHasMainRows = false;
461 SCROW nRepeatRowStart = 0;
462 SCROW nRepeatRowEnd = 0;
463 SCROW nMainRowStart = 0;
464 SCROW nMainRowEnd = 0;
466 tools::Rectangle aHeaderRect, aRepeatRect, aMainRect;
467 SCTAB nTab = 0;
469 for (auto const& it : m_Entries)
471 if ( it->eType == SC_PLOC_CELLRANGE )
473 if ( it->bRepeatCol )
475 bHasRepCols = true;
476 nRepeatColStart = it->aCellRange.aStart.Col();
477 nRepeatColEnd = it->aCellRange.aEnd.Col();
478 aRepeatRect.Left() = it->aPixelRect.Left();
479 aRepeatRect.Right() = it->aPixelRect.Right();
481 else
483 bHasMainCols = true;
484 nMainColStart = it->aCellRange.aStart.Col();
485 nMainColEnd = it->aCellRange.aEnd.Col();
486 aMainRect.Left() = it->aPixelRect.Left();
487 aMainRect.Right() = it->aPixelRect.Right();
489 if ( it->bRepeatRow )
491 bHasRepRows = true;
492 nRepeatRowStart = it->aCellRange.aStart.Row();
493 nRepeatRowEnd = it->aCellRange.aEnd.Row();
494 aRepeatRect.Top() = it->aPixelRect.Top();
495 aRepeatRect.Bottom() = it->aPixelRect.Bottom();
497 else
499 bHasMainRows = true;
500 nMainRowStart = it->aCellRange.aStart.Row();
501 nMainRowEnd = it->aCellRange.aEnd.Row();
502 aMainRect.Top() = it->aPixelRect.Top();
503 aMainRect.Bottom() = it->aPixelRect.Bottom();
505 nTab = it->aCellRange.aStart.Tab(); //! store separately?
507 else if ( it->eType == SC_PLOC_ROWHEADER )
509 // row headers result in an additional column
510 bHasHeaderCol = true;
511 aHeaderRect.Left() = it->aPixelRect.Left();
512 aHeaderRect.Right() = it->aPixelRect.Right();
514 else if ( it->eType == SC_PLOC_COLHEADER )
516 // column headers result in an additional row
517 bHasHeaderRow = true;
518 aHeaderRect.Top() = it->aPixelRect.Top();
519 aHeaderRect.Bottom() = it->aPixelRect.Bottom();
523 // get column info
525 SCCOL nColCount = 0;
526 SCCOL nCol;
527 if ( bHasHeaderCol )
528 ++nColCount;
529 if ( bHasRepCols )
530 for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
531 if (!pDoc->ColHidden(nCol, nTab))
532 ++nColCount;
533 if ( bHasMainCols )
534 for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
535 if (!pDoc->ColHidden(nCol, nTab))
536 ++nColCount;
538 if ( nColCount > 0 )
540 ScPreviewColRowInfo* pColInfo = new ScPreviewColRowInfo[ nColCount ];
541 SCCOL nColPos = 0;
543 if ( bHasHeaderCol )
545 pColInfo[nColPos].Set( true, 0, aHeaderRect.Left(), aHeaderRect.Right() );
546 ++nColPos;
548 if ( bHasRepCols )
550 long nPosX = 0;
551 for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
552 if (!pDoc->ColHidden(nCol, nTab))
554 sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
555 long nNextX = nPosX + (long) (nDocW * nScaleX);
557 long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
558 long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
559 pColInfo[nColPos].Set( false, nCol,
560 aRepeatRect.Left() + nPixelStart,
561 aRepeatRect.Left() + nPixelEnd );
563 nPosX = nNextX;
564 ++nColPos;
567 if ( bHasMainCols )
569 long nPosX = 0;
570 for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
571 if (!pDoc->ColHidden(nCol, nTab))
573 sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
574 long nNextX = nPosX + (long) (nDocW * nScaleX);
576 long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
577 long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
578 pColInfo[nColPos].Set( false, nCol,
579 aMainRect.Left() + nPixelStart,
580 aMainRect.Left() + nPixelEnd );
582 nPosX = nNextX;
583 ++nColPos;
586 rInfo.SetColInfo( nColCount, pColInfo );
588 else
589 rInfo.SetColInfo( 0, nullptr );
591 // get row info
593 SCROW nRowCount = 0;
594 if ( bHasHeaderRow )
595 ++nRowCount;
596 if ( bHasRepRows )
597 nRowCount += pDoc->CountVisibleRows(nRepeatRowStart, nRepeatRowEnd, nTab);
598 if ( bHasMainRows )
599 nRowCount += pDoc->CountVisibleRows(nMainRowStart, nMainRowEnd, nTab);
601 if ( nRowCount > 0 )
603 ScPreviewColRowInfo* pRowInfo = new ScPreviewColRowInfo[ nRowCount ];
604 SCROW nRowPos = 0;
606 if ( bHasHeaderRow )
608 pRowInfo[nRowPos].Set( true, 0, aHeaderRect.Top(), aHeaderRect.Bottom() );
609 ++nRowPos;
611 if ( bHasRepRows )
613 long nPosY = 0;
614 for (SCROW nRow = nRepeatRowStart; nRow <= nRepeatRowEnd; ++nRow)
616 if (pDoc->RowHidden(nRow, nTab))
617 continue;
619 sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
620 long nNextY = nPosY + (long) (nDocH * nScaleY);
622 long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
623 long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
624 pRowInfo[nRowPos].Set( false, nRow,
625 aRepeatRect.Top() + nPixelStart,
626 aRepeatRect.Top() + nPixelEnd );
628 nPosY = nNextY;
629 ++nRowPos;
632 if ( bHasMainRows )
634 long nPosY = 0;
635 for (SCROW nRow = nMainRowStart; nRow <= nMainRowEnd; ++nRow)
637 if (pDoc->RowHidden(nRow, nTab))
638 continue;
640 sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
641 long nNextY = nPosY + (long) (nDocH * nScaleY);
643 long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
644 long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
645 pRowInfo[nRowPos].Set( false, nRow,
646 aMainRect.Top() + nPixelStart,
647 aMainRect.Top() + nPixelEnd );
649 nPosY = nNextY;
650 ++nRowPos;
653 rInfo.SetRowInfo( nRowCount, pRowInfo );
655 else
656 rInfo.SetRowInfo( 0, nullptr );
658 // limit to visible area
660 rInfo.SetTab( nTab );
661 rInfo.LimitToArea( rVisiblePixel );
664 tools::Rectangle ScPreviewLocationData::GetHeaderCellOutputRect(const tools::Rectangle& rVisRect, const ScAddress& rCellPos, bool bColHeader) const
666 // first a stupid implementation
667 // NN says here should be done more
668 tools::Rectangle aClipRect;
669 ScPreviewTableInfo aTableInfo;
670 GetTableInfo( rVisRect, aTableInfo );
672 if ( (rCellPos.Col() >= 0) &&
673 (rCellPos.Row() >= 0) && (rCellPos.Col() < aTableInfo.GetCols()) &&
674 (rCellPos.Row() < aTableInfo.GetRows()) )
676 SCCOL nCol(0);
677 SCROW nRow(0);
678 if (bColHeader)
679 nCol = rCellPos.Col();
680 else
681 nRow = rCellPos.Row();
682 const ScPreviewColRowInfo& rColInfo = aTableInfo.GetColInfo()[nCol];
683 const ScPreviewColRowInfo& rRowInfo = aTableInfo.GetRowInfo()[nRow];
685 if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
686 aClipRect = tools::Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
688 return aClipRect;
691 tools::Rectangle ScPreviewLocationData::GetCellOutputRect(const ScAddress& rCellPos) const
693 // first a stupid implementation
694 // NN says here should be done more
695 tools::Rectangle aRect;
696 GetCellPosition(rCellPos, aRect);
697 return aRect;
700 // GetMainCellRange is used for links in PDF export
702 bool ScPreviewLocationData::GetMainCellRange( ScRange& rRange, tools::Rectangle& rPixRect ) const
704 for (auto const& it : m_Entries)
706 if ( it->eType == SC_PLOC_CELLRANGE && !it->bRepeatCol && !it->bRepeatRow )
708 rRange = it->aCellRange;
709 rPixRect = it->aPixelRect;
710 return true;
714 return false;
717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */