LibreOffice Module sc (master) 1
xmlannoi.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 "xmlannoi.hxx"
21#include "xmlimprt.hxx"
22#include "xmlconti.hxx"
24
26#include <xmloff/xmltoken.hxx>
27
28using namespace com::sun::star;
29using namespace xmloff::token;
30
32 mbUseShapePos( false ),
33 mbShown( false )
34{
35}
36
38{
39}
40
42 sal_Int32 nElement,
43 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
44 ScXMLAnnotationData& rAnnotationData) :
45 ScXMLImportContext( rImport ),
46 mrAnnotationData( rAnnotationData )
47{
48 uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
49 if (xLocalShapes.is())
50 {
51 XMLTableShapeImportHelper* pTableShapeImport = static_cast<XMLTableShapeImportHelper*>(GetScImport().GetShapeImport().get());
52 pTableShapeImport->SetAnnotation(this);
54 GetScImport(), nElement, xAttrList, xLocalShapes, true) );
55 }
56
57 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
58 {
59 switch( aIter.getToken() )
60 {
62 {
63 maAuthorBuffer = aIter.toString();
64 }
65 break;
67 {
68 maCreateDateBuffer = aIter.toString();
69 }
70 break;
72 {
73 maCreateDateStringBuffer = aIter.toString();
74 }
75 break;
77 {
79 }
80 break;
81 case XML_ELEMENT(SVG, XML_X):
82 case XML_ELEMENT(SVG_COMPAT, XML_X):
83 {
85 }
86 break;
87 case XML_ELEMENT(SVG, XML_Y):
88 case XML_ELEMENT(SVG_COMPAT, XML_Y):
89 {
91 }
92 break;
93 default:
94 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
95 }
96 }
97}
98
100{
101}
102
103void ScXMLAnnotationContext::startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList)
104{
105 if (pShapeContext)
106 pShapeContext->startFastElement(nElement, xAttrList);
107}
108
109css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLAnnotationContext::createFastChildContext(
110 sal_Int32 nElement,
111 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
112{
113 switch (nElement)
114 {
115 case XML_ELEMENT(DC, XML_CREATOR):
117 case XML_ELEMENT(DC, XML_DATE):
121 }
122
123 if( pShapeContext )
124 {
125 auto p = pShapeContext->createFastChildContext(nElement, xAttrList);
126 if (p)
127 return p;
128 }
129
130 XMLOFF_WARN_UNKNOWN_ELEMENT("sc", nElement);
131 return nullptr;
132}
133
134void ScXMLAnnotationContext::characters( const OUString& rChars )
135{
136 maTextBuffer.append(rChars);
137}
138
140{
141 if (pShapeContext)
142 {
143 pShapeContext->endFastElement(nElement);
144 pShapeContext.reset();
145 }
146
147 mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
148 mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
149 if (mrAnnotationData.maCreateDate.isEmpty())
151 mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
152
153 XMLTableShapeImportHelper* pTableShapeImport = static_cast<XMLTableShapeImportHelper*>(GetScImport().GetShapeImport().get());
154 pTableShapeImport->SetAnnotation(nullptr);
155}
156
157void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
158 const OUString& rStyleName, const OUString& rTextStyle )
159{
160 mrAnnotationData.mxShape = rxShape;
161 mrAnnotationData.mxShapes = rxShapes;
162 mrAnnotationData.maStyleName = rStyleName;
163 mrAnnotationData.maTextStyle = rTextStyle;
164}
165
166void ScXMLAnnotationContext::AddContentStyle( XmlStyleFamily nFamily, const OUString& rName, const ESelection& rSelection )
167{
168 mrAnnotationData.maContentStyles.emplace_back( nFamily, rName, rSelection );
169}
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScXMLAnnotationData & mrAnnotationData
Definition: xmlannoi.hxx:96
std::unique_ptr< SvXMLImportContext > pShapeContext
Definition: xmlannoi.hxx:101
OUStringBuffer maAuthorBuffer
Definition: xmlannoi.hxx:98
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlannoi.cxx:103
OUStringBuffer maCreateDateStringBuffer
Definition: xmlannoi.hxx:100
virtual ~ScXMLAnnotationContext() override
Definition: xmlannoi.cxx:99
OUStringBuffer maTextBuffer
Definition: xmlannoi.hxx:97
void SetShape(const css::uno::Reference< css::drawing::XShape > &rxShape, const css::uno::Reference< css::drawing::XShapes > &rxShapes, const OUString &rStyleName, const OUString &rTextStyle)
Definition: xmlannoi.cxx:157
ScXMLAnnotationContext(ScXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, ScXMLAnnotationData &rAnnotationData)
Definition: xmlannoi.cxx:41
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlannoi.cxx:139
OUStringBuffer maCreateDateBuffer
Definition: xmlannoi.hxx:99
void AddContentStyle(XmlStyleFamily nFamily, const OUString &rName, const ESelection &rSelection)
Definition: xmlannoi.cxx:166
virtual void SAL_CALL characters(const OUString &rChars) override
Definition: xmlannoi.cxx:134
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlannoi.cxx:109
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
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)
void SetAnnotation(ScXMLAnnotationContext *pAnnotation)
XmlStyleFamily
void * p
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_AUTHOR
XML_CREATOR
XML_X
XML_CREATE_DATE
XML_DISPLAY
XML_TRUE
XML_DATE_STRING
XML_CREATE_DATE_STRING
XML_Y
XML_DATE
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
std::vector< ScXMLAnnotationStyleEntry > maContentStyles
Definition: xmlannoi.hxx:61
css::uno::Reference< css::drawing::XShape > mxShape
Definition: xmlannoi.hxx:51
OUString maCreateDate
Definition: xmlannoi.hxx:55
OUString maStyleName
Definition: xmlannoi.hxx:57
OUString maTextStyle
Definition: xmlannoi.hxx:58
OUString maSimpleText
Definition: xmlannoi.hxx:56
css::uno::Reference< css::drawing::XShapes > mxShapes
Definition: xmlannoi.hxx:53
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)