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 <svl/numformat.hxx>
21 #include <osl/diagnose.h>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include <docoptio.hxx>
27 #include <miscuno.hxx>
31 using namespace com::sun::star::uno
;
34 using sc::TwipsToEvenHMM
;
36 static sal_uInt16
lcl_GetDefaultTabDist()
38 if ( ScOptionsUtil::IsMetricSystem() )
39 return 709; // 1,25 cm
44 // ScDocOptions - document options
46 ScDocOptions::ScDocOptions()
51 void ScDocOptions::ResetDocOptions()
53 bIsIgnoreCase
= false;
57 nPrecStandardFormat
= SvNumberFormatter::UNLIMITED_PRECISION
;
61 nYear2000
= SvNumberFormatter::GetYear2000Default();
62 nTabDistance
= lcl_GetDefaultTabDist();
64 bMatchWholeCell
= true;
65 bLookUpColRowNames
= true;
66 bFormulaRegexEnabled
= false;
67 bFormulaWildcardsEnabled
= true;
68 eFormulaSearchType
= utl::SearchParam::SearchType::Wildcard
;
69 bWriteCalcConfig
= true;
72 void ScDocOptions::SetFormulaRegexEnabled( bool bVal
)
76 bFormulaRegexEnabled
= true;
77 bFormulaWildcardsEnabled
= false;
78 eFormulaSearchType
= utl::SearchParam::SearchType::Regexp
;
80 else if (!bFormulaRegexEnabled
)
81 ; // nothing changes for setting false to false
84 bFormulaRegexEnabled
= false;
85 eFormulaSearchType
= utl::SearchParam::SearchType::Unknown
;
89 void ScDocOptions::SetFormulaWildcardsEnabled( bool bVal
)
93 bFormulaRegexEnabled
= false;
94 bFormulaWildcardsEnabled
= true;
95 eFormulaSearchType
= utl::SearchParam::SearchType::Wildcard
;
97 else if (!bFormulaWildcardsEnabled
)
98 ; // nothing changes for setting false to false
101 bFormulaWildcardsEnabled
= false;
102 eFormulaSearchType
= utl::SearchParam::SearchType::Unknown
;
106 // ScTpCalcItem - data for the CalcOptions TabPage
108 ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP
, const ScDocOptions
& rOpt
)
109 : SfxPoolItem ( nWhichP
, SfxItemType::ScTpCalcItemType
),
114 ScTpCalcItem::~ScTpCalcItem()
118 bool ScTpCalcItem::operator==( const SfxPoolItem
& rItem
) const
120 assert(SfxPoolItem::operator==(rItem
));
122 const ScTpCalcItem
& rPItem
= static_cast<const ScTpCalcItem
&>(rItem
);
124 return ( theOptions
== rPItem
.theOptions
);
127 ScTpCalcItem
* ScTpCalcItem::Clone( SfxItemPool
* ) const
129 return new ScTpCalcItem( *this );
132 // Config Item containing document options
134 constexpr OUStringLiteral CFGPATH_CALC
= u
"Office.Calc/Calculate";
136 #define SCCALCOPT_ITER_ITER 0
137 #define SCCALCOPT_ITER_STEPS 1
138 #define SCCALCOPT_ITER_MINCHG 2
139 #define SCCALCOPT_DATE_DAY 3
140 #define SCCALCOPT_DATE_MONTH 4
141 #define SCCALCOPT_DATE_YEAR 5
142 #define SCCALCOPT_DECIMALS 6
143 #define SCCALCOPT_CASESENSITIVE 7
144 #define SCCALCOPT_PRECISION 8
145 #define SCCALCOPT_SEARCHCRIT 9
146 #define SCCALCOPT_FINDLABEL 10
147 #define SCCALCOPT_REGEX 11
148 #define SCCALCOPT_WILDCARDS 12
150 constexpr OUStringLiteral CFGPATH_DOCLAYOUT
= u
"Office.Calc/Layout/Other";
152 #define SCDOCLAYOUTOPT_TABSTOP 0
154 Sequence
<OUString
> ScDocCfg::GetCalcPropertyNames()
156 return {u
"IterativeReference/Iteration"_ustr
, // SCCALCOPT_ITER_ITER
157 u
"IterativeReference/Steps"_ustr
, // SCCALCOPT_ITER_STEPS
158 u
"IterativeReference/MinimumChange"_ustr
, // SCCALCOPT_ITER_MINCHG
159 u
"Other/Date/DD"_ustr
, // SCCALCOPT_DATE_DAY
160 u
"Other/Date/MM"_ustr
, // SCCALCOPT_DATE_MONTH
161 u
"Other/Date/YY"_ustr
, // SCCALCOPT_DATE_YEAR
162 u
"Other/DecimalPlaces"_ustr
, // SCCALCOPT_DECIMALS
163 u
"Other/CaseSensitive"_ustr
, // SCCALCOPT_CASESENSITIVE
164 u
"Other/Precision"_ustr
, // SCCALCOPT_PRECISION
165 u
"Other/SearchCriteria"_ustr
, // SCCALCOPT_SEARCHCRIT
166 u
"Other/FindLabel"_ustr
, // SCCALCOPT_FINDLABEL
167 u
"Other/RegularExpressions"_ustr
, // SCCALCOPT_REGEX
168 u
"Other/Wildcards"_ustr
}; // SCCALCOPT_WILDCARDS
171 Sequence
<OUString
> ScDocCfg::GetLayoutPropertyNames()
173 if (ScOptionsUtil::IsMetricSystem())
174 return {u
"TabStop/Metric"_ustr
}; // SCDOCLAYOUTOPT_TABSTOP
176 return {u
"TabStop/NonMetric"_ustr
}; // SCDOCLAYOUTOPT_TABSTOP
179 ScDocCfg::ScDocCfg() :
180 aCalcItem( CFGPATH_CALC
),
181 aLayoutItem(CFGPATH_DOCLAYOUT
)
183 sal_Int32 nIntVal
= 0;
185 Sequence
<OUString
> aNames
;
186 Sequence
<Any
> aValues
;
187 const Any
* pValues
= nullptr;
189 sal_uInt16 nDateDay
, nDateMonth
;
191 GetDate( nDateDay
, nDateMonth
, nDateYear
);
193 aNames
= GetCalcPropertyNames();
194 aValues
= aCalcItem
.GetProperties(aNames
);
195 aCalcItem
.EnableNotification(aNames
);
196 pValues
= aValues
.getConstArray();
197 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
198 if(aValues
.getLength() == aNames
.getLength())
200 double fDoubleVal
= 0;
201 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
203 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
204 if(pValues
[nProp
].hasValue())
208 case SCCALCOPT_ITER_ITER
:
209 SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
211 case SCCALCOPT_ITER_STEPS
:
212 if (pValues
[nProp
] >>= nIntVal
) SetIterCount( static_cast<sal_uInt16
>(nIntVal
) );
214 case SCCALCOPT_ITER_MINCHG
:
215 if (pValues
[nProp
] >>= fDoubleVal
) SetIterEps( fDoubleVal
);
217 case SCCALCOPT_DATE_DAY
:
218 if (pValues
[nProp
] >>= nIntVal
) nDateDay
= static_cast<sal_uInt16
>(nIntVal
);
220 case SCCALCOPT_DATE_MONTH
:
221 if (pValues
[nProp
] >>= nIntVal
) nDateMonth
= static_cast<sal_uInt16
>(nIntVal
);
223 case SCCALCOPT_DATE_YEAR
:
224 if (pValues
[nProp
] >>= nIntVal
) nDateYear
= static_cast<sal_Int16
>(nIntVal
);
226 case SCCALCOPT_DECIMALS
:
227 if (pValues
[nProp
] >>= nIntVal
) SetStdPrecision( static_cast<sal_uInt16
>(nIntVal
) );
229 case SCCALCOPT_CASESENSITIVE
:
230 // content is reversed
231 SetIgnoreCase( !ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
233 case SCCALCOPT_PRECISION
:
234 SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
236 case SCCALCOPT_SEARCHCRIT
:
237 SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
239 case SCCALCOPT_FINDLABEL
:
240 SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
242 case SCCALCOPT_REGEX
:
243 SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
245 case SCCALCOPT_WILDCARDS
:
246 SetFormulaWildcardsEnabled( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
252 aCalcItem
.SetCommitLink( LINK( this, ScDocCfg
, CalcCommitHdl
) );
254 SetDate( nDateDay
, nDateMonth
, nDateYear
);
256 aNames
= GetLayoutPropertyNames();
257 aValues
= aLayoutItem
.GetProperties(aNames
);
258 aLayoutItem
.EnableNotification(aNames
);
259 pValues
= aValues
.getConstArray();
260 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
261 if(aValues
.getLength() == aNames
.getLength())
263 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
265 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
266 if(pValues
[nProp
].hasValue())
270 case SCDOCLAYOUTOPT_TABSTOP
:
271 // TabDistance in ScDocOptions is in twips
272 if (pValues
[nProp
] >>= nIntVal
)
273 SetTabDistance(o3tl::toTwips(nIntVal
, o3tl::Length::mm100
));
279 aLayoutItem
.SetCommitLink( LINK( this, ScDocCfg
, LayoutCommitHdl
) );
282 IMPL_LINK_NOARG(ScDocCfg
, CalcCommitHdl
, ScLinkConfigItem
&, void)
284 Sequence
<OUString
> aNames
= GetCalcPropertyNames();
285 Sequence
<Any
> aValues(aNames
.getLength());
286 Any
* pValues
= aValues
.getArray();
288 sal_uInt16 nDateDay
, nDateMonth
;
290 GetDate( nDateDay
, nDateMonth
, nDateYear
);
292 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
296 case SCCALCOPT_ITER_ITER
:
297 pValues
[nProp
] <<= IsIter();
299 case SCCALCOPT_ITER_STEPS
:
300 pValues
[nProp
] <<= static_cast<sal_Int32
>(GetIterCount());
302 case SCCALCOPT_ITER_MINCHG
:
303 pValues
[nProp
] <<= GetIterEps();
305 case SCCALCOPT_DATE_DAY
:
306 pValues
[nProp
] <<= static_cast<sal_Int32
>(nDateDay
);
308 case SCCALCOPT_DATE_MONTH
:
309 pValues
[nProp
] <<= static_cast<sal_Int32
>(nDateMonth
);
311 case SCCALCOPT_DATE_YEAR
:
312 pValues
[nProp
] <<= static_cast<sal_Int32
>(nDateYear
);
314 case SCCALCOPT_DECIMALS
:
315 pValues
[nProp
] <<= static_cast<sal_Int32
>(GetStdPrecision());
317 case SCCALCOPT_CASESENSITIVE
:
318 // content is reversed
319 pValues
[nProp
] <<= !IsIgnoreCase();
321 case SCCALCOPT_PRECISION
:
322 pValues
[nProp
] <<= IsCalcAsShown();
324 case SCCALCOPT_SEARCHCRIT
:
325 pValues
[nProp
] <<= IsMatchWholeCell();
327 case SCCALCOPT_FINDLABEL
:
328 pValues
[nProp
] <<= IsLookUpColRowNames();
330 case SCCALCOPT_REGEX
:
331 pValues
[nProp
] <<= IsFormulaRegexEnabled();
333 case SCCALCOPT_WILDCARDS
:
334 pValues
[nProp
] <<= IsFormulaWildcardsEnabled();
338 aCalcItem
.PutProperties(aNames
, aValues
);
341 IMPL_LINK_NOARG(ScDocCfg
, LayoutCommitHdl
, ScLinkConfigItem
&, void)
343 Sequence
<OUString
> aNames
= GetLayoutPropertyNames();
344 Sequence
<Any
> aValues(aNames
.getLength());
345 Any
* pValues
= aValues
.getArray();
347 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
351 case SCDOCLAYOUTOPT_TABSTOP
:
352 // TabDistance in ScDocOptions is in twips
353 // use only even numbers, so defaults don't get changed
354 // by modifying other settings in the same config item
355 pValues
[nProp
] <<= static_cast<sal_Int32
>(TwipsToEvenHMM( GetTabDistance() ));
359 aLayoutItem
.PutProperties(aNames
, aValues
);
362 void ScDocCfg::SetOptions( const ScDocOptions
& rNew
)
364 *static_cast<ScDocOptions
*>(this) = rNew
;
366 aCalcItem
.SetModified();
367 aLayoutItem
.SetModified();
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */