Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/misc/ImageMapInfo.cxx
Line
Count
Source
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
29
SvxIMapInfo* SvxIMapInfo::GetIMapInfo(SdrObject const* pObject)
30
0
{
31
0
    assert(pObject);
32
33
0
    SvxIMapInfo* pIMapInfo = nullptr;
34
0
    sal_uInt16 nCount = pObject->GetUserDataCount();
35
36
    // Can we find IMap information within the user data?
37
0
    for (sal_uInt16 i = 0; i < nCount; i++)
38
0
    {
39
0
        SdrObjUserData* pUserData = pObject->GetUserData(i);
40
41
0
        if ((pUserData->GetInventor() == SdrInventor::StarDrawUserData)
42
0
            && (pUserData->GetId() == SVX_IMAPINFO_ID))
43
0
            pIMapInfo = static_cast<SvxIMapInfo*>(pUserData);
44
0
    }
45
46
0
    return pIMapInfo;
47
0
}
48
49
IMapObject* SvxIMapInfo::GetHitIMapObject(const SdrObject* pObj, const Point& rWinPoint,
50
                                          const OutputDevice* pCmpWnd)
51
0
{
52
0
    SvxIMapInfo* pIMapInfo = GetIMapInfo(pObj);
53
0
    IMapObject* pIMapObj = nullptr;
54
55
0
    if (pIMapInfo)
56
0
    {
57
0
        const MapMode aMap100(MapUnit::Map100thMM);
58
0
        Size aGraphSize;
59
0
        Point aRelPoint(rWinPoint);
60
0
        const ImageMap& rImageMap = pIMapInfo->GetImageMap();
61
0
        tools::Rectangle aRect = pObj->GetLogicRect();
62
63
0
        if (pCmpWnd)
64
0
        {
65
0
            const MapMode& aWndMode = pCmpWnd->GetMapMode();
66
0
            aRelPoint = pCmpWnd->LogicToLogic(rWinPoint, &aWndMode, &aMap100);
67
0
            aRect = pCmpWnd->LogicToLogic(pObj->GetLogicRect(), &aWndMode, &aMap100);
68
0
        }
69
70
0
        bool bObjSupported = false;
71
72
        // execute HitTest
73
0
        if (auto pGrafObj = dynamic_cast<const SdrGrafObj*>(pObj)) // simple graphics object
74
0
        {
75
0
            const GeoStat& rGeo = pGrafObj->GetGeoStat();
76
0
            std::unique_ptr<SdrGrafObjGeoData> pGeoData(
77
0
                static_cast<SdrGrafObjGeoData*>(pGrafObj->GetGeoData().release()));
78
79
            // Undo rotation
80
0
            if (rGeo.m_nRotationAngle)
81
0
                RotatePoint(aRelPoint, aRect.TopLeft(), -rGeo.mfSinRotationAngle,
82
0
                            rGeo.mfCosRotationAngle);
83
84
            // Undo mirroring
85
0
            if (pGeoData->bMirrored)
86
0
                aRelPoint.setX(aRect.Right() + aRect.Left() - aRelPoint.X());
87
88
            // Undo shearing
89
0
            if (rGeo.m_nShearAngle)
90
0
                ShearPoint(aRelPoint, aRect.TopLeft(), -rGeo.mfTanShearAngle);
91
92
0
            if (pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
93
0
                aGraphSize = Application::GetDefaultDevice()->PixelToLogic(
94
0
                    pGrafObj->GetGrafPrefSize(), aMap100);
95
0
            else
96
0
                aGraphSize = OutputDevice::LogicToLogic(pGrafObj->GetGrafPrefSize(),
97
0
                                                        pGrafObj->GetGrafPrefMapMode(), aMap100);
98
99
0
            bObjSupported = true;
100
0
        }
101
0
        else if (auto pOleObj = dynamic_cast<const SdrOle2Obj*>(pObj)) // OLE object
102
0
        {
103
0
            aGraphSize = pOleObj->GetOrigObjSize();
104
0
            bObjSupported = true;
105
0
        }
106
107
        // Everything worked out well, thus execute HitTest
108
0
        if (bObjSupported)
109
0
        {
110
            // Calculate relative position of mouse cursor
111
0
            aRelPoint -= aRect.TopLeft();
112
0
            pIMapObj = rImageMap.GetHitIMapObject(aGraphSize, aRect.GetSize(), aRelPoint);
113
114
            // We don't care about deactivated objects
115
0
            if (pIMapObj && !pIMapObj->IsActive())
116
0
                pIMapObj = nullptr;
117
0
        }
118
0
    }
119
120
0
    return pIMapObj;
121
0
}