Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <vcl/outdev.hxx>
22 :
23 : #include "prevloc.hxx"
24 : #include "document.hxx"
25 :
26 : enum ScPreviewLocationType
27 : {
28 : SC_PLOC_CELLRANGE,
29 : SC_PLOC_COLHEADER,
30 : SC_PLOC_ROWHEADER,
31 : SC_PLOC_LEFTHEADER,
32 : SC_PLOC_RIGHTHEADER,
33 : SC_PLOC_LEFTFOOTER,
34 : SC_PLOC_RIGHTFOOTER,
35 : SC_PLOC_NOTEMARK,
36 : SC_PLOC_NOTETEXT
37 : };
38 :
39 : struct ScPreviewLocationEntry
40 : {
41 : ScPreviewLocationType eType;
42 : Rectangle aPixelRect;
43 : ScRange aCellRange;
44 : sal_Bool bRepeatCol;
45 : sal_Bool bRepeatRow;
46 :
47 73 : ScPreviewLocationEntry( ScPreviewLocationType eNewType, const Rectangle& rPixel, const ScRange& rRange,
48 : sal_Bool bRepCol, sal_Bool bRepRow ) :
49 : eType( eNewType ),
50 : aPixelRect( rPixel ),
51 : aCellRange( rRange ),
52 : bRepeatCol( bRepCol ),
53 73 : bRepeatRow( bRepRow )
54 : {
55 73 : }
56 : };
57 :
58 40 : ScPreviewTableInfo::ScPreviewTableInfo() :
59 : nTab(0),
60 : nCols(0),
61 : nRows(0),
62 : pColInfo(NULL),
63 40 : pRowInfo(NULL)
64 : {
65 40 : }
66 :
67 40 : ScPreviewTableInfo::~ScPreviewTableInfo()
68 : {
69 40 : delete[] pColInfo;
70 40 : delete[] pRowInfo;
71 40 : }
72 :
73 40 : void ScPreviewTableInfo::SetTab( SCTAB nNewTab )
74 : {
75 40 : nTab = nNewTab;
76 40 : }
77 :
78 40 : void ScPreviewTableInfo::SetColInfo( SCCOL nCount, ScPreviewColRowInfo* pNewInfo )
79 : {
80 40 : delete[] pColInfo;
81 40 : pColInfo = pNewInfo;
82 40 : nCols = nCount;
83 40 : }
84 :
85 40 : void ScPreviewTableInfo::SetRowInfo( SCROW nCount, ScPreviewColRowInfo* pNewInfo )
86 : {
87 40 : delete[] pRowInfo;
88 40 : pRowInfo = pNewInfo;
89 40 : nRows = nCount;
90 40 : }
91 :
92 40 : void ScPreviewTableInfo::LimitToArea( const Rectangle& rPixelArea )
93 : {
94 40 : if ( pColInfo )
95 : {
96 : // cells completely left of the visible area
97 40 : SCCOL nStart = 0;
98 80 : while ( nStart < nCols && pColInfo[nStart].nPixelEnd < rPixelArea.Left() )
99 0 : ++nStart;
100 :
101 : // cells completely right of the visible area
102 40 : SCCOL nEnd = nCols;
103 80 : while ( nEnd > 0 && pColInfo[nEnd-1].nPixelStart > rPixelArea.Right() )
104 0 : --nEnd;
105 :
106 40 : if ( nStart > 0 || nEnd < nCols )
107 : {
108 0 : if ( nEnd > nStart )
109 : {
110 0 : SCCOL nNewCount = nEnd - nStart;
111 0 : ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
112 0 : for (SCCOL i=0; i<nNewCount; i++)
113 0 : pNewInfo[i] = pColInfo[nStart + i];
114 0 : SetColInfo( nNewCount, pNewInfo );
115 : }
116 : else
117 0 : SetColInfo( 0, NULL ); // all invisible
118 : }
119 : }
120 :
121 40 : if ( pRowInfo )
122 : {
123 : // cells completely above the visible area
124 40 : SCROW nStart = 0;
125 80 : while ( nStart < nRows && pRowInfo[nStart].nPixelEnd < rPixelArea.Top() )
126 0 : ++nStart;
127 :
128 : // cells completely below the visible area
129 40 : SCROW nEnd = nRows;
130 80 : while ( nEnd > 0 && pRowInfo[nEnd-1].nPixelStart > rPixelArea.Bottom() )
131 0 : --nEnd;
132 :
133 40 : if ( nStart > 0 || nEnd < nRows )
134 : {
135 0 : if ( nEnd > nStart )
136 : {
137 0 : SCROW nNewCount = nEnd - nStart;
138 0 : ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
139 0 : for (SCROW i=0; i<nNewCount; i++)
140 0 : pNewInfo[i] = pRowInfo[nStart + i];
141 0 : SetRowInfo( nNewCount, pNewInfo );
142 : }
143 : else
144 0 : SetRowInfo( 0, NULL ); // all invisible
145 : }
146 : }
147 40 : }
148 :
149 8 : ScPreviewLocationData::ScPreviewLocationData( ScDocument* pDocument, OutputDevice* pWin ) :
150 : pWindow( pWin ),
151 : pDoc( pDocument ),
152 : nDrawRanges( 0 ),
153 8 : nPrintTab( 0 )
154 : {
155 8 : }
156 :
157 16 : ScPreviewLocationData::~ScPreviewLocationData()
158 : {
159 8 : Clear();
160 8 : }
161 :
162 23 : void ScPreviewLocationData::SetCellMapMode( const MapMode& rMapMode )
163 : {
164 23 : aCellMapMode = rMapMode;
165 23 : }
166 :
167 23 : void ScPreviewLocationData::SetPrintTab( SCTAB nNew )
168 : {
169 23 : nPrintTab = nNew;
170 23 : }
171 :
172 31 : void ScPreviewLocationData::Clear()
173 : {
174 31 : aEntries.clear();
175 :
176 31 : nDrawRanges = 0;
177 31 : }
178 :
179 23 : void ScPreviewLocationData::AddCellRange( const Rectangle& rRect, const ScRange& rRange, sal_Bool bRepCol, sal_Bool bRepRow,
180 : const MapMode& rDrawMap )
181 : {
182 23 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
183 23 : aEntries.push_front( new ScPreviewLocationEntry( SC_PLOC_CELLRANGE, aPixelRect, rRange, bRepCol, bRepRow ) );
184 :
185 : OSL_ENSURE( nDrawRanges < SC_PREVIEW_MAXRANGES, "too many ranges" );
186 :
187 23 : if ( nDrawRanges < SC_PREVIEW_MAXRANGES )
188 : {
189 23 : aDrawRectangle[nDrawRanges] = aPixelRect;
190 23 : aDrawMapMode[nDrawRanges] = rDrawMap;
191 :
192 23 : if (bRepCol)
193 : {
194 0 : if (bRepRow)
195 0 : aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_EDGE;
196 : else
197 0 : aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPCOL;
198 : }
199 : else
200 : {
201 23 : if (bRepRow)
202 0 : aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPROW;
203 : else
204 23 : aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_TAB;
205 : }
206 :
207 23 : ++nDrawRanges;
208 : }
209 23 : }
210 :
211 2 : void ScPreviewLocationData::AddColHeaders( const Rectangle& rRect, SCCOL nStartCol, SCCOL nEndCol, sal_Bool bRepCol )
212 : {
213 2 : SCTAB nTab = 0; //! ?
214 2 : ScRange aRange( nStartCol, 0, nTab, nEndCol, 0, nTab );
215 2 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
216 :
217 2 : aEntries.push_front( new ScPreviewLocationEntry( SC_PLOC_COLHEADER, aPixelRect, aRange, bRepCol, false ) );
218 2 : }
219 :
220 2 : void ScPreviewLocationData::AddRowHeaders( const Rectangle& rRect, SCROW nStartRow, SCROW nEndRow, sal_Bool bRepRow )
221 : {
222 2 : SCTAB nTab = 0; //! ?
223 2 : ScRange aRange( 0, nStartRow, nTab, 0, nEndRow, nTab );
224 2 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
225 :
226 2 : aEntries.push_front( new ScPreviewLocationEntry( SC_PLOC_ROWHEADER, aPixelRect, aRange, false, bRepRow ) );
227 2 : }
228 :
229 46 : void ScPreviewLocationData::AddHeaderFooter( const Rectangle& rRect, sal_Bool bHeader, sal_Bool bLeft )
230 : {
231 46 : ScRange aRange; //! ?
232 46 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
233 :
234 : ScPreviewLocationType eType = bHeader ?
235 : ( bLeft ? SC_PLOC_LEFTHEADER : SC_PLOC_RIGHTHEADER ) :
236 46 : ( bLeft ? SC_PLOC_LEFTFOOTER : SC_PLOC_RIGHTFOOTER );
237 :
238 46 : aEntries.push_front( new ScPreviewLocationEntry( eType, aPixelRect, aRange, false, false ) );
239 46 : }
240 :
241 0 : void ScPreviewLocationData::AddNoteMark( const Rectangle& rRect, const ScAddress& rPos )
242 : {
243 0 : ScRange aRange( rPos );
244 0 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
245 :
246 0 : aEntries.push_front( new ScPreviewLocationEntry( SC_PLOC_NOTEMARK, aPixelRect, aRange, false, false ) );
247 0 : }
248 :
249 0 : void ScPreviewLocationData::AddNoteText( const Rectangle& rRect, const ScAddress& rPos )
250 : {
251 0 : ScRange aRange( rPos );
252 0 : Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
253 :
254 0 : aEntries.push_front( new ScPreviewLocationEntry( SC_PLOC_NOTETEXT, aPixelRect, aRange, false, false ) );
255 0 : }
256 :
257 18 : void ScPreviewLocationData::GetDrawRange( sal_uInt16 nPos, Rectangle& rPixelRect, MapMode& rMapMode, sal_uInt8& rRangeId ) const
258 : {
259 : OSL_ENSURE( nPos < nDrawRanges, "wrong position" );
260 18 : if ( nPos < nDrawRanges )
261 : {
262 18 : rPixelRect = aDrawRectangle[nPos];
263 18 : rMapMode = aDrawMapMode[nPos];
264 18 : rRangeId = aDrawRangeId[nPos];
265 : }
266 18 : }
267 :
268 31 : static ScPreviewLocationEntry* lcl_GetEntryByAddress( const boost::ptr_list<ScPreviewLocationEntry> &rEntries,
269 : const ScAddress& rPos, ScPreviewLocationType eType )
270 : {
271 31 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
272 43 : for (it = rEntries.begin(); it != rEntries.end(); ++it)
273 : {
274 43 : if ( it->eType == eType && it->aCellRange.In( rPos ) )
275 31 : return const_cast<ScPreviewLocationEntry*>(&(*it));
276 : }
277 :
278 0 : return NULL;
279 : }
280 :
281 :
282 31 : Rectangle ScPreviewLocationData::GetOffsetPixel( const ScAddress& rCellPos, const ScRange& rRange ) const
283 : {
284 31 : const double nScaleX = HMM_PER_TWIPS;
285 31 : const double nScaleY = HMM_PER_TWIPS;
286 31 : SCTAB nTab = rRange.aStart.Tab();
287 :
288 31 : long nPosX = 0;
289 31 : SCCOL nEndCol = rCellPos.Col();
290 31 : for (SCCOL nCol = rRange.aStart.Col(); nCol < nEndCol; nCol++)
291 : {
292 0 : sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
293 0 : if (nDocW)
294 0 : nPosX += (long) (nDocW * nScaleX);
295 : }
296 31 : long nSizeX = (long) ( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );
297 :
298 31 : SCROW nEndRow = rCellPos.Row();
299 : long nPosY = (long) pDoc->GetScaledRowHeight( rRange.aStart.Row(),
300 31 : nEndRow, nTab, nScaleY);
301 31 : long nSizeY = (long) ( pDoc->GetRowHeight( nEndRow, nTab ) * nScaleY );
302 :
303 31 : Size aOffsetLogic( nPosX, nPosY );
304 31 : Size aSizeLogic( nSizeX, nSizeY );
305 31 : Size aOffsetPixel = pWindow->LogicToPixel( aOffsetLogic, aCellMapMode );
306 31 : Size aSizePixel = pWindow->LogicToPixel( aSizeLogic, aCellMapMode );
307 :
308 31 : return Rectangle( Point( aOffsetPixel.Width(), aOffsetPixel.Height() ), aSizePixel );
309 : }
310 :
311 31 : sal_Bool ScPreviewLocationData::GetCellPosition( const ScAddress& rCellPos, Rectangle& rCellRect ) const
312 : {
313 31 : ScPreviewLocationEntry* pEntry = lcl_GetEntryByAddress( aEntries, rCellPos, SC_PLOC_CELLRANGE );
314 31 : if ( pEntry )
315 : {
316 31 : Rectangle aOffsetRect = GetOffsetPixel( rCellPos, pEntry->aCellRange );
317 62 : rCellRect = Rectangle( aOffsetRect.Left() + pEntry->aPixelRect.Left(),
318 62 : aOffsetRect.Top() + pEntry->aPixelRect.Top(),
319 62 : aOffsetRect.Right() + pEntry->aPixelRect.Left(),
320 217 : aOffsetRect.Bottom() + pEntry->aPixelRect.Top() );
321 31 : return sal_True;
322 : }
323 0 : return false;
324 : }
325 :
326 92 : sal_Bool ScPreviewLocationData::HasCellsInRange( const Rectangle& rVisiblePixel ) const
327 : {
328 92 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
329 92 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
330 : {
331 92 : if ( it->eType == SC_PLOC_CELLRANGE || it->eType == SC_PLOC_COLHEADER || it->eType == SC_PLOC_ROWHEADER )
332 92 : if ( it->aPixelRect.IsOver( rVisiblePixel ) )
333 92 : return true;
334 : }
335 :
336 0 : return false;
337 : }
338 :
339 723 : sal_Bool ScPreviewLocationData::GetHeaderPosition( Rectangle& rRect ) const
340 : {
341 723 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
342 2249 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
343 : {
344 2249 : if ( it->eType == SC_PLOC_LEFTHEADER || it->eType == SC_PLOC_RIGHTHEADER )
345 : {
346 723 : rRect = it->aPixelRect;
347 723 : return true;
348 : }
349 : }
350 :
351 0 : return false;
352 : }
353 :
354 112 : sal_Bool ScPreviewLocationData::GetFooterPosition( Rectangle& rRect ) const
355 : {
356 112 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
357 296 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
358 : {
359 296 : if ( it->eType == SC_PLOC_LEFTFOOTER || it->eType == SC_PLOC_RIGHTFOOTER )
360 : {
361 112 : rRect = it->aPixelRect;
362 112 : return true;
363 : }
364 : }
365 :
366 0 : return false;
367 : }
368 :
369 17 : sal_Bool ScPreviewLocationData::IsHeaderLeft() const
370 : {
371 17 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
372 55 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
373 : {
374 55 : if ( it->eType == SC_PLOC_LEFTHEADER )
375 0 : return true;
376 :
377 55 : if ( it->eType == SC_PLOC_RIGHTHEADER )
378 17 : return false;
379 : }
380 :
381 0 : return false;
382 : }
383 :
384 3 : sal_Bool ScPreviewLocationData::IsFooterLeft() const
385 : {
386 3 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
387 10 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
388 : {
389 10 : if ( it->eType == SC_PLOC_LEFTFOOTER )
390 0 : return true;
391 :
392 10 : if ( it->eType == SC_PLOC_RIGHTFOOTER )
393 3 : return false;
394 : }
395 :
396 0 : return false;
397 : }
398 :
399 46 : long ScPreviewLocationData::GetNoteCountInRange( const Rectangle& rVisiblePixel, sal_Bool bNoteMarks ) const
400 : {
401 46 : ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
402 :
403 46 : sal_uLong nRet = 0;
404 46 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
405 192 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
406 : {
407 146 : if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
408 0 : ++nRet;
409 : }
410 :
411 46 : return nRet;
412 : }
413 :
414 0 : sal_Bool ScPreviewLocationData::GetNoteInRange( const Rectangle& rVisiblePixel, long nIndex, sal_Bool bNoteMarks,
415 : ScAddress& rCellPos, Rectangle& rNoteRect ) const
416 : {
417 0 : ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
418 :
419 0 : sal_uLong nPos = 0;
420 0 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
421 0 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
422 : {
423 0 : if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
424 : {
425 0 : if ( nPos == sal::static_int_cast<sal_uLong>(nIndex) )
426 : {
427 0 : rCellPos = it->aCellRange.aStart;
428 0 : rNoteRect = it->aPixelRect;
429 0 : return true;
430 : }
431 0 : ++nPos;
432 : }
433 : }
434 :
435 0 : return false;
436 : }
437 :
438 0 : Rectangle ScPreviewLocationData::GetNoteInRangeOutputRect(const Rectangle& rVisiblePixel, sal_Bool bNoteMarks, const ScAddress& aCellPos) const
439 : {
440 0 : ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
441 :
442 0 : sal_uLong nPos = 0;
443 0 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
444 0 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
445 : {
446 0 : if ( it->eType == eType && it->aPixelRect.IsOver( rVisiblePixel ) )
447 : {
448 0 : if ( aCellPos == it->aCellRange.aStart )
449 0 : return it->aPixelRect;
450 0 : ++nPos;
451 : }
452 : }
453 :
454 0 : return Rectangle();
455 : }
456 :
457 40 : void ScPreviewLocationData::GetTableInfo( const Rectangle& rVisiblePixel, ScPreviewTableInfo& rInfo ) const
458 : {
459 40 : const double nScaleX = HMM_PER_TWIPS;
460 40 : const double nScaleY = HMM_PER_TWIPS;
461 :
462 : // from left to right:
463 40 : sal_Bool bHasHeaderCol = false;
464 40 : sal_Bool bHasRepCols = false;
465 40 : sal_Bool bHasMainCols = false;
466 40 : SCCOL nRepeatColStart = 0;
467 40 : SCCOL nRepeatColEnd = 0;
468 40 : SCCOL nMainColStart = 0;
469 40 : SCCOL nMainColEnd = 0;
470 :
471 : // from top to bottom:
472 40 : sal_Bool bHasHeaderRow = false;
473 40 : sal_Bool bHasRepRows = false;
474 40 : sal_Bool bHasMainRows = false;
475 40 : SCROW nRepeatRowStart = 0;
476 40 : SCROW nRepeatRowEnd = 0;
477 40 : SCROW nMainRowStart = 0;
478 40 : SCROW nMainRowEnd = 0;
479 :
480 40 : Rectangle aHeaderRect, aRepeatRect, aMainRect;
481 40 : SCTAB nTab = 0;
482 :
483 40 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
484 210 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
485 : {
486 170 : if ( it->eType == SC_PLOC_CELLRANGE )
487 : {
488 40 : if ( it->bRepeatCol )
489 : {
490 0 : bHasRepCols = true;
491 0 : nRepeatColStart = it->aCellRange.aStart.Col();
492 0 : nRepeatColEnd = it->aCellRange.aEnd.Col();
493 0 : aRepeatRect.Left() = it->aPixelRect.Left();
494 0 : aRepeatRect.Right() = it->aPixelRect.Right();
495 : }
496 : else
497 : {
498 40 : bHasMainCols = true;
499 40 : nMainColStart = it->aCellRange.aStart.Col();
500 40 : nMainColEnd = it->aCellRange.aEnd.Col();
501 40 : aMainRect.Left() = it->aPixelRect.Left();
502 40 : aMainRect.Right() = it->aPixelRect.Right();
503 : }
504 40 : if ( it->bRepeatRow )
505 : {
506 0 : bHasRepRows = true;
507 0 : nRepeatRowStart = it->aCellRange.aStart.Row();
508 0 : nRepeatRowEnd = it->aCellRange.aEnd.Row();
509 0 : aRepeatRect.Top() = it->aPixelRect.Top();
510 0 : aRepeatRect.Bottom() = it->aPixelRect.Bottom();
511 : }
512 : else
513 : {
514 40 : bHasMainRows = true;
515 40 : nMainRowStart = it->aCellRange.aStart.Row();
516 40 : nMainRowEnd = it->aCellRange.aEnd.Row();
517 40 : aMainRect.Top() = it->aPixelRect.Top();
518 40 : aMainRect.Bottom() = it->aPixelRect.Bottom();
519 : }
520 40 : nTab = it->aCellRange.aStart.Tab(); //! store separately?
521 : }
522 130 : else if ( it->eType == SC_PLOC_ROWHEADER )
523 : {
524 : // row headers result in an additional column
525 25 : bHasHeaderCol = true;
526 25 : aHeaderRect.Left() = it->aPixelRect.Left();
527 25 : aHeaderRect.Right() = it->aPixelRect.Right();
528 : }
529 105 : else if ( it->eType == SC_PLOC_COLHEADER )
530 : {
531 : // column headers result in an additional row
532 25 : bHasHeaderRow = true;
533 25 : aHeaderRect.Top() = it->aPixelRect.Top();
534 25 : aHeaderRect.Bottom() = it->aPixelRect.Bottom();
535 : }
536 : }
537 :
538 : //
539 : // get column info
540 : //
541 :
542 40 : SCCOL nColCount = 0;
543 : SCCOL nCol;
544 40 : if ( bHasHeaderCol )
545 25 : ++nColCount;
546 40 : if ( bHasRepCols )
547 0 : for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
548 0 : if (!pDoc->ColHidden(nCol, nTab))
549 0 : ++nColCount;
550 40 : if ( bHasMainCols )
551 80 : for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
552 40 : if (!pDoc->ColHidden(nCol, nTab))
553 40 : ++nColCount;
554 :
555 40 : if ( nColCount > 0 )
556 : {
557 40 : ScPreviewColRowInfo* pColInfo = new ScPreviewColRowInfo[ nColCount ];
558 40 : SCCOL nColPos = 0;
559 :
560 40 : if ( bHasHeaderCol )
561 : {
562 25 : pColInfo[nColPos].Set( sal_True, 0, aHeaderRect.Left(), aHeaderRect.Right() );
563 25 : ++nColPos;
564 : }
565 40 : if ( bHasRepCols )
566 : {
567 0 : long nPosX = 0;
568 0 : for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
569 0 : if (!pDoc->ColHidden(nCol, nTab))
570 : {
571 0 : sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
572 0 : long nNextX = nPosX + (long) (nDocW * nScaleX);
573 :
574 0 : long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
575 0 : long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
576 : pColInfo[nColPos].Set( false, nCol,
577 0 : aRepeatRect.Left() + nPixelStart,
578 0 : aRepeatRect.Left() + nPixelEnd );
579 :
580 0 : nPosX = nNextX;
581 0 : ++nColPos;
582 : }
583 : }
584 40 : if ( bHasMainCols )
585 : {
586 40 : long nPosX = 0;
587 80 : for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
588 40 : if (!pDoc->ColHidden(nCol, nTab))
589 : {
590 40 : sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
591 40 : long nNextX = nPosX + (long) (nDocW * nScaleX);
592 :
593 40 : long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
594 40 : long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
595 : pColInfo[nColPos].Set( false, nCol,
596 40 : aMainRect.Left() + nPixelStart,
597 80 : aMainRect.Left() + nPixelEnd );
598 :
599 40 : nPosX = nNextX;
600 40 : ++nColPos;
601 : }
602 : }
603 40 : rInfo.SetColInfo( nColCount, pColInfo );
604 : }
605 : else
606 0 : rInfo.SetColInfo( 0, NULL );
607 :
608 : //
609 : // get row info
610 : //
611 :
612 40 : SCROW nRowCount = 0;
613 40 : if ( bHasHeaderRow )
614 25 : ++nRowCount;
615 40 : if ( bHasRepRows )
616 0 : nRowCount += pDoc->CountVisibleRows(nRepeatRowStart, nRepeatRowEnd, nTab);
617 40 : if ( bHasMainRows )
618 40 : nRowCount += pDoc->CountVisibleRows(nMainRowStart, nMainRowEnd, nTab);
619 :
620 40 : if ( nRowCount > 0 )
621 : {
622 40 : ScPreviewColRowInfo* pRowInfo = new ScPreviewColRowInfo[ nRowCount ];
623 40 : SCROW nRowPos = 0;
624 :
625 40 : if ( bHasHeaderRow )
626 : {
627 25 : pRowInfo[nRowPos].Set( sal_True, 0, aHeaderRect.Top(), aHeaderRect.Bottom() );
628 25 : ++nRowPos;
629 : }
630 40 : if ( bHasRepRows )
631 : {
632 0 : long nPosY = 0;
633 0 : for (SCROW nRow = nRepeatRowStart; nRow <= nRepeatRowEnd; ++nRow)
634 : {
635 0 : if (pDoc->RowHidden(nRow, nTab))
636 0 : continue;
637 :
638 0 : sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
639 0 : long nNextY = nPosY + (long) (nDocH * nScaleY);
640 :
641 0 : long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
642 0 : long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
643 : pRowInfo[nRowPos].Set( false, nRow,
644 0 : aRepeatRect.Top() + nPixelStart,
645 0 : aRepeatRect.Top() + nPixelEnd );
646 :
647 0 : nPosY = nNextY;
648 0 : ++nRowPos;
649 : }
650 : }
651 40 : if ( bHasMainRows )
652 : {
653 40 : long nPosY = 0;
654 80 : for (SCROW nRow = nMainRowStart; nRow <= nMainRowEnd; ++nRow)
655 : {
656 40 : if (pDoc->RowHidden(nRow, nTab))
657 0 : continue;
658 :
659 40 : sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
660 40 : long nNextY = nPosY + (long) (nDocH * nScaleY);
661 :
662 40 : long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
663 40 : long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
664 : pRowInfo[nRowPos].Set( false, nRow,
665 40 : aMainRect.Top() + nPixelStart,
666 80 : aMainRect.Top() + nPixelEnd );
667 :
668 40 : nPosY = nNextY;
669 40 : ++nRowPos;
670 : }
671 : }
672 40 : rInfo.SetRowInfo( nRowCount, pRowInfo );
673 : }
674 : else
675 0 : rInfo.SetRowInfo( 0, NULL );
676 :
677 : //
678 : // limit to visible area
679 : //
680 :
681 40 : rInfo.SetTab( nTab );
682 40 : rInfo.LimitToArea( rVisiblePixel );
683 40 : }
684 :
685 16 : Rectangle ScPreviewLocationData::GetHeaderCellOutputRect(const Rectangle& rVisRect, const ScAddress& rCellPos, sal_Bool bColHeader) const
686 : {
687 : // first a stupid implementation
688 : // NN says here should be done more
689 16 : Rectangle aClipRect;
690 16 : ScPreviewTableInfo aTableInfo;
691 16 : GetTableInfo( rVisRect, aTableInfo );
692 :
693 48 : if ( (rCellPos.Col() >= 0) &&
694 48 : (rCellPos.Row() >= 0) && (rCellPos.Col() < aTableInfo.GetCols()) &&
695 16 : (rCellPos.Row() < aTableInfo.GetRows()) )
696 : {
697 16 : SCCOL nCol(0);
698 16 : SCROW nRow(0);
699 16 : if (bColHeader)
700 12 : nCol = rCellPos.Col();
701 : else
702 4 : nRow = rCellPos.Row();
703 16 : const ScPreviewColRowInfo& rColInfo = aTableInfo.GetColInfo()[nCol];
704 16 : const ScPreviewColRowInfo& rRowInfo = aTableInfo.GetRowInfo()[nRow];
705 :
706 16 : if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
707 16 : aClipRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
708 : }
709 16 : return aClipRect;
710 : }
711 :
712 21 : Rectangle ScPreviewLocationData::GetCellOutputRect(const ScAddress& rCellPos) const
713 : {
714 : // first a stupid implementation
715 : // NN says here should be done more
716 21 : Rectangle aRect;
717 21 : GetCellPosition(rCellPos, aRect);
718 21 : return aRect;
719 : }
720 :
721 : // GetMainCellRange is used for links in PDF export
722 :
723 0 : sal_Bool ScPreviewLocationData::GetMainCellRange( ScRange& rRange, Rectangle& rPixRect ) const
724 : {
725 0 : boost::ptr_list<ScPreviewLocationEntry>::const_iterator it;
726 0 : for (it = aEntries.begin(); it != aEntries.end(); ++it)
727 : {
728 0 : if ( it->eType == SC_PLOC_CELLRANGE && !it->bRepeatCol && !it->bRepeatRow )
729 : {
730 0 : rRange = it->aCellRange;
731 0 : rPixRect = it->aPixelRect;
732 0 : return true;
733 : }
734 : }
735 :
736 0 : return false;
737 93 : }
738 :
739 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|