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