1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnmspe.hxx>
27 #include <sax/tools/converter.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
31 using namespace com::sun::star
;
32 using namespace xmloff::token
;
34 ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport
& rImport
,
35 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
36 ScXMLImportContext( rImport
),
37 fIterationEpsilon(0.001),
40 eSearchType(utl::SearchParam::SearchType::Regexp
),
41 bIsIterationEnabled(false),
49 aNullDate
.Year
= 1899;
52 for (auto &aIter
: *rAttrList
)
54 switch (aIter
.getToken())
56 case XML_ELEMENT( TABLE
, XML_CASE_SENSITIVE
):
57 if( IsXMLToken( aIter
, XML_FALSE
) )
60 case XML_ELEMENT( TABLE
, XML_PRECISION_AS_SHOWN
):
61 if( IsXMLToken( aIter
, XML_TRUE
) )
64 case XML_ELEMENT( TABLE
, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL
):
65 if( IsXMLToken( aIter
, XML_FALSE
) )
66 bMatchWholeCell
= false;
68 case XML_ELEMENT( TABLE
, XML_AUTOMATIC_FIND_LABELS
):
69 if( IsXMLToken( aIter
, XML_FALSE
) )
70 bLookUpLabels
= false;
72 case XML_ELEMENT( TABLE
, XML_NULL_YEAR
):
74 ::sax::Converter::convertNumber( nTemp
, aIter
.toString() );
75 nYear2000
= static_cast<sal_uInt16
>(nTemp
);
77 case XML_ELEMENT( TABLE
, XML_USE_REGULAR_EXPRESSIONS
):
78 // Overwrite only the default (regex true) value, not wildcard.
79 if( eSearchType
== utl::SearchParam::SearchType::Regexp
&& IsXMLToken( aIter
, XML_FALSE
) )
80 eSearchType
= utl::SearchParam::SearchType::Normal
;
82 case XML_ELEMENT( TABLE
, XML_USE_WILDCARDS
):
83 if( IsXMLToken( aIter
, XML_TRUE
) )
84 eSearchType
= utl::SearchParam::SearchType::Wildcard
;
91 ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
95 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCalculationSettingsContext::createFastChildContext(
96 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
98 SvXMLImportContext
*pContext
= nullptr;
99 sax_fastparser::FastAttributeList
*pAttribList
=
100 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
102 if (nElement
== XML_ELEMENT( TABLE
, XML_NULL_DATE
))
103 pContext
= new ScXMLNullDateContext(GetScImport(), pAttribList
, this);
104 else if (nElement
== XML_ELEMENT( TABLE
, XML_ITERATION
))
105 pContext
= new ScXMLIterationContext(GetScImport(), pAttribList
, this);
108 pContext
= new SvXMLImportContext( GetImport() );
113 void SAL_CALL
ScXMLCalculationSettingsContext::endFastElement( sal_Int32
/*nElement*/ )
115 if (GetScImport().GetModel().is())
117 uno::Reference
<beans::XPropertySet
> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY
);
118 if (xPropertySet
.is())
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())
134 ScXMLImport::MutexGuard
aGuard(GetScImport());
135 ScDocOptions
aDocOptions (GetScImport().GetDocument()->GetDocOptions());
136 aDocOptions
.SetYear2000(nYear2000
);
137 GetScImport().GetDocument()->SetDocOptions(aDocOptions
);
143 ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport
& rImport
,
144 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
145 ScXMLCalculationSettingsContext
* pCalcSet
) :
146 ScXMLImportContext( rImport
)
148 if ( rAttrList
.is() )
150 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_DATE_VALUE
) ) );
151 if (aIter
!= rAttrList
->end())
153 util::DateTime aDateTime
;
154 ::sax::Converter::parseDateTime(aDateTime
, aIter
.toString());
156 aDate
.Day
= aDateTime
.Day
;
157 aDate
.Month
= aDateTime
.Month
;
158 aDate
.Year
= aDateTime
.Year
;
159 pCalcSet
->SetNullDate(aDate
);
164 ScXMLNullDateContext::~ScXMLNullDateContext()
168 ScXMLIterationContext::ScXMLIterationContext( ScXMLImport
& rImport
,
169 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
170 ScXMLCalculationSettingsContext
* pCalcSet
) :
171 ScXMLImportContext( rImport
)
173 if ( rAttrList
.is() )
175 for (auto &aIter
: *rAttrList
)
177 switch (aIter
.getToken())
179 case XML_ELEMENT( TABLE
, XML_STATUS
):
180 if (IsXMLToken(aIter
, XML_ENABLE
))
181 pCalcSet
->SetIterationStatus(true);
183 case XML_ELEMENT( TABLE
, XML_STEPS
):
184 pCalcSet
->SetIterationCount(aIter
.toInt32());
186 case XML_ELEMENT( TABLE
, XML_MAXIMUM_DIFFERENCE
):
187 pCalcSet
->SetIterationEpsilon( aIter
.toDouble() );
194 ScXMLIterationContext::~ScXMLIterationContext()
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */