LibreOffice Module svx (master) 1
ImageMapInfo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svx/ImageMapInfo.hxx>
21
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>
28
30{
31 assert(pObject);
32
33 SvxIMapInfo* pIMapInfo = nullptr;
34 sal_uInt16 nCount = pObject->GetUserDataCount();
35
36 // Can we find IMap information within the user data?
37 for (sal_uInt16 i = 0; i < nCount; i++)
38 {
39 SdrObjUserData* pUserData = pObject->GetUserData(i);
40
41 if ((pUserData->GetInventor() == SdrInventor::StarDrawUserData)
42 && (pUserData->GetId() == SVX_IMAPINFO_ID))
43 pIMapInfo = static_cast<SvxIMapInfo*>(pUserData);
44 }
45
46 return pIMapInfo;
47}
48
50 const OutputDevice* pCmpWnd)
51{
52 SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj);
53 IMapObject* pIMapObj = nullptr;
54
55 if (pIMapInfo)
56 {
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();
62
63 if (pCmpWnd)
64 {
65 MapMode aWndMode = pCmpWnd->GetMapMode();
66 aRelPoint = pCmpWnd->LogicToLogic(rWinPoint, &aWndMode, &aMap100);
67 aRect = pCmpWnd->LogicToLogic(pObj->GetLogicRect(), &aWndMode, &aMap100);
68 }
69
70 bool bObjSupported = false;
71
72 // execute HitTest
73 if (auto pGrafObj = dynamic_cast<const SdrGrafObj*>(pObj)) // simple graphics object
74 {
75 const GeoStat& rGeo = pGrafObj->GetGeoStat();
76 std::unique_ptr<SdrGrafObjGeoData> pGeoData(
77 static_cast<SdrGrafObjGeoData*>(pGrafObj->GetGeoData().release()));
78
79 // Undo rotation
80 if (rGeo.m_nRotationAngle)
81 RotatePoint(aRelPoint, aRect.TopLeft(), -rGeo.mfSinRotationAngle,
83
84 // Undo mirroring
85 if (pGeoData->bMirrored)
86 aRelPoint.setX(aRect.Right() + aRect.Left() - aRelPoint.X());
87
88 // Undo shearing
89 if (rGeo.m_nShearAngle)
90 ShearPoint(aRelPoint, aRect.TopLeft(), -rGeo.mfTanShearAngle);
91
92 if (pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
94 pGrafObj->GetGrafPrefSize(), aMap100);
95 else
96 aGraphSize = OutputDevice::LogicToLogic(pGrafObj->GetGrafPrefSize(),
97 pGrafObj->GetGrafPrefMapMode(), aMap100);
98
99 bObjSupported = true;
100 }
101 else if (auto pOleObj = dynamic_cast<const SdrOle2Obj*>(pObj)) // OLE object
102 {
103 aGraphSize = pOleObj->GetOrigObjSize();
104 bObjSupported = true;
105 }
106
107 // Everything worked out well, thus execute HitTest
108 if (bObjSupported)
109 {
110 // Calculate relative position of mouse cursor
111 aRelPoint -= aRect.TopLeft();
112 pIMapObj = rImageMap.GetHitIMapObject(aGraphSize, aRect.GetSize(), aRelPoint);
113
114 // We don't care about deactivated objects
115 if (pIMapObj && !pIMapObj->IsActive())
116 pIMapObj = nullptr;
117 }
118 }
119
120 return pIMapObj;
121}
#define SVX_IMAPINFO_ID
static OutputDevice * GetDefaultDevice()
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:201
double mfTanShearAngle
Definition: svdtrans.hxx:205
double mfCosRotationAngle
Definition: svdtrans.hxx:207
double mfSinRotationAngle
Definition: svdtrans.hxx:206
Degree100 m_nShearAngle
Definition: svdtrans.hxx:204
Degree100 m_nRotationAngle
Definition: svdtrans.hxx:203
bool IsActive() const
IMapObject * GetHitIMapObject(const Size &rOriginalSize, const Size &rDisplaySize, const Point &rRelHitPoint, sal_uLong nFlags=0) const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const MapMode & GetMapMode() const
void setX(tools::Long nX)
constexpr tools::Long X() const
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:68
User data of a drawing object, e.g.
Definition: svdobj.hxx:152
SdrInventor GetInventor() const
Definition: svdobj.hxx:166
sal_uInt16 GetId() const
Definition: svdobj.hxx:167
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual const tools::Rectangle & GetLogicRect() const
Definition: svdobj.cxx:1672
static SvxIMapInfo * GetIMapInfo(const SdrObject *pObject)
const ImageMap & GetImageMap() const
static IMapObject * GetHitIMapObject(const SdrObject *pObj, const Point &rWinPoint, const OutputDevice *pCmpWnd=nullptr)
constexpr Point TopLeft() const
constexpr Size GetSize() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
int nCount
EmbeddedObjectRef * pObject
int i
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:109
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:101