bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdpntv.cxx
blobdb7feab72467fa2efc4ab7e8156c163f3efa690b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <com/sun/star/awt/XWindow.hpp>
21 #include <svx/svdpntv.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <svx/sdrpaintwindow.hxx>
24 #include <svtools/grfmgr.hxx>
25 #include <svx/svdmodel.hxx>
27 #ifdef DBG_UTIL
28 #include <svdibrow.hxx>
29 #endif
30 #include <svx/svdpage.hxx>
31 #include <svx/svdpagv.hxx>
32 #include <svl/smplhint.hxx>
34 #include <editeng/editdata.hxx>
35 #include <svx/svdmrkv.hxx>
36 #include <svx/svdundo.hxx>
37 #include <svx/svdview.hxx>
38 #include <svx/svdglue.hxx>
39 #include <svx/svdobj.hxx>
40 #include <svx/svdograf.hxx>
41 #include <svx/svdattrx.hxx>
42 #include "svdibrow.hxx"
43 #include "svx/svditer.hxx"
44 #include <svx/svdouno.hxx>
45 #include <svx/sdr/overlay/overlayobjectlist.hxx>
46 #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
47 #include <svx/sdr/overlay/overlaymanager.hxx>
48 #include <svx/sxlayitm.hxx>
49 #include <svl/itemiter.hxx>
50 #include <editeng/eeitem.hxx>
51 #include <svl/whiter.hxx>
52 #include <svl/style.hxx>
53 #include <svx/sdrpagewindow.hxx>
54 #include <vcl/svapp.hxx>
55 #include <com/sun/star/awt/PosSize.hpp>
56 #include <com/sun/star/awt/XControl.hpp>
57 #include <svx/sdr/contact/objectcontact.hxx>
58 #include <svx/sdr/animation/objectanimator.hxx>
59 #include <svx/sdr/contact/viewcontact.hxx>
60 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
61 #include <basegfx/matrix/b2dhommatrixtools.hxx>
63 using namespace ::rtl;
64 using namespace ::com::sun::star;
66 ////////////////////////////////////////////////////////////////////////////////////////////////////
67 // interface to SdrPaintWindow
69 SdrPaintWindow* SdrPaintView::FindPaintWindow(const OutputDevice& rOut) const
71 for(SdrPaintWindowVector::const_iterator a = maPaintWindows.begin(); a != maPaintWindows.end(); ++a)
73 if(&((*a)->GetOutputDevice()) == &rOut)
75 return *a;
79 return 0L;
82 SdrPaintWindow* SdrPaintView::GetPaintWindow(sal_uInt32 nIndex) const
84 if(nIndex < maPaintWindows.size())
86 return maPaintWindows[nIndex];
89 return 0L;
92 void SdrPaintView::AppendPaintWindow(SdrPaintWindow& rNew)
94 maPaintWindows.push_back(&rNew);
97 SdrPaintWindow* SdrPaintView::RemovePaintWindow(SdrPaintWindow& rOld)
99 SdrPaintWindow* pRetval = 0L;
100 const SdrPaintWindowVector::iterator aFindResult = ::std::find(maPaintWindows.begin(), maPaintWindows.end(), &rOld);
102 if(aFindResult != maPaintWindows.end())
104 // remember return value, aFindResult is no longer valid after deletion
105 pRetval = *aFindResult;
106 maPaintWindows.erase(aFindResult);
109 return pRetval;
112 OutputDevice* SdrPaintView::GetFirstOutputDevice() const
114 if(PaintWindowCount())
116 return &(GetPaintWindow(0)->GetOutputDevice());
119 return 0L;
122 ////////////////////////////////////////////////////////////////////////////////////////////////////
124 TYPEINIT1( SvxViewHint, SfxHint );
126 SvxViewHint::SvxViewHint (HintType eHintType)
127 : meHintType(eHintType)
131 SvxViewHint::HintType SvxViewHint::GetHintType (void) const
133 return meHintType;
137 ////////////////////////////////////////////////////////////////////////////////////////////////////
139 BitmapEx convertMetafileToBitmapEx(
140 const GDIMetaFile& rMtf,
141 const basegfx::B2DRange& rTargetRange,
142 const sal_uInt32 nMaximumQuadraticPixels)
144 BitmapEx aBitmapEx;
146 if(rMtf.GetActionSize())
148 const drawinglayer::primitive2d::Primitive2DReference aMtf(
149 new drawinglayer::primitive2d::MetafilePrimitive2D(
150 basegfx::tools::createScaleTranslateB2DHomMatrix(
151 rTargetRange.getRange(),
152 rTargetRange.getMinimum()),
153 rMtf));
154 aBitmapEx = convertPrimitive2DSequenceToBitmapEx(
155 drawinglayer::primitive2d::Primitive2DSequence(&aMtf, 1),
156 rTargetRange,
157 nMaximumQuadraticPixels);
160 return aBitmapEx;
163 ////////////////////////////////////////////////////////////////////////////////////////////////////
165 TYPEINIT2(SdrPaintView,SfxListener,SfxRepeatTarget);
167 DBG_NAME(SdrPaintView);
169 void SdrPaintView::ImpClearVars()
171 #ifdef DBG_UTIL
172 pItemBrowser=NULL;
173 #endif
174 bPageVisible=sal_True;
175 bPageBorderVisible=sal_True;
176 bBordVisible=sal_True;
177 bGridVisible=sal_True;
178 bGridFront =sal_False;
179 bHlplVisible=sal_True;
180 bHlplFront =sal_True;
181 bGlueVisible=sal_False;
182 bGlueVisible2=sal_False;
183 bGlueVisible3=sal_False;
184 bGlueVisible4=sal_False;
185 bSwapAsynchron=sal_False;
186 bPrintPreview=sal_False;
187 mbPreviewRenderer=sal_False;
189 eAnimationMode = SDR_ANIMATION_ANIMATE;
190 bAnimationPause = sal_False;
192 nHitTolPix=2;
193 nMinMovPix=3;
194 nHitTolLog=0;
195 nMinMovLog=0;
196 pActualOutDev=NULL;
197 pDragWin=NULL;
198 bRestoreColors=sal_True;
199 pDefaultStyleSheet=NULL;
200 bSomeObjChgdFlag=sal_False;
201 nGraphicManagerDrawMode = GRFMGR_DRAW_STANDARD;
202 aComeBackTimer.SetTimeout(1);
203 aComeBackTimer.SetTimeoutHdl(LINK(this,SdrPaintView,ImpComeBackHdl));
205 if (pMod)
206 SetDefaultStyleSheet(pMod->GetDefaultStyleSheet(), sal_True);
208 maGridColor = Color( COL_BLACK );
211 SdrPaintView::SdrPaintView(SdrModel* pModel1, OutputDevice* pOut)
212 : mpPageView(NULL),
213 aDefaultAttr(pModel1->GetItemPool()),
214 mbBufferedOutputAllowed(false),
215 mbBufferedOverlayAllowed(false),
216 mbPagePaintingAllowed(true),
217 mbHideOle(false),
218 mbHideChart(false),
219 mbHideDraw(false),
220 mbHideFormControl(false)
222 DBG_CTOR(SdrPaintView,NULL);
223 pMod=pModel1;
224 ImpClearVars();
226 if(pOut)
228 AddWindowToPaintView(pOut);
231 // flag to visualize groups
232 bVisualizeEnteredGroup = sal_True;
234 maColorConfig.AddListener(this);
235 onChangeColorConfig();
238 SdrPaintView::~SdrPaintView()
240 DBG_DTOR(SdrPaintView,NULL);
241 if (pDefaultStyleSheet)
242 EndListening(*pDefaultStyleSheet);
244 maColorConfig.RemoveListener(this);
245 ClearPageView();
247 #ifdef DBG_UTIL
248 if(pItemBrowser)
250 delete pItemBrowser;
252 #endif
254 // delete existing SdrPaintWindows
255 while(!maPaintWindows.empty())
257 delete maPaintWindows.back();
258 maPaintWindows.pop_back();
262 ////////////////////////////////////////////////////////////////////////////////////////////////////
264 void SdrPaintView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
266 //If the stylesheet has been destroyed
267 if (&rBC == pDefaultStyleSheet)
269 if (rHint.ISA(SfxSimpleHint) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING)
270 pDefaultStyleSheet = NULL;
271 return;
274 bool bObjChg=!bSomeObjChgdFlag; // if true, evaluate for ComeBack timer
275 if (bObjChg) {
276 SdrHint* pSdrHint=PTR_CAST(SdrHint,&rHint);
277 if (pSdrHint!=NULL) {
278 SdrHintKind eKind=pSdrHint->GetKind();
279 if (eKind==HINT_OBJCHG || eKind==HINT_OBJINSERTED || eKind==HINT_OBJREMOVED) {
280 if (bObjChg) {
281 bSomeObjChgdFlag=sal_True;
282 aComeBackTimer.Start();
285 if (eKind==HINT_PAGEORDERCHG) {
286 const SdrPage* pPg=pSdrHint->GetPage();
288 if(pPg && !pPg->IsInserted())
290 if(mpPageView && mpPageView->GetPage() == pPg)
292 HideSdrPage();
300 void SdrPaintView::ConfigurationChanged( ::utl::ConfigurationBroadcaster* , sal_uInt32 )
302 onChangeColorConfig();
303 InvalidateAllWin();
306 ////////////////////////////////////////////////////////////////////////////////////////////////////
308 IMPL_LINK_NOARG_INLINE_START(SdrPaintView, ImpComeBackHdl)
310 if (bSomeObjChgdFlag) {
311 bSomeObjChgdFlag=sal_False;
312 ModelHasChanged();
314 return 0;
316 IMPL_LINK_NOARG_INLINE_END(SdrPaintView,ImpComeBackHdl)
318 void SdrPaintView::FlushComeBackTimer() const
320 if (bSomeObjChgdFlag) {
321 // casting to nonconst
322 ((SdrPaintView*)this)->ImpComeBackHdl(&((SdrPaintView*)this)->aComeBackTimer);
323 ((SdrPaintView*)this)->aComeBackTimer.Stop();
327 void SdrPaintView::ModelHasChanged()
329 // broadcast to all PageViews
330 if(mpPageView && !mpPageView->GetPage()->IsInserted())
332 HideSdrPage();
335 // test mpPageView here again, HideSdrPage() may have invalidated it.
336 if(mpPageView)
338 mpPageView->ModelHasChanged();
341 #ifdef DBG_UTIL
342 if(pItemBrowser)
344 pItemBrowser->SetDirty();
346 #endif
349 ////////////////////////////////////////////////////////////////////////////////////////////////////
351 sal_Bool SdrPaintView::IsAction() const
353 return false;
356 void SdrPaintView::MovAction(const Point&)
360 void SdrPaintView::EndAction()
364 void SdrPaintView::BckAction()
368 void SdrPaintView::BrkAction()
372 void SdrPaintView::TakeActionRect(Rectangle&) const
376 ////////////////////////////////////////////////////////////////////////////////////////////////////
377 // info about TextEdit. Default is sal_False.
378 bool SdrPaintView::IsTextEdit() const
380 return false;
383 // info about TextEditPageView. Default is 0L.
384 SdrPageView* SdrPaintView::GetTextEditPageView() const
386 return 0L;
389 ////////////////////////////////////////////////////////////////////////////////////////////////////
391 sal_uInt16 SdrPaintView::ImpGetMinMovLogic(short nMinMov, const OutputDevice* pOut) const
393 if (nMinMov>=0) return sal_uInt16(nMinMov);
394 if (pOut==NULL)
396 pOut = GetFirstOutputDevice();
398 if (pOut!=NULL) {
399 return short(-pOut->PixelToLogic(Size(nMinMov,0)).Width());
400 } else {
401 return 0;
405 sal_uInt16 SdrPaintView::ImpGetHitTolLogic(short nHitTol, const OutputDevice* pOut) const
407 if (nHitTol>=0) return sal_uInt16(nHitTol);
408 if (pOut==NULL)
410 pOut = GetFirstOutputDevice();
412 if (pOut!=NULL) {
413 return short(-pOut->PixelToLogic(Size(nHitTol,0)).Width());
414 } else {
415 return 0;
419 void SdrPaintView::TheresNewMapMode()
421 if (pActualOutDev!=NULL) {
422 nHitTolLog=(sal_uInt16)((OutputDevice*)pActualOutDev)->PixelToLogic(Size(nHitTolPix,0)).Width();
423 nMinMovLog=(sal_uInt16)((OutputDevice*)pActualOutDev)->PixelToLogic(Size(nMinMovPix,0)).Width();
427 void SdrPaintView::SetActualWin(const OutputDevice* pWin)
429 pActualOutDev=pWin;
430 TheresNewMapMode();
433 ////////////////////////////////////////////////////////////////////////////////////////////////////
435 void SdrPaintView::ClearPageView()
437 BrkAction();
439 if(mpPageView)
441 InvalidateAllWin();
442 delete mpPageView;
443 mpPageView = 0L;
447 SdrPageView* SdrPaintView::ShowSdrPage(SdrPage* pPage)
449 if(pPage && (!mpPageView || mpPageView->GetPage() != pPage))
451 if(mpPageView)
453 InvalidateAllWin();
454 delete mpPageView;
457 mpPageView = new SdrPageView(pPage, *((SdrView*)this));
458 mpPageView->Show();
461 return mpPageView;
464 void SdrPaintView::HideSdrPage()
466 if(mpPageView)
468 mpPageView->Hide();
469 delete mpPageView;
470 mpPageView = 0L;
474 void SdrPaintView::AddWindowToPaintView(OutputDevice* pNewWin)
476 DBG_ASSERT(pNewWin, "SdrPaintView::AddWindowToPaintView: No OutputDevice(!)");
477 SdrPaintWindow* pNewPaintWindow = new SdrPaintWindow(*this, *pNewWin);
478 AppendPaintWindow(*pNewPaintWindow);
480 if(mpPageView)
482 mpPageView->AddPaintWindowToPageView(*pNewPaintWindow);
485 #ifdef DBG_UTIL
486 if (pItemBrowser!=NULL)
487 pItemBrowser->ForceParent();
488 #endif
491 void SdrPaintView::DeleteWindowFromPaintView(OutputDevice* pOldWin)
493 DBG_ASSERT(pOldWin, "SdrPaintView::DeleteWindowFromPaintView: No OutputDevice(!)");
494 SdrPaintWindow* pCandidate = FindPaintWindow(*pOldWin);
496 if(pCandidate)
498 if(mpPageView)
500 mpPageView->RemovePaintWindowFromPageView(*pCandidate);
503 RemovePaintWindow(*pCandidate);
504 delete pCandidate;
507 #ifdef DBG_UTIL
508 if (pItemBrowser!=NULL)
509 pItemBrowser->ForceParent();
510 #endif
513 void SdrPaintView::SetLayerVisible(const XubString& rName, sal_Bool bShow)
515 if(mpPageView)
517 mpPageView->SetLayerVisible(rName,bShow);
520 InvalidateAllWin();
523 bool SdrPaintView::IsLayerVisible(const XubString& rName) const
525 if(mpPageView)
527 return mpPageView->IsLayerVisible(rName);
530 return false;
533 void SdrPaintView::SetLayerLocked(const XubString& rName, sal_Bool bLock)
535 if(mpPageView)
537 mpPageView->SetLayerLocked(rName,bLock);
541 bool SdrPaintView::IsLayerLocked(const XubString& rName) const
543 if(mpPageView)
545 return mpPageView->IsLayerLocked(rName);
548 return false;
551 void SdrPaintView::SetLayerPrintable(const XubString& rName, sal_Bool bPrn)
553 if(mpPageView)
555 mpPageView->SetLayerPrintable(rName,bPrn);
559 bool SdrPaintView::IsLayerPrintable(const XubString& rName) const
561 if(mpPageView)
563 return mpPageView->IsLayerPrintable(rName);
566 return false;
569 void SdrPaintView::PrePaint()
571 if(mpPageView)
573 mpPageView->PrePaint();
577 ////////////////////////////////////////////////////////////////////////////////////////////////////
578 // #define SVX_REPAINT_TIMER_TEST
580 void SdrPaintView::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
582 #ifdef SVX_REPAINT_TIMER_TEST
583 #define REMEMBERED_TIMES_COUNT (10)
584 static bool bDoTimerTest(false);
585 static bool bTimesInited(false);
586 static sal_uInt32 nRepeatCount(10L);
587 static double fLastTimes[REMEMBERED_TIMES_COUNT];
588 const sal_uInt32 nStartTime(Time::GetSystemTicks());
589 sal_uInt32 count(1L);
590 sal_uInt32 a;
592 if(bDoTimerTest)
594 count = nRepeatCount;
597 for(a = 0L; a < count; a++)
599 #endif // SVX_REPAINT_TIMER_TEST
601 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
602 // rReg may be made more granular (fine) with using it. Normally, rReg
603 // does come from Window::Paint() anyways and thus is based on a single
604 // rectangle which was derived from exactly that repaint region
605 Region aOptimizedRepaintRegion(rReg);
607 if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType())
609 Window* pWindow = (Window*)pOut;
611 if(pWindow->IsInPaint())
613 if(!pWindow->GetPaintRegion().IsEmpty())
615 aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
617 #ifdef DBG_UTIL
618 // #i74769# test-paint repaint region
619 static bool bDoPaintForVisualControl(false);
620 if(bDoPaintForVisualControl)
622 RegionHandle aRegionHandle(aOptimizedRepaintRegion.BeginEnumRects());
623 Rectangle aRegionRectangle;
625 while(aOptimizedRepaintRegion.GetEnumRects(aRegionHandle, aRegionRectangle))
627 pWindow->SetLineColor(COL_LIGHTGREEN);
628 pWindow->SetFillColor();
629 pWindow->DrawRect(aRegionRectangle);
632 aOptimizedRepaintRegion.EndEnumRects(aRegionHandle);
634 #endif
639 SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
640 OSL_ENSURE(pPaintWindow, "SdrPaintView::CompleteRedraw: No OutDev (!)");
642 DoCompleteRedraw(*pPaintWindow, aOptimizedRepaintRegion, pRedirector);
643 EndCompleteRedraw(*pPaintWindow, true);
645 #ifdef SVX_REPAINT_TIMER_TEST
648 if(bDoTimerTest)
650 const sal_uInt32 nStopTime(Time::GetSystemTicks());
651 const sal_uInt32 nNeededTime(nStopTime - nStartTime);
652 const double fTimePerPaint((double)nNeededTime / (double)nRepeatCount);
654 if(!bTimesInited)
656 for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
658 fLastTimes[a] = fTimePerPaint;
661 bTimesInited = true;
663 else
665 for(a = 1L; a < REMEMBERED_TIMES_COUNT; a++)
667 fLastTimes[a - 1L] = fLastTimes[a];
670 fLastTimes[REMEMBERED_TIMES_COUNT - 1L] = fTimePerPaint;
673 double fAddedTimes(0.0);
675 for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
677 fAddedTimes += fLastTimes[a];
680 const double fAverageTimePerPaint(fAddedTimes / (double)REMEMBERED_TIMES_COUNT);
682 fprintf(stderr, "-----------(start result)----------\n");
683 fprintf(stderr, "StartTime : %u, StopTime: %u, NeededTime: %u, TimePerPaint: %f\n", nStartTime, nStopTime, nNeededTime, fTimePerPaint);
684 fprintf(stderr, "Remembered times: ");
686 for(a = 0L; a < REMEMBERED_TIMES_COUNT; a++)
688 fprintf(stderr, "%d: %f ", a, fLastTimes[a]);
691 fprintf(stderr, "\n");
692 fprintf(stderr, "AverageTimePerPaint: %f\n", fAverageTimePerPaint);
693 fprintf(stderr, "-----------(stop result)----------\n");
695 #endif // SVX_REPAINT_TIMER_TEST
698 ////////////////////////////////////////////////////////////////////////////////////////////////////
699 // #i72889#
701 SdrPaintWindow* SdrPaintView::BeginCompleteRedraw(OutputDevice* pOut)
703 OSL_ENSURE(pOut, "SdrPaintView::BeginCompleteRedraw: No OutDev (!)");
704 SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
706 if(pPaintWindow)
708 // draw preprocessing, only for known devices
709 // prepare PreRendering
710 pPaintWindow->PreparePreRenderDevice();
712 else
714 // None of the known OutputDevices is the target of this paint, use
715 // a temporary SdrPaintWindow for this Redraw.
716 pPaintWindow = new SdrPaintWindow(*this, *pOut);
717 pPaintWindow->setTemporaryTarget(true);
720 return pPaintWindow;
723 void SdrPaintView::DoCompleteRedraw(SdrPaintWindow& rPaintWindow, const Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector)
725 // redraw all PageViews with the target. This may expand the RedrawRegion
726 // at the PaintWindow, plus taking care of FormLayer expansion
727 if(mpPageView)
729 mpPageView->CompleteRedraw(rPaintWindow, rReg, pRedirector);
733 void SdrPaintView::EndCompleteRedraw(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
735 if(rPaintWindow.getTemporaryTarget())
737 // get rid of temp target again
738 delete (&rPaintWindow);
740 else
742 // draw postprocessing, only for known devices
743 // it is necessary to always paint FormLayer
744 if(bPaintFormLayer)
746 ImpFormLayerDrawing(rPaintWindow);
749 // look for active TextEdit. As long as this cannot be painted to a VDev,
750 // it cannot get part of buffering. In that case, output evtl. prerender
751 // early and paint text edit to window.
752 if(IsTextEdit() && GetSdrPageView())
754 static_cast< SdrView* >(this)->TextEditDrawing(rPaintWindow);
757 // draw Overlay, also to PreRender device if exists
758 rPaintWindow.DrawOverlay(rPaintWindow.GetRedrawRegion());
760 // output PreRendering
761 rPaintWindow.OutputPreRenderDevice(rPaintWindow.GetRedrawRegion());
765 ////////////////////////////////////////////////////////////////////////////////////////////////////
767 SdrPaintWindow* SdrPaintView::BeginDrawLayers(OutputDevice* pOut, const Region& rReg, bool bDisableIntersect)
769 // #i74769# use BeginCompleteRedraw() as common base
770 SdrPaintWindow* pPaintWindow = BeginCompleteRedraw(pOut);
771 OSL_ENSURE(pPaintWindow, "SdrPaintView::BeginDrawLayers: No SdrPaintWindow (!)");
773 if(mpPageView)
775 SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(*pPaintWindow);
777 if(pKnownTarget)
779 Region aOptimizedRepaintRegion = OptimizeDrawLayersRegion( pOut, rReg, bDisableIntersect );
781 // prepare redraw
782 pKnownTarget->PrepareRedraw(aOptimizedRepaintRegion);
784 // remember prepared SdrPageWindow
785 mpPageView->setPreparedPageWindow(pKnownTarget);
789 return pPaintWindow;
792 void SdrPaintView::EndDrawLayers(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer)
794 // #i74769# use EndCompleteRedraw() as common base
795 EndCompleteRedraw(rPaintWindow, bPaintFormLayer);
797 if(mpPageView)
799 // forget prepared SdrPageWindow
800 mpPageView->setPreparedPageWindow(0);
804 void SdrPaintView::UpdateDrawLayersRegion(OutputDevice* pOut, const Region& rReg, bool bDisableIntersect)
806 SdrPaintWindow* pPaintWindow = FindPaintWindow(*pOut);
807 OSL_ENSURE(pPaintWindow, "SdrPaintView::UpdateDrawLayersRegion: No SdrPaintWindow (!)");
809 if(mpPageView)
811 SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(*pPaintWindow);
813 if(pKnownTarget)
815 Region aOptimizedRepaintRegion = OptimizeDrawLayersRegion( pOut, rReg, bDisableIntersect );
816 pKnownTarget->GetPaintWindow().SetRedrawRegion(aOptimizedRepaintRegion);
817 mpPageView->setPreparedPageWindow(pKnownTarget); // already set actually
822 Region SdrPaintView::OptimizeDrawLayersRegion(OutputDevice* pOut, const Region& rReg, bool bDisableIntersect)
824 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
825 // rReg may be made more granular (fine) with using it. Normally, rReg
826 // does come from Window::Paint() anyways and thus is based on a single
827 // rectangle which was derived from exactly that repaint region
828 Region aOptimizedRepaintRegion(rReg);
830 // #i76114# Intersecting the region with the Window's paint region is disabled
831 // for print preview in Calc, because the intersection can be empty (if the paint
832 // region is outside of the table area of the page), and then no clip region
833 // would be set.
834 if(pOut && OUTDEV_WINDOW == pOut->GetOutDevType() && !bDisableIntersect)
836 Window* pWindow = (Window*)pOut;
838 if(pWindow->IsInPaint())
840 if(!pWindow->GetPaintRegion().IsEmpty())
842 aOptimizedRepaintRegion.Intersect(pWindow->GetPaintRegion());
844 #ifdef DBG_UTIL
845 // #i74769# test-paint repaint region
846 static bool bDoPaintForVisualControl(false);
847 if(bDoPaintForVisualControl)
849 RegionHandle aRegionHandle(aOptimizedRepaintRegion.BeginEnumRects());
850 Rectangle aRegionRectangle;
852 while(aOptimizedRepaintRegion.GetEnumRects(aRegionHandle, aRegionRectangle))
854 pWindow->SetLineColor(COL_LIGHTGREEN);
855 pWindow->SetFillColor();
856 pWindow->DrawRect(aRegionRectangle);
859 aOptimizedRepaintRegion.EndEnumRects(aRegionHandle);
861 #endif
865 return aOptimizedRepaintRegion;
868 ////////////////////////////////////////////////////////////////////////////////////////////////////
870 void SdrPaintView::ImpFormLayerDrawing(SdrPaintWindow& rPaintWindow) const
872 if(mpPageView)
874 SdrPageWindow* pKnownTarget = mpPageView->FindPageWindow(rPaintWindow);
876 if(pKnownTarget)
878 const SdrModel& rModel = *(GetModel());
879 const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
880 const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), sal_False);
882 // BUFFERED use GetTargetOutputDevice() now, it may be targeted to VDevs, too
883 // need to set PreparedPageWindow to make DrawLayer use the correct ObjectContact
884 mpPageView->setPreparedPageWindow(pKnownTarget);
885 mpPageView->DrawLayer(nControlLayerId, &rPaintWindow.GetTargetOutputDevice());
886 mpPageView->setPreparedPageWindow(0);
891 ////////////////////////////////////////////////////////////////////////////////////////////////////
893 sal_Bool SdrPaintView::KeyInput(const KeyEvent& /*rKEvt*/, Window* /*pWin*/)
895 return sal_False;
898 void SdrPaintView::GlueInvalidate() const
900 const sal_uInt32 nWindowCount(PaintWindowCount());
902 for(sal_uInt32 nWinNum(0L); nWinNum < nWindowCount; nWinNum++)
904 SdrPaintWindow* pPaintWindow = GetPaintWindow(nWinNum);
906 if(pPaintWindow->OutputToWindow())
908 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
910 if(mpPageView)
912 const SdrObjList* pOL=mpPageView->GetObjList();
913 sal_uIntPtr nObjAnz=pOL->GetObjCount();
914 for (sal_uIntPtr nObjNum=0; nObjNum<nObjAnz; nObjNum++) {
915 const SdrObject* pObj=pOL->GetObj(nObjNum);
916 const SdrGluePointList* pGPL=pObj->GetGluePointList();
917 if (pGPL!=NULL && pGPL->GetCount()!=0) {
918 pGPL->Invalidate((Window&)rOutDev, pObj);
926 void SdrPaintView::InvalidateAllWin()
928 const sal_uInt32 nWindowCount(PaintWindowCount());
930 for(sal_uInt32 a(0L); a < nWindowCount; a++)
932 SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
934 if(pPaintWindow->OutputToWindow())
936 InvalidateOneWin((Window&)pPaintWindow->GetOutputDevice());
941 void SdrPaintView::InvalidateAllWin(const Rectangle& rRect, sal_Bool bPlus1Pix)
943 const sal_uInt32 nWindowCount(PaintWindowCount());
945 for(sal_uInt32 a(0L); a < nWindowCount; a++)
947 SdrPaintWindow* pPaintWindow = GetPaintWindow(a);
949 if(pPaintWindow->OutputToWindow())
951 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
952 Rectangle aRect(rRect);
954 if(bPlus1Pix)
956 Size aPixSiz(1,1);
957 Size aSiz(rOutDev.PixelToLogic(aPixSiz));
958 aRect.Left ()-=aSiz.Width();
959 aRect.Top ()-=aSiz.Height();
960 aRect.Right ()+=aSiz.Width();
961 aRect.Bottom()+=aSiz.Height();
964 Point aOrg(rOutDev.GetMapMode().GetOrigin());
965 aOrg.X()=-aOrg.X(); aOrg.Y()=-aOrg.Y();
966 Rectangle aOutRect(aOrg, rOutDev.GetOutputSize());
968 if (aRect.IsOver(aOutRect))
970 InvalidateOneWin((Window&)rOutDev, aRect);
976 void SdrPaintView::InvalidateOneWin(Window& rWin)
978 // do not erase background, that causes flicker (!)
979 rWin.Invalidate(INVALIDATE_NOERASE);
982 void SdrPaintView::InvalidateOneWin(Window& rWin, const Rectangle& rRect)
984 // do not erase background, that causes flicker (!)
985 rWin.Invalidate(rRect, INVALIDATE_NOERASE);
988 void SdrPaintView::LeaveOneGroup()
990 if(mpPageView)
992 mpPageView->LeaveOneGroup();
996 void SdrPaintView::LeaveAllGroup()
998 if(mpPageView)
1000 mpPageView->LeaveAllGroup();
1004 bool SdrPaintView::IsGroupEntered() const
1006 if(mpPageView)
1008 return (mpPageView->GetEnteredLevel() != 0);
1011 return false;
1014 void SdrPaintView::SetNotPersistDefaultAttr(const SfxItemSet& rAttr, sal_Bool /*bReplaceAll*/)
1016 // bReplaceAll has no effect here at all.
1017 bool bMeasure=ISA(SdrView) && ((SdrView*)this)->IsMeasureTool();
1018 const SfxPoolItem *pPoolItem=NULL;
1019 if (rAttr.GetItemState(SDRATTR_LAYERID,sal_True,&pPoolItem)==SFX_ITEM_SET) {
1020 SdrLayerID nLayerId=((const SdrLayerIdItem*)pPoolItem)->GetValue();
1021 const SdrLayer* pLayer=pMod->GetLayerAdmin().GetLayerPerID(nLayerId);
1022 if (pLayer!=NULL) {
1023 if (bMeasure) aMeasureLayer=pLayer->GetName();
1024 else aAktLayer=pLayer->GetName();
1027 if (rAttr.GetItemState(SDRATTR_LAYERNAME,sal_True,&pPoolItem)==SFX_ITEM_SET) {
1028 if (bMeasure) aMeasureLayer=((const SdrLayerNameItem*)pPoolItem)->GetValue();
1029 else aAktLayer=((const SdrLayerNameItem*)pPoolItem)->GetValue();
1033 void SdrPaintView::MergeNotPersistDefaultAttr(SfxItemSet& rAttr, sal_Bool /*bOnlyHardAttr*/) const
1035 // bOnlyHardAttr has no effect here at all.
1036 bool bMeasure=ISA(SdrView) && ((SdrView*)this)->IsMeasureTool();
1037 const XubString& aNam=bMeasure?aMeasureLayer:aAktLayer;
1038 rAttr.Put(SdrLayerNameItem(aNam));
1039 SdrLayerID nLayer=pMod->GetLayerAdmin().GetLayerID(aNam,sal_True);
1040 if (nLayer!=SDRLAYER_NOTFOUND) {
1041 rAttr.Put(SdrLayerIdItem(nLayer));
1045 void SdrPaintView::SetDefaultAttr(const SfxItemSet& rAttr, sal_Bool bReplaceAll)
1047 #ifdef DBG_UTIL
1049 bool bHasEEFeatureItems=false;
1050 SfxItemIter aIter(rAttr);
1051 const SfxPoolItem* pItem=aIter.FirstItem();
1052 while (!bHasEEFeatureItems && pItem!=NULL) {
1053 if (!IsInvalidItem(pItem)) {
1054 sal_uInt16 nW=pItem->Which();
1055 if (nW>=EE_FEATURE_START && nW<=EE_FEATURE_END) bHasEEFeatureItems=true;
1057 pItem=aIter.NextItem();
1060 if(bHasEEFeatureItems)
1062 String aMessage;
1063 aMessage.AppendAscii("SdrPaintView::SetDefaultAttr(): Setting EE_FEATURE items at the SdrView does not make sense! It only leads to overhead and unreadable documents.");
1064 InfoBox(NULL, aMessage).Execute();
1067 #endif
1068 if (bReplaceAll) aDefaultAttr.Set(rAttr);
1069 else aDefaultAttr.Put(rAttr,sal_False); // if FALSE, regard InvalidItems as "holes," not as Default
1070 SetNotPersistDefaultAttr(rAttr,bReplaceAll);
1071 #ifdef DBG_UTIL
1072 if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1073 #endif
1076 void SdrPaintView::SetDefaultStyleSheet(SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr)
1078 if (pDefaultStyleSheet)
1079 EndListening(*pDefaultStyleSheet);
1080 pDefaultStyleSheet=pStyleSheet;
1081 if (pDefaultStyleSheet)
1082 StartListening(*pDefaultStyleSheet);
1084 if (pStyleSheet!=NULL && !bDontRemoveHardAttr) {
1085 SfxWhichIter aIter(pStyleSheet->GetItemSet());
1086 sal_uInt16 nWhich=aIter.FirstWhich();
1087 while (nWhich!=0) {
1088 if (pStyleSheet->GetItemSet().GetItemState(nWhich,sal_True)==SFX_ITEM_SET) {
1089 aDefaultAttr.ClearItem(nWhich);
1091 nWhich=aIter.NextWhich();
1094 #ifdef DBG_UTIL
1095 if (pItemBrowser!=NULL) pItemBrowser->SetDirty();
1096 #endif
1099 sal_Bool SdrPaintView::GetAttributes(SfxItemSet& rTargetSet, sal_Bool bOnlyHardAttr) const
1101 if(bOnlyHardAttr || !pDefaultStyleSheet)
1103 rTargetSet.Put(aDefaultAttr, sal_False);
1105 else
1107 // else merge with DefStyleSheet
1108 rTargetSet.Put(pDefaultStyleSheet->GetItemSet(), sal_False);
1109 rTargetSet.Put(aDefaultAttr, sal_False);
1111 MergeNotPersistDefaultAttr(rTargetSet, bOnlyHardAttr);
1112 return sal_True;
1115 sal_Bool SdrPaintView::SetAttributes(const SfxItemSet& rSet, sal_Bool bReplaceAll)
1117 SetDefaultAttr(rSet,bReplaceAll);
1118 return sal_True;
1121 SfxStyleSheet* SdrPaintView::GetStyleSheet() const
1123 return GetDefaultStyleSheet();
1126 sal_Bool SdrPaintView::SetStyleSheet(SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr)
1128 SetDefaultStyleSheet(pStyleSheet,bDontRemoveHardAttr);
1129 return sal_True;
1132 ////////////////////////////////////////////////////////////////////////////////////////////////////
1134 #ifdef DBG_UTIL
1135 void SdrPaintView::ShowItemBrowser(sal_Bool bShow)
1137 if (bShow) {
1138 if (pItemBrowser==NULL) {
1139 pItemBrowser=new SdrItemBrowser(*(SdrView*)this);
1140 pItemBrowser->SetFloatingMode(sal_True);
1142 pItemBrowser->Show();
1143 pItemBrowser->GrabFocus();
1144 } else {
1145 if (pItemBrowser!=NULL) {
1146 pItemBrowser->Hide();
1147 delete pItemBrowser;
1148 pItemBrowser=NULL;
1152 #endif
1154 void SdrPaintView::MakeVisible(const Rectangle& rRect, Window& rWin)
1156 MapMode aMap(rWin.GetMapMode());
1157 Size aActualSize(rWin.GetOutputSize());
1159 if( aActualSize.Height() > 0 && aActualSize.Width() > 0 )
1161 Size aNewSize(rRect.GetSize());
1162 bool bNewScale=false;
1163 bool bNeedMoreX=aNewSize.Width()>aActualSize.Width();
1164 bool bNeedMoreY=aNewSize.Height()>aActualSize.Height();
1165 if (bNeedMoreX || bNeedMoreY)
1167 bNewScale=true;
1168 // set new MapMode (Size+Org) and invalidate everything
1169 Fraction aXFact(aNewSize.Width(),aActualSize.Width());
1170 Fraction aYFact(aNewSize.Height(),aActualSize.Height());
1171 if (aYFact>aXFact) aXFact=aYFact;
1172 aXFact*=aMap.GetScaleX();
1173 aXFact.ReduceInaccurate(10); // to avoid runovers and BigInt mapping
1174 aMap.SetScaleX(aXFact);
1175 aMap.SetScaleY(aYFact);
1176 rWin.SetMapMode(aMap);
1177 aActualSize=rWin.GetOutputSize();
1179 Point aOrg(aMap.GetOrigin());
1180 long dx=0,dy=0;
1181 long l=-aOrg.X();
1182 long r=-aOrg.X()+aActualSize.Width()-1;
1183 long o=-aOrg.Y();
1184 long u=-aOrg.Y()+aActualSize.Height()-1;
1185 if (l>rRect.Left()) dx=rRect.Left()-l;
1186 else if (r<rRect.Right()) dx=rRect.Right()-r;
1187 if (o>rRect.Top()) dy=rRect.Top()-o;
1188 else if (u<rRect.Bottom()) dy=rRect.Bottom()-u;
1189 aMap.SetOrigin(Point(aOrg.X()-dx,aOrg.Y()-dy));
1190 if (!bNewScale) {
1191 if (dx!=0 || dy!=0) {
1192 rWin.Scroll(-dx,-dy);
1193 rWin.SetMapMode(aMap);
1194 rWin.Update();
1196 } else {
1197 rWin.SetMapMode(aMap);
1198 InvalidateOneWin(rWin);
1203 void SdrPaintView::DoConnect(SdrOle2Obj* /*pOleObj*/)
1207 void SdrPaintView::SetAnimationEnabled( sal_Bool bEnable )
1209 SetAnimationMode( bEnable ? SDR_ANIMATION_ANIMATE : SDR_ANIMATION_DISABLE );
1212 void SdrPaintView::SetAnimationPause( bool bSet )
1214 if((bool)bAnimationPause != bSet)
1216 bAnimationPause = bSet;
1218 if(mpPageView)
1220 for(sal_uInt32 b(0L); b < mpPageView->PageWindowCount(); b++)
1222 const SdrPageWindow& rPageWindow = *(mpPageView->GetPageWindow(b));
1223 sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
1224 sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
1226 if(rAnimator.IsPaused() != bSet)
1228 rAnimator.SetPaused(bSet);
1235 void SdrPaintView::SetAnimationMode( const SdrAnimationMode eMode )
1237 eAnimationMode = eMode;
1240 void SdrPaintView::VisAreaChanged(const OutputDevice* pOut)
1242 if(mpPageView)
1244 if (pOut)
1246 SdrPageWindow* pWindow = mpPageView->FindPageWindow(*((OutputDevice*)pOut));
1248 if(pWindow)
1250 VisAreaChanged(*pWindow);
1253 else
1255 for(sal_uInt32 a(0L); a < mpPageView->PageWindowCount(); a++)
1257 VisAreaChanged(*mpPageView->GetPageWindow(a));
1263 void SdrPaintView::VisAreaChanged(const SdrPageWindow& /*rWindow*/)
1265 // notify SfxListener
1266 Broadcast(SvxViewHint(SvxViewHint::SVX_HINT_VIEWCHANGED));
1269 void SdrPaintView::onChangeColorConfig()
1271 SetGridColor( Color( maColorConfig.GetColorValue( svtools::DRAWGRID ).nColor ) );
1274 void SdrPaintView::SetGridColor( Color aColor )
1276 maGridColor = aColor;
1279 Color SdrPaintView::GetGridColor() const
1281 return maGridColor;
1284 // Set background color for svx at SdrPageViews
1285 void SdrPaintView::SetApplicationBackgroundColor(Color aBackgroundColor)
1287 if(mpPageView)
1289 mpPageView->SetApplicationBackgroundColor(aBackgroundColor);
1293 // Set document color for svx at SdrPageViews
1294 void SdrPaintView::SetApplicationDocumentColor(Color aDocumentColor)
1296 if(mpPageView)
1298 mpPageView->SetApplicationDocumentColor(aDocumentColor);
1302 bool SdrPaintView::IsBufferedOutputAllowed() const
1304 return (mbBufferedOutputAllowed && maDrawinglayerOpt.IsPaintBuffer());
1307 void SdrPaintView::SetBufferedOutputAllowed(bool bNew)
1309 if(bNew != (bool)mbBufferedOutputAllowed)
1311 mbBufferedOutputAllowed = bNew;
1315 bool SdrPaintView::IsBufferedOverlayAllowed() const
1317 return (mbBufferedOverlayAllowed && maDrawinglayerOpt.IsOverlayBuffer());
1320 void SdrPaintView::SetBufferedOverlayAllowed(bool bNew)
1322 if(bNew != (bool)mbBufferedOverlayAllowed)
1324 mbBufferedOverlayAllowed = bNew;
1328 sal_Bool SdrPaintView::IsPagePaintingAllowed() const
1330 return mbPagePaintingAllowed;
1333 void SdrPaintView::SetPagePaintingAllowed(bool bNew)
1335 if(bNew != (bool)mbPagePaintingAllowed)
1337 mbPagePaintingAllowed = bNew;
1341 // #i38135# Sets the timer for Object animations and restarts.
1342 void SdrPaintView::SetAnimationTimer(sal_uInt32 nTime)
1344 if(mpPageView)
1346 // first, reset all timers at all windows to 0L
1347 for(sal_uInt32 a(0L); a < mpPageView->PageWindowCount(); a++)
1349 const SdrPageWindow& rPageWindow = *mpPageView->GetPageWindow(a);
1350 sdr::contact::ObjectContact& rObjectContact = rPageWindow.GetObjectContact();
1351 sdr::animation::primitiveAnimator& rAnimator = rObjectContact.getPrimitiveAnimator();
1352 rAnimator.SetTime(nTime);
1357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */