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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/svdpagv.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdogrp.hxx>
#include <svx/svdtypes.hxx>
#include <svx/sdr/contact/viewobjectcontactredirector.hxx>
#include <algorithm>
#include <svx/sdrpagewindow.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/scopeguard.hxx>
#include <basegfx/range/b2irectangle.hxx>
#include <osl/diagnose.h>
using namespace ::com::sun::star;
// interface to SdrPageWindow
SdrPageWindow* SdrPageView::FindPageWindow(const SdrPaintWindow& rPaintWindow) const
{
for(auto & a : maPageWindows)
{
if(&(a->GetPaintWindow()) == &rPaintWindow)
{
return a.get();
}
}
return nullptr;
}
const SdrPageWindow* SdrPageView::FindPatchedPageWindow( const OutputDevice& _rOutDev ) const
{
for ( auto const & pPageWindow : maPageWindows )
{
const SdrPaintWindow& rPaintWindow( pPageWindow->GetOriginalPaintWindow() ? *pPageWindow->GetOriginalPaintWindow() : pPageWindow->GetPaintWindow() );
if ( &rPaintWindow.GetOutputDevice() == &_rOutDev )
{
return pPageWindow.get();
}
}
return nullptr;
}
SdrPageWindow* SdrPageView::FindPageWindow(const OutputDevice& rOutDev) const
{
for ( auto const & pPageWindow : maPageWindows )
{
if(&(pPageWindow->GetPaintWindow().GetOutputDevice()) == &rOutDev)
{
return pPageWindow.get();
}
}
return nullptr;
}
SdrPageWindow* SdrPageView::GetPageWindow(sal_uInt32 nIndex) const
{
return maPageWindows[nIndex].get();
}
SdrPageView::SdrPageView(SdrPage* pPage1, SdrView& rNewView)
: mrView(rNewView),
// col_auto color lets the view takes the default SvxColorConfig entry
maDocumentColor( COL_AUTO ),
maBackgroundColor( COL_AUTO ), // #i48367# also react on autocolor
mpPreparedPageWindow(nullptr) // #i72752#
{
mpPage = pPage1;
if(mpPage)
{
maPageOrigin.setX(mpPage->GetLeftBorder() );
maPageOrigin.setY(mpPage->GetUpperBorder() );
}
// For example, in the case of charts, there is a LayerAdmin, but it has no valid values. Therefore
// a solution like pLayerAdmin->getVisibleLayersODF(aLayerVisi) is not possible. So use the
// generic SetAll() for now.
aLayerVisi.SetAll();
aLayerPrn.SetAll();
mbHasMarked = false;
mbVisible = false;
pCurrentList = nullptr;
pCurrentGroup = nullptr;
SetCurrentGroupAndList(nullptr, mpPage);
for(sal_uInt32 a(0); a < rNewView.PaintWindowCount(); a++)
{
AddPaintWindowToPageView(*rNewView.GetPaintWindow(a));
}
}
SdrPageView::~SdrPageView()
{
}
void SdrPageView::AddPaintWindowToPageView(SdrPaintWindow& rPaintWindow)
{
if(!FindPageWindow(rPaintWindow))
{
maPageWindows.emplace_back(new SdrPageWindow(*this, rPaintWindow));
}
}
void SdrPageView::RemovePaintWindowFromPageView(SdrPaintWindow& rPaintWindow)
{
auto it = std::find_if(maPageWindows.begin(), maPageWindows.end(),
[&rPaintWindow](const std::unique_ptr<SdrPageWindow>& rpWindow) {
return &(rpWindow->GetPaintWindow()) == &rPaintWindow;
});
if (it != maPageWindows.end())
maPageWindows.erase(it);
}
css::uno::Reference< css::awt::XControlContainer > SdrPageView::GetControlContainer( const OutputDevice& _rDevice ) const
{
css::uno::Reference< css::awt::XControlContainer > xReturn;
const SdrPageWindow* pCandidate = FindPatchedPageWindow( _rDevice );
if ( pCandidate )
xReturn = pCandidate->GetControlContainer();
return xReturn;
}
void SdrPageView::ModelHasChanged()
{
if (GetCurrentGroup()!=nullptr) CheckCurrentGroup();
}
bool SdrPageView::IsReadOnly() const
{
return (nullptr == GetPage() || GetView().GetModel().IsReadOnly() || GetPage()->IsReadOnly() || GetObjList()->IsReadOnly());
}
void SdrPageView::Show()
{
if(!IsVisible())
{
mbVisible = true;
for(sal_uInt32 a(0); a < GetView().PaintWindowCount(); a++)
{
AddPaintWindowToPageView(*GetView().GetPaintWindow(a));
}
}
}
void SdrPageView::Hide()
{
if(IsVisible())
{
if (!comphelper::LibreOfficeKit::isActive())
{
InvalidateAllWin();
}
mbVisible = false;
maPageWindows.clear();
}
}
tools::Rectangle SdrPageView::GetPageRect() const
{
if (GetPage()==nullptr) return tools::Rectangle();
return tools::Rectangle(Point(),Size(GetPage()->GetWidth()+1,GetPage()->GetHeight()+1));
}
void SdrPageView::InvalidateAllWin()
{
if(IsVisible() && GetPage())
{
tools::Rectangle aRect(Point(0,0),Size(GetPage()->GetWidth()+1,GetPage()->GetHeight()+1));
aRect.Union(GetPage()->GetAllObjBoundRect());
GetView().InvalidateAllWin(aRect);
}
}
void SdrPageView::PrePaint()
{
const sal_uInt32 nCount(PageWindowCount());
for(sal_uInt32 a(0); a < nCount; a++)
{
SdrPageWindow* pCandidate = GetPageWindow(a);
if(pCandidate)
{
pCandidate->PrePaint();
}
}
}
void SdrPageView::CompleteRedraw(
SdrPaintWindow& rPaintWindow, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector )
{
if(!GetPage())
return;
SdrPageWindow* pPageWindow = FindPageWindow(rPaintWindow);
std::unique_ptr<SdrPageWindow> pTempPageWindow;
if(!pPageWindow)
{
// create temp PageWindow
pTempPageWindow.reset(new SdrPageWindow(*this, rPaintWindow));
pPageWindow = pTempPageWindow.get();
}
// do the redraw
pPageWindow->PrepareRedraw(rReg);
pPageWindow->RedrawAll(pRedirector);
}
// #i74769# use SdrPaintWindow directly
void SdrPageView::setPreparedPageWindow(SdrPageWindow* pKnownTarget)
{
// #i72752# remember prepared SdrPageWindow
mpPreparedPageWindow = pKnownTarget;
}
void SdrPageView::DrawLayer(SdrLayerID nID, OutputDevice* pGivenTarget,
sdr::contact::ViewObjectContactRedirector* pRedirector,
const tools::Rectangle& rRect, basegfx::B2IRectangle const*const pPageFrame)
{
if(!GetPage())
return;
if(pGivenTarget)
{
SdrPageWindow* pKnownTarget = FindPageWindow(*pGivenTarget);
if(pKnownTarget)
{
// paint known target
pKnownTarget->RedrawLayer(&nID, pRedirector, pPageFrame);
}
else
{
// #i72752# DrawLayer() uses an OutputDevice different from BeginDrawLayer. This happens
// e.g. when SW paints a single text line in text edit mode. Try to use it
SdrPageWindow* pPreparedTarget = mpPreparedPageWindow;
if(pPreparedTarget)
{
// if we have a prepared target, do not use a new SdrPageWindow since this
// works but is expensive. Just use a temporary PaintWindow
SdrPaintWindow aTemporaryPaintWindow(mrView, *pGivenTarget);
// Copy existing paint region to use the same as prepared in BeginDrawLayer
SdrPaintWindow& rExistingPaintWindow = pPreparedTarget->GetPaintWindow();
const vcl::Region& rExistingRegion = rExistingPaintWindow.GetRedrawRegion();
bool bUseRect(false);
if (!rRect.IsEmpty())
{
vcl::Region r(rExistingRegion);
r.Intersect(rRect);
// fdo#74435: FIXME: visibility check broken if empty
if (!r.IsEmpty())
bUseRect = true;
}
if (!bUseRect)
aTemporaryPaintWindow.SetRedrawRegion(rExistingRegion);
else
aTemporaryPaintWindow.SetRedrawRegion(vcl::Region(rRect));
// patch the ExistingPageWindow
auto pPreviousWindow = pPreparedTarget->patchPaintWindow(aTemporaryPaintWindow);
// unpatch window when leaving the scope
const ::comphelper::ScopeGuard aGuard(
[&pPreviousWindow, &pPreparedTarget]() { pPreparedTarget->unpatchPaintWindow(pPreviousWindow); } );
// redraw the layer
pPreparedTarget->RedrawLayer(&nID, pRedirector, pPageFrame);
}
else
{
OSL_FAIL("SdrPageView::DrawLayer: Creating temporary SdrPageWindow (ObjectContact), this should never be needed (!)");
// None of the known OutputDevices is the target of this paint, use
// a temporary SdrPageWindow for this Redraw.
SdrPaintWindow aTemporaryPaintWindow(mrView, *pGivenTarget);
SdrPageWindow aTemporaryPageWindow(*this, aTemporaryPaintWindow);
// #i72752#
// Copy existing paint region if other PageWindows exist, this was created by
// PrepareRedraw() from BeginDrawLayer(). Needs to be used e.g. when suddenly SW
// paints into an unknown device other than the view was created for (e.g. VirtualDevice)
if(PageWindowCount())
{
SdrPageWindow* pExistingPageWindow = GetPageWindow(0);
SdrPaintWindow& rExistingPaintWindow = pExistingPageWindow->GetPaintWindow();
const vcl::Region& rExistingRegion = rExistingPaintWindow.GetRedrawRegion();
aTemporaryPaintWindow.SetRedrawRegion(rExistingRegion);
}
aTemporaryPageWindow.RedrawLayer(&nID, pRedirector, nullptr);
}
}
}
else
{
// paint in all known windows
for(sal_uInt32 a(0); a < PageWindowCount(); a++)
{
SdrPageWindow* pTarget = GetPageWindow(a);
pTarget->RedrawLayer(&nID, pRedirector, nullptr);
}
}
}
void SdrPageView::SetDesignMode( bool _bDesignMode ) const
{
for ( sal_uInt32 i = 0; i < PageWindowCount(); ++i )
{
const SdrPageWindow& rPageViewWindow = *GetPageWindow(i);
rPageViewWindow.SetDesignMode( _bDesignMode );
}
}
void SdrPageView::DrawPageViewGrid(OutputDevice& rOut, const tools::Rectangle& rRect, Color aColor)
{
if (GetPage()==nullptr)
return;
tools::Long nx1=GetView().maGridBig.Width();
tools::Long nx2=GetView().maGridFin.Width();
tools::Long ny1=GetView().maGridBig.Height();
tools::Long ny2=GetView().maGridFin.Height();
if (nx1==0) nx1=nx2;
if (nx2==0) nx2=nx1;
if (ny1==0) ny1=ny2;
if (ny2==0) ny2=ny1;
if (nx1==0) { nx1=ny1; nx2=ny2; }
if (ny1==0) { ny1=nx1; ny2=nx2; }
if (nx1<0) nx1=-nx1;
if (nx2<0) nx2=-nx2;
if (ny1<0) ny1=-ny1;
if (ny2<0) ny2=-ny2;
if (nx1==0)
return;
// no more global output size, use window size instead to decide grid sizes
tools::Long nScreenWdt = rOut.GetOutputSizePixel().Width();
tools::Long nMinDotPix=2;
tools::Long nMinLinPix=4;
if (nScreenWdt>=1600)
{
nMinDotPix=4;
nMinLinPix=8;
}
else if (nScreenWdt>=1024)
{
nMinDotPix=3;
nMinLinPix=6;
}
else
{ // e. g. 640x480
nMinDotPix=2;
nMinLinPix=4;
}
Size aMinDotDist(rOut.PixelToLogic(Size(nMinDotPix,nMinDotPix)));
Size aMinLinDist(rOut.PixelToLogic(Size(nMinLinPix,nMinLinPix)));
bool bHoriSolid=nx2<aMinDotDist.Width();
bool bVertSolid=ny2<aMinDotDist.Height();
// enlarge line offset (minimum 4 pixels)
// enlarge by: *2 *5 *10 *20 *50 *100 ...
int nTgl=0;
tools::Long nVal0=nx1;
while (nx1<aMinLinDist.Width())
{
tools::Long a=nx1;
if (nTgl==0) nx1*=2;
if (nTgl==1) nx1=nVal0*5; // => nx1*=2.5
if (nTgl==2) nx1*=2;
nVal0=a;
nTgl++; if (nTgl>=3) nTgl=0;
}
nTgl=0;
nVal0=ny1;
while (ny1<aMinLinDist.Height())
{
tools::Long a=ny1;
if (nTgl==0) ny1*=2;
if (nTgl==1) ny1=nVal0*5; // => ny1*=2.5
if (nTgl==2) ny1*=2;
nVal0=a;
nTgl++;
if (nTgl>=3) nTgl=0;
}
bool bHoriFine=nx2<nx1;
bool bVertFine=ny2<ny1;
bool bHoriLines=bHoriSolid || bHoriFine || !bVertFine;
bool bVertLines=bVertSolid || bVertFine;
Color aOriginalLineColor( rOut.GetLineColor() );
rOut.SetLineColor( aColor );
bool bMap0=rOut.IsMapModeEnabled();
tools::Long nWrX=0;
tools::Long nWrY=0;
Point aOrg(maPageOrigin);
tools::Long x1 = 0;
tools::Long x2 = 0;
if (GetPage()->GetWidth() < 0) // ScDrawPage of RTL sheet
{
x1 = GetPage()->GetWidth() + GetPage()->GetLeftBorder() + 1;
x2 = - GetPage()->GetRightBorder() - 1;
}
else
{
x1 = GetPage()->GetLeftBorder() + 1;
x2 = GetPage()->GetWidth() - GetPage()->GetRightBorder() - 1;
}
tools::Long y1 = GetPage()->GetUpperBorder() + 1;
tools::Long y2 = GetPage()->GetHeight() - GetPage()->GetLowerBorder() - 1;
const SdrPageGridFrameList* pFrames=GetPage()->GetGridFrameList(this,nullptr);
sal_uInt16 nGridPaintCnt=1;
if (pFrames!=nullptr) nGridPaintCnt=pFrames->GetCount();
for (sal_uInt16 nGridPaintNum=0; nGridPaintNum<nGridPaintCnt; nGridPaintNum++) {
if (pFrames!=nullptr) {
const SdrPageGridFrame& rGF=(*pFrames)[nGridPaintNum];
nWrX=rGF.GetPaperRect().Left();
nWrY=rGF.GetPaperRect().Top();
x1=rGF.GetUserArea().Left();
x2=rGF.GetUserArea().Right();
y1=rGF.GetUserArea().Top();
y2=rGF.GetUserArea().Bottom();
aOrg=rGF.GetUserArea().TopLeft();
aOrg-=rGF.GetPaperRect().TopLeft();
}
if (!rRect.IsEmpty()) {
Size a1PixSiz(rOut.PixelToLogic(Size(1,1)));
tools::Long nX1Pix=a1PixSiz.Width(); // add 1 pixel of tolerance
tools::Long nY1Pix=a1PixSiz.Height();
if (x1<rRect.Left() -nX1Pix) x1=rRect.Left() -nX1Pix;
if (x2>rRect.Right() +nX1Pix) x2=rRect.Right() +nX1Pix;
if (y1<rRect.Top() -nY1Pix) y1=rRect.Top() -nY1Pix;
if (y2>rRect.Bottom()+nY1Pix) y2=rRect.Bottom()+nY1Pix;
}
tools::Long xBigOrg=aOrg.X()+nWrX;
while (xBigOrg>=x1) xBigOrg-=nx1;
while (xBigOrg<x1) xBigOrg+=nx1;
tools::Long xFinOrg=xBigOrg;
while (xFinOrg>=x1) xFinOrg-=nx2;
while (xFinOrg<x1) xFinOrg+=nx2;
tools::Long yBigOrg=aOrg.Y()+nWrY;
while (yBigOrg>=y1) yBigOrg-=ny1;
while (yBigOrg<y1) yBigOrg+=ny1;
tools::Long yFinOrg=yBigOrg;
while (yFinOrg>=y1) yFinOrg-=ny2;
while (yFinOrg<y1) yFinOrg+=ny2;
if( x1 <= x2 && y1 <= y2 )
{
if( bHoriLines )
{
DrawGridFlags nGridFlags = ( bHoriSolid ? DrawGridFlags::HorzLines : DrawGridFlags::Dots );
sal_uInt16 nSteps = sal_uInt16(nx1 / nx2);
sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((nx1 * 1000)/ nSteps) - (nx2 * 1000) ) : 0;
sal_uInt32 nStepOffset = 0;
sal_uInt16 nPointOffset = 0;
for(sal_uInt16 a=0;a<nSteps;a++)
{
// draw
rOut.DrawGrid(
tools::Rectangle( xFinOrg + (a * nx2) + nPointOffset, yBigOrg, x2, y2 ),
Size( nx1, ny1 ), nGridFlags );
// do a step
nStepOffset += nRestPerStepMul1000;
while(nStepOffset >= 1000)
{
nStepOffset -= 1000;
nPointOffset++;
}
}
}
if( bVertLines )
{
DrawGridFlags nGridFlags = ( bVertSolid ? DrawGridFlags::VertLines : DrawGridFlags::Dots );
sal_uInt16 nSteps = sal_uInt16(ny1 / ny2);
sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((ny1 * 1000L)/ nSteps) - (ny2 * 1000L) ) : 0;
sal_uInt32 nStepOffset = 0;
sal_uInt16 nPointOffset = 0;
for(sal_uInt16 a=0;a<nSteps;a++)
{
// draw
rOut.DrawGrid(
tools::Rectangle( xBigOrg, yFinOrg + (a * ny2) + nPointOffset, x2, y2 ),
Size( nx1, ny1 ), nGridFlags );
// do a step
nStepOffset += nRestPerStepMul1000;
while(nStepOffset >= 1000)
{
nStepOffset -= 1000;
nPointOffset++;
}
}
}
}
}
rOut.EnableMapMode(bMap0);
rOut.SetLineColor(aOriginalLineColor);
}
void SdrPageView::AdjHdl()
{
GetView().AdjustMarkHdl();
}
// return true if changed, false if unchanged
bool SdrPageView::SetLayer(const OUString& rName, SdrLayerIDSet& rBS, bool bJa)
{
if (!GetPage())
return false;
SdrLayerID nID = GetPage()->GetLayerAdmin().GetLayerID(rName);
if (SDRLAYER_NOTFOUND == nID)
return false;
if (rBS.IsSet(nID) == bJa)
return false;
rBS.Set(nID, bJa);
return true;
}
bool SdrPageView::IsLayer(const OUString& rName, const SdrLayerIDSet& rBS) const
{
if(!GetPage())
return false;
bool bRet(false);
if (!rName.isEmpty())
{
SdrLayerID nId = GetPage()->GetLayerAdmin().GetLayerID(rName);
if(SDRLAYER_NOTFOUND != nId)
{
bRet = rBS.IsSet(nId);
}
}
return bRet;
}
bool SdrPageView::IsObjMarkable(SdrObject const * pObj) const
{
if (!pObj)
return false;
if (pObj->IsMarkProtect())
return false; // excluded from selection?
if (!pObj->IsVisible())
return false; // only visible are selectable
if (!pObj->IsInserted())
return false; // Obj deleted?
if (auto pObjGroup = dynamic_cast<const SdrObjGroup*>(pObj))
{
// If object is a Group object, visibility may depend on
// multiple layers. If one object is markable, Group is markable.
SdrObjList* pObjList = pObjGroup->GetSubList();
if (pObjList && pObjList->GetObjCount())
{
for (const rtl::Reference<SdrObject>& pCandidate : *pObjList)
{
// call recursively
if (IsObjMarkable(pCandidate.get()))
return true;
}
return false;
}
else
{
// #i43302#
// Allow empty groups to be selected to be able to delete them
return true;
}
}
if (!pObj->Is3DObj() && pObj->getSdrPageFromSdrObject() != GetPage())
{
// Obj suddenly in different Page
return false;
}
// the layer has to be visible and must not be locked
SdrLayerID nL = pObj->GetLayer();
if (!aLayerVisi.IsSet(nL))
return false;
if (aLayerLock.IsSet(nL))
return false;
return true;
}
void SdrPageView::SetPageOrigin(const Point& rOrg)
{
if (rOrg != maPageOrigin)
{
maPageOrigin = rOrg;
if (GetView().IsGridVisible())
{
InvalidateAllWin();
}
}
}
void SdrPageView::ImpInvalidateHelpLineArea(sal_uInt16 nNum) const
{
if (!(GetView().IsHlplVisible() && nNum<aHelpLines.GetCount())) return;
const SdrHelpLine& rHL=aHelpLines[nNum];
for(sal_uInt32 a(0); a < GetView().PaintWindowCount(); a++)
{
SdrPaintWindow* pCandidate = GetView().GetPaintWindow(a);
if(pCandidate->OutputToWindow())
{
OutputDevice& rOutDev = pCandidate->GetOutputDevice();
tools::Rectangle aR(rHL.GetBoundRect(rOutDev));
Size aSiz(rOutDev.PixelToLogic(Size(1,1)));
aR.AdjustLeft( -(aSiz.Width()) );
aR.AdjustRight(aSiz.Width() );
aR.AdjustTop( -(aSiz.Height()) );
aR.AdjustBottom(aSiz.Height() );
const_cast<SdrView&>(GetView()).InvalidateOneWin(rOutDev, aR);
}
}
}
void SdrPageView::SetHelpLines(const SdrHelpLineList& rHLL)
{
aHelpLines=rHLL;
InvalidateAllWin();
}
void SdrPageView::SetHelpLine(sal_uInt16 nNum, const SdrHelpLine& rNewHelpLine)
{
if (nNum >= aHelpLines.GetCount() || aHelpLines[nNum] == rNewHelpLine)
return;
bool bNeedRedraw = true;
if (aHelpLines[nNum].GetKind()==rNewHelpLine.GetKind()) {
switch (rNewHelpLine.GetKind()) {
case SdrHelpLineKind::Vertical : if (aHelpLines[nNum].GetPos().X()==rNewHelpLine.GetPos().X()) bNeedRedraw = false; break;
case SdrHelpLineKind::Horizontal: if (aHelpLines[nNum].GetPos().Y()==rNewHelpLine.GetPos().Y()) bNeedRedraw = false; break;
default: break;
} // switch
}
if (bNeedRedraw) ImpInvalidateHelpLineArea(nNum);
aHelpLines[nNum]=rNewHelpLine;
if (bNeedRedraw) ImpInvalidateHelpLineArea(nNum);
}
void SdrPageView::DeleteHelpLine(sal_uInt16 nNum)
{
if (nNum<aHelpLines.GetCount()) {
ImpInvalidateHelpLineArea(nNum);
aHelpLines.Delete(nNum);
}
}
void SdrPageView::InsertHelpLine(const SdrHelpLine& rHL)
{
sal_uInt16 nNum = aHelpLines.GetCount();
aHelpLines.Insert(rHL,nNum);
if (GetView().IsHlplVisible())
ImpInvalidateHelpLineArea(nNum);
}
// set current group and list
void SdrPageView::SetCurrentGroupAndList(SdrObject* pNewGroup, SdrObjList* pNewList)
{
if(pCurrentGroup != pNewGroup)
{
pCurrentGroup = pNewGroup;
}
if(pCurrentList != pNewList)
{
pCurrentList = pNewList;
}
}
bool SdrPageView::EnterGroup(SdrObject* pObj)
{
if(!pObj || !pObj->IsGroupObject())
return false;
// Don't allow enter Diagrams
if(nullptr != pObj && pObj->isDiagram())
return false;
const bool bGlueInvalidate(GetView().ImpIsGlueVisible());
if (bGlueInvalidate)
{
GetView().GlueInvalidate();
}
// deselect all
GetView().UnmarkAll();
// set current group and list
SdrObjList* pNewObjList = pObj->GetSubList();
SetCurrentGroupAndList(pObj, pNewObjList);
// select contained object if only one object is contained,
// else select nothing and let the user decide what to do next
if(pNewObjList && pNewObjList->GetObjCount() == 1)
{
SdrObject* pFirstObject = pNewObjList->GetObj(0);
if(GetView().GetSdrPageView())
{
GetView().MarkObj(pFirstObject, GetView().GetSdrPageView());
}
}
// build new handles
GetView().AdjustMarkHdl();
// invalidate only when view wants to visualize group entering
InvalidateAllWin();
if (bGlueInvalidate)
{
GetView().GlueInvalidate();
}
return true;
}
void SdrPageView::LeaveOneGroup()
{
SdrObject* pLastGroup = GetCurrentGroup();
if (!pLastGroup)
return;
bool bGlueInvalidate = GetView().ImpIsGlueVisible();
if(bGlueInvalidate)
GetView().GlueInvalidate();
SdrObject* pParentGroup = pLastGroup->getParentSdrObjectFromSdrObject();
SdrObjList* pParentList = GetPage();
if(pParentGroup)
pParentList = pParentGroup->GetSubList();
// deselect everything
GetView().UnmarkAll();
// allocations, pCurrentGroup and pCurrentList need to be set
SetCurrentGroupAndList(pParentGroup, pParentList);
// select the group we just left
if (GetView().GetSdrPageView())
GetView().MarkObj(pLastGroup, GetView().GetSdrPageView());
GetView().AdjustMarkHdl();
// invalidate only if view wants to visualize group entering
InvalidateAllWin();
if(bGlueInvalidate)
GetView().GlueInvalidate();
}
void SdrPageView::LeaveAllGroup()
{
SdrObject* pLastGroup = GetCurrentGroup();
if (!pLastGroup)
return;
bool bGlueInvalidate = GetView().ImpIsGlueVisible();
if(bGlueInvalidate)
GetView().GlueInvalidate();
// deselect everything
GetView().UnmarkAll();
// allocations, pCurrentGroup and pCurrentList always need to be set
SetCurrentGroupAndList(nullptr, GetPage());
// find and select uppermost group
while (pLastGroup->getParentSdrObjectFromSdrObject())
pLastGroup = pLastGroup->getParentSdrObjectFromSdrObject();
if (GetView().GetSdrPageView())
GetView().MarkObj(pLastGroup, GetView().GetSdrPageView());
GetView().AdjustMarkHdl();
// invalidate only when view wants to visualize group entering
InvalidateAllWin();
if(bGlueInvalidate)
GetView().GlueInvalidate();
}
sal_uInt16 SdrPageView::GetEnteredLevel() const
{
sal_uInt16 nCount=0;
SdrObject* pGrp=GetCurrentGroup();
while (pGrp!=nullptr) {
nCount++;
pGrp=pGrp->getParentSdrObjectFromSdrObject();
}
return nCount;
}
void SdrPageView::CheckCurrentGroup()
{
SdrObject* pGrp(GetCurrentGroup());
while(nullptr != pGrp &&
(!pGrp->IsInserted() || nullptr == pGrp->getParentSdrObjListFromSdrObject() || nullptr == pGrp->getSdrPageFromSdrObject()))
{
// anything outside of the borders?
pGrp = pGrp->getParentSdrObjectFromSdrObject();
}
if(pGrp != GetCurrentGroup())
{
if(nullptr != pGrp)
{
EnterGroup(pGrp);
}
else
{
LeaveAllGroup();
}
}
}
// Set background color for svx at SdrPageViews
void SdrPageView::SetApplicationBackgroundColor(Color aBackgroundColor)
{
maBackgroundColor = aBackgroundColor;
}
// Set document color for svx at SdrPageViews
void SdrPageView::SetApplicationDocumentColor(Color aDocumentColor)
{
maDocumentColor = aDocumentColor;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|