1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/drawingml/embeddedwavaudiofile.hxx"
29 using namespace ::oox::core
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::xml::sax
;
36 HyperLinkContext::HyperLinkContext( ContextHandler
& rParent
,
37 const Reference
< XFastAttributeList
>& xAttributes
, PropertyMap
& aProperties
)
38 : ContextHandler( rParent
)
39 , maProperties(aProperties
)
42 OUString aRelId
= xAttributes
->getOptionalValue( R_TOKEN( id
) );
43 if ( !aRelId
.isEmpty() )
45 OSL_TRACE("OOX: URI rId %s", OUStringToOString (aRelId
, RTL_TEXTENCODING_UTF8
).pData
->buffer
);
46 sHref
= getRelations().getExternalTargetFromRelId( aRelId
);
47 if( !sHref
.isEmpty() )
49 OSL_TRACE("OOX: URI href %s", OUStringToOString (sHref
, RTL_TEXTENCODING_UTF8
).pData
->buffer
);
50 sURL
= getFilter().getAbsoluteUrl( sHref
);
54 // not sure if we also need to set sHref to the internal target
55 sURL
= getRelations().getInternalTargetFromRelId( aRelId
);
58 OUString sTooltip
= xAttributes
->getOptionalValue( R_TOKEN( tooltip
) );
59 if ( !sTooltip
.isEmpty() )
60 maProperties
[ PROP_Representation
] <<= sTooltip
;
61 OUString sFrame
= xAttributes
->getOptionalValue( R_TOKEN( tgtFrame
) );
62 if( !sFrame
.isEmpty() )
63 maProperties
[ PROP_TargetFrame
] <<= sFrame
;
64 OUString aAction
= xAttributes
->getOptionalValue( XML_action
);
65 if ( !aAction
.isEmpty() )
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
81 const OUString
sPPAction( "ppaction://" );
82 if ( aAction
.matchIgnoreAsciiCase( sPPAction
, 0 ) )
84 OUString
aPPAct( aAction
.copy( sPPAction
.getLength() ) );
85 sal_Int32 nIndex
= aPPAct
.indexOf( '?', 0 );
86 OUString
aPPAction( nIndex
> 0 ? aPPAct
.copy( 0, nIndex
) : aPPAct
);
88 const OUString
sHlinkshowjump( "hlinkshowjump" );
89 const OUString
sHlinksldjump( "hlinksldjump" );
90 if ( aPPAction
.match( sHlinkshowjump
) )
92 const OUString
sJump( "jump=" );
93 if ( aPPAct
.match( sJump
, nIndex
+ 1 ) )
95 OUString
aDestination( aPPAct
.copy( nIndex
+ 1 + sJump
.getLength() ) );
96 sURL
= sURL
.concat( "#action?jump=" );
97 sURL
= sURL
.concat( aDestination
);
100 else if ( aPPAction
.match( sHlinksldjump
) )
104 sal_Int32 nIndex2
= 0;
105 while ( nIndex2
< sHref
.getLength() )
107 sal_Unicode nChar
= sHref
[ nIndex2
];
108 if ( ( nChar
>= '0' ) && ( nChar
<= '9' ) )
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' ) )
122 sal_Int32 nPageNumber
= sHref
.copy( nIndex2
, nLength
).toInt32();
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
= OUString( "#Slide " ).concat( OUString::valueOf( nPageNumber
) );
130 else if ( aSlideType
.match( sNotesSlide
) )
131 sURL
= OUString( "#Notes " ).concat( OUString::valueOf( 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
[ PROP_URL
] <<= sURL
;
144 // XML_highlightClick
148 HyperLinkContext::~HyperLinkContext()
152 Reference
< XFastContextHandler
> HyperLinkContext::createFastChildContext(
153 ::sal_Int32 aElement
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
155 Reference
< XFastContextHandler
> xRet
;
158 case A_TOKEN( extLst
):
161 EmbeddedWAVAudioFile aAudio
;
162 getEmbeddedWAVAudioFile( getRelations(), xAttribs
, aAudio
);
170 } // namespace drawingml
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */