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 <sal/log.hxx>
21 #include <sax/tools/converter.hxx>
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"
29 #include "XMLTextFrameHyperlinkContext.hxx"
31 #include <com/sun/star/drawing/XShapes.hpp>
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
;
40 namespace drawing
= com::sun::star::drawing
;
43 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
45 sal_Int32
/*nElement*/,
46 const Reference
< XFastAttributeList
> & xAttrList
,
47 TextContentAnchorType eATyp
) :
48 SvXMLImportContext( rImport
),
49 eDefaultAnchorType( eATyp
),
54 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
56 switch( aIter
.getToken() )
58 case XML_ELEMENT(XLINK
, XML_HREF
):
59 sHRef
= GetImport().GetAbsoluteReference( aIter
.toString() );
61 case XML_ELEMENT(OFFICE
, XML_NAME
):
62 sName
= aIter
.toString();
64 case XML_ELEMENT(OFFICE
, XML_TARGET_FRAME_NAME
):
65 sTargetFrameName
= aIter
.toString();
67 case XML_ELEMENT(XLINK
, XML_SHOW
):
68 sShow
= aIter
.toString();
70 case XML_ELEMENT(OFFICE
, XML_SERVER_MAP
):
73 if (::sax::Converter::convertBool( bTmp
, aIter
.toView() ))
80 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
84 if( !sShow
.isEmpty() && sTargetFrameName
.isEmpty() )
86 if( IsXMLToken( sShow
, XML_NEW
) )
87 sTargetFrameName
= "_blank";
88 else if( IsXMLToken( sShow
, XML_REPLACE
) )
89 sTargetFrameName
= "_self";
93 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
97 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTextFrameHyperlinkContext::createFastChildContext(
99 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
101 SvXMLImportContext
*pContext
= nullptr;
102 XMLTextFrameContext
*pTextFrameContext
= nullptr;
106 case XML_ELEMENT(DRAW
, XML_FRAME
):
108 pTextFrameContext
= new XMLTextFrameContext(GetImport(), xAttrList
, eDefaultAnchorType
);
109 pTextFrameContext
->SetHyperlink(sHRef
, sName
, sTargetFrameName
, bMap
);
110 pContext
= pTextFrameContext
;
111 xFrameContext
= pContext
;
114 case XML_ELEMENT(DRAW
, XML_CUSTOM_SHAPE
):
115 case XML_ELEMENT(DRAW
, XML_PATH
):
116 case XML_ELEMENT(DRAW
, XML_ELLIPSE
):
117 case XML_ELEMENT(DRAW
, XML_LINE
):
118 case XML_ELEMENT(DRAW
, XML_RECT
):
119 case XML_ELEMENT(DRAW
, XML_CAPTION
):
120 case XML_ELEMENT(DRAW
, XML_POLYGON
):
121 case XML_ELEMENT(DRAW
, XML_POLYLINE
):
122 case XML_ELEMENT(DRAW
, XML_MEASURE
):
123 case XML_ELEMENT(DRAW
, XML_CIRCLE
):
124 case XML_ELEMENT(DRAW
, XML_CONNECTOR
):
125 case XML_ELEMENT(DRAW
, XML_CONTROL
):
126 case XML_ELEMENT(DRAW
, XML_PAGE_THUMBNAIL
):
127 case XML_ELEMENT(DRAW
, XML_G
):
128 case XML_ELEMENT(DR3D
, XML_SCENE
):
130 Reference
<XShapes
> xShapes
;
131 SvXMLShapeContext
* pShapeContext
= XMLShapeImportHelper::CreateGroupChildContext(
132 GetImport(), nElement
, xAttrList
, xShapes
);
133 pShapeContext
->setHyperlink(sHRef
);
134 pContext
= pShapeContext
;
140 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
146 TextContentAnchorType
XMLTextFrameHyperlinkContext::GetAnchorType() const
148 if( xFrameContext
.is() )
150 SvXMLImportContext
*pContext
= xFrameContext
.get();
151 return dynamic_cast<XMLTextFrameContext
&>(*pContext
).GetAnchorType();
154 return eDefaultAnchorType
;
158 Reference
< XTextContent
> XMLTextFrameHyperlinkContext::GetTextContent() const
160 Reference
<XTextContent
> xTxt
;
161 if( xFrameContext
.is() )
163 SvXMLImportContext
*pContext
= xFrameContext
.get();
164 xTxt
= dynamic_cast<XMLTextFrameContext
&>(*pContext
).GetTextContent();
170 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
171 Reference
< drawing::XShape
> XMLTextFrameHyperlinkContext::GetShape() const
173 Reference
< drawing::XShape
> xShape
;
174 if( xFrameContext
.is() )
176 SvXMLImportContext
*pContext
= xFrameContext
.get();
177 xShape
= dynamic_cast<XMLTextFrameContext
&>(*pContext
).GetShape();
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */