xref: /AOO41X/main/svx/source/svdraw/sdrpaintwindow.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
31*cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanagerbuffered.hxx>
32*cdf0e10cSrcweir #include <svx/svdpntv.hxx>
33*cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
34*cdf0e10cSrcweir #include <vcl/svapp.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
39*cdf0e10cSrcweir :	mrOutputDevice(rOriginal)
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir }
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir SdrPreRenderDevice::~SdrPreRenderDevice()
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir }
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir void SdrPreRenderDevice::PreparePreRenderDevice()
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir 	// compare size of maPreRenderDevice with size of visible area
50*cdf0e10cSrcweir 	if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
51*cdf0e10cSrcweir 	{
52*cdf0e10cSrcweir 		maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
53*cdf0e10cSrcweir 	}
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 	// Also compare the MapModes for zoom/scroll changes
56*cdf0e10cSrcweir 	if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
57*cdf0e10cSrcweir 	{
58*cdf0e10cSrcweir 		maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
59*cdf0e10cSrcweir 	}
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	// #i29186#
62*cdf0e10cSrcweir 	maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
63*cdf0e10cSrcweir 	maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	// region to pixels
69*cdf0e10cSrcweir 	Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
70*cdf0e10cSrcweir 	RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
71*cdf0e10cSrcweir 	Rectangle aRegionRectanglePixel;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	// MapModes off
74*cdf0e10cSrcweir 	sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
75*cdf0e10cSrcweir 	sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
76*cdf0e10cSrcweir 	mrOutputDevice.EnableMapMode(sal_False);
77*cdf0e10cSrcweir 	maPreRenderDevice.EnableMapMode(sal_False);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 		// for each rectangle, copy the area
82*cdf0e10cSrcweir 		const Point aTopLeft(aRegionRectanglePixel.TopLeft());
83*cdf0e10cSrcweir 		const Size aSize(aRegionRectanglePixel.GetSize());
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 		mrOutputDevice.DrawOutDev(
86*cdf0e10cSrcweir 			aTopLeft, aSize,
87*cdf0e10cSrcweir 			aTopLeft, aSize,
88*cdf0e10cSrcweir 			maPreRenderDevice);
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir #ifdef DBG_UTIL
91*cdf0e10cSrcweir 		// #i74769#
92*cdf0e10cSrcweir 		static bool bDoPaintForVisualControlRegion(false);
93*cdf0e10cSrcweir 		if(bDoPaintForVisualControlRegion)
94*cdf0e10cSrcweir 		{
95*cdf0e10cSrcweir 			Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
96*cdf0e10cSrcweir 			mrOutputDevice.SetLineColor(aColor);
97*cdf0e10cSrcweir 			mrOutputDevice.SetFillColor();
98*cdf0e10cSrcweir 			mrOutputDevice.DrawRect(aRegionRectanglePixel);
99*cdf0e10cSrcweir 		}
100*cdf0e10cSrcweir #endif
101*cdf0e10cSrcweir 	}
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	aRegionPixel.EndEnumRects(aRegionHandle);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
106*cdf0e10cSrcweir 	maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void SdrPaintWindow::impCreateOverlayManager(const bool bUseBuffer)
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     // When the buffer usage has changed then we have to create a new
114*cdf0e10cSrcweir     // overlay manager.  Save the current one so that later we can move its
115*cdf0e10cSrcweir     // overlay objects to the new one.
116*cdf0e10cSrcweir     sdr::overlay::OverlayManager* pOldOverlayManager = NULL;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	if(mbUseBuffer != bUseBuffer)
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         mbUseBuffer = bUseBuffer;
121*cdf0e10cSrcweir         pOldOverlayManager = mpOverlayManager;
122*cdf0e10cSrcweir         mpOverlayManager = NULL;
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	// not yet one created?
126*cdf0e10cSrcweir 	if(!mpOverlayManager)
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir 		// is it a window?
129*cdf0e10cSrcweir 		if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
130*cdf0e10cSrcweir 		{
131*cdf0e10cSrcweir 			// decide which OverlayManager to use
132*cdf0e10cSrcweir 			if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
133*cdf0e10cSrcweir 			{
134*cdf0e10cSrcweir 				// buffered OverlayManager, buffers it's background and refreshes from there
135*cdf0e10cSrcweir 				// for pure overlay changes (no system redraw). The 3rd parameter specifies
136*cdf0e10cSrcweir 				// if that refresh itself will use a 2nd vdev to avoid flickering.
137*cdf0e10cSrcweir 				// Also hand over the evtl. existing old OverlayManager; this means to take over
138*cdf0e10cSrcweir 				// the registered OverlayObjects from it
139*cdf0e10cSrcweir 				mpOverlayManager = new ::sdr::overlay::OverlayManagerBuffered(GetOutputDevice(), pOldOverlayManager, true);
140*cdf0e10cSrcweir 			}
141*cdf0e10cSrcweir 			else
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir 				// unbuffered OverlayManager, just invalidates places where changes
144*cdf0e10cSrcweir 				// take place
145*cdf0e10cSrcweir 				// Also hand over the evtl. existing old OverlayManager; this means to take over
146*cdf0e10cSrcweir 				// the registered OverlayObjects from it
147*cdf0e10cSrcweir 				mpOverlayManager = new ::sdr::overlay::OverlayManager(GetOutputDevice(), pOldOverlayManager);
148*cdf0e10cSrcweir 			}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 			OSL_ENSURE(mpOverlayManager, "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir             // Request a repaint so that the buffered overlay manager fills
153*cdf0e10cSrcweir             // its buffer properly.  This is a workaround for missing buffer
154*cdf0e10cSrcweir             // updates.
155*cdf0e10cSrcweir             Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
156*cdf0e10cSrcweir             if (pWindow != NULL)
157*cdf0e10cSrcweir                 pWindow->Invalidate();
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
160*cdf0e10cSrcweir 			Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 			if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
163*cdf0e10cSrcweir 			{
164*cdf0e10cSrcweir 				aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
165*cdf0e10cSrcweir 				aColB.Invert();
166*cdf0e10cSrcweir 			}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 			mpOverlayManager->setStripeColorA(aColA);
169*cdf0e10cSrcweir 			mpOverlayManager->setStripeColorB(aColB);
170*cdf0e10cSrcweir 			mpOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
171*cdf0e10cSrcweir 		}
172*cdf0e10cSrcweir 	}
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	// OverlayObjects are transfered for the evtl. newly created OverlayManager by handing over
175*cdf0e10cSrcweir 	// at construction time
176*cdf0e10cSrcweir 	if(pOldOverlayManager)
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         // The old overlay manager is not used anymore and can be (has to be) deleted.
179*cdf0e10cSrcweir         delete pOldOverlayManager;
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
184*cdf0e10cSrcweir :	mrOutputDevice(rOut),
185*cdf0e10cSrcweir 	mrPaintView(rNewPaintView),
186*cdf0e10cSrcweir 	mpOverlayManager(0L),
187*cdf0e10cSrcweir 	mpPreRenderDevice(0L),
188*cdf0e10cSrcweir 	mbTemporaryTarget(false), // #i72889#
189*cdf0e10cSrcweir     mbUseBuffer(true)
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir SdrPaintWindow::~SdrPaintWindow()
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	if(mpOverlayManager)
196*cdf0e10cSrcweir 	{
197*cdf0e10cSrcweir 		delete mpOverlayManager;
198*cdf0e10cSrcweir 		mpOverlayManager = 0L;
199*cdf0e10cSrcweir 	}
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	DestroyPreRenderDevice();
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir ::sdr::overlay::OverlayManager* SdrPaintWindow::GetOverlayManager() const
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	if(!mpOverlayManager)
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir         // Create buffered overlay manager by default.
209*cdf0e10cSrcweir 		const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager(true);
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	return mpOverlayManager;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir Rectangle SdrPaintWindow::GetVisibleArea() const
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
218*cdf0e10cSrcweir 	return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
224*cdf0e10cSrcweir 	return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void SdrPaintWindow::PreparePreRenderDevice()
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir 	const sal_Bool bPrepareBufferedOutput(
230*cdf0e10cSrcweir 		mrPaintView.IsBufferedOutputAllowed()
231*cdf0e10cSrcweir 		&& !OutputToPrinter()
232*cdf0e10cSrcweir 		&& !OutputToVirtualDevice()
233*cdf0e10cSrcweir 		&& !OutputToRecordingMetaFile());
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	if(bPrepareBufferedOutput)
236*cdf0e10cSrcweir 	{
237*cdf0e10cSrcweir 		if(!mpPreRenderDevice)
238*cdf0e10cSrcweir 		{
239*cdf0e10cSrcweir 			mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
240*cdf0e10cSrcweir 		}
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir 	else
243*cdf0e10cSrcweir 	{
244*cdf0e10cSrcweir 		DestroyPreRenderDevice();
245*cdf0e10cSrcweir 	}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	if(mpPreRenderDevice)
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 		mpPreRenderDevice->PreparePreRenderDevice();
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void SdrPaintWindow::DestroyPreRenderDevice()
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	if(mpPreRenderDevice)
256*cdf0e10cSrcweir 	{
257*cdf0e10cSrcweir 		delete mpPreRenderDevice;
258*cdf0e10cSrcweir 		mpPreRenderDevice = 0L;
259*cdf0e10cSrcweir 	}
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir 	if(mpPreRenderDevice)
265*cdf0e10cSrcweir 	{
266*cdf0e10cSrcweir 		mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir // #i73602# add flag if buffer shall be used
271*cdf0e10cSrcweir void SdrPaintWindow::DrawOverlay(const Region& rRegion, bool bUseBuffer)
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir 	// ## force creation of OverlayManager since the first repaint needs to
274*cdf0e10cSrcweir 	// save the background to get a controlled start into overlay mechanism
275*cdf0e10cSrcweir 	impCreateOverlayManager(bUseBuffer);
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	if(mpOverlayManager && !OutputToPrinter())
278*cdf0e10cSrcweir 	{
279*cdf0e10cSrcweir 		if(mpPreRenderDevice && bUseBuffer)
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			mpOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 		else
284*cdf0e10cSrcweir 		{
285*cdf0e10cSrcweir 			mpOverlayManager->completeRedraw(rRegion);
286*cdf0e10cSrcweir 		}
287*cdf0e10cSrcweir 	}
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir void SdrPaintWindow::HideOverlay(const Region& rRegion)
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	if(mpOverlayManager && !OutputToPrinter())
293*cdf0e10cSrcweir 	{
294*cdf0e10cSrcweir 		if(!mpPreRenderDevice)
295*cdf0e10cSrcweir 		{
296*cdf0e10cSrcweir 			mpOverlayManager->restoreBackground(rRegion);
297*cdf0e10cSrcweir 		}
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir const Region& SdrPaintWindow::GetRedrawRegion() const
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	return maRedrawRegion;
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 	maRedrawRegion = rNew;
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
312*cdf0e10cSrcweir // eof
313