xref: /AOO41X/main/sc/source/ui/optdlg/tpcalc.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
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 
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 
105 __EXPORT ScTpCalcOptions::~ScTpCalcOptions()
106 {
107     delete pOldOptions;
108     delete pLocalOptions;
109 }
110 
111 //-----------------------------------------------------------------------
112 
113 void ScTpCalcOptions::Init()
114 {
115     aBtnIterate .SetClickHdl( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
116     aBtnGeneralPrec.SetClickHdl( LINK(this, ScTpCalcOptions, CheckClickHdl) );
117     aBtnDateStd .SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
118     aBtnDateSc10.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
119     aBtnDate1904.SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
120 }
121 
122 //-----------------------------------------------------------------------
123 
124 sal_uInt16* __EXPORT ScTpCalcOptions::GetRanges()
125 {
126     return pCalcOptRanges;
127 }
128 
129 //-----------------------------------------------------------------------
130 
131 SfxTabPage* __EXPORT ScTpCalcOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
132 {
133     return ( new ScTpCalcOptions( pParent, rAttrSet ) );
134 }
135 
136 //-----------------------------------------------------------------------
137 
138 void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
139 {
140     sal_uInt16  d,m,y;
141 
142     *pLocalOptions  = *pOldOptions;
143 
144     aBtnCase   .Check( !pLocalOptions->IsIgnoreCase() );
145     aBtnCalc   .Check( pLocalOptions->IsCalcAsShown() );
146     aBtnMatch  .Check( pLocalOptions->IsMatchWholeCell() );
147     aBtnRegex  .Check( pLocalOptions->IsFormulaRegexEnabled() );
148     aBtnLookUp .Check( pLocalOptions->IsLookUpColRowNames() );
149     aBtnIterate.Check( pLocalOptions->IsIter() );
150     aEdSteps   .SetValue( pLocalOptions->GetIterCount() );
151     aEdEps     .SetValue( pLocalOptions->GetIterEps(), 6 );
152 
153     pLocalOptions->GetDate( d, m, y );
154 
155     switch ( y )
156     {
157         case 1899:
158             aBtnDateStd.Check();
159             break;
160         case 1900:
161             aBtnDateSc10.Check();
162             break;
163         case 1904:
164             aBtnDate1904.Check();
165             break;
166     }
167 
168     sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
169     if (nPrec == SvNumberFormatter::UNLIMITED_PRECISION)
170     {
171         aFtPrec.Disable();
172         aEdPrec.Disable();
173         aBtnGeneralPrec.Check(false);
174     }
175     else
176     {
177         aBtnGeneralPrec.Check();
178         aFtPrec.Enable();
179         aEdPrec.Enable();
180         aEdPrec.SetValue(nPrec);
181     }
182 
183     CheckClickHdl( &aBtnIterate );
184 }
185 
186 
187 //-----------------------------------------------------------------------
188 
189 sal_Bool __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
190 {
191     // alle weiteren Optionen werden in den Handlern aktualisiert
192     pLocalOptions->SetIterCount( (sal_uInt16)aEdSteps.GetValue() );
193     pLocalOptions->SetIgnoreCase( !aBtnCase.IsChecked() );
194     pLocalOptions->SetCalcAsShown( aBtnCalc.IsChecked() );
195     pLocalOptions->SetMatchWholeCell( aBtnMatch.IsChecked() );
196     pLocalOptions->SetFormulaRegexEnabled( aBtnRegex.IsChecked() );
197     pLocalOptions->SetLookUpColRowNames( aBtnLookUp.IsChecked() );
198 
199     if (aBtnGeneralPrec.IsChecked())
200         pLocalOptions->SetStdPrecision(
201             static_cast<sal_uInt16>(aEdPrec.GetValue()) );
202     else
203         pLocalOptions->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION );
204 
205     if ( *pLocalOptions != *pOldOptions )
206     {
207         rCoreAttrs.Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
208         return sal_True;
209     }
210     else
211         return sal_False;
212 }
213 
214 //------------------------------------------------------------------------
215 
216 int __EXPORT ScTpCalcOptions::DeactivatePage( SfxItemSet* pSetP )
217 {
218     int nReturn = KEEP_PAGE;
219 
220     double fEps;
221     if( aEdEps.GetValue( fEps ) && (fEps > 0.0) )
222     {
223         pLocalOptions->SetIterEps( fEps );
224         nReturn = LEAVE_PAGE;
225     }
226 
227     if ( nReturn == KEEP_PAGE )
228     {
229         ErrorBox( this,
230                   WinBits( WB_OK | WB_DEF_OK ),
231                   ScGlobal::GetRscString( STR_INVALID_EPS )
232                 ).Execute();
233 
234         aEdEps.GrabFocus();
235     }
236     else if ( pSetP )
237         FillItemSet( *pSetP );
238 
239     return nReturn;
240 }
241 
242 //-----------------------------------------------------------------------
243 // Handler:
244 
245 IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
246 {
247     if ( pBtn == &aBtnDateStd )
248     {
249         pLocalOptions->SetDate( 30, 12, 1899 );
250     }
251     else if ( pBtn == &aBtnDateSc10 )
252     {
253         pLocalOptions->SetDate( 1, 1, 1900 );
254     }
255     else if ( pBtn == &aBtnDate1904 )
256     {
257         pLocalOptions->SetDate( 1, 1, 1904 );
258     }
259 
260     return 0;
261 }
262 
263 //-----------------------------------------------------------------------
264 
265 IMPL_LINK( ScTpCalcOptions, CheckClickHdl, CheckBox*, pBtn )
266 {
267     if (pBtn == &aBtnGeneralPrec)
268     {
269         if (pBtn->IsChecked())
270         {
271             aEdPrec.Enable();
272             aFtPrec.Enable();
273         }
274         else
275         {
276             aEdPrec.Disable();
277             aFtPrec.Disable();
278         }
279     }
280     else if (pBtn == &aBtnIterate)
281     {
282         if ( pBtn->IsChecked() )
283         {
284             pLocalOptions->SetIter( sal_True );
285             aFtSteps.Enable();  aEdSteps.Enable();
286             aFtEps  .Enable();  aEdEps  .Enable();
287         }
288         else
289         {
290             pLocalOptions->SetIter( sal_False );
291             aFtSteps.Disable(); aEdSteps.Disable();
292             aFtEps  .Disable(); aEdEps  .Disable();
293         }
294     }
295 
296     return 0;
297 }
298 
299 
300 
301 
302