LibreOffice Module sc (master)  1
XMLCalculationSettingsContext.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 
21 #include "xmlimprt.hxx"
22 #include <unonames.hxx>
23 #include <docoptio.hxx>
24 #include <document.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <sax/tools/converter.hxx>
28 
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
31 
32 using namespace com::sun::star;
33 using namespace xmloff::token;
34 
37  ScXMLImportContext( rImport ),
38  fIterationEpsilon(0.001),
39  nIterationCount(100),
40  nYear2000(1930),
41  eSearchType(utl::SearchParam::SearchType::Regexp),
42  bIsIterationEnabled(false),
43  bCalcAsShown(false),
44  bIgnoreCase(false),
45  bLookUpLabels(true),
46  bMatchWholeCell(true)
47 {
48  aNullDate.Day = 30;
49  aNullDate.Month = 12;
50  aNullDate.Year = 1899;
51  if ( !rAttrList.is() )
52  return;
53 
54  for (auto &aIter : *rAttrList)
55  {
56  switch (aIter.getToken())
57  {
59  if( IsXMLToken( aIter, XML_FALSE ) )
60  bIgnoreCase = true;
61  break;
63  if( IsXMLToken( aIter, XML_TRUE ) )
64  bCalcAsShown = true;
65  break;
67  if( IsXMLToken( aIter, XML_FALSE ) )
68  bMatchWholeCell = false;
69  break;
71  if( IsXMLToken( aIter, XML_FALSE ) )
72  bLookUpLabels = false;
73  break;
75  sal_Int32 nTemp;
76  ::sax::Converter::convertNumber( nTemp, aIter.toString() );
77  nYear2000 = static_cast<sal_uInt16>(nTemp);
78  break;
80  // Overwrite only the default (regex true) value, not wildcard.
83  break;
85  if( IsXMLToken( aIter, XML_TRUE ) )
87  break;
88  }
89  }
90 }
91 
93 {
94 }
95 
96 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCalculationSettingsContext::createFastChildContext(
97  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
98 {
99  SvXMLImportContext *pContext = nullptr;
100  sax_fastparser::FastAttributeList *pAttribList =
102 
103  if (nElement == XML_ELEMENT( TABLE, XML_NULL_DATE ))
104  pContext = new ScXMLNullDateContext(GetScImport(), pAttribList, this);
105  else if (nElement == XML_ELEMENT( TABLE, XML_ITERATION ))
106  pContext = new ScXMLIterationContext(GetScImport(), pAttribList, this);
107 
108  return pContext;
109 }
110 
111 void SAL_CALL ScXMLCalculationSettingsContext::endFastElement( sal_Int32 /*nElement*/ )
112 {
113  if (!GetScImport().GetModel().is())
114  return;
115 
116  uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
117  if (!xPropertySet.is())
118  return;
119 
120  xPropertySet->setPropertyValue( SC_UNO_CALCASSHOWN, uno::makeAny(bCalcAsShown) );
121  xPropertySet->setPropertyValue( SC_UNO_IGNORECASE, uno::makeAny(bIgnoreCase) );
122  xPropertySet->setPropertyValue( SC_UNO_LOOKUPLABELS, uno::makeAny(bLookUpLabels) );
123  xPropertySet->setPropertyValue( SC_UNO_MATCHWHOLE, uno::makeAny(bMatchWholeCell) );
124  bool bWildcards, bRegex;
125  utl::SearchParam::ConvertToBool( eSearchType, bWildcards, bRegex);
126  xPropertySet->setPropertyValue( SC_UNO_REGEXENABLED, uno::makeAny(bRegex) );
127  xPropertySet->setPropertyValue( SC_UNO_WILDCARDSENABLED, uno::makeAny(bWildcards) );
128  xPropertySet->setPropertyValue( SC_UNO_ITERENABLED, uno::makeAny(bIsIterationEnabled) );
129  xPropertySet->setPropertyValue( SC_UNO_ITERCOUNT, uno::makeAny(nIterationCount) );
130  xPropertySet->setPropertyValue( SC_UNO_ITEREPSILON, uno::makeAny(fIterationEpsilon) );
131  xPropertySet->setPropertyValue( SC_UNO_NULLDATE, uno::makeAny(aNullDate) );
132  if (GetScImport().GetDocument())
133  {
135  ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
136  aDocOptions.SetYear2000(nYear2000);
137  GetScImport().GetDocument()->SetDocOptions(aDocOptions);
138  }
139 }
140 
144  ScXMLImportContext( rImport )
145 {
146  if ( !rAttrList.is() )
147  return;
148 
149  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DATE_VALUE ) ) );
150  if (aIter != rAttrList->end())
151  {
152  util::DateTime aDateTime;
153  ::sax::Converter::parseDateTime(aDateTime, aIter.toString());
154  util::Date aDate;
155  aDate.Day = aDateTime.Day;
156  aDate.Month = aDateTime.Month;
157  aDate.Year = aDateTime.Year;
158  pCalcSet->SetNullDate(aDate);
159  }
160 }
161 
163 {
164 }
165 
169  ScXMLImportContext( rImport )
170 {
171  if ( !rAttrList.is() )
172  return;
173 
174  for (auto &aIter : *rAttrList)
175  {
176  switch (aIter.getToken())
177  {
178  case XML_ELEMENT( TABLE, XML_STATUS ):
179  if (IsXMLToken(aIter, XML_ENABLE))
180  pCalcSet->SetIterationStatus(true);
181  break;
182  case XML_ELEMENT( TABLE, XML_STEPS ):
183  pCalcSet->SetIterationCount(aIter.toInt32());
184  break;
186  pCalcSet->SetIterationEpsilon( aIter.toDouble() );
187  break;
188  }
189  }
190 }
191 
193 {
194 }
195 
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SC_UNO_IGNORECASE
Definition: unonames.hxx:502
#define SC_UNO_ITERENABLED
Definition: unonames.hxx:504
#define SC_UNO_ITERCOUNT
Definition: unonames.hxx:503
ScDocument * GetDocument()
Definition: xmlimprt.hxx:206
XML_USE_WILDCARDS
XML_NULL_YEAR
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_PRECISION_AS_SHOWN
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
XML_MAXIMUM_DIFFERENCE
XML_ITERATION
#define SC_UNO_NULLDATE
Definition: unonames.hxx:508
XML_FALSE
XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL
XML_CASE_SENSITIVE
#define SC_UNO_MATCHWHOLE
Definition: unonames.hxx:507
This class exists only to provide GetScImport() to its derived classes.
XML_STATUS
#define SC_UNO_WILDCARDSENABLED
Definition: unonames.hxx:512
#define SC_UNO_REGEXENABLED
Definition: unonames.hxx:511
XML_STEPS
ScXMLIterationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLCalculationSettingsContext *pCalcSet)
void SetYear2000(sal_uInt16 nVal)
Definition: docoptio.hxx:85
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:294
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
#define SC_UNO_LOOKUPLABELS
Definition: unonames.hxx:506
TABLE
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1928
XML_AUTOMATIC_FIND_LABELS
#define SC_UNO_CALCASSHOWN
Definition: unonames.hxx:499
XML_ENABLE
#define XML_ELEMENT(prefix, name)
void SetNullDate(const css::util::Date &aDate)
ScXMLCalculationSettingsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
static void ConvertToBool(const SearchType eSearchType, bool &rbWildcard, bool &rbRegExp)
XML_NULL_DATE
XML_TRUE
XML_USE_REGULAR_EXPRESSIONS
XML_DATE_VALUE
void SetIterationCount(const sal_Int32 nValue)
#define SC_UNO_ITEREPSILON
Definition: unonames.hxx:505
ScXMLNullDateContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLCalculationSettingsContext *pCalcSet)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)