1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir //------------------------------------------------------------------
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "scitems.hxx"
34cdf0e10cSrcweir #include <vcl/msgbox.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "global.hxx"
37cdf0e10cSrcweir #include "globstr.hrc"
38cdf0e10cSrcweir #include "uiitems.hxx"
39cdf0e10cSrcweir #include "docsh.hxx"
40cdf0e10cSrcweir #include "document.hxx"
41cdf0e10cSrcweir #include "docoptio.hxx"
42cdf0e10cSrcweir #include "scresid.hxx"
43cdf0e10cSrcweir #include "sc.hrc" // -> Slot-IDs
44cdf0e10cSrcweir #include "optdlg.hrc"
45cdf0e10cSrcweir
46cdf0e10cSrcweir #define _TPCALC_CXX
47cdf0e10cSrcweir #include "tpcalc.hxx"
48cdf0e10cSrcweir #undef _TPCALC_CXX
49cdf0e10cSrcweir
50cdf0e10cSrcweir #include <math.h>
51cdf0e10cSrcweir
52cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
53cdf0e10cSrcweir
54cdf0e10cSrcweir static sal_uInt16 pCalcOptRanges[] =
55cdf0e10cSrcweir {
56cdf0e10cSrcweir SID_SCDOCOPTIONS,
57cdf0e10cSrcweir SID_SCDOCOPTIONS,
58cdf0e10cSrcweir 0
59cdf0e10cSrcweir };
60cdf0e10cSrcweir
61cdf0e10cSrcweir //========================================================================
62cdf0e10cSrcweir
ScTpCalcOptions(Window * pParent,const SfxItemSet & rCoreAttrs)63cdf0e10cSrcweir ScTpCalcOptions::ScTpCalcOptions( Window* pParent,
64cdf0e10cSrcweir const SfxItemSet& rCoreAttrs )
65cdf0e10cSrcweir
66cdf0e10cSrcweir : SfxTabPage ( pParent,
67cdf0e10cSrcweir ScResId( RID_SCPAGE_CALC ),
68cdf0e10cSrcweir rCoreAttrs ),
69cdf0e10cSrcweir
70cdf0e10cSrcweir aGbZRefs ( this, ScResId( GB_ZREFS ) ),
71cdf0e10cSrcweir aBtnIterate ( this, ScResId( BTN_ITERATE ) ),
72cdf0e10cSrcweir aFtSteps ( this, ScResId( FT_STEPS ) ),
73cdf0e10cSrcweir aEdSteps ( this, ScResId( ED_STEPS ) ),
74cdf0e10cSrcweir aFtEps ( this, ScResId( FT_EPS ) ),
75cdf0e10cSrcweir aEdEps ( this, ScResId( ED_EPS ) ),
76cdf0e10cSrcweir aSeparatorFL ( this, ScResId( FL_SEPARATOR ) ),
77cdf0e10cSrcweir aGbDate ( this, ScResId( GB_DATE ) ),
78cdf0e10cSrcweir aBtnDateStd ( this, ScResId( BTN_DATESTD ) ),
79cdf0e10cSrcweir aBtnDateSc10 ( this, ScResId( BTN_DATESC10 ) ),
80cdf0e10cSrcweir aBtnDate1904 ( this, ScResId( BTN_DATE1904 ) ),
81cdf0e10cSrcweir aHSeparatorFL ( this, ScResId( FL_H_SEPARATOR ) ),
82cdf0e10cSrcweir aBtnCase ( this, ScResId( BTN_CASE ) ),
83cdf0e10cSrcweir aBtnCalc ( this, ScResId( BTN_CALC ) ),
84cdf0e10cSrcweir aBtnMatch ( this, ScResId( BTN_MATCH ) ),
85cdf0e10cSrcweir aBtnRegex ( this, ScResId( BTN_REGEX ) ),
86cdf0e10cSrcweir aBtnLookUp ( this, ScResId( BTN_LOOKUP ) ),
87cdf0e10cSrcweir aBtnGeneralPrec ( this, ScResId( BTN_GENERAL_PREC ) ),
88cdf0e10cSrcweir aFtPrec ( this, ScResId( FT_PREC ) ),
89cdf0e10cSrcweir aEdPrec ( this, ScResId( ED_PREC ) ),
90cdf0e10cSrcweir pOldOptions ( new ScDocOptions(
91cdf0e10cSrcweir ((const ScTpCalcItem&)rCoreAttrs.Get(
92cdf0e10cSrcweir GetWhich( SID_SCDOCOPTIONS ))).
93cdf0e10cSrcweir GetDocOptions() ) ),
94cdf0e10cSrcweir pLocalOptions ( new ScDocOptions ),
95cdf0e10cSrcweir nWhichCalc ( GetWhich( SID_SCDOCOPTIONS ) )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir aSeparatorFL.SetStyle( aSeparatorFL.GetStyle() | WB_VERT );
98cdf0e10cSrcweir Init();
99cdf0e10cSrcweir FreeResource();
100cdf0e10cSrcweir SetExchangeSupport();
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir //-----------------------------------------------------------------------
104cdf0e10cSrcweir
~ScTpCalcOptions()105cdf0e10cSrcweir __EXPORT ScTpCalcOptions::~ScTpCalcOptions()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir delete pOldOptions;
108cdf0e10cSrcweir delete pLocalOptions;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir //-----------------------------------------------------------------------
112cdf0e10cSrcweir
Init()113cdf0e10cSrcweir void ScTpCalcOptions::Init()
114cdf0e10cSrcweir {
115*c3d385a8SAriel Constenla-Haile const Size a6Size = aFtPrec.LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
116*c3d385a8SAriel Constenla-Haile const Size aMin = aFtPrec.CalcMinimumSize();
117*c3d385a8SAriel Constenla-Haile const Point aPos = aFtPrec.GetPosPixel();
118*c3d385a8SAriel Constenla-Haile const long nNewX = aPos.X() + aFtPrec.GetSizePixel().Width() - aMin.Width();
119*c3d385a8SAriel Constenla-Haile
120*c3d385a8SAriel Constenla-Haile aFtPrec.SetPosPixel( Point( nNewX, aPos.Y() ) );
121*c3d385a8SAriel Constenla-Haile aFtPrec.SetSizePixel( aMin );
122*c3d385a8SAriel Constenla-Haile aBtnGeneralPrec.SetSizePixel( Size(
123*c3d385a8SAriel Constenla-Haile nNewX - a6Size.Width() - aBtnGeneralPrec.GetPosPixel().X(),
124*c3d385a8SAriel Constenla-Haile aBtnGeneralPrec.GetSizePixel().Height() ) );
125*c3d385a8SAriel Constenla-Haile
126cdf0e10cSrcweir aBtnIterate .SetClickHdl( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
127cdf0e10cSrcweir aBtnGeneralPrec.SetClickHdl( LINK(this, ScTpCalcOptions, CheckClickHdl) );
128cdf0e10cSrcweir aBtnDateStd .SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
129cdf0e10cSrcweir aBtnDateSc10.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
130cdf0e10cSrcweir aBtnDate1904.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir //-----------------------------------------------------------------------
134cdf0e10cSrcweir
GetRanges()135cdf0e10cSrcweir sal_uInt16* __EXPORT ScTpCalcOptions::GetRanges()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir return pCalcOptRanges;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir //-----------------------------------------------------------------------
141cdf0e10cSrcweir
Create(Window * pParent,const SfxItemSet & rAttrSet)142cdf0e10cSrcweir SfxTabPage* __EXPORT ScTpCalcOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir return ( new ScTpCalcOptions( pParent, rAttrSet ) );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir //-----------------------------------------------------------------------
148cdf0e10cSrcweir
Reset(const SfxItemSet &)149cdf0e10cSrcweir void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir sal_uInt16 d,m,y;
152cdf0e10cSrcweir
153cdf0e10cSrcweir *pLocalOptions = *pOldOptions;
154cdf0e10cSrcweir
155cdf0e10cSrcweir aBtnCase .Check( !pLocalOptions->IsIgnoreCase() );
156cdf0e10cSrcweir aBtnCalc .Check( pLocalOptions->IsCalcAsShown() );
157cdf0e10cSrcweir aBtnMatch .Check( pLocalOptions->IsMatchWholeCell() );
158cdf0e10cSrcweir aBtnRegex .Check( pLocalOptions->IsFormulaRegexEnabled() );
159cdf0e10cSrcweir aBtnLookUp .Check( pLocalOptions->IsLookUpColRowNames() );
160cdf0e10cSrcweir aBtnIterate.Check( pLocalOptions->IsIter() );
161cdf0e10cSrcweir aEdSteps .SetValue( pLocalOptions->GetIterCount() );
162cdf0e10cSrcweir aEdEps .SetValue( pLocalOptions->GetIterEps(), 6 );
163cdf0e10cSrcweir
164cdf0e10cSrcweir pLocalOptions->GetDate( d, m, y );
165cdf0e10cSrcweir
166cdf0e10cSrcweir switch ( y )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir case 1899:
169cdf0e10cSrcweir aBtnDateStd.Check();
170cdf0e10cSrcweir break;
171cdf0e10cSrcweir case 1900:
172cdf0e10cSrcweir aBtnDateSc10.Check();
173cdf0e10cSrcweir break;
174cdf0e10cSrcweir case 1904:
175cdf0e10cSrcweir aBtnDate1904.Check();
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
180cdf0e10cSrcweir if (nPrec == SvNumberFormatter::UNLIMITED_PRECISION)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir aFtPrec.Disable();
183cdf0e10cSrcweir aEdPrec.Disable();
184cdf0e10cSrcweir aBtnGeneralPrec.Check(false);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir aBtnGeneralPrec.Check();
189cdf0e10cSrcweir aFtPrec.Enable();
190cdf0e10cSrcweir aEdPrec.Enable();
191cdf0e10cSrcweir aEdPrec.SetValue(nPrec);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir CheckClickHdl( &aBtnIterate );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir
198cdf0e10cSrcweir //-----------------------------------------------------------------------
199cdf0e10cSrcweir
FillItemSet(SfxItemSet & rCoreAttrs)200cdf0e10cSrcweir sal_Bool __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir // alle weiteren Optionen werden in den Handlern aktualisiert
203cdf0e10cSrcweir pLocalOptions->SetIterCount( (sal_uInt16)aEdSteps.GetValue() );
204cdf0e10cSrcweir pLocalOptions->SetIgnoreCase( !aBtnCase.IsChecked() );
205cdf0e10cSrcweir pLocalOptions->SetCalcAsShown( aBtnCalc.IsChecked() );
206cdf0e10cSrcweir pLocalOptions->SetMatchWholeCell( aBtnMatch.IsChecked() );
207cdf0e10cSrcweir pLocalOptions->SetFormulaRegexEnabled( aBtnRegex.IsChecked() );
208cdf0e10cSrcweir pLocalOptions->SetLookUpColRowNames( aBtnLookUp.IsChecked() );
209cdf0e10cSrcweir
210cdf0e10cSrcweir if (aBtnGeneralPrec.IsChecked())
211cdf0e10cSrcweir pLocalOptions->SetStdPrecision(
212cdf0e10cSrcweir static_cast<sal_uInt16>(aEdPrec.GetValue()) );
213cdf0e10cSrcweir else
214cdf0e10cSrcweir pLocalOptions->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION );
215cdf0e10cSrcweir
216cdf0e10cSrcweir if ( *pLocalOptions != *pOldOptions )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir rCoreAttrs.Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
219cdf0e10cSrcweir return sal_True;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir else
222cdf0e10cSrcweir return sal_False;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
225cdf0e10cSrcweir //------------------------------------------------------------------------
226cdf0e10cSrcweir
DeactivatePage(SfxItemSet * pSetP)227cdf0e10cSrcweir int __EXPORT ScTpCalcOptions::DeactivatePage( SfxItemSet* pSetP )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir int nReturn = KEEP_PAGE;
230cdf0e10cSrcweir
231cdf0e10cSrcweir double fEps;
232cdf0e10cSrcweir if( aEdEps.GetValue( fEps ) && (fEps > 0.0) )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir pLocalOptions->SetIterEps( fEps );
235cdf0e10cSrcweir nReturn = LEAVE_PAGE;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir if ( nReturn == KEEP_PAGE )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir ErrorBox( this,
241cdf0e10cSrcweir WinBits( WB_OK | WB_DEF_OK ),
242cdf0e10cSrcweir ScGlobal::GetRscString( STR_INVALID_EPS )
243cdf0e10cSrcweir ).Execute();
244cdf0e10cSrcweir
245cdf0e10cSrcweir aEdEps.GrabFocus();
246cdf0e10cSrcweir }
247cdf0e10cSrcweir else if ( pSetP )
248cdf0e10cSrcweir FillItemSet( *pSetP );
249cdf0e10cSrcweir
250cdf0e10cSrcweir return nReturn;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
253cdf0e10cSrcweir //-----------------------------------------------------------------------
254cdf0e10cSrcweir // Handler:
255cdf0e10cSrcweir
IMPL_LINK(ScTpCalcOptions,RadioClickHdl,RadioButton *,pBtn)256cdf0e10cSrcweir IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir if ( pBtn == &aBtnDateStd )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir pLocalOptions->SetDate( 30, 12, 1899 );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir else if ( pBtn == &aBtnDateSc10 )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir pLocalOptions->SetDate( 1, 1, 1900 );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir else if ( pBtn == &aBtnDate1904 )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir pLocalOptions->SetDate( 1, 1, 1904 );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir return 0;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir //-----------------------------------------------------------------------
275cdf0e10cSrcweir
IMPL_LINK(ScTpCalcOptions,CheckClickHdl,CheckBox *,pBtn)276cdf0e10cSrcweir IMPL_LINK( ScTpCalcOptions, CheckClickHdl, CheckBox*, pBtn )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir if (pBtn == &aBtnGeneralPrec)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir if (pBtn->IsChecked())
281cdf0e10cSrcweir {
282cdf0e10cSrcweir aEdPrec.Enable();
283cdf0e10cSrcweir aFtPrec.Enable();
284cdf0e10cSrcweir }
285cdf0e10cSrcweir else
286cdf0e10cSrcweir {
287cdf0e10cSrcweir aEdPrec.Disable();
288cdf0e10cSrcweir aFtPrec.Disable();
289cdf0e10cSrcweir }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir else if (pBtn == &aBtnIterate)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir if ( pBtn->IsChecked() )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir pLocalOptions->SetIter( sal_True );
296cdf0e10cSrcweir aFtSteps.Enable(); aEdSteps.Enable();
297cdf0e10cSrcweir aFtEps .Enable(); aEdEps .Enable();
298cdf0e10cSrcweir }
299cdf0e10cSrcweir else
300cdf0e10cSrcweir {
301cdf0e10cSrcweir pLocalOptions->SetIter( sal_False );
302cdf0e10cSrcweir aFtSteps.Disable(); aEdSteps.Disable();
303cdf0e10cSrcweir aFtEps .Disable(); aEdEps .Disable();
304cdf0e10cSrcweir }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir return 0;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir
311cdf0e10cSrcweir
312cdf0e10cSrcweir
313