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 "xmlannoi.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlconti.hxx"
23 #include "XMLTableShapeImportHelper.hxx"
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
28 using namespace com::sun::star
;
29 using namespace xmloff::token
;
31 ScXMLAnnotationData::ScXMLAnnotationData() :
32 mbUseShapePos( false ),
37 ScXMLAnnotationData::~ScXMLAnnotationData()
41 ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport
& rImport
,
43 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
,
44 ScXMLAnnotationData
& rAnnotationData
) :
45 ScXMLImportContext( rImport
),
46 mrAnnotationData( rAnnotationData
)
48 uno::Reference
<drawing::XShapes
> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
49 if (xLocalShapes
.is())
51 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
52 pTableShapeImport
->SetAnnotation(this);
53 pShapeContext
.reset( XMLShapeImportHelper::CreateGroupChildContext(
54 GetScImport(), nElement
, xAttrList
, xLocalShapes
, true) );
57 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
59 switch( aIter
.getToken() )
61 case XML_ELEMENT(OFFICE
, XML_AUTHOR
):
63 maAuthorBuffer
= aIter
.toString();
66 case XML_ELEMENT(OFFICE
, XML_CREATE_DATE
):
68 maCreateDateBuffer
= aIter
.toString();
71 case XML_ELEMENT(OFFICE
, XML_CREATE_DATE_STRING
):
73 maCreateDateStringBuffer
= aIter
.toString();
76 case XML_ELEMENT(OFFICE
, XML_DISPLAY
):
78 mrAnnotationData
.mbShown
= IsXMLToken(aIter
, XML_TRUE
);
81 case XML_ELEMENT(SVG
, XML_X
):
82 case XML_ELEMENT(SVG_COMPAT
, XML_X
):
84 mrAnnotationData
.mbUseShapePos
= true;
87 case XML_ELEMENT(SVG
, XML_Y
):
88 case XML_ELEMENT(SVG_COMPAT
, XML_Y
):
90 mrAnnotationData
.mbUseShapePos
= true;
94 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
99 ScXMLAnnotationContext::~ScXMLAnnotationContext()
103 void ScXMLAnnotationContext::startFastElement(sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
106 pShapeContext
->startFastElement(nElement
, xAttrList
);
109 css::uno::Reference
< css::xml::sax::XFastContextHandler
> ScXMLAnnotationContext::createFastChildContext(
111 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
115 case XML_ELEMENT(DC
, XML_CREATOR
):
116 return new ScXMLContentContext(GetScImport(), maAuthorBuffer
);
117 case XML_ELEMENT(DC
, XML_DATE
):
118 return new ScXMLContentContext(GetScImport(), maCreateDateBuffer
);
119 case XML_ELEMENT(META
, XML_DATE_STRING
):
120 return new ScXMLContentContext(GetScImport(), maCreateDateStringBuffer
);
125 auto p
= pShapeContext
->createFastChildContext(nElement
, xAttrList
);
130 XMLOFF_WARN_UNKNOWN_ELEMENT("sc", nElement
);
134 void ScXMLAnnotationContext::characters( const OUString
& rChars
)
136 maTextBuffer
.append(rChars
);
139 void ScXMLAnnotationContext::endFastElement(sal_Int32 nElement
)
143 pShapeContext
->endFastElement(nElement
);
144 pShapeContext
.reset();
147 mrAnnotationData
.maAuthor
= maAuthorBuffer
.makeStringAndClear();
148 mrAnnotationData
.maCreateDate
= maCreateDateBuffer
.makeStringAndClear();
149 if (mrAnnotationData
.maCreateDate
.isEmpty())
150 mrAnnotationData
.maCreateDate
= maCreateDateStringBuffer
.makeStringAndClear();
151 mrAnnotationData
.maSimpleText
= maTextBuffer
.makeStringAndClear();
153 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
154 pTableShapeImport
->SetAnnotation(nullptr);
157 void ScXMLAnnotationContext::SetShape( const uno::Reference
< drawing::XShape
>& rxShape
, const uno::Reference
< drawing::XShapes
>& rxShapes
,
158 const OUString
& rStyleName
, const OUString
& rTextStyle
)
160 mrAnnotationData
.mxShape
= rxShape
;
161 mrAnnotationData
.mxShapes
= rxShapes
;
162 mrAnnotationData
.maStyleName
= rStyleName
;
163 mrAnnotationData
.maTextStyle
= rTextStyle
;
166 void ScXMLAnnotationContext::AddContentStyle( XmlStyleFamily nFamily
, const OUString
& rName
, const ESelection
& rSelection
)
168 mrAnnotationData
.maContentStyles
.emplace_back( nFamily
, rName
, rSelection
);
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */