bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLTextFrameHyperlinkContext.cxx
blob1e76bd351ec4864eec4e9eed9c14320187d24d3a
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 <sax/tools/converter.hxx>
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include "XMLTextFrameContext.hxx"
27 #include "XMLTextFrameHyperlinkContext.hxx"
29 #include <txtparaimphint.hxx>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::text;
33 using namespace ::com::sun::star::xml::sax;
34 using namespace ::com::sun::star::beans;
35 using namespace ::xmloff::token;
37 namespace drawing = com::sun::star::drawing;
39 TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
41 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
42 SvXMLImport& rImport,
43 sal_uInt16 nPrfx, const OUString& rLName,
44 const Reference< XAttributeList > & xAttrList,
45 TextContentAnchorType eATyp ) :
46 SvXMLImportContext( rImport, nPrfx, rLName ),
47 eDefaultAnchorType( eATyp ),
48 bMap( false )
50 OUString sShow;
51 const SvXMLTokenMap& rTokenMap =
52 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
54 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55 for( sal_Int16 i=0; i < nAttrCount; i++ )
57 const OUString& rAttrName = xAttrList->getNameByIndex( i );
58 const OUString& rValue = xAttrList->getValueByIndex( i );
60 OUString aLocalName;
61 sal_uInt16 nPrefix =
62 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
63 &aLocalName );
64 switch( rTokenMap.Get( nPrefix, aLocalName ) )
66 case XML_TOK_TEXT_HYPERLINK_HREF:
67 sHRef = GetImport().GetAbsoluteReference( rValue );
68 break;
69 case XML_TOK_TEXT_HYPERLINK_NAME:
70 sName = rValue;
71 break;
72 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
73 sTargetFrameName = rValue;
74 break;
75 case XML_TOK_TEXT_HYPERLINK_SHOW:
76 sShow = rValue;
77 break;
78 case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
80 bool bTmp(false);
81 if (::sax::Converter::convertBool( bTmp, rValue ))
83 bMap = bTmp;
86 break;
90 if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
92 if( IsXMLToken( sShow, XML_NEW ) )
93 sTargetFrameName = "_blank";
94 else if( IsXMLToken( sShow, XML_REPLACE ) )
95 sTargetFrameName = "_self";
99 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
103 void XMLTextFrameHyperlinkContext::EndElement()
107 SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
108 sal_uInt16 nPrefix,
109 const OUString& rLocalName,
110 const Reference< XAttributeList > & xAttrList )
112 SvXMLImportContext *pContext = 0;
113 XMLTextFrameContext *pTextFrameContext = 0;
115 if( XML_NAMESPACE_DRAW == nPrefix )
117 if( IsXMLToken( rLocalName, XML_FRAME ) )
118 pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
119 rLocalName, xAttrList,
120 eDefaultAnchorType );
123 if( pTextFrameContext )
125 pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
126 pContext = pTextFrameContext;
127 xFrameContext = pContext;
129 else
130 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
132 return pContext;
136 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
138 if( xFrameContext.Is() )
140 SvXMLImportContext *pContext = &xFrameContext;
141 return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
143 else
144 return eDefaultAnchorType;
148 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
150 Reference <XTextContent > xTxt;
151 if( xFrameContext.Is() )
153 SvXMLImportContext *pContext = &xFrameContext;
154 xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
157 return xTxt;
160 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
161 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
163 Reference < drawing::XShape > xShape;
164 if( xFrameContext.Is() )
166 SvXMLImportContext *pContext = &xFrameContext;
167 xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
170 return xShape;
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */