LibreOffice Module xmloff (master)  1
XMLTextFrameHyperlinkContext.cxx
Go to the documentation of this file.
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 <sal/log.hxx>
21 #include <sax/tools/converter.hxx>
22 
23 #include <xmloff/shapeimport.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/namespacemap.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include "XMLTextFrameContext.hxx"
30 
31 #include <com/sun/star/drawing/XShapes.hpp>
32 
33 using namespace ::com::sun::star::drawing;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::text;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace ::com::sun::star::beans;
38 using namespace ::xmloff::token;
39 
41 
42 
44  SvXMLImport& rImport,
45  sal_Int32 /*nElement*/,
46  const Reference< XFastAttributeList > & xAttrList,
47  TextContentAnchorType eATyp ) :
48  SvXMLImportContext( rImport ),
49  eDefaultAnchorType( eATyp ),
50  bMap( false )
51 {
52  OUString sShow;
53 
54  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
55  {
56  switch( aIter.getToken() )
57  {
58  case XML_ELEMENT(XLINK, XML_HREF):
59  sHRef = GetImport().GetAbsoluteReference( aIter.toString() );
60  break;
62  sName = aIter.toString();
63  break;
65  sTargetFrameName = aIter.toString();
66  break;
67  case XML_ELEMENT(XLINK, XML_SHOW):
68  sShow = aIter.toString();
69  break;
71  {
72  bool bTmp(false);
73  if (::sax::Converter::convertBool( bTmp, aIter.toView() ))
74  {
75  bMap = bTmp;
76  }
77  }
78  break;
79  default:
80  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
81  }
82  }
83 
84  if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
85  {
86  if( IsXMLToken( sShow, XML_NEW ) )
87  sTargetFrameName = "_blank";
88  else if( IsXMLToken( sShow, XML_REPLACE ) )
89  sTargetFrameName = "_self";
90  }
91 }
92 
94 {
95 }
96 
97 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameHyperlinkContext::createFastChildContext(
98  sal_Int32 nElement,
99  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList )
100 {
101  SvXMLImportContext *pContext = nullptr;
102  XMLTextFrameContext *pTextFrameContext = nullptr;
103 
104  switch (nElement)
105  {
106  case XML_ELEMENT(DRAW, XML_FRAME):
107  {
108  pTextFrameContext = new XMLTextFrameContext(GetImport(), xAttrList, eDefaultAnchorType);
109  pTextFrameContext->SetHyperlink(sHRef, sName, sTargetFrameName, bMap);
110  pContext = pTextFrameContext;
111  xFrameContext = pContext;
112  }
113  break;
115  case XML_ELEMENT(DRAW, XML_PATH):
117  case XML_ELEMENT(DRAW, XML_LINE):
118  case XML_ELEMENT(DRAW, XML_RECT):
123  case XML_ELEMENT(DRAW, XML_CIRCLE):
127  case XML_ELEMENT(DRAW, XML_G):
128  case XML_ELEMENT(DR3D, XML_SCENE):
129  {
130  Reference<XShapes> xShapes;
132  GetImport(), nElement, xAttrList, xShapes);
133  pShapeContext->setHyperlink(sHRef);
134  pContext = pShapeContext;
135  }
136  break;
137  }
138 
139  if (!pContext)
140  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
141 
142  return pContext;
143 }
144 
145 
146 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
147 {
148  if( xFrameContext.is() )
149  {
150  SvXMLImportContext *pContext = xFrameContext.get();
151  return dynamic_cast<XMLTextFrameContext&>(*pContext).GetAnchorType();
152  }
153  else
154  return eDefaultAnchorType;
155 
156 }
157 
158 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
159 {
160  Reference <XTextContent > xTxt;
161  if( xFrameContext.is() )
162  {
163  SvXMLImportContext *pContext = xFrameContext.get();
164  xTxt = dynamic_cast<XMLTextFrameContext&>(*pContext).GetTextContent();
165  }
166 
167  return xTxt;
168 }
169 
170 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
171 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
172 {
173  Reference < drawing::XShape > xShape;
174  if( xFrameContext.is() )
175  {
176  SvXMLImportContext *pContext = xFrameContext.get();
177  xShape = dynamic_cast<XMLTextFrameContext&>(*pContext).GetShape();
178  }
179 
180  return xShape;
181 }
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3508
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void setHyperlink(const OUString &rHyperlink)
void SetHyperlink(const OUString &rHRef, const OUString &rName, const OUString &rTargetFrameName, bool bMap)
css::uno::Reference< css::text::XTextContent > GetTextContent() const
DRAW
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
css::text::TextContentAnchorType GetAnchorType() const
css::uno::Reference< css::drawing::XShape > GetShape() const
css::uno::Reference< css::text::XTextContent > GetTextContent() const
static bool convertBool(bool &rBool, std::u16string_view rString)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1602
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
css::text::TextContentAnchorType GetAnchorType() const
css::text::TextContentAnchorType eDefaultAnchorType
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119
static SvXMLShapeContext * CreateGroupChildContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes, bool bTemporaryShape=false)
css::uno::Reference< css::drawing::XShape > GetShape() const
XMLTextFrameHyperlinkContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::text::TextContentAnchorType eDefaultAnchorType)