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: sdrpaintwindow.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 <sdrpaintwindow.hxx>
34 #include <svx/sdr/overlay/overlaymanagerbuffered.hxx>
35 #include <svx/svdpntv.hxx>
36 #include <vcl/gdimtf.hxx>
37 #include <vcl/svapp.hxx>
39 ////////////////////////////////////////////////////////////////////////////////////////////////////
41 SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice
& rOriginal
)
42 : mrOutputDevice(rOriginal
)
46 SdrPreRenderDevice::~SdrPreRenderDevice()
50 void SdrPreRenderDevice::PreparePreRenderDevice()
52 // compare size of maPreRenderDevice with size of visible area
53 if(maPreRenderDevice
.GetOutputSizePixel() != mrOutputDevice
.GetOutputSizePixel())
55 maPreRenderDevice
.SetOutputSizePixel(mrOutputDevice
.GetOutputSizePixel());
58 // Also compare the MapModes for zoom/scroll changes
59 if(maPreRenderDevice
.GetMapMode() != mrOutputDevice
.GetMapMode())
61 maPreRenderDevice
.SetMapMode(mrOutputDevice
.GetMapMode());
65 maPreRenderDevice
.SetDrawMode(mrOutputDevice
.GetDrawMode());
66 maPreRenderDevice
.SetSettings(mrOutputDevice
.GetSettings());
69 void SdrPreRenderDevice::OutputPreRenderDevice(const Region
& rExpandedRegion
)
72 Region
aRegionPixel(mrOutputDevice
.LogicToPixel(rExpandedRegion
));
73 RegionHandle
aRegionHandle(aRegionPixel
.BeginEnumRects());
74 Rectangle aRegionRectanglePixel
;
77 sal_Bool
bMapModeWasEnabledDest(mrOutputDevice
.IsMapModeEnabled());
78 sal_Bool
bMapModeWasEnabledSource(maPreRenderDevice
.IsMapModeEnabled());
79 mrOutputDevice
.EnableMapMode(sal_False
);
80 maPreRenderDevice
.EnableMapMode(sal_False
);
82 while(aRegionPixel
.GetEnumRects(aRegionHandle
, aRegionRectanglePixel
))
84 // for each rectangle, copy the area
85 const Point
aTopLeft(aRegionRectanglePixel
.TopLeft());
86 const Size
aSize(aRegionRectanglePixel
.GetSize());
88 mrOutputDevice
.DrawOutDev(
95 static bool bDoPaintForVisualControlRegion(false);
96 if(bDoPaintForVisualControlRegion
)
98 Color
aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
99 mrOutputDevice
.SetLineColor(aColor
);
100 mrOutputDevice
.SetFillColor();
101 mrOutputDevice
.DrawRect(aRegionRectanglePixel
);
106 aRegionPixel
.EndEnumRects(aRegionHandle
);
108 mrOutputDevice
.EnableMapMode(bMapModeWasEnabledDest
);
109 maPreRenderDevice
.EnableMapMode(bMapModeWasEnabledSource
);
112 ////////////////////////////////////////////////////////////////////////////////////////////////////
114 void SdrPaintWindow::impCreateOverlayManager(const bool bUseBuffer
)
116 // When the buffer usage has changed then we have to create a new
117 // overlay manager. Save the current one so that later we can move its
118 // overlay objects to the new one.
119 sdr::overlay::OverlayManager
* pOldOverlayManager
= NULL
;
121 if(mbUseBuffer
!= bUseBuffer
)
123 mbUseBuffer
= bUseBuffer
;
124 pOldOverlayManager
= mpOverlayManager
;
125 mpOverlayManager
= NULL
;
128 // not yet one created?
129 if(!mpOverlayManager
)
132 if(OUTDEV_WINDOW
== GetOutputDevice().GetOutDevType())
134 // decide which OverlayManager to use
135 if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer
)
137 // buffered OverlayManager, buffers it's background and refreshes from there
138 // for pure overlay changes (no system redraw). The 3rd parameter specifies
139 // if that refresh itself will use a 2nd vdev to avoid flickering.
140 // Also hand over the evtl. existing old OverlayManager; this means to take over
141 // the registered OverlayObjects from it
142 mpOverlayManager
= new ::sdr::overlay::OverlayManagerBuffered(GetOutputDevice(), pOldOverlayManager
, true);
146 // unbuffered OverlayManager, just invalidates places where changes
148 // Also hand over the evtl. existing old OverlayManager; this means to take over
149 // the registered OverlayObjects from it
150 mpOverlayManager
= new ::sdr::overlay::OverlayManager(GetOutputDevice(), pOldOverlayManager
);
153 OSL_ENSURE(mpOverlayManager
, "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
155 // Request a repaint so that the buffered overlay manager fills
156 // its buffer properly. This is a workaround for missing buffer
158 Window
* pWindow
= dynamic_cast<Window
*>(&GetOutputDevice());
160 pWindow
->Invalidate();
162 Color
aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
163 Color
aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
165 if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
167 aColA
= aColB
= Application::GetSettings().GetStyleSettings().GetHighlightColor();
171 mpOverlayManager
->setStripeColorA(aColA
);
172 mpOverlayManager
->setStripeColorB(aColB
);
173 mpOverlayManager
->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
177 // OverlayObjects are transfered for the evtl. newly created OverlayManager by handing over
178 // at construction time
179 if(pOldOverlayManager
)
181 // The old overlay manager is not used anymore and can be (has to be) deleted.
182 delete pOldOverlayManager
;
186 SdrPaintWindow::SdrPaintWindow(SdrPaintView
& rNewPaintView
, OutputDevice
& rOut
)
187 : mrOutputDevice(rOut
),
188 mrPaintView(rNewPaintView
),
189 mpOverlayManager(0L),
190 mpPreRenderDevice(0L),
191 mbTemporaryTarget(false), // #i72889#
196 SdrPaintWindow::~SdrPaintWindow()
200 delete mpOverlayManager
;
201 mpOverlayManager
= 0L;
204 DestroyPreRenderDevice();
207 ::sdr::overlay::OverlayManager
* SdrPaintWindow::GetOverlayManager() const
209 if(!mpOverlayManager
)
211 // Create buffered overlay manager by default.
212 const_cast< SdrPaintWindow
* >(this)->impCreateOverlayManager(true);
215 return mpOverlayManager
;
218 Rectangle
SdrPaintWindow::GetVisibleArea() const
220 Size
aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
221 return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel
)));
224 sal_Bool
SdrPaintWindow::OutputToRecordingMetaFile() const
226 GDIMetaFile
* pMetaFile
= mrOutputDevice
.GetConnectMetaFile();
227 return (pMetaFile
&& pMetaFile
->IsRecord() && !pMetaFile
->IsPause());
230 void SdrPaintWindow::PreparePreRenderDevice()
232 const sal_Bool
bPrepareBufferedOutput(
233 mrPaintView
.IsBufferedOutputAllowed()
234 && !OutputToPrinter()
235 && !OutputToVirtualDevice()
236 && !OutputToRecordingMetaFile());
238 if(bPrepareBufferedOutput
)
240 if(!mpPreRenderDevice
)
242 mpPreRenderDevice
= new SdrPreRenderDevice(mrOutputDevice
);
247 DestroyPreRenderDevice();
250 if(mpPreRenderDevice
)
252 mpPreRenderDevice
->PreparePreRenderDevice();
256 void SdrPaintWindow::DestroyPreRenderDevice()
258 if(mpPreRenderDevice
)
260 delete mpPreRenderDevice
;
261 mpPreRenderDevice
= 0L;
265 void SdrPaintWindow::OutputPreRenderDevice(const Region
& rExpandedRegion
)
267 if(mpPreRenderDevice
)
269 mpPreRenderDevice
->OutputPreRenderDevice(rExpandedRegion
);
273 // #i73602# add flag if buffer shall be used
274 void SdrPaintWindow::DrawOverlay(const Region
& rRegion
, bool bUseBuffer
)
276 // ## force creation of OverlayManager since the first repaint needs to
277 // save the background to get a controlled start into overlay mechanism
278 impCreateOverlayManager(bUseBuffer
);
280 if(mpOverlayManager
&& !OutputToPrinter())
282 if(mpPreRenderDevice
&& bUseBuffer
)
284 mpOverlayManager
->completeRedraw(rRegion
, &mpPreRenderDevice
->GetPreRenderDevice());
288 mpOverlayManager
->completeRedraw(rRegion
);
293 void SdrPaintWindow::HideOverlay(const Region
& rRegion
)
295 if(mpOverlayManager
&& !OutputToPrinter())
297 if(!mpPreRenderDevice
)
299 mpOverlayManager
->restoreBackground(rRegion
);
304 const Region
& SdrPaintWindow::GetRedrawRegion() const
306 return maRedrawRegion
;
309 void SdrPaintWindow::SetRedrawRegion(const Region
& rNew
)
311 maRedrawRegion
= rNew
;
314 ////////////////////////////////////////////////////////////////////////////////////////////////////