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 <svl/zforlist.hxx>
22 #include <tools/UnitConversion.hxx>
23 #include <osl/diagnose.h>
24 
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 
28 #include <docoptio.hxx>
29 #include <miscuno.hxx>
30 #include <global.hxx>
31 
32 using namespace utl;
33 using namespace com::sun::star::uno;
34 
35 
36 using sc::TwipsToEvenHMM;
37 
38 static sal_uInt16 lcl_GetDefaultTabDist()
39 {
41  return 709; // 1,25 cm
42  else
43  return 720; // 1/2"
44 }
45 
46 // ScDocOptions - document options
47 
49 {
50  ResetDocOptions();
51 }
52 
54 {
55  bIsIgnoreCase = false;
56  bIsIter = false;
57  nIterCount = 100;
58  fIterEps = 1.0E-3;
59  nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
60  nDay = 30;
61  nMonth = 12;
62  nYear = 1899;
64  nTabDistance = lcl_GetDefaultTabDist();
65  bCalcAsShown = false;
66  bMatchWholeCell = true;
67  bDoAutoSpell = false;
68  bLookUpColRowNames = true;
69  bFormulaRegexEnabled= false;
70  bFormulaWildcardsEnabled= true;
71  eFormulaSearchType = utl::SearchParam::SearchType::Wildcard;
72  bWriteCalcConfig = true;
73 }
74 
76 {
77  if (bVal)
78  {
79  bFormulaRegexEnabled = true;
80  bFormulaWildcardsEnabled = false;
81  eFormulaSearchType = utl::SearchParam::SearchType::Regexp;
82  }
83  else if (!bFormulaRegexEnabled)
84  ; // nothing changes for setting false to false
85  else
86  {
87  bFormulaRegexEnabled = false;
88  eFormulaSearchType = utl::SearchParam::SearchType::Unknown;
89  }
90 }
91 
93 {
94  if (bVal)
95  {
96  bFormulaRegexEnabled = false;
97  bFormulaWildcardsEnabled = true;
98  eFormulaSearchType = utl::SearchParam::SearchType::Wildcard;
99  }
100  else if (!bFormulaWildcardsEnabled)
101  ; // nothing changes for setting false to false
102  else
103  {
104  bFormulaWildcardsEnabled = false;
105  eFormulaSearchType = utl::SearchParam::SearchType::Unknown;
106  }
107 }
108 
109 // ScTpCalcItem - data for the CalcOptions TabPage
110 
111 ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP, const ScDocOptions& rOpt )
112  : SfxPoolItem ( nWhichP ),
113  theOptions ( rOpt )
114 {
115 }
116 
118 {
119 }
120 
121 bool ScTpCalcItem::operator==( const SfxPoolItem& rItem ) const
122 {
123  assert(SfxPoolItem::operator==(rItem));
124 
125  const ScTpCalcItem& rPItem = static_cast<const ScTpCalcItem&>(rItem);
126 
127  return ( theOptions == rPItem.theOptions );
128 }
129 
131 {
132  return new ScTpCalcItem( *this );
133 }
134 
135 // Config Item containing document options
136 
137 constexpr OUStringLiteral CFGPATH_CALC = u"Office.Calc/Calculate";
138 
139 #define SCCALCOPT_ITER_ITER 0
140 #define SCCALCOPT_ITER_STEPS 1
141 #define SCCALCOPT_ITER_MINCHG 2
142 #define SCCALCOPT_DATE_DAY 3
143 #define SCCALCOPT_DATE_MONTH 4
144 #define SCCALCOPT_DATE_YEAR 5
145 #define SCCALCOPT_DECIMALS 6
146 #define SCCALCOPT_CASESENSITIVE 7
147 #define SCCALCOPT_PRECISION 8
148 #define SCCALCOPT_SEARCHCRIT 9
149 #define SCCALCOPT_FINDLABEL 10
150 #define SCCALCOPT_REGEX 11
151 #define SCCALCOPT_WILDCARDS 12
152 
153 constexpr OUStringLiteral CFGPATH_DOCLAYOUT = u"Office.Calc/Layout/Other";
154 
155 #define SCDOCLAYOUTOPT_TABSTOP 0
156 
158 {
159  return {"IterativeReference/Iteration", // SCCALCOPT_ITER_ITER
160  "IterativeReference/Steps", // SCCALCOPT_ITER_STEPS
161  "IterativeReference/MinimumChange", // SCCALCOPT_ITER_MINCHG
162  "Other/Date/DD", // SCCALCOPT_DATE_DAY
163  "Other/Date/MM", // SCCALCOPT_DATE_MONTH
164  "Other/Date/YY", // SCCALCOPT_DATE_YEAR
165  "Other/DecimalPlaces", // SCCALCOPT_DECIMALS
166  "Other/CaseSensitive", // SCCALCOPT_CASESENSITIVE
167  "Other/Precision", // SCCALCOPT_PRECISION
168  "Other/SearchCriteria", // SCCALCOPT_SEARCHCRIT
169  "Other/FindLabel", // SCCALCOPT_FINDLABEL
170  "Other/RegularExpressions", // SCCALCOPT_REGEX
171  "Other/Wildcards"}; // SCCALCOPT_WILDCARDS
172 }
173 
175 {
177  return {"TabStop/Metric"}; // SCDOCLAYOUTOPT_TABSTOP
178  else
179  return {"TabStop/NonMetric"}; // SCDOCLAYOUTOPT_TABSTOP
180 }
181 
183  aCalcItem( CFGPATH_CALC ),
184  aLayoutItem(CFGPATH_DOCLAYOUT)
185 {
186  sal_Int32 nIntVal = 0;
187 
188  Sequence<OUString> aNames;
189  Sequence<Any> aValues;
190  const Any* pValues = nullptr;
191 
192  sal_uInt16 nDateDay, nDateMonth;
193  sal_Int16 nDateYear;
194  GetDate( nDateDay, nDateMonth, nDateYear );
195 
196  aNames = GetCalcPropertyNames();
197  aValues = aCalcItem.GetProperties(aNames);
199  pValues = aValues.getConstArray();
200  OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
201  if(aValues.getLength() == aNames.getLength())
202  {
203  double fDoubleVal = 0;
204  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
205  {
206  OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
207  if(pValues[nProp].hasValue())
208  {
209  switch(nProp)
210  {
211  case SCCALCOPT_ITER_ITER:
212  SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
213  break;
215  if (pValues[nProp] >>= nIntVal) SetIterCount( static_cast<sal_uInt16>(nIntVal) );
216  break;
218  if (pValues[nProp] >>= fDoubleVal) SetIterEps( fDoubleVal );
219  break;
220  case SCCALCOPT_DATE_DAY:
221  if (pValues[nProp] >>= nIntVal) nDateDay = static_cast<sal_uInt16>(nIntVal);
222  break;
224  if (pValues[nProp] >>= nIntVal) nDateMonth = static_cast<sal_uInt16>(nIntVal);
225  break;
226  case SCCALCOPT_DATE_YEAR:
227  if (pValues[nProp] >>= nIntVal) nDateYear = static_cast<sal_Int16>(nIntVal);
228  break;
229  case SCCALCOPT_DECIMALS:
230  if (pValues[nProp] >>= nIntVal) SetStdPrecision( static_cast<sal_uInt16>(nIntVal) );
231  break;
233  // content is reversed
235  break;
236  case SCCALCOPT_PRECISION:
238  break;
241  break;
242  case SCCALCOPT_FINDLABEL:
244  break;
245  case SCCALCOPT_REGEX :
247  break;
248  case SCCALCOPT_WILDCARDS :
250  break;
251  }
252  }
253  }
254  }
255  aCalcItem.SetCommitLink( LINK( this, ScDocCfg, CalcCommitHdl ) );
256 
257  SetDate( nDateDay, nDateMonth, nDateYear );
258 
259  aNames = GetLayoutPropertyNames();
260  aValues = aLayoutItem.GetProperties(aNames);
262  pValues = aValues.getConstArray();
263  OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
264  if(aValues.getLength() == aNames.getLength())
265  {
266  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
267  {
268  OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
269  if(pValues[nProp].hasValue())
270  {
271  switch(nProp)
272  {
274  // TabDistance in ScDocOptions is in twips
275  if (pValues[nProp] >>= nIntVal)
277  break;
278  }
279  }
280  }
281  }
282  aLayoutItem.SetCommitLink( LINK( this, ScDocCfg, LayoutCommitHdl ) );
283 }
284 
286 {
287  Sequence<OUString> aNames = GetCalcPropertyNames();
288  Sequence<Any> aValues(aNames.getLength());
289  Any* pValues = aValues.getArray();
290 
291  sal_uInt16 nDateDay, nDateMonth;
292  sal_Int16 nDateYear;
293  GetDate( nDateDay, nDateMonth, nDateYear );
294 
295  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
296  {
297  switch(nProp)
298  {
299  case SCCALCOPT_ITER_ITER:
300  pValues[nProp] <<= IsIter();
301  break;
303  pValues[nProp] <<= static_cast<sal_Int32>(GetIterCount());
304  break;
306  pValues[nProp] <<= GetIterEps();
307  break;
308  case SCCALCOPT_DATE_DAY:
309  pValues[nProp] <<= static_cast<sal_Int32>(nDateDay);
310  break;
312  pValues[nProp] <<= static_cast<sal_Int32>(nDateMonth);
313  break;
314  case SCCALCOPT_DATE_YEAR:
315  pValues[nProp] <<= static_cast<sal_Int32>(nDateYear);
316  break;
317  case SCCALCOPT_DECIMALS:
318  pValues[nProp] <<= static_cast<sal_Int32>(GetStdPrecision());
319  break;
321  // content is reversed
322  pValues[nProp] <<= !IsIgnoreCase();
323  break;
324  case SCCALCOPT_PRECISION:
325  pValues[nProp] <<= IsCalcAsShown();
326  break;
328  pValues[nProp] <<= IsMatchWholeCell();
329  break;
330  case SCCALCOPT_FINDLABEL:
331  pValues[nProp] <<= IsLookUpColRowNames();
332  break;
333  case SCCALCOPT_REGEX :
334  pValues[nProp] <<= IsFormulaRegexEnabled();
335  break;
336  case SCCALCOPT_WILDCARDS :
337  pValues[nProp] <<= IsFormulaWildcardsEnabled();
338  break;
339  }
340  }
341  aCalcItem.PutProperties(aNames, aValues);
342 }
343 
344 IMPL_LINK_NOARG(ScDocCfg, LayoutCommitHdl, ScLinkConfigItem&, void)
345 {
346  Sequence<OUString> aNames = GetLayoutPropertyNames();
347  Sequence<Any> aValues(aNames.getLength());
348  Any* pValues = aValues.getArray();
349 
350  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
351  {
352  switch(nProp)
353  {
355  // TabDistance in ScDocOptions is in twips
356  // use only even numbers, so defaults don't get changed
357  // by modifying other settings in the same config item
358  pValues[nProp] <<= static_cast<sal_Int32>(TwipsToEvenHMM( GetTabDistance() ));
359  break;
360  }
361  }
362  aLayoutItem.PutProperties(aNames, aValues);
363 }
364 
366 {
367  *static_cast<ScDocOptions*>(this) = rNew;
368 
371 }
372 
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScTpCalcItem(sal_uInt16 nWhich, const ScDocOptions &rOpt)
Definition: docoptio.cxx:111
#define SCCALCOPT_FINDLABEL
Definition: docoptio.cxx:149
constexpr auto toTwips(N number, Length from)
virtual bool operator==(const SfxPoolItem &) const override
Definition: docoptio.cxx:121
virtual ~ScTpCalcItem() override
Definition: docoptio.cxx:117
void SetFormulaWildcardsEnabled(bool bVal)
Definition: docoptio.cxx:92
void SetOptions(const ScDocOptions &rNew)
Definition: docoptio.cxx:365
void SetTabDistance(sal_uInt16 nTabDist)
Definition: docoptio.hxx:71
IMPL_LINK_NOARG(ScDocCfg, CalcCommitHdl, ScLinkConfigItem &, void)
Definition: docoptio.cxx:285
void SetCommitLink(const Link< ScLinkConfigItem &, void > &rLink)
Definition: optutil.cxx:47
#define SCCALCOPT_PRECISION
Definition: docoptio.cxx:147
#define SCCALCOPT_ITER_MINCHG
Definition: docoptio.cxx:141
#define SCCALCOPT_CASESENSITIVE
Definition: docoptio.cxx:146
#define SCCALCOPT_DATE_YEAR
Definition: docoptio.cxx:144
static css::uno::Sequence< OUString > GetCalcPropertyNames()
Definition: docoptio.cxx:157
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:140
static css::uno::Sequence< OUString > GetLayoutPropertyNames()
Definition: docoptio.cxx:174
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:130
ScLinkConfigItem aCalcItem
Definition: docoptio.hxx:160
#define SCCALCOPT_DATE_DAY
Definition: docoptio.cxx:142
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
#define SCCALCOPT_DECIMALS
Definition: docoptio.cxx:145
#define SCCALCOPT_ITER_ITER
Definition: docoptio.cxx:139
static const sal_uInt16 UNLIMITED_PRECISION
#define SCCALCOPT_SEARCHCRIT
Definition: docoptio.cxx:148
void SetStdPrecision(sal_uInt16 n)
Definition: docoptio.hxx:79
static sal_uInt16 lcl_GetDefaultTabDist()
Definition: docoptio.cxx:38
const PropertyValue * pValues
void ResetDocOptions()
Definition: docoptio.cxx:53
#define SCCALCOPT_DATE_MONTH
Definition: docoptio.cxx:143
void SetMatchWholeCell(bool bVal)
Definition: docoptio.hxx:56
inline::tools::Long TwipsToEvenHMM(::tools::Long nTwips)
Definition: global.hxx:110
#define SCDOCLAYOUTOPT_TABSTOP
Definition: docoptio.cxx:155
constexpr OUStringLiteral CFGPATH_CALC
Definition: docoptio.cxx:137
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:75
#define SCCALCOPT_WILDCARDS
Definition: docoptio.cxx:151
ScDocOptions theOptions
Definition: docoptio.hxx:153
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
Definition: optutil.hxx:51
void GetDate(sal_uInt16 &rD, sal_uInt16 &rM, sal_Int16 &rY) const
Definition: docoptio.hxx:66
constexpr OUStringLiteral CFGPATH_DOCLAYOUT
Definition: docoptio.cxx:153
#define SCCALCOPT_REGEX
Definition: docoptio.cxx:150
void SetIterEps(double fEps)
Definition: docoptio.hxx:64