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