Update ooo320-m1
[ooovba.git] / svx / source / sdr / overlay / overlayobjectlist.cxx
blob1ca102e36e735c84e31c22bf434d0da236ae5be1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: overlayobjectlist.cxx,v $
10 * $Revision: 1.4 $
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
41 #include <algorithm>
43 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
45 //////////////////////////////////////////////////////////////////////////////
47 namespace sdr
49 namespace overlay
51 OverlayObjectList::~OverlayObjectList()
53 clear();
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);
69 delete pCandidate;
72 maVector.clear();
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 (!)");
81 if(bFound)
83 maVector.erase(aFindResult);
87 bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
89 if(maVector.size())
91 OverlayObjectVector::const_iterator aStart(maVector.begin());
92 sdr::overlay::OverlayObject* pFirst = *aStart;
93 OSL_ENSURE(pFirst, "Corrupt OverlayObjectList (!)");
94 OverlayManager* pManager = pFirst->getOverlayManager();
96 if(pManager)
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(
107 aViewInformation2D,
108 rLogicPosition,
109 fLogicTolerance,
110 false);
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())
127 return true;
135 return false;
138 bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition, sal_uInt32 nDiscreteTolerance) const
140 if(maVector.size())
142 OverlayObjectVector::const_iterator aStart(maVector.begin());
143 sdr::overlay::OverlayObject* pCandidate = *aStart;
144 OverlayManager* pManager = pCandidate->getOverlayManager();
146 if(pManager)
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());
156 else
158 return isHitLogic(aPosition);
163 return false;
166 basegfx::B2DRange OverlayObjectList::getBaseRange() const
168 basegfx::B2DRange aRetval;
170 if(maVector.size())
172 OverlayObjectVector::const_iterator aStart(maVector.begin());
174 for(; aStart != maVector.end(); aStart++)
176 ::sdr::overlay::OverlayObject* pCandidate = *aStart;
177 aRetval.expand(pCandidate->getBaseRange());
181 return aRetval;
183 } // end of namespace overlay
184 } // end of namespace sdr
186 //////////////////////////////////////////////////////////////////////////////
187 // eof