xref: /trunk/main/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
27cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
28cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
29cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir #include "XMLTextFrameContext.hxx"
32cdf0e10cSrcweir #include "XMLTextFrameHyperlinkContext.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // OD 2004-04-21 #i26791#
35cdf0e10cSrcweir #include <txtparaimphint.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using ::rtl::OUString;
38cdf0e10cSrcweir using ::rtl::OUStringBuffer;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir using namespace ::com::sun::star::text;
42cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
43cdf0e10cSrcweir using namespace ::com::sun::star::beans;
44cdf0e10cSrcweir using namespace ::xmloff::token;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
47cdf0e10cSrcweir 
XMLTextFrameHyperlinkContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,TextContentAnchorType eATyp)48cdf0e10cSrcweir XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
49cdf0e10cSrcweir         SvXMLImport& rImport,
50cdf0e10cSrcweir         sal_uInt16 nPrfx, const OUString& rLName,
51cdf0e10cSrcweir         const Reference< XAttributeList > & xAttrList,
52cdf0e10cSrcweir         TextContentAnchorType eATyp ) :
53cdf0e10cSrcweir     SvXMLImportContext( rImport, nPrfx, rLName ),
54cdf0e10cSrcweir     eDefaultAnchorType( eATyp ),
55cdf0e10cSrcweir     bMap( sal_False )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     OUString sShow;
58cdf0e10cSrcweir     const SvXMLTokenMap& rTokenMap =
59cdf0e10cSrcweir         GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
65cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         OUString aLocalName;
68cdf0e10cSrcweir         sal_uInt16 nPrefix =
69cdf0e10cSrcweir             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
70cdf0e10cSrcweir                                                             &aLocalName );
71cdf0e10cSrcweir         switch( rTokenMap.Get( nPrefix, aLocalName ) )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir         case XML_TOK_TEXT_HYPERLINK_HREF:
74cdf0e10cSrcweir             sHRef = GetImport().GetAbsoluteReference( rValue );
75cdf0e10cSrcweir             break;
76cdf0e10cSrcweir         case XML_TOK_TEXT_HYPERLINK_NAME:
77cdf0e10cSrcweir             sName = rValue;
78cdf0e10cSrcweir             break;
79cdf0e10cSrcweir         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
80cdf0e10cSrcweir             sTargetFrameName = rValue;
81cdf0e10cSrcweir             break;
82cdf0e10cSrcweir         case XML_TOK_TEXT_HYPERLINK_SHOW:
83cdf0e10cSrcweir             sShow = rValue;
84cdf0e10cSrcweir             break;
85cdf0e10cSrcweir         case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 sal_Bool bTmp;
88cdf0e10cSrcweir                 if( rImport.GetMM100UnitConverter().convertBool( bTmp,
89cdf0e10cSrcweir                                                                   rValue ) )
90cdf0e10cSrcweir                 {
91cdf0e10cSrcweir                     bMap = bTmp;
92cdf0e10cSrcweir                 }
93cdf0e10cSrcweir             }
94cdf0e10cSrcweir             break;
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     if( sShow.getLength() && !sTargetFrameName.getLength() )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         if( IsXMLToken( sShow, XML_NEW ) )
101cdf0e10cSrcweir             sTargetFrameName =
102cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) );
103cdf0e10cSrcweir         else if( IsXMLToken( sShow, XML_REPLACE ) )
104cdf0e10cSrcweir             sTargetFrameName =
105cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) );
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
~XMLTextFrameHyperlinkContext()109cdf0e10cSrcweir XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
EndElement()113cdf0e10cSrcweir void XMLTextFrameHyperlinkContext::EndElement()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)117cdf0e10cSrcweir SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
118cdf0e10cSrcweir         sal_uInt16 nPrefix,
119cdf0e10cSrcweir         const OUString& rLocalName,
120cdf0e10cSrcweir         const Reference< XAttributeList > & xAttrList )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
123cdf0e10cSrcweir     XMLTextFrameContext *pTextFrameContext = 0;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     if( XML_NAMESPACE_DRAW == nPrefix )
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         if( IsXMLToken( rLocalName, XML_FRAME ) )
128cdf0e10cSrcweir             pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
129cdf0e10cSrcweir                                                 rLocalName, xAttrList,
130cdf0e10cSrcweir                                                 eDefaultAnchorType );
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     if( pTextFrameContext )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
136cdf0e10cSrcweir         pContext = pTextFrameContext;
137cdf0e10cSrcweir         xFrameContext = pContext;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir     else
140cdf0e10cSrcweir         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     return pContext;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
GetAnchorType() const146cdf0e10cSrcweir TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     if( xFrameContext.Is() )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         SvXMLImportContext *pContext = &xFrameContext;
151cdf0e10cSrcweir         return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     else
154cdf0e10cSrcweir         return eDefaultAnchorType;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
GetTextContent() const158cdf0e10cSrcweir Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     Reference <XTextContent > xTxt;
161cdf0e10cSrcweir     if( xFrameContext.Is() )
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         SvXMLImportContext *pContext = &xFrameContext;
164cdf0e10cSrcweir         xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     return xTxt;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir // --> OD 2004-08-24 #33242#
GetShape() const171cdf0e10cSrcweir Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     Reference < drawing::XShape > xShape;
174cdf0e10cSrcweir     if( xFrameContext.Is() )
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         SvXMLImportContext *pContext = &xFrameContext;
177cdf0e10cSrcweir         xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     return xShape;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir // <--
183