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
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207 | /* -*- 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 <memory>
#include <svx/svdpntv.hxx>
#include <vcl/weld.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svl/hint.hxx>
#include <svx/svdview.hxx>
#include <svx/svdglue.hxx>
#include <svx/svdobj.hxx>
#include <sxlayitm.hxx>
#include <svl/itemiter.hxx>
#include <editeng/eeitem.hxx>
#include <svl/whiter.hxx>
#include <svl/style.hxx>
#include <svx/sdrpagewindow.hxx>
#include <vcl/svapp.hxx>
#include <svx/sdr/contact/objectcontact.hxx>
#include <svx/sdr/animation/objectanimator.hxx>
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <comphelper/lok.hxx>
#include <svx/svdviter.hxx>
using namespace ::com::sun::star;
// interface to SdrPaintWindow
SdrPaintWindow* SdrPaintView::FindPaintWindow(const OutputDevice& rOut) const
{
// back to loop - there is more to test than a std::find_if and a lambda can do
for(auto& candidate : maPaintWindows)
{
if(&(candidate->GetOutputDevice()) == &rOut)
{
return candidate.get();
}
// check for patched to allow finding in that state, too
if(nullptr != candidate->getPatched() && &(candidate->getPatched()->GetOutputDevice()) == &rOut)
{
return candidate->getPatched();
}
}
return nullptr;
}
SdrPaintWindow* SdrPaintView::GetPaintWindow(sal_uInt32 nIndex) const
{
return maPaintWindows[nIndex].get();
}
void SdrPaintView::DeletePaintWindow(SdrPaintWindow& rOld)
{
auto aFindResult = ::std::find_if(maPaintWindows.begin(), maPaintWindows.end(),
[&](const std::unique_ptr<SdrPaintWindow>& p) { return p.get() == &rOld; });
if(aFindResult != maPaintWindows.end())
{
maPaintWindows.erase(aFindResult);
}
}
OutputDevice* SdrPaintView::GetFirstOutputDevice() const
{
if(PaintWindowCount())
{
return &(GetPaintWindow(0)->GetOutputDevice());
}
return nullptr;
}
SvxViewChangedHint::SvxViewChangedHint()
{
}
BitmapEx convertMetafileToBitmapEx(
const GDIMetaFile& rMtf,
const basegfx::B2DRange& rTargetRange,
const sal_uInt32 nMaximumQuadraticPixels)
{
BitmapEx aBitmapEx;
if(rMtf.GetActionSize())
{
const drawinglayer::primitive2d::Primitive2DReference aMtf(
new drawinglayer::primitive2d::MetafilePrimitive2D(
basegfx::utils::createScaleTranslateB2DHomMatrix(
rTargetRange.getRange(),
rTargetRange.getMinimum()),
rMtf));
aBitmapEx = convertPrimitive2DSequenceToBitmapEx(
drawinglayer::primitive2d::Primitive2DContainer { aMtf },
rTargetRange,
nMaximumQuadraticPixels);
}
return aBitmapEx;
}
void SdrPaintView::ImpClearVars()
{
mbPageVisible=true;
mbPageShadowVisible=true;
mbPageBorderVisible=true;
mbBordVisible=true;
mbGridVisible=true;
mbGridFront =false;
mbHlplVisible=true;
mbHlplFront =true;
mbGlueVisible=false;
mbGlueVisible2=false;
mbGlueVisible3=false;
mbGlueVisible4=false;
mbSwapAsynchron=false;
mbPrintPreview=false;
mbPreviewRenderer=false;
meAnimationMode = SdrAnimationMode::Animate;
mbAnimationPause = false;
mnHitTolPix=2;
mnMinMovPix=3;
mnHitTolLog=0;
mnMinMovLog=0;
mpActualOutDev=nullptr;
mpDragWin=nullptr;
mpDefaultStyleSheet=nullptr;
mbSomeObjChgdFlag=false;
maComeBackIdle.SetPriority(TaskPriority::REPAINT);
maComeBackIdle.SetInvokeHandler(LINK(this,SdrPaintView,ImpComeBackHdl));
maComeBackIdle.SetDebugName( "svx::SdrPaintView aComeBackIdle" );
if (mpModel)
SetDefaultStyleSheet(mpModel->GetDefaultStyleSheet(), true);
maGridColor = COL_BLACK;
}
SdrPaintView::SdrPaintView(
SdrModel& rSdrModel,
OutputDevice* pOut)
: mrSdrModelFromSdrView(rSdrModel),
maDefaultAttr(rSdrModel.GetItemPool()),
mbBufferedOutputAllowed(false),
mbBufferedOverlayAllowed(false),
mbPagePaintingAllowed(true),
mbHideOle(false),
mbHideChart(false),
mbHideDraw(false),
mbHideFormControl(false)
{
mpModel=&rSdrModel;
ImpClearVars();
if(pOut)
{
AddWindowToPaintView(pOut, nullptr);
}
maColorConfig.AddListener(this);
onChangeColorConfig();
}
SdrPaintView::~SdrPaintView()
{
if (mpDefaultStyleSheet)
EndListening(*mpDefaultStyleSheet);
maColorConfig.RemoveListener(this);
ClearPageView();
// delete existing SdrPaintWindows
maPaintWindows.clear();
}
void SdrPaintView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
//If the stylesheet has been destroyed
if (&rBC == mpDefaultStyleSheet)
{
if (rHint.GetId() == SfxHintId::Dying)
mpDefaultStyleSheet = nullptr;
return;
}
if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
return;
const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint);
SdrHintKind eKind = pSdrHint->GetKind();
if (eKind==SdrHintKind::ObjectChange || eKind==SdrHintKind::ObjectInserted || eKind==SdrHintKind::ObjectRemoved)
{
bool bObjChg = !mbSomeObjChgdFlag; // if true, evaluate for ComeBack timer
if (bObjChg)
{
mbSomeObjChgdFlag=true;
maComeBackIdle.Start();
}
}
if (eKind==SdrHintKind::PageOrderChange)
{
const SdrPage* pPg=pSdrHint->GetPage();
if (pPg && !pPg->IsInserted())
{
if(mpPageView && mpPageView->GetPage() == pPg)
{
HideSdrPage();
}
}
}
}
void SdrPaintView::ConfigurationChanged( ::utl::ConfigurationBroadcaster* , ConfigurationHints )
{
onChangeColorConfig();
InvalidateAllWin();
}
IMPL_LINK_NOARG(SdrPaintView, ImpComeBackHdl, Timer *, void)
{
if (mbSomeObjChgdFlag) {
mbSomeObjChgdFlag=false;
ModelHasChanged();
}
}
void SdrPaintView::FlushComeBackTimer() const
{
if (mbSomeObjChgdFlag) {
// casting to nonconst
const_cast<SdrPaintView*>(this)->ImpComeBackHdl(&const_cast<SdrPaintView*>(this)->maComeBackIdle);
const_cast<SdrPaintView*>(this)->maComeBackIdle.Stop();
}
}
void SdrPaintView::ModelHasChanged()
{
// broadcast to all PageViews
if(mpPageView && !mpPageView->GetPage()->IsInserted())
{
HideSdrPage();
}
// test mpPageView here again, HideSdrPage() may have invalidated it.
if(mpPageView)
{
mpPageView->ModelHasChanged();
}
}
bool SdrPaintView::IsAction() const
{
return false;
}
void SdrPaintView::MovAction(const Point&)
{
}
void SdrPaintView::EndAction()
{
}
void SdrPaintView::BckAction()
{
}
void SdrPaintView::BrkAction()
{
}
void SdrPaintView::TakeActionRect(tools::Rectangle&) const
{
}
// info about TextEdit. Default is false.
bool SdrPaintView::IsTextEdit() const
{
return false;
}
sal_uInt16 SdrPaintView::ImpGetMinMovLogic(short nMinMov, const OutputDevice* pOut) const
{
if (nMinMov>=0) return sal_uInt16(nMinMov);
if (pOut==nullptr)
{
pOut = GetFirstOutputDevice();
}
if (pOut!=nullptr) {
return short(-pOut->PixelToLogic(Size(nMinMov,0)).Width());
} else {
return 0;
}
}
sal_uInt16 SdrPaintView::ImpGetHitTolLogic(short nHitTol, const OutputDevice* pOut) const
{
if (nHitTol>=0) return sal_uInt16(nHitTol);
if (pOut==nullptr)
{
pOut = GetFirstOutputDevice();
}
if (pOut!=nullptr) {
return short(-pOut->PixelToLogic(Size(nHitTol,0)).Width());
} else {
return 0;
}
}
void SdrPaintView::TheresNewMapMode()
{
if (mpActualOutDev) {
mnHitTolLog=static_cast<sal_uInt16>(mpActualOutDev->PixelToLogic(Size(mnHitTolPix,0)).Width());
mnMinMovLog=static_cast<sal_uInt16>(mpActualOutDev->PixelToLogic(Size(mnMinMovPix,0)).Width());
}
}
void SdrPaintView::SetActualWin(const OutputDevice* pWin)
{
mpActualOutDev = const_cast<OutputDevice *>(pWin);
TheresNewMapMode();
}
void SdrPaintView::ClearPageView()
{
BrkAction();
if(mpPageView)
{
InvalidateAllWin();
mpPageView.reset();
}
}
SdrPageView* SdrPaintView::ShowSdrPage(SdrPage* pPage)
{
if(pPage && (!mpPageView || mpPageView->GetPage() != pPage))
{
if(mpPageView)
{
InvalidateAllWin();
mpPageView.reset();
}
mpPageView.reset(new SdrPageView(pPage, *static_cast<SdrView*>(this)));
mpPageView->Show();
}
return mpPageView.get();
}
void SdrPaintView::HideSdrPage()
{
if(mpPageView)
{
mpPageView->Hide();
mpPageView.reset();
}
}
void SdrPaintView::AddWindowToPaintView(OutputDevice* pNewWin, vcl::Window *pWindow)
{
DBG_ASSERT(pNewWin, "SdrPaintView::AddWindowToPaintView: No OutputDevice(!)");
SdrPaintWindow* pNewPaintWindow = new SdrPaintWindow(*this, *pNewWin, pWindow);
maPaintWindows.emplace_back(pNewPaintWindow);
if(mpPageView)
{
mpPageView->AddPaintWindowToPageView(*pNewPaintWindow);
}
}
void SdrPaintView::DeleteWindowFromPaintView(OutputDevice* pOldWin)
{
assert(pOldWin && "SdrPaintView::DeleteWindowFromPaintView: No OutputDevice(!)");
SdrPaintWindow* pCandidate = FindPaintWindow(*pOldWin);
if(pCandidate)
{
if(mpPageView)
{
mpPageView->RemovePaintWindowFromPageView(*pCandidate);
}
DeletePaintWindow(*pCandidate);
}
}
void SdrPaintView::SetLayerVisible(const OUString& rName, bool bShow)
{
if(mpPageView)
{
mpPageView->SetLayerVisible(rName, bShow);
}
InvalidateAllWin();
}
bool SdrPaintView::IsLayerVisible(const OUString& rName) const
{
if(mpPageView)
{
return mpPageView->IsLayerVisible(rName);
}
return false;
}
void SdrPaintView::SetLayerLocked(const OUString& rName, bool bLock)
{
if(mpPageView)
{
mpPageView->SetLayerLocked(rName,bLock);
}
}
bool SdrPaintView::IsLayerLocked(const OUString& rName) const
{
if(mpPageView)
{
return mpPageView->IsLayerLocked(rName);
}
return false;
}
void SdrPaintView::SetLayerPrintable(const OUString& rName, bool bPrn)
{
if(mpPageView)
{
mpPageView->SetLayerPrintable(rName,bPrn);
}
}
bool SdrPaintView::IsLayerPrintable(const OUString& rName) const
{
if(mpPageView)
{
return mpPageView->IsLayerPrintable(rName);
}
return false;
}
void SdrPaintView::PrePaint()
{
if(mpPageView)
{
mpPageView->PrePaint();
}
}
// #define SVX_REPAINT_TIMER_TEST
void SdrPaintView::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
{
#ifdef SVX_REPAINT_TIMER_TEST
#define REMEMBERED_TIMES_COUNT (10)
static bool bDoTimerTest(false);
static bool bTimesInited(false);<--- The scope of the variable 'bTimesInited' can be reduced. [+]The scope of the variable 'bTimesInited' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
static sal_uInt32 nRepeatCount(10);
static double fLastTimes[REMEMBERED_TIMES_COUNT];
const sal_uInt64 nStartTime(tools::Time::GetSystemTicks());
sal_uInt32 count(1);
sal_uInt32 a;
if(bDoTimerTest)
{
count = nRepeatCount;
}
for(a = 0; a < count; a++)
{
#endif // SVX_REPAINT_TIMER_TEST
// #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
// rReg may be made more granular (fine) with using it. Normally, rReg
// does come from Window::Paint() anyways and thus is based on a single
// rectangle which was derived from exactly that repaint region
vcl::Region aOptimizedRepaintRegion(rReg);
if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType())
{
vcl::Window* pWindow = static_cast<vcl::Window*>(pOut);
if(pWindow->IsInPaint())
{
if(!pWindow->GetPaintRegion().IsEmpty())
{
aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
}
}
}
SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
OSL_ENSURE(pPaintWindow, "SdrPaintView::CompleteRedraw: No OutDev (!)");
DoCompleteRedraw(*pPaintWindow, aOptimizedRepaintRegion, pRedirector);
EndCompleteRedraw(*pPaintWindow, true);
#ifdef SVX_REPAINT_TIMER_TEST
}
if(bDoTimerTest)
{
const sal_uInt64 nStopTime(tools::Time::GetSystemTicks());
const sal_uInt64 nNeededTime(nStopTime - nStartTime);
const double fTimePerPaint((double)nNeededTime / (double)nRepeatCount);
if(!bTimesInited)
{
for(a = 0; a < REMEMBERED_TIMES_COUNT; a++)
{
fLastTimes[a] = fTimePerPaint;
}
bTimesInited = true;
}
else
{
for(a = 1; a < REMEMBERED_TIMES_COUNT; a++)
{
fLastTimes[a - 1] = fLastTimes[a];
}
fLastTimes[REMEMBERED_TIMES_COUNT - 1] = fTimePerPaint;
}
double fAddedTimes(0.0);
for(a = 0; a < REMEMBERED_TIMES_COUNT; a++)
{
fAddedTimes += fLastTimes[a];
}
const double fAverageTimePerPaint(fAddedTimes / (double)REMEMBERED_TIMES_COUNT);
fprintf(stderr, "-----------(start result)----------\n");
fprintf(stderr, "StartTime : %" SAL_PRIuUINT64 ", StopTime: %" SAL_PRIuUINT64 ", NeededTime: %" SAL_PRIuUINT64 ", TimePerPaint: %f\n", nStartTime, nStopTime, nNeededTime, fTimePerPaint);
fprintf(stderr, "Remembered times: ");
for(a = 0; a < REMEMBERED_TIMES_COUNT; a++)
{
fprintf(stderr, "%d: %f ", a, fLastTimes[a]);
}
fprintf(stderr, "\n");
fprintf(stderr, "AverageTimePerPaint: %f\n", fAverageTimePerPaint);
fprintf(stderr, "-----------(stop result)----------\n");
}
#endif // SVX_REPAINT_TIMER_TEST
}
// #i72889#
SdrPaintWindow* SdrPaintView::BeginCompleteRedraw(OutputDevice* pOut)
{
OSL_ENSURE(pOut, "SdrPaintView::BeginCompleteRedraw: No OutDev (!)");
SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
if(pPaintWindow)
{
// draw preprocessing, only for known devices
// prepare PreRendering
pPaintWindow->PreparePreRenderDevice();
}
else
{
// None of the known OutputDevices is the target of this paint, use
// a temporary SdrPaintWindow for this Redraw.
pPaintWindow = new SdrPaintWindow(*this, *pOut);
pPaintWindow->setTemporaryTarget(true);
}
return pPaintWindow;
}
void SdrPaintView::DoCompleteRedraw(SdrPaintWindow& rPaintWindow, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
{
// redraw all PageViews with the target. This may expand the RedrawRegion
// at the PaintWindow, plus taking care of FormLayer expansion
if(mpPageView)
{
mpPageView->CompleteRedraw(rPaintWindow, rReg, pRedirector);
}
}
void SdrPaintView::EndCompleteRedraw(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
{
std::unique_ptr<SdrPaintWindow> pPaintWindow;
if (comphelper::LibreOfficeKit::isActive() && rPaintWindow.getTemporaryTarget())
{
// Tiled rendering, we must paint the TextEdit to the output device.
pPaintWindow.reset(&rPaintWindow);
pPaintWindow->setTemporaryTarget(false);
}
if(rPaintWindow.getTemporaryTarget())
{
// get rid of temp target again
delete &rPaintWindow;
}
else
{
// draw postprocessing, only for known devices
// it is necessary to always paint FormLayer
if(bPaintFormLayer)
{
ImpFormLayerDrawing(rPaintWindow);
}
// look for active TextEdit. As long as this cannot be painted to a VDev,
// it cannot get part of buffering. In that case, output evtl. prerender
// early and paint text edit to window.
if(IsTextEdit() && GetSdrPageView())
{
static_cast< SdrView* >(this)->TextEditDrawing(rPaintWindow);
}
if (comphelper::LibreOfficeKit::isActive())
{
// Look for active text edits in other views showing the same page,
// and show them as well.
if (SdrPageView* pPageView = GetSdrPageView())
{
SdrViewIter aIter(pPageView->GetPage());
for (SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView())
{
if (pView == this)
continue;
if (pView->IsTextEdit() && pView->GetSdrPageView())
{
pView->TextEditDrawing(rPaintWindow);
}
}
}
}
// draw Overlay, also to PreRender device if exists
rPaintWindow.DrawOverlay(rPaintWindow.GetRedrawRegion());
// output PreRendering
rPaintWindow.OutputPreRenderDevice(rPaintWindow.GetRedrawRegion());
}
}
SdrPaintWindow* SdrPaintView::BeginDrawLayers(OutputDevice* pOut, const vcl::Region& rReg, bool bDisableIntersect)
{
// #i74769# use BeginCompleteRedraw() as common base
SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
OSL_ENSURE(pPaintWindow, "SdrPaintView::BeginDrawLayers: No SdrPaintWindow (!)");
if(mpPageView)
{
SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(*pPaintWindow);
if(pKnownTarget)
{
vcl::Region aOptimizedRepaintRegion = OptimizeDrawLayersRegion( pOut, rReg, bDisableIntersect );
// prepare redraw
pKnownTarget->PrepareRedraw(aOptimizedRepaintRegion);
// remember prepared SdrPageWindow
mpPageView->setPreparedPageWindow(pKnownTarget);
}
}
return pPaintWindow;
}
void SdrPaintView::EndDrawLayers(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
{
// #i74769# use EndCompleteRedraw() as common base
EndCompleteRedraw(rPaintWindow, bPaintFormLayer);
if(mpPageView)
{
// forget prepared SdrPageWindow
mpPageView->setPreparedPageWindow(nullptr);
}
}
void SdrPaintView::UpdateDrawLayersRegion(OutputDevice* pOut, const vcl::Region& rReg)
{
SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
OSL_ENSURE(pPaintWindow, "SdrPaintView::UpdateDrawLayersRegion: No SdrPaintWindow (!)");
if(mpPageView)
{
SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(*pPaintWindow);
if(pKnownTarget)
{
vcl::Region aOptimizedRepaintRegion = OptimizeDrawLayersRegion( pOut, rReg, false/*bDisableIntersect*/ );
pKnownTarget->GetPaintWindow().SetRedrawRegion(aOptimizedRepaintRegion);
mpPageView->setPreparedPageWindow(pKnownTarget); // already set actually
}
}
}
vcl::Region SdrPaintView::OptimizeDrawLayersRegion(OutputDevice* pOut, const vcl::Region& rReg, bool bDisableIntersect)
{
// #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
// rReg may be made more granular (fine) with using it. Normally, rReg
// does come from Window::Paint() anyways and thus is based on a single
// rectangle which was derived from exactly that repaint region
vcl::Region aOptimizedRepaintRegion(rReg);
// #i76114# Intersecting the region with the Window's paint region is disabled
// for print preview in Calc, because the intersection can be empty (if the paint
// region is outside of the table area of the page), and then no clip region
// would be set.
if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType() && !bDisableIntersect)
{
vcl::Window* pWindow = static_cast<vcl::Window*>(pOut);
if(pWindow->IsInPaint())
{
if(!pWindow->GetPaintRegion().IsEmpty())
{
aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
}
}
}
return aOptimizedRepaintRegion;
}
void SdrPaintView::ImpFormLayerDrawing( SdrPaintWindow& rPaintWindow )
{
if(mpPageView)
{
SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(rPaintWindow);
if(pKnownTarget)
{
const SdrModel& rModel = *(GetModel());
const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName());
// BUFFERED use GetTargetOutputDevice() now, it may be targeted to VDevs, too
// need to set PreparedPageWindow to make DrawLayer use the correct ObjectContact
mpPageView->setPreparedPageWindow(pKnownTarget);
mpPageView->DrawLayer(nControlLayerId, &rPaintWindow.GetTargetOutputDevice());
mpPageView->setPreparedPageWindow(nullptr);
}
}
}
bool SdrPaintView::KeyInput(const KeyEvent& /*rKEvt*/, vcl::Window* /*pWin*/)
{
return false;
}
void SdrPaintView::GlueInvalidate() const
{
const sal_uInt32 nWindowCount(PaintWindowCount());
for(sal_uInt32 nWinNum(0); nWinNum < nWindowCount; nWinNum++)
{
SdrPaintWindow* pPaintWindow = GetPaintWindow(nWinNum);
if(pPaintWindow->OutputToWindow())
{
OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
if(mpPageView)
{
const SdrObjList* pOL=mpPageView->GetObjList();
const size_t nObjCount = pOL->GetObjCount();
for (size_t nObjNum=0; nObjNum<nObjCount; ++nObjNum) {
const SdrObject* pObj=pOL->GetObj(nObjNum);
const SdrGluePointList* pGPL=pObj->GetGluePointList();
if (pGPL!=nullptr && pGPL->GetCount()!=0) {
pGPL->Invalidate(static_cast<vcl::Window&>(rOutDev), pObj);
}
}
}
}
}
}
void SdrPaintView::InvalidateAllWin()
{
const sal_uInt32 nWindowCount(PaintWindowCount());
for(sal_uInt32 a(0); a < nWindowCount; a++)
{
SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
if(pPaintWindow->OutputToWindow())
{
InvalidateOneWin(pPaintWindow->GetOutputDevice());
}
}
}
void SdrPaintView::InvalidateAllWin(const tools::Rectangle& rRect)
{
const sal_uInt32 nWindowCount(PaintWindowCount());
for(sal_uInt32 a(0); a < nWindowCount; a++)
{
SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
if(pPaintWindow->OutputToWindow())
{
OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
tools::Rectangle aRect(rRect);
Point aOrg(rOutDev.GetMapMode().GetOrigin());
aOrg.setX(-aOrg.X() ); aOrg.setY(-aOrg.Y() );
tools::Rectangle aOutRect(aOrg, rOutDev.GetOutputSize());
// In case of tiled rendering we want to get all invalidations, so visual area is not interesting.
if (aRect.IsOver(aOutRect) || comphelper::LibreOfficeKit::isActive())
{
InvalidateOneWin(rOutDev, aRect);
}
}
}
}
void SdrPaintView::InvalidateOneWin(OutputDevice& rDevice)
{
vcl::Window& rWin(static_cast<vcl::Window&>(rDevice));
// do not erase background, that causes flicker (!)
rWin.Invalidate(InvalidateFlags::NoErase);
}
void SdrPaintView::InvalidateOneWin(OutputDevice& rDevice, const tools::Rectangle& rRect)
{
vcl::Window& rWin(static_cast<vcl::Window&>(rDevice));
// do not erase background, that causes flicker (!)
rWin.Invalidate(rRect, InvalidateFlags::NoErase);
}
void SdrPaintView::LeaveOneGroup()
{
if(mpPageView)
{
mpPageView->LeaveOneGroup();
}
}
void SdrPaintView::LeaveAllGroup()
{
if(mpPageView)
{
mpPageView->LeaveAllGroup();
}
}
bool SdrPaintView::IsGroupEntered() const
{
if(mpPageView)
{
return (mpPageView->GetEnteredLevel() != 0);
}
return false;
}
void SdrPaintView::SetNotPersistDefaultAttr(const SfxItemSet& rAttr)
{
// bReplaceAll has no effect here at all.
bool bMeasure= dynamic_cast<const SdrView*>(this) != nullptr && static_cast<SdrView*>(this)->IsMeasureTool();
const SfxPoolItem *pPoolItem=nullptr;
if (rAttr.GetItemState(SDRATTR_LAYERID,true,&pPoolItem)==SfxItemState::SET) {
SdrLayerID nLayerId=static_cast<const SdrLayerIdItem*>(pPoolItem)->GetValue();
const SdrLayer* pLayer=mpModel->GetLayerAdmin().GetLayerPerID(nLayerId);
if (pLayer!=nullptr) {
if (bMeasure) maMeasureLayer=pLayer->GetName();
else maActualLayer=pLayer->GetName();
}
}
if (rAttr.GetItemState(SDRATTR_LAYERNAME,true,&pPoolItem)==SfxItemState::SET) {
if (bMeasure) maMeasureLayer=static_cast<const SdrLayerNameItem*>(pPoolItem)->GetValue();
else maActualLayer=static_cast<const SdrLayerNameItem*>(pPoolItem)->GetValue();
}
}
void SdrPaintView::MergeNotPersistDefaultAttr(SfxItemSet& rAttr) const
{
// bOnlyHardAttr has no effect here at all.
bool bMeasure= dynamic_cast<const SdrView*>(this) != nullptr && static_cast<const SdrView*>(this)->IsMeasureTool();
const OUString& aNam = bMeasure ? maMeasureLayer : maActualLayer;
rAttr.Put(SdrLayerNameItem(aNam));
SdrLayerID nLayer=mpModel->GetLayerAdmin().GetLayerID(aNam);
if (nLayer!=SDRLAYER_NOTFOUND) {
rAttr.Put(SdrLayerIdItem(nLayer));
}
}
void SdrPaintView::SetDefaultAttr(const SfxItemSet& rAttr, bool bReplaceAll)
{
#ifdef DBG_UTIL
{
bool bHasEEFeatureItems=false;
SfxItemIter aIter(rAttr);
for (const SfxPoolItem* pItem = aIter.GetCurItem(); !bHasEEFeatureItems && pItem;
pItem = aIter.NextItem())
{
if (!IsInvalidItem(pItem)) {
sal_uInt16 nW=pItem->Which();
if (nW>=EE_FEATURE_START && nW<=EE_FEATURE_END) bHasEEFeatureItems=true;
}
}
if(bHasEEFeatureItems)
{
std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Info, VclButtonsType::Ok,
"SdrPaintView::SetDefaultAttr(): Setting EE_FEATURE items at the SdrView does not make sense! It only leads to overhead and unreadable documents."));
xInfoBox->run();
}
}
#endif
if (bReplaceAll) maDefaultAttr.Set(rAttr);
else maDefaultAttr.Put(rAttr,false); // if FALSE, regard InvalidItems as "holes," not as Default
SetNotPersistDefaultAttr(rAttr);
}
void SdrPaintView::SetDefaultStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
{
if (mpDefaultStyleSheet)
EndListening(*mpDefaultStyleSheet);
mpDefaultStyleSheet=pStyleSheet;
if (mpDefaultStyleSheet)
StartListening(*mpDefaultStyleSheet);
if (pStyleSheet!=nullptr && !bDontRemoveHardAttr) {
SfxWhichIter aIter(pStyleSheet->GetItemSet());
sal_uInt16 nWhich=aIter.FirstWhich();
while (nWhich!=0) {
if (pStyleSheet->GetItemSet().GetItemState(nWhich)==SfxItemState::SET) {
maDefaultAttr.ClearItem(nWhich);
}
nWhich=aIter.NextWhich();
}
}
}
void SdrPaintView::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const
{
if(bOnlyHardAttr || !mpDefaultStyleSheet)
{
rTargetSet.Put(maDefaultAttr, false);
}
else
{
// else merge with DefStyleSheet
rTargetSet.Put(mpDefaultStyleSheet->GetItemSet(), false);
rTargetSet.Put(maDefaultAttr, false);
}
MergeNotPersistDefaultAttr(rTargetSet);
}
void SdrPaintView::SetAttributes(const SfxItemSet& rSet, bool bReplaceAll)
{
SetDefaultAttr(rSet,bReplaceAll);
}
SfxStyleSheet* SdrPaintView::GetStyleSheet() const
{
return mpDefaultStyleSheet;
}
void SdrPaintView::SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
{
SetDefaultStyleSheet(pStyleSheet,bDontRemoveHardAttr);
}
void SdrPaintView::MakeVisible(const tools::Rectangle& rRect, vcl::Window& rWin)
{
// TODO: handle when the text cursor goes out of the chart area
// However this hack avoids that the cursor gets misplaced wrt the text.
if (comphelper::LibreOfficeKit::isActive() && rWin.IsChart())
{
return;
}
MapMode aMap(rWin.GetMapMode());
Size aActualSize(rWin.GetOutputSize());
if( aActualSize.IsEmpty() )
return;
Size aNewSize(rRect.GetSize());
bool bNewScale=false;
bool bNeedMoreX=aNewSize.Width()>aActualSize.Width();
bool bNeedMoreY=aNewSize.Height()>aActualSize.Height();
if (bNeedMoreX || bNeedMoreY)
{
bNewScale=true;
// set new MapMode (Size+Org) and invalidate everything
Fraction aXFact(aNewSize.Width(),aActualSize.Width());
Fraction aYFact(aNewSize.Height(),aActualSize.Height());
if (aYFact>aXFact) aXFact=aYFact;
aXFact*=aMap.GetScaleX();
aXFact.ReduceInaccurate(10); // to avoid runovers and BigInt mapping
aMap.SetScaleX(aXFact);
aMap.SetScaleY(aYFact);
rWin.SetMapMode(aMap);
aActualSize=rWin.GetOutputSize();
}
Point aOrg(aMap.GetOrigin());
long dx=0,dy=0;
long l=-aOrg.X();
long r=-aOrg.X()+aActualSize.Width()-1;
long o=-aOrg.Y();
long u=-aOrg.Y()+aActualSize.Height()-1;
if (l>rRect.Left()) dx=rRect.Left()-l;
else if (r<rRect.Right()) dx=rRect.Right()-r;
if (o>rRect.Top()) dy=rRect.Top()-o;
else if (u<rRect.Bottom()) dy=rRect.Bottom()-u;
aMap.SetOrigin(Point(aOrg.X()-dx,aOrg.Y()-dy));
if (!bNewScale) {
if (dx!=0 || dy!=0) {
rWin.Scroll(-dx,-dy);
rWin.SetMapMode(aMap);
rWin.PaintImmediately();
}
} else {
rWin.SetMapMode(aMap);
InvalidateOneWin(rWin);
}
}
void SdrPaintView::DoConnect(SdrOle2Obj* /*pOleObj*/)
{
}
void SdrPaintView::SetAnimationEnabled( bool bEnable )
{
SetAnimationMode( bEnable ? SdrAnimationMode::Animate : SdrAnimationMode::Disable );
}
void SdrPaintView::SetAnimationPause( bool bSet )
{
if(mbAnimationPause != bSet)
{
mbAnimationPause = bSet;
if(mpPageView)
{
for(sal_uInt32 b(0); b < mpPageView->PageWindowCount(); b++)
{
SdrPageWindow& rPageWindow = *(mpPageView->GetPageWindow(b));
sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
if(rAnimator.IsPaused() != bSet)
{
rAnimator.SetPaused(bSet);
}
}
}
}
}
void SdrPaintView::SetAnimationMode( const SdrAnimationMode eMode )
{
meAnimationMode = eMode;
}
void SdrPaintView::VisAreaChanged(const OutputDevice* pOut)
{
if(mpPageView)
{
if (pOut)
{
SdrPageWindow* pWindow = mpPageView->FindPageWindow(*const_cast<OutputDevice*>(pOut));
if(pWindow)
{
VisAreaChanged();
}
}
else
{
VisAreaChanged();
}
}
}
void SdrPaintView::VisAreaChanged()
{
// notify SfxListener
Broadcast(SvxViewChangedHint());
}
void SdrPaintView::onChangeColorConfig()
{
maGridColor = maColorConfig.GetColorValue( svtools::DRAWGRID ).nColor;
}
// Set background color for svx at SdrPageViews
void SdrPaintView::SetApplicationBackgroundColor(Color aBackgroundColor)
{
if(mpPageView)
{
mpPageView->SetApplicationBackgroundColor(aBackgroundColor);
}
}
// Set document color for svx at SdrPageViews
void SdrPaintView::SetApplicationDocumentColor(Color aDocumentColor)
{
if(mpPageView)
{
mpPageView->SetApplicationDocumentColor(aDocumentColor);
}
}
bool SdrPaintView::IsBufferedOutputAllowed() const
{
return (mbBufferedOutputAllowed && maDrawinglayerOpt.IsPaintBuffer());
}
void SdrPaintView::SetBufferedOutputAllowed(bool bNew)
{
if(bNew != mbBufferedOutputAllowed)
{
mbBufferedOutputAllowed = bNew;
}
}
bool SdrPaintView::IsBufferedOverlayAllowed() const
{
return (mbBufferedOverlayAllowed && maDrawinglayerOpt.IsOverlayBuffer());
}
void SdrPaintView::SetBufferedOverlayAllowed(bool bNew)
{
if(bNew != mbBufferedOverlayAllowed)
{
mbBufferedOverlayAllowed = bNew;
}
}
void SdrPaintView::SetPagePaintingAllowed(bool bNew)
{
if(bNew != mbPagePaintingAllowed)
{
mbPagePaintingAllowed = bNew;
}
}
// #i38135# Sets the timer for Object animations and restarts.
void SdrPaintView::SetAnimationTimer(sal_uInt32 nTime)
{
if(mpPageView)
{
// first, reset all timers at all windows to 0L
for(sal_uInt32 a(0); a < mpPageView->PageWindowCount(); a++)
{
SdrPageWindow& rPageWindow = *mpPageView->GetPageWindow(a);
sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
rAnimator.SetTime(nTime);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|