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