Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / hyperlinkcontext.cxx
blob35b29b29f20d2e5103b73a4039382abb0ba894dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "hyperlinkcontext.hxx"
22 #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
24 #include <oox/helper/propertymap.hxx>
25 #include <oox/core/relations.hxx>
26 #include <oox/core/xmlfilterbase.hxx>
27 #include <oox/token/namespaces.hxx>
28 #include <oox/token/properties.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <drawingml/embeddedwavaudiofile.hxx>
32 using namespace ::oox::core;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
36 namespace oox {
37 namespace drawingml {
39 HyperLinkContext::HyperLinkContext( ContextHandler2Helper const & rParent,
40 const AttributeList& rAttribs, PropertyMap& aProperties )
41 : ContextHandler2( rParent )
42 , maProperties(aProperties)
44 OUString sURL, sHref;
45 OUString aRelId = rAttribs.getString( R_TOKEN( id ) ).get();
46 if ( !aRelId.isEmpty() )
48 sHref = getRelations().getExternalTargetFromRelId( aRelId );
49 if( !sHref.isEmpty() )
51 sURL = getFilter().getAbsoluteUrl( sHref );
53 else
55 // not sure if we also need to set sHref to the internal target
56 sURL = getRelations().getInternalTargetFromRelId( aRelId );
59 OUString sTooltip = rAttribs.getString( R_TOKEN( tooltip ) ).get();
60 if ( !sTooltip.isEmpty() )
61 maProperties.setProperty(PROP_Representation, sTooltip);
62 OUString sFrame = rAttribs.getString( R_TOKEN( tgtFrame ) ).get();
63 if( !sFrame.isEmpty() )
64 maProperties.setProperty(PROP_TargetFrame, sFrame);
65 OUString aAction = rAttribs.getString( XML_action ).get();
66 if ( !aAction.isEmpty() )
68 // reserved values of the unrestricted string aAction:
69 // ppaction://customshow?id=SHOW_ID // custom presentation
70 // ppaction://hlinkfile // external file via r:id
71 // ppaction://hlinkpres?slideindex=SLIDE_NUM // external presentation via r:id
72 // ppaction://hlinkshowjump?jump=endshow
73 // ppaction://hlinkshowjump?jump=firstslide
74 // ppaction://hlinkshowjump?jump=lastslide
75 // ppaction://hlinkshowjump?jump=lastslideviewed
76 // ppaction://hlinkshowjump?jump=nextslide
77 // ppaction://hlinkshowjump?jump=previousslide
78 // ppaction://hlinksldjump
79 // ppaction://macro?name=MACRO_NAME
80 // ppaction://program
82 const OUString sPPAction( "ppaction://" );
83 if ( aAction.matchIgnoreAsciiCase( sPPAction ) )
85 OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
86 sal_Int32 nIndex = aPPAct.indexOf( '?' );
87 OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
89 const OUString sHlinkshowjump( "hlinkshowjump" );
90 const OUString sHlinksldjump( "hlinksldjump" );
91 if ( aPPAction.match( sHlinkshowjump ) )
93 const OUString sJump( "jump=" );
94 if ( aPPAct.match( sJump, nIndex + 1 ) )
96 OUString aDestination( aPPAct.copy( nIndex + 1 + sJump.getLength() ) );
97 sURL += "#action?jump=" + aDestination;
100 else if ( aPPAction.match( sHlinksldjump ) )
102 sURL.clear();
104 sal_Int32 nIndex2 = 0;
105 while ( nIndex2 < sHref.getLength() )
107 sal_Unicode nChar = sHref[ nIndex2 ];
108 if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
109 break;
110 nIndex2++;
112 if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
114 sal_Int32 nLength = 1;
115 while( ( nIndex2 + nLength ) < sHref.getLength() )
117 sal_Unicode nChar = sHref[ nIndex2 + nLength ];
118 if ( ( nChar < '0' ) || ( nChar > '9' ) )
119 break;
120 nLength++;
122 sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
123 if ( nPageNumber )
125 const OUString sSlide( "slide" );
126 const OUString sNotesSlide( "notesSlide" );
127 const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
128 if ( aSlideType.match( sSlide ) )
129 sURL = "#Slide " + OUString::number( nPageNumber );
130 else if ( aSlideType.match( sNotesSlide ) )
131 sURL = "#Notes " + OUString::number( nPageNumber );
132 // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
138 if ( !sURL.isEmpty() )
139 maProperties.setProperty(PROP_URL, sURL);
141 // TODO unhandled
142 // XML_invalidUrl
143 // XML_history
144 // XML_highlightClick
145 // XML_endSnd
148 HyperLinkContext::~HyperLinkContext()
152 ContextHandlerRef HyperLinkContext::onCreateContext(
153 ::sal_Int32 aElement, const AttributeList& )
155 switch( aElement )
157 case A_TOKEN( extLst ):
158 return nullptr;
159 case A_TOKEN( snd ):
160 // TODO use getEmbeddedWAVAudioFile() here
161 break;
164 return this;
167 } // namespace drawingml
168 } // namespace oox
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */