Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svx/sdrpaintwindow.hxx>
21 : #include <svx/sdr/overlay/overlaymanagerbuffered.hxx>
22 : #include <svx/svdpntv.hxx>
23 : #include <vcl/gdimtf.hxx>
24 : #include <vcl/svapp.hxx>
25 :
26 : ////////////////////////////////////////////////////////////////////////////////////////////////////
27 :
28 330 : SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
29 330 : : mrOutputDevice(rOriginal)
30 : {
31 330 : }
32 :
33 18 : SdrPreRenderDevice::~SdrPreRenderDevice()
34 : {
35 18 : }
36 :
37 689 : void SdrPreRenderDevice::PreparePreRenderDevice()
38 : {
39 : // compare size of maPreRenderDevice with size of visible area
40 689 : if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
41 : {
42 332 : maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
43 : }
44 :
45 : // Also compare the MapModes for zoom/scroll changes
46 689 : if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
47 : {
48 356 : maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
49 : }
50 :
51 : // #i29186#
52 689 : maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
53 689 : maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
54 689 : }
55 :
56 689 : void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
57 : {
58 : // region to pixels
59 689 : Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
60 689 : RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
61 689 : Rectangle aRegionRectanglePixel;
62 :
63 : // MapModes off
64 689 : sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
65 689 : sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
66 689 : mrOutputDevice.EnableMapMode(sal_False);
67 689 : maPreRenderDevice.EnableMapMode(sal_False);
68 :
69 2078 : while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
70 : {
71 : // for each rectangle, copy the area
72 700 : const Point aTopLeft(aRegionRectanglePixel.TopLeft());
73 700 : const Size aSize(aRegionRectanglePixel.GetSize());
74 :
75 : mrOutputDevice.DrawOutDev(
76 : aTopLeft, aSize,
77 : aTopLeft, aSize,
78 700 : maPreRenderDevice);
79 :
80 : #ifdef DBG_UTIL
81 : // #i74769#
82 : static bool bDoPaintForVisualControlRegion(false);
83 : if(bDoPaintForVisualControlRegion)
84 : {
85 : Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
86 : mrOutputDevice.SetLineColor(aColor);
87 : mrOutputDevice.SetFillColor();
88 : mrOutputDevice.DrawRect(aRegionRectanglePixel);
89 : }
90 : #endif
91 : }
92 :
93 689 : aRegionPixel.EndEnumRects(aRegionHandle);
94 :
95 689 : mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
96 689 : maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
97 689 : }
98 :
99 : ////////////////////////////////////////////////////////////////////////////////////////////////////
100 :
101 737 : void SdrPaintWindow::impCreateOverlayManager(const bool bUseBuffer)
102 : {
103 : // When the buffer usage has changed then we have to create a new
104 : // overlay manager. Save the current one so that later we can move its
105 : // overlay objects to the new one.
106 737 : rtl::Reference<sdr::overlay::OverlayManager> xOldOverlayManager;
107 :
108 737 : if(mbUseBuffer != bUseBuffer)
109 : {
110 0 : mbUseBuffer = bUseBuffer;
111 0 : xOldOverlayManager = mxOverlayManager;
112 0 : mxOverlayManager.clear();
113 : }
114 :
115 : // not yet one created?
116 737 : if(!mxOverlayManager.is())
117 : {
118 : // is it a window?
119 362 : if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
120 : {
121 : // decide which OverlayManager to use
122 356 : if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
123 : {
124 : // buffered OverlayManager, buffers its background and refreshes from there
125 : // for pure overlay changes (no system redraw). The 3rd parameter specifies
126 : // whether that refresh itself will use a 2nd vdev to avoid flickering.
127 : // Also hand over the old OverlayManager if existent; this means to take over
128 : // the registered OverlayObjects from it
129 356 : mxOverlayManager = ::sdr::overlay::OverlayManagerBuffered::create(GetOutputDevice(),
130 712 : xOldOverlayManager.get(), true);
131 : }
132 : else
133 : {
134 : // unbuffered OverlayManager, just invalidates places where changes
135 : // take place
136 : // Also hand over the old OverlayManager if existent; this means to take over
137 : // the registered OverlayObjects from it
138 0 : mxOverlayManager = ::sdr::overlay::OverlayManager::create(GetOutputDevice(),
139 0 : xOldOverlayManager.get());
140 : }
141 :
142 : OSL_ENSURE(mxOverlayManager.is(), "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
143 :
144 : // Request a repaint so that the buffered overlay manager fills
145 : // its buffer properly. This is a workaround for missing buffer
146 : // updates.
147 356 : Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
148 356 : if (pWindow != NULL)
149 356 : pWindow->Invalidate();
150 :
151 356 : Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
152 356 : Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
153 :
154 356 : if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
155 : {
156 0 : aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
157 0 : aColB.Invert();
158 : }
159 :
160 356 : mxOverlayManager->setStripeColorA(aColA);
161 356 : mxOverlayManager->setStripeColorB(aColB);
162 356 : mxOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
163 : }
164 737 : }
165 737 : }
166 :
167 2637 : SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
168 : : mrOutputDevice(rOut),
169 : mrPaintView(rNewPaintView),
170 : mpPreRenderDevice(0L),
171 : mbTemporaryTarget(false), // #i72889#
172 2637 : mbUseBuffer(true)
173 : {
174 2637 : }
175 :
176 4454 : SdrPaintWindow::~SdrPaintWindow()
177 : {
178 2227 : mxOverlayManager.clear();
179 :
180 2227 : DestroyPreRenderDevice();
181 2227 : }
182 :
183 320 : rtl::Reference< ::sdr::overlay::OverlayManager > SdrPaintWindow::GetOverlayManager() const
184 : {
185 320 : if(!mxOverlayManager.is())
186 : {
187 : // Create buffered overlay manager by default.
188 42 : const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager(true);
189 : }
190 :
191 320 : return mxOverlayManager;
192 : }
193 :
194 0 : Rectangle SdrPaintWindow::GetVisibleArea() const
195 : {
196 0 : Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
197 0 : return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
198 : }
199 :
200 689 : sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const
201 : {
202 689 : GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
203 689 : return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
204 : }
205 :
206 695 : void SdrPaintWindow::PreparePreRenderDevice()
207 : {
208 : const sal_Bool bPrepareBufferedOutput(
209 695 : mrPaintView.IsBufferedOutputAllowed()
210 693 : && !OutputToPrinter()
211 693 : && !OutputToVirtualDevice()
212 2081 : && !OutputToRecordingMetaFile());
213 :
214 695 : if(bPrepareBufferedOutput)
215 : {
216 689 : if(!mpPreRenderDevice)
217 : {
218 330 : mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
219 : }
220 : }
221 : else
222 : {
223 6 : DestroyPreRenderDevice();
224 : }
225 :
226 695 : if(mpPreRenderDevice)
227 : {
228 689 : mpPreRenderDevice->PreparePreRenderDevice();
229 : }
230 695 : }
231 :
232 2233 : void SdrPaintWindow::DestroyPreRenderDevice()
233 : {
234 2233 : if(mpPreRenderDevice)
235 : {
236 18 : delete mpPreRenderDevice;
237 18 : mpPreRenderDevice = 0L;
238 : }
239 2233 : }
240 :
241 695 : void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
242 : {
243 695 : if(mpPreRenderDevice)
244 : {
245 689 : mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
246 : }
247 695 : }
248 :
249 : // #i73602# add flag if buffer shall be used
250 695 : void SdrPaintWindow::DrawOverlay(const Region& rRegion, bool bUseBuffer)
251 : {
252 : // ## force creation of OverlayManager since the first repaint needs to
253 : // save the background to get a controlled start into overlay mechanism
254 695 : impCreateOverlayManager(bUseBuffer);
255 :
256 695 : if(mxOverlayManager.is() && !OutputToPrinter())
257 : {
258 689 : if(mpPreRenderDevice && bUseBuffer)
259 : {
260 689 : mxOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
261 : }
262 : else
263 : {
264 0 : mxOverlayManager->completeRedraw(rRegion);
265 : }
266 : }
267 695 : }
268 :
269 5608 : const Region& SdrPaintWindow::GetRedrawRegion() const
270 : {
271 5608 : return maRedrawRegion;
272 : }
273 :
274 6720 : void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
275 : {
276 6720 : maRedrawRegion = rNew;
277 6720 : }
278 :
279 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|