bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sdr / overlay / overlaymanager.cxx
blobf54195f7241a5c10abc39544ab3908faa5037e43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/overlay/overlaymanager.hxx>
21 #include <basegfx/point/b2dpoint.hxx>
22 #include <basegfx/range/b2drange.hxx>
23 #include <tools/gen.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/window.hxx>
26 #include <svx/sdr/overlay/overlayobject.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <drawinglayer/processor2d/processor2dtools.hxx>
29 #include <boost/scoped_ptr.hpp>
32 using namespace com::sun::star;
36 namespace sdr
38 namespace overlay
40 void OverlayManager::ImpDrawMembers(const basegfx::B2DRange& rRange, OutputDevice& rDestinationDevice) const
42 const sal_uInt32 nSize(maOverlayObjects.size());
44 if(nSize)
46 const AntialiasingFlags nOriginalAA(rDestinationDevice.GetAntialiasing());
47 const bool bIsAntiAliasing(getDrawinglayerOpt().IsAntiAliasing());
49 // create processor
50 boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createProcessor2DFromOutputDevice(
51 rDestinationDevice,
52 getCurrentViewInformation2D()));
54 if(pProcessor)
56 for(OverlayObjectVector::const_iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); ++aIter)
58 OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
59 const OverlayObject& rCandidate = **aIter;
61 if(rCandidate.isVisible())
63 const drawinglayer::primitive2d::Primitive2DSequence& rSequence = rCandidate.getOverlayObjectPrimitive2DSequence();
65 if(rSequence.hasElements())
67 if(rRange.overlaps(rCandidate.getBaseRange()))
69 if(bIsAntiAliasing && rCandidate.allowsAntiAliase())
71 rDestinationDevice.SetAntialiasing(nOriginalAA | AntialiasingFlags::EnableB2dDraw);
73 else
75 rDestinationDevice.SetAntialiasing(nOriginalAA & ~AntialiasingFlags::EnableB2dDraw);
78 pProcessor->process(rSequence);
84 pProcessor.reset();
87 // restore AA settings
88 rDestinationDevice.SetAntialiasing(nOriginalAA);
92 void OverlayManager::ImpStripeDefinitionChanged()
94 const sal_uInt32 nSize(maOverlayObjects.size());
96 if(nSize)
98 for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); ++aIter)
100 OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
101 OverlayObject& rCandidate = **aIter;
102 rCandidate.stripeDefinitionHasChanged();
107 double OverlayManager::getDiscreteOne() const
109 if(basegfx::fTools::equalZero(mfDiscreteOne))
111 const basegfx::B2DVector aDiscreteInLogic(getOutputDevice().GetInverseViewTransformation() * basegfx::B2DVector(1.0, 0.0));
112 const_cast< OverlayManager* >(this)->mfDiscreteOne = aDiscreteInLogic.getLength();
115 return mfDiscreteOne;
118 OverlayManager::OverlayManager(OutputDevice& rOutputDevice, const SdrModel* pModel)
119 : Scheduler(),
120 mrOutputDevice(rOutputDevice),
121 mpModel(pModel),
122 maOverlayObjects(),
123 maStripeColorA(Color(COL_BLACK)),
124 maStripeColorB(Color(COL_WHITE)),
125 mnStripeLengthPixel(5),
126 maDrawinglayerOpt(),
127 maViewTransformation(),
128 maViewInformation2D(),
129 mfDiscreteOne(0.0)
131 // set Property 'ReducedDisplayQuality' to true to allow simpler interaction
132 // visualisations
133 static bool bUseReducedDisplayQualityForDrag(true);
135 if(bUseReducedDisplayQualityForDrag)
137 uno::Sequence< beans::PropertyValue > xProperties(1);
138 xProperties[0].Name = "ReducedDisplayQuality";
139 xProperties[0].Value <<= true;
140 maViewInformation2D = drawinglayer::geometry::ViewInformation2D(xProperties);
144 rtl::Reference<OverlayManager> OverlayManager::create(OutputDevice& rOutputDevice, const SdrModel* pModel)
146 return rtl::Reference<OverlayManager>(new OverlayManager(rOutputDevice, pModel));
149 const drawinglayer::geometry::ViewInformation2D OverlayManager::getCurrentViewInformation2D() const
151 if(getOutputDevice().GetViewTransformation() != maViewTransformation)
153 basegfx::B2DRange aViewRange(maViewInformation2D.getViewport());
155 if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType())
157 const Size aOutputSizePixel(getOutputDevice().GetOutputSizePixel());
159 // only set when we *have* a output size, else let aViewRange
160 // stay on empty
161 if(aOutputSizePixel.Width() && aOutputSizePixel.Height())
163 aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
164 aViewRange.transform(getOutputDevice().GetInverseViewTransformation());
168 OverlayManager* pThis = const_cast< OverlayManager* >(this);
170 pThis->maViewTransformation = getOutputDevice().GetViewTransformation();
171 pThis->maViewInformation2D = drawinglayer::geometry::ViewInformation2D(
172 maViewInformation2D.getObjectTransformation(),
173 maViewTransformation,
174 aViewRange,
175 maViewInformation2D.getVisualizedPage(),
176 maViewInformation2D.getViewTime(),
177 maViewInformation2D.getExtendedInformationSequence());
178 pThis->mfDiscreteOne = 0.0;
181 return maViewInformation2D;
184 void OverlayManager::impApplyRemoveActions(OverlayObject& rTarget)
186 // handle evtl. animation
187 if(rTarget.allowsAnimation())
189 // remove from event chain
190 RemoveEvent(&rTarget);
193 // make invisible
194 invalidateRange(rTarget.getBaseRange());
196 // clear manager
197 rTarget.mpOverlayManager = 0;
200 void OverlayManager::impApplyAddActions(OverlayObject& rTarget)
202 // set manager
203 rTarget.mpOverlayManager = this;
205 // make visible
206 invalidateRange(rTarget.getBaseRange());
208 // handle evtl. animation
209 if(rTarget.allowsAnimation())
211 // Trigger at current time to get alive. This will do the
212 // object-specific next time calculation and hand over adding
213 // again to the scheduler to the animated object, too. This works for
214 // a paused or non-paused animator.
215 rTarget.Trigger(GetTime());
219 OverlayManager::~OverlayManager()
221 // The OverlayManager is not the owner of the OverlayObjects
222 // and thus will not delete them, but remove them. Profit here
223 // from knowing that all will be removed
224 const sal_uInt32 nSize(maOverlayObjects.size());
226 if(nSize)
228 for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); ++aIter)
230 OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
231 OverlayObject& rCandidate = **aIter;
232 impApplyRemoveActions(rCandidate);
235 // erase vector
236 maOverlayObjects.clear();
240 void OverlayManager::completeRedraw(const vcl::Region& rRegion, OutputDevice* pPreRenderDevice) const
242 if(!rRegion.IsEmpty() && maOverlayObjects.size())
244 // check for changed MapModes. That may influence the
245 // logical size of pixel based OverlayObjects (like BitmapHandles)
246 //ImpCheckMapModeChange();
248 // paint members
249 const Rectangle aRegionBoundRect(rRegion.GetBoundRect());
250 const basegfx::B2DRange aRegionRange(
251 aRegionBoundRect.Left(), aRegionBoundRect.Top(),
252 aRegionBoundRect.Right(), aRegionBoundRect.Bottom());
254 OutputDevice& rTarget = (pPreRenderDevice) ? *pPreRenderDevice : getOutputDevice();
255 ImpDrawMembers(aRegionRange, rTarget);
259 void OverlayManager::flush()
261 // default has nothing to do
264 // #i68597# part of content gets copied, react on it
265 void OverlayManager::copyArea(const Point& /*rDestPt*/, const Point& /*rSrcPt*/, const Size& /*rSrcSize*/)
267 // unbuffered versions do nothing here
270 void OverlayManager::restoreBackground(const vcl::Region& /*rRegion*/) const
272 // unbuffered versions do nothing here
275 void OverlayManager::add(OverlayObject& rOverlayObject)
277 OSL_ENSURE(0 == rOverlayObject.mpOverlayManager, "OverlayObject is added twice to an OverlayManager (!)");
279 // add to the end of chain to preserve display order in paint
280 maOverlayObjects.push_back(&rOverlayObject);
282 // execute add actions
283 impApplyAddActions(rOverlayObject);
286 void OverlayManager::remove(OverlayObject& rOverlayObject)
288 OSL_ENSURE(rOverlayObject.mpOverlayManager == this, "OverlayObject is removed from wrong OverlayManager (!)");
290 // execute remove actions
291 impApplyRemoveActions(rOverlayObject);
293 // remove from vector
294 const OverlayObjectVector::iterator aFindResult = ::std::find(maOverlayObjects.begin(), maOverlayObjects.end(), &rOverlayObject);
295 const bool bFound(aFindResult != maOverlayObjects.end());
296 OSL_ENSURE(bFound, "OverlayObject NOT found at OverlayManager (!)");
298 if(bFound)
300 maOverlayObjects.erase(aFindResult);
304 void OverlayManager::invalidateRange(const basegfx::B2DRange& rRange)
306 if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType())
308 if(getDrawinglayerOpt().IsAntiAliasing())
310 // assume AA needs one pixel more and invalidate one pixel more
311 const double fDiscreteOne(getDiscreteOne());
312 const Rectangle aInvalidateRectangle(
313 (sal_Int32)floor(rRange.getMinX() - fDiscreteOne),
314 (sal_Int32)floor(rRange.getMinY() - fDiscreteOne),
315 (sal_Int32)ceil(rRange.getMaxX() + fDiscreteOne),
316 (sal_Int32)ceil(rRange.getMaxY() + fDiscreteOne));
318 // simply invalidate
319 static_cast<vcl::Window&>(getOutputDevice()).Invalidate(aInvalidateRectangle, INVALIDATE_NOERASE);
321 else
323 // #i77674# transform to rectangle. Use floor/ceil to get all covered
324 // discrete pixels, see #i75163# and OverlayManagerBuffered::invalidateRange
325 const Rectangle aInvalidateRectangle(
326 (sal_Int32)floor(rRange.getMinX()), (sal_Int32)floor(rRange.getMinY()),
327 (sal_Int32)ceil(rRange.getMaxX()), (sal_Int32)ceil(rRange.getMaxY()));
329 // simply invalidate
330 static_cast<vcl::Window&>(getOutputDevice()).Invalidate(aInvalidateRectangle, INVALIDATE_NOERASE);
335 // stripe support ColA
336 void OverlayManager::setStripeColorA(Color aNew)
338 if(aNew != maStripeColorA)
340 maStripeColorA = aNew;
341 ImpStripeDefinitionChanged();
345 // stripe support ColB
346 void OverlayManager::setStripeColorB(Color aNew)
348 if(aNew != maStripeColorB)
350 maStripeColorB = aNew;
351 ImpStripeDefinitionChanged();
355 // stripe support StripeLengthPixel
356 void OverlayManager::setStripeLengthPixel(sal_uInt32 nNew)
358 if(nNew != mnStripeLengthPixel)
360 mnStripeLengthPixel = nNew;
361 ImpStripeDefinitionChanged();
365 } // end of namespace overlay
366 } // end of namespace sdr
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */