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