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 <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(
43 sal_uInt16 nPrfx
, const OUString
& rLName
,
44 const Reference
< XAttributeList
> & xAttrList
,
45 TextContentAnchorType eATyp
) :
46 SvXMLImportContext( rImport
, nPrfx
, rLName
),
47 eDefaultAnchorType( eATyp
),
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
);
62 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
64 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
66 case XML_TOK_TEXT_HYPERLINK_HREF
:
67 sHRef
= GetImport().GetAbsoluteReference( rValue
);
69 case XML_TOK_TEXT_HYPERLINK_NAME
:
72 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME
:
73 sTargetFrameName
= rValue
;
75 case XML_TOK_TEXT_HYPERLINK_SHOW
:
78 case XML_TOK_TEXT_HYPERLINK_SERVER_MAP
:
81 if (::sax::Converter::convertBool( bTmp
, rValue
))
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(
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
;
130 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
136 TextContentAnchorType
XMLTextFrameHyperlinkContext::GetAnchorType() const
138 if( xFrameContext
.Is() )
140 SvXMLImportContext
*pContext
= &xFrameContext
;
141 return PTR_CAST( XMLTextFrameContext
, pContext
) ->GetAnchorType();
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();
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();
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */