1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
/*************************************************************************
*
* $RCSfile: prevloc.cxx,v $
*
* $Revision: 1.8 $
*
* last change: $Author: sab $ $Date: 2002-05-24 14:57:27 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifdef PCH
#include "ui_pch.hxx"
#endif
#pragma hdrstop
// INCLUDE ---------------------------------------------------------------
#include <vcl/window.hxx>
#include <tools/debug.hxx>
#include "prevloc.hxx"
#include "document.hxx"
//==================================================================
enum ScPreviewLocationType
{
SC_PLOC_CELLRANGE,
SC_PLOC_COLHEADER,
SC_PLOC_ROWHEADER,
SC_PLOC_LEFTHEADER,
SC_PLOC_RIGHTHEADER,
SC_PLOC_LEFTFOOTER,
SC_PLOC_RIGHTFOOTER,
SC_PLOC_NOTEMARK,
SC_PLOC_NOTETEXT
};
struct ScPreviewLocationEntry
{
ScPreviewLocationType eType;
Rectangle aPixelRect;
ScRange aCellRange;
BOOL bRepeatCol;
BOOL bRepeatRow;
ScPreviewLocationEntry( ScPreviewLocationType eNewType, const Rectangle& rPixel, const ScRange& rRange,
BOOL bRepCol, BOOL bRepRow ) :
eType( eNewType ),
aPixelRect( rPixel ),
aCellRange( rRange ),
bRepeatCol( bRepCol ),
bRepeatRow( bRepRow )
{
}
};
//==================================================================
ScPreviewTableInfo::ScPreviewTableInfo() :
nTab(0),
nCols(0),
nRows(0),
pColInfo(NULL),
pRowInfo(NULL)
{
}
ScPreviewTableInfo::~ScPreviewTableInfo()
{
delete[] pColInfo;
delete[] pRowInfo;
}
void ScPreviewTableInfo::SetTab( USHORT nNewTab )
{
nTab = nNewTab;
}
void ScPreviewTableInfo::SetColInfo( USHORT nCount, ScPreviewColRowInfo* pNewInfo )
{
delete[] pColInfo;
pColInfo = pNewInfo;
nCols = nCount;
}
void ScPreviewTableInfo::SetRowInfo( USHORT nCount, ScPreviewColRowInfo* pNewInfo )
{
delete[] pRowInfo;
pRowInfo = pNewInfo;
nRows = nCount;
}
void ScPreviewTableInfo::LimitToArea( const Rectangle& rPixelArea )
{
if ( pColInfo )
{
// cells completely left of the visible area
USHORT nStart = 0;
while ( nStart < nCols && pColInfo[nStart].nPixelEnd < rPixelArea.Left() )
++nStart;
// cells completely right of the visible area
USHORT nEnd = nCols;
while ( nEnd > 0 && pColInfo[nEnd-1].nPixelStart > rPixelArea.Right() )
--nEnd;
if ( nStart > 0 || nEnd < nCols )
{
if ( nEnd > nStart )
{
USHORT nNewCount = nEnd - nStart;
ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
for (USHORT i=0; i<nNewCount; i++)
pNewInfo[i] = pColInfo[nStart + i];
SetColInfo( nNewCount, pNewInfo );
}
else
SetColInfo( 0, NULL ); // all invisible
}
}
if ( pRowInfo )
{
// cells completely above the visible area
USHORT nStart = 0;
while ( nStart < nRows && pRowInfo[nStart].nPixelEnd < rPixelArea.Top() )
++nStart;
// cells completely below the visible area
USHORT nEnd = nRows;
while ( nEnd > 0 && pRowInfo[nEnd-1].nPixelStart > rPixelArea.Bottom() )
--nEnd;
if ( nStart > 0 || nEnd < nRows )
{
if ( nEnd > nStart )
{
USHORT nNewCount = nEnd - nStart;
ScPreviewColRowInfo* pNewInfo = new ScPreviewColRowInfo[nNewCount];
for (USHORT i=0; i<nNewCount; i++)
pNewInfo[i] = pRowInfo[nStart + i];
SetRowInfo( nNewCount, pNewInfo );
}
else
SetRowInfo( 0, NULL ); // all invisible
}
}
}
//------------------------------------------------------------------
ScPreviewLocationData::ScPreviewLocationData( ScDocument* pDocument, Window* pWin ) :
pDoc( pDocument ),
pWindow( pWin ),
nDrawRanges( 0 ),
nPrintTab( 0 )
{
}
ScPreviewLocationData::~ScPreviewLocationData()
{
Clear();
}
void ScPreviewLocationData::SetCellMapMode( const MapMode& rMapMode )
{
aCellMapMode = rMapMode;
}
void ScPreviewLocationData::SetPrintTab( USHORT nNew )
{
nPrintTab = nNew;
}
void ScPreviewLocationData::Clear()
{
void* pEntry = aEntries.First();
while ( pEntry )
{
delete (ScPreviewLocationEntry*) pEntry;
pEntry = aEntries.Next();
}
aEntries.Clear();
nDrawRanges = 0;
}
void ScPreviewLocationData::AddCellRange( const Rectangle& rRect, const ScRange& rRange, BOOL bRepCol, BOOL bRepRow,
const MapMode& rDrawMap )
{
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_CELLRANGE, aPixelRect, rRange, bRepCol, bRepRow ) );
DBG_ASSERT( nDrawRanges < SC_PREVIEW_MAXRANGES, "too many ranges" );
if ( nDrawRanges < SC_PREVIEW_MAXRANGES )
{
aDrawRectangle[nDrawRanges] = rRect;
aDrawMapMode[nDrawRanges] = rDrawMap;
if (bRepCol)
if (bRepRow)
aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_EDGE;
else
aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPCOL;
else
if (bRepRow)
aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_REPROW;
else
aDrawRangeId[nDrawRanges] = SC_PREVIEW_RANGE_TAB;
++nDrawRanges;
}
}
void ScPreviewLocationData::AddColHeaders( const Rectangle& rRect, USHORT nStartCol, USHORT nEndCol, BOOL bRepCol )
{
USHORT nTab = 0; //! ?
ScRange aRange( nStartCol, 0, nTab, nEndCol, 0, nTab );
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_COLHEADER, aPixelRect, aRange, bRepCol, FALSE ) );
}
void ScPreviewLocationData::AddRowHeaders( const Rectangle& rRect, USHORT nStartRow, USHORT nEndRow, BOOL bRepRow )
{
USHORT nTab = 0; //! ?
ScRange aRange( 0, nStartRow, nTab, 0, nEndRow, nTab );
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_ROWHEADER, aPixelRect, aRange, FALSE, bRepRow ) );
}
void ScPreviewLocationData::AddHeaderFooter( const Rectangle& rRect, BOOL bHeader, BOOL bLeft )
{
ScRange aRange; //! ?
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
ScPreviewLocationType eType = bHeader ?
( bLeft ? SC_PLOC_LEFTHEADER : SC_PLOC_RIGHTHEADER ) :
( bLeft ? SC_PLOC_LEFTFOOTER : SC_PLOC_RIGHTFOOTER );
aEntries.Insert( new ScPreviewLocationEntry( eType, aPixelRect, aRange, FALSE, FALSE ) );
}
void ScPreviewLocationData::AddNoteMark( const Rectangle& rRect, const ScAddress& rPos )
{
ScRange aRange( rPos );
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_NOTEMARK, aPixelRect, aRange, FALSE, FALSE ) );
}
void ScPreviewLocationData::AddNoteText( const Rectangle& rRect, const ScAddress& rPos )
{
ScRange aRange( rPos );
Rectangle aPixelRect( pWindow->LogicToPixel( rRect ) );
aEntries.Insert( new ScPreviewLocationEntry( SC_PLOC_NOTETEXT, aPixelRect, aRange, FALSE, FALSE ) );
}
//------------------------------------------------------------------
void ScPreviewLocationData::GetDrawRange( USHORT nPos, Rectangle& rPixelRect, MapMode& rMapMode, sal_uInt8& rRangeId ) const
{
DBG_ASSERT( nPos < nDrawRanges, "wrong position" );
if ( nPos < nDrawRanges )
{
rPixelRect = aDrawRectangle[nPos];
rMapMode = aDrawMapMode[nPos];
rRangeId = aDrawRangeId[nPos];
}
}
ScPreviewLocationEntry* lcl_GetEntryByPosition( const List& rEntries, const Point& rPos, ScPreviewLocationType eType )
{
ULONG nCount = rEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)rEntries.GetObject(nListPos);
if ( pEntry->eType == eType && pEntry->aPixelRect.IsInside( rPos ) )
return pEntry;
}
return NULL;
}
ScPreviewLocationEntry* lcl_GetEntryByAddress( const List& rEntries, const ScAddress& rPos, ScPreviewLocationType eType )
{
ULONG nCount = rEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)rEntries.GetObject(nListPos);
if ( pEntry->eType == eType && pEntry->aCellRange.In( rPos ) )
return pEntry;
}
return NULL;
}
ScAddress ScPreviewLocationData::GetCellFromRange( const Size& rOffsetPixel, const ScRange& rRange ) const
{
const double nScaleX = HMM_PER_TWIPS;
const double nScaleY = HMM_PER_TWIPS;
Size aOffsetLogic = pWindow->PixelToLogic( rOffsetPixel, aCellMapMode );
USHORT nTab = rRange.aStart.Tab();
long nPosX = 0;
USHORT nCol = rRange.aStart.Col();
USHORT nEndCol = rRange.aEnd.Col();
while ( nCol <= nEndCol && nPosX < aOffsetLogic.Width() )
{
USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
if (nDocW)
nPosX += (long) (nDocW * nScaleX);
++nCol;
}
if ( nCol > rRange.aStart.Col() )
--nCol;
long nPosY = 0;
USHORT nRow = rRange.aStart.Row();
USHORT nEndRow = rRange.aEnd.Row();
while ( nRow <= nEndRow && nPosY < aOffsetLogic.Height() )
{
USHORT nDocH = pDoc->FastGetRowHeight( nRow, nTab );
if (nDocH)
nPosY += (long) (nDocH * nScaleY);
++nRow;
}
if ( nRow > rRange.aStart.Row() )
--nRow;
return ScAddress( nCol, nRow, nTab );
}
Rectangle ScPreviewLocationData::GetOffsetPixel( const ScAddress& rCellPos, const ScRange& rRange ) const
{
const double nScaleX = HMM_PER_TWIPS;
const double nScaleY = HMM_PER_TWIPS;
USHORT nTab = rRange.aStart.Tab();
long nPosX = 0;
USHORT nEndCol = rCellPos.Col();
for (USHORT nCol = rRange.aStart.Col(); nCol < nEndCol; nCol++)
{
USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
if (nDocW)
nPosX += (long) (nDocW * nScaleX);
}
long nSizeX = (long) ( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );
long nPosY = 0;
USHORT nEndRow = rCellPos.Row();
for (USHORT nRow = rRange.aStart.Row(); nRow < nEndRow; nRow++)
{
USHORT nDocH = pDoc->FastGetRowHeight( nRow, nTab );
if (nDocH)
nPosY += (long) (nDocH * nScaleY);
}
long nSizeY = (long) ( pDoc->FastGetRowHeight( nEndRow, nTab ) * nScaleY );
Size aOffsetLogic( nPosX, nPosY );
Size aSizeLogic( nSizeX, nSizeY );
Size aOffsetPixel = pWindow->LogicToPixel( aOffsetLogic, aCellMapMode );
Size aSizePixel = pWindow->LogicToPixel( aSizeLogic, aCellMapMode );
return Rectangle( Point( aOffsetPixel.Width(), aOffsetPixel.Height() ), aSizePixel );
}
BOOL ScPreviewLocationData::GetCell( const Point& rPos, ScAddress& rCellPos, Rectangle& rCellRect ) const
{
ScPreviewLocationEntry* pEntry = lcl_GetEntryByPosition( aEntries, rPos, SC_PLOC_CELLRANGE );
if ( pEntry )
{
Size aOffsetPixel( rPos.X() - pEntry->aPixelRect.Left(), rPos.Y() - pEntry->aPixelRect.Top() );
rCellPos = GetCellFromRange( aOffsetPixel, pEntry->aCellRange );
Rectangle aOffsetRect = GetOffsetPixel( rCellPos, pEntry->aCellRange );
rCellRect = Rectangle( aOffsetRect.Left() + pEntry->aPixelRect.Left(),
aOffsetRect.Top() + pEntry->aPixelRect.Top(),
aOffsetRect.Right() + pEntry->aPixelRect.Left(),
aOffsetRect.Bottom() + pEntry->aPixelRect.Top() );
return TRUE;
}
return FALSE;
}
BOOL ScPreviewLocationData::GetCellPosition( const ScAddress& rCellPos, Rectangle& rCellRect ) const
{
ScPreviewLocationEntry* pEntry = lcl_GetEntryByAddress( aEntries, rCellPos, SC_PLOC_CELLRANGE );
if ( pEntry )
{
Rectangle aOffsetRect = GetOffsetPixel( rCellPos, pEntry->aCellRange );
rCellRect = Rectangle( aOffsetRect.Left() + pEntry->aPixelRect.Left(),
aOffsetRect.Top() + pEntry->aPixelRect.Top(),
aOffsetRect.Right() + pEntry->aPixelRect.Left(),
aOffsetRect.Bottom() + pEntry->aPixelRect.Top() );
return TRUE;
}
return FALSE;
}
BOOL ScPreviewLocationData::HasCellsInRange( const Rectangle& rVisiblePixel ) const
{
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
ScPreviewLocationType eType = pEntry->eType;
if ( eType == SC_PLOC_CELLRANGE || eType == SC_PLOC_COLHEADER || eType == SC_PLOC_ROWHEADER )
if ( pEntry->aPixelRect.IsOver( rVisiblePixel ) )
return TRUE;
}
return FALSE;
}
BOOL ScPreviewLocationData::GetHeaderPosition( Rectangle& rRect ) const
{
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == SC_PLOC_LEFTHEADER || pEntry->eType == SC_PLOC_RIGHTHEADER )
{
rRect = pEntry->aPixelRect;
return TRUE;
}
}
return FALSE;
}
BOOL ScPreviewLocationData::GetFooterPosition( Rectangle& rRect ) const
{
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == SC_PLOC_LEFTFOOTER || pEntry->eType == SC_PLOC_RIGHTFOOTER )
{
rRect = pEntry->aPixelRect;
return TRUE;
}
}
return FALSE;
}
BOOL ScPreviewLocationData::IsHeaderLeft() const
{
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == SC_PLOC_LEFTHEADER )
return TRUE;
if ( pEntry->eType == SC_PLOC_RIGHTHEADER )
return FALSE;
}
return FALSE;
}
BOOL ScPreviewLocationData::IsFooterLeft() const
{
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == SC_PLOC_LEFTFOOTER )
return TRUE;
if ( pEntry->eType == SC_PLOC_RIGHTFOOTER )
return FALSE;
}
return FALSE;
}
long ScPreviewLocationData::GetNoteCountInRange( const Rectangle& rVisiblePixel, BOOL bNoteMarks ) const
{
ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
ULONG nRet = 0;
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
++nRet;
}
return nRet;
}
BOOL ScPreviewLocationData::GetNoteInRange( const Rectangle& rVisiblePixel, long nIndex, BOOL bNoteMarks,
ScAddress& rCellPos, Rectangle& rNoteRect ) const
{
ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
ULONG nPos = 0;
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
{
if ( nPos == nIndex )
{
rCellPos = pEntry->aCellRange.aStart;
rNoteRect = pEntry->aPixelRect;
return TRUE;
}
++nPos;
}
}
return FALSE;
}
Rectangle ScPreviewLocationData::GetNoteInRangeOutputRect(const Rectangle& rVisiblePixel, BOOL bNoteMarks, const ScAddress& aCellPos) const
{
ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
ULONG nPos = 0;
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == eType && pEntry->aPixelRect.IsOver( rVisiblePixel ) )
{
if ( aCellPos == pEntry->aCellRange.aStart )
return pEntry->aPixelRect;
++nPos;
}
}
return Rectangle();
}
void ScPreviewLocationData::GetTableInfo( const Rectangle& rVisiblePixel, ScPreviewTableInfo& rInfo ) const
{
const double nScaleX = HMM_PER_TWIPS;
const double nScaleY = HMM_PER_TWIPS;
// from left to right:
BOOL bHasHeaderCol = FALSE;
BOOL bHasRepCols = FALSE;
BOOL bHasMainCols = FALSE;
USHORT nRepeatColStart = 0;
USHORT nRepeatColEnd = 0;
USHORT nMainColStart = 0;
USHORT nMainColEnd = 0;
// from top to bottom:
BOOL bHasHeaderRow = FALSE;
BOOL bHasRepRows = FALSE;
BOOL bHasMainRows = FALSE;
USHORT nRepeatRowStart = 0;
USHORT nRepeatRowEnd = 0;
USHORT nMainRowStart = 0;
USHORT nMainRowEnd = 0;
Rectangle aHeaderRect, aRepeatRect, aMainRect;
USHORT nTab = 0;
ULONG nCount = aEntries.Count();
for (ULONG nListPos=0; nListPos<nCount; nListPos++)
{
ScPreviewLocationEntry* pEntry = (ScPreviewLocationEntry*)aEntries.GetObject(nListPos);
if ( pEntry->eType == SC_PLOC_CELLRANGE )
{
if ( pEntry->bRepeatCol )
{
bHasRepCols = TRUE;
nRepeatColStart = pEntry->aCellRange.aStart.Col();
nRepeatColEnd = pEntry->aCellRange.aEnd.Col();
aRepeatRect.Left() = pEntry->aPixelRect.Left();
aRepeatRect.Right() = pEntry->aPixelRect.Right();
}
else
{
bHasMainCols = TRUE;
nMainColStart = pEntry->aCellRange.aStart.Col();
nMainColEnd = pEntry->aCellRange.aEnd.Col();
aMainRect.Left() = pEntry->aPixelRect.Left();
aMainRect.Right() = pEntry->aPixelRect.Right();
}
if ( pEntry->bRepeatRow )
{
bHasRepRows = TRUE;
nRepeatRowStart = pEntry->aCellRange.aStart.Row();
nRepeatRowEnd = pEntry->aCellRange.aEnd.Row();
aRepeatRect.Top() = pEntry->aPixelRect.Top();
aRepeatRect.Bottom() = pEntry->aPixelRect.Bottom();
}
else
{
bHasMainRows = TRUE;
nMainRowStart = pEntry->aCellRange.aStart.Row();
nMainRowEnd = pEntry->aCellRange.aEnd.Row();
aMainRect.Top() = pEntry->aPixelRect.Top();
aMainRect.Bottom() = pEntry->aPixelRect.Bottom();
}
nTab = pEntry->aCellRange.aStart.Tab(); //! store separately?
}
else if ( pEntry->eType == SC_PLOC_ROWHEADER )
{
// row headers result in an additional column
bHasHeaderCol = TRUE;
aHeaderRect.Left() = pEntry->aPixelRect.Left();
aHeaderRect.Right() = pEntry->aPixelRect.Right();
}
else if ( pEntry->eType == SC_PLOC_COLHEADER )
{
// column headers result in an additional row
bHasHeaderRow = TRUE;
aHeaderRect.Top() = pEntry->aPixelRect.Top();
aHeaderRect.Bottom() = pEntry->aPixelRect.Bottom();
}
}
//
// get column info
//
USHORT nColCount = 0;
USHORT nCol;
if ( bHasHeaderCol )
++nColCount;
if ( bHasRepCols )
for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
if ( ( pDoc->GetColFlags( nCol, nTab ) & CR_HIDDEN ) == 0 )
++nColCount;
if ( bHasMainCols )
for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
if ( ( pDoc->GetColFlags( nCol, nTab ) & CR_HIDDEN ) == 0 )
++nColCount;
if ( nColCount > 0 )
{
ScPreviewColRowInfo* pColInfo = new ScPreviewColRowInfo[ nColCount ];
USHORT nColPos = 0;
if ( bHasHeaderCol )
{
pColInfo[nColPos].Set( TRUE, 0, aHeaderRect.Left(), aHeaderRect.Right() );
++nColPos;
}
if ( bHasRepCols )
{
long nPosX = 0;
for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
if ( ( pDoc->GetColFlags( nCol, nTab ) & CR_HIDDEN ) == 0 )
{
USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
long nNextX = nPosX + (long) (nDocW * nScaleX);
long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
pColInfo[nColPos].Set( FALSE, nCol,
aRepeatRect.Left() + nPixelStart,
aRepeatRect.Left() + nPixelEnd );
nPosX = nNextX;
++nColPos;
}
}
if ( bHasMainCols )
{
long nPosX = 0;
for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
if ( ( pDoc->GetColFlags( nCol, nTab ) & CR_HIDDEN ) == 0 )
{
USHORT nDocW = pDoc->GetColWidth( nCol, nTab );
long nNextX = nPosX + (long) (nDocW * nScaleX);
long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
pColInfo[nColPos].Set( FALSE, nCol,
aMainRect.Left() + nPixelStart,
aMainRect.Left() + nPixelEnd );
nPosX = nNextX;
++nColPos;
}
}
rInfo.SetColInfo( nColCount, pColInfo );
}
else
rInfo.SetColInfo( 0, NULL );
//
// get row info
//
USHORT nRowCount = 0;
USHORT nRow;
if ( bHasHeaderRow )
++nRowCount;
if ( bHasRepRows )
for ( nRow=nRepeatRowStart; nRow<=nRepeatRowEnd; nRow++ )
if ( ( pDoc->GetRowFlags( nRow, nTab ) & CR_HIDDEN ) == 0 )
++nRowCount;
if ( bHasMainRows )
for ( nRow=nMainRowStart; nRow<=nMainRowEnd; nRow++ )
if ( ( pDoc->GetRowFlags( nRow, nTab ) & CR_HIDDEN ) == 0 )
++nRowCount;
if ( nRowCount > 0 )
{
ScPreviewColRowInfo* pRowInfo = new ScPreviewColRowInfo[ nRowCount ];
USHORT nRowPos = 0;
if ( bHasHeaderRow )
{
pRowInfo[nRowPos].Set( TRUE, 0, aHeaderRect.Top(), aHeaderRect.Bottom() );
++nRowPos;
}
if ( bHasRepRows )
{
long nPosY = 0;
for ( nRow=nRepeatRowStart; nRow<=nRepeatRowEnd; nRow++ )
if ( ( pDoc->GetRowFlags( nRow, nTab ) & CR_HIDDEN ) == 0 )
{
USHORT nDocH = pDoc->FastGetRowHeight( nRow, nTab );
long nNextY = nPosY + (long) (nDocH * nScaleY);
long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
pRowInfo[nRowPos].Set( FALSE, nRow,
aRepeatRect.Top() + nPixelStart,
aRepeatRect.Top() + nPixelEnd );
nPosY = nNextY;
++nRowPos;
}
}
if ( bHasMainRows )
{
long nPosY = 0;
for ( nRow=nMainRowStart; nRow<=nMainRowEnd; nRow++ )
if ( ( pDoc->GetRowFlags( nRow, nTab ) & CR_HIDDEN ) == 0 )
{
USHORT nDocH = pDoc->FastGetRowHeight( nRow, nTab );
long nNextY = nPosY + (long) (nDocH * nScaleY);
long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
pRowInfo[nRowPos].Set( FALSE, nRow,
aMainRect.Top() + nPixelStart,
aMainRect.Top() + nPixelEnd );
nPosY = nNextY;
++nRowPos;
}
}
rInfo.SetRowInfo( nRowCount, pRowInfo );
}
else
rInfo.SetRowInfo( 0, NULL );
//
// limit to visible area
//
rInfo.SetTab( nTab );
rInfo.LimitToArea( rVisiblePixel );
}
Rectangle ScPreviewLocationData::GetHeaderCellOutputRect(const Rectangle& rVisRect, const ScAddress& rCellPos, sal_Bool bColHeader) const
{
// first a stupid implementation
// NN says here should be done more
Rectangle aClipRect;
ScPreviewTableInfo aTableInfo;
GetTableInfo( rVisRect, aTableInfo );
if ( (rCellPos.Col() >= 0) &&
(rCellPos.Row() >= 0) && (rCellPos.Col() < aTableInfo.GetCols()) &&
(rCellPos.Row() < aTableInfo.GetRows()) )
{
sal_Int16 nCol(0);
sal_Int16 nRow(0);
if (bColHeader)
nCol = rCellPos.Col();
else
nRow = rCellPos.Row();
const ScPreviewColRowInfo& rColInfo = aTableInfo.GetColInfo()[nCol];
const ScPreviewColRowInfo& rRowInfo = aTableInfo.GetRowInfo()[nRow];
if ( rColInfo.bIsHeader || rRowInfo.bIsHeader )
aClipRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
}
return aClipRect;
}
Rectangle ScPreviewLocationData::GetCellOutputRect(const ScAddress& rCellPos) const
{
// first a stupid implementation
// NN says here should be done more
Rectangle aRect;
GetCellPosition(rCellPos, aRect);
return aRect;
}
|