tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / XMLCalculationSettingsContext.cxx
blobd57111e66295d383315eddf85b7d3044a633726c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLCalculationSettingsContext.hxx"
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 #include <docuno.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
32 using namespace com::sun::star;
33 using namespace xmloff::token;
35 ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport& rImport,
36 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
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)
48 aNullDate.Day = 30;
49 aNullDate.Month = 12;
50 aNullDate.Year = 1899;
51 if ( !rAttrList.is() )
52 return;
54 for (auto &aIter : *rAttrList)
56 switch (aIter.getToken())
58 case XML_ELEMENT( TABLE, XML_CASE_SENSITIVE ):
59 if( IsXMLToken( aIter, XML_FALSE ) )
60 bIgnoreCase = true;
61 break;
62 case XML_ELEMENT( TABLE, XML_PRECISION_AS_SHOWN ):
63 if( IsXMLToken( aIter, XML_TRUE ) )
64 bCalcAsShown = true;
65 break;
66 case XML_ELEMENT( TABLE, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL ):
67 if( IsXMLToken( aIter, XML_FALSE ) )
68 bMatchWholeCell = false;
69 break;
70 case XML_ELEMENT( TABLE, XML_AUTOMATIC_FIND_LABELS ):
71 if( IsXMLToken( aIter, XML_FALSE ) )
72 bLookUpLabels = false;
73 break;
74 case XML_ELEMENT( TABLE, XML_NULL_YEAR ):
75 sal_Int32 nTemp;
76 ::sax::Converter::convertNumber( nTemp, aIter.toView() );
77 nYear2000 = static_cast<sal_uInt16>(nTemp);
78 break;
79 case XML_ELEMENT( TABLE, XML_USE_REGULAR_EXPRESSIONS ):
80 // Overwrite only the default (regex true) value, not wildcard.
81 if( eSearchType == utl::SearchParam::SearchType::Regexp && IsXMLToken( aIter, XML_FALSE ) )
82 eSearchType = utl::SearchParam::SearchType::Normal;
83 break;
84 case XML_ELEMENT( TABLE, XML_USE_WILDCARDS ):
85 if( IsXMLToken( aIter, XML_TRUE ) )
86 eSearchType = utl::SearchParam::SearchType::Wildcard;
87 break;
92 ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
96 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCalculationSettingsContext::createFastChildContext(
97 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
99 SvXMLImportContext *pContext = nullptr;
100 sax_fastparser::FastAttributeList *pAttribList =
101 &sax_fastparser::castToFastAttributeList( xAttrList );
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);
108 return pContext;
111 void SAL_CALL ScXMLCalculationSettingsContext::endFastElement( sal_Int32 /*nElement*/ )
113 ScModelObj* xPropertySet(GetScImport().GetScModel());
114 if (!xPropertySet)
115 return;
117 xPropertySet->setPropertyValue( SC_UNO_CALCASSHOWN, uno::Any(bCalcAsShown) );
118 xPropertySet->setPropertyValue( SC_UNO_IGNORECASE, uno::Any(bIgnoreCase) );
119 xPropertySet->setPropertyValue( SC_UNO_LOOKUPLABELS, uno::Any(bLookUpLabels) );
120 xPropertySet->setPropertyValue( SC_UNO_MATCHWHOLE, uno::Any(bMatchWholeCell) );
121 bool bWildcards, bRegex;
122 utl::SearchParam::ConvertToBool( eSearchType, bWildcards, bRegex);
123 xPropertySet->setPropertyValue( SC_UNO_REGEXENABLED, uno::Any(bRegex) );
124 xPropertySet->setPropertyValue( SC_UNO_WILDCARDSENABLED, uno::Any(bWildcards) );
125 xPropertySet->setPropertyValue( SC_UNO_ITERENABLED, uno::Any(bIsIterationEnabled) );
126 xPropertySet->setPropertyValue( SC_UNO_ITERCOUNT, uno::Any(nIterationCount) );
127 xPropertySet->setPropertyValue( SC_UNO_ITEREPSILON, uno::Any(fIterationEpsilon) );
128 xPropertySet->setPropertyValue( SC_UNO_NULLDATE, uno::Any(aNullDate) );
129 if (ScDocument* pDoc = GetScImport().GetDocument())
131 ScXMLImport::MutexGuard aGuard(GetScImport());
132 ScDocOptions aDocOptions (pDoc->GetDocOptions());
133 aDocOptions.SetYear2000(nYear2000);
134 GetScImport().GetDocument()->SetDocOptions(aDocOptions);
138 ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport& rImport,
139 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
140 ScXMLCalculationSettingsContext* pCalcSet) :
141 ScXMLImportContext( rImport )
143 if ( !rAttrList.is() )
144 return;
146 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DATE_VALUE ) ) );
147 if (aIter != rAttrList->end())
149 util::DateTime aDateTime;
150 if (::sax::Converter::parseDateTime(aDateTime, aIter.toView()))
152 util::Date aDate;
153 aDate.Day = aDateTime.Day;
154 aDate.Month = aDateTime.Month;
155 aDate.Year = aDateTime.Year;
156 pCalcSet->SetNullDate(aDate);
158 else
160 SAL_WARN("sc.filter","ignoring invalid NullDate '" << aIter.toView() << "'");
165 ScXMLNullDateContext::~ScXMLNullDateContext()
169 ScXMLIterationContext::ScXMLIterationContext( ScXMLImport& rImport,
170 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
171 ScXMLCalculationSettingsContext* pCalcSet) :
172 ScXMLImportContext( rImport )
174 if ( !rAttrList.is() )
175 return;
177 for (auto &aIter : *rAttrList)
179 switch (aIter.getToken())
181 case XML_ELEMENT( TABLE, XML_STATUS ):
182 if (IsXMLToken(aIter, XML_ENABLE))
183 pCalcSet->SetIterationStatus(true);
184 break;
185 case XML_ELEMENT( TABLE, XML_STEPS ):
186 pCalcSet->SetIterationCount(aIter.toInt32());
187 break;
188 case XML_ELEMENT( TABLE, XML_MAXIMUM_DIFFERENCE ):
189 pCalcSet->SetIterationEpsilon( aIter.toDouble() );
190 break;
195 ScXMLIterationContext::~ScXMLIterationContext()
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */