xref: /trunk/main/svx/source/sdr/overlay/overlayobjectlist.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/overlay/overlayobjectlist.hxx>
27cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanager.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <vcl/outdev.hxx>
30cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
31cdf0e10cSrcweir 
32*86e1cf34SPedro Giffuni // for SOLARIS compiler include of algorithm part of _STL is necessary to
33cdf0e10cSrcweir // get access to basic algos like ::std::find
34cdf0e10cSrcweir #include <algorithm>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace sdr
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     namespace overlay
43cdf0e10cSrcweir     {
~OverlayObjectList()44cdf0e10cSrcweir         OverlayObjectList::~OverlayObjectList()
45cdf0e10cSrcweir         {
46cdf0e10cSrcweir             clear();
47cdf0e10cSrcweir         }
48cdf0e10cSrcweir 
clear()49cdf0e10cSrcweir         void OverlayObjectList::clear()
50cdf0e10cSrcweir         {
51cdf0e10cSrcweir             OverlayObjectVector::iterator aStart(maVector.begin());
52cdf0e10cSrcweir 
53cdf0e10cSrcweir             for(; aStart != maVector.end(); aStart++)
54cdf0e10cSrcweir             {
55cdf0e10cSrcweir                 ::sdr::overlay::OverlayObject* pCandidate = *aStart;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir                 if(pCandidate->getOverlayManager())
58cdf0e10cSrcweir                 {
59cdf0e10cSrcweir                     pCandidate->getOverlayManager()->remove(*pCandidate);
60cdf0e10cSrcweir                 }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir                 delete pCandidate;
63cdf0e10cSrcweir             }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir             maVector.clear();
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir 
remove(OverlayObject & rOverlayObject)68cdf0e10cSrcweir         void OverlayObjectList::remove(OverlayObject& rOverlayObject)
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             const OverlayObjectVector::iterator aFindResult = ::std::find(maVector.begin(), maVector.end(), &rOverlayObject);
71cdf0e10cSrcweir             const bool bFound(aFindResult != maVector.end());
72cdf0e10cSrcweir             OSL_ENSURE(bFound, "Could not find given object in list (!)");
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             if(bFound)
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 maVector.erase(aFindResult);
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir 
isHitLogic(const basegfx::B2DPoint & rLogicPosition,double fLogicTolerance) const80cdf0e10cSrcweir         bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             if(!maVector.empty())
83cdf0e10cSrcweir             {
84cdf0e10cSrcweir                 OverlayObjectVector::const_iterator aStart(maVector.begin());
85cdf0e10cSrcweir                 sdr::overlay::OverlayObject* pFirst = *aStart;
86cdf0e10cSrcweir                 OSL_ENSURE(pFirst, "Corrupt OverlayObjectList (!)");
87cdf0e10cSrcweir                 OverlayManager* pManager = pFirst->getOverlayManager();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir                 if(pManager)
90cdf0e10cSrcweir                 {
91cdf0e10cSrcweir                     if(0.0 == fLogicTolerance)
92cdf0e10cSrcweir                     {
93cdf0e10cSrcweir                         const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
94cdf0e10cSrcweir                             Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL, DEFAULT_VALUE_FOR_HITTEST_PIXEL)));
95cdf0e10cSrcweir                         fLogicTolerance = aSizeLogic.Width();
96cdf0e10cSrcweir                     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir                     const drawinglayer::geometry::ViewInformation2D aViewInformation2D(pManager->getCurrentViewInformation2D());
99cdf0e10cSrcweir                     drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
100cdf0e10cSrcweir                         aViewInformation2D,
101cdf0e10cSrcweir                         rLogicPosition,
102cdf0e10cSrcweir                         fLogicTolerance,
103cdf0e10cSrcweir                         false);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir                     for(; aStart != maVector.end(); aStart++)
106cdf0e10cSrcweir                     {
107cdf0e10cSrcweir                         sdr::overlay::OverlayObject* pCandidate = *aStart;
108cdf0e10cSrcweir                         OSL_ENSURE(pCandidate, "Corrupt OverlayObjectList (!)");
109cdf0e10cSrcweir 
110cdf0e10cSrcweir                         if(pCandidate->isHittable())
111cdf0e10cSrcweir                         {
112cdf0e10cSrcweir                             const drawinglayer::primitive2d::Primitive2DSequence& rSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                             if(rSequence.hasElements())
115cdf0e10cSrcweir                             {
116cdf0e10cSrcweir                                 aHitTestProcessor2D.process(rSequence);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                                 if(aHitTestProcessor2D.getHit())
119cdf0e10cSrcweir                                 {
120cdf0e10cSrcweir                                     return true;
121cdf0e10cSrcweir                                 }
122cdf0e10cSrcweir                             }
123cdf0e10cSrcweir                         }
124cdf0e10cSrcweir                     }
125cdf0e10cSrcweir                 }
126cdf0e10cSrcweir             }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             return false;
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 
isHitPixel(const Point & rDiscretePosition,sal_uInt32 nDiscreteTolerance) const131cdf0e10cSrcweir         bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition, sal_uInt32 nDiscreteTolerance) const
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             if(!maVector.empty())
134cdf0e10cSrcweir             {
135cdf0e10cSrcweir                 OverlayObjectVector::const_iterator aStart(maVector.begin());
136cdf0e10cSrcweir                 sdr::overlay::OverlayObject* pCandidate = *aStart;
137cdf0e10cSrcweir                 OverlayManager* pManager = pCandidate->getOverlayManager();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir                 if(pManager)
140cdf0e10cSrcweir                 {
141cdf0e10cSrcweir                     const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
142cdf0e10cSrcweir                     const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
143cdf0e10cSrcweir 
144cdf0e10cSrcweir                     if(nDiscreteTolerance)
145cdf0e10cSrcweir                     {
146cdf0e10cSrcweir                         const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
147cdf0e10cSrcweir                         return isHitLogic(aPosition, (double)aSizeLogic.Width());
148cdf0e10cSrcweir                     }
149cdf0e10cSrcweir                     else
150cdf0e10cSrcweir                     {
151cdf0e10cSrcweir                         return isHitLogic(aPosition);
152cdf0e10cSrcweir                     }
153cdf0e10cSrcweir                 }
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             return false;
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir 
getBaseRange() const159cdf0e10cSrcweir         basegfx::B2DRange OverlayObjectList::getBaseRange() const
160cdf0e10cSrcweir         {
161cdf0e10cSrcweir             basegfx::B2DRange aRetval;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             if(!maVector.empty())
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 OverlayObjectVector::const_iterator aStart(maVector.begin());
166cdf0e10cSrcweir 
167cdf0e10cSrcweir                 for(; aStart != maVector.end(); aStart++)
168cdf0e10cSrcweir                 {
169cdf0e10cSrcweir                     ::sdr::overlay::OverlayObject* pCandidate = *aStart;
170cdf0e10cSrcweir                     aRetval.expand(pCandidate->getBaseRange());
171cdf0e10cSrcweir                 }
172cdf0e10cSrcweir             }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir             return aRetval;
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir     } // end of namespace overlay
177cdf0e10cSrcweir } // end of namespace sdr
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
180cdf0e10cSrcweir // eof
181