diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-08-26 22:03:54 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-08-27 12:29:57 +0200 |
commit | 09be7ac7dce1e8141f25bc84273968ea273a018c (patch) | |
tree | 736ef1b9d555abb966f19e7c95dcd23dc647956f /svx | |
parent | c7ea7664002b54786795fab7f6233024a6362f71 (diff) |
Move ImageMap related functions to svx
So that in can be used from slideshow module
Change-Id: I105582cf523a454701963a253ba39054f09730e8
Reviewed-on: https://gerrit.libreoffice.org/78156
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svxcore.mk | 1 | ||||
-rw-r--r-- | svx/source/sdr/misc/ImageMapInfo.cxx | 122 |
2 files changed, 123 insertions, 0 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 4aca86ba0fb5..aa5c744d7409 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -235,6 +235,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/sdr/overlay/overlaymanager \ svx/source/sdr/overlay/overlayobjectlist \ svx/source/sdr/overlay/overlayhandle \ + svx/source/sdr/misc/ImageMapInfo \ svx/source/sdr/primitive2d/sdrellipseprimitive2d \ svx/source/sdr/primitive2d/sdrprimitivetools \ svx/source/sdr/primitive2d/sdrtextprimitive2d \ diff --git a/svx/source/sdr/misc/ImageMapInfo.cxx b/svx/source/sdr/misc/ImageMapInfo.cxx new file mode 100644 index 000000000000..ca820a240b82 --- /dev/null +++ b/svx/source/sdr/misc/ImageMapInfo.cxx @@ -0,0 +1,122 @@ +/* -*- 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 <svx/ImageMapInfo.hxx> + +#include <svx/svdobj.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdoole2.hxx> +#include <svx/unoshape.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> +#include <vcl/imapobj.hxx> + +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<SvxIMapInfo*>(pUserData); + } + + return pIMapInfo; +} + +IMapObject* SvxIMapInfo::GetHitIMapObject(SdrObject const* pObj, const Point& rWinPoint) +{ + SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj); + IMapObject* pIMapObj = nullptr; + + if (pIMapInfo) + { + const MapMode aMap100(MapUnit::Map100thMM); + Size aGraphSize; + Point aRelPoint(rWinPoint); + ImageMap& rImageMap = const_cast<ImageMap&>(pIMapInfo->GetImageMap()); + const ::tools::Rectangle& rRect = pObj->GetLogicRect(); + bool bObjSupported = false; + + // execute HitTest + if (auto pGrafObj = dynamic_cast<const SdrGrafObj*>(pObj)) // simple graphics object + { + const GeoStat& rGeo = pGrafObj->GetGeoStat(); + std::unique_ptr<SdrGrafObjGeoData> pGeoData( + static_cast<SdrGrafObjGeoData*>(pGrafObj->GetGeoData())); + + // Undo rotation + if (rGeo.nRotationAngle) + RotatePoint(aRelPoint, rRect.TopLeft(), -rGeo.nSin, rGeo.nCos); + + // Undo mirroring + if (pGeoData->bMirrored) + aRelPoint.setX(rRect.Right() + rRect.Left() - aRelPoint.X()); + + // Undo shearing + if (rGeo.nShearAngle) + ShearPoint(aRelPoint, rRect.TopLeft(), -rGeo.nTan); + + 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<const SdrOle2Obj*>(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; +} + +ImageMap* SvxIMapInfo::GetImageMapForObject(SdrObject* pObj) +{ + SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj); + if (pIMapInfo) + { + return const_cast<ImageMap*>(&(pIMapInfo->GetImageMap())); + } + return nullptr; +}
\ No newline at end of file |