cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / overlay / overlayobjectlist.cxx
blob6cda0e57d0781db5b88cb0b3450e8aff2a4387f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/overlay/overlayobjectlist.hxx>
21 #include <svx/sdr/overlay/overlaymanager.hxx>
22 #include <vcl/outdev.hxx>
23 #include <tools/gen.hxx>
25 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
26 #include <comphelper/lok.hxx>
28 #define DEFAULT_VALUE_FOR_HITTEST_PIXEL (2)
29 #define DEFAULT_VALUE_FOR_HITTEST_TWIP (30)
31 namespace sdr::overlay
33 OverlayObjectList::~OverlayObjectList()
35 clear();
38 void OverlayObjectList::clear()
40 for(auto & pCandidate : maVector)
42 if(pCandidate->getOverlayManager())
43 pCandidate->getOverlayManager()->remove(*pCandidate);
45 maVector.clear();
48 void OverlayObjectList::append(std::unique_ptr<OverlayObject> pOverlayObject)
50 assert(pOverlayObject && "tried to add invalid OverlayObject to OverlayObjectList");
51 maVector.push_back(std::move(pOverlayObject));
54 bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
56 if(!maVector.empty())
58 OverlayObject* pFirst = maVector.front().get();
59 OverlayManager* pManager = pFirst->getOverlayManager();
61 if(pManager)
63 if(0.0 == fLogicTolerance)
65 Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
66 Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL, DEFAULT_VALUE_FOR_HITTEST_PIXEL)));
68 // When tiled rendering, we always work in logic units, use the non-pixel default.
69 if (comphelper::LibreOfficeKit::isActive())
71 aSizeLogic = Size(DEFAULT_VALUE_FOR_HITTEST_TWIP, DEFAULT_VALUE_FOR_HITTEST_TWIP);
72 if (pManager->getOutputDevice().GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
73 aSizeLogic = o3tl::convert(aSizeLogic, o3tl::Length::twip, o3tl::Length::mm100);
76 fLogicTolerance = aSizeLogic.Width();
79 const drawinglayer::geometry::ViewInformation2D& aViewInformation2D(pManager->getCurrentViewInformation2D());
80 drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
81 aViewInformation2D,
82 rLogicPosition,
83 {fLogicTolerance, fLogicTolerance},
84 false);
86 for(auto & pCandidate : maVector)
88 if(pCandidate->isHittable())
90 const drawinglayer::primitive2d::Primitive2DContainer aSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
92 if(!aSequence.empty())
94 aHitTestProcessor2D.process(aSequence);
96 if(aHitTestProcessor2D.getHit())
98 return true;
106 return false;
109 bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition) const
111 constexpr sal_uInt32 nDiscreteTolerance = DEFAULT_VALUE_FOR_HITTEST_PIXEL;
112 if(!maVector.empty())
114 OverlayObject* pCandidate = maVector.front().get();
115 OverlayManager* pManager = pCandidate->getOverlayManager();
117 if(pManager)
119 const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
120 const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
122 const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
123 return isHitLogic(aPosition, static_cast<double>(aSizeLogic.Width()));
127 return false;
130 basegfx::B2DRange OverlayObjectList::getBaseRange() const
132 basegfx::B2DRange aRetval;
134 for(auto & pCandidate : maVector)
136 aRetval.expand(pCandidate->getBaseRange());
139 return aRetval;
142 } // end of namespace
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */