LibreOffice Module sc (master)  1
tpcalc.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #undef SC_DLLIMPLEMENTATION
21 
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <svl/numformat.hxx>
25 #include <svl/zforlist.hxx>
26 
27 #include <globstr.hrc>
28 #include <scresid.hxx>
29 #include <docoptio.hxx>
30 #include <sc.hrc>
31 #include <officecfg/Office/Calc.hxx>
33 
34 #include <tpcalc.hxx>
35 
37  : SfxTabPage(pPage, pController, "modules/scalc/ui/optcalculatepage.ui", "OptCalculatePage", &rCoreAttrs)
38  , pOldOptions(new ScDocOptions(
39  static_cast<const ScTpCalcItem&>(rCoreAttrs.Get(
40  GetWhich(SID_SCDOCOPTIONS))).GetDocOptions()))
41  , pLocalOptions(new ScDocOptions)
42  , nWhichCalc(GetWhich(SID_SCDOCOPTIONS))
43  , m_xBtnIterate(m_xBuilder->weld_check_button("iterate"))
44  , m_xFtSteps(m_xBuilder->weld_label("stepsft"))
45  , m_xEdSteps(m_xBuilder->weld_spin_button("steps"))
46  , m_xFtEps(m_xBuilder->weld_label("minchangeft"))
47  , m_xEdEps(new ScDoubleField(m_xBuilder->weld_entry("minchange")))
48  , m_xBtnDateStd(m_xBuilder->weld_radio_button("datestd"))
49  , m_xBtnDateSc10(m_xBuilder->weld_radio_button("datesc10"))
50  , m_xBtnDate1904(m_xBuilder->weld_radio_button("date1904"))
51  , m_xBtnCase(m_xBuilder->weld_check_button("case"))
52  , m_xBtnCalc(m_xBuilder->weld_check_button("calc"))
53  , m_xBtnMatch(m_xBuilder->weld_check_button("match"))
54  , m_xBtnWildcards(m_xBuilder->weld_radio_button("formulawildcards"))
55  , m_xBtnRegex(m_xBuilder->weld_radio_button("formularegex"))
56  , m_xBtnLiteral(m_xBuilder->weld_radio_button("formulaliteral"))
57  , m_xBtnLookUp(m_xBuilder->weld_check_button("lookup"))
58  , m_xBtnGeneralPrec(m_xBuilder->weld_check_button("generalprec"))
59  , m_xFtPrec(m_xBuilder->weld_label("precft"))
60  , m_xEdPrec(m_xBuilder->weld_spin_button("prec"))
61  , m_xBtnThread(m_xBuilder->weld_check_button("threadingenabled"))
62 {
63  Init();
65 }
66 
68 {
69 }
70 
72 {
73  m_xBtnIterate->connect_toggled( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
74  m_xBtnGeneralPrec->connect_toggled( LINK(this, ScTpCalcOptions, CheckClickHdl) );
75  m_xBtnDateStd->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
76  m_xBtnDateSc10->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
77  m_xBtnDate1904->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
78  m_xBtnThread->connect_toggled( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
79 }
80 
81 std::unique_ptr<SfxTabPage> ScTpCalcOptions::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
82 {
83  return std::make_unique<ScTpCalcOptions>( pPage, pController, *rAttrSet );
84 }
85 
86 void ScTpCalcOptions::Reset( const SfxItemSet* /* rCoreAttrs */ )
87 {
88  sal_uInt16 d,m;
89  sal_Int16 y;
90 
92 
93  m_xBtnCase->set_active( !pLocalOptions->IsIgnoreCase() );
94  m_xBtnCase->set_sensitive( !officecfg::Office::Calc::Calculate::Other::CaseSensitive::isReadOnly() );
95  m_xBtnCalc->set_active( pLocalOptions->IsCalcAsShown() );
96  m_xBtnCalc->set_sensitive( !officecfg::Office::Calc::Calculate::Other::Precision::isReadOnly() );
97  m_xBtnMatch->set_active( pLocalOptions->IsMatchWholeCell() );
98  m_xBtnMatch->set_sensitive( !officecfg::Office::Calc::Calculate::Other::SearchCriteria::isReadOnly() );
99  bool bWildcards = pLocalOptions->IsFormulaWildcardsEnabled();
100  bool bRegex = pLocalOptions->IsFormulaRegexEnabled();
101  // If both, Wildcards and Regex, are set then Wildcards shall take
102  // precedence. This is also how other code calling Search handles it. Both
103  // simultaneously couldn't be set using UI but editing the configuration.
104  if (bWildcards && bRegex)
105  bRegex = false;
106  m_xBtnWildcards->set_active( bWildcards );
107  m_xBtnRegex->set_active( bRegex );
108  m_xBtnWildcards->set_sensitive( !officecfg::Office::Calc::Calculate::Other::Wildcards::isReadOnly() );
109  m_xBtnRegex->set_sensitive( !officecfg::Office::Calc::Calculate::Other::RegularExpressions::isReadOnly() );
110  m_xBtnLiteral->set_active( !bWildcards && !bRegex );
111  m_xBtnLiteral->set_sensitive( m_xBtnWildcards->get_sensitive() || m_xBtnRegex->get_sensitive() );
112  // if either regex or wildcards radio button is set and read-only, disable all three
113  if ( (!m_xBtnWildcards->get_sensitive() && bWildcards) || (!m_xBtnRegex->get_sensitive() && bRegex) )
114  {
115  m_xBtnWildcards->set_sensitive( false );
116  m_xBtnRegex->set_sensitive( false );
117  m_xBtnLiteral->set_sensitive( false );
118  }
119  m_xBtnLookUp->set_active( pLocalOptions->IsLookUpColRowNames() );
120  m_xBtnLookUp->set_sensitive( !officecfg::Office::Calc::Calculate::Other::FindLabel::isReadOnly() );
121  m_xBtnIterate->set_active( pLocalOptions->IsIter() );
122  m_xEdSteps->set_value( pLocalOptions->GetIterCount() );
123  m_xEdEps->SetValue( pLocalOptions->GetIterEps(), 6 );
124 
125  pLocalOptions->GetDate( d, m, y );
126 
127  switch ( y )
128  {
129  case 1899:
130  m_xBtnDateStd->set_active(true);
131  break;
132  case 1900:
133  m_xBtnDateSc10->set_active(true);
134  break;
135  case 1904:
136  m_xBtnDate1904->set_active(true);
137  break;
138  }
139 
140  sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
142  {
143  m_xFtPrec->set_sensitive(false);
144  m_xEdPrec->set_sensitive(false);
145  m_xBtnGeneralPrec->set_active(false);
146  }
147  else
148  {
149  m_xBtnGeneralPrec->set_active(true);
150  m_xFtPrec->set_sensitive(true);
151  m_xEdPrec->set_sensitive(true);
152  m_xEdPrec->set_value(nPrec);
153  }
154 
155  m_xBtnThread->set_sensitive( !officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::isReadOnly() );
156  m_xBtnThread->set_active( officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get() );
157 
158  CheckClickHdl(*m_xBtnIterate);
159 }
160 
162 {
163  // every other options are updated in handlers
164  pLocalOptions->SetIterCount( static_cast<sal_uInt16>(m_xEdSteps->get_value()) );
165  pLocalOptions->SetIgnoreCase( !m_xBtnCase->get_active() );
166  pLocalOptions->SetCalcAsShown( m_xBtnCalc->get_active() );
167  pLocalOptions->SetMatchWholeCell( m_xBtnMatch->get_active() );
168  pLocalOptions->SetFormulaWildcardsEnabled( m_xBtnWildcards->get_active() );
169  pLocalOptions->SetFormulaRegexEnabled( m_xBtnRegex->get_active() );
170  pLocalOptions->SetLookUpColRowNames( m_xBtnLookUp->get_active() );
171 
172  if (m_xBtnGeneralPrec->get_active())
173  pLocalOptions->SetStdPrecision(
174  static_cast<sal_uInt16>(m_xEdPrec->get_value()) );
175  else
177 
178  bool bShouldEnableThreading = m_xBtnThread->get_active();
179  if (bShouldEnableThreading != officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get())
180  {
181  std::shared_ptr<comphelper::ConfigurationChanges> xBatch(comphelper::ConfigurationChanges::create());
182  officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::set(bShouldEnableThreading, xBatch);
183  xBatch->commit();
184  SolarMutexGuard aGuard;
188  GetDialogController()->response(RET_OK);
189  }
190  if ( *pLocalOptions != *pOldOptions )
191  {
192  rCoreAttrs->Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
193  return true;
194  }
195  else
196  return false;
197 }
198 
200 {
201  DeactivateRC nReturn = DeactivateRC::KeepPage;
202 
203  double fEps;
204  if( m_xEdEps->GetValue( fEps ) && (fEps > 0.0) )
205  {
206  pLocalOptions->SetIterEps( fEps );
207  nReturn = DeactivateRC::LeavePage;
208  }
209 
210  if ( nReturn == DeactivateRC::KeepPage )
211  {
212  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning,
213  VclButtonsType::Ok, ScResId(STR_INVALID_EPS)));
214  xBox->run();
215 
216  m_xEdEps->grab_focus();
217  }
218  else if ( pSetP )
219  FillItemSet( pSetP );
220 
221  return nReturn;
222 }
223 
224 // Handler:
225 
226 IMPL_LINK( ScTpCalcOptions, RadioClickHdl, weld::Toggleable&, rBtn, void )
227 {
228  if (!rBtn.get_active())
229  return;
230  if (m_xBtnDateStd->get_active())
231  {
232  pLocalOptions->SetDate( 30, 12, 1899 );
233  }
234  else if (m_xBtnDateSc10->get_active())
235  {
236  pLocalOptions->SetDate( 1, 1, 1900 );
237  }
238  else if (m_xBtnDate1904->get_active())
239  {
240  pLocalOptions->SetDate( 1, 1, 1904 );
241  }
242 }
243 
244 IMPL_LINK(ScTpCalcOptions, CheckClickHdl, weld::Toggleable&, rBtn, void)
245 {
246  if (&rBtn == m_xBtnGeneralPrec.get())
247  {
248  if (rBtn.get_active())
249  {
250  m_xEdPrec->set_sensitive(true);
251  m_xFtPrec->set_sensitive(true);
252  }
253  else
254  {
255  m_xEdPrec->set_sensitive(false);
256  m_xFtPrec->set_sensitive(false);
257  }
258  }
259  else if (&rBtn == m_xBtnIterate.get())
260  {
261  if (rBtn.get_active())
262  {
263  pLocalOptions->SetIter( true );
264  m_xFtSteps->set_sensitive(true); m_xEdSteps->set_sensitive(true);
265  m_xFtEps->set_sensitive(true); m_xEdEps->set_sensitive(true);
266  }
267  else
268  {
269  pLocalOptions->SetIter( false );
270  m_xFtSteps->set_sensitive(false); m_xEdSteps->set_sensitive(false);
271  m_xFtEps->set_sensitive(false); m_xEdEps->set_sensitive(false);
272  }
273  }
274 }
275 
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::CheckButton > m_xBtnCase
Definition: tpcalc.hxx:52
std::unique_ptr< weld::CheckButton > m_xBtnThread
Definition: tpcalc.hxx:64
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
RESTART_REASON_THREADING
virtual void Reset(const SfxItemSet *rCoreSet) override
Definition: tpcalc.cxx:86
virtual bool FillItemSet(SfxItemSet *rCoreSet) override
Definition: tpcalc.cxx:161
virtual ~ScTpCalcOptions() override
Definition: tpcalc.cxx:67
std::unique_ptr< weld::SpinButton > m_xEdPrec
Definition: tpcalc.hxx:62
std::unique_ptr< weld::RadioButton > m_xBtnRegex
Definition: tpcalc.hxx:56
std::unique_ptr< ScDoubleField > m_xEdEps
Definition: tpcalc.hxx:46
ScTpCalcOptions(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rCoreSet)
Definition: tpcalc.cxx:36
std::unique_ptr< weld::RadioButton > m_xBtnDate1904
Definition: tpcalc.hxx:50
void SetExchangeSupport()
std::unique_ptr< weld::CheckButton > m_xBtnMatch
Definition: tpcalc.hxx:54
static std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpcalc.cxx:199
std::unique_ptr< weld::RadioButton > m_xBtnWildcards
Definition: tpcalc.hxx:55
double d
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
Definition: tpcalc.cxx:81
float y
sal_uInt16 nWhichCalc
Definition: tpcalc.hxx:40
SVT_DLLPUBLIC bool executeRestartDialog(css::uno::Reference< css::uno::XComponentContext > const &context, weld::Window *parent, RestartReason reason)
IMPL_LINK(ScTpCalcOptions, RadioClickHdl, weld::Toggleable &, rBtn, void)
Definition: tpcalc.cxx:226
An edit control that contains a double precision floating-point value.
Definition: editfield.hxx:25
std::unique_ptr< ScDocOptions > pOldOptions
Definition: tpcalc.hxx:38
static const sal_uInt16 UNLIMITED_PRECISION
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::CheckButton > m_xBtnGeneralPrec
Definition: tpcalc.hxx:59
weld::Window * GetFrameWeld() const
#define GetWhich(nSlot)
std::unique_ptr< weld::CheckButton > m_xBtnCalc
Definition: tpcalc.hxx:53
RET_OK
Reference< XComponentContext > getProcessComponentContext()
SfxOkDialogController * GetDialogController() const
std::unique_ptr< weld::SpinButton > m_xEdSteps
Definition: tpcalc.hxx:44
std::unique_ptr< weld::Label > m_xFtPrec
Definition: tpcalc.hxx:61
std::unique_ptr< weld::CheckButton > m_xBtnLookUp
Definition: tpcalc.hxx:58
DeactivateRC
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
std::unique_ptr< weld::RadioButton > m_xBtnDateStd
Definition: tpcalc.hxx:48
tuple m
std::unique_ptr< ScDocOptions > pLocalOptions
Definition: tpcalc.hxx:39
std::unique_ptr< weld::CheckButton > m_xBtnIterate
Definition: tpcalc.hxx:42
void Init()
Definition: tpcalc.cxx:71
std::unique_ptr< weld::RadioButton > m_xBtnDateSc10
Definition: tpcalc.hxx:49
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
std::unique_ptr< weld::RadioButton > m_xBtnLiteral
Definition: tpcalc.hxx:57