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: overlaymanager.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 <svx/sdr/overlay/overlaymanager.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
35 #include <basegfx/range/b2drange.hxx>
36 #include <tools/gen.hxx>
37 #include <vcl/salbtype.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/window.hxx>
40 #include <svx/sdr/overlay/overlayobject.hxx>
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
43 #include <svx/sdr/contact/objectcontacttools.hxx>
45 //////////////////////////////////////////////////////////////////////////////
51 void OverlayManager::ImpDrawMembers(const basegfx::B2DRange
& rRange
, OutputDevice
& rDestinationDevice
) const
53 const sal_uInt32
nSize(maOverlayObjects
.size());
57 const sal_uInt16
nOriginalAA(rDestinationDevice
.GetAntialiasing());
58 const bool bIsAntiAliasing(getDrawinglayerOpt().IsAntiAliasing());
61 drawinglayer::processor2d::BaseProcessor2D
* pProcessor
= ::sdr::contact::createBaseProcessor2DFromOutputDevice(
63 getCurrentViewInformation2D());
67 for(OverlayObjectVector::const_iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); aIter
++)
69 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
70 const OverlayObject
& rCandidate
= **aIter
;
72 if(rCandidate
.isVisible())
74 const drawinglayer::primitive2d::Primitive2DSequence
& rSequence
= rCandidate
.getOverlayObjectPrimitive2DSequence();
76 if(rSequence
.hasElements())
78 if(rRange
.overlaps(rCandidate
.getBaseRange()))
80 if(bIsAntiAliasing
&& rCandidate
.allowsAntiAliase())
82 rDestinationDevice
.SetAntialiasing(nOriginalAA
| ANTIALIASING_ENABLE_B2DDRAW
);
86 rDestinationDevice
.SetAntialiasing(nOriginalAA
& ~ANTIALIASING_ENABLE_B2DDRAW
);
89 pProcessor
->process(rSequence
);
98 // restore AA settings
99 rDestinationDevice
.SetAntialiasing(nOriginalAA
);
103 void OverlayManager::ImpStripeDefinitionChanged()
105 const sal_uInt32
nSize(maOverlayObjects
.size());
109 for(OverlayObjectVector::iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); aIter
++)
111 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
112 OverlayObject
& rCandidate
= **aIter
;
113 rCandidate
.stripeDefinitionHasChanged();
118 double OverlayManager::getDiscreteOne() const
120 if(basegfx::fTools::equalZero(mfDiscreteOne
))
122 const basegfx::B2DVector
aDiscreteInLogic(getOutputDevice().GetInverseViewTransformation() * basegfx::B2DVector(1.0, 0.0));
123 const_cast< OverlayManager
* >(this)->mfDiscreteOne
= aDiscreteInLogic
.getLength();
126 return mfDiscreteOne
;
129 OverlayManager::OverlayManager(
130 OutputDevice
& rOutputDevice
,
131 OverlayManager
* pOldOverlayManager
)
133 rmOutputDevice(rOutputDevice
),
135 maStripeColorA(Color(COL_BLACK
)),
136 maStripeColorB(Color(COL_WHITE
)),
137 mnStripeLengthPixel(5),
139 maViewTransformation(),
140 maViewInformation2D(0),
143 if(pOldOverlayManager
)
145 // take over OverlayObjects from given OverlayManager. Copy
146 // the vector of pointers
147 maOverlayObjects
= pOldOverlayManager
->maOverlayObjects
;
148 const sal_uInt32
nSize(maOverlayObjects
.size());
152 for(OverlayObjectVector::iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); aIter
++)
154 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
155 OverlayObject
& rCandidate
= **aIter
;
157 // remove from old and add to new OverlayManager
158 pOldOverlayManager
->impApplyRemoveActions(rCandidate
);
159 impApplyAddActions(rCandidate
);
162 pOldOverlayManager
->maOverlayObjects
.clear();
167 const drawinglayer::geometry::ViewInformation2D
OverlayManager::getCurrentViewInformation2D() const
169 if(getOutputDevice().GetViewTransformation() != maViewTransformation
)
171 basegfx::B2DRange
aViewRange(maViewInformation2D
.getViewport());
173 if(OUTDEV_WINDOW
== getOutputDevice().GetOutDevType())
175 const Size
aOutputSizePixel(getOutputDevice().GetOutputSizePixel());
176 aViewRange
= basegfx::B2DRange(0.0, 0.0, aOutputSizePixel
.getWidth(), aOutputSizePixel
.getHeight());
177 aViewRange
.transform(getOutputDevice().GetInverseViewTransformation());
180 OverlayManager
* pThis
= const_cast< OverlayManager
* >(this);
182 pThis
->maViewTransformation
= getOutputDevice().GetViewTransformation();
183 pThis
->maViewInformation2D
= drawinglayer::geometry::ViewInformation2D(
184 maViewInformation2D
.getObjectTransformation(),
185 maViewTransformation
,
187 maViewInformation2D
.getVisualizedPage(),
188 maViewInformation2D
.getViewTime(),
189 maViewInformation2D
.getExtendedInformationSequence());
190 pThis
->mfDiscreteOne
= 0.0;
193 return maViewInformation2D
;
196 void OverlayManager::impApplyRemoveActions(OverlayObject
& rTarget
)
198 // handle evtl. animation
199 if(rTarget
.allowsAnimation())
201 // remove from event chain
202 RemoveEvent(&rTarget
);
206 invalidateRange(rTarget
.getBaseRange());
209 rTarget
.mpOverlayManager
= 0;
212 void OverlayManager::impApplyAddActions(OverlayObject
& rTarget
)
215 rTarget
.mpOverlayManager
= this;
218 invalidateRange(rTarget
.getBaseRange());
220 // handle evtl. animation
221 if(rTarget
.allowsAnimation())
223 // Trigger at current time to get alive. This will do the
224 // object-specific next time calculation and hand over adding
225 // again to the scheduler to the animated object, too. This works for
226 // a paused or non-paused animator.
227 rTarget
.Trigger(GetTime());
231 OverlayManager::~OverlayManager()
233 // The OverlayManager is not the owner of the OverlayObjects
234 // and thus will not delete them, but remove them. Profit here
235 // from knowing that all will be removed
236 const sal_uInt32
nSize(maOverlayObjects
.size());
240 for(OverlayObjectVector::iterator
aIter(maOverlayObjects
.begin()); aIter
!= maOverlayObjects
.end(); aIter
++)
242 OSL_ENSURE(*aIter
, "Corrupted OverlayObject List (!)");
243 OverlayObject
& rCandidate
= **aIter
;
244 impApplyRemoveActions(rCandidate
);
248 maOverlayObjects
.clear();
252 void OverlayManager::completeRedraw(const Region
& rRegion
, OutputDevice
* pPreRenderDevice
) const
254 if(!rRegion
.IsEmpty() && maOverlayObjects
.size())
256 // check for changed MapModes. That may influence the
257 // logical size of pixel based OverlayObjects (like BitmapHandles)
258 //ImpCheckMapModeChange();
261 const Rectangle
aRegionBoundRect(rRegion
.GetBoundRect());
262 const basegfx::B2DRange
aRegionRange(
263 aRegionBoundRect
.Left(), aRegionBoundRect
.Top(),
264 aRegionBoundRect
.Right(), aRegionBoundRect
.Bottom());
266 OutputDevice
& rTarget
= (pPreRenderDevice
) ? *pPreRenderDevice
: getOutputDevice();
267 ImpDrawMembers(aRegionRange
, rTarget
);
271 void OverlayManager::flush()
273 // default has nothing to do
276 // #i68597# part of content gets copied, react on it
277 void OverlayManager::copyArea(const Point
& /*rDestPt*/, const Point
& /*rSrcPt*/, const Size
& /*rSrcSize*/)
279 // unbuffered versions do nothing here
282 void OverlayManager::restoreBackground(const Region
& /*rRegion*/) const
284 // unbuffered versions do nothing here
287 void OverlayManager::add(OverlayObject
& rOverlayObject
)
289 OSL_ENSURE(0 == rOverlayObject
.mpOverlayManager
, "OverlayObject is added twice to an OverlayManager (!)");
291 // add to the end of chain to preserve display order in paint
292 maOverlayObjects
.push_back(&rOverlayObject
);
294 // execute add actions
295 impApplyAddActions(rOverlayObject
);
298 void OverlayManager::remove(OverlayObject
& rOverlayObject
)
300 OSL_ENSURE(rOverlayObject
.mpOverlayManager
== this, "OverlayObject is removed from wrong OverlayManager (!)");
302 // execute remove actions
303 impApplyRemoveActions(rOverlayObject
);
305 // remove from vector
306 const OverlayObjectVector::iterator aFindResult
= ::std::find(maOverlayObjects
.begin(), maOverlayObjects
.end(), &rOverlayObject
);
307 const bool bFound(aFindResult
!= maOverlayObjects
.end());
308 OSL_ENSURE(bFound
, "OverlayObject NOT found at OverlayManager (!)");
312 maOverlayObjects
.erase(aFindResult
);
316 void OverlayManager::invalidateRange(const basegfx::B2DRange
& rRange
)
318 if(OUTDEV_WINDOW
== getOutputDevice().GetOutDevType())
320 if(getDrawinglayerOpt().IsAntiAliasing())
322 // assume AA needs one pixel more and invalidate one pixel more
323 const double fDiscreteOne(getDiscreteOne());
324 const Rectangle
aInvalidateRectangle(
325 (sal_Int32
)floor(rRange
.getMinX() - fDiscreteOne
),
326 (sal_Int32
)floor(rRange
.getMinY() - fDiscreteOne
),
327 (sal_Int32
)ceil(rRange
.getMaxX() + fDiscreteOne
),
328 (sal_Int32
)ceil(rRange
.getMaxY() + fDiscreteOne
));
331 ((Window
&)getOutputDevice()).Invalidate(aInvalidateRectangle
, INVALIDATE_NOERASE
);
335 // #i77674# transform to rectangle. Use floor/ceil to get all covered
336 // discrete pixels, see #i75163# and OverlayManagerBuffered::invalidateRange
337 const Rectangle
aInvalidateRectangle(
338 (sal_Int32
)floor(rRange
.getMinX()), (sal_Int32
)floor(rRange
.getMinY()),
339 (sal_Int32
)ceil(rRange
.getMaxX()), (sal_Int32
)ceil(rRange
.getMaxY()));
342 ((Window
&)getOutputDevice()).Invalidate(aInvalidateRectangle
, INVALIDATE_NOERASE
);
347 // stripe support ColA
348 void OverlayManager::setStripeColorA(Color aNew
)
350 if(aNew
!= maStripeColorA
)
352 maStripeColorA
= aNew
;
353 ImpStripeDefinitionChanged();
357 // stripe support ColB
358 void OverlayManager::setStripeColorB(Color aNew
)
360 if(aNew
!= maStripeColorB
)
362 maStripeColorB
= aNew
;
363 ImpStripeDefinitionChanged();
367 // stripe support StripeLengthPixel
368 void OverlayManager::setStripeLengthPixel(sal_uInt32 nNew
)
370 if(nNew
!= mnStripeLengthPixel
)
372 mnStripeLengthPixel
= nNew
;
373 ImpStripeDefinitionChanged();
376 } // end of namespace overlay
377 } // end of namespace sdr
379 //////////////////////////////////////////////////////////////////////////////