Update ooo320-m1
[ooovba.git] / sc / source / ui / optdlg / tpcalc.cxx
blob86a44764a07358aeb6a847ce86d2666388fe6811
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpcalc.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <vcl/msgbox.hxx>
43 #include "global.hxx"
44 #include "globstr.hrc"
45 #include "uiitems.hxx"
46 #include "docsh.hxx"
47 #include "document.hxx"
48 #include "docoptio.hxx"
49 #include "scresid.hxx"
50 #include "sc.hrc" // -> Slot-IDs
51 #include "optdlg.hrc"
53 #define _TPCALC_CXX
54 #include "tpcalc.hxx"
55 #undef _TPCALC_CXX
57 #include <math.h>
59 // STATIC DATA -----------------------------------------------------------
61 static USHORT pCalcOptRanges[] =
63 SID_SCDOCOPTIONS,
64 SID_SCDOCOPTIONS,
68 //========================================================================
70 ScTpCalcOptions::ScTpCalcOptions( Window* pParent,
71 const SfxItemSet& rCoreAttrs )
73 : SfxTabPage ( pParent,
74 ScResId( RID_SCPAGE_CALC ),
75 rCoreAttrs ),
77 aGbZRefs ( this, ScResId( GB_ZREFS ) ),
78 aBtnIterate ( this, ScResId( BTN_ITERATE ) ),
79 aFtSteps ( this, ScResId( FT_STEPS ) ),
80 aEdSteps ( this, ScResId( ED_STEPS ) ),
81 aFtEps ( this, ScResId( FT_EPS ) ),
82 aEdEps ( this, ScResId( ED_EPS ) ),
83 aSeparatorFL ( this, ScResId( FL_SEPARATOR ) ),
84 aGbDate ( this, ScResId( GB_DATE ) ),
85 aBtnDateStd ( this, ScResId( BTN_DATESTD ) ),
86 aBtnDateSc10 ( this, ScResId( BTN_DATESC10 ) ),
87 aBtnDate1904 ( this, ScResId( BTN_DATE1904 ) ),
88 aHSeparatorFL ( this, ScResId( FL_H_SEPARATOR ) ),
89 aBtnCase ( this, ScResId( BTN_CASE ) ),
90 aBtnCalc ( this, ScResId( BTN_CALC ) ),
91 aBtnMatch ( this, ScResId( BTN_MATCH ) ),
92 aBtnRegex ( this, ScResId( BTN_REGEX ) ),
93 aBtnLookUp ( this, ScResId( BTN_LOOKUP ) ),
94 aFtPrec ( this, ScResId( FT_PREC ) ),
95 aEdPrec ( this, ScResId( ED_PREC ) ),
96 pOldOptions ( new ScDocOptions(
97 ((const ScTpCalcItem&)rCoreAttrs.Get(
98 GetWhich( SID_SCDOCOPTIONS ))).
99 GetDocOptions() ) ),
100 pLocalOptions ( new ScDocOptions ),
101 nWhichCalc ( GetWhich( SID_SCDOCOPTIONS ) )
103 aSeparatorFL.SetStyle( aSeparatorFL.GetStyle() | WB_VERT );
104 Init();
105 FreeResource();
106 SetExchangeSupport();
109 //-----------------------------------------------------------------------
111 __EXPORT ScTpCalcOptions::~ScTpCalcOptions()
113 delete pOldOptions;
114 delete pLocalOptions;
117 //-----------------------------------------------------------------------
119 void ScTpCalcOptions::Init()
121 aBtnIterate .SetClickHdl( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
122 aBtnDateStd .SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
123 aBtnDateSc10.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
124 aBtnDate1904.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
127 //-----------------------------------------------------------------------
129 USHORT* __EXPORT ScTpCalcOptions::GetRanges()
131 return pCalcOptRanges;
134 //-----------------------------------------------------------------------
136 SfxTabPage* __EXPORT ScTpCalcOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
138 return ( new ScTpCalcOptions( pParent, rAttrSet ) );
141 //-----------------------------------------------------------------------
143 void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
145 USHORT d,m,y;
147 *pLocalOptions = *pOldOptions;
149 aBtnCase .Check( !pLocalOptions->IsIgnoreCase() );
150 aBtnCalc .Check( pLocalOptions->IsCalcAsShown() );
151 aBtnMatch .Check( pLocalOptions->IsMatchWholeCell() );
152 aBtnRegex .Check( pLocalOptions->IsFormulaRegexEnabled() );
153 aBtnLookUp .Check( pLocalOptions->IsLookUpColRowNames() );
154 aBtnIterate.Check( pLocalOptions->IsIter() );
155 aEdSteps .SetValue( pLocalOptions->GetIterCount() );
156 aEdPrec .SetValue( pLocalOptions->GetStdPrecision() );
157 aEdEps .SetValue( pLocalOptions->GetIterEps(), 6 );
159 pLocalOptions->GetDate( d, m, y );
161 switch ( y )
163 case 1899:
164 aBtnDateStd.Check();
165 break;
166 case 1900:
167 aBtnDateSc10.Check();
168 break;
169 case 1904:
170 aBtnDate1904.Check();
171 break;
174 CheckClickHdl( &aBtnIterate );
178 //-----------------------------------------------------------------------
180 BOOL __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
182 // alle weiteren Optionen werden in den Handlern aktualisiert
183 pLocalOptions->SetIterCount( (USHORT)aEdSteps.GetValue() );
184 pLocalOptions->SetStdPrecision( (USHORT)aEdPrec.GetValue() );
185 pLocalOptions->SetIgnoreCase( !aBtnCase.IsChecked() );
186 pLocalOptions->SetCalcAsShown( aBtnCalc.IsChecked() );
187 pLocalOptions->SetMatchWholeCell( aBtnMatch.IsChecked() );
188 pLocalOptions->SetFormulaRegexEnabled( aBtnRegex.IsChecked() );
189 pLocalOptions->SetLookUpColRowNames( aBtnLookUp.IsChecked() );
191 if ( *pLocalOptions != *pOldOptions )
193 rCoreAttrs.Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
194 return TRUE;
196 else
197 return FALSE;
200 //------------------------------------------------------------------------
202 int __EXPORT ScTpCalcOptions::DeactivatePage( SfxItemSet* pSetP )
204 int nReturn = KEEP_PAGE;
206 double fEps;
207 if( aEdEps.GetValue( fEps ) && (fEps > 0.0) )
209 pLocalOptions->SetIterEps( fEps );
210 nReturn = LEAVE_PAGE;
213 if ( nReturn == KEEP_PAGE )
215 ErrorBox( this,
216 WinBits( WB_OK | WB_DEF_OK ),
217 ScGlobal::GetRscString( STR_INVALID_EPS )
218 ).Execute();
220 aEdEps.GrabFocus();
222 else if ( pSetP )
223 FillItemSet( *pSetP );
225 return nReturn;
228 //-----------------------------------------------------------------------
229 // Handler:
231 IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
233 if ( pBtn == &aBtnDateStd )
235 pLocalOptions->SetDate( 30, 12, 1899 );
237 else if ( pBtn == &aBtnDateSc10 )
239 pLocalOptions->SetDate( 1, 1, 1900 );
241 else if ( pBtn == &aBtnDate1904 )
243 pLocalOptions->SetDate( 1, 1, 1904 );
246 return 0;
249 //-----------------------------------------------------------------------
251 IMPL_LINK( ScTpCalcOptions, CheckClickHdl, CheckBox*, pBtn )
253 if ( pBtn->IsChecked() )
255 pLocalOptions->SetIter( TRUE );
256 aFtSteps.Enable(); aEdSteps.Enable();
257 aFtEps .Enable(); aEdEps .Enable();
259 else
261 pLocalOptions->SetIter( FALSE );
262 aFtSteps.Disable(); aEdSteps.Disable();
263 aFtEps .Disable(); aEdEps .Disable();
266 return 0;