1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/svdpntv.hxx>
22 #include <vcl/weld.hxx>
23 #include <vcl/window.hxx>
24 #include <svx/sdrpaintwindow.hxx>
25 #include <svx/svdmodel.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdpagv.hxx>
29 #include <svl/hint.hxx>
31 #include <svx/svdview.hxx>
32 #include <svx/svdglue.hxx>
33 #include <svx/svdobj.hxx>
34 #include <sxlayitm.hxx>
35 #include <svl/itemiter.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <svl/whiter.hxx>
38 #include <svl/style.hxx>
39 #include <svx/sdrpagewindow.hxx>
40 #include <vcl/svapp.hxx>
41 #include <svx/sdr/contact/objectcontact.hxx>
42 #include <svx/sdr/animation/objectanimator.hxx>
43 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
44 #include <drawinglayer/converters.hxx>
45 #include <basegfx/matrix/b2dhommatrixtools.hxx>
46 #include <comphelper/lok.hxx>
47 #include <svx/svdviter.hxx>
48 #include <svtools/optionsdrawinglayer.hxx>
49 #include <osl/diagnose.h>
51 using namespace ::com::sun::star
;
53 // interface to SdrPaintWindow
55 SdrPaintWindow
* SdrPaintView::FindPaintWindow(const OutputDevice
& rOut
) const
57 // back to loop - there is more to test than a std::find_if and a lambda can do
58 for(auto& candidate
: maPaintWindows
)
60 if(&(candidate
->GetOutputDevice()) == &rOut
)
62 return candidate
.get();
65 // check for patched to allow finding in that state, too
66 if(nullptr != candidate
->getPatched() && &(candidate
->getPatched()->GetOutputDevice()) == &rOut
)
68 return candidate
->getPatched();
75 SdrPaintWindow
* SdrPaintView::GetPaintWindow(sal_uInt32 nIndex
) const
77 return maPaintWindows
[nIndex
].get();
80 void SdrPaintView::DeletePaintWindow(const SdrPaintWindow
& rOld
)
82 auto aFindResult
= ::std::find_if(maPaintWindows
.begin(), maPaintWindows
.end(),
83 [&](const std::unique_ptr
<SdrPaintWindow
>& p
) { return p
.get() == &rOld
; });
85 if(aFindResult
!= maPaintWindows
.end())
87 maPaintWindows
.erase(aFindResult
);
91 OutputDevice
* SdrPaintView::GetFirstOutputDevice() const
93 if(PaintWindowCount())
95 return &(GetPaintWindow(0)->GetOutputDevice());
102 SvxViewChangedHint::SvxViewChangedHint() : SfxHint(SfxHintId::SvxViewChanged
)
107 BitmapEx
convertMetafileToBitmapEx(
108 const GDIMetaFile
& rMtf
,
109 const basegfx::B2DRange
& rTargetRange
,
110 const sal_uInt32 nMaximumQuadraticPixels
)
114 if(rMtf
.GetActionSize())
116 const drawinglayer::primitive2d::Primitive2DReference
aMtf(
117 new drawinglayer::primitive2d::MetafilePrimitive2D(
118 basegfx::utils::createScaleTranslateB2DHomMatrix(
119 rTargetRange
.getRange(),
120 rTargetRange
.getMinimum()),
122 aBitmapEx
= drawinglayer::convertPrimitive2DContainerToBitmapEx(
123 drawinglayer::primitive2d::Primitive2DContainer
{ aMtf
},
125 nMaximumQuadraticPixels
);
131 SdrPaintView::SdrPaintView(SdrModel
& rSdrModel
, OutputDevice
* pOut
)
133 , mpActualOutDev(nullptr)
135 , mpDefaultStyleSheet(nullptr)
136 , maDefaultAttr(rSdrModel
.GetItemPool())
137 , maComeBackIdle( "svx::SdrPaintView aComeBackIdle" )
138 , meAnimationMode(SdrAnimationMode::Animate
)
143 , mbPageVisible(true)
144 , mbPageShadowVisible(true)
145 , mbPageBorderVisible(true)
146 , mbBordVisible(true)
147 , mbGridVisible(true)
149 , mbHlplVisible(true)
151 , mbGlueVisible(false)
152 , mbGlueVisible2(false)
153 , mbGlueVisible3(false)
154 , mbGlueVisible4(false)
155 , mbSomeObjChgdFlag(false)
156 , mbSwapAsynchron(false)
157 , mbPrintPreview(false)
158 , mbAnimationPause(false)
159 , mbBufferedOutputAllowed(false)
160 , mbBufferedOverlayAllowed(false)
161 , mbPagePaintingAllowed(true)
162 , mbPreviewRenderer(false)
166 , mbHideFormControl(false)
167 , mbPaintTextEdit(true)
168 , maGridColor(COL_BLACK
)
170 maComeBackIdle
.SetPriority(TaskPriority::REPAINT
);
171 maComeBackIdle
.SetInvokeHandler(LINK(this,SdrPaintView
,ImpComeBackHdl
));
173 SetDefaultStyleSheet(GetModel().GetDefaultStyleSheet(), true);
176 AddDeviceToPaintView(*pOut
, nullptr);
178 maColorConfig
.AddListener(this);
179 onChangeColorConfig();
182 SdrPaintView::~SdrPaintView()
184 if (mpDefaultStyleSheet
)
185 EndListening(*mpDefaultStyleSheet
);
187 maColorConfig
.RemoveListener(this);
190 // delete existing SdrPaintWindows
191 maPaintWindows
.clear();
195 void SdrPaintView::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
197 //If the stylesheet has been destroyed
198 if (&rBC
== mpDefaultStyleSheet
)
200 if (rHint
.GetId() == SfxHintId::Dying
)
201 mpDefaultStyleSheet
= nullptr;
205 if (rHint
.GetId() != SfxHintId::ThisIsAnSdrHint
)
207 const SdrHint
* pSdrHint
= static_cast<const SdrHint
*>(&rHint
);
208 SdrHintKind eKind
= pSdrHint
->GetKind();
209 if (eKind
==SdrHintKind::ObjectChange
|| eKind
==SdrHintKind::ObjectInserted
|| eKind
==SdrHintKind::ObjectRemoved
)
211 bool bObjChg
= !mbSomeObjChgdFlag
; // if true, evaluate for ComeBack timer
214 mbSomeObjChgdFlag
=true;
215 maComeBackIdle
.Start();
219 if (eKind
==SdrHintKind::PageOrderChange
)
221 const SdrPage
* pPg
=pSdrHint
->GetPage();
222 if (pPg
&& !pPg
->IsInserted())
224 if(mpPageView
&& mpPageView
->GetPage() == pPg
)
232 void SdrPaintView::ConfigurationChanged( ::utl::ConfigurationBroadcaster
* , ConfigurationHints
)
234 onChangeColorConfig();
238 IMPL_LINK_NOARG(SdrPaintView
, ImpComeBackHdl
, Timer
*, void)
240 if (mbSomeObjChgdFlag
) {
241 mbSomeObjChgdFlag
=false;
246 void SdrPaintView::FlushComeBackTimer() const
248 if (mbSomeObjChgdFlag
) {
249 // casting to nonconst
250 const_cast<SdrPaintView
*>(this)->ImpComeBackHdl(&const_cast<SdrPaintView
*>(this)->maComeBackIdle
);
251 const_cast<SdrPaintView
*>(this)->maComeBackIdle
.Stop();
255 void SdrPaintView::ModelHasChanged()
257 // broadcast to all PageViews
258 if(mpPageView
&& !mpPageView
->GetPage()->IsInserted())
263 // test mpPageView here again, HideSdrPage() may have invalidated it.
266 mpPageView
->ModelHasChanged();
271 bool SdrPaintView::IsAction() const
276 void SdrPaintView::MovAction(const Point
&)
280 void SdrPaintView::EndAction()
284 void SdrPaintView::BckAction()
288 void SdrPaintView::BrkAction()
292 void SdrPaintView::TakeActionRect(tools::Rectangle
&) const
297 // info about TextEdit. Default is false.
298 bool SdrPaintView::IsTextEdit() const
303 sal_uInt16
SdrPaintView::ImpGetMinMovLogic(short nMinMov
, const OutputDevice
* pOut
) const
305 if (nMinMov
>=0) return sal_uInt16(nMinMov
);
308 pOut
= GetFirstOutputDevice();
311 return short(-pOut
->PixelToLogic(Size(nMinMov
,0)).Width());
317 sal_uInt16
SdrPaintView::ImpGetHitTolLogic(short nHitTol
, const OutputDevice
* pOut
) const
319 if (nHitTol
>=0) return sal_uInt16(nHitTol
);
322 pOut
= GetFirstOutputDevice();
325 return short(-pOut
->PixelToLogic(Size(nHitTol
,0)).Width());
331 void SdrPaintView::TheresNewMapMode()
333 if (mpActualOutDev
) {
334 mnHitTolLog
=static_cast<sal_uInt16
>(mpActualOutDev
->PixelToLogic(Size(mnHitTolPix
,0)).Width());
335 mnMinMovLog
=static_cast<sal_uInt16
>(mpActualOutDev
->PixelToLogic(Size(mnMinMovPix
,0)).Width());
339 void SdrPaintView::SetActualWin(const OutputDevice
* pWin
)
341 mpActualOutDev
= const_cast<OutputDevice
*>(pWin
);
346 void SdrPaintView::ClearPageView()
357 SdrPageView
* SdrPaintView::ShowSdrPage(SdrPage
* pPage
)
359 if(pPage
&& (!mpPageView
|| mpPageView
->GetPage() != pPage
))
367 if (SdrView
*pView
= dynamic_cast<SdrView
*>(this))
369 mpPageView
.reset(new SdrPageView(pPage
, *pView
));
374 return mpPageView
.get();
377 void SdrPaintView::HideSdrPage()
386 void SdrPaintView::AddDeviceToPaintView(OutputDevice
& rNewDev
, vcl::Window
*pWindow
)
388 SdrPaintWindow
* pNewPaintWindow
= new SdrPaintWindow(*this, rNewDev
, pWindow
);
389 maPaintWindows
.emplace_back(pNewPaintWindow
);
393 mpPageView
->AddPaintWindowToPageView(*pNewPaintWindow
);
397 void SdrPaintView::DeleteDeviceFromPaintView(OutputDevice
& rOldDev
)
399 SdrPaintWindow
* pCandidate
= FindPaintWindow(rOldDev
);
405 mpPageView
->RemovePaintWindowFromPageView(*pCandidate
);
408 DeletePaintWindow(*pCandidate
);
412 void SdrPaintView::SetLayerVisible(const OUString
& rName
, bool bShow
)
416 mpPageView
->SetLayerVisible(rName
, bShow
);
422 bool SdrPaintView::IsLayerVisible(const OUString
& rName
) const
426 return mpPageView
->IsLayerVisible(rName
);
432 void SdrPaintView::SetLayerLocked(const OUString
& rName
, bool bLock
)
436 mpPageView
->SetLayerLocked(rName
,bLock
);
440 bool SdrPaintView::IsLayerLocked(const OUString
& rName
) const
444 return mpPageView
->IsLayerLocked(rName
);
450 void SdrPaintView::SetLayerPrintable(const OUString
& rName
, bool bPrn
)
454 mpPageView
->SetLayerPrintable(rName
,bPrn
);
458 bool SdrPaintView::IsLayerPrintable(const OUString
& rName
) const
462 return mpPageView
->IsLayerPrintable(rName
);
468 void SdrPaintView::PrePaint()
472 mpPageView
->PrePaint();
477 // #define SVX_REPAINT_TIMER_TEST
479 void SdrPaintView::CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
)
481 #ifdef SVX_REPAINT_TIMER_TEST
482 #define REMEMBERED_TIMES_COUNT (10)
483 static bool bDoTimerTest(false);
484 static bool bTimesInited(false);
485 static sal_uInt32
nRepeatCount(10);
486 static double fLastTimes
[REMEMBERED_TIMES_COUNT
];
487 const sal_uInt64
nStartTime(tools::Time::GetSystemTicks());
493 count
= nRepeatCount
;
496 for(a
= 0; a
< count
; a
++)
498 #endif // SVX_REPAINT_TIMER_TEST
500 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
501 // rReg may be made more granular (fine) with using it. Normally, rReg
502 // does come from Window::Paint() anyways and thus is based on a single
503 // rectangle which was derived from exactly that repaint region
504 vcl::Region
aOptimizedRepaintRegion(rReg
);
506 if(pOut
&& OUTDEV_WINDOW
== pOut
->GetOutDevType())
508 vcl::Window
* pWindow
= pOut
->GetOwnerWindow();
510 if(pWindow
->IsInPaint())
512 if(!pWindow
->GetPaintRegion().IsEmpty())
514 aOptimizedRepaintRegion
.Intersect(pWindow
->GetPaintRegion());
519 SdrPaintWindow
* pPaintWindow
= BeginCompleteRedraw(pOut
);
520 OSL_ENSURE(pPaintWindow
, "SdrPaintView::CompleteRedraw: No OutDev (!)");
522 DoCompleteRedraw(*pPaintWindow
, aOptimizedRepaintRegion
, pRedirector
);
523 EndCompleteRedraw(*pPaintWindow
, true);
525 #ifdef SVX_REPAINT_TIMER_TEST
530 const sal_uInt64
nStopTime(tools::Time::GetSystemTicks());
531 const sal_uInt64
nNeededTime(nStopTime
- nStartTime
);
532 const double fTimePerPaint((double)nNeededTime
/ (double)nRepeatCount
);
536 for(a
= 0; a
< REMEMBERED_TIMES_COUNT
; a
++)
538 fLastTimes
[a
] = fTimePerPaint
;
545 for(a
= 1; a
< REMEMBERED_TIMES_COUNT
; a
++)
547 fLastTimes
[a
- 1] = fLastTimes
[a
];
550 fLastTimes
[REMEMBERED_TIMES_COUNT
- 1] = fTimePerPaint
;
553 double fAddedTimes(0.0);
555 for(a
= 0; a
< REMEMBERED_TIMES_COUNT
; a
++)
557 fAddedTimes
+= fLastTimes
[a
];
560 const double fAverageTimePerPaint(fAddedTimes
/ (double)REMEMBERED_TIMES_COUNT
);
562 fprintf(stderr
, "-----------(start result)----------\n");
563 fprintf(stderr
, "StartTime : %" SAL_PRIuUINT64
", StopTime: %" SAL_PRIuUINT64
", NeededTime: %" SAL_PRIuUINT64
", TimePerPaint: %f\n", nStartTime
, nStopTime
, nNeededTime
, fTimePerPaint
);
564 fprintf(stderr
, "Remembered times: ");
566 for(a
= 0; a
< REMEMBERED_TIMES_COUNT
; a
++)
568 fprintf(stderr
, "%d: %f ", a
, fLastTimes
[a
]);
571 fprintf(stderr
, "\n");
572 fprintf(stderr
, "AverageTimePerPaint: %f\n", fAverageTimePerPaint
);
573 fprintf(stderr
, "-----------(stop result)----------\n");
575 #endif // SVX_REPAINT_TIMER_TEST
581 SdrPaintWindow
* SdrPaintView::BeginCompleteRedraw(OutputDevice
* pOut
)
583 OSL_ENSURE(pOut
, "SdrPaintView::BeginCompleteRedraw: No OutDev (!)");
584 SdrPaintWindow
* pPaintWindow
= FindPaintWindow(*pOut
);
588 // draw preprocessing, only for known devices
589 // prepare PreRendering
590 pPaintWindow
->PreparePreRenderDevice();
594 // None of the known OutputDevices is the target of this paint, use
595 // a temporary SdrPaintWindow for this Redraw.
596 pPaintWindow
= new SdrPaintWindow(*this, *pOut
);
597 pPaintWindow
->setTemporaryTarget(true);
603 void SdrPaintView::DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
)
605 // redraw all PageViews with the target. This may expand the RedrawRegion
606 // at the PaintWindow, plus taking care of FormLayer expansion
609 mpPageView
->CompleteRedraw(rPaintWindow
, rReg
, pRedirector
);
613 void SdrPaintView::EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
)
615 std::unique_ptr
<SdrPaintWindow
> pPaintWindow
;
616 if (comphelper::LibreOfficeKit::isActive() && rPaintWindow
.getTemporaryTarget())
618 // Tiled rendering, we must paint the TextEdit to the output device.
619 pPaintWindow
.reset(&rPaintWindow
);
620 pPaintWindow
->setTemporaryTarget(false);
623 if(rPaintWindow
.getTemporaryTarget())
625 // get rid of temp target again
626 delete &rPaintWindow
;
630 // draw postprocessing, only for known devices
631 // it is necessary to always paint FormLayer
632 // In the LOK case control rendering is performed through LokControlHandler
633 if(!comphelper::LibreOfficeKit::isActive() && bPaintFormLayer
)
635 ImpFormLayerDrawing(rPaintWindow
);
638 // look for active TextEdit. As long as this cannot be painted to a VDev,
639 // it cannot get part of buffering. In that case, output evtl. prerender
640 // early and paint text edit to window.
641 SdrPageView
* pPageView
= GetSdrPageView();
642 if(IsTextEdit() && pPageView
)
644 if (!comphelper::LibreOfficeKit::isActive() || mbPaintTextEdit
)
645 static_cast< SdrView
* >(this)->TextEditDrawing(rPaintWindow
);
648 if (comphelper::LibreOfficeKit::isActive() && pPageView
)
650 // Look for active text edits in other views showing the same page,
651 // and show them as well. Show only if Page/MasterPage mode is matching.
652 SdrViewIter
aIter(pPageView
->GetPage());
653 bool bRequireMasterPage
= pPageView
->GetPage() ? pPageView
->GetPage()->IsMasterPage() : false;
654 for (SdrView
* pView
= aIter
.FirstView(); pView
; pView
= aIter
.NextView())
656 SdrPageView
* pCurrentPageView
= pView
->GetSdrPageView();
657 bool bIsCurrentMasterPage
= (pCurrentPageView
&& pCurrentPageView
->GetPage()) ?
658 pCurrentPageView
->GetPage()->IsMasterPage() : false;
660 if (pView
== this || bRequireMasterPage
!= bIsCurrentMasterPage
)
663 if (pView
->IsTextEdit() && pView
->GetSdrPageView())
665 pView
->TextEditDrawing(rPaintWindow
);
670 // draw Overlay, also to PreRender device if exists
671 rPaintWindow
.DrawOverlay(rPaintWindow
.GetRedrawRegion());
673 // output PreRendering
674 rPaintWindow
.OutputPreRenderDevice(rPaintWindow
.GetRedrawRegion());
679 SdrPaintWindow
* SdrPaintView::BeginDrawLayers(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
)
681 // #i74769# use BeginCompleteRedraw() as common base
682 SdrPaintWindow
* pPaintWindow
= BeginCompleteRedraw(pOut
);
683 OSL_ENSURE(pPaintWindow
, "SdrPaintView::BeginDrawLayers: No SdrPaintWindow (!)");
687 SdrPageWindow
* pKnownTarget
= mpPageView
->FindPageWindow(*pPaintWindow
);
691 vcl::Region aOptimizedRepaintRegion
= OptimizeDrawLayersRegion( pOut
, rReg
, bDisableIntersect
);
694 pKnownTarget
->PrepareRedraw(aOptimizedRepaintRegion
);
696 // remember prepared SdrPageWindow
697 mpPageView
->setPreparedPageWindow(pKnownTarget
);
704 void SdrPaintView::EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
)
706 // #i74769# use EndCompleteRedraw() as common base
707 EndCompleteRedraw(rPaintWindow
, bPaintFormLayer
);
711 // forget prepared SdrPageWindow
712 mpPageView
->setPreparedPageWindow(nullptr);
716 void SdrPaintView::UpdateDrawLayersRegion(const OutputDevice
* pOut
, const vcl::Region
& rReg
)
718 SdrPaintWindow
* pPaintWindow
= FindPaintWindow(*pOut
);
719 OSL_ENSURE(pPaintWindow
, "SdrPaintView::UpdateDrawLayersRegion: No SdrPaintWindow (!)");
723 SdrPageWindow
* pKnownTarget
= mpPageView
->FindPageWindow(*pPaintWindow
);
727 vcl::Region aOptimizedRepaintRegion
= OptimizeDrawLayersRegion( pOut
, rReg
, false/*bDisableIntersect*/ );
728 pKnownTarget
->GetPaintWindow().SetRedrawRegion(aOptimizedRepaintRegion
);
729 mpPageView
->setPreparedPageWindow(pKnownTarget
); // already set actually
734 vcl::Region
SdrPaintView::OptimizeDrawLayersRegion(const OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
)
736 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
737 // rReg may be made more granular (fine) with using it. Normally, rReg
738 // does come from Window::Paint() anyways and thus is based on a single
739 // rectangle which was derived from exactly that repaint region
740 vcl::Region
aOptimizedRepaintRegion(rReg
);
742 // #i76114# Intersecting the region with the Window's paint region is disabled
743 // for print preview in Calc, because the intersection can be empty (if the paint
744 // region is outside of the table area of the page), and then no clip region
746 if(pOut
&& OUTDEV_WINDOW
== pOut
->GetOutDevType() && !bDisableIntersect
)
748 vcl::Window
* pWindow
= pOut
->GetOwnerWindow();
750 if(pWindow
->IsInPaint())
752 if(!pWindow
->GetPaintRegion().IsEmpty())
754 aOptimizedRepaintRegion
.Intersect(pWindow
->GetPaintRegion());
758 return aOptimizedRepaintRegion
;
762 void SdrPaintView::ImpFormLayerDrawing( SdrPaintWindow
& rPaintWindow
)
767 SdrPageWindow
* pKnownTarget
= mpPageView
->FindPageWindow(rPaintWindow
);
771 const SdrModel
& rModel
= GetModel();
772 const SdrLayerAdmin
& rLayerAdmin
= rModel
.GetLayerAdmin();
773 const SdrLayerID nControlLayerId
= rLayerAdmin
.GetLayerID(rLayerAdmin
.GetControlLayerName());
775 // BUFFERED use GetTargetOutputDevice() now, it may be targeted to VDevs, too
776 // need to set PreparedPageWindow to make DrawLayer use the correct ObjectContact
777 mpPageView
->setPreparedPageWindow(pKnownTarget
);
778 mpPageView
->DrawLayer(nControlLayerId
, &rPaintWindow
.GetTargetOutputDevice());
779 mpPageView
->setPreparedPageWindow(nullptr);
784 bool SdrPaintView::KeyInput(const KeyEvent
& /*rKEvt*/, vcl::Window
* /*pWin*/)
789 void SdrPaintView::GlueInvalidate() const
791 // Do not invalidate GluePoints in Online
792 // They are handled on front-end
793 if (comphelper::LibreOfficeKit::isActive())
796 const sal_uInt32
nWindowCount(PaintWindowCount());
798 for(sal_uInt32
nWinNum(0); nWinNum
< nWindowCount
; nWinNum
++)
800 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(nWinNum
);
802 if(pPaintWindow
->OutputToWindow())
804 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
808 const SdrObjList
* pOL
=mpPageView
->GetObjList();
809 const size_t nObjCount
= pOL
->GetObjCount();
810 for (size_t nObjNum
=0; nObjNum
<nObjCount
; ++nObjNum
) {
811 const SdrObject
* pObj
=pOL
->GetObj(nObjNum
);
812 const SdrGluePointList
* pGPL
=pObj
->GetGluePointList();
813 if (pGPL
!=nullptr && pGPL
->GetCount()!=0) {
814 pGPL
->Invalidate(*rOutDev
.GetOwnerWindow(), pObj
);
822 void SdrPaintView::InvalidateAllWin()
824 const sal_uInt32
nWindowCount(PaintWindowCount());
826 for(sal_uInt32
a(0); a
< nWindowCount
; a
++)
828 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
830 if(pPaintWindow
->OutputToWindow())
832 InvalidateOneWin(pPaintWindow
->GetOutputDevice());
837 void SdrPaintView::InvalidateAllWin(const tools::Rectangle
& rRect
)
839 const sal_uInt32
nWindowCount(PaintWindowCount());
841 for(sal_uInt32
a(0); a
< nWindowCount
; a
++)
843 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
845 if(pPaintWindow
->OutputToWindow())
847 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
848 tools::Rectangle
aRect(rRect
);
850 Point
aOrg(rOutDev
.GetMapMode().GetOrigin());
851 aOrg
.setX(-aOrg
.X() ); aOrg
.setY(-aOrg
.Y() );
852 tools::Rectangle
aOutRect(aOrg
, rOutDev
.GetOutputSize());
854 // In case of tiled rendering we want to get all invalidations, so visual area is not interesting.
855 if (aRect
.Overlaps(aOutRect
) || comphelper::LibreOfficeKit::isActive())
857 InvalidateOneWin(rOutDev
, aRect
);
863 void SdrPaintView::InvalidateOneWin(OutputDevice
& rDevice
)
865 // do not erase background, that causes flicker (!)
866 rDevice
.GetOwnerWindow()->Invalidate(InvalidateFlags::NoErase
);
869 void SdrPaintView::InvalidateOneWin(OutputDevice
& rDevice
, const tools::Rectangle
& rRect
)
871 // do not erase background, that causes flicker (!)
872 rDevice
.GetOwnerWindow()->Invalidate(rRect
, InvalidateFlags::NoErase
);
875 void SdrPaintView::LeaveOneGroup()
879 mpPageView
->LeaveOneGroup();
883 void SdrPaintView::LeaveAllGroup()
887 mpPageView
->LeaveAllGroup();
891 bool SdrPaintView::IsGroupEntered() const
895 return (mpPageView
->GetEnteredLevel() != 0);
901 void SdrPaintView::SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
)
903 // bReplaceAll has no effect here at all.
904 bool bMeasure
= dynamic_cast<const SdrView
*>(this) != nullptr && static_cast<SdrView
*>(this)->IsMeasureTool();
906 if (const SdrLayerIdItem
*pPoolItem
= rAttr
.GetItemIfSet(SDRATTR_LAYERID
))
908 SdrLayerID nLayerId
= pPoolItem
->GetValue();
909 const SdrLayer
* pLayer
= GetModel().GetLayerAdmin().GetLayerPerID(nLayerId
);
910 if (pLayer
!=nullptr) {
911 if (bMeasure
) maMeasureLayer
=pLayer
->GetName();
912 else maActualLayer
=pLayer
->GetName();
915 if (const SdrLayerNameItem
*pPoolItem
= rAttr
.GetItemIfSet(SDRATTR_LAYERNAME
))
917 if (bMeasure
) maMeasureLayer
= pPoolItem
->GetValue();
918 else maActualLayer
= pPoolItem
->GetValue();
922 void SdrPaintView::MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
) const
924 // bOnlyHardAttr has no effect here at all.
925 bool bMeasure
= dynamic_cast<const SdrView
*>(this) != nullptr && static_cast<const SdrView
*>(this)->IsMeasureTool();
926 const OUString
& aNam
= bMeasure
? maMeasureLayer
: maActualLayer
;
927 rAttr
.Put(SdrLayerNameItem(aNam
));
928 SdrLayerID nLayer
= GetModel().GetLayerAdmin().GetLayerID(aNam
);
929 if (nLayer
!=SDRLAYER_NOTFOUND
) {
930 rAttr
.Put(SdrLayerIdItem(nLayer
));
934 void SdrPaintView::SetDefaultAttr(const SfxItemSet
& rAttr
, bool bReplaceAll
)
938 bool bHasEEFeatureItems
=false;
939 SfxItemIter
aIter(rAttr
);
940 for (const SfxPoolItem
* pItem
= aIter
.GetCurItem(); !bHasEEFeatureItems
&& pItem
;
941 pItem
= aIter
.NextItem())
943 if (!IsInvalidItem(pItem
)) {
944 sal_uInt16 nW
=pItem
->Which();
945 if (nW
>=EE_FEATURE_START
&& nW
<=EE_FEATURE_END
) bHasEEFeatureItems
=true;
949 if(bHasEEFeatureItems
)
951 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(nullptr,
952 VclMessageType::Info
, VclButtonsType::Ok
,
953 "SdrPaintView::SetDefaultAttr(): Setting EE_FEATURE items at the SdrView does not make sense! It only leads to overhead and unreadable documents."));
958 if (bReplaceAll
) maDefaultAttr
.Set(rAttr
);
959 else maDefaultAttr
.Put(rAttr
,false); // if FALSE, regard InvalidItems as "holes," not as Default
960 SetNotPersistDefaultAttr(rAttr
);
963 void SdrPaintView::SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
)
965 if (mpDefaultStyleSheet
)
966 EndListening(*mpDefaultStyleSheet
);
967 mpDefaultStyleSheet
=pStyleSheet
;
968 if (mpDefaultStyleSheet
)
969 StartListening(*mpDefaultStyleSheet
);
971 if (pStyleSheet
!=nullptr && !bDontRemoveHardAttr
) {
972 SfxWhichIter
aIter(pStyleSheet
->GetItemSet());
973 sal_uInt16 nWhich
=aIter
.FirstWhich();
975 if (aIter
.GetItemState()==SfxItemState::SET
) {
976 maDefaultAttr
.ClearItem(nWhich
);
978 nWhich
=aIter
.NextWhich();
983 void SdrPaintView::GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const
985 if(bOnlyHardAttr
|| !mpDefaultStyleSheet
)
987 rTargetSet
.Put(maDefaultAttr
, false);
991 // else merge with DefStyleSheet
992 rTargetSet
.Put(mpDefaultStyleSheet
->GetItemSet(), false);
993 rTargetSet
.Put(maDefaultAttr
, false);
995 MergeNotPersistDefaultAttr(rTargetSet
);
998 void SdrPaintView::SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
)
1000 SetDefaultAttr(rSet
,bReplaceAll
);
1003 SfxStyleSheet
* SdrPaintView::GetStyleSheet() const
1005 return mpDefaultStyleSheet
;
1008 void SdrPaintView::SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
)
1010 SetDefaultStyleSheet(pStyleSheet
,bDontRemoveHardAttr
);
1013 void SdrPaintView::MakeVisible(const tools::Rectangle
& rRect
, vcl::Window
& rWin
)
1015 // TODO: handle when the text cursor goes out of the chart area
1016 // However this hack avoids that the cursor gets misplaced wrt the text.
1017 if (comphelper::LibreOfficeKit::isActive() && rWin
.IsChart())
1022 MapMode
aMap(rWin
.GetMapMode());
1023 Size
aActualSize(rWin
.GetOutDev()->GetOutputSize());
1025 if( aActualSize
.IsEmpty() )
1028 Size
aNewSize(rRect
.GetSize());
1029 bool bNewScale
=false;
1030 bool bNeedMoreX
=aNewSize
.Width()>aActualSize
.Width();
1031 bool bNeedMoreY
=aNewSize
.Height()>aActualSize
.Height();
1032 if (bNeedMoreX
|| bNeedMoreY
)
1035 // set new MapMode (Size+Org) and invalidate everything
1036 Fraction
aXFact(aNewSize
.Width(),aActualSize
.Width());
1037 Fraction
aYFact(aNewSize
.Height(),aActualSize
.Height());
1038 if (aYFact
>aXFact
) aXFact
=aYFact
;
1039 aXFact
*=aMap
.GetScaleX();
1040 aXFact
.ReduceInaccurate(10); // to avoid runovers and BigInt mapping
1041 aMap
.SetScaleX(aXFact
);
1042 aMap
.SetScaleY(aYFact
);
1043 rWin
.SetMapMode(aMap
);
1044 aActualSize
=rWin
.GetOutDev()->GetOutputSize();
1046 Point
aOrg(aMap
.GetOrigin());
1047 tools::Long dx
=0,dy
=0;
1048 tools::Long l
=-aOrg
.X();
1049 tools::Long r
=-aOrg
.X()+aActualSize
.Width()-1;
1050 tools::Long o
=-aOrg
.Y();
1051 tools::Long u
=-aOrg
.Y()+aActualSize
.Height()-1;
1052 if (l
>rRect
.Left()) dx
=rRect
.Left()-l
;
1053 else if (r
<rRect
.Right()) dx
=rRect
.Right()-r
;
1054 if (o
>rRect
.Top()) dy
=rRect
.Top()-o
;
1055 else if (u
<rRect
.Bottom()) dy
=rRect
.Bottom()-u
;
1056 aMap
.SetOrigin(Point(aOrg
.X()-dx
,aOrg
.Y()-dy
));
1058 if (dx
!=0 || dy
!=0) {
1059 rWin
.Scroll(-dx
,-dy
);
1060 rWin
.SetMapMode(aMap
);
1061 rWin
.PaintImmediately();
1064 rWin
.SetMapMode(aMap
);
1065 InvalidateOneWin(*rWin
.GetOutDev());
1069 void SdrPaintView::DoConnect(SdrOle2Obj
* /*pOleObj*/)
1073 void SdrPaintView::SetAnimationEnabled( bool bEnable
)
1075 SetAnimationMode( bEnable
? SdrAnimationMode::Animate
: SdrAnimationMode::Disable
);
1078 void SdrPaintView::SetAnimationPause( bool bSet
)
1080 if(mbAnimationPause
== bSet
)
1083 mbAnimationPause
= bSet
;
1088 for(sal_uInt32
b(0); b
< mpPageView
->PageWindowCount(); b
++)
1090 SdrPageWindow
& rPageWindow
= *(mpPageView
->GetPageWindow(b
));
1091 sdr::contact::ObjectContact
& rObjectContact
= rPageWindow
.GetObjectContact();
1092 sdr::animation::primitiveAnimator
& rAnimator
= rObjectContact
.getPrimitiveAnimator();
1094 if(rAnimator
.IsPaused() != bSet
)
1096 rAnimator
.SetPaused(bSet
);
1101 void SdrPaintView::SetAnimationMode( const SdrAnimationMode eMode
)
1103 meAnimationMode
= eMode
;
1106 void SdrPaintView::VisAreaChanged(const OutputDevice
* pOut
)
1113 SdrPageWindow
* pWindow
= mpPageView
->FindPageWindow(*const_cast<OutputDevice
*>(pOut
));
1126 void SdrPaintView::VisAreaChanged()
1128 // notify SfxListener
1129 Broadcast(SvxViewChangedHint());
1133 void SdrPaintView::onChangeColorConfig()
1135 maGridColor
= maColorConfig
.GetColorValue( svtools::DRAWGRID
).nColor
;
1139 // Set background color for svx at SdrPageViews
1140 void SdrPaintView::SetApplicationBackgroundColor(Color aBackgroundColor
)
1144 mpPageView
->SetApplicationBackgroundColor(aBackgroundColor
);
1148 // Set document color for svx at SdrPageViews
1149 void SdrPaintView::SetApplicationDocumentColor(Color aDocumentColor
)
1153 mpPageView
->SetApplicationDocumentColor(aDocumentColor
);
1157 bool SdrPaintView::IsBufferedOutputAllowed() const
1159 return (mbBufferedOutputAllowed
&& SvtOptionsDrawinglayer::IsPaintBuffer());
1162 void SdrPaintView::SetBufferedOutputAllowed(bool bNew
)
1164 if(bNew
!= mbBufferedOutputAllowed
)
1166 mbBufferedOutputAllowed
= bNew
;
1170 bool SdrPaintView::IsBufferedOverlayAllowed() const
1172 return (mbBufferedOverlayAllowed
&& SvtOptionsDrawinglayer::IsOverlayBuffer());
1175 void SdrPaintView::SetBufferedOverlayAllowed(bool bNew
)
1177 if(bNew
!= mbBufferedOverlayAllowed
)
1179 mbBufferedOverlayAllowed
= bNew
;
1184 void SdrPaintView::SetPagePaintingAllowed(bool bNew
)
1186 if(bNew
!= mbPagePaintingAllowed
)
1188 mbPagePaintingAllowed
= bNew
;
1192 // #i38135# Sets the timer for Object animations and restarts.
1193 void SdrPaintView::SetAnimationTimer(sal_uInt32 nTime
)
1197 // first, reset all timers at all windows to 0L
1198 for(sal_uInt32
a(0); a
< mpPageView
->PageWindowCount(); a
++)
1200 SdrPageWindow
& rPageWindow
= *mpPageView
->GetPageWindow(a
);
1201 sdr::contact::ObjectContact
& rObjectContact
= rPageWindow
.GetObjectContact();
1202 sdr::animation::primitiveAnimator
& rAnimator
= rObjectContact
.getPrimitiveAnimator();
1203 rAnimator
.SetTime(nTime
);
1208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */