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