1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
21 #include <svl/zforlist.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
27 #include "docoptio.hxx"
28 #include "rechead.hxx"
29 #include "scresid.hxx"
31 #include "miscuno.hxx"
33 #include "globstr.hrc"
36 using namespace com::sun::star::uno
;
38 TYPEINIT1(ScTpCalcItem
, SfxPoolItem
);
42 using sc::TwipsToEvenHMM
;
44 static sal_uInt16
lcl_GetDefaultTabDist()
46 if ( ScOptionsUtil::IsMetricSystem() )
47 return 709; // 1,25 cm
52 // ScDocOptions - Dokument-Optionen
54 ScDocOptions::ScDocOptions()
59 ScDocOptions::ScDocOptions( const ScDocOptions
& rCpy
)
60 : fIterEps( rCpy
.fIterEps
),
61 nIterCount( rCpy
.nIterCount
),
62 nPrecStandardFormat( rCpy
.nPrecStandardFormat
),
64 nMonth( rCpy
.nMonth
),
66 nYear2000( rCpy
.nYear2000
),
67 nTabDistance( rCpy
.nTabDistance
),
68 bIsIgnoreCase( rCpy
.bIsIgnoreCase
),
69 bIsIter( rCpy
.bIsIter
),
70 bCalcAsShown( rCpy
.bCalcAsShown
),
71 bMatchWholeCell( rCpy
.bMatchWholeCell
),
72 bDoAutoSpell( rCpy
.bDoAutoSpell
),
73 bLookUpColRowNames( rCpy
.bLookUpColRowNames
),
74 bFormulaRegexEnabled( rCpy
.bFormulaRegexEnabled
)
78 ScDocOptions::~ScDocOptions()
82 void ScDocOptions::ResetDocOptions()
84 bIsIgnoreCase
= false;
88 nPrecStandardFormat
= SvNumberFormatter::UNLIMITED_PRECISION
;
92 nYear2000
= SvNumberFormatter::GetYear2000Default();
93 nTabDistance
= lcl_GetDefaultTabDist();
95 bMatchWholeCell
= true;
97 bLookUpColRowNames
= true;
98 bFormulaRegexEnabled
= true;
101 // ScTpCalcItem - Daten fuer die CalcOptions-TabPage
103 ScTpCalcItem::ScTpCalcItem( sal_uInt16 nWhichP
, const ScDocOptions
& rOpt
)
104 : SfxPoolItem ( nWhichP
),
109 ScTpCalcItem::ScTpCalcItem( const ScTpCalcItem
& rItem
)
110 : SfxPoolItem ( rItem
),
111 theOptions ( rItem
.theOptions
)
115 ScTpCalcItem::~ScTpCalcItem()
119 OUString
ScTpCalcItem::GetValueText() const
121 return OUString("ScTpCalcItem");
124 int ScTpCalcItem::operator==( const SfxPoolItem
& rItem
) const
126 OSL_ENSURE( SfxPoolItem::operator==( rItem
), "unequal Which or Type" );
128 const ScTpCalcItem
& rPItem
= (const ScTpCalcItem
&)rItem
;
130 return ( theOptions
== rPItem
.theOptions
);
133 SfxPoolItem
* ScTpCalcItem::Clone( SfxItemPool
* ) const
135 return new ScTpCalcItem( *this );
138 // Config Item containing document options
140 #define CFGPATH_CALC "Office.Calc/Calculate"
142 #define SCCALCOPT_ITER_ITER 0
143 #define SCCALCOPT_ITER_STEPS 1
144 #define SCCALCOPT_ITER_MINCHG 2
145 #define SCCALCOPT_DATE_DAY 3
146 #define SCCALCOPT_DATE_MONTH 4
147 #define SCCALCOPT_DATE_YEAR 5
148 #define SCCALCOPT_DECIMALS 6
149 #define SCCALCOPT_CASESENSITIVE 7
150 #define SCCALCOPT_PRECISION 8
151 #define SCCALCOPT_SEARCHCRIT 9
152 #define SCCALCOPT_FINDLABEL 10
153 #define SCCALCOPT_REGEX 11
154 #define SCCALCOPT_COUNT 12
156 #define CFGPATH_DOCLAYOUT "Office.Calc/Layout/Other"
158 #define SCDOCLAYOUTOPT_TABSTOP 0
159 #define SCDOCLAYOUTOPT_COUNT 1
161 Sequence
<OUString
> ScDocCfg::GetCalcPropertyNames()
163 static const char* aPropNames
[] =
165 "IterativeReference/Iteration", // SCCALCOPT_ITER_ITER
166 "IterativeReference/Steps", // SCCALCOPT_ITER_STEPS
167 "IterativeReference/MinimumChange", // SCCALCOPT_ITER_MINCHG
168 "Other/Date/DD", // SCCALCOPT_DATE_DAY
169 "Other/Date/MM", // SCCALCOPT_DATE_MONTH
170 "Other/Date/YY", // SCCALCOPT_DATE_YEAR
171 "Other/DecimalPlaces", // SCCALCOPT_DECIMALS
172 "Other/CaseSensitive", // SCCALCOPT_CASESENSITIVE
173 "Other/Precision", // SCCALCOPT_PRECISION
174 "Other/SearchCriteria", // SCCALCOPT_SEARCHCRIT
175 "Other/FindLabel", // SCCALCOPT_FINDLABEL
176 "Other/RegularExpressions", // SCCALCOPT_REGEX
178 Sequence
<OUString
> aNames(SCCALCOPT_COUNT
);
179 OUString
* pNames
= aNames
.getArray();
180 for(int i
= 0; i
< SCCALCOPT_COUNT
; i
++)
181 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
186 Sequence
<OUString
> ScDocCfg::GetLayoutPropertyNames()
188 static const char* aPropNames
[] =
190 "TabStop/NonMetric" // SCDOCLAYOUTOPT_TABSTOP
192 Sequence
<OUString
> aNames(SCDOCLAYOUTOPT_COUNT
);
193 OUString
* pNames
= aNames
.getArray();
194 for(int i
= 0; i
< SCDOCLAYOUTOPT_COUNT
; i
++)
195 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
197 // adjust for metric system
198 if (ScOptionsUtil::IsMetricSystem())
199 pNames
[SCDOCLAYOUTOPT_TABSTOP
] = "TabStop/Metric";
204 ScDocCfg::ScDocCfg() :
205 aCalcItem( OUString( CFGPATH_CALC
) ),
206 aLayoutItem(OUString(CFGPATH_DOCLAYOUT
))
208 sal_Int32 nIntVal
= 0;
210 Sequence
<OUString
> aNames
;
211 Sequence
<Any
> aValues
;
212 const Any
* pValues
= NULL
;
214 sal_uInt16 nDateDay
, nDateMonth
, nDateYear
;
215 GetDate( nDateDay
, nDateMonth
, nDateYear
);
217 aNames
= GetCalcPropertyNames();
218 aValues
= aCalcItem
.GetProperties(aNames
);
219 aCalcItem
.EnableNotification(aNames
);
220 pValues
= aValues
.getConstArray();
221 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
222 if(aValues
.getLength() == aNames
.getLength())
224 double fDoubleVal
= 0;
225 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
227 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
228 if(pValues
[nProp
].hasValue())
232 case SCCALCOPT_ITER_ITER
:
233 SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
235 case SCCALCOPT_ITER_STEPS
:
236 if (pValues
[nProp
] >>= nIntVal
) SetIterCount( (sal_uInt16
) nIntVal
);
238 case SCCALCOPT_ITER_MINCHG
:
239 if (pValues
[nProp
] >>= fDoubleVal
) SetIterEps( fDoubleVal
);
241 case SCCALCOPT_DATE_DAY
:
242 if (pValues
[nProp
] >>= nIntVal
) nDateDay
= (sal_uInt16
) nIntVal
;
244 case SCCALCOPT_DATE_MONTH
:
245 if (pValues
[nProp
] >>= nIntVal
) nDateMonth
= (sal_uInt16
) nIntVal
;
247 case SCCALCOPT_DATE_YEAR
:
248 if (pValues
[nProp
] >>= nIntVal
) nDateYear
= (sal_uInt16
) nIntVal
;
250 case SCCALCOPT_DECIMALS
:
251 if (pValues
[nProp
] >>= nIntVal
) SetStdPrecision( (sal_uInt16
) nIntVal
);
253 case SCCALCOPT_CASESENSITIVE
:
254 // content is reversed
255 SetIgnoreCase( !ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
257 case SCCALCOPT_PRECISION
:
258 SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
260 case SCCALCOPT_SEARCHCRIT
:
261 SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
263 case SCCALCOPT_FINDLABEL
:
264 SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
266 case SCCALCOPT_REGEX
:
267 SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
273 aCalcItem
.SetCommitLink( LINK( this, ScDocCfg
, CalcCommitHdl
) );
275 SetDate( nDateDay
, nDateMonth
, nDateYear
);
277 aNames
= GetLayoutPropertyNames();
278 aValues
= aLayoutItem
.GetProperties(aNames
);
279 aLayoutItem
.EnableNotification(aNames
);
280 pValues
= aValues
.getConstArray();
281 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
282 if(aValues
.getLength() == aNames
.getLength())
284 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
286 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
287 if(pValues
[nProp
].hasValue())
291 case SCDOCLAYOUTOPT_TABSTOP
:
292 // TabDistance in ScDocOptions is in twips
293 if (pValues
[nProp
] >>= nIntVal
)
294 SetTabDistance( (sal_uInt16
) HMMToTwips( nIntVal
) );
300 aLayoutItem
.SetCommitLink( LINK( this, ScDocCfg
, LayoutCommitHdl
) );
303 IMPL_LINK_NOARG(ScDocCfg
, CalcCommitHdl
)
305 Sequence
<OUString
> aNames
= GetCalcPropertyNames();
306 Sequence
<Any
> aValues(aNames
.getLength());
307 Any
* pValues
= aValues
.getArray();
309 sal_uInt16 nDateDay
, nDateMonth
, nDateYear
;
310 GetDate( nDateDay
, nDateMonth
, nDateYear
);
312 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
316 case SCCALCOPT_ITER_ITER
:
317 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsIter() );
319 case SCCALCOPT_ITER_STEPS
:
320 pValues
[nProp
] <<= (sal_Int32
) GetIterCount();
322 case SCCALCOPT_ITER_MINCHG
:
323 pValues
[nProp
] <<= (double) GetIterEps();
325 case SCCALCOPT_DATE_DAY
:
326 pValues
[nProp
] <<= (sal_Int32
) nDateDay
;
328 case SCCALCOPT_DATE_MONTH
:
329 pValues
[nProp
] <<= (sal_Int32
) nDateMonth
;
331 case SCCALCOPT_DATE_YEAR
:
332 pValues
[nProp
] <<= (sal_Int32
) nDateYear
;
334 case SCCALCOPT_DECIMALS
:
335 pValues
[nProp
] <<= (sal_Int32
) GetStdPrecision();
337 case SCCALCOPT_CASESENSITIVE
:
338 // content is reversed
339 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], !IsIgnoreCase() );
341 case SCCALCOPT_PRECISION
:
342 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsCalcAsShown() );
344 case SCCALCOPT_SEARCHCRIT
:
345 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsMatchWholeCell() );
347 case SCCALCOPT_FINDLABEL
:
348 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsLookUpColRowNames() );
350 case SCCALCOPT_REGEX
:
351 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsFormulaRegexEnabled() );
354 aCalcItem
.PutProperties(aNames
, aValues
);
359 IMPL_LINK_NOARG(ScDocCfg
, LayoutCommitHdl
)
361 Sequence
<OUString
> aNames
= GetLayoutPropertyNames();
362 Sequence
<Any
> aValues(aNames
.getLength());
363 Any
* pValues
= aValues
.getArray();
365 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
369 case SCDOCLAYOUTOPT_TABSTOP
:
370 // TabDistance in ScDocOptions is in twips
371 // use only even numbers, so defaults don't get changed
372 // by modifying other settings in the same config item
373 pValues
[nProp
] <<= (sal_Int32
) TwipsToEvenHMM( GetTabDistance() );
377 aLayoutItem
.PutProperties(aNames
, aValues
);
382 void ScDocCfg::SetOptions( const ScDocOptions
& rNew
)
384 *(ScDocOptions
*)this = rNew
;
386 aCalcItem
.SetModified();
387 aLayoutItem
.SetModified();
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */