Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svx/sdr/overlay/overlayobjectlist.hxx>
21 : #include <svx/sdr/overlay/overlaymanager.hxx>
22 : #include <vcl/outdev.hxx>
23 : #include <basegfx/matrix/b2dhommatrix.hxx>
24 : #include <tools/gen.hxx>
25 :
26 : // for SOLARIS compiler include of algorithm part of _STL is necessary to
27 : // get access to basic algos like ::std::find
28 : #include <algorithm>
29 :
30 : #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
31 :
32 :
33 :
34 : namespace sdr
35 : {
36 : namespace overlay
37 : {
38 0 : OverlayObjectList::~OverlayObjectList()
39 : {
40 0 : clear();
41 0 : }
42 :
43 0 : void OverlayObjectList::clear()
44 : {
45 0 : OverlayObjectVector::iterator aStart(maVector.begin());
46 :
47 0 : for(; aStart != maVector.end(); ++aStart)
48 : {
49 0 : ::sdr::overlay::OverlayObject* pCandidate = *aStart;
50 :
51 0 : if(pCandidate->getOverlayManager())
52 : {
53 0 : pCandidate->getOverlayManager()->remove(*pCandidate);
54 : }
55 :
56 0 : delete pCandidate;
57 : }
58 :
59 0 : maVector.clear();
60 0 : }
61 :
62 0 : bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
63 : {
64 0 : if(!maVector.empty())
65 : {
66 0 : OverlayObjectVector::const_iterator aStart(maVector.begin());
67 0 : sdr::overlay::OverlayObject* pFirst = *aStart;
68 : OSL_ENSURE(pFirst, "Corrupt OverlayObjectList (!)");
69 0 : OverlayManager* pManager = pFirst->getOverlayManager();
70 :
71 0 : if(pManager)
72 : {
73 0 : if(0.0 == fLogicTolerance)
74 : {
75 0 : const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
76 0 : Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL, DEFAULT_VALUE_FOR_HITTEST_PIXEL)));
77 0 : fLogicTolerance = aSizeLogic.Width();
78 : }
79 :
80 0 : const drawinglayer::geometry::ViewInformation2D aViewInformation2D(pManager->getCurrentViewInformation2D());
81 : drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
82 : aViewInformation2D,
83 : rLogicPosition,
84 : fLogicTolerance,
85 0 : false);
86 :
87 0 : for(; aStart != maVector.end(); ++aStart)
88 : {
89 0 : sdr::overlay::OverlayObject* pCandidate = *aStart;
90 : OSL_ENSURE(pCandidate, "Corrupt OverlayObjectList (!)");
91 :
92 0 : if(pCandidate->isHittable())
93 : {
94 0 : const drawinglayer::primitive2d::Primitive2DSequence& rSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
95 :
96 0 : if(rSequence.hasElements())
97 : {
98 0 : aHitTestProcessor2D.process(rSequence);
99 :
100 0 : if(aHitTestProcessor2D.getHit())
101 : {
102 0 : return true;
103 : }
104 0 : }
105 : }
106 0 : }
107 : }
108 : }
109 :
110 0 : return false;
111 : }
112 :
113 0 : bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition, sal_uInt32 nDiscreteTolerance) const
114 : {
115 0 : if(!maVector.empty())
116 : {
117 0 : OverlayObjectVector::const_iterator aStart(maVector.begin());
118 0 : sdr::overlay::OverlayObject* pCandidate = *aStart;
119 0 : OverlayManager* pManager = pCandidate->getOverlayManager();
120 :
121 0 : if(pManager)
122 : {
123 0 : const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
124 0 : const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
125 :
126 0 : if(nDiscreteTolerance)
127 : {
128 0 : const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
129 0 : return isHitLogic(aPosition, (double)aSizeLogic.Width());
130 : }
131 : else
132 : {
133 0 : return isHitLogic(aPosition);
134 0 : }
135 : }
136 : }
137 :
138 0 : return false;
139 : }
140 :
141 0 : basegfx::B2DRange OverlayObjectList::getBaseRange() const
142 : {
143 0 : basegfx::B2DRange aRetval;
144 :
145 0 : if(!maVector.empty())
146 : {
147 0 : OverlayObjectVector::const_iterator aStart(maVector.begin());
148 :
149 0 : for(; aStart != maVector.end(); ++aStart)
150 : {
151 0 : ::sdr::overlay::OverlayObject* pCandidate = *aStart;
152 0 : aRetval.expand(pCandidate->getBaseRange());
153 : }
154 : }
155 :
156 0 : return aRetval;
157 : }
158 : } // end of namespace overlay
159 : } // end of namespace sdr
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|