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 <svx/svdmodel.hxx>
23 : #include <vcl/outdev.hxx>
24 : #include <basegfx/matrix/b2dhommatrix.hxx>
25 : #include <tools/gen.hxx>
26 :
27 : // for SOLARIS compiler include of algorithm part of _STL is necessary to
28 : // get access to basic algos like ::std::find
29 : #include <algorithm>
30 :
31 : #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
32 :
33 :
34 :
35 : namespace sdr
36 : {
37 : namespace overlay
38 : {
39 34286 : OverlayObjectList::~OverlayObjectList()
40 : {
41 17143 : clear();
42 17143 : }
43 :
44 32023 : void OverlayObjectList::clear()
45 : {
46 32023 : OverlayObjectVector::iterator aStart(maVector.begin());
47 :
48 37999 : for(; aStart != maVector.end(); ++aStart)
49 : {
50 5976 : sdr::overlay::OverlayObject* pCandidate = *aStart;
51 :
52 5976 : if(pCandidate->getOverlayManager())
53 : {
54 5383 : pCandidate->getOverlayManager()->remove(*pCandidate);
55 : }
56 :
57 5976 : delete pCandidate;
58 : }
59 :
60 32023 : maVector.clear();
61 32023 : }
62 :
63 63 : bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
64 : {
65 63 : if(!maVector.empty())
66 : {
67 63 : OverlayObjectVector::const_iterator aStart(maVector.begin());
68 63 : sdr::overlay::OverlayObject* pFirst = *aStart;
69 : OSL_ENSURE(pFirst, "Corrupt OverlayObjectList (!)");
70 63 : OverlayManager* pManager = pFirst->getOverlayManager();
71 :
72 63 : if(pManager)
73 : {
74 63 : if(0.0 == fLogicTolerance)
75 : {
76 63 : Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
77 126 : Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL, DEFAULT_VALUE_FOR_HITTEST_PIXEL)));
78 :
79 : // When tiled rendering, we always work in logic units, use the non-pixel default.
80 63 : if (pManager->getModel()->isTiledRendering())
81 : {
82 63 : aSizeLogic = Size(DEFAULT_VALUE_FOR_HITTEST_TWIP, DEFAULT_VALUE_FOR_HITTEST_TWIP);
83 63 : if (pManager->getOutputDevice().GetMapMode().GetMapUnit() == MAP_100TH_MM)
84 24 : aSizeLogic = OutputDevice::LogicToLogic(aSizeLogic, MAP_TWIP, MAP_100TH_MM);
85 : }
86 :
87 63 : fLogicTolerance = aSizeLogic.Width();
88 : }
89 :
90 63 : const drawinglayer::geometry::ViewInformation2D aViewInformation2D(pManager->getCurrentViewInformation2D());
91 : drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
92 : aViewInformation2D,
93 : rLogicPosition,
94 : fLogicTolerance,
95 : false,
96 108 : pManager->getModel()->isTiledRendering());
97 :
98 108 : for(; aStart != maVector.end(); ++aStart)
99 : {
100 63 : sdr::overlay::OverlayObject* pCandidate = *aStart;
101 : OSL_ENSURE(pCandidate, "Corrupt OverlayObjectList (!)");
102 :
103 63 : if(pCandidate->isHittable())
104 : {
105 63 : const drawinglayer::primitive2d::Primitive2DSequence& rSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
106 :
107 63 : if(rSequence.hasElements())
108 : {
109 63 : aHitTestProcessor2D.process(rSequence);
110 :
111 63 : if(aHitTestProcessor2D.getHit())
112 : {
113 18 : return true;
114 : }
115 45 : }
116 : }
117 45 : }
118 : }
119 : }
120 :
121 45 : return false;
122 : }
123 :
124 0 : bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition, sal_uInt32 nDiscreteTolerance) const
125 : {
126 0 : if(!maVector.empty())
127 : {
128 0 : OverlayObjectVector::const_iterator aStart(maVector.begin());
129 0 : sdr::overlay::OverlayObject* pCandidate = *aStart;
130 0 : OverlayManager* pManager = pCandidate->getOverlayManager();
131 :
132 0 : if(pManager)
133 : {
134 0 : const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
135 0 : const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
136 :
137 0 : if(nDiscreteTolerance)
138 : {
139 0 : const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
140 0 : return isHitLogic(aPosition, (double)aSizeLogic.Width());
141 : }
142 : else
143 : {
144 0 : return isHitLogic(aPosition);
145 0 : }
146 : }
147 : }
148 :
149 0 : return false;
150 : }
151 :
152 9 : basegfx::B2DRange OverlayObjectList::getBaseRange() const
153 : {
154 9 : basegfx::B2DRange aRetval;
155 :
156 9 : if(!maVector.empty())
157 : {
158 5 : OverlayObjectVector::const_iterator aStart(maVector.begin());
159 :
160 10 : for(; aStart != maVector.end(); ++aStart)
161 : {
162 5 : sdr::overlay::OverlayObject* pCandidate = *aStart;
163 5 : aRetval.expand(pCandidate->getBaseRange());
164 : }
165 : }
166 :
167 9 : return aRetval;
168 : }
169 : } // end of namespace overlay
170 435 : } // end of namespace sdr
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|