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 
30 using namespace utl;
31 using namespace com::sun::star::uno;
32 
33 
34 using sc::TwipsToEvenHMM;
35 
36 static 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 {
48  ResetDocOptions();
49 }
50 
52 {
53  bIsIgnoreCase = false;
54  bIsIter = false;
55  nIterCount = 100;
56  fIterEps = 1.0E-3;
57  nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
58  nDay = 30;
59  nMonth = 12;
60  nYear = 1899;
62  nTabDistance = lcl_GetDefaultTabDist();
63  bCalcAsShown = false;
64  bMatchWholeCell = true;
65  bDoAutoSpell = false;
66  bLookUpColRowNames = true;
67  bFormulaRegexEnabled= false;
68  bFormulaWildcardsEnabled= true;
69  eFormulaSearchType = utl::SearchParam::SearchType::Wildcard;
70  bWriteCalcConfig = true;
71 }
72 
74 {
75  if (bVal)
76  {
77  bFormulaRegexEnabled = true;
78  bFormulaWildcardsEnabled = false;
79  eFormulaSearchType = utl::SearchParam::SearchType::Regexp;
80  }
81  else if (!bFormulaRegexEnabled)
82  ; // nothing changes for setting false to false
83  else
84  {
85  bFormulaRegexEnabled = false;
86  eFormulaSearchType = utl::SearchParam::SearchType::Unknown;
87  }
88 }
89 
91 {
92  if (bVal)
93  {
94  bFormulaRegexEnabled = false;
95  bFormulaWildcardsEnabled = true;
96  eFormulaSearchType = utl::SearchParam::SearchType::Wildcard;
97  }
98  else if (!bFormulaWildcardsEnabled)
99  ; // nothing changes for setting false to false
100  else
101  {
102  bFormulaWildcardsEnabled = false;
103  eFormulaSearchType = utl::SearchParam::SearchType::Unknown;
104  }
105 }
106 
107 // ScTpCalcItem - data for the CalcOptions TabPage
108 
109 ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP, const ScDocOptions& rOpt )
110  : SfxPoolItem ( nWhichP ),
111  theOptions ( rOpt )
112 {
113 }
114 
116 {
117 }
118 
119 bool 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 
135 constexpr 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 
151 constexpr 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  {
209  case SCCALCOPT_ITER_ITER:
210  SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
211  break;
213  if (pValues[nProp] >>= nIntVal) SetIterCount( static_cast<sal_uInt16>(nIntVal) );
214  break;
216  if (pValues[nProp] >>= fDoubleVal) SetIterEps( fDoubleVal );
217  break;
218  case SCCALCOPT_DATE_DAY:
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;
224  case SCCALCOPT_DATE_YEAR:
225  if (pValues[nProp] >>= nIntVal) nDateYear = static_cast<sal_Int16>(nIntVal);
226  break;
227  case SCCALCOPT_DECIMALS:
228  if (pValues[nProp] >>= nIntVal) SetStdPrecision( static_cast<sal_uInt16>(nIntVal) );
229  break;
231  // content is reversed
233  break;
234  case SCCALCOPT_PRECISION:
236  break;
239  break;
240  case SCCALCOPT_FINDLABEL:
242  break;
243  case SCCALCOPT_REGEX :
245  break;
246  case SCCALCOPT_WILDCARDS :
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  {
297  case SCCALCOPT_ITER_ITER:
298  pValues[nProp] <<= IsIter();
299  break;
301  pValues[nProp] <<= static_cast<sal_Int32>(GetIterCount());
302  break;
304  pValues[nProp] <<= GetIterEps();
305  break;
306  case SCCALCOPT_DATE_DAY:
307  pValues[nProp] <<= static_cast<sal_Int32>(nDateDay);
308  break;
310  pValues[nProp] <<= static_cast<sal_Int32>(nDateMonth);
311  break;
312  case SCCALCOPT_DATE_YEAR:
313  pValues[nProp] <<= static_cast<sal_Int32>(nDateYear);
314  break;
315  case SCCALCOPT_DECIMALS:
316  pValues[nProp] <<= static_cast<sal_Int32>(GetStdPrecision());
317  break;
319  // content is reversed
320  pValues[nProp] <<= !IsIgnoreCase();
321  break;
322  case SCCALCOPT_PRECISION:
323  pValues[nProp] <<= IsCalcAsShown();
324  break;
326  pValues[nProp] <<= IsMatchWholeCell();
327  break;
328  case SCCALCOPT_FINDLABEL:
329  pValues[nProp] <<= IsLookUpColRowNames();
330  break;
331  case SCCALCOPT_REGEX :
332  pValues[nProp] <<= IsFormulaRegexEnabled();
333  break;
334  case SCCALCOPT_WILDCARDS :
335  pValues[nProp] <<= IsFormulaWildcardsEnabled();
336  break;
337  }
338  }
339  aCalcItem.PutProperties(aNames, aValues);
340 }
341 
342 IMPL_LINK_NOARG(ScDocCfg, LayoutCommitHdl, ScLinkConfigItem&, void)
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: */
ScTpCalcItem(sal_uInt16 nWhich, const ScDocOptions &rOpt)
Definition: docoptio.cxx:109
#define SCCALCOPT_FINDLABEL
Definition: docoptio.cxx:147
constexpr auto toTwips(N number, Length from)
virtual bool operator==(const SfxPoolItem &) const override
Definition: docoptio.cxx:119
virtual ~ScTpCalcItem() override
Definition: docoptio.cxx:115
void SetFormulaWildcardsEnabled(bool bVal)
Definition: docoptio.cxx:90
void SetOptions(const ScDocOptions &rNew)
Definition: docoptio.cxx:363
void SetTabDistance(sal_uInt16 nTabDist)
Definition: docoptio.hxx:71
IMPL_LINK_NOARG(ScDocCfg, CalcCommitHdl, ScLinkConfigItem &, void)
Definition: docoptio.cxx:283
void SetCommitLink(const Link< ScLinkConfigItem &, void > &rLink)
Definition: optutil.cxx:47
#define SCCALCOPT_PRECISION
Definition: docoptio.cxx:145
#define SCCALCOPT_ITER_MINCHG
Definition: docoptio.cxx:139
#define SCCALCOPT_CASESENSITIVE
Definition: docoptio.cxx:144
#define SCCALCOPT_DATE_YEAR
Definition: docoptio.cxx:142
static css::uno::Sequence< OUString > GetCalcPropertyNames()
Definition: docoptio.cxx:155
static bool IsMetricSystem()
Definition: optutil.cxx:25
void SetLookUpColRowNames(bool bVal)
Definition: docoptio.hxx:52
void SetIgnoreCase(bool bVal)
Definition: docoptio.hxx:58
#define SCCALCOPT_ITER_STEPS
Definition: docoptio.cxx:138
static css::uno::Sequence< OUString > GetLayoutPropertyNames()
Definition: docoptio.cxx:172
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
void SetCalcAsShown(bool bVal)
Definition: docoptio.hxx:82
virtual ScTpCalcItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: docoptio.cxx:128
ScLinkConfigItem aCalcItem
Definition: docoptio.hxx:160
#define SCCALCOPT_DATE_DAY
Definition: docoptio.cxx:140
void SetIter(bool bVal)
Definition: docoptio.hxx:60
void SetDate(sal_uInt16 nD, sal_uInt16 nM, sal_Int16 nY)
Definition: docoptio.hxx:68
float u
static sal_uInt16 GetYear2000Default()
void SetIterCount(sal_uInt16 nCount)
Definition: docoptio.hxx:62
constexpr::tools::Long TwipsToEvenHMM(::tools::Long nTwips)
Definition: global.hxx:99
#define SCCALCOPT_DECIMALS
Definition: docoptio.cxx:143
#define SCCALCOPT_ITER_ITER
Definition: docoptio.cxx:137
static const sal_uInt16 UNLIMITED_PRECISION
#define SCCALCOPT_SEARCHCRIT
Definition: docoptio.cxx:146
void SetStdPrecision(sal_uInt16 n)
Definition: docoptio.hxx:79
static sal_uInt16 lcl_GetDefaultTabDist()
Definition: docoptio.cxx:36
const PropertyValue * pValues
void ResetDocOptions()
Definition: docoptio.cxx:51
#define SCCALCOPT_DATE_MONTH
Definition: docoptio.cxx:141
void SetMatchWholeCell(bool bVal)
Definition: docoptio.hxx:56
#define SCDOCLAYOUTOPT_TABSTOP
Definition: docoptio.cxx:153
constexpr OUStringLiteral CFGPATH_CALC
Definition: docoptio.cxx:135
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:138
ScLinkConfigItem aLayoutItem
Definition: docoptio.hxx:161
void SetFormulaRegexEnabled(bool bVal)
Definition: docoptio.cxx:73
#define SCCALCOPT_WILDCARDS
Definition: docoptio.cxx:149
ScDocOptions theOptions
Definition: docoptio.hxx:153
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
Definition: optutil.hxx:53
void GetDate(sal_uInt16 &rD, sal_uInt16 &rM, sal_Int16 &rY) const
Definition: docoptio.hxx:66
constexpr OUStringLiteral CFGPATH_DOCLAYOUT
Definition: docoptio.cxx:151
#define SCCALCOPT_REGEX
Definition: docoptio.cxx:148
void SetIterEps(double fEps)
Definition: docoptio.hxx:64