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 bool ScTpCalcItem::operator==( const SfxPoolItem
& rItem
) const
121 assert(SfxPoolItem::operator==(rItem
));
123 const ScTpCalcItem
& rPItem
= static_cast<const ScTpCalcItem
&>(rItem
);
125 return ( theOptions
== rPItem
.theOptions
);
128 SfxPoolItem
* ScTpCalcItem::Clone( SfxItemPool
* ) const
130 return new ScTpCalcItem( *this );
133 // Config Item containing document options
135 #define CFGPATH_CALC "Office.Calc/Calculate"
137 #define SCCALCOPT_ITER_ITER 0
138 #define SCCALCOPT_ITER_STEPS 1
139 #define SCCALCOPT_ITER_MINCHG 2
140 #define SCCALCOPT_DATE_DAY 3
141 #define SCCALCOPT_DATE_MONTH 4
142 #define SCCALCOPT_DATE_YEAR 5
143 #define SCCALCOPT_DECIMALS 6
144 #define SCCALCOPT_CASESENSITIVE 7
145 #define SCCALCOPT_PRECISION 8
146 #define SCCALCOPT_SEARCHCRIT 9
147 #define SCCALCOPT_FINDLABEL 10
148 #define SCCALCOPT_REGEX 11
149 #define SCCALCOPT_COUNT 12
151 #define CFGPATH_DOCLAYOUT "Office.Calc/Layout/Other"
153 #define SCDOCLAYOUTOPT_TABSTOP 0
154 #define SCDOCLAYOUTOPT_COUNT 1
156 Sequence
<OUString
> ScDocCfg::GetCalcPropertyNames()
158 static const char* aPropNames
[] =
160 "IterativeReference/Iteration", // SCCALCOPT_ITER_ITER
161 "IterativeReference/Steps", // SCCALCOPT_ITER_STEPS
162 "IterativeReference/MinimumChange", // SCCALCOPT_ITER_MINCHG
163 "Other/Date/DD", // SCCALCOPT_DATE_DAY
164 "Other/Date/MM", // SCCALCOPT_DATE_MONTH
165 "Other/Date/YY", // SCCALCOPT_DATE_YEAR
166 "Other/DecimalPlaces", // SCCALCOPT_DECIMALS
167 "Other/CaseSensitive", // SCCALCOPT_CASESENSITIVE
168 "Other/Precision", // SCCALCOPT_PRECISION
169 "Other/SearchCriteria", // SCCALCOPT_SEARCHCRIT
170 "Other/FindLabel", // SCCALCOPT_FINDLABEL
171 "Other/RegularExpressions", // SCCALCOPT_REGEX
173 Sequence
<OUString
> aNames(SCCALCOPT_COUNT
);
174 OUString
* pNames
= aNames
.getArray();
175 for(int i
= 0; i
< SCCALCOPT_COUNT
; i
++)
176 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
181 Sequence
<OUString
> ScDocCfg::GetLayoutPropertyNames()
183 static const char* aPropNames
[] =
185 "TabStop/NonMetric" // SCDOCLAYOUTOPT_TABSTOP
187 Sequence
<OUString
> aNames(SCDOCLAYOUTOPT_COUNT
);
188 OUString
* pNames
= aNames
.getArray();
189 for(int i
= 0; i
< SCDOCLAYOUTOPT_COUNT
; i
++)
190 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
192 // adjust for metric system
193 if (ScOptionsUtil::IsMetricSystem())
194 pNames
[SCDOCLAYOUTOPT_TABSTOP
] = "TabStop/Metric";
199 ScDocCfg::ScDocCfg() :
200 aCalcItem( OUString( CFGPATH_CALC
) ),
201 aLayoutItem(OUString(CFGPATH_DOCLAYOUT
))
203 sal_Int32 nIntVal
= 0;
205 Sequence
<OUString
> aNames
;
206 Sequence
<Any
> aValues
;
207 const Any
* pValues
= NULL
;
209 sal_uInt16 nDateDay
, nDateMonth
, nDateYear
;
210 GetDate( nDateDay
, nDateMonth
, nDateYear
);
212 aNames
= GetCalcPropertyNames();
213 aValues
= aCalcItem
.GetProperties(aNames
);
214 aCalcItem
.EnableNotification(aNames
);
215 pValues
= aValues
.getConstArray();
216 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
217 if(aValues
.getLength() == aNames
.getLength())
219 double fDoubleVal
= 0;
220 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
222 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
223 if(pValues
[nProp
].hasValue())
227 case SCCALCOPT_ITER_ITER
:
228 SetIter( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
230 case SCCALCOPT_ITER_STEPS
:
231 if (pValues
[nProp
] >>= nIntVal
) SetIterCount( (sal_uInt16
) nIntVal
);
233 case SCCALCOPT_ITER_MINCHG
:
234 if (pValues
[nProp
] >>= fDoubleVal
) SetIterEps( fDoubleVal
);
236 case SCCALCOPT_DATE_DAY
:
237 if (pValues
[nProp
] >>= nIntVal
) nDateDay
= (sal_uInt16
) nIntVal
;
239 case SCCALCOPT_DATE_MONTH
:
240 if (pValues
[nProp
] >>= nIntVal
) nDateMonth
= (sal_uInt16
) nIntVal
;
242 case SCCALCOPT_DATE_YEAR
:
243 if (pValues
[nProp
] >>= nIntVal
) nDateYear
= (sal_uInt16
) nIntVal
;
245 case SCCALCOPT_DECIMALS
:
246 if (pValues
[nProp
] >>= nIntVal
) SetStdPrecision( (sal_uInt16
) nIntVal
);
248 case SCCALCOPT_CASESENSITIVE
:
249 // content is reversed
250 SetIgnoreCase( !ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
252 case SCCALCOPT_PRECISION
:
253 SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
255 case SCCALCOPT_SEARCHCRIT
:
256 SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
258 case SCCALCOPT_FINDLABEL
:
259 SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
261 case SCCALCOPT_REGEX
:
262 SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
268 aCalcItem
.SetCommitLink( LINK( this, ScDocCfg
, CalcCommitHdl
) );
270 SetDate( nDateDay
, nDateMonth
, nDateYear
);
272 aNames
= GetLayoutPropertyNames();
273 aValues
= aLayoutItem
.GetProperties(aNames
);
274 aLayoutItem
.EnableNotification(aNames
);
275 pValues
= aValues
.getConstArray();
276 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
277 if(aValues
.getLength() == aNames
.getLength())
279 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
281 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
282 if(pValues
[nProp
].hasValue())
286 case SCDOCLAYOUTOPT_TABSTOP
:
287 // TabDistance in ScDocOptions is in twips
288 if (pValues
[nProp
] >>= nIntVal
)
289 SetTabDistance( (sal_uInt16
) HMMToTwips( nIntVal
) );
295 aLayoutItem
.SetCommitLink( LINK( this, ScDocCfg
, LayoutCommitHdl
) );
298 IMPL_LINK_NOARG(ScDocCfg
, CalcCommitHdl
)
300 Sequence
<OUString
> aNames
= GetCalcPropertyNames();
301 Sequence
<Any
> aValues(aNames
.getLength());
302 Any
* pValues
= aValues
.getArray();
304 sal_uInt16 nDateDay
, nDateMonth
, nDateYear
;
305 GetDate( nDateDay
, nDateMonth
, nDateYear
);
307 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
311 case SCCALCOPT_ITER_ITER
:
312 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsIter() );
314 case SCCALCOPT_ITER_STEPS
:
315 pValues
[nProp
] <<= (sal_Int32
) GetIterCount();
317 case SCCALCOPT_ITER_MINCHG
:
318 pValues
[nProp
] <<= (double) GetIterEps();
320 case SCCALCOPT_DATE_DAY
:
321 pValues
[nProp
] <<= (sal_Int32
) nDateDay
;
323 case SCCALCOPT_DATE_MONTH
:
324 pValues
[nProp
] <<= (sal_Int32
) nDateMonth
;
326 case SCCALCOPT_DATE_YEAR
:
327 pValues
[nProp
] <<= (sal_Int32
) nDateYear
;
329 case SCCALCOPT_DECIMALS
:
330 pValues
[nProp
] <<= (sal_Int32
) GetStdPrecision();
332 case SCCALCOPT_CASESENSITIVE
:
333 // content is reversed
334 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], !IsIgnoreCase() );
336 case SCCALCOPT_PRECISION
:
337 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsCalcAsShown() );
339 case SCCALCOPT_SEARCHCRIT
:
340 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsMatchWholeCell() );
342 case SCCALCOPT_FINDLABEL
:
343 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsLookUpColRowNames() );
345 case SCCALCOPT_REGEX
:
346 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], IsFormulaRegexEnabled() );
349 aCalcItem
.PutProperties(aNames
, aValues
);
354 IMPL_LINK_NOARG(ScDocCfg
, LayoutCommitHdl
)
356 Sequence
<OUString
> aNames
= GetLayoutPropertyNames();
357 Sequence
<Any
> aValues(aNames
.getLength());
358 Any
* pValues
= aValues
.getArray();
360 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
364 case SCDOCLAYOUTOPT_TABSTOP
:
365 // TabDistance in ScDocOptions is in twips
366 // use only even numbers, so defaults don't get changed
367 // by modifying other settings in the same config item
368 pValues
[nProp
] <<= (sal_Int32
) TwipsToEvenHMM( GetTabDistance() );
372 aLayoutItem
.PutProperties(aNames
, aValues
);
377 void ScDocCfg::SetOptions( const ScDocOptions
& rNew
)
379 *(ScDocOptions
*)this = rNew
;
381 aCalcItem
.SetModified();
382 aLayoutItem
.SetModified();
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */