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/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
;
39 HyperLinkContext::HyperLinkContext( ContextHandler2Helper
& rParent
,
40 const AttributeList
& rAttribs
, PropertyMap
& aProperties
)
41 : ContextHandler2( rParent
)
42 , maProperties(aProperties
)
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
);
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
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
= sURL
.concat( "#action?jump=" );
98 sURL
= sURL
.concat( aDestination
);
101 else if ( aPPAction
.match( sHlinksldjump
) )
105 sal_Int32 nIndex2
= 0;
106 while ( nIndex2
< sHref
.getLength() )
108 sal_Unicode nChar
= sHref
[ nIndex2
];
109 if ( ( nChar
>= '0' ) && ( nChar
<= '9' ) )
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' ) )
123 sal_Int32 nPageNumber
= sHref
.copy( nIndex2
, nLength
).toInt32();
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
);
145 // XML_highlightClick
149 HyperLinkContext::~HyperLinkContext()
153 ContextHandlerRef
HyperLinkContext::onCreateContext(
154 ::sal_Int32 aElement
, const AttributeList
& )
158 case A_TOKEN( extLst
):
161 // TODO use getEmbeddedWAVAudioFile() here
168 } // namespace drawingml
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */