Bump for 3.6-28
[LibreOffice.git] / xmloff / source / text / XMLTextFrameHyperlinkContext.cxx
blobafe55e88628b44b477708a77c72396d3e5f40f51
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sax/tools/converter.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include "XMLTextFrameContext.hxx"
37 #include "XMLTextFrameHyperlinkContext.hxx"
39 // OD 2004-04-21 #i26791#
40 #include <txtparaimphint.hxx>
42 using ::rtl::OUString;
43 using ::rtl::OUStringBuffer;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::text;
47 using namespace ::com::sun::star::xml::sax;
48 using namespace ::com::sun::star::beans;
49 using namespace ::xmloff::token;
51 TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
53 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
54 SvXMLImport& rImport,
55 sal_uInt16 nPrfx, const OUString& rLName,
56 const Reference< XAttributeList > & xAttrList,
57 TextContentAnchorType eATyp ) :
58 SvXMLImportContext( rImport, nPrfx, rLName ),
59 eDefaultAnchorType( eATyp ),
60 bMap( sal_False )
62 OUString sShow;
63 const SvXMLTokenMap& rTokenMap =
64 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
66 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
67 for( sal_Int16 i=0; i < nAttrCount; i++ )
69 const OUString& rAttrName = xAttrList->getNameByIndex( i );
70 const OUString& rValue = xAttrList->getValueByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix =
74 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
75 &aLocalName );
76 switch( rTokenMap.Get( nPrefix, aLocalName ) )
78 case XML_TOK_TEXT_HYPERLINK_HREF:
79 sHRef = GetImport().GetAbsoluteReference( rValue );
80 break;
81 case XML_TOK_TEXT_HYPERLINK_NAME:
82 sName = rValue;
83 break;
84 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
85 sTargetFrameName = rValue;
86 break;
87 case XML_TOK_TEXT_HYPERLINK_SHOW:
88 sShow = rValue;
89 break;
90 case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
92 bool bTmp(false);
93 if (::sax::Converter::convertBool( bTmp, rValue ))
95 bMap = bTmp;
98 break;
102 if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
104 if( IsXMLToken( sShow, XML_NEW ) )
105 sTargetFrameName =
106 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) );
107 else if( IsXMLToken( sShow, XML_REPLACE ) )
108 sTargetFrameName =
109 OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) );
113 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
117 void XMLTextFrameHyperlinkContext::EndElement()
121 SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
122 sal_uInt16 nPrefix,
123 const OUString& rLocalName,
124 const Reference< XAttributeList > & xAttrList )
126 SvXMLImportContext *pContext = 0;
127 XMLTextFrameContext *pTextFrameContext = 0;
129 if( XML_NAMESPACE_DRAW == nPrefix )
131 if( IsXMLToken( rLocalName, XML_FRAME ) )
132 pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
133 rLocalName, xAttrList,
134 eDefaultAnchorType );
137 if( pTextFrameContext )
139 pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
140 pContext = pTextFrameContext;
141 xFrameContext = pContext;
143 else
144 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
146 return pContext;
150 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
152 if( xFrameContext.Is() )
154 SvXMLImportContext *pContext = &xFrameContext;
155 return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
157 else
158 return eDefaultAnchorType;
162 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
164 Reference <XTextContent > xTxt;
165 if( xFrameContext.Is() )
167 SvXMLImportContext *pContext = &xFrameContext;
168 xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
171 return xTxt;
174 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
175 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
177 Reference < drawing::XShape > xShape;
178 if( xFrameContext.Is() )
180 SvXMLImportContext *pContext = &xFrameContext;
181 xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
184 return xShape;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */