From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- svx/source/sdr/misc/ImageMapInfo.cxx | 121 +++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 svx/source/sdr/misc/ImageMapInfo.cxx (limited to 'svx/source/sdr/misc') diff --git a/svx/source/sdr/misc/ImageMapInfo.cxx b/svx/source/sdr/misc/ImageMapInfo.cxx new file mode 100644 index 000000000..c50fb2fcc --- /dev/null +++ b/svx/source/sdr/misc/ImageMapInfo.cxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include + +SvxIMapInfo* SvxIMapInfo::GetIMapInfo(SdrObject const* pObject) +{ + assert(pObject); + + SvxIMapInfo* pIMapInfo = nullptr; + sal_uInt16 nCount = pObject->GetUserDataCount(); + + // Can we find IMap information within the user data? + for (sal_uInt16 i = 0; i < nCount; i++) + { + SdrObjUserData* pUserData = pObject->GetUserData(i); + + if ((pUserData->GetInventor() == SdrInventor::StarDrawUserData) + && (pUserData->GetId() == SVX_IMAPINFO_ID)) + pIMapInfo = static_cast(pUserData); + } + + return pIMapInfo; +} + +IMapObject* SvxIMapInfo::GetHitIMapObject(const SdrObject* pObj, const Point& rWinPoint, + const OutputDevice* pCmpWnd) +{ + SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj); + IMapObject* pIMapObj = nullptr; + + if (pIMapInfo) + { + const MapMode aMap100(MapUnit::Map100thMM); + Size aGraphSize; + Point aRelPoint(rWinPoint); + ImageMap& rImageMap = const_cast(pIMapInfo->GetImageMap()); + tools::Rectangle& rRect = const_cast(pObj->GetLogicRect()); + + if (pCmpWnd) + { + MapMode aWndMode = pCmpWnd->GetMapMode(); + aRelPoint = pCmpWnd->LogicToLogic(rWinPoint, &aWndMode, &aMap100); + rRect = pCmpWnd->LogicToLogic(pObj->GetLogicRect(), &aWndMode, &aMap100); + } + + bool bObjSupported = false; + + // execute HitTest + if (auto pGrafObj = dynamic_cast(pObj)) // simple graphics object + { + const GeoStat& rGeo = pGrafObj->GetGeoStat(); + std::unique_ptr pGeoData( + static_cast(pGrafObj->GetGeoData().release())); + + // Undo rotation + if (rGeo.nRotationAngle) + RotatePoint(aRelPoint, rRect.TopLeft(), -rGeo.mfSinRotationAngle, + rGeo.mfCosRotationAngle); + + // Undo mirroring + if (pGeoData->bMirrored) + aRelPoint.setX(rRect.Right() + rRect.Left() - aRelPoint.X()); + + // Undo shearing + if (rGeo.nShearAngle) + ShearPoint(aRelPoint, rRect.TopLeft(), -rGeo.mfTanShearAngle); + + if (pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel) + aGraphSize = Application::GetDefaultDevice()->PixelToLogic( + pGrafObj->GetGrafPrefSize(), aMap100); + else + aGraphSize = OutputDevice::LogicToLogic(pGrafObj->GetGrafPrefSize(), + pGrafObj->GetGrafPrefMapMode(), aMap100); + + bObjSupported = true; + } + else if (auto pOleObj = dynamic_cast(pObj)) // OLE object + { + aGraphSize = pOleObj->GetOrigObjSize(); + bObjSupported = true; + } + + // Everything worked out well, thus execute HitTest + if (bObjSupported) + { + // Calculate relative position of mouse cursor + aRelPoint -= rRect.TopLeft(); + pIMapObj = rImageMap.GetHitIMapObject(aGraphSize, rRect.GetSize(), aRelPoint); + + // We don't care about deactivated objects + if (pIMapObj && !pIMapObj->IsActive()) + pIMapObj = nullptr; + } + } + + return pIMapObj; +} -- cgit v1.2.3