xref: /AOO41X/main/sc/source/ui/optdlg/tpcalc.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //------------------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "scitems.hxx"
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "global.hxx"
41*cdf0e10cSrcweir #include "globstr.hrc"
42*cdf0e10cSrcweir #include "uiitems.hxx"
43*cdf0e10cSrcweir #include "docsh.hxx"
44*cdf0e10cSrcweir #include "document.hxx"
45*cdf0e10cSrcweir #include "docoptio.hxx"
46*cdf0e10cSrcweir #include "scresid.hxx"
47*cdf0e10cSrcweir #include "sc.hrc"       // -> Slot-IDs
48*cdf0e10cSrcweir #include "optdlg.hrc"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #define _TPCALC_CXX
51*cdf0e10cSrcweir #include "tpcalc.hxx"
52*cdf0e10cSrcweir #undef _TPCALC_CXX
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <math.h>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir static sal_uInt16 pCalcOptRanges[] =
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	SID_SCDOCOPTIONS,
61*cdf0e10cSrcweir 	SID_SCDOCOPTIONS,
62*cdf0e10cSrcweir 	0
63*cdf0e10cSrcweir };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //========================================================================
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir ScTpCalcOptions::ScTpCalcOptions( Window*			pParent,
68*cdf0e10cSrcweir 								  const SfxItemSet& rCoreAttrs )
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	:	SfxTabPage		( pParent,
71*cdf0e10cSrcweir 						  ScResId( RID_SCPAGE_CALC ),
72*cdf0e10cSrcweir 						  rCoreAttrs ),
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 		aGbZRefs		( this, ScResId( GB_ZREFS ) ),
75*cdf0e10cSrcweir 		aBtnIterate 	( this, ScResId( BTN_ITERATE ) ),
76*cdf0e10cSrcweir 		aFtSteps		( this, ScResId( FT_STEPS ) ),
77*cdf0e10cSrcweir 		aEdSteps		( this, ScResId( ED_STEPS ) ),
78*cdf0e10cSrcweir 		aFtEps			( this, ScResId( FT_EPS ) ),
79*cdf0e10cSrcweir 		aEdEps			( this, ScResId( ED_EPS ) ),
80*cdf0e10cSrcweir         aSeparatorFL    ( this, ScResId( FL_SEPARATOR ) ),
81*cdf0e10cSrcweir 		aGbDate 		( this, ScResId( GB_DATE ) ),
82*cdf0e10cSrcweir 		aBtnDateStd 	( this, ScResId( BTN_DATESTD ) ),
83*cdf0e10cSrcweir 		aBtnDateSc10	( this, ScResId( BTN_DATESC10 ) ),
84*cdf0e10cSrcweir 		aBtnDate1904	( this, ScResId( BTN_DATE1904 ) ),
85*cdf0e10cSrcweir         aHSeparatorFL   ( this, ScResId( FL_H_SEPARATOR ) ),
86*cdf0e10cSrcweir 		aBtnCase	 	( this, ScResId( BTN_CASE ) ),
87*cdf0e10cSrcweir 		aBtnCalc	 	( this, ScResId( BTN_CALC ) ),
88*cdf0e10cSrcweir 		aBtnMatch	 	( this, ScResId( BTN_MATCH ) ),
89*cdf0e10cSrcweir         aBtnRegex       ( this, ScResId( BTN_REGEX ) ),
90*cdf0e10cSrcweir 		aBtnLookUp   	( this, ScResId( BTN_LOOKUP ) ),
91*cdf0e10cSrcweir         aBtnGeneralPrec ( this, ScResId( BTN_GENERAL_PREC ) ),
92*cdf0e10cSrcweir 		aFtPrec 		( this, ScResId( FT_PREC ) ),
93*cdf0e10cSrcweir 		aEdPrec 		( this, ScResId( ED_PREC ) ),
94*cdf0e10cSrcweir 		pOldOptions 	( new ScDocOptions(
95*cdf0e10cSrcweir 							((const ScTpCalcItem&)rCoreAttrs.Get(
96*cdf0e10cSrcweir 								GetWhich( SID_SCDOCOPTIONS ))).
97*cdf0e10cSrcweir 									GetDocOptions() ) ),
98*cdf0e10cSrcweir 		pLocalOptions	( new ScDocOptions ),
99*cdf0e10cSrcweir 		nWhichCalc		( GetWhich( SID_SCDOCOPTIONS ) )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     aSeparatorFL.SetStyle( aSeparatorFL.GetStyle() | WB_VERT );
102*cdf0e10cSrcweir     Init();
103*cdf0e10cSrcweir 	FreeResource();
104*cdf0e10cSrcweir 	SetExchangeSupport();
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir //-----------------------------------------------------------------------
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir __EXPORT ScTpCalcOptions::~ScTpCalcOptions()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	delete pOldOptions;
112*cdf0e10cSrcweir 	delete pLocalOptions;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //-----------------------------------------------------------------------
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir void ScTpCalcOptions::Init()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	aBtnIterate .SetClickHdl( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
120*cdf0e10cSrcweir     aBtnGeneralPrec.SetClickHdl( LINK(this, ScTpCalcOptions, CheckClickHdl) );
121*cdf0e10cSrcweir 	aBtnDateStd .SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
122*cdf0e10cSrcweir 	aBtnDateSc10.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
123*cdf0e10cSrcweir 	aBtnDate1904.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //-----------------------------------------------------------------------
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir sal_uInt16* __EXPORT ScTpCalcOptions::GetRanges()
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir 	return pCalcOptRanges;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //-----------------------------------------------------------------------
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir SfxTabPage* __EXPORT ScTpCalcOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	return ( new ScTpCalcOptions( pParent, rAttrSet ) );
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir //-----------------------------------------------------------------------
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir 	sal_uInt16	d,m,y;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	*pLocalOptions	= *pOldOptions;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	aBtnCase   .Check( !pLocalOptions->IsIgnoreCase() );
149*cdf0e10cSrcweir 	aBtnCalc   .Check( pLocalOptions->IsCalcAsShown() );
150*cdf0e10cSrcweir 	aBtnMatch  .Check( pLocalOptions->IsMatchWholeCell() );
151*cdf0e10cSrcweir     aBtnRegex  .Check( pLocalOptions->IsFormulaRegexEnabled() );
152*cdf0e10cSrcweir 	aBtnLookUp .Check( pLocalOptions->IsLookUpColRowNames() );
153*cdf0e10cSrcweir 	aBtnIterate.Check( pLocalOptions->IsIter() );
154*cdf0e10cSrcweir 	aEdSteps   .SetValue( pLocalOptions->GetIterCount() );
155*cdf0e10cSrcweir     aEdEps     .SetValue( pLocalOptions->GetIterEps(), 6 );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	pLocalOptions->GetDate( d, m, y );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	switch ( y )
160*cdf0e10cSrcweir 	{
161*cdf0e10cSrcweir 		case 1899:
162*cdf0e10cSrcweir 			aBtnDateStd.Check();
163*cdf0e10cSrcweir 			break;
164*cdf0e10cSrcweir 		case 1900:
165*cdf0e10cSrcweir 			aBtnDateSc10.Check();
166*cdf0e10cSrcweir 			break;
167*cdf0e10cSrcweir 		case 1904:
168*cdf0e10cSrcweir 			aBtnDate1904.Check();
169*cdf0e10cSrcweir 			break;
170*cdf0e10cSrcweir 	}
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
173*cdf0e10cSrcweir     if (nPrec == SvNumberFormatter::UNLIMITED_PRECISION)
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         aFtPrec.Disable();
176*cdf0e10cSrcweir         aEdPrec.Disable();
177*cdf0e10cSrcweir         aBtnGeneralPrec.Check(false);
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir     else
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         aBtnGeneralPrec.Check();
182*cdf0e10cSrcweir         aFtPrec.Enable();
183*cdf0e10cSrcweir         aEdPrec.Enable();
184*cdf0e10cSrcweir         aEdPrec.SetValue(nPrec);
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	CheckClickHdl( &aBtnIterate );
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //-----------------------------------------------------------------------
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir sal_Bool __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	// alle weiteren Optionen werden in den Handlern aktualisiert
196*cdf0e10cSrcweir 	pLocalOptions->SetIterCount( (sal_uInt16)aEdSteps.GetValue() );
197*cdf0e10cSrcweir 	pLocalOptions->SetIgnoreCase( !aBtnCase.IsChecked() );
198*cdf0e10cSrcweir 	pLocalOptions->SetCalcAsShown( aBtnCalc.IsChecked() );
199*cdf0e10cSrcweir 	pLocalOptions->SetMatchWholeCell( aBtnMatch.IsChecked() );
200*cdf0e10cSrcweir     pLocalOptions->SetFormulaRegexEnabled( aBtnRegex.IsChecked() );
201*cdf0e10cSrcweir 	pLocalOptions->SetLookUpColRowNames( aBtnLookUp.IsChecked() );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     if (aBtnGeneralPrec.IsChecked())
204*cdf0e10cSrcweir         pLocalOptions->SetStdPrecision(
205*cdf0e10cSrcweir             static_cast<sal_uInt16>(aEdPrec.GetValue()) );
206*cdf0e10cSrcweir     else
207*cdf0e10cSrcweir         pLocalOptions->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	if ( *pLocalOptions != *pOldOptions )
210*cdf0e10cSrcweir 	{
211*cdf0e10cSrcweir 		rCoreAttrs.Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
212*cdf0e10cSrcweir 		return sal_True;
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 	else
215*cdf0e10cSrcweir 		return sal_False;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir //------------------------------------------------------------------------
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir int __EXPORT ScTpCalcOptions::DeactivatePage( SfxItemSet* pSetP )
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     int nReturn = KEEP_PAGE;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     double fEps;
225*cdf0e10cSrcweir     if( aEdEps.GetValue( fEps ) && (fEps > 0.0) )
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         pLocalOptions->SetIterEps( fEps );
228*cdf0e10cSrcweir         nReturn = LEAVE_PAGE;
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	if ( nReturn == KEEP_PAGE )
232*cdf0e10cSrcweir 	{
233*cdf0e10cSrcweir 		ErrorBox( this,
234*cdf0e10cSrcweir 				  WinBits( WB_OK | WB_DEF_OK ),
235*cdf0e10cSrcweir 				  ScGlobal::GetRscString( STR_INVALID_EPS )
236*cdf0e10cSrcweir 				).Execute();
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 		aEdEps.GrabFocus();
239*cdf0e10cSrcweir 	}
240*cdf0e10cSrcweir     else if ( pSetP )
241*cdf0e10cSrcweir         FillItemSet( *pSetP );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	return nReturn;
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir //-----------------------------------------------------------------------
247*cdf0e10cSrcweir // Handler:
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	if ( pBtn == &aBtnDateStd )
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir 		pLocalOptions->SetDate( 30, 12, 1899 );
254*cdf0e10cSrcweir 	}
255*cdf0e10cSrcweir 	else if ( pBtn == &aBtnDateSc10 )
256*cdf0e10cSrcweir 	{
257*cdf0e10cSrcweir 		pLocalOptions->SetDate( 1, 1, 1900 );
258*cdf0e10cSrcweir 	}
259*cdf0e10cSrcweir 	else if ( pBtn == &aBtnDate1904 )
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir 		pLocalOptions->SetDate( 1, 1, 1904 );
262*cdf0e10cSrcweir 	}
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	return 0;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir //-----------------------------------------------------------------------
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir IMPL_LINK( ScTpCalcOptions, CheckClickHdl, CheckBox*, pBtn )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     if (pBtn == &aBtnGeneralPrec)
272*cdf0e10cSrcweir 	{
273*cdf0e10cSrcweir         if (pBtn->IsChecked())
274*cdf0e10cSrcweir         {
275*cdf0e10cSrcweir             aEdPrec.Enable();
276*cdf0e10cSrcweir             aFtPrec.Enable();
277*cdf0e10cSrcweir         }
278*cdf0e10cSrcweir         else
279*cdf0e10cSrcweir         {
280*cdf0e10cSrcweir             aEdPrec.Disable();
281*cdf0e10cSrcweir             aFtPrec.Disable();
282*cdf0e10cSrcweir         }
283*cdf0e10cSrcweir 	}
284*cdf0e10cSrcweir     else if (pBtn == &aBtnIterate)
285*cdf0e10cSrcweir 	{
286*cdf0e10cSrcweir         if ( pBtn->IsChecked() )
287*cdf0e10cSrcweir         {
288*cdf0e10cSrcweir             pLocalOptions->SetIter( sal_True );
289*cdf0e10cSrcweir             aFtSteps.Enable();	aEdSteps.Enable();
290*cdf0e10cSrcweir             aFtEps	.Enable();	aEdEps	.Enable();
291*cdf0e10cSrcweir         }
292*cdf0e10cSrcweir         else
293*cdf0e10cSrcweir         {
294*cdf0e10cSrcweir             pLocalOptions->SetIter( sal_False );
295*cdf0e10cSrcweir             aFtSteps.Disable(); aEdSteps.Disable();
296*cdf0e10cSrcweir             aFtEps	.Disable(); aEdEps	.Disable();
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	return 0;
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 
306