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