1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdpntv.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/awt/XWindow.hpp>
34 #include <svx/svdpntv.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <sdrpaintwindow.hxx>
37 #include <goodies/grfmgr.hxx>
38 #include <svx/svdmodel.hxx>
41 #include <svdibrow.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdpagv.hxx>
45 #include <svtools/smplhint.hxx>
47 #include <svx/svdpntv.hxx>
48 #include <svx/editdata.hxx>
49 #include <svx/svdmrkv.hxx>
50 #include <svx/svdpagv.hxx>
51 #include <svx/svdpage.hxx>
52 #include <svx/svdmodel.hxx>
53 #include <svx/svdundo.hxx>
54 #include <svx/svdview.hxx>
55 #include <svx/svdglue.hxx>
56 #include <svx/svdobj.hxx>
57 #include <svx/svdograf.hxx>
58 #include <svx/svdattrx.hxx>
59 #include "svdibrow.hxx"
60 #include "svditer.hxx"
61 #include <svx/svdouno.hxx>
62 #include <svx/sdr/overlay/overlayobjectlist.hxx>
63 #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
64 #include <svx/sdr/overlay/overlaymanager.hxx>
65 #include <svx/svdglue.hxx>
66 #include <svx/svdobj.hxx>
67 #include <svx/svdview.hxx>
68 #include <svx/sxlayitm.hxx>
69 #include <svtools/itemiter.hxx>
70 #include <svx/eeitem.hxx>
71 #include <svtools/whiter.hxx>
72 #include <svtools/style.hxx>
73 #include <svx/sdrpagewindow.hxx>
74 #include <svx/svdouno.hxx>
75 #include <vcl/svapp.hxx>
76 #include <com/sun/star/awt/XWindow.hpp>
77 #include <com/sun/star/awt/PosSize.hpp>
78 #include <com/sun/star/awt/XControl.hpp>
81 #include <svx/sdr/contact/objectcontact.hxx>
82 #include <svx/sdr/animation/objectanimator.hxx>
83 #include <svx/sdr/contact/viewcontact.hxx>
85 using namespace ::rtl
;
86 using namespace ::com::sun::star
;
88 ////////////////////////////////////////////////////////////////////////////////////////////////////
89 // #114409#-3 Migrate Encirclement
90 class ImplEncirclementOverlay
93 ::sdr::overlay::OverlayObjectList maObjects
;
95 // The remembered second position in logical coodinates
96 basegfx::B2DPoint maSecondPosition
;
99 ImplEncirclementOverlay(const SdrPaintView
& rView
, const basegfx::B2DPoint
& rStartPos
);
100 ~ImplEncirclementOverlay();
102 void SetSecondPosition(const basegfx::B2DPoint
& rNewPosition
);
105 ImplEncirclementOverlay::ImplEncirclementOverlay(const SdrPaintView
& rView
, const basegfx::B2DPoint
& rStartPos
)
106 : maSecondPosition(rStartPos
)
108 for(sal_uInt32
a(0L); a
< rView
.PaintWindowCount(); a
++)
110 SdrPaintWindow
* pCandidate
= rView
.GetPaintWindow(a
);
111 ::sdr::overlay::OverlayManager
* pTargetOverlay
= pCandidate
->GetOverlayManager();
115 ::sdr::overlay::OverlayRollingRectangleStriped
* aNew
= new ::sdr::overlay::OverlayRollingRectangleStriped(
116 rStartPos
, rStartPos
, false);
117 pTargetOverlay
->add(*aNew
);
118 maObjects
.append(*aNew
);
123 ImplEncirclementOverlay::~ImplEncirclementOverlay()
125 // The OverlayObjects are cleared using the destructor of OverlayObjectList.
126 // That destructor calls clear() at the list which removes all objects from the
127 // OverlayManager and deletes them.
130 void ImplEncirclementOverlay::SetSecondPosition(const basegfx::B2DPoint
& rNewPosition
)
132 if(rNewPosition
!= maSecondPosition
)
134 // apply to OverlayObjects
135 for(sal_uInt32
a(0L); a
< maObjects
.count(); a
++)
137 ::sdr::overlay::OverlayRollingRectangleStriped
& rCandidate
= (::sdr::overlay::OverlayRollingRectangleStriped
&)maObjects
.getOverlayObject(a
);
138 rCandidate
.setSecondPosition(rNewPosition
);
141 // remember new position
142 maSecondPosition
= rNewPosition
;
146 ////////////////////////////////////////////////////////////////////////////////////////////////////
147 // interface to SdrPaintWindow
149 SdrPaintWindow
* SdrPaintView::FindPaintWindow(const OutputDevice
& rOut
) const
151 for(SdrPaintWindowVector::const_iterator a
= maPaintWindows
.begin(); a
!= maPaintWindows
.end(); a
++)
153 if(&((*a
)->GetOutputDevice()) == &rOut
)
162 SdrPaintWindow
* SdrPaintView::GetPaintWindow(sal_uInt32 nIndex
) const
164 if(nIndex
< maPaintWindows
.size())
166 return maPaintWindows
[nIndex
];
172 void SdrPaintView::AppendPaintWindow(SdrPaintWindow
& rNew
)
174 maPaintWindows
.push_back(&rNew
);
177 SdrPaintWindow
* SdrPaintView::RemovePaintWindow(SdrPaintWindow
& rOld
)
179 SdrPaintWindow
* pRetval
= 0L;
180 const SdrPaintWindowVector::iterator aFindResult
= ::std::find(maPaintWindows
.begin(), maPaintWindows
.end(), &rOld
);
182 if(aFindResult
!= maPaintWindows
.end())
184 // remember return value, aFindResult is no longer valid after deletion
185 pRetval
= *aFindResult
;
186 maPaintWindows
.erase(aFindResult
);
192 OutputDevice
* SdrPaintView::GetFirstOutputDevice() const
194 if(PaintWindowCount())
196 return &(GetPaintWindow(0)->GetOutputDevice());
202 ////////////////////////////////////////////////////////////////////////////////////////////////////
204 TYPEINIT1( SvxViewHint
, SfxHint
);
206 SvxViewHint::SvxViewHint (HintType eHintType
)
207 : meHintType(eHintType
)
211 SvxViewHint::HintType
SvxViewHint::GetHintType (void) const
217 ////////////////////////////////////////////////////////////////////////////////////////////////////
219 TYPEINIT2(SdrPaintView
,SfxListener
,SfxRepeatTarget
);
221 DBG_NAME(SdrPaintView
);
223 void SdrPaintView::ImpClearVars()
229 bPageBorderVisible
=TRUE
;
239 bSwapAsynchron
=FALSE
;
241 mbPreviewRenderer
=FALSE
;
243 eAnimationMode
= SDR_ANIMATION_ANIMATE
;
244 bAnimationPause
= FALSE
;
253 pDefaultStyleSheet
=NULL
;
254 bSomeObjChgdFlag
=FALSE
;
255 nGraphicManagerDrawMode
= GRFMGR_DRAW_STANDARD
;
256 aComeBackTimer
.SetTimeout(1);
257 aComeBackTimer
.SetTimeoutHdl(LINK(this,SdrPaintView
,ImpComeBackHdl
));
258 String aNam
; // System::GetUserName() just return an empty string
261 SetDefaultStyleSheet(pMod
->GetDefaultStyleSheet(), TRUE
);
265 maGridColor
= Color( COL_BLACK
);
269 SdrPaintView::SdrPaintView(SdrModel
* pModel1
, OutputDevice
* pOut
)
270 : mpEncirclementOverlay(0L),
272 aDefaultAttr(pModel1
->GetItemPool()),
273 mbBufferedOutputAllowed(false),
274 mbBufferedOverlayAllowed(false),
275 mbPagePaintingAllowed(true),
280 DBG_CTOR(SdrPaintView
,NULL
);
286 AddWindowToPaintView(pOut
);
289 // Flag zur Visualisierung von Gruppen
290 bVisualizeEnteredGroup
= TRUE
;
292 StartListening( maColorConfig
);
293 onChangeColorConfig();
296 SdrPaintView::~SdrPaintView()
298 DBG_DTOR(SdrPaintView
,NULL
);
299 EndListening( maColorConfig
);
309 // delete existing SdrPaintWindows
310 while(maPaintWindows
.size())
312 delete maPaintWindows
.back();
313 maPaintWindows
.pop_back();
316 // #114409#-3 Migrate HelpLine
320 ////////////////////////////////////////////////////////////////////////////////////////////////////
322 void __EXPORT
SdrPaintView::Notify(SfxBroadcaster
& /*rBC*/, const SfxHint
& rHint
)
324 BOOL bObjChg
=!bSomeObjChgdFlag
; // TRUE= auswerten fuer ComeBack-Timer
326 SdrHint
* pSdrHint
=PTR_CAST(SdrHint
,&rHint
);
327 if (pSdrHint
!=NULL
) {
328 SdrHintKind eKind
=pSdrHint
->GetKind();
329 if (eKind
==HINT_OBJCHG
|| eKind
==HINT_OBJINSERTED
|| eKind
==HINT_OBJREMOVED
) {
331 bSomeObjChgdFlag
=TRUE
;
332 aComeBackTimer
.Start();
335 if (eKind
==HINT_PAGEORDERCHG
) {
336 const SdrPage
* pPg
=pSdrHint
->GetPage();
338 if(!pPg
->IsInserted())
340 if(mpPageView
&& mpPageView
->GetPage() == pPg
)
349 if( rHint
.ISA( SfxSimpleHint
) && ( (SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_COLORS_CHANGED
)
351 onChangeColorConfig();
356 ////////////////////////////////////////////////////////////////////////////////////////////////////
358 IMPL_LINK_INLINE_START(SdrPaintView
,ImpComeBackHdl
,Timer
*,EMPTYARG
)
360 if (bSomeObjChgdFlag
) {
361 bSomeObjChgdFlag
=FALSE
;
366 IMPL_LINK_INLINE_END(SdrPaintView
,ImpComeBackHdl
,Timer
*,pTimer
)
368 void SdrPaintView::FlushComeBackTimer() const
370 if (bSomeObjChgdFlag
) {
371 // casting auf nonconst
372 ((SdrPaintView
*)this)->ImpComeBackHdl(&((SdrPaintView
*)this)->aComeBackTimer
);
373 ((SdrPaintView
*)this)->aComeBackTimer
.Stop();
377 void SdrPaintView::ModelHasChanged()
379 // Auch alle PageViews benachrichtigen
380 if(mpPageView
&& !mpPageView
->GetPage()->IsInserted())
385 // test mpPageView here again, HideSdrPage() may have invalidated it.
388 mpPageView
->ModelHasChanged();
394 pItemBrowser
->SetDirty();
399 ////////////////////////////////////////////////////////////////////////////////////////////////////
401 BOOL
SdrPaintView::IsAction() const
403 return IsEncirclement();
406 void SdrPaintView::MovAction(const Point
& rPnt
)
408 if (IsEncirclement())
410 MovEncirclement(rPnt
);
414 void SdrPaintView::EndAction()
422 void SdrPaintView::BckAction()
427 void SdrPaintView::BrkAction()
432 void SdrPaintView::TakeActionRect(Rectangle
& rRect
) const
436 rRect
= Rectangle(aDragStat
.GetStart(),aDragStat
.GetNow());
440 ////////////////////////////////////////////////////////////////////////////////////////////////////
441 // info about TextEdit. Default is sal_False.
442 bool SdrPaintView::IsTextEdit() const
447 // info about TextEditPageView. Default is 0L.
448 SdrPageView
* SdrPaintView::GetTextEditPageView() const
453 ////////////////////////////////////////////////////////////////////////////////////////////////////
455 USHORT
SdrPaintView::ImpGetMinMovLogic(short nMinMov
, const OutputDevice
* pOut
) const
457 if (nMinMov
>=0) return USHORT(nMinMov
);
460 pOut
= GetFirstOutputDevice();
463 return short(-pOut
->PixelToLogic(Size(nMinMov
,0)).Width());
469 USHORT
SdrPaintView::ImpGetHitTolLogic(short nHitTol
, const OutputDevice
* pOut
) const
471 if (nHitTol
>=0) return USHORT(nHitTol
);
474 pOut
= GetFirstOutputDevice();
477 return short(-pOut
->PixelToLogic(Size(nHitTol
,0)).Width());
483 void SdrPaintView::TheresNewMapMode()
485 if (pActualOutDev
!=NULL
) {
486 nHitTolLog
=(USHORT
)((OutputDevice
*)pActualOutDev
)->PixelToLogic(Size(nHitTolPix
,0)).Width();
487 nMinMovLog
=(USHORT
)((OutputDevice
*)pActualOutDev
)->PixelToLogic(Size(nMinMovPix
,0)).Width();
491 void SdrPaintView::SetActualWin(const OutputDevice
* pWin
)
497 ////////////////////////////////////////////////////////////////////////////////////////////////////
499 void SdrPaintView::BegEncirclement(const Point
& rPnt
)
503 DBG_ASSERT(0L == mpEncirclementOverlay
, "SdrSnapView::BegSetPageOrg: There exists a ImplPageOriginOverlay (!)");
504 basegfx::B2DPoint
aStartPos(rPnt
.X(), rPnt
.Y());
505 mpEncirclementOverlay
= new ImplEncirclementOverlay(*this, aStartPos
);
507 aDragStat
.Reset(rPnt
);
508 aDragStat
.SetMinMove(ImpGetMinMovLogic(-2,0L));
509 aDragStat
.NextPoint();
512 void SdrPaintView::MovEncirclement(const Point
& rPnt
)
514 if(IsEncirclement() && aDragStat
.CheckMinMoved(rPnt
))
516 aDragStat
.NextMove(rPnt
);
518 DBG_ASSERT(mpEncirclementOverlay
, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
519 basegfx::B2DPoint
aNewPos(rPnt
.X(), rPnt
.Y());
520 mpEncirclementOverlay
->SetSecondPosition(aNewPos
);
524 Rectangle
SdrPaintView::EndEncirclement(sal_Bool bNoJustify
)
530 if(aDragStat
.IsMinMoved())
532 aRetval
= Rectangle(aDragStat
.GetStart(), aDragStat
.GetNow());
547 void SdrPaintView::BrkEncirclement()
551 DBG_ASSERT(mpEncirclementOverlay
, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
552 delete mpEncirclementOverlay
;
553 mpEncirclementOverlay
= 0L;
557 ////////////////////////////////////////////////////////////////////////////////////////////////////
559 void SdrPaintView::ClearPageView()
571 SdrPageView
* SdrPaintView::ShowSdrPage(SdrPage
* pPage
)
573 if(pPage
&& (!mpPageView
|| mpPageView
->GetPage() != pPage
))
581 mpPageView
= new SdrPageView(pPage
, *((SdrView
*)this));
588 void SdrPaintView::HideSdrPage()
598 void SdrPaintView::AddWindowToPaintView(OutputDevice
* pNewWin
)
600 DBG_ASSERT(pNewWin
, "SdrPaintView::AddWindowToPaintView: No OutputDevice(!)");
601 SdrPaintWindow
* pNewPaintWindow
= new SdrPaintWindow(*this, *pNewWin
);
602 AppendPaintWindow(*pNewPaintWindow
);
606 mpPageView
->AddPaintWindowToPageView(*pNewPaintWindow
);
610 if (pItemBrowser
!=NULL
)
611 pItemBrowser
->ForceParent();
615 void SdrPaintView::DeleteWindowFromPaintView(OutputDevice
* pOldWin
)
617 DBG_ASSERT(pOldWin
, "SdrPaintView::DeleteWindowFromPaintView: No OutputDevice(!)");
618 SdrPaintWindow
* pCandidate
= FindPaintWindow(*pOldWin
);
624 mpPageView
->RemovePaintWindowFromPageView(*pCandidate
);
627 RemovePaintWindow(*pCandidate
);
632 if (pItemBrowser
!=NULL
)
633 pItemBrowser
->ForceParent();
637 void SdrPaintView::SetLayerVisible(const XubString
& rName
, BOOL bShow
)
641 mpPageView
->SetLayerVisible(rName
,bShow
);
647 bool SdrPaintView::IsLayerVisible(const XubString
& rName
) const
651 return mpPageView
->IsLayerVisible(rName
);
657 void SdrPaintView::SetAllLayersVisible(BOOL bShow
)
661 mpPageView
->SetAllLayersVisible(bShow
);
667 void SdrPaintView::SetLayerLocked(const XubString
& rName
, BOOL bLock
)
671 mpPageView
->SetLayerLocked(rName
,bLock
);
675 bool SdrPaintView::IsLayerLocked(const XubString
& rName
) const
679 return mpPageView
->IsLayerLocked(rName
);
685 void SdrPaintView::SetAllLayersLocked(BOOL bLock
)
689 mpPageView
->SetAllLayersLocked(bLock
);
693 void SdrPaintView::SetLayerPrintable(const XubString
& rName
, BOOL bPrn
)
697 mpPageView
->SetLayerPrintable(rName
,bPrn
);
701 bool SdrPaintView::IsLayerPrintable(const XubString
& rName
) const
705 return mpPageView
->IsLayerPrintable(rName
);
711 void SdrPaintView::SetAllLayersPrintable(BOOL bPrn
)
715 mpPageView
->SetAllLayersPrintable(bPrn
);
719 void SdrPaintView::PrePaint()
723 mpPageView
->PrePaint();
727 ////////////////////////////////////////////////////////////////////////////////////////////////////
728 // #define SVX_REPAINT_TIMER_TEST
730 void SdrPaintView::CompleteRedraw(OutputDevice
* pOut
, const Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
)
732 #ifdef SVX_REPAINT_TIMER_TEST
733 #define REMEMBERED_TIMES_COUNT (10)
734 static bool bDoTimerTest(false);
735 static bool bTimesInited(false);
736 static sal_uInt32
nRepeatCount(10L);
737 static double fLastTimes
[REMEMBERED_TIMES_COUNT
];
738 const sal_uInt32
nStartTime(Time::GetSystemTicks());
739 sal_uInt32
count(1L);
744 count
= nRepeatCount
;
747 for(a
= 0L; a
< count
; a
++)
749 #endif // SVX_REPAINT_TIMER_TEST
751 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
752 // rReg may be made more granular (fine) with using it. Normally, rReg
753 // does come from Window::Paint() anyways and thus is based on a single
754 // rectangle which was derived from exactly that repaint region
755 Region
aOptimizedRepaintRegion(rReg
);
757 if(pOut
&& OUTDEV_WINDOW
== pOut
->GetOutDevType())
759 Window
* pWindow
= (Window
*)pOut
;
761 if(pWindow
->IsInPaint())
763 if(!pWindow
->GetPaintRegion().IsEmpty())
765 aOptimizedRepaintRegion
.Intersect(pWindow
->GetPaintRegion());
768 // #i74769# test-paint repaint region
769 static bool bDoPaintForVisualControl(false);
770 if(bDoPaintForVisualControl
)
772 RegionHandle
aRegionHandle(aOptimizedRepaintRegion
.BeginEnumRects());
773 Rectangle aRegionRectangle
;
775 while(aOptimizedRepaintRegion
.GetEnumRects(aRegionHandle
, aRegionRectangle
))
777 pWindow
->SetLineColor(COL_LIGHTGREEN
);
778 pWindow
->SetFillColor();
779 pWindow
->DrawRect(aRegionRectangle
);
782 aOptimizedRepaintRegion
.EndEnumRects(aRegionHandle
);
789 SdrPaintWindow
* pPaintWindow
= BeginCompleteRedraw(pOut
);
790 OSL_ENSURE(pPaintWindow
, "SdrPaintView::CompleteRedraw: No OutDev (!)");
792 DoCompleteRedraw(*pPaintWindow
, aOptimizedRepaintRegion
, pRedirector
);
793 EndCompleteRedraw(*pPaintWindow
, true);
795 #ifdef SVX_REPAINT_TIMER_TEST
800 const sal_uInt32
nStopTime(Time::GetSystemTicks());
801 const sal_uInt32
nNeededTime(nStopTime
- nStartTime
);
802 const double fTimePerPaint((double)nNeededTime
/ (double)nRepeatCount
);
806 for(a
= 0L; a
< REMEMBERED_TIMES_COUNT
; a
++)
808 fLastTimes
[a
] = fTimePerPaint
;
815 for(a
= 1L; a
< REMEMBERED_TIMES_COUNT
; a
++)
817 fLastTimes
[a
- 1L] = fLastTimes
[a
];
820 fLastTimes
[REMEMBERED_TIMES_COUNT
- 1L] = fTimePerPaint
;
823 double fAddedTimes(0.0);
825 for(a
= 0L; a
< REMEMBERED_TIMES_COUNT
; a
++)
827 fAddedTimes
+= fLastTimes
[a
];
830 const double fAverageTimePerPaint(fAddedTimes
/ (double)REMEMBERED_TIMES_COUNT
);
832 fprintf(stderr
, "-----------(start result)----------\n");
833 fprintf(stderr
, "StartTime : %u, StopTime: %u, NeededTime: %u, TimePerPaint: %f\n", nStartTime
, nStopTime
, nNeededTime
, fTimePerPaint
);
834 fprintf(stderr
, "Remembered times: ");
836 for(a
= 0L; a
< REMEMBERED_TIMES_COUNT
; a
++)
838 fprintf(stderr
, "%d: %f ", a
, fLastTimes
[a
]);
841 fprintf(stderr
, "\n");
842 fprintf(stderr
, "AverageTimePerPaint: %f\n", fAverageTimePerPaint
);
843 fprintf(stderr
, "-----------(stop result)----------\n");
845 #endif // SVX_REPAINT_TIMER_TEST
848 ////////////////////////////////////////////////////////////////////////////////////////////////////
851 SdrPaintWindow
* SdrPaintView::BeginCompleteRedraw(OutputDevice
* pOut
)
853 OSL_ENSURE(pOut
, "SdrPaintView::BeginCompleteRedraw: No OutDev (!)");
854 SdrPaintWindow
* pPaintWindow
= FindPaintWindow(*pOut
);
858 // draw preprocessing, only for known devices
859 // prepare PreRendering
860 pPaintWindow
->PreparePreRenderDevice();
864 // None of the known OutputDevices is the target of this paint, use
865 // a temporary SdrPaintWindow for this Redraw.
866 pPaintWindow
= new SdrPaintWindow(*this, *pOut
);
867 pPaintWindow
->setTemporaryTarget(true);
873 void SdrPaintView::DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
)
875 // redraw all PageViews with the target. This may expand the RedrawRegion
876 // at the PaintWindow, plus taking care of FormLayer expansion
879 mpPageView
->CompleteRedraw(rPaintWindow
, rReg
, pRedirector
);
883 void SdrPaintView::EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
)
885 if(rPaintWindow
.getTemporaryTarget())
887 // get rid of temp target again
888 delete (&rPaintWindow
);
892 // draw postprocessing, only for known devices
893 // it is necessary to always paint FormLayer
896 ImpFormLayerDrawing(rPaintWindow
);
899 // look for active TextEdit. As long as this cannot be painted to a VDev,
900 // it cannot get part of buffering. In that case, output evtl. prerender
901 // early and paint text edit to window.
902 const bool bTextEditActive(IsTextEdit() && GetTextEditPageView());
906 // output PreRendering and destroy it so that it is not used for FormLayer
908 rPaintWindow
.OutputPreRenderDevice(rPaintWindow
.GetRedrawRegion());
910 // draw old text edit stuff before overlay to have it as part of the background
911 // ATM. This will be changed to have the text editing on the overlay, bit it
912 // is not an easy thing to do, see BegTextEdit and the OutlinerView stuff used...
915 ImpTextEditDrawing(rPaintWindow
);
918 // draw Overlay directly to window. This will save the contents of the window
919 // in the RedrawRegion to the overlay background buffer, too.
920 // This may lead to problems when reading from the screen is slow from the
921 // graphics driver/graphiccard combination.
922 rPaintWindow
.DrawOverlay(rPaintWindow
.GetRedrawRegion(), false);
926 // draw Overlay, also to PreRender device if exists
927 rPaintWindow
.DrawOverlay(rPaintWindow
.GetRedrawRegion(), true);
929 // output PreRendering
930 rPaintWindow
.OutputPreRenderDevice(rPaintWindow
.GetRedrawRegion());
935 ////////////////////////////////////////////////////////////////////////////////////////////////////
937 SdrPaintWindow
* SdrPaintView::BeginDrawLayers(OutputDevice
* pOut
, const Region
& rReg
, bool bDisableIntersect
)
939 // #i74769# use BeginCompleteRedraw() as common base
940 SdrPaintWindow
* pPaintWindow
= BeginCompleteRedraw(pOut
);
941 OSL_ENSURE(pPaintWindow
, "SdrPaintView::BeginDrawLayers: No SdrPaintWindow (!)");
945 SdrPageWindow
* pKnownTarget
= mpPageView
->FindPageWindow(*pPaintWindow
);
949 // #i74769# check if pOut is a win and has a ClipRegion. If Yes, the Region
950 // rReg may be made more granular (fine) with using it. Normally, rReg
951 // does come from Window::Paint() anyways and thus is based on a single
952 // rectangle which was derived from exactly that repaint region
953 Region
aOptimizedRepaintRegion(rReg
);
955 // #i76114# Intersecting the region with the Window's paint region is disabled
956 // for print preview in Calc, because the intersection can be empty (if the paint
957 // region is outside of the table area of the page), and then no clip region
959 if(pOut
&& OUTDEV_WINDOW
== pOut
->GetOutDevType() && !bDisableIntersect
)
961 Window
* pWindow
= (Window
*)pOut
;
963 if(pWindow
->IsInPaint())
965 if(!pWindow
->GetPaintRegion().IsEmpty())
967 aOptimizedRepaintRegion
.Intersect(pWindow
->GetPaintRegion());
970 // #i74769# test-paint repaint region
971 static bool bDoPaintForVisualControl(false);
972 if(bDoPaintForVisualControl
)
974 RegionHandle
aRegionHandle(aOptimizedRepaintRegion
.BeginEnumRects());
975 Rectangle aRegionRectangle
;
977 while(aOptimizedRepaintRegion
.GetEnumRects(aRegionHandle
, aRegionRectangle
))
979 pWindow
->SetLineColor(COL_LIGHTGREEN
);
980 pWindow
->SetFillColor();
981 pWindow
->DrawRect(aRegionRectangle
);
984 aOptimizedRepaintRegion
.EndEnumRects(aRegionHandle
);
992 pKnownTarget
->PrepareRedraw(aOptimizedRepaintRegion
);
994 // remember prepared SdrPageWindow
995 mpPageView
->setPreparedPageWindow(pKnownTarget
);
1002 void SdrPaintView::EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
)
1004 // #i74769# use EndCompleteRedraw() as common base
1005 EndCompleteRedraw(rPaintWindow
, bPaintFormLayer
);
1009 // forget prepared SdrPageWindow
1010 mpPageView
->setPreparedPageWindow(0);
1014 ////////////////////////////////////////////////////////////////////////////////////////////////////
1016 void SdrPaintView::ImpTextEditDrawing(SdrPaintWindow
& rPaintWindow
) const
1018 // draw old text edit stuff
1021 SdrPageView
* pPageView
= GetTextEditPageView();
1025 // paint TextEdit directly to the destination OutDev
1026 const Region
& rRedrawRegion
= rPaintWindow
.GetRedrawRegion();
1027 const Rectangle
aCheckRect(rRedrawRegion
.GetBoundRect());
1028 pPageView
->PaintOutlinerView(&rPaintWindow
.GetOutputDevice(), aCheckRect
);
1033 void SdrPaintView::ImpFormLayerDrawing(SdrPaintWindow
& rPaintWindow
) const
1037 SdrPageWindow
* pKnownTarget
= mpPageView
->FindPageWindow(rPaintWindow
);
1041 const SdrModel
& rModel
= *(GetModel());
1042 const SdrLayerAdmin
& rLayerAdmin
= rModel
.GetLayerAdmin();
1043 const SdrLayerID nControlLayerId
= rLayerAdmin
.GetLayerID(rLayerAdmin
.GetControlLayerName(), sal_False
);
1045 // BUFFERED use GetTargetOutputDevice() now, it may be targeted to VDevs, too
1046 // need to set PreparedPageWindow to make DrawLayer use the correct ObjectContact
1047 mpPageView
->setPreparedPageWindow(pKnownTarget
);
1048 mpPageView
->DrawLayer(nControlLayerId
, &rPaintWindow
.GetTargetOutputDevice());
1049 mpPageView
->setPreparedPageWindow(0);
1054 ////////////////////////////////////////////////////////////////////////////////////////////////////
1056 BOOL
SdrPaintView::KeyInput(const KeyEvent
& /*rKEvt*/, Window
* /*pWin*/)
1061 void SdrPaintView::GlueInvalidate() const
1063 const sal_uInt32
nWindowCount(PaintWindowCount());
1065 for(sal_uInt32
nWinNum(0L); nWinNum
< nWindowCount
; nWinNum
++)
1067 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(nWinNum
);
1069 if(pPaintWindow
->OutputToWindow())
1071 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
1075 const SdrObjList
* pOL
=mpPageView
->GetObjList();
1076 ULONG nObjAnz
=pOL
->GetObjCount();
1077 for (ULONG nObjNum
=0; nObjNum
<nObjAnz
; nObjNum
++) {
1078 const SdrObject
* pObj
=pOL
->GetObj(nObjNum
);
1079 const SdrGluePointList
* pGPL
=pObj
->GetGluePointList();
1080 if (pGPL
!=NULL
&& pGPL
->GetCount()!=0) {
1081 pGPL
->Invalidate((Window
&)rOutDev
, pObj
);
1089 void SdrPaintView::InvalidateAllWin()
1091 const sal_uInt32
nWindowCount(PaintWindowCount());
1093 for(sal_uInt32
a(0L); a
< nWindowCount
; a
++)
1095 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
1097 if(pPaintWindow
->OutputToWindow())
1099 InvalidateOneWin((Window
&)pPaintWindow
->GetOutputDevice());
1104 void SdrPaintView::InvalidateAllWin(const Rectangle
& rRect
, BOOL bPlus1Pix
)
1106 const sal_uInt32
nWindowCount(PaintWindowCount());
1108 for(sal_uInt32
a(0L); a
< nWindowCount
; a
++)
1110 SdrPaintWindow
* pPaintWindow
= GetPaintWindow(a
);
1112 if(pPaintWindow
->OutputToWindow())
1114 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
1115 Rectangle
aRect(rRect
);
1120 Size
aSiz(rOutDev
.PixelToLogic(aPixSiz
));
1121 aRect
.Left ()-=aSiz
.Width();
1122 aRect
.Top ()-=aSiz
.Height();
1123 aRect
.Right ()+=aSiz
.Width();
1124 aRect
.Bottom()+=aSiz
.Height();
1127 Point
aOrg(rOutDev
.GetMapMode().GetOrigin());
1128 aOrg
.X()=-aOrg
.X(); aOrg
.Y()=-aOrg
.Y();
1129 Rectangle
aOutRect(aOrg
, rOutDev
.GetOutputSize());
1131 if (aRect
.IsOver(aOutRect
))
1133 InvalidateOneWin((Window
&)rOutDev
, aRect
);
1139 void SdrPaintView::InvalidateOneWin(Window
& rWin
)
1142 // do not erase background, that causes flicker (!)
1143 rWin
.Invalidate(INVALIDATE_NOERASE
);
1146 void SdrPaintView::InvalidateOneWin(Window
& rWin
, const Rectangle
& rRect
)
1149 // do not erase background, that causes flicker (!)
1150 rWin
.Invalidate(rRect
, INVALIDATE_NOERASE
);
1153 void SdrPaintView::LeaveOneGroup()
1157 mpPageView
->LeaveOneGroup();
1161 void SdrPaintView::LeaveAllGroup()
1165 mpPageView
->LeaveAllGroup();
1169 bool SdrPaintView::IsGroupEntered() const
1173 return (mpPageView
->GetEnteredLevel() != 0);
1179 void SdrPaintView::SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
, BOOL
/*bReplaceAll*/)
1181 // bReplaceAll hat hier keinerlei Wirkung
1182 BOOL bMeasure
=ISA(SdrView
) && ((SdrView
*)this)->IsMeasureTool();
1183 const SfxPoolItem
*pPoolItem
=NULL
;
1184 if (rAttr
.GetItemState(SDRATTR_LAYERID
,TRUE
,&pPoolItem
)==SFX_ITEM_SET
) {
1185 SdrLayerID nLayerId
=((const SdrLayerIdItem
*)pPoolItem
)->GetValue();
1186 const SdrLayer
* pLayer
=pMod
->GetLayerAdmin().GetLayerPerID(nLayerId
);
1188 if (bMeasure
) aMeasureLayer
=pLayer
->GetName();
1189 else aAktLayer
=pLayer
->GetName();
1192 if (rAttr
.GetItemState(SDRATTR_LAYERNAME
,TRUE
,&pPoolItem
)==SFX_ITEM_SET
) {
1193 if (bMeasure
) aMeasureLayer
=((const SdrLayerNameItem
*)pPoolItem
)->GetValue();
1194 else aAktLayer
=((const SdrLayerNameItem
*)pPoolItem
)->GetValue();
1198 void SdrPaintView::MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
, BOOL
/*bOnlyHardAttr*/) const
1200 // bOnlyHardAttr hat hier keinerlei Wirkung
1201 BOOL bMeasure
=ISA(SdrView
) && ((SdrView
*)this)->IsMeasureTool();
1202 const XubString
& aNam
=bMeasure
?aMeasureLayer
:aAktLayer
;
1203 rAttr
.Put(SdrLayerNameItem(aNam
));
1204 SdrLayerID nLayer
=pMod
->GetLayerAdmin().GetLayerID(aNam
,TRUE
);
1205 if (nLayer
!=SDRLAYER_NOTFOUND
) {
1206 rAttr
.Put(SdrLayerIdItem(nLayer
));
1210 void SdrPaintView::SetDefaultAttr(const SfxItemSet
& rAttr
, BOOL bReplaceAll
)
1214 BOOL bHasEEFeatureItems
=FALSE
;
1215 SfxItemIter
aIter(rAttr
);
1216 const SfxPoolItem
* pItem
=aIter
.FirstItem();
1217 while (!bHasEEFeatureItems
&& pItem
!=NULL
) {
1218 if (!IsInvalidItem(pItem
)) {
1219 USHORT nW
=pItem
->Which();
1220 if (nW
>=EE_FEATURE_START
&& nW
<=EE_FEATURE_END
) bHasEEFeatureItems
=TRUE
;
1222 pItem
=aIter
.NextItem();
1225 if(bHasEEFeatureItems
)
1228 aMessage
.AppendAscii("SdrPaintView::SetDefaultAttr(): Das setzen von EE_FEATURE-Items an der SdrView macht keinen Sinn! Es fuehrt nur zu Overhead und nicht mehr lesbaren Dokumenten.");
1229 InfoBox(NULL
, aMessage
).Execute();
1233 if (bReplaceAll
) aDefaultAttr
.Set(rAttr
);
1234 else aDefaultAttr
.Put(rAttr
,FALSE
); // FALSE= InvalidItems nicht als Default, sondern als "Loecher" betrachten
1235 SetNotPersistDefaultAttr(rAttr
,bReplaceAll
);
1237 if (pItemBrowser
!=NULL
) pItemBrowser
->SetDirty();
1241 void SdrPaintView::SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, BOOL bDontRemoveHardAttr
)
1243 pDefaultStyleSheet
=pStyleSheet
;
1244 if (pStyleSheet
!=NULL
&& !bDontRemoveHardAttr
) {
1245 SfxWhichIter
aIter(pStyleSheet
->GetItemSet());
1246 USHORT nWhich
=aIter
.FirstWhich();
1248 if (pStyleSheet
->GetItemSet().GetItemState(nWhich
,TRUE
)==SFX_ITEM_SET
) {
1249 aDefaultAttr
.ClearItem(nWhich
);
1251 nWhich
=aIter
.NextWhich();
1255 if (pItemBrowser
!=NULL
) pItemBrowser
->SetDirty();
1259 /* new interface src537 */
1260 BOOL
SdrPaintView::GetAttributes(SfxItemSet
& rTargetSet
, BOOL bOnlyHardAttr
) const
1262 if(bOnlyHardAttr
|| !pDefaultStyleSheet
)
1264 rTargetSet
.Put(aDefaultAttr
, FALSE
);
1268 // sonst DefStyleSheet dazumergen
1269 rTargetSet
.Put(pDefaultStyleSheet
->GetItemSet(), FALSE
);
1270 rTargetSet
.Put(aDefaultAttr
, FALSE
);
1272 MergeNotPersistDefaultAttr(rTargetSet
, bOnlyHardAttr
);
1276 BOOL
SdrPaintView::SetAttributes(const SfxItemSet
& rSet
, BOOL bReplaceAll
)
1278 SetDefaultAttr(rSet
,bReplaceAll
);
1282 SfxStyleSheet
* SdrPaintView::GetStyleSheet() const // SfxStyleSheet* SdrPaintView::GetStyleSheet(BOOL& rOk) const
1285 return GetDefaultStyleSheet();
1288 BOOL
SdrPaintView::SetStyleSheet(SfxStyleSheet
* pStyleSheet
, BOOL bDontRemoveHardAttr
)
1290 SetDefaultStyleSheet(pStyleSheet
,bDontRemoveHardAttr
);
1294 ////////////////////////////////////////////////////////////////////////////////////////////////////
1297 void SdrPaintView::ShowItemBrowser(BOOL bShow
)
1300 if (pItemBrowser
==NULL
) {
1301 pItemBrowser
=new SdrItemBrowser(*(SdrView
*)this);
1302 pItemBrowser
->SetFloatingMode(TRUE
);
1304 pItemBrowser
->Show();
1305 pItemBrowser
->GrabFocus();
1307 if (pItemBrowser
!=NULL
) {
1308 pItemBrowser
->Hide();
1309 delete pItemBrowser
;
1316 void SdrPaintView::MakeVisible(const Rectangle
& rRect
, Window
& rWin
)
1318 MapMode
aMap(rWin
.GetMapMode());
1319 Size
aActualSize(rWin
.GetOutputSize());
1321 if( aActualSize
.Height() > 0 && aActualSize
.Width() > 0 )
1323 Size
aNewSize(rRect
.GetSize());
1324 BOOL bNewScale
=FALSE
;
1325 BOOL bNeedMoreX
=aNewSize
.Width()>aActualSize
.Width();
1326 BOOL bNeedMoreY
=aNewSize
.Height()>aActualSize
.Height();
1327 if (bNeedMoreX
|| bNeedMoreY
)
1330 // Neuen MapMode (Size+Org) setzen und dabei alles invalidieren
1331 Fraction
aXFact(aNewSize
.Width(),aActualSize
.Width());
1332 Fraction
aYFact(aNewSize
.Height(),aActualSize
.Height());
1333 if (aYFact
>aXFact
) aXFact
=aYFact
;
1334 aXFact
*=aMap
.GetScaleX();
1335 aXFact
.ReduceInaccurate(10); // Um Ueberlaeufe und BigInt-Mapping zu vermeiden
1336 aMap
.SetScaleX(aXFact
);
1337 aMap
.SetScaleY(aYFact
);
1338 rWin
.SetMapMode(aMap
);
1339 aActualSize
=rWin
.GetOutputSize();
1341 Point
aOrg(aMap
.GetOrigin());
1344 long r
=-aOrg
.X()+aActualSize
.Width()-1;
1346 long u
=-aOrg
.Y()+aActualSize
.Height()-1;
1347 if (l
>rRect
.Left()) dx
=rRect
.Left()-l
;
1348 else if (r
<rRect
.Right()) dx
=rRect
.Right()-r
;
1349 if (o
>rRect
.Top()) dy
=rRect
.Top()-o
;
1350 else if (u
<rRect
.Bottom()) dy
=rRect
.Bottom()-u
;
1351 aMap
.SetOrigin(Point(aOrg
.X()-dx
,aOrg
.Y()-dy
));
1353 if (dx
!=0 || dy
!=0) {
1354 rWin
.Scroll(-dx
,-dy
);
1355 rWin
.SetMapMode(aMap
);
1359 rWin
.SetMapMode(aMap
);
1360 InvalidateOneWin(rWin
);
1365 void SdrPaintView::DoConnect(SdrOle2Obj
* /*pOleObj*/)
1369 void SdrPaintView::SetAnimationEnabled( BOOL bEnable
)
1371 SetAnimationMode( bEnable
? SDR_ANIMATION_ANIMATE
: SDR_ANIMATION_DISABLE
);
1374 void SdrPaintView::SetAnimationPause( bool bSet
)
1376 if((bool)bAnimationPause
!= bSet
)
1378 bAnimationPause
= bSet
;
1382 for(sal_uInt32
b(0L); b
< mpPageView
->PageWindowCount(); b
++)
1384 const SdrPageWindow
& rPageWindow
= *(mpPageView
->GetPageWindow(b
));
1385 sdr::contact::ObjectContact
& rObjectContact
= rPageWindow
.GetObjectContact();
1386 sdr::animation::primitiveAnimator
& rAnimator
= rObjectContact
.getPrimitiveAnimator();
1388 if(rAnimator
.IsPaused() != bSet
)
1390 rAnimator
.SetPaused(bSet
);
1397 void SdrPaintView::SetAnimationMode( const SdrAnimationMode eMode
)
1399 eAnimationMode
= eMode
;
1402 void SdrPaintView::VisAreaChanged(const OutputDevice
* pOut
)
1408 SdrPageWindow
* pWindow
= mpPageView
->FindPageWindow(*((OutputDevice
*)pOut
));
1412 VisAreaChanged(*pWindow
);
1417 for(sal_uInt32
a(0L); a
< mpPageView
->PageWindowCount(); a
++)
1419 VisAreaChanged(*mpPageView
->GetPageWindow(a
));
1425 void SdrPaintView::VisAreaChanged(const SdrPageWindow
& /*rWindow*/)
1427 // notify SfxListener
1428 Broadcast(SvxViewHint(SvxViewHint::SVX_HINT_VIEWCHANGED
));
1431 const svtools::ColorConfig
& SdrPaintView::getColorConfig() const
1433 return maColorConfig
;
1436 void SdrPaintView::onChangeColorConfig()
1438 SetGridColor( Color( maColorConfig
.GetColorValue( svtools::DRAWGRID
).nColor
) );
1441 void SdrPaintView::SetGridColor( Color aColor
)
1443 maGridColor
= aColor
;
1446 Color
SdrPaintView::GetGridColor() const
1451 // #103834# Set background color for svx at SdrPageViews
1452 void SdrPaintView::SetApplicationBackgroundColor(Color aBackgroundColor
)
1456 mpPageView
->SetApplicationBackgroundColor(aBackgroundColor
);
1460 // #103911# Set document color for svx at SdrPageViews
1461 void SdrPaintView::SetApplicationDocumentColor(Color aDocumentColor
)
1465 mpPageView
->SetApplicationDocumentColor(aDocumentColor
);
1470 bool SdrPaintView::IsBufferedOutputAllowed() const
1472 return (mbBufferedOutputAllowed
&& maDrawinglayerOpt
.IsPaintBuffer());
1476 void SdrPaintView::SetBufferedOutputAllowed(bool bNew
)
1478 if(bNew
!= (bool)mbBufferedOutputAllowed
)
1480 mbBufferedOutputAllowed
= bNew
;
1484 bool SdrPaintView::IsBufferedOverlayAllowed() const
1486 return (mbBufferedOverlayAllowed
&& maDrawinglayerOpt
.IsOverlayBuffer());
1489 void SdrPaintView::SetBufferedOverlayAllowed(bool bNew
)
1491 if(bNew
!= (bool)mbBufferedOverlayAllowed
)
1493 mbBufferedOverlayAllowed
= bNew
;
1497 sal_Bool
SdrPaintView::IsPagePaintingAllowed() const
1499 return mbPagePaintingAllowed
;
1502 void SdrPaintView::SetPagePaintingAllowed(bool bNew
)
1504 if(bNew
!= (bool)mbPagePaintingAllowed
)
1506 mbPagePaintingAllowed
= bNew
;
1510 // #i38135# Sets the timer for Object animations and restarts.
1511 void SdrPaintView::SetAnimationTimer(sal_uInt32 nTime
)
1515 // first, reset all timers at all windows to 0L
1516 for(sal_uInt32
a(0L); a
< mpPageView
->PageWindowCount(); a
++)
1518 const SdrPageWindow
& rPageWindow
= *mpPageView
->GetPageWindow(a
);
1519 sdr::contact::ObjectContact
& rObjectContact
= rPageWindow
.GetObjectContact();
1520 sdr::animation::primitiveAnimator
& rAnimator
= rObjectContact
.getPrimitiveAnimator();
1521 rAnimator
.SetTime(nTime
);