Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sax/tools/converter.hxx>
21 :
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"
28 :
29 : // OD 2004-04-21 #i26791#
30 : #include <txtparaimphint.hxx>
31 :
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::text;
34 : using namespace ::com::sun::star::xml::sax;
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::xmloff::token;
37 :
38 : namespace drawing = com::sun::star::drawing;
39 :
40 0 : TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
41 :
42 0 : XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
43 : SvXMLImport& rImport,
44 : sal_uInt16 nPrfx, const OUString& rLName,
45 : const Reference< XAttributeList > & xAttrList,
46 : TextContentAnchorType eATyp ) :
47 : SvXMLImportContext( rImport, nPrfx, rLName ),
48 : eDefaultAnchorType( eATyp ),
49 0 : bMap( sal_False )
50 : {
51 0 : OUString sShow;
52 : const SvXMLTokenMap& rTokenMap =
53 0 : GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
54 :
55 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
56 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
57 : {
58 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
59 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
60 :
61 0 : OUString aLocalName;
62 : sal_uInt16 nPrefix =
63 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
64 0 : &aLocalName );
65 0 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
66 : {
67 : case XML_TOK_TEXT_HYPERLINK_HREF:
68 0 : sHRef = GetImport().GetAbsoluteReference( rValue );
69 0 : break;
70 : case XML_TOK_TEXT_HYPERLINK_NAME:
71 0 : sName = rValue;
72 0 : break;
73 : case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
74 0 : sTargetFrameName = rValue;
75 0 : break;
76 : case XML_TOK_TEXT_HYPERLINK_SHOW:
77 0 : sShow = rValue;
78 0 : break;
79 : case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
80 : {
81 0 : bool bTmp(false);
82 0 : if (::sax::Converter::convertBool( bTmp, rValue ))
83 : {
84 0 : bMap = bTmp;
85 : }
86 : }
87 0 : break;
88 : }
89 0 : }
90 :
91 0 : if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
92 : {
93 0 : if( IsXMLToken( sShow, XML_NEW ) )
94 0 : sTargetFrameName = "_blank";
95 0 : else if( IsXMLToken( sShow, XML_REPLACE ) )
96 0 : sTargetFrameName = "_self";
97 0 : }
98 0 : }
99 :
100 0 : XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
101 : {
102 0 : }
103 :
104 0 : void XMLTextFrameHyperlinkContext::EndElement()
105 : {
106 0 : }
107 :
108 0 : SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
109 : sal_uInt16 nPrefix,
110 : const OUString& rLocalName,
111 : const Reference< XAttributeList > & xAttrList )
112 : {
113 0 : SvXMLImportContext *pContext = 0;
114 0 : XMLTextFrameContext *pTextFrameContext = 0;
115 :
116 0 : if( XML_NAMESPACE_DRAW == nPrefix )
117 : {
118 0 : if( IsXMLToken( rLocalName, XML_FRAME ) )
119 0 : pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
120 : rLocalName, xAttrList,
121 0 : eDefaultAnchorType );
122 : }
123 :
124 0 : if( pTextFrameContext )
125 : {
126 0 : pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
127 0 : pContext = pTextFrameContext;
128 0 : xFrameContext = pContext;
129 : }
130 : else
131 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
132 :
133 0 : return pContext;
134 : }
135 :
136 :
137 0 : TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
138 : {
139 0 : if( xFrameContext.Is() )
140 : {
141 0 : SvXMLImportContext *pContext = &xFrameContext;
142 0 : return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
143 : }
144 : else
145 0 : return eDefaultAnchorType;
146 :
147 : }
148 :
149 0 : Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
150 : {
151 0 : Reference <XTextContent > xTxt;
152 0 : if( xFrameContext.Is() )
153 : {
154 0 : SvXMLImportContext *pContext = &xFrameContext;
155 0 : xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
156 : }
157 :
158 0 : return xTxt;
159 : }
160 :
161 : // Frame "to character": anchor moves from first to last char after saving (#i33242#)
162 0 : Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
163 : {
164 0 : Reference < drawing::XShape > xShape;
165 0 : if( xFrameContext.Is() )
166 : {
167 0 : SvXMLImportContext *pContext = &xFrameContext;
168 0 : xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
169 : }
170 :
171 0 : return xShape;
172 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|