fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / hyperlinkcontext.cxx
blob8dfb90c61e943953b34710fdfa25667b7639ffe0
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 <osl/diagnose.h>
25 #include "oox/helper/propertymap.hxx"
26 #include "oox/core/relations.hxx"
27 #include "oox/core/xmlfilterbase.hxx"
28 #include "drawingml/embeddedwavaudiofile.hxx"
30 using namespace ::oox::core;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
34 namespace oox {
35 namespace drawingml {
37 HyperLinkContext::HyperLinkContext( ContextHandler2Helper& rParent,
38 const AttributeList& rAttribs, PropertyMap& aProperties )
39 : ContextHandler2( rParent )
40 , maProperties(aProperties)
42 OUString sURL, sHref;
43 OUString aRelId = rAttribs.getString( R_TOKEN( id ) ).get();
44 if ( !aRelId.isEmpty() )
46 OSL_TRACE("OOX: URI rId %s", OUStringToOString (aRelId, RTL_TEXTENCODING_UTF8).pData->buffer);
47 sHref = getRelations().getExternalTargetFromRelId( aRelId );
48 if( !sHref.isEmpty() )
50 OSL_TRACE("OOX: URI href %s", OUStringToOString (sHref, RTL_TEXTENCODING_UTF8).pData->buffer);
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, 0 ) )
85 OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
86 sal_Int32 nIndex = aPPAct.indexOf( '?', 0 );
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 = sURL.concat( "#action?jump=" );
98 sURL = sURL.concat( aDestination );
101 else if ( aPPAction.match( sHlinksldjump ) )
103 sURL.clear();
105 sal_Int32 nIndex2 = 0;
106 while ( nIndex2 < sHref.getLength() )
108 sal_Unicode nChar = sHref[ nIndex2 ];
109 if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
110 break;
111 nIndex2++;
113 if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
115 sal_Int32 nLength = 1;
116 while( ( nIndex2 + nLength ) < sHref.getLength() )
118 sal_Unicode nChar = sHref[ nIndex2 + nLength ];
119 if ( ( nChar < '0' ) || ( nChar > '9' ) )
120 break;
121 nLength++;
123 sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
124 if ( nPageNumber )
126 const OUString sSlide( "slide" );
127 const OUString sNotesSlide( "notesSlide" );
128 const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
129 if ( aSlideType.match( sSlide ) )
130 sURL = "#Slide " + OUString::number( nPageNumber );
131 else if ( aSlideType.match( sNotesSlide ) )
132 sURL = "#Notes " + OUString::number( nPageNumber );
133 // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
139 if ( !sURL.isEmpty() )
140 maProperties.setProperty(PROP_URL, sURL);
142 // TODO unhandled
143 // XML_invalidUrl
144 // XML_history
145 // XML_highlightClick
146 // XML_endSnd
149 HyperLinkContext::~HyperLinkContext()
153 ContextHandlerRef HyperLinkContext::onCreateContext(
154 ::sal_Int32 aElement, const AttributeList& )
156 switch( aElement )
158 case A_TOKEN( extLst ):
159 return 0;
160 case A_TOKEN( snd ):
161 // TODO use getEmbeddedWAVAudioFile() here
162 break;
165 return this;
168 } // namespace drawingml
169 } // namespace oox
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */