Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/contact/viewcontactofsdrobj.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/sdr/contact/viewcontactofsdrobj.hxx>
21
#include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
22
#include <svx/sdr/contact/viewobjectcontact.hxx>
23
#include <svx/svdobj.hxx>
24
#include <tools/debug.hxx>
25
#include <svx/svdpage.hxx>
26
#include <svx/sdr/contact/objectcontact.hxx>
27
#include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
28
#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
29
#include <svx/svdhdl.hxx>
30
31
namespace sdr::contact {
32
33
// Create an Object-Specific ViewObjectContact, set ViewContact and
34
// ObjectContact. Always needs to return something.
35
ViewObjectContact& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
36
3.12k
{
37
3.12k
    ViewObjectContact* pRetval = new ViewObjectContactOfSdrObj(rObjectContact, *this);
38
3.12k
    DBG_ASSERT(pRetval, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
39
40
3.12k
    return *pRetval;
41
3.12k
}
42
43
ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject& rObj)
44
1.06M
:   mrObject(rObj)
45
1.06M
{
46
1.06M
}
47
48
ViewContactOfSdrObj::~ViewContactOfSdrObj()
49
1.06M
{
50
1.06M
}
51
52
// Access to possible sub-hierarchy
53
sal_uInt32 ViewContactOfSdrObj::GetObjectCount() const
54
791k
{
55
791k
    if(GetSdrObject().GetSubList())
56
12.2k
    {
57
12.2k
        return GetSdrObject().GetSubList()->GetObjCount();
58
12.2k
    }
59
60
779k
    return 0;
61
791k
}
62
63
ViewContact& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex) const
64
26.4k
{
65
26.4k
    assert(GetSdrObject().GetSubList() &&
66
26.4k
        "ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
67
26.4k
    SdrObject* pObj = GetSdrObject().GetSubList()->GetObj(nIndex);
68
26.4k
    assert(pObj && "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
69
26.4k
    return pObj->GetViewContact();
70
26.4k
}
71
72
ViewContact* ViewContactOfSdrObj::GetParentContact() const
73
968k
{
74
968k
    ViewContact* pRetval = nullptr;
75
968k
    SdrObjList* pObjList = GetSdrObject().getParentSdrObjListFromSdrObject();
76
77
968k
    if(pObjList)
78
968k
    {
79
968k
        if(auto pPage = dynamic_cast<SdrPage*>( pObjList))
80
835k
        {
81
            // Is a page
82
835k
            pRetval = &(pPage->GetViewContact());
83
835k
        }
84
132k
        else
85
132k
        {
86
            // Is a group?
87
132k
            if(pObjList->getSdrObjectFromSdrObjList())
88
132k
            {
89
132k
                pRetval = &(pObjList->getSdrObjectFromSdrObjList()->GetViewContact());
90
132k
            }
91
132k
        }
92
968k
    }
93
94
968k
    return pRetval;
95
968k
}
96
97
// React on changes of the object of this ViewContact
98
void ViewContactOfSdrObj::ActionChanged()
99
10.2M
{
100
    // look for own changes
101
10.2M
    if (SdrTextObj* pTextObj = DynCastSdrTextObj(&GetSdrObject()))
102
9.40M
    {
103
        //  tdf#146860 no idea why, but calling this makes the text boxes render properly
104
9.40M
        pTextObj->GetTextAniKind();
105
9.40M
    }
106
107
    // call parent
108
10.2M
    ViewContact::ActionChanged();
109
10.2M
}
110
111
// override for accessing the SdrObject
112
SdrObject* ViewContactOfSdrObj::TryToGetSdrObject() const
113
10.1k
{
114
10.1k
    return &GetSdrObject();
115
10.1k
}
116
117
118
// primitive stuff
119
120
// add Gluepoints (if available)
121
drawinglayer::primitive2d::Primitive2DContainer ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
122
0
{
123
0
    drawinglayer::primitive2d::Primitive2DContainer xRetval;
124
0
    const SdrGluePointList* pGluePointList = GetSdrObject().GetGluePointList();
125
126
0
    if(pGluePointList)
127
0
    {
128
0
        const sal_uInt32 nCount(pGluePointList->GetCount());
129
130
0
        if(nCount)
131
0
        {
132
            // prepare point vector
133
0
            std::vector< basegfx::B2DPoint > aGluepointVector;
134
135
            // create GluePoint primitives. ATM these are relative to the SnapRect
136
0
            for(sal_uInt32 a(0); a < nCount; a++)
137
0
            {
138
0
                const SdrGluePoint& rCandidate = (*pGluePointList)[static_cast<sal_uInt16>(a)];
139
0
                const Point aPosition(rCandidate.GetAbsolutePos(GetSdrObject()));
140
141
0
                aGluepointVector.emplace_back(aPosition.X(), aPosition.Y());
142
0
            }
143
144
0
            if(!aGluepointVector.empty())
145
0
            {
146
0
                const drawinglayer::primitive2d::Primitive2DReference xReference(
147
0
                        new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
148
0
                                std::move(aGluepointVector), SdrHdl::createGluePointBitmap()));
149
0
                xRetval = drawinglayer::primitive2d::Primitive2DContainer{ xReference };
150
0
            }
151
0
        }
152
0
    }
153
154
0
    return xRetval;
155
0
}
156
157
drawinglayer::primitive2d::Primitive2DContainer ViewContactOfSdrObj::embedToObjectSpecificInformation(drawinglayer::primitive2d::Primitive2DContainer aSource) const
158
3.29k
{
159
3.29k
    if(!aSource.empty() &&
160
3.28k
        (!GetSdrObject().GetName().isEmpty() ||
161
1.18k
         !GetSdrObject().GetTitle().isEmpty() ||
162
1.18k
         !GetSdrObject().GetDescription().isEmpty()))
163
2.09k
    {
164
2.09k
        const drawinglayer::primitive2d::Primitive2DReference xRef(
165
2.09k
            new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
166
2.09k
                std::move(aSource),
167
2.09k
                GetSdrObject().GetName(),
168
2.09k
                GetSdrObject().GetTitle(),
169
2.09k
                GetSdrObject().GetDescription()));
170
171
2.09k
        return drawinglayer::primitive2d::Primitive2DContainer { xRef };
172
2.09k
    }
173
174
1.19k
    return aSource;
175
3.29k
}
176
177
}
178
179
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */