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