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