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