LibreOffice Module sc (master) 1
docoptio.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 <svl/numformat.hxx>
21#include <osl/diagnose.h>
22
23#include <com/sun/star/uno/Any.hxx>
24#include <com/sun/star/uno/Sequence.hxx>
25
26#include <docoptio.hxx>
27#include <miscuno.hxx>
28#include <global.hxx>
29
30using namespace utl;
31using namespace com::sun::star::uno;
32
33
35
36static sal_uInt16 lcl_GetDefaultTabDist()
37{
39 return 709; // 1,25 cm
40 else
41 return 720; // 1/2"
42}
43
44// ScDocOptions - document options
45
47{
49}
50
52{
53 bIsIgnoreCase = false;
54 bIsIter = false;
55 nIterCount = 100;
56 fIterEps = 1.0E-3;
58 nDay = 30;
59 nMonth = 12;
60 nYear = 1899;
63 bCalcAsShown = false;
64 bMatchWholeCell = true;
65 bDoAutoSpell = false;
66 bLookUpColRowNames = true;
70 bWriteCalcConfig = true;
71}
72
74{
75 if (bVal)
76 {
80 }
81 else if (!bFormulaRegexEnabled)
82 ; // nothing changes for setting false to false
83 else
84 {
87 }
88}
89
91{
92 if (bVal)
93 {
97 }
99 ; // nothing changes for setting false to false
100 else
101 {
104 }
105}
106
107// ScTpCalcItem - data for the CalcOptions TabPage
108
109ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP, const ScDocOptions& rOpt )
110 : SfxPoolItem ( nWhichP ),
111 theOptions ( rOpt )
112{
113}
114
116{
117}
118
119bool ScTpCalcItem::operator==( const SfxPoolItem& rItem ) const
120{
121 assert(SfxPoolItem::operator==(rItem));
122
123 const ScTpCalcItem& rPItem = static_cast<const ScTpCalcItem&>(rItem);
124
125 return ( theOptions == rPItem.theOptions );
126}
127
129{
130 return new ScTpCalcItem( *this );
131}
132
133// Config Item containing document options
134
135constexpr OUStringLiteral CFGPATH_CALC = u"Office.Calc/Calculate";
136
137#define SCCALCOPT_ITER_ITER 0
138#define SCCALCOPT_ITER_STEPS 1
139#define SCCALCOPT_ITER_MINCHG 2
140#define SCCALCOPT_DATE_DAY 3
141#define SCCALCOPT_DATE_MONTH 4
142#define SCCALCOPT_DATE_YEAR 5
143#define SCCALCOPT_DECIMALS 6
144#define SCCALCOPT_CASESENSITIVE 7
145#define SCCALCOPT_PRECISION 8
146#define SCCALCOPT_SEARCHCRIT 9
147#define SCCALCOPT_FINDLABEL 10
148#define SCCALCOPT_REGEX 11
149#define SCCALCOPT_WILDCARDS 12
150
151constexpr OUStringLiteral CFGPATH_DOCLAYOUT = u"Office.Calc/Layout/Other";
152
153#define SCDOCLAYOUTOPT_TABSTOP 0
154
156{
157 return {"IterativeReference/Iteration", // SCCALCOPT_ITER_ITER
158 "IterativeReference/Steps", // SCCALCOPT_ITER_STEPS
159 "IterativeReference/MinimumChange", // SCCALCOPT_ITER_MINCHG
160 "Other/Date/DD", // SCCALCOPT_DATE_DAY
161 "Other/Date/MM", // SCCALCOPT_DATE_MONTH
162 "Other/Date/YY", // SCCALCOPT_DATE_YEAR
163 "Other/DecimalPlaces", // SCCALCOPT_DECIMALS
164 "Other/CaseSensitive", // SCCALCOPT_CASESENSITIVE
165 "Other/Precision", // SCCALCOPT_PRECISION
166 "Other/SearchCriteria", // SCCALCOPT_SEARCHCRIT
167 "Other/FindLabel", // SCCALCOPT_FINDLABEL
168 "Other/RegularExpressions", // SCCALCOPT_REGEX
169 "Other/Wildcards"}; // SCCALCOPT_WILDCARDS
170}
171
173{
175 return {"TabStop/Metric"}; // SCDOCLAYOUTOPT_TABSTOP
176 else
177 return {"TabStop/NonMetric"}; // SCDOCLAYOUTOPT_TABSTOP
178}
179
181 aCalcItem( CFGPATH_CALC ),
182 aLayoutItem(CFGPATH_DOCLAYOUT)
183{
184 sal_Int32 nIntVal = 0;
185
186 Sequence<OUString> aNames;
187 Sequence<Any> aValues;
188 const Any* pValues = nullptr;
189
190 sal_uInt16 nDateDay, nDateMonth;
191 sal_Int16 nDateYear;
192 GetDate( nDateDay, nDateMonth, nDateYear );
193
194 aNames = GetCalcPropertyNames();
195 aValues = aCalcItem.GetProperties(aNames);
197 pValues = aValues.getConstArray();
198 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
199 if(aValues.getLength() == aNames.getLength())
200 {
201 double fDoubleVal = 0;
202 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
203 {
204 OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
205 if(pValues[nProp].hasValue())
206 {
207 switch(nProp)
208 {
211 break;
213 if (pValues[nProp] >>= nIntVal) SetIterCount( static_cast<sal_uInt16>(nIntVal) );
214 break;
216 if (pValues[nProp] >>= fDoubleVal) SetIterEps( fDoubleVal );
217 break;
219 if (pValues[nProp] >>= nIntVal) nDateDay = static_cast<sal_uInt16>(nIntVal);
220 break;
222 if (pValues[nProp] >>= nIntVal) nDateMonth = static_cast<sal_uInt16>(nIntVal);
223 break;
225 if (pValues[nProp] >>= nIntVal) nDateYear = static_cast<sal_Int16>(nIntVal);
226 break;
228 if (pValues[nProp] >>= nIntVal) SetStdPrecision( static_cast<sal_uInt16>(nIntVal) );
229 break;
231 // content is reversed
233 break;
236 break;
239 break;
242 break;
243 case SCCALCOPT_REGEX :
245 break;
248 break;
249 }
250 }
251 }
252 }
253 aCalcItem.SetCommitLink( LINK( this, ScDocCfg, CalcCommitHdl ) );
254
255 SetDate( nDateDay, nDateMonth, nDateYear );
256
257 aNames = GetLayoutPropertyNames();
258 aValues = aLayoutItem.GetProperties(aNames);
260 pValues = aValues.getConstArray();
261 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
262 if(aValues.getLength() == aNames.getLength())
263 {
264 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
265 {
266 OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
267 if(pValues[nProp].hasValue())
268 {
269 switch(nProp)
270 {
272 // TabDistance in ScDocOptions is in twips
273 if (pValues[nProp] >>= nIntVal)
275 break;
276 }
277 }
278 }
279 }
280 aLayoutItem.SetCommitLink( LINK( this, ScDocCfg, LayoutCommitHdl ) );
281}
282
284{
285 Sequence<OUString> aNames = GetCalcPropertyNames();
286 Sequence<Any> aValues(aNames.getLength());
287 Any* pValues = aValues.getArray();
288
289 sal_uInt16 nDateDay, nDateMonth;
290 sal_Int16 nDateYear;
291 GetDate( nDateDay, nDateMonth, nDateYear );
292
293 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
294 {
295 switch(nProp)
296 {
298 pValues[nProp] <<= IsIter();
299 break;
301 pValues[nProp] <<= static_cast<sal_Int32>(GetIterCount());
302 break;
304 pValues[nProp] <<= GetIterEps();
305 break;
307 pValues[nProp] <<= static_cast<sal_Int32>(nDateDay);
308 break;
310 pValues[nProp] <<= static_cast<sal_Int32>(nDateMonth);
311 break;
313 pValues[nProp] <<= static_cast<sal_Int32>(nDateYear);
314 break;
316 pValues[nProp] <<= static_cast<sal_Int32>(GetStdPrecision());
317 break;
319 // content is reversed
320 pValues[nProp] <<= !IsIgnoreCase();
321 break;
323 pValues[nProp] <<= IsCalcAsShown();
324 break;
326 pValues[nProp] <<= IsMatchWholeCell();
327 break;
329 pValues[nProp] <<= IsLookUpColRowNames();
330 break;
331 case SCCALCOPT_REGEX :
332 pValues[nProp] <<= IsFormulaRegexEnabled();
333 break;
335 pValues[nProp] <<= IsFormulaWildcardsEnabled();
336 break;
337 }
338 }
339 aCalcItem.PutProperties(aNames, aValues);
340}
341
343{
344 Sequence<OUString> aNames = GetLayoutPropertyNames();
345 Sequence<Any> aValues(aNames.getLength());
346 Any* pValues = aValues.getArray();
347
348 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
349 {
350 switch(nProp)
351 {
353 // TabDistance in ScDocOptions is in twips
354 // use only even numbers, so defaults don't get changed
355 // by modifying other settings in the same config item
356 pValues[nProp] <<= static_cast<sal_Int32>(TwipsToEvenHMM( GetTabDistance() ));
357 break;
358 }
359 }
360 aLayoutItem.PutProperties(aNames, aValues);
361}
362
364{
365 *static_cast<ScDocOptions*>(this) = rNew;
366
369}
370
371/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
ScLinkConfigItem aCalcItem
Definition: docoptio.hxx:160
static css::uno::Sequence< OUString > GetCalcPropertyNames()
Definition: docoptio.cxx:155
static css::uno::Sequence< OUString > GetLayoutPropertyNames()
Definition: docoptio.cxx:172
ScLinkConfigItem aLayoutItem
Definition: docoptio.hxx:161
void SetOptions(const ScDocOptions &rNew)
Definition: docoptio.cxx:363
bool bWriteCalcConfig
(subset of) Calc config will be written to user's profile
Definition: docoptio.hxx:46
sal_uInt16 nIterCount
number
Definition: docoptio.hxx:30
bool bMatchWholeCell
search criteria must match the whole cell
Definition: docoptio.hxx:41
void GetDate(sal_uInt16 &rD, sal_uInt16 &rM, sal_Int16 &rY) const
Definition: docoptio.hxx:66
bool bIsIter
iterations for circular refs
Definition: docoptio.hxx:39
bool bDoAutoSpell
auto-spelling
Definition: docoptio.hxx:42
utl::SearchParam::SearchType eFormulaSearchType
wildcards or regular expressions or normal search
Definition: docoptio.hxx:37
void SetTabDistance(sal_uInt16 nTabDist)
Definition: docoptio.hxx:71
void SetFormulaRegexEnabled(bool bVal)
Definition: docoptio.cxx:73
sal_uInt16 nMonth
Definition: docoptio.hxx:33
bool bCalcAsShown
calculate as shown (wrt precision)
Definition: docoptio.hxx:40
void SetCalcAsShown(bool bVal)
Definition: docoptio.hxx:82
sal_uInt16 nYear2000
earlier 19YY is assumed, 20YY otherwise (if only YY of year is given)
Definition: docoptio.hxx:35
bool bFormulaRegexEnabled
regular expressions in formulas enabled, only when reading settings
Definition: docoptio.hxx:44
void SetIgnoreCase(bool bVal)
Definition: docoptio.hxx:58
void SetLookUpColRowNames(bool bVal)
Definition: docoptio.hxx:52
void SetIter(bool bVal)
Definition: docoptio.hxx:60
double fIterEps
Definition: docoptio.hxx:29
bool bIsIgnoreCase
ignore case for comparisons?
Definition: docoptio.hxx:38
void SetFormulaWildcardsEnabled(bool bVal)
Definition: docoptio.cxx:90
void SetIterEps(double fEps)
Definition: docoptio.hxx:64
bool bFormulaWildcardsEnabled
wildcards in formulas enabled, only when reading settings
Definition: docoptio.hxx:45
void SetMatchWholeCell(bool bVal)
Definition: docoptio.hxx:56
void SetStdPrecision(sal_uInt16 n)
Definition: docoptio.hxx:79
void ResetDocOptions()
Definition: docoptio.cxx:51
void SetDate(sal_uInt16 nD, sal_uInt16 nM, sal_Int16 nY)
Definition: docoptio.hxx:68
bool bLookUpColRowNames
determine column-/row titles automagically
Definition: docoptio.hxx:43
sal_uInt16 nYear
Definition: docoptio.hxx:34
sal_uInt16 nTabDistance
distance of standard tabs
Definition: docoptio.hxx:36
sal_uInt16 nDay
Null date:
Definition: docoptio.hxx:32
void SetIterCount(sal_uInt16 nCount)
Definition: docoptio.hxx:62
sal_uInt16 nPrecStandardFormat
precision for standard format
Definition: docoptio.hxx:31
void SetCommitLink(const Link< ScLinkConfigItem &, void > &rLink)
Definition: optutil.cxx:47
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
Definition: optutil.hxx:53
static bool IsMetricSystem()
Definition: optutil.cxx:25
virtual ~ScTpCalcItem() override
Definition: docoptio.cxx:115
virtual bool operator==(const SfxPoolItem &) const override
Definition: docoptio.cxx:119
virtual ScTpCalcItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: docoptio.cxx:128
ScTpCalcItem(sal_uInt16 nWhich, const ScDocOptions &rOpt)
Definition: docoptio.cxx:109
ScDocOptions theOptions
Definition: docoptio.hxx:153
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:139
static sal_uInt16 GetYear2000Default()
static const sal_uInt16 UNLIMITED_PRECISION
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
#define SCCALCOPT_ITER_MINCHG
Definition: docoptio.cxx:139
#define SCCALCOPT_FINDLABEL
Definition: docoptio.cxx:147
static sal_uInt16 lcl_GetDefaultTabDist()
Definition: docoptio.cxx:36
#define SCCALCOPT_CASESENSITIVE
Definition: docoptio.cxx:144
#define SCDOCLAYOUTOPT_TABSTOP
Definition: docoptio.cxx:153
#define SCCALCOPT_DATE_MONTH
Definition: docoptio.cxx:141
constexpr OUStringLiteral CFGPATH_DOCLAYOUT
Definition: docoptio.cxx:151
#define SCCALCOPT_PRECISION
Definition: docoptio.cxx:145
#define SCCALCOPT_DECIMALS
Definition: docoptio.cxx:143
#define SCCALCOPT_ITER_ITER
Definition: docoptio.cxx:137
IMPL_LINK_NOARG(ScDocCfg, CalcCommitHdl, ScLinkConfigItem &, void)
Definition: docoptio.cxx:283
#define SCCALCOPT_DATE_YEAR
Definition: docoptio.cxx:142
#define SCCALCOPT_REGEX
Definition: docoptio.cxx:148
constexpr OUStringLiteral CFGPATH_CALC
Definition: docoptio.cxx:135
#define SCCALCOPT_ITER_STEPS
Definition: docoptio.cxx:138
#define SCCALCOPT_WILDCARDS
Definition: docoptio.cxx:149
#define SCCALCOPT_DATE_DAY
Definition: docoptio.cxx:140
#define SCCALCOPT_SEARCHCRIT
Definition: docoptio.cxx:146
float u
constexpr auto toTwips(N number, Length from)
constexpr ::tools::Long TwipsToEvenHMM(::tools::Long nTwips)
Definition: global.hxx:100