Line data Source code
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 :
24 : #include "oox/helper/propertymap.hxx"
25 : #include "oox/core/relations.hxx"
26 : #include "oox/core/xmlfilterbase.hxx"
27 : #include "oox/drawingml/embeddedwavaudiofile.hxx"
28 :
29 : using namespace ::oox::core;
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::xml::sax;
32 :
33 : namespace oox {
34 : namespace drawingml {
35 :
36 0 : HyperLinkContext::HyperLinkContext( ContextHandler2Helper& rParent,
37 : const AttributeList& rAttribs, PropertyMap& aProperties )
38 : : ContextHandler2( rParent )
39 0 : , maProperties(aProperties)
40 : {
41 0 : OUString sURL, sHref;
42 0 : OUString aRelId = rAttribs.getString( R_TOKEN( id ) ).get();
43 0 : if ( !aRelId.isEmpty() )
44 : {
45 : OSL_TRACE("OOX: URI rId %s", OUStringToOString (aRelId, RTL_TEXTENCODING_UTF8).pData->buffer);
46 0 : sHref = getRelations().getExternalTargetFromRelId( aRelId );
47 0 : if( !sHref.isEmpty() )
48 : {
49 : OSL_TRACE("OOX: URI href %s", OUStringToOString (sHref, RTL_TEXTENCODING_UTF8).pData->buffer);
50 0 : sURL = getFilter().getAbsoluteUrl( sHref );
51 : }
52 : else
53 : {
54 : // not sure if we also need to set sHref to the internal target
55 0 : sURL = getRelations().getInternalTargetFromRelId( aRelId );
56 : }
57 : }
58 0 : OUString sTooltip = rAttribs.getString( R_TOKEN( tooltip ) ).get();
59 0 : if ( !sTooltip.isEmpty() )
60 0 : maProperties.setProperty(PROP_Representation, sTooltip);
61 0 : OUString sFrame = rAttribs.getString( R_TOKEN( tgtFrame ) ).get();
62 0 : if( !sFrame.isEmpty() )
63 0 : maProperties.setProperty(PROP_TargetFrame, sFrame);
64 0 : OUString aAction = rAttribs.getString( XML_action ).get();
65 0 : if ( !aAction.isEmpty() )
66 : {
67 : // reserved values of the unrestricted string aAction:
68 : // ppaction://customshow?id=SHOW_ID // custom presentation
69 : // ppaction://hlinkfile // external file via r:id
70 : // ppaction://hlinkpres?slideindex=SLIDE_NUM // external presentation via r:id
71 : // ppaction://hlinkshowjump?jump=endshow
72 : // ppaction://hlinkshowjump?jump=firstslide
73 : // ppaction://hlinkshowjump?jump=lastslide
74 : // ppaction://hlinkshowjump?jump=lastslideviewed
75 : // ppaction://hlinkshowjump?jump=nextslide
76 : // ppaction://hlinkshowjump?jump=previousslide
77 : // ppaction://hlinksldjump
78 : // ppaction://macro?name=MACRO_NAME
79 : // ppaction://program
80 :
81 0 : const OUString sPPAction( "ppaction://" );
82 0 : if ( aAction.matchIgnoreAsciiCase( sPPAction, 0 ) )
83 : {
84 0 : OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
85 0 : sal_Int32 nIndex = aPPAct.indexOf( '?', 0 );
86 0 : OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
87 :
88 0 : const OUString sHlinkshowjump( "hlinkshowjump" );
89 0 : const OUString sHlinksldjump( "hlinksldjump" );
90 0 : if ( aPPAction.match( sHlinkshowjump ) )
91 : {
92 0 : const OUString sJump( "jump=" );
93 0 : if ( aPPAct.match( sJump, nIndex + 1 ) )
94 : {
95 0 : OUString aDestination( aPPAct.copy( nIndex + 1 + sJump.getLength() ) );
96 0 : sURL = sURL.concat( "#action?jump=" );
97 0 : sURL = sURL.concat( aDestination );
98 0 : }
99 : }
100 0 : else if ( aPPAction.match( sHlinksldjump ) )
101 : {
102 0 : sURL = OUString();
103 :
104 0 : sal_Int32 nIndex2 = 0;
105 0 : while ( nIndex2 < sHref.getLength() )
106 : {
107 0 : sal_Unicode nChar = sHref[ nIndex2 ];
108 0 : if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
109 0 : break;
110 0 : nIndex2++;
111 : }
112 0 : if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
113 : {
114 0 : sal_Int32 nLength = 1;
115 0 : while( ( nIndex2 + nLength ) < sHref.getLength() )
116 : {
117 0 : sal_Unicode nChar = sHref[ nIndex2 + nLength ];
118 0 : if ( ( nChar < '0' ) || ( nChar > '9' ) )
119 : break;
120 0 : nLength++;
121 : }
122 0 : sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
123 0 : if ( nPageNumber )
124 : {
125 0 : const OUString sSlide( "slide" );
126 0 : const OUString sNotesSlide( "notesSlide" );
127 0 : const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
128 0 : if ( aSlideType.match( sSlide ) )
129 0 : sURL = "#Slide " + OUString::number( nPageNumber );
130 0 : else if ( aSlideType.match( sNotesSlide ) )
131 0 : sURL = "#Notes " + OUString::number( nPageNumber );
132 : // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
133 : }
134 : }
135 0 : }
136 0 : }
137 : }
138 0 : if ( !sURL.isEmpty() )
139 0 : maProperties.setProperty(PROP_URL, sURL);
140 :
141 : // TODO unhandled
142 : // XML_invalidUrl
143 : // XML_history
144 : // XML_highlightClick
145 : // XML_endSnd
146 0 : }
147 :
148 0 : HyperLinkContext::~HyperLinkContext()
149 : {
150 0 : }
151 :
152 0 : ContextHandlerRef HyperLinkContext::onCreateContext(
153 : ::sal_Int32 aElement, const AttributeList& rAttribs )
154 : {
155 0 : switch( aElement )
156 : {
157 : case A_TOKEN( extLst ):
158 0 : return 0;
159 : case A_TOKEN( snd ):
160 0 : EmbeddedWAVAudioFile aAudio;
161 0 : getEmbeddedWAVAudioFile( getRelations(), rAttribs.getFastAttributeList(), aAudio );
162 0 : break;
163 : }
164 :
165 0 : return this;
166 : }
167 :
168 : } // namespace drawingml
169 0 : } // namespace oox
170 :
171 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|