1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/baseprocessor2d.hxx>
29 #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
31 //////////////////////////////////////////////////////////////////////////////
33 using namespace com::sun::star
;
35 //////////////////////////////////////////////////////////////////////////////
41 void OverlayManager::ImpDrawMembers(const basegfx::B2DRange
& rRange
, OutputDevice
& rDestinationDevice
) const
43 const sal_uInt32
nSize(maOverlayObjects
.size());
47 const sal_uInt16
nOriginalAA(rDestinationDevice
.GetAntialiasing());
48 const bool bIsAntiAliasing(getDrawinglayerOpt().IsAntiAliasing());
51 drawinglayer::processor2d::BaseProcessor2D
* pProcessor
=
52 ::drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
54 getCurrentViewInformation2D());
58 for(OverlayObjectVector::const_iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); ++aIter
)
60 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
61 const OverlayObject
& rCandidate
= **aIter
;
63 if(rCandidate
.isVisible())
65 const drawinglayer::primitive2d::Primitive2DSequence
& rSequence
= rCandidate
.getOverlayObjectPrimitive2DSequence();
67 if(rSequence
.hasElements())
69 if(rRange
.overlaps(rCandidate
.getBaseRange()))
71 if(bIsAntiAliasing
&& rCandidate
.allowsAntiAliase())
73 rDestinationDevice
.SetAntialiasing(nOriginalAA
| ANTIALIASING_ENABLE_B2DDRAW
);
77 rDestinationDevice
.SetAntialiasing(nOriginalAA
& ~ANTIALIASING_ENABLE_B2DDRAW
);
80 pProcessor
->process(rSequence
);
89 // restore AA settings
90 rDestinationDevice
.SetAntialiasing(nOriginalAA
);
94 void OverlayManager::ImpStripeDefinitionChanged()
96 const sal_uInt32
nSize(maOverlayObjects
.size());
100 for(OverlayObjectVector::iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); ++aIter
)
102 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
103 OverlayObject
& rCandidate
= **aIter
;
104 rCandidate
.stripeDefinitionHasChanged();
109 double OverlayManager::getDiscreteOne() const
111 if(basegfx::fTools::equalZero(mfDiscreteOne
))
113 const basegfx::B2DVector
aDiscreteInLogic(getOutputDevice().GetInverseViewTransformation() * basegfx::B2DVector(1.0, 0.0));
114 const_cast< OverlayManager
* >(this)->mfDiscreteOne
= aDiscreteInLogic
.getLength();
117 return mfDiscreteOne
;
120 OverlayManager::OverlayManager(OutputDevice
& rOutputDevice
)
123 rmOutputDevice(rOutputDevice
),
125 maStripeColorA(Color(COL_BLACK
)),
126 maStripeColorB(Color(COL_WHITE
)),
127 mnStripeLengthPixel(5),
129 maViewTransformation(),
130 maViewInformation2D(),
133 // set Property 'ReducedDisplayQuality' to true to allow simpler interaction
135 static bool bUseReducedDisplayQualityForDrag(true);
137 if(bUseReducedDisplayQualityForDrag
)
139 uno::Sequence
< beans::PropertyValue
> xProperties(1);
140 xProperties
[0].Name
= OUString("ReducedDisplayQuality");
141 xProperties
[0].Value
<<= true;
142 maViewInformation2D
= drawinglayer::geometry::ViewInformation2D(xProperties
);
146 rtl::Reference
<OverlayManager
> OverlayManager::create(OutputDevice
& rOutputDevice
)
148 return rtl::Reference
<OverlayManager
>(new OverlayManager(rOutputDevice
));
151 const drawinglayer::geometry::ViewInformation2D
OverlayManager::getCurrentViewInformation2D() const
153 if(getOutputDevice().GetViewTransformation() != maViewTransformation
)
155 basegfx::B2DRange
aViewRange(maViewInformation2D
.getViewport());
157 if(OUTDEV_WINDOW
== getOutputDevice().GetOutDevType())
159 const Size
aOutputSizePixel(getOutputDevice().GetOutputSizePixel());
160 aViewRange
= basegfx::B2DRange(0.0, 0.0, aOutputSizePixel
.getWidth(), aOutputSizePixel
.getHeight());
161 aViewRange
.transform(getOutputDevice().GetInverseViewTransformation());
164 OverlayManager
* pThis
= const_cast< OverlayManager
* >(this);
166 pThis
->maViewTransformation
= getOutputDevice().GetViewTransformation();
167 pThis
->maViewInformation2D
= drawinglayer::geometry::ViewInformation2D(
168 maViewInformation2D
.getObjectTransformation(),
169 maViewTransformation
,
171 maViewInformation2D
.getVisualizedPage(),
172 maViewInformation2D
.getViewTime(),
173 maViewInformation2D
.getExtendedInformationSequence());
174 pThis
->mfDiscreteOne
= 0.0;
177 return maViewInformation2D
;
180 void OverlayManager::impApplyRemoveActions(OverlayObject
& rTarget
)
182 // handle evtl. animation
183 if(rTarget
.allowsAnimation())
185 // remove from event chain
186 RemoveEvent(&rTarget
);
190 invalidateRange(rTarget
.getBaseRange());
193 rTarget
.mpOverlayManager
= 0;
196 void OverlayManager::impApplyAddActions(OverlayObject
& rTarget
)
199 rTarget
.mpOverlayManager
= this;
202 invalidateRange(rTarget
.getBaseRange());
204 // handle evtl. animation
205 if(rTarget
.allowsAnimation())
207 // Trigger at current time to get alive. This will do the
208 // object-specific next time calculation and hand over adding
209 // again to the scheduler to the animated object, too. This works for
210 // a paused or non-paused animator.
211 rTarget
.Trigger(GetTime());
215 OverlayManager::~OverlayManager()
217 // The OverlayManager is not the owner of the OverlayObjects
218 // and thus will not delete them, but remove them. Profit here
219 // from knowing that all will be removed
220 const sal_uInt32
nSize(maOverlayObjects
.size());
224 for(OverlayObjectVector::iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); ++aIter
)
226 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
227 OverlayObject
& rCandidate
= **aIter
;
228 impApplyRemoveActions(rCandidate
);
232 maOverlayObjects
.clear();
236 void OverlayManager::completeRedraw(const Region
& rRegion
, OutputDevice
* pPreRenderDevice
) const
238 if(!rRegion
.IsEmpty() && maOverlayObjects
.size())
240 // check for changed MapModes. That may influence the
241 // logical size of pixel based OverlayObjects (like BitmapHandles)
242 //ImpCheckMapModeChange();
245 const Rectangle
aRegionBoundRect(rRegion
.GetBoundRect());
246 const basegfx::B2DRange
aRegionRange(
247 aRegionBoundRect
.Left(), aRegionBoundRect
.Top(),
248 aRegionBoundRect
.Right(), aRegionBoundRect
.Bottom());
250 OutputDevice
& rTarget
= (pPreRenderDevice
) ? *pPreRenderDevice
: getOutputDevice();
251 ImpDrawMembers(aRegionRange
, rTarget
);
255 void OverlayManager::flush()
257 // default has nothing to do
260 // #i68597# part of content gets copied, react on it
261 void OverlayManager::copyArea(const Point
& /*rDestPt*/, const Point
& /*rSrcPt*/, const Size
& /*rSrcSize*/)
263 // unbuffered versions do nothing here
266 void OverlayManager::restoreBackground(const Region
& /*rRegion*/) const
268 // unbuffered versions do nothing here
271 void OverlayManager::add(OverlayObject
& rOverlayObject
)
273 OSL_ENSURE(0 == rOverlayObject
.mpOverlayManager
, "OverlayObject is added twice to an OverlayManager (!)");
275 // add to the end of chain to preserve display order in paint
276 maOverlayObjects
.push_back(&rOverlayObject
);
278 // execute add actions
279 impApplyAddActions(rOverlayObject
);
282 void OverlayManager::remove(OverlayObject
& rOverlayObject
)
284 OSL_ENSURE(rOverlayObject
.mpOverlayManager
== this, "OverlayObject is removed from wrong OverlayManager (!)");
286 // execute remove actions
287 impApplyRemoveActions(rOverlayObject
);
289 // remove from vector
290 const OverlayObjectVector::iterator aFindResult
= ::std::find(maOverlayObjects
.begin(), maOverlayObjects
.end(), &rOverlayObject
);
291 const bool bFound(aFindResult
!= maOverlayObjects
.end());
292 OSL_ENSURE(bFound
, "OverlayObject NOT found at OverlayManager (!)");
296 maOverlayObjects
.erase(aFindResult
);
300 void OverlayManager::invalidateRange(const basegfx::B2DRange
& rRange
)
302 if(OUTDEV_WINDOW
== getOutputDevice().GetOutDevType())
304 if(getDrawinglayerOpt().IsAntiAliasing())
306 // assume AA needs one pixel more and invalidate one pixel more
307 const double fDiscreteOne(getDiscreteOne());
308 const Rectangle
aInvalidateRectangle(
309 (sal_Int32
)floor(rRange
.getMinX() - fDiscreteOne
),
310 (sal_Int32
)floor(rRange
.getMinY() - fDiscreteOne
),
311 (sal_Int32
)ceil(rRange
.getMaxX() + fDiscreteOne
),
312 (sal_Int32
)ceil(rRange
.getMaxY() + fDiscreteOne
));
315 ((Window
&)getOutputDevice()).Invalidate(aInvalidateRectangle
, INVALIDATE_NOERASE
);
319 // #i77674# transform to rectangle. Use floor/ceil to get all covered
320 // discrete pixels, see #i75163# and OverlayManagerBuffered::invalidateRange
321 const Rectangle
aInvalidateRectangle(
322 (sal_Int32
)floor(rRange
.getMinX()), (sal_Int32
)floor(rRange
.getMinY()),
323 (sal_Int32
)ceil(rRange
.getMaxX()), (sal_Int32
)ceil(rRange
.getMaxY()));
326 ((Window
&)getOutputDevice()).Invalidate(aInvalidateRectangle
, INVALIDATE_NOERASE
);
331 // stripe support ColA
332 void OverlayManager::setStripeColorA(Color aNew
)
334 if(aNew
!= maStripeColorA
)
336 maStripeColorA
= aNew
;
337 ImpStripeDefinitionChanged();
341 // stripe support ColB
342 void OverlayManager::setStripeColorB(Color aNew
)
344 if(aNew
!= maStripeColorB
)
346 maStripeColorB
= aNew
;
347 ImpStripeDefinitionChanged();
351 // stripe support StripeLengthPixel
352 void OverlayManager::setStripeLengthPixel(sal_uInt32 nNew
)
354 if(nNew
!= mnStripeLengthPixel
)
356 mnStripeLengthPixel
= nNew
;
357 ImpStripeDefinitionChanged();
361 oslInterlockedCount
OverlayManager::acquire()
363 return osl_atomic_increment( &mnRefCount
);
366 oslInterlockedCount
OverlayManager::release()
368 oslInterlockedCount
nCount( osl_atomic_decrement( &mnRefCount
) );
374 } // end of namespace overlay
375 } // end of namespace sdr
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */