LibreOffice Module sc (master)  1
XMLDetectiveContext.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 "XMLDetectiveContext.hxx"
21 
22 #include <sax/tools/converter.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include "xmlimprt.hxx"
26 #include "XMLConverter.hxx"
27 #include <rangeutl.hxx>
28 
29 using namespace ::com::sun::star;
30 using namespace xmloff::token;
31 
33  aSourceRange(),
34  eObjType( SC_DETOBJ_NONE ),
35  bHasError( false )
36 {
37 }
38 
40 {
41  return (nIndex < rDetOp.nIndex);
42 }
43 
45 {
46  aDetectiveOpList.sort();
47 }
48 
50 {
51  if( aDetectiveOpList.empty() )
52  return false;
53  ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
54  rDetOp = *aItr;
55  aDetectiveOpList.erase( aItr );
56  return true;
57 }
58 
60  ScXMLImport& rImport,
61  ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
62  ScXMLImportContext( rImport ),
63  pDetectiveObjVec( pNewDetectiveObjVec )
64 {
65 }
66 
68 {
69 }
70 
71 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDetectiveContext::createFastChildContext(
72  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
73 {
74  SvXMLImportContext* pContext = nullptr;
77 
78  switch (nElement)
79  {
81  pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList, pDetectiveObjVec );
82  break;
84  pContext = new ScXMLDetectiveOperationContext( GetScImport(), pAttribList );
85  break;
86  }
87 
88  return pContext;
89 }
90 
92  ScXMLImport& rImport,
94  ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
95  ScXMLImportContext( rImport ),
96  pDetectiveObjVec( pNewDetectiveObjVec ),
97  aDetectiveObj(),
98  bValid( false )
99 {
100  if ( !rAttrList.is() )
101  return;
102 
103  for (auto &aIter : *rAttrList)
104  {
105  switch (aIter.getToken())
106  {
108  {
109  sal_Int32 nOffset(0);
112  }
113  break;
116  break;
119  break;
121  {
122  if (IsXMLToken(aIter, XML_TRUE))
124  }
125  break;
126  }
127  }
128 }
129 
131 {
132 }
133 
134 void SAL_CALL ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32 /*nElement*/ )
135 {
136  switch( aDetectiveObj.eObjType )
137  {
138  case SC_DETOBJ_ARROW:
140  break;
142  case SC_DETOBJ_CIRCLE:
143  bValid = true;
144  break;
145  default:
146  bValid = false;
147  }
148  if( bValid )
149  pDetectiveObjVec->push_back( aDetectiveObj );
150 }
151 
153  ScXMLImport& rImport,
155  ScXMLImportContext( rImport ),
156  aDetectiveOp(),
157  bHasType( false )
158 {
159  if ( rAttrList.is() )
160  {
161  for (auto &aIter : *rAttrList)
162  {
163  switch (aIter.getToken())
164  {
165  case XML_ELEMENT( TABLE, XML_NAME ):
167  break;
168  case XML_ELEMENT( TABLE, XML_INDEX ):
169  {
170  sal_Int32 nValue;
171  if (::sax::Converter::convertNumber( nValue, aIter.toString(), 0 ))
172  aDetectiveOp.nIndex = nValue;
173  }
174  break;
175  }
176  }
177  }
179 }
180 
182 {
183 }
184 
185 void SAL_CALL ScXMLDetectiveOperationContext::endFastElement( sal_Int32 /*nElement*/ )
186 {
187  if( bHasType && (aDetectiveOp.nIndex >= 0) )
189 }
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
XML_NAME
ScDocument * GetDocument()
Definition: xmlimprt.hxx:296
ScXMLDetectiveContext(ScXMLImport &rImport, ScMyImpDetectiveObjVec *pNewDetectiveObjVec)
ScMyTables & GetTables()
Definition: xmlimprt.hxx:299
bool GetFirstOp(ScMyImpDetectiveOp &rDetOp)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual ~ScXMLDetectiveContext() override
XML_INDEX
XML_CELL_RANGE_ADDRESS
ScMyImpDetectiveOpList aDetectiveOpList
static ScDetectiveObjType GetDetObjTypeFromString(const OUString &rString)
ScMyImpDetectiveObjVec * pDetectiveObjVec
XML_HIGHLIGHTED_RANGE
void AddDetectiveOp(const ScMyImpDetectiveOp &rDetOp)
ScMyImpDetectiveObjVec * pDetectiveObjVec
XML_MARKED_INVALID
virtual ~ScXMLDetectiveHighlightedContext() override
This class exists only to provide GetScImport() to its derived classes.
ScDetectiveObjType eObjType
bool operator<(const ScMyImpDetectiveOp &rDetOp) const
virtual ~ScXMLDetectiveOperationContext() override
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:392
ScXMLImport & GetScImport()
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XML_OPERATION
const ScAddress & GetCurrentCellPos() const
Definition: xmlsubti.hxx:81
TABLE
#define XML_ELEMENT(prefix, name)
XML_DIRECTION
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XML_CONTAINS_ERROR
ScMyImpDetectiveOpArray * GetDetectiveOpArray()
Definition: xmlimprt.cxx:1854
XML_TRUE
::std::vector< ScMyImpDetectiveObj > ScMyImpDetectiveObjVec
ScXMLDetectiveOperationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
sal_Int16 nValue
static bool GetDetOpTypeFromString(ScDetOpType &rDetOpType, const OUString &rString)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
ScXMLDetectiveHighlightedContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScMyImpDetectiveObjVec *pNewDetectiveObjVec)