Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / optdlg / tpcalc.cxx
blob4599a426595adc285f0a02f6953b0e3831ee8369
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "scitems.hxx"
23 #include <vcl/msgbox.hxx>
25 #include "global.hxx"
26 #include "globstr.hrc"
27 #include "uiitems.hxx"
28 #include "docsh.hxx"
29 #include "document.hxx"
30 #include "docoptio.hxx"
31 #include "scresid.hxx"
32 #include "sc.hrc"
34 #include "tpcalc.hxx"
36 #include <math.h>
38 ScTpCalcOptions::ScTpCalcOptions(vcl::Window* pParent, const SfxItemSet& rCoreAttrs)
39 : SfxTabPage(pParent, "OptCalculatePage",
40 "modules/scalc/ui/optcalculatepage.ui", &rCoreAttrs)
41 , pOldOptions(new ScDocOptions(
42 static_cast<const ScTpCalcItem&>(rCoreAttrs.Get(
43 GetWhich(SID_SCDOCOPTIONS))).GetDocOptions()))
44 , pLocalOptions(new ScDocOptions)
45 , nWhichCalc(GetWhich(SID_SCDOCOPTIONS))
47 get(m_pBtnIterate, "iterate");
48 get(m_pFtSteps, "stepsft");
49 get(m_pEdSteps, "steps");
50 get(m_pFtEps, "minchangeft");
51 get(m_pEdEps, "minchange");
52 get(m_pBtnDateStd, "datestd");
53 get(m_pBtnDateSc10, "datesc10");
54 get(m_pBtnDate1904, "date1904");
55 get(m_pBtnCase, "case");
56 get(m_pBtnCalc, "calc");
57 get(m_pBtnMatch, "match");
58 get(m_pBtnWildcards, "formulawildcards");
59 get(m_pBtnRegex, "formularegex");
60 get(m_pBtnLiteral, "formulaliteral");
61 get(m_pBtnLookUp, "lookup");
62 get(m_pBtnGeneralPrec, "generalprec");
63 get(m_pFtPrec, "precft");
64 get(m_pEdPrec, "prec");
65 Init();
66 SetExchangeSupport();
69 ScTpCalcOptions::~ScTpCalcOptions()
71 disposeOnce();
74 void ScTpCalcOptions::dispose()
76 delete pOldOptions;
77 delete pLocalOptions;
78 m_pBtnIterate.clear();
79 m_pFtSteps.clear();
80 m_pEdSteps.clear();
81 m_pFtEps.clear();
82 m_pEdEps.clear();
83 m_pBtnDateStd.clear();
84 m_pBtnDateSc10.clear();
85 m_pBtnDate1904.clear();
86 m_pBtnCase.clear();
87 m_pBtnCalc.clear();
88 m_pBtnMatch.clear();
89 m_pBtnWildcards.clear();
90 m_pBtnRegex.clear();
91 m_pBtnLiteral.clear();
92 m_pBtnLookUp.clear();
93 m_pBtnGeneralPrec.clear();
94 m_pFtPrec.clear();
95 m_pEdPrec.clear();
96 SfxTabPage::dispose();
99 void ScTpCalcOptions::Init()
101 m_pBtnIterate->SetClickHdl( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
102 m_pBtnGeneralPrec->SetClickHdl( LINK(this, ScTpCalcOptions, CheckClickHdl) );
103 m_pBtnDateStd->SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
104 m_pBtnDateSc10->SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
105 m_pBtnDate1904->SetClickHdl( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
108 VclPtr<SfxTabPage> ScTpCalcOptions::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
110 return VclPtr<ScTpCalcOptions>::Create( pParent, *rAttrSet );
113 void ScTpCalcOptions::Reset( const SfxItemSet* /* rCoreAttrs */ )
115 sal_uInt16 d,m,y;
117 *pLocalOptions = *pOldOptions;
119 m_pBtnCase->Check( !pLocalOptions->IsIgnoreCase() );
120 m_pBtnCalc->Check( pLocalOptions->IsCalcAsShown() );
121 m_pBtnMatch->Check( pLocalOptions->IsMatchWholeCell() );
122 bool bWildcards = pLocalOptions->IsFormulaWildcardsEnabled();
123 bool bRegex = pLocalOptions->IsFormulaRegexEnabled();
124 if (bWildcards && bRegex)
125 bRegex = false;
126 m_pBtnWildcards->Check( bWildcards );
127 m_pBtnRegex->Check( bRegex );
128 m_pBtnLiteral->Check( !bWildcards && !bRegex );
129 m_pBtnLookUp->Check( pLocalOptions->IsLookUpColRowNames() );
130 m_pBtnIterate->Check( pLocalOptions->IsIter() );
131 m_pEdSteps->SetValue( pLocalOptions->GetIterCount() );
132 m_pEdEps->SetValue( pLocalOptions->GetIterEps(), 6 );
134 pLocalOptions->GetDate( d, m, y );
136 switch ( y )
138 case 1899:
139 m_pBtnDateStd->Check();
140 break;
141 case 1900:
142 m_pBtnDateSc10->Check();
143 break;
144 case 1904:
145 m_pBtnDate1904->Check();
146 break;
149 sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
150 if (nPrec == SvNumberFormatter::UNLIMITED_PRECISION)
152 m_pFtPrec->Disable();
153 m_pEdPrec->Disable();
154 m_pBtnGeneralPrec->Check(false);
156 else
158 m_pBtnGeneralPrec->Check();
159 m_pFtPrec->Enable();
160 m_pEdPrec->Enable();
161 m_pEdPrec->SetValue(nPrec);
164 CheckClickHdl(m_pBtnIterate);
167 bool ScTpCalcOptions::FillItemSet( SfxItemSet* rCoreAttrs )
169 // alle weiteren Optionen werden in den Handlern aktualisiert
170 pLocalOptions->SetIterCount( (sal_uInt16)m_pEdSteps->GetValue() );
171 pLocalOptions->SetIgnoreCase( !m_pBtnCase->IsChecked() );
172 pLocalOptions->SetCalcAsShown( m_pBtnCalc->IsChecked() );
173 pLocalOptions->SetMatchWholeCell( m_pBtnMatch->IsChecked() );
174 pLocalOptions->SetFormulaWildcardsEnabled( m_pBtnWildcards->IsChecked() );
175 pLocalOptions->SetFormulaRegexEnabled( m_pBtnRegex->IsChecked() );
176 pLocalOptions->SetLookUpColRowNames( m_pBtnLookUp->IsChecked() );
178 if (m_pBtnGeneralPrec->IsChecked())
179 pLocalOptions->SetStdPrecision(
180 static_cast<sal_uInt16>(m_pEdPrec->GetValue()) );
181 else
182 pLocalOptions->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION );
184 if ( *pLocalOptions != *pOldOptions )
186 rCoreAttrs->Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
187 return true;
189 else
190 return false;
193 SfxTabPage::sfxpg ScTpCalcOptions::DeactivatePage( SfxItemSet* pSetP )
195 sfxpg nReturn = KEEP_PAGE;
197 double fEps;
198 if( m_pEdEps->GetValue( fEps ) && (fEps > 0.0) )
200 pLocalOptions->SetIterEps( fEps );
201 nReturn = LEAVE_PAGE;
204 if ( nReturn == KEEP_PAGE )
206 ScopedVclPtrInstance<MessageDialog>( this,
207 ScGlobal::GetRscString( STR_INVALID_EPS )
208 )->Execute();
210 m_pEdEps->GrabFocus();
212 else if ( pSetP )
213 FillItemSet( pSetP );
215 return nReturn;
218 // Handler:
220 IMPL_LINK_TYPED( ScTpCalcOptions, RadioClickHdl, Button*, pBtn, void )
222 if (pBtn == m_pBtnDateStd)
224 pLocalOptions->SetDate( 30, 12, 1899 );
226 else if (pBtn == m_pBtnDateSc10)
228 pLocalOptions->SetDate( 1, 1, 1900 );
230 else if (pBtn == m_pBtnDate1904)
232 pLocalOptions->SetDate( 1, 1, 1904 );
236 IMPL_LINK_TYPED( ScTpCalcOptions, CheckClickHdl, Button*, p, void )
238 CheckBox* pBtn = static_cast<CheckBox*>(p);
239 if (pBtn == m_pBtnGeneralPrec)
241 if (pBtn->IsChecked())
243 m_pEdPrec->Enable();
244 m_pFtPrec->Enable();
246 else
248 m_pEdPrec->Disable();
249 m_pFtPrec->Disable();
252 else if (pBtn == m_pBtnIterate)
254 if ( pBtn->IsChecked() )
256 pLocalOptions->SetIter( true );
257 m_pFtSteps->Enable(); m_pEdSteps->Enable();
258 m_pFtEps->Enable(); m_pEdEps->Enable();
260 else
262 pLocalOptions->SetIter( false );
263 m_pFtSteps->Disable(); m_pEdSteps->Disable();
264 m_pFtEps->Disable(); m_pEdEps->Disable();
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */