Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/svapp.hxx>
30 : : #include <svl/zforlist.hxx>
31 : :
32 : : #include <com/sun/star/uno/Any.hxx>
33 : : #include <com/sun/star/uno/Sequence.hxx>
34 : :
35 : : #include "cfgids.hxx"
36 : : #include "docoptio.hxx"
37 : : #include "rechead.hxx"
38 : : #include "scresid.hxx"
39 : : #include "sc.hrc"
40 : : #include "miscuno.hxx"
41 : : #include "global.hxx"
42 : : #include "globstr.hrc"
43 : :
44 : : using namespace utl;
45 : : using namespace com::sun::star::uno;
46 : : using ::rtl::OUString;
47 : :
48 : : //------------------------------------------------------------------------
49 : :
50 : : #define SC_VERSION ((sal_uInt16)251)
51 : :
52 [ # # ][ # # ]: 0 : TYPEINIT1(ScTpCalcItem, SfxPoolItem);
53 : :
54 : : //------------------------------------------------------------------------
55 : :
56 : : using sc::HMMToTwips;
57 : : using sc::TwipsToHMM;
58 : : using sc::TwipsToEvenHMM;
59 : :
60 : : //------------------------------------------------------------------------
61 : :
62 : 2678 : sal_uInt16 lcl_GetDefaultTabDist()
63 : : {
64 [ - + ]: 2678 : if ( ScOptionsUtil::IsMetricSystem() )
65 : 0 : return 709; // 1,25 cm
66 : : else
67 : 2678 : return 720; // 1/2"
68 : : }
69 : :
70 : : //========================================================================
71 : : // ScDocOptions - Dokument-Optionen
72 : : //========================================================================
73 : :
74 : 2678 : ScDocOptions::ScDocOptions()
75 : : {
76 : 2678 : ResetDocOptions();
77 : 2678 : }
78 : :
79 : : //------------------------------------------------------------------------
80 : :
81 : 2971 : ScDocOptions::ScDocOptions( const ScDocOptions& rCpy )
82 : : : fIterEps( rCpy.fIterEps ),
83 : : nIterCount( rCpy.nIterCount ),
84 : : nPrecStandardFormat( rCpy.nPrecStandardFormat ),
85 : : nDay( rCpy.nDay ),
86 : : nMonth( rCpy.nMonth ),
87 : : nYear( rCpy.nYear ),
88 : : nYear2000( rCpy.nYear2000 ),
89 : : nTabDistance( rCpy.nTabDistance ),
90 : : bIsIgnoreCase( rCpy.bIsIgnoreCase ),
91 : : bIsIter( rCpy.bIsIter ),
92 : : bCalcAsShown( rCpy.bCalcAsShown ),
93 : : bMatchWholeCell( rCpy.bMatchWholeCell ),
94 : : bDoAutoSpell( rCpy.bDoAutoSpell ),
95 : : bLookUpColRowNames( rCpy.bLookUpColRowNames ),
96 : 2971 : bFormulaRegexEnabled( rCpy.bFormulaRegexEnabled )
97 : : {
98 : 2971 : }
99 : :
100 : : //------------------------------------------------------------------------
101 : :
102 : 5295 : ScDocOptions::~ScDocOptions()
103 : : {
104 : 5295 : }
105 : :
106 : : //------------------------------------------------------------------------
107 : :
108 : 2678 : void ScDocOptions::ResetDocOptions()
109 : : {
110 : 2678 : bIsIgnoreCase = false;
111 : 2678 : bIsIter = false;
112 : 2678 : nIterCount = 100;
113 : 2678 : fIterEps = 1.0E-3;
114 : 2678 : nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
115 : 2678 : nDay = 30;
116 : 2678 : nMonth = 12;
117 : 2678 : nYear = 1899;
118 : 2678 : nYear2000 = SvNumberFormatter::GetYear2000Default();
119 : 2678 : nTabDistance = lcl_GetDefaultTabDist();
120 : 2678 : bCalcAsShown = false;
121 : 2678 : bMatchWholeCell = true;
122 : 2678 : bDoAutoSpell = false;
123 : 2678 : bLookUpColRowNames = true;
124 : 2678 : bFormulaRegexEnabled= true;
125 : 2678 : }
126 : :
127 : : //========================================================================
128 : : // ScTpCalcItem - Daten fuer die CalcOptions-TabPage
129 : : //========================================================================
130 : :
131 : : //------------------------------------------------------------------------
132 : :
133 : 0 : ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP, const ScDocOptions& rOpt )
134 : : : SfxPoolItem ( nWhichP ),
135 [ # # ]: 0 : theOptions ( rOpt )
136 : : {
137 : 0 : }
138 : :
139 : : //------------------------------------------------------------------------
140 : :
141 : 0 : ScTpCalcItem::ScTpCalcItem( const ScTpCalcItem& rItem )
142 : : : SfxPoolItem ( rItem ),
143 [ # # ]: 0 : theOptions ( rItem.theOptions )
144 : : {
145 : 0 : }
146 : :
147 : : //------------------------------------------------------------------------
148 : :
149 [ # # ]: 0 : ScTpCalcItem::~ScTpCalcItem()
150 : : {
151 [ # # ]: 0 : }
152 : :
153 : : //------------------------------------------------------------------------
154 : :
155 : 0 : String ScTpCalcItem::GetValueText() const
156 : : {
157 [ # # ]: 0 : return rtl::OUString("ScTpCalcItem");
158 : : }
159 : :
160 : : //------------------------------------------------------------------------
161 : :
162 : 0 : int ScTpCalcItem::operator==( const SfxPoolItem& rItem ) const
163 : : {
164 : : OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
165 : :
166 : 0 : const ScTpCalcItem& rPItem = (const ScTpCalcItem&)rItem;
167 : :
168 : 0 : return ( theOptions == rPItem.theOptions );
169 : : }
170 : :
171 : : //------------------------------------------------------------------------
172 : :
173 : 0 : SfxPoolItem* ScTpCalcItem::Clone( SfxItemPool * ) const
174 : : {
175 [ # # ]: 0 : return new ScTpCalcItem( *this );
176 : : }
177 : :
178 : : //==================================================================
179 : : // Config Item containing document options
180 : : //==================================================================
181 : :
182 : : #define CFGPATH_CALC "Office.Calc/Calculate"
183 : :
184 : : #define SCCALCOPT_ITER_ITER 0
185 : : #define SCCALCOPT_ITER_STEPS 1
186 : : #define SCCALCOPT_ITER_MINCHG 2
187 : : #define SCCALCOPT_DATE_DAY 3
188 : : #define SCCALCOPT_DATE_MONTH 4
189 : : #define SCCALCOPT_DATE_YEAR 5
190 : : #define SCCALCOPT_DECIMALS 6
191 : : #define SCCALCOPT_CASESENSITIVE 7
192 : : #define SCCALCOPT_PRECISION 8
193 : : #define SCCALCOPT_SEARCHCRIT 9
194 : : #define SCCALCOPT_FINDLABEL 10
195 : : #define SCCALCOPT_REGEX 11
196 : : #define SCCALCOPT_COUNT 12
197 : :
198 : : #define CFGPATH_DOCLAYOUT "Office.Calc/Layout/Other"
199 : :
200 : : #define SCDOCLAYOUTOPT_TABSTOP 0
201 : : #define SCDOCLAYOUTOPT_COUNT 1
202 : :
203 : 51 : Sequence<OUString> ScDocCfg::GetCalcPropertyNames()
204 : : {
205 : : static const char* aPropNames[] =
206 : : {
207 : : "IterativeReference/Iteration", // SCCALCOPT_ITER_ITER
208 : : "IterativeReference/Steps", // SCCALCOPT_ITER_STEPS
209 : : "IterativeReference/MinimumChange", // SCCALCOPT_ITER_MINCHG
210 : : "Other/Date/DD", // SCCALCOPT_DATE_DAY
211 : : "Other/Date/MM", // SCCALCOPT_DATE_MONTH
212 : : "Other/Date/YY", // SCCALCOPT_DATE_YEAR
213 : : "Other/DecimalPlaces", // SCCALCOPT_DECIMALS
214 : : "Other/CaseSensitive", // SCCALCOPT_CASESENSITIVE
215 : : "Other/Precision", // SCCALCOPT_PRECISION
216 : : "Other/SearchCriteria", // SCCALCOPT_SEARCHCRIT
217 : : "Other/FindLabel", // SCCALCOPT_FINDLABEL
218 : : "Other/RegularExpressions", // SCCALCOPT_REGEX
219 : : };
220 : 51 : Sequence<OUString> aNames(SCCALCOPT_COUNT);
221 [ + - ]: 51 : OUString* pNames = aNames.getArray();
222 [ + + ]: 663 : for(int i = 0; i < SCCALCOPT_COUNT; i++)
223 : 612 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
224 : :
225 : 51 : return aNames;
226 : : }
227 : :
228 : 51 : Sequence<OUString> ScDocCfg::GetLayoutPropertyNames()
229 : : {
230 : : static const char* aPropNames[] =
231 : : {
232 : : "TabStop/NonMetric" // SCDOCLAYOUTOPT_TABSTOP
233 : : };
234 : 51 : Sequence<OUString> aNames(SCDOCLAYOUTOPT_COUNT);
235 [ + - ]: 51 : OUString* pNames = aNames.getArray();
236 [ + + ]: 102 : for(int i = 0; i < SCDOCLAYOUTOPT_COUNT; i++)
237 : 51 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
238 : :
239 : : // adjust for metric system
240 [ + - ][ - + ]: 51 : if (ScOptionsUtil::IsMetricSystem())
241 [ # # ]: 0 : pNames[SCDOCLAYOUTOPT_TABSTOP] = OUString(RTL_CONSTASCII_USTRINGPARAM( "TabStop/Metric") );
242 : :
243 : 51 : return aNames;
244 : : }
245 : :
246 : 51 : ScDocCfg::ScDocCfg() :
247 : : aCalcItem( OUString(RTL_CONSTASCII_USTRINGPARAM( CFGPATH_CALC )) ),
248 [ + - ][ + - ]: 51 : aLayoutItem(OUString(RTL_CONSTASCII_USTRINGPARAM(CFGPATH_DOCLAYOUT)))
[ + - ][ + - ]
249 : : {
250 : 51 : sal_Int32 nIntVal = 0;
251 : :
252 [ + - ]: 51 : Sequence<OUString> aNames;
253 [ + - ]: 51 : Sequence<Any> aValues;
254 : 51 : const Any* pValues = NULL;
255 : :
256 : : sal_uInt16 nDateDay, nDateMonth, nDateYear;
257 : 51 : GetDate( nDateDay, nDateMonth, nDateYear );
258 : :
259 [ + - ][ + - ]: 51 : aNames = GetCalcPropertyNames();
[ + - ]
260 [ + - ][ + - ]: 51 : aValues = aCalcItem.GetProperties(aNames);
[ + - ]
261 [ + - ]: 51 : aCalcItem.EnableNotification(aNames);
262 : 51 : pValues = aValues.getConstArray();
263 : : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
264 [ + - ]: 51 : if(aValues.getLength() == aNames.getLength())
265 : : {
266 : 51 : double fDoubleVal = 0;
267 [ + + ]: 663 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
268 : : {
269 : : OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
270 [ + - ]: 612 : if(pValues[nProp].hasValue())
271 : : {
272 [ + + + + : 612 : switch(nProp)
+ + + + +
+ + + - ]
273 : : {
274 : : case SCCALCOPT_ITER_ITER:
275 [ + - ]: 51 : SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
276 : 51 : break;
277 : : case SCCALCOPT_ITER_STEPS:
278 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal) SetIterCount( (sal_uInt16) nIntVal );
279 : 51 : break;
280 : : case SCCALCOPT_ITER_MINCHG:
281 [ + - ]: 51 : if (pValues[nProp] >>= fDoubleVal) SetIterEps( fDoubleVal );
282 : 51 : break;
283 : : case SCCALCOPT_DATE_DAY:
284 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal) nDateDay = (sal_uInt16) nIntVal;
285 : 51 : break;
286 : : case SCCALCOPT_DATE_MONTH:
287 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal) nDateMonth = (sal_uInt16) nIntVal;
288 : 51 : break;
289 : : case SCCALCOPT_DATE_YEAR:
290 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal) nDateYear = (sal_uInt16) nIntVal;
291 : 51 : break;
292 : : case SCCALCOPT_DECIMALS:
293 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal) SetStdPrecision( (sal_uInt16) nIntVal );
294 : 51 : break;
295 : : case SCCALCOPT_CASESENSITIVE:
296 : : // content is reversed
297 [ + - ]: 51 : SetIgnoreCase( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
298 : 51 : break;
299 : : case SCCALCOPT_PRECISION:
300 [ + - ]: 51 : SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
301 : 51 : break;
302 : : case SCCALCOPT_SEARCHCRIT:
303 [ + - ]: 51 : SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
304 : 51 : break;
305 : : case SCCALCOPT_FINDLABEL:
306 [ + - ]: 51 : SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
307 : 51 : break;
308 : : case SCCALCOPT_REGEX :
309 [ + - ]: 51 : SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
310 : 612 : break;
311 : : }
312 : : }
313 : : }
314 : : }
315 [ + - ][ + - ]: 51 : aCalcItem.SetCommitLink( LINK( this, ScDocCfg, CalcCommitHdl ) );
316 : :
317 : 51 : SetDate( nDateDay, nDateMonth, nDateYear );
318 : :
319 [ + - ][ + - ]: 51 : aNames = GetLayoutPropertyNames();
[ + - ]
320 [ + - ][ + - ]: 51 : aValues = aLayoutItem.GetProperties(aNames);
[ + - ]
321 [ + - ]: 51 : aLayoutItem.EnableNotification(aNames);
322 : 51 : pValues = aValues.getConstArray();
323 : : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
324 [ + - ]: 51 : if(aValues.getLength() == aNames.getLength())
325 : : {
326 [ + + ]: 102 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
327 : : {
328 : : OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
329 [ + - ]: 51 : if(pValues[nProp].hasValue())
330 : : {
331 [ + - ]: 51 : switch(nProp)
332 : : {
333 : : case SCDOCLAYOUTOPT_TABSTOP:
334 : : // TabDistance in ScDocOptions is in twips
335 [ + - ]: 51 : if (pValues[nProp] >>= nIntVal)
336 : 51 : SetTabDistance( (sal_uInt16) HMMToTwips( nIntVal ) );
337 : 51 : break;
338 : : }
339 : : }
340 : : }
341 : : }
342 [ + - ][ + - ]: 51 : aLayoutItem.SetCommitLink( LINK( this, ScDocCfg, LayoutCommitHdl ) );
[ + - ][ + - ]
343 : 51 : }
344 : :
345 : 0 : IMPL_LINK_NOARG(ScDocCfg, CalcCommitHdl)
346 : : {
347 [ # # ]: 0 : Sequence<OUString> aNames = GetCalcPropertyNames();
348 [ # # ]: 0 : Sequence<Any> aValues(aNames.getLength());
349 [ # # ]: 0 : Any* pValues = aValues.getArray();
350 : :
351 : : sal_uInt16 nDateDay, nDateMonth, nDateYear;
352 : 0 : GetDate( nDateDay, nDateMonth, nDateYear );
353 : :
354 [ # # ]: 0 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
355 : : {
356 [ # # # # : 0 : switch(nProp)
# # # # #
# # # # ]
357 : : {
358 : : case SCCALCOPT_ITER_ITER:
359 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], IsIter() );
360 : 0 : break;
361 : : case SCCALCOPT_ITER_STEPS:
362 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) GetIterCount();
363 : 0 : break;
364 : : case SCCALCOPT_ITER_MINCHG:
365 [ # # ]: 0 : pValues[nProp] <<= (double) GetIterEps();
366 : 0 : break;
367 : : case SCCALCOPT_DATE_DAY:
368 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) nDateDay;
369 : 0 : break;
370 : : case SCCALCOPT_DATE_MONTH:
371 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) nDateMonth;
372 : 0 : break;
373 : : case SCCALCOPT_DATE_YEAR:
374 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) nDateYear;
375 : 0 : break;
376 : : case SCCALCOPT_DECIMALS:
377 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) GetStdPrecision();
378 : 0 : break;
379 : : case SCCALCOPT_CASESENSITIVE:
380 : : // content is reversed
381 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !IsIgnoreCase() );
382 : 0 : break;
383 : : case SCCALCOPT_PRECISION:
384 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], IsCalcAsShown() );
385 : 0 : break;
386 : : case SCCALCOPT_SEARCHCRIT:
387 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], IsMatchWholeCell() );
388 : 0 : break;
389 : : case SCCALCOPT_FINDLABEL:
390 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], IsLookUpColRowNames() );
391 : 0 : break;
392 : : case SCCALCOPT_REGEX :
393 [ # # ]: 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], IsFormulaRegexEnabled() );
394 : : }
395 : : }
396 [ # # ]: 0 : aCalcItem.PutProperties(aNames, aValues);
397 : :
398 [ # # ][ # # ]: 0 : return 0;
399 : : }
400 : :
401 : 0 : IMPL_LINK_NOARG(ScDocCfg, LayoutCommitHdl)
402 : : {
403 [ # # ]: 0 : Sequence<OUString> aNames = GetLayoutPropertyNames();
404 [ # # ]: 0 : Sequence<Any> aValues(aNames.getLength());
405 [ # # ]: 0 : Any* pValues = aValues.getArray();
406 : :
407 [ # # ]: 0 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
408 : : {
409 [ # # ]: 0 : switch(nProp)
410 : : {
411 : : case SCDOCLAYOUTOPT_TABSTOP:
412 : : // TabDistance in ScDocOptions is in twips
413 : : // use only even numbers, so defaults don't get changed
414 : : // by modifying other settings in the same config item
415 [ # # ]: 0 : pValues[nProp] <<= (sal_Int32) TwipsToEvenHMM( GetTabDistance() );
416 : 0 : break;
417 : : }
418 : : }
419 [ # # ]: 0 : aLayoutItem.PutProperties(aNames, aValues);
420 : :
421 [ # # ][ # # ]: 0 : return 0;
422 : : }
423 : :
424 : 0 : void ScDocCfg::SetOptions( const ScDocOptions& rNew )
425 : : {
426 : 0 : *(ScDocOptions*)this = rNew;
427 : :
428 : 0 : aCalcItem.SetModified();
429 : 0 : aLayoutItem.SetModified();
430 : 0 : }
431 : :
432 : :
433 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|