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