Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / overlay / overlayobjectlist.cxx
blob182acf22e38be12e2f219f2bf4d2d44e76666714
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 <svx/svdmodel.hxx>
23 #include <vcl/outdev.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <tools/gen.hxx>
27 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
28 #include <comphelper/lok.hxx>
30 #define DEFAULT_VALUE_FOR_HITTEST_PIXEL (2)
31 #define DEFAULT_VALUE_FOR_HITTEST_TWIP (30)
33 namespace sdr
35 namespace overlay
37 OverlayObjectList::~OverlayObjectList()
39 clear();
42 void OverlayObjectList::clear()
44 for(auto & pCandidate : maVector)
46 if(pCandidate->getOverlayManager())
47 pCandidate->getOverlayManager()->remove(*pCandidate);
49 maVector.clear();
52 void OverlayObjectList::append(std::unique_ptr<OverlayObject> pOverlayObject)
54 assert(pOverlayObject && "tried to add invalid OverlayObject to OverlayObjectList");
55 maVector.push_back(std::move(pOverlayObject));
58 bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
60 if(!maVector.empty())
62 OverlayObject* pFirst = maVector.front().get();
63 OverlayManager* pManager = pFirst->getOverlayManager();
65 if(pManager)
67 if(0.0 == fLogicTolerance)
69 Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
70 Size(DEFAULT_VALUE_FOR_HITTEST_PIXEL, DEFAULT_VALUE_FOR_HITTEST_PIXEL)));
72 // When tiled rendering, we always work in logic units, use the non-pixel default.
73 if (comphelper::LibreOfficeKit::isActive())
75 aSizeLogic = Size(DEFAULT_VALUE_FOR_HITTEST_TWIP, DEFAULT_VALUE_FOR_HITTEST_TWIP);
76 if (pManager->getOutputDevice().GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
77 aSizeLogic = OutputDevice::LogicToLogic(aSizeLogic, MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
80 fLogicTolerance = aSizeLogic.Width();
83 const drawinglayer::geometry::ViewInformation2D& aViewInformation2D(pManager->getCurrentViewInformation2D());
84 drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
85 aViewInformation2D,
86 rLogicPosition,
87 fLogicTolerance,
88 false);
90 for(auto & pCandidate : maVector)
92 if(pCandidate->isHittable())
94 const drawinglayer::primitive2d::Primitive2DContainer& rSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
96 if(!rSequence.empty())
98 aHitTestProcessor2D.process(rSequence);
100 if(aHitTestProcessor2D.getHit())
102 return true;
110 return false;
113 bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition) const
115 sal_uInt32 nDiscreteTolerance = DEFAULT_VALUE_FOR_HITTEST_PIXEL;
116 if(!maVector.empty())
118 OverlayObject* pCandidate = maVector.front().get();
119 OverlayManager* pManager = pCandidate->getOverlayManager();
121 if(pManager)
123 const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
124 const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
126 const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
127 return isHitLogic(aPosition, static_cast<double>(aSizeLogic.Width()));
131 return false;
134 basegfx::B2DRange OverlayObjectList::getBaseRange() const
136 basegfx::B2DRange aRetval;
138 for(auto & pCandidate : maVector)
140 aRetval.expand(pCandidate->getBaseRange());
143 return aRetval;
145 } // end of namespace overlay
146 } // end of namespace sdr
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */