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
SdrPreRenderDevice(OutputDevice & rOriginal)33cdf0e10cSrcweir SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
34cdf0e10cSrcweir : mrOutputDevice(rOriginal)
35cdf0e10cSrcweir {
36cdf0e10cSrcweir }
37cdf0e10cSrcweir
~SdrPreRenderDevice()38cdf0e10cSrcweir SdrPreRenderDevice::~SdrPreRenderDevice()
39cdf0e10cSrcweir {
40cdf0e10cSrcweir }
41cdf0e10cSrcweir
PreparePreRenderDevice()42cdf0e10cSrcweir void SdrPreRenderDevice::PreparePreRenderDevice()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir // compare size of maPreRenderDevice with size of visible area
45cdf0e10cSrcweir if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
46cdf0e10cSrcweir {
47cdf0e10cSrcweir maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
50cdf0e10cSrcweir // Also compare the MapModes for zoom/scroll changes
51cdf0e10cSrcweir if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
52cdf0e10cSrcweir {
53cdf0e10cSrcweir maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir // #i29186#
57cdf0e10cSrcweir maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
58cdf0e10cSrcweir maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
OutputPreRenderDevice(const Region & rExpandedRegion)61cdf0e10cSrcweir void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir // region to pixels
64e6f63103SArmin Le Grand const Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
65e6f63103SArmin Le Grand //RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
66e6f63103SArmin Le Grand //Rectangle aRegionRectanglePixel;
67cdf0e10cSrcweir
68cdf0e10cSrcweir // MapModes off
69cdf0e10cSrcweir sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
70cdf0e10cSrcweir sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
71cdf0e10cSrcweir mrOutputDevice.EnableMapMode(sal_False);
72cdf0e10cSrcweir maPreRenderDevice.EnableMapMode(sal_False);
73cdf0e10cSrcweir
74e6f63103SArmin Le Grand RectangleVector aRectangles;
75e6f63103SArmin Le Grand aRegionPixel.GetRegionRectangles(aRectangles);
76e6f63103SArmin Le Grand
77e6f63103SArmin Le Grand for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir // for each rectangle, copy the area
80e6f63103SArmin Le Grand const Point aTopLeft(aRectIter->TopLeft());
81e6f63103SArmin Le Grand const Size aSize(aRectIter->GetSize());
82cdf0e10cSrcweir
83cdf0e10cSrcweir mrOutputDevice.DrawOutDev(
84cdf0e10cSrcweir aTopLeft, aSize,
85cdf0e10cSrcweir aTopLeft, aSize,
86cdf0e10cSrcweir maPreRenderDevice);
87cdf0e10cSrcweir
88cdf0e10cSrcweir #ifdef DBG_UTIL
89cdf0e10cSrcweir // #i74769#
90cdf0e10cSrcweir static bool bDoPaintForVisualControlRegion(false);
91e6f63103SArmin Le Grand
92cdf0e10cSrcweir if(bDoPaintForVisualControlRegion)
93cdf0e10cSrcweir {
94e6f63103SArmin Le Grand const Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
95e6f63103SArmin Le Grand
96cdf0e10cSrcweir mrOutputDevice.SetLineColor(aColor);
97cdf0e10cSrcweir mrOutputDevice.SetFillColor();
98e6f63103SArmin Le Grand mrOutputDevice.DrawRect(*aRectIter);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir #endif
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103e6f63103SArmin Le Grand // while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
104e6f63103SArmin Le Grand // {
105e6f63103SArmin Le Grand // // for each rectangle, copy the area
106e6f63103SArmin Le Grand // const Point aTopLeft(aRegionRectanglePixel.TopLeft());
107e6f63103SArmin Le Grand // const Size aSize(aRegionRectanglePixel.GetSize());
108e6f63103SArmin Le Grand //
109e6f63103SArmin Le Grand // mrOutputDevice.DrawOutDev(
110e6f63103SArmin Le Grand // aTopLeft, aSize,
111e6f63103SArmin Le Grand // aTopLeft, aSize,
112e6f63103SArmin Le Grand // maPreRenderDevice);
113e6f63103SArmin Le Grand //
114e6f63103SArmin Le Grand //#ifdef DBG_UTIL
115e6f63103SArmin Le Grand // // #i74769#
116e6f63103SArmin Le Grand // static bool bDoPaintForVisualControlRegion(false);
117e6f63103SArmin Le Grand // if(bDoPaintForVisualControlRegion)
118e6f63103SArmin Le Grand // {
119e6f63103SArmin Le Grand // Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
120e6f63103SArmin Le Grand // mrOutputDevice.SetLineColor(aColor);
121e6f63103SArmin Le Grand // mrOutputDevice.SetFillColor();
122e6f63103SArmin Le Grand // mrOutputDevice.DrawRect(aRegionRectanglePixel);
123e6f63103SArmin Le Grand // }
124e6f63103SArmin Le Grand //#endif
125e6f63103SArmin Le Grand // }
126e6f63103SArmin Le Grand //
127e6f63103SArmin Le Grand // aRegionPixel.EndEnumRects(aRegionHandle);
128cdf0e10cSrcweir
129cdf0e10cSrcweir mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
130cdf0e10cSrcweir maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir
impCreateOverlayManager()134a56bd57bSArmin Le Grand void SdrPaintWindow::impCreateOverlayManager()
135cdf0e10cSrcweir {
136cdf0e10cSrcweir // not yet one created?
137cdf0e10cSrcweir if(!mpOverlayManager)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir // is it a window?
140cdf0e10cSrcweir if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
141cdf0e10cSrcweir {
142cdf0e10cSrcweir // decide which OverlayManager to use
143cdf0e10cSrcweir if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
144cdf0e10cSrcweir {
145*4d196ef4Smseidel // buffered OverlayManager, buffers its background and refreshes from there
146cdf0e10cSrcweir // for pure overlay changes (no system redraw). The 3rd parameter specifies
147cdf0e10cSrcweir // if that refresh itself will use a 2nd vdev to avoid flickering.
148cdf0e10cSrcweir // Also hand over the evtl. existing old OverlayManager; this means to take over
149cdf0e10cSrcweir // the registered OverlayObjects from it
150a56bd57bSArmin Le Grand mpOverlayManager = new ::sdr::overlay::OverlayManagerBuffered(GetOutputDevice(), true);
151cdf0e10cSrcweir }
152cdf0e10cSrcweir else
153cdf0e10cSrcweir {
154cdf0e10cSrcweir // unbuffered OverlayManager, just invalidates places where changes
155cdf0e10cSrcweir // take place
156cdf0e10cSrcweir // Also hand over the evtl. existing old OverlayManager; this means to take over
157cdf0e10cSrcweir // the registered OverlayObjects from it
158a56bd57bSArmin Le Grand mpOverlayManager = new ::sdr::overlay::OverlayManager(GetOutputDevice());
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir OSL_ENSURE(mpOverlayManager, "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
162cdf0e10cSrcweir
163cdf0e10cSrcweir // Request a repaint so that the buffered overlay manager fills
164cdf0e10cSrcweir // its buffer properly. This is a workaround for missing buffer
165cdf0e10cSrcweir // updates.
166cdf0e10cSrcweir Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
167cdf0e10cSrcweir if (pWindow != NULL)
168cdf0e10cSrcweir pWindow->Invalidate();
169cdf0e10cSrcweir
170cdf0e10cSrcweir Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
171cdf0e10cSrcweir Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
172cdf0e10cSrcweir
173cdf0e10cSrcweir if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
174cdf0e10cSrcweir {
175cdf0e10cSrcweir aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
176cdf0e10cSrcweir aColB.Invert();
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir mpOverlayManager->setStripeColorA(aColA);
180cdf0e10cSrcweir mpOverlayManager->setStripeColorB(aColB);
181cdf0e10cSrcweir mpOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
182cdf0e10cSrcweir }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
SdrPaintWindow(SdrPaintView & rNewPaintView,OutputDevice & rOut)186cdf0e10cSrcweir SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
187cdf0e10cSrcweir : mrOutputDevice(rOut),
188cdf0e10cSrcweir mrPaintView(rNewPaintView),
189cdf0e10cSrcweir mpOverlayManager(0L),
190cdf0e10cSrcweir mpPreRenderDevice(0L),
191cdf0e10cSrcweir mbTemporaryTarget(false), // #i72889#
192cdf0e10cSrcweir mbUseBuffer(true)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
~SdrPaintWindow()196cdf0e10cSrcweir SdrPaintWindow::~SdrPaintWindow()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir if(mpOverlayManager)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir delete mpOverlayManager;
201cdf0e10cSrcweir mpOverlayManager = 0L;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir DestroyPreRenderDevice();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
GetOverlayManager() const207cdf0e10cSrcweir ::sdr::overlay::OverlayManager* SdrPaintWindow::GetOverlayManager() const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir if(!mpOverlayManager)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir // Create buffered overlay manager by default.
212a56bd57bSArmin Le Grand const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir return mpOverlayManager;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
GetVisibleArea() const218cdf0e10cSrcweir Rectangle SdrPaintWindow::GetVisibleArea() const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
221cdf0e10cSrcweir return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
OutputToRecordingMetaFile() const224cdf0e10cSrcweir sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const
225cdf0e10cSrcweir {
226cdf0e10cSrcweir GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
227cdf0e10cSrcweir return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
PreparePreRenderDevice()230cdf0e10cSrcweir void SdrPaintWindow::PreparePreRenderDevice()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir const sal_Bool bPrepareBufferedOutput(
233cdf0e10cSrcweir mrPaintView.IsBufferedOutputAllowed()
234cdf0e10cSrcweir && !OutputToPrinter()
235cdf0e10cSrcweir && !OutputToVirtualDevice()
236cdf0e10cSrcweir && !OutputToRecordingMetaFile());
237cdf0e10cSrcweir
238cdf0e10cSrcweir if(bPrepareBufferedOutput)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir if(!mpPreRenderDevice)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir else
246cdf0e10cSrcweir {
247cdf0e10cSrcweir DestroyPreRenderDevice();
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir if(mpPreRenderDevice)
251cdf0e10cSrcweir {
252cdf0e10cSrcweir mpPreRenderDevice->PreparePreRenderDevice();
253cdf0e10cSrcweir }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
DestroyPreRenderDevice()256cdf0e10cSrcweir void SdrPaintWindow::DestroyPreRenderDevice()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir if(mpPreRenderDevice)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir delete mpPreRenderDevice;
261cdf0e10cSrcweir mpPreRenderDevice = 0L;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
OutputPreRenderDevice(const Region & rExpandedRegion)265cdf0e10cSrcweir void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir if(mpPreRenderDevice)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir // #i73602# add flag if buffer shall be used
DrawOverlay(const Region & rRegion)274a56bd57bSArmin Le Grand void SdrPaintWindow::DrawOverlay(const Region& rRegion)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir // ## force creation of OverlayManager since the first repaint needs to
277cdf0e10cSrcweir // save the background to get a controlled start into overlay mechanism
278a56bd57bSArmin Le Grand impCreateOverlayManager();
279cdf0e10cSrcweir
280cdf0e10cSrcweir if(mpOverlayManager && !OutputToPrinter())
281cdf0e10cSrcweir {
282a56bd57bSArmin Le Grand if(mpPreRenderDevice)
283cdf0e10cSrcweir {
284cdf0e10cSrcweir mpOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
285cdf0e10cSrcweir }
286cdf0e10cSrcweir else
287cdf0e10cSrcweir {
288cdf0e10cSrcweir mpOverlayManager->completeRedraw(rRegion);
289cdf0e10cSrcweir }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
HideOverlay(const Region & rRegion)293cdf0e10cSrcweir void SdrPaintWindow::HideOverlay(const Region& rRegion)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir if(mpOverlayManager && !OutputToPrinter())
296cdf0e10cSrcweir {
297cdf0e10cSrcweir if(!mpPreRenderDevice)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir mpOverlayManager->restoreBackground(rRegion);
300cdf0e10cSrcweir }
301cdf0e10cSrcweir }
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
GetRedrawRegion() const304cdf0e10cSrcweir const Region& SdrPaintWindow::GetRedrawRegion() const
305cdf0e10cSrcweir {
306cdf0e10cSrcweir return maRedrawRegion;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
SetRedrawRegion(const Region & rNew)309cdf0e10cSrcweir void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir maRedrawRegion = rNew;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314*4d196ef4Smseidel /* vim: set noet sw=4 ts=4: */
315