Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLTextFrameHyperlinkContext.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 <sal/log.hxx>
21
#include <sax/tools/converter.hxx>
22
23
#include <xmloff/shapeimport.hxx>
24
#include <xmloff/xmlimp.hxx>
25
#include <xmloff/xmlnamespace.hxx>
26
#include <xmloff/xmltoken.hxx>
27
#include "XMLTextFrameContext.hxx"
28
#include "XMLTextFrameHyperlinkContext.hxx"
29
30
#include <com/sun/star/drawing/XShapes.hpp>
31
32
using namespace ::com::sun::star::drawing;
33
using namespace ::com::sun::star::uno;
34
using namespace ::com::sun::star::text;
35
using namespace ::com::sun::star::xml::sax;
36
using namespace ::com::sun::star::beans;
37
using namespace ::xmloff::token;
38
39
namespace drawing = com::sun::star::drawing;
40
41
42
XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
43
        SvXMLImport& rImport,
44
        sal_Int32 /*nElement*/,
45
        const Reference< XFastAttributeList > & xAttrList,
46
        TextContentAnchorType eATyp ) :
47
78
    SvXMLImportContext( rImport ),
48
78
    eDefaultAnchorType( eATyp ),
49
78
    bMap( false )
50
78
{
51
78
    OUString sShow;
52
53
78
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
54
7
    {
55
7
        switch( aIter.getToken() )
56
7
        {
57
0
        case XML_ELEMENT(XLINK, XML_HREF):
58
0
            sHRef = GetImport().GetAbsoluteReference( aIter.toString() );
59
0
            break;
60
0
        case XML_ELEMENT(OFFICE, XML_NAME):
61
0
            sName = aIter.toString();
62
0
            break;
63
0
        case XML_ELEMENT(OFFICE, XML_TARGET_FRAME_NAME):
64
0
            sTargetFrameName = aIter.toString();
65
0
            break;
66
0
        case XML_ELEMENT(XLINK, XML_SHOW):
67
0
            sShow = aIter.toString();
68
0
            break;
69
0
        case XML_ELEMENT(OFFICE, XML_SERVER_MAP):
70
0
            {
71
0
                bool bTmp(false);
72
0
                if (::sax::Converter::convertBool( bTmp, aIter.toView() ))
73
0
                {
74
0
                    bMap = bTmp;
75
0
                }
76
0
            }
77
0
            break;
78
7
        default:
79
7
            XMLOFF_WARN_UNKNOWN("xmloff", aIter);
80
7
        }
81
7
    }
82
83
78
    if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
84
0
    {
85
0
        if( IsXMLToken( sShow, XML_NEW ) )
86
0
            sTargetFrameName = "_blank";
87
0
        else if( IsXMLToken( sShow, XML_REPLACE ) )
88
0
            sTargetFrameName = "_self";
89
0
    }
90
78
}
91
92
XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
93
78
{
94
78
}
95
96
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameHyperlinkContext::createFastChildContext(
97
    sal_Int32 nElement,
98
    const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList )
99
2
{
100
2
    SvXMLImportContext *pContext = nullptr;
101
2
    XMLTextFrameContext *pTextFrameContext = nullptr;
102
103
2
    switch (nElement)
104
2
    {
105
0
        case XML_ELEMENT(DRAW, XML_FRAME):
106
0
        {
107
0
            pTextFrameContext = new XMLTextFrameContext(GetImport(), xAttrList, eDefaultAnchorType);
108
0
            pTextFrameContext->SetHyperlink(sHRef, sName, sTargetFrameName, bMap);
109
0
            pContext = pTextFrameContext;
110
0
            xFrameContext = pContext;
111
0
        }
112
0
        break;
113
0
        case XML_ELEMENT(DRAW, XML_CUSTOM_SHAPE):
114
0
        case XML_ELEMENT(DRAW, XML_PATH):
115
0
        case XML_ELEMENT(DRAW, XML_ELLIPSE):
116
0
        case XML_ELEMENT(DRAW, XML_LINE):
117
0
        case XML_ELEMENT(DRAW, XML_RECT):
118
0
        case XML_ELEMENT(DRAW, XML_CAPTION):
119
0
        case XML_ELEMENT(DRAW, XML_POLYGON):
120
0
        case XML_ELEMENT(DRAW, XML_POLYLINE):
121
0
        case XML_ELEMENT(DRAW, XML_MEASURE):
122
0
        case XML_ELEMENT(DRAW, XML_CIRCLE):
123
0
        case XML_ELEMENT(DRAW, XML_CONNECTOR):
124
0
        case XML_ELEMENT(DRAW, XML_CONTROL):
125
0
        case XML_ELEMENT(DRAW, XML_PAGE_THUMBNAIL):
126
0
        case XML_ELEMENT(DRAW, XML_G):
127
0
        case XML_ELEMENT(DR3D, XML_SCENE):
128
0
        {
129
0
            Reference<XShapes> xShapes;
130
0
            SvXMLShapeContext* pShapeContext = XMLShapeImportHelper::CreateGroupChildContext(
131
0
                GetImport(), nElement, xAttrList, xShapes);
132
0
            pShapeContext->setHyperlink(sHRef);
133
0
            pContext = pShapeContext;
134
0
        }
135
0
        break;
136
2
    }
137
138
2
    if (!pContext)
139
2
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
140
141
2
    return pContext;
142
2
}
143
144
145
TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
146
0
{
147
0
    if( xFrameContext.is() )
148
0
    {
149
0
        SvXMLImportContext *pContext = xFrameContext.get();
150
0
        return dynamic_cast<XMLTextFrameContext&>(*pContext).GetAnchorType();
151
0
    }
152
0
    else
153
0
        return eDefaultAnchorType;
154
155
0
}
156
157
Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
158
0
{
159
0
    Reference <XTextContent > xTxt;
160
0
    if( xFrameContext.is() )
161
0
    {
162
0
        SvXMLImportContext *pContext = xFrameContext.get();
163
0
        xTxt = dynamic_cast<XMLTextFrameContext&>(*pContext).GetTextContent();
164
0
    }
165
166
0
    return xTxt;
167
0
}
168
169
// Frame "to character": anchor moves from first to last char after saving (#i33242#)
170
Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
171
0
{
172
0
    Reference < drawing::XShape > xShape;
173
0
    if( xFrameContext.is() )
174
0
    {
175
0
        SvXMLImportContext *pContext = xFrameContext.get();
176
0
        xShape = dynamic_cast<XMLTextFrameContext&>(*pContext).GetShape();
177
0
    }
178
179
0
    return xShape;
180
0
}
181
182
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */