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/xmlnamespace.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);
111  ScDocument* pDoc = GetScImport().GetDocument();
112  assert(pDoc);
114  }
115  break;
118  break;
121  break;
123  {
124  if (IsXMLToken(aIter, XML_TRUE))
126  }
127  break;
128  }
129  }
130 }
131 
133 {
134 }
135 
136 void SAL_CALL ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32 /*nElement*/ )
137 {
138  switch( aDetectiveObj.eObjType )
139  {
140  case SC_DETOBJ_ARROW:
142  break;
144  case SC_DETOBJ_CIRCLE:
145  bValid = true;
146  break;
147  default:
148  bValid = false;
149  }
150  if( bValid )
151  pDetectiveObjVec->push_back( aDetectiveObj );
152 }
153 
155  ScXMLImport& rImport,
157  ScXMLImportContext( rImport ),
158  aDetectiveOp(),
159  bHasType( false )
160 {
161  if ( rAttrList.is() )
162  {
163  for (auto &aIter : *rAttrList)
164  {
165  switch (aIter.getToken())
166  {
167  case XML_ELEMENT( TABLE, XML_NAME ):
169  break;
170  case XML_ELEMENT( TABLE, XML_INDEX ):
171  {
172  sal_Int32 nValue;
173  if (::sax::Converter::convertNumber( nValue, aIter.toString(), 0 ))
174  aDetectiveOp.nIndex = nValue;
175  }
176  break;
177  }
178  }
179  }
181 }
182 
184 {
185 }
186 
187 void SAL_CALL ScXMLDetectiveOperationContext::endFastElement( sal_Int32 /*nElement*/ )
188 {
189  if( bHasType && (aDetectiveOp.nIndex >= 0) )
191 }
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XML_NAME
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
ScXMLDetectiveContext(ScXMLImport &rImport, ScMyImpDetectiveObjVec *pNewDetectiveObjVec)
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
bool GetFirstOp(ScMyImpDetectiveOp &rDetOp)
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual ~ScXMLDetectiveContext() override
XML_INDEX
XML_CELL_RANGE_ADDRESS
ScMyImpDetectiveOpList aDetectiveOpList
ScMyImpDetectiveObjVec * pDetectiveObjVec
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
XML_HIGHLIGHTED_RANGE
void AddDetectiveOp(const ScMyImpDetectiveOp &rDetOp)
ScMyImpDetectiveObjVec * pDetectiveObjVec
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
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
static ScDetectiveObjType GetDetObjTypeFromString(std::u16string_view rString)
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:293
static bool GetDetOpTypeFromString(ScDetOpType &rDetOpType, std::u16string_view rString)
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:80
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:1673
XML_TRUE
::std::vector< ScMyImpDetectiveObj > ScMyImpDetectiveObjVec
ScXMLDetectiveOperationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
sal_Int16 nValue
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)