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