cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / misc / ImageMapInfo.cxx
blob44e7f0eda6d2d98fa9eda9e70aa5319fa25f86b8
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/ImageMapInfo.hxx>
22 #include <svx/svdobj.hxx>
23 #include <svx/svdograf.hxx>
24 #include <svx/svdoole2.hxx>
25 #include <vcl/imapobj.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/outdev.hxx>
29 SvxIMapInfo* SvxIMapInfo::GetIMapInfo(SdrObject const* pObject)
31 assert(pObject);
33 SvxIMapInfo* pIMapInfo = nullptr;
34 sal_uInt16 nCount = pObject->GetUserDataCount();
36 // Can we find IMap information within the user data?
37 for (sal_uInt16 i = 0; i < nCount; i++)
39 SdrObjUserData* pUserData = pObject->GetUserData(i);
41 if ((pUserData->GetInventor() == SdrInventor::StarDrawUserData)
42 && (pUserData->GetId() == SVX_IMAPINFO_ID))
43 pIMapInfo = static_cast<SvxIMapInfo*>(pUserData);
46 return pIMapInfo;
49 IMapObject* SvxIMapInfo::GetHitIMapObject(const SdrObject* pObj, const Point& rWinPoint,
50 const OutputDevice* pCmpWnd)
52 SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj);
53 IMapObject* pIMapObj = nullptr;
55 if (pIMapInfo)
57 const MapMode aMap100(MapUnit::Map100thMM);
58 Size aGraphSize;
59 Point aRelPoint(rWinPoint);
60 const ImageMap& rImageMap = pIMapInfo->GetImageMap();
61 tools::Rectangle aRect = pObj->GetLogicRect();
63 if (pCmpWnd)
65 const MapMode& aWndMode = pCmpWnd->GetMapMode();
66 aRelPoint = pCmpWnd->LogicToLogic(rWinPoint, &aWndMode, &aMap100);
67 aRect = pCmpWnd->LogicToLogic(pObj->GetLogicRect(), &aWndMode, &aMap100);
70 bool bObjSupported = false;
72 // execute HitTest
73 if (auto pGrafObj = dynamic_cast<const SdrGrafObj*>(pObj)) // simple graphics object
75 const GeoStat& rGeo = pGrafObj->GetGeoStat();
76 std::unique_ptr<SdrGrafObjGeoData> pGeoData(
77 static_cast<SdrGrafObjGeoData*>(pGrafObj->GetGeoData().release()));
79 // Undo rotation
80 if (rGeo.m_nRotationAngle)
81 RotatePoint(aRelPoint, aRect.TopLeft(), -rGeo.mfSinRotationAngle,
82 rGeo.mfCosRotationAngle);
84 // Undo mirroring
85 if (pGeoData->bMirrored)
86 aRelPoint.setX(aRect.Right() + aRect.Left() - aRelPoint.X());
88 // Undo shearing
89 if (rGeo.m_nShearAngle)
90 ShearPoint(aRelPoint, aRect.TopLeft(), -rGeo.mfTanShearAngle);
92 if (pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
93 aGraphSize = Application::GetDefaultDevice()->PixelToLogic(
94 pGrafObj->GetGrafPrefSize(), aMap100);
95 else
96 aGraphSize = OutputDevice::LogicToLogic(pGrafObj->GetGrafPrefSize(),
97 pGrafObj->GetGrafPrefMapMode(), aMap100);
99 bObjSupported = true;
101 else if (auto pOleObj = dynamic_cast<const SdrOle2Obj*>(pObj)) // OLE object
103 aGraphSize = pOleObj->GetOrigObjSize();
104 bObjSupported = true;
107 // Everything worked out well, thus execute HitTest
108 if (bObjSupported)
110 // Calculate relative position of mouse cursor
111 aRelPoint -= aRect.TopLeft();
112 pIMapObj = rImageMap.GetHitIMapObject(aGraphSize, aRect.GetSize(), aRelPoint);
114 // We don't care about deactivated objects
115 if (pIMapObj && !pIMapObj->IsActive())
116 pIMapObj = nullptr;
120 return pIMapObj;