LibreOffice Module oox (master) 1
hyperlinkcontext.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 "hyperlinkcontext.hxx"
21
22#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
23
28#include <oox/token/namespaces.hxx>
29#include <oox/token/properties.hxx>
30#include <oox/token/tokens.hxx>
31#include <o3tl/string_view.hxx>
32#include <ooxresid.hxx>
33#include <strings.hrc>
34
35using namespace ::oox::core;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::xml::sax;
38
39namespace oox::drawingml {
40
41HyperLinkContext::HyperLinkContext( ContextHandler2Helper const & rParent,
42 const AttributeList& rAttribs, PropertyMap& aProperties )
43 : ContextHandler2( rParent )
45{
46 OUString sURL, sHref;
47 OUString aRelId = rAttribs.getStringDefaulted( R_TOKEN( id ) );
48 if ( !aRelId.isEmpty() )
49 {
50 sHref = getRelations().getExternalTargetFromRelId( aRelId );
51 if( !sHref.isEmpty() )
52 {
53 sURL = getFilter().getAbsoluteUrl( sHref );
54 }
55 else
56 {
57 // not sure if we also need to set sHref to the internal target
59 }
60 }
61 OUString sTooltip = rAttribs.getStringDefaulted( R_TOKEN( tooltip ) );
62 if ( !sTooltip.isEmpty() )
63 maProperties.setProperty(PROP_Representation, sTooltip);
64 OUString sFrame = rAttribs.getStringDefaulted( R_TOKEN( tgtFrame ) );
65 if( !sFrame.isEmpty() )
66 maProperties.setProperty(PROP_TargetFrame, sFrame);
67 OUString aAction = rAttribs.getStringDefaulted( XML_action );
68 if ( !aAction.isEmpty() )
69 {
70 // reserved values of the unrestricted string aAction:
71 // ppaction://customshow?id=SHOW_ID // custom presentation
72 // ppaction://hlinkfile // external file via r:id
73 // ppaction://hlinkpres?slideindex=SLIDE_NUM // external presentation via r:id
74 // ppaction://hlinkshowjump?jump=endshow
75 // ppaction://hlinkshowjump?jump=firstslide
76 // ppaction://hlinkshowjump?jump=lastslide
77 // ppaction://hlinkshowjump?jump=lastslideviewed
78 // ppaction://hlinkshowjump?jump=nextslide
79 // ppaction://hlinkshowjump?jump=previousslide
80 // ppaction://hlinksldjump
81 // ppaction://macro?name=MACRO_NAME
82 // ppaction://program
83
84 static constexpr OUStringLiteral sPPAction( u"ppaction://" );
85 if ( aAction.matchIgnoreAsciiCase( sPPAction ) )
86 {
87 OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
88 sal_Int32 nIndex = aPPAct.indexOf( '?' );
89 OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
90
91 if ( aPPAction.match( "hlinkshowjump" ) )
92 {
93 static constexpr OUStringLiteral sJump( u"jump=" );
94 if ( aPPAct.match( sJump, nIndex + 1 ) )
95 {
96 std::u16string_view aDestination( aPPAct.subView( nIndex + 1 + sJump.getLength() ) );
97 sURL += OUString::Concat("#action?jump=") + aDestination;
98 }
99 }
100 else if ( aPPAction.match( "hlinksldjump" ) )
101 {
102 sHref = sURL;
103
104 sal_Int32 nIndex2 = 0;
105 while ( nIndex2 < sHref.getLength() )
106 {
107 sal_Unicode nChar = sHref[ nIndex2 ];
108 if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
109 break;
110 nIndex2++;
111 }
112 if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
113 {
114 sal_Int32 nLength = 1;
115 while( ( nIndex2 + nLength ) < sHref.getLength() )
116 {
117 sal_Unicode nChar = sHref[ nIndex2 + nLength ];
118 if ( ( nChar < '0' ) || ( nChar > '9' ) )
119 break;
120 nLength++;
121 }
122 sal_Int32 nPageNumber = o3tl::toInt32(sHref.subView( nIndex2, nLength ));
123 if ( nPageNumber )
124 {
125 const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
126 if ( aSlideType.match( "slide" ) )
127 sURL = "#" + URLResId(STR_SLIDE_NAME) + " " + OUString::number( nPageNumber );
128 else if ( aSlideType.match( "notesSlide" ) )
129 sURL = "#Notes " + OUString::number( nPageNumber );
130// else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
131 }
132 }
133 }
134 }
135 }
136 if ( !sURL.isEmpty() )
137 maProperties.setProperty(PROP_URL, sURL);
138
139 // TODO unhandled
140 // XML_invalidUrl
141 // XML_history
142 // XML_highlightClick
143 // XML_endSnd
144}
145
147{
148}
149
151 ::sal_Int32 aElement, const AttributeList& )
152{
153 switch( aElement )
154 {
155 case A_TOKEN( extLst ):
157 break;
158 case A_TOKEN( snd ):
159 // TODO use getEmbeddedWAVAudioFile() here
160 break;
161 }
162
163 return this;
164}
165
166} // namespace oox::drawingml
167
168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
constexpr OUStringLiteral sFrame
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
XmlFilterBase & getFilter() const
Returns the filter instance.
const Relations & getRelations() const
Returns the relations of the current fragment.
OUString getAbsoluteUrl(const OUString &rUrl) const
Returns an absolute URL for the passed relative or absolute URL.
Definition: filterbase.cxx:268
OUString getInternalTargetFromRelId(const OUString &rRelId) const
Returns the internal target of the relation with the passed relation identifier.
Definition: relations.cxx:94
OUString getExternalTargetFromRelId(const OUString &rRelId) const
Returns the external target of the relation with the passed relation identifier.
Definition: relations.cxx:88
HyperLinkContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, PropertyMap &aProperties)
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
float u
sal_Int32 nIndex
SvGenericNameContainerMapImpl maProperties
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
OUString URLResId(TranslateId aId)
Definition: ooxresid.cxx:15
sal_uInt16 sal_Unicode
constexpr OUStringLiteral PROP_CharColor
sal_Int32 nLength