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