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: overlayobjectlist.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/overlayobjectlist.hxx>
34 #include <svx/sdr/overlay/overlaymanager.hxx>
35 #include <tools/debug.hxx>
36 #include <vcl/outdev.hxx>
37 #include <basegfx/matrix/b2dhommatrix.hxx>
39 // for SOLARIS compiler include of algorithm part of _STL is necesary to
40 // get access to basic algos like ::std::find
43 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
45 //////////////////////////////////////////////////////////////////////////////
51 OverlayObjectList::~OverlayObjectList()
56 void OverlayObjectList::clear()
58 OverlayObjectVector::iterator
aStart(maVector
.begin());
60 for(; aStart
!= maVector
.end(); aStart
++)
62 ::sdr::overlay::OverlayObject
* pCandidate
= *aStart
;
64 if(pCandidate
->getOverlayManager())
66 pCandidate
->getOverlayManager()->remove(*pCandidate
);
75 void OverlayObjectList::remove(OverlayObject
& rOverlayObject
)
77 const OverlayObjectVector::iterator aFindResult
= ::std::find(maVector
.begin(), maVector
.end(), &rOverlayObject
);
78 const bool bFound(aFindResult
!= maVector
.end());
79 OSL_ENSURE(bFound
, "Could not find given object in list (!)");
83 maVector
.erase(aFindResult
);
87 bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint
& rLogicPosition
, double fLogicTolerance
) const
91 OverlayObjectVector::const_iterator
aStart(maVector
.begin());
92 sdr::overlay::OverlayObject
* pFirst
= *aStart
;
93 OSL_ENSURE(pFirst
, "Corrupt OverlayObjectList (!)");
94 OverlayManager
* pManager
= pFirst
->getOverlayManager();
98 if(0.0 == fLogicTolerance
)
100 const Size
aSizeLogic(pManager
->getOutputDevice().PixelToLogic(
101 Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL
, DEFAULT_VALUE_FOR_HITTEST_PIXEL
)));
102 fLogicTolerance
= aSizeLogic
.Width();
105 const drawinglayer::geometry::ViewInformation2D
aViewInformation2D(pManager
->getCurrentViewInformation2D());
106 drawinglayer::processor2d::HitTestProcessor2D
aHitTestProcessor2D(
112 for(; aStart
!= maVector
.end(); aStart
++)
114 sdr::overlay::OverlayObject
* pCandidate
= *aStart
;
115 OSL_ENSURE(pCandidate
, "Corrupt OverlayObjectList (!)");
117 if(pCandidate
->isHittable())
119 const drawinglayer::primitive2d::Primitive2DSequence
& rSequence
= pCandidate
->getOverlayObjectPrimitive2DSequence();
121 if(rSequence
.hasElements())
123 aHitTestProcessor2D
.process(rSequence
);
125 if(aHitTestProcessor2D
.getHit())
138 bool OverlayObjectList::isHitPixel(const Point
& rDiscretePosition
, sal_uInt32 nDiscreteTolerance
) const
142 OverlayObjectVector::const_iterator
aStart(maVector
.begin());
143 sdr::overlay::OverlayObject
* pCandidate
= *aStart
;
144 OverlayManager
* pManager
= pCandidate
->getOverlayManager();
148 const Point
aPosLogic(pManager
->getOutputDevice().PixelToLogic(rDiscretePosition
));
149 const basegfx::B2DPoint
aPosition(aPosLogic
.X(), aPosLogic
.Y());
151 if(nDiscreteTolerance
)
153 const Size
aSizeLogic(pManager
->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance
, nDiscreteTolerance
)));
154 return isHitLogic(aPosition
, (double)aSizeLogic
.Width());
158 return isHitLogic(aPosition
);
166 basegfx::B2DRange
OverlayObjectList::getBaseRange() const
168 basegfx::B2DRange aRetval
;
172 OverlayObjectVector::const_iterator
aStart(maVector
.begin());
174 for(; aStart
!= maVector
.end(); aStart
++)
176 ::sdr::overlay::OverlayObject
* pCandidate
= *aStart
;
177 aRetval
.expand(pCandidate
->getBaseRange());
183 } // end of namespace overlay
184 } // end of namespace sdr
186 //////////////////////////////////////////////////////////////////////////////