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
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 rCoreAttrs.Get(SID_SCDOCOPTIONS).GetDocOptions()))
39 , pLocalOptions(new ScDocOptions)
40 , m_xBtnIterate(m_xBuilder->weld_check_button("iterate"))
41 , m_xFtSteps(m_xBuilder->weld_label("stepsft"))
42 , m_xEdSteps(m_xBuilder->weld_spin_button("steps"))
43 , m_xFtEps(m_xBuilder->weld_label("minchangeft"))
44 , m_xEdEps(new ScDoubleField(m_xBuilder->weld_entry("minchange")))
45 , m_xBtnDateStd(m_xBuilder->weld_radio_button("datestd"))
46 , m_xBtnDateSc10(m_xBuilder->weld_radio_button("datesc10"))
47 , m_xBtnDate1904(m_xBuilder->weld_radio_button("date1904"))
48 , m_xBtnCase(m_xBuilder->weld_check_button("case"))
49 , m_xBtnCalc(m_xBuilder->weld_check_button("calc"))
50 , m_xBtnMatch(m_xBuilder->weld_check_button("match"))
51 , m_xBtnWildcards(m_xBuilder->weld_radio_button("formulawildcards"))
52 , m_xBtnRegex(m_xBuilder->weld_radio_button("formularegex"))
53 , m_xBtnLiteral(m_xBuilder->weld_radio_button("formulaliteral"))
54 , m_xBtnLookUp(m_xBuilder->weld_check_button("lookup"))
55 , m_xBtnGeneralPrec(m_xBuilder->weld_check_button("generalprec"))
56 , m_xFtPrec(m_xBuilder->weld_label("precft"))
57 , m_xEdPrec(m_xBuilder->weld_spin_button("prec"))
58 , m_xBtnThread(m_xBuilder->weld_check_button("threadingenabled"))
59{
60 Init();
62}
63
65{
66}
67
69{
70 m_xBtnIterate->connect_toggled( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
71 m_xBtnGeneralPrec->connect_toggled( LINK(this, ScTpCalcOptions, CheckClickHdl) );
72 m_xBtnDateStd->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
73 m_xBtnDateSc10->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
74 m_xBtnDate1904->connect_toggled( LINK( this, ScTpCalcOptions, RadioClickHdl ) );
75 m_xBtnThread->connect_toggled( LINK( this, ScTpCalcOptions, CheckClickHdl ) );
76}
77
78std::unique_ptr<SfxTabPage> ScTpCalcOptions::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
79{
80 return std::make_unique<ScTpCalcOptions>( pPage, pController, *rAttrSet );
81}
82
83void ScTpCalcOptions::Reset(const SfxItemSet* rCoreAttrs)
84{
85 sal_uInt16 d,m;
86 sal_Int16 y;
87
88 pOldOptions.reset(new ScDocOptions(
89 rCoreAttrs->Get(SID_SCDOCOPTIONS).GetDocOptions()));
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 m_xEdPrec->set_value(0);
147 }
148 else
149 {
150 m_xBtnGeneralPrec->set_active(true);
151 m_xFtPrec->set_sensitive(true);
152 m_xEdPrec->set_sensitive(true);
153 m_xEdPrec->set_value(nPrec);
154 }
155
156 m_xBtnThread->set_sensitive( !officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::isReadOnly() );
157 m_xBtnThread->set_active( officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get() );
158
159 CheckClickHdl(*m_xBtnIterate);
160}
161
163{
164 // every other options are updated in handlers
165 pLocalOptions->SetIterCount( static_cast<sal_uInt16>(m_xEdSteps->get_value()) );
166 pLocalOptions->SetIgnoreCase( !m_xBtnCase->get_active() );
167 pLocalOptions->SetCalcAsShown( m_xBtnCalc->get_active() );
168 pLocalOptions->SetMatchWholeCell( m_xBtnMatch->get_active() );
169 pLocalOptions->SetFormulaWildcardsEnabled( m_xBtnWildcards->get_active() );
170 pLocalOptions->SetFormulaRegexEnabled( m_xBtnRegex->get_active() );
171 pLocalOptions->SetLookUpColRowNames( m_xBtnLookUp->get_active() );
172
173 if (m_xBtnGeneralPrec->get_active())
174 pLocalOptions->SetStdPrecision(
175 static_cast<sal_uInt16>(m_xEdPrec->get_value()) );
176 else
178
179 bool bShouldEnableThreading = m_xBtnThread->get_active();
180 if (bShouldEnableThreading != officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get())
181 {
182 std::shared_ptr<comphelper::ConfigurationChanges> xBatch(comphelper::ConfigurationChanges::create());
183 officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::set(bShouldEnableThreading, xBatch);
184 xBatch->commit();
185 SolarMutexGuard aGuard;
189 GetDialogController()->response(RET_OK);
190 }
191 if ( *pLocalOptions != *pOldOptions )
192 {
193 rCoreAttrs->Put( ScTpCalcItem( SID_SCDOCOPTIONS, *pLocalOptions ) );
194 return true;
195 }
196 else
197 return false;
198}
199
201{
202 DeactivateRC nReturn = DeactivateRC::KeepPage;
203
204 double fEps;
205 if( m_xEdEps->GetValue( fEps ) && (fEps > 0.0) )
206 {
207 pLocalOptions->SetIterEps( fEps );
208 nReturn = DeactivateRC::LeavePage;
209 }
210
211 if ( nReturn == DeactivateRC::KeepPage )
212 {
213 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning,
214 VclButtonsType::Ok, ScResId(STR_INVALID_EPS)));
215 xBox->run();
216
217 m_xEdEps->grab_focus();
218 }
219 else if ( pSetP )
220 FillItemSet( pSetP );
221
222 return nReturn;
223}
224
225// Handler:
226
227IMPL_LINK( ScTpCalcOptions, RadioClickHdl, weld::Toggleable&, rBtn, void )
228{
229 if (!rBtn.get_active())
230 return;
231 if (m_xBtnDateStd->get_active())
232 {
233 pLocalOptions->SetDate( 30, 12, 1899 );
234 }
235 else if (m_xBtnDateSc10->get_active())
236 {
237 pLocalOptions->SetDate( 1, 1, 1900 );
238 }
239 else if (m_xBtnDate1904->get_active())
240 {
241 pLocalOptions->SetDate( 1, 1, 1904 );
242 }
243}
244
245IMPL_LINK(ScTpCalcOptions, CheckClickHdl, weld::Toggleable&, rBtn, void)
246{
247 if (&rBtn == m_xBtnGeneralPrec.get())
248 {
249 if (rBtn.get_active())
250 {
251 m_xEdPrec->set_sensitive(true);
252 m_xFtPrec->set_sensitive(true);
253 }
254 else
255 {
256 m_xEdPrec->set_sensitive(false);
257 m_xFtPrec->set_sensitive(false);
258 }
259 }
260 else if (&rBtn == m_xBtnIterate.get())
261 {
262 if (rBtn.get_active())
263 {
264 pLocalOptions->SetIter( true );
265 m_xFtSteps->set_sensitive(true); m_xEdSteps->set_sensitive(true);
266 m_xFtEps->set_sensitive(true); m_xEdEps->set_sensitive(true);
267 }
268 else
269 {
270 pLocalOptions->SetIter( false );
271 m_xFtSteps->set_sensitive(false); m_xEdSteps->set_sensitive(false);
272 m_xFtEps->set_sensitive(false); m_xEdEps->set_sensitive(false);
273 }
274 }
275}
276
277/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
An edit control that contains a double precision floating-point value.
Definition: editfield.hxx:26
std::unique_ptr< ScDoubleField > m_xEdEps
Definition: tpcalc.hxx:45
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
Definition: tpcalc.cxx:78
std::unique_ptr< weld::CheckButton > m_xBtnThread
Definition: tpcalc.hxx:63
std::unique_ptr< weld::RadioButton > m_xBtnDateSc10
Definition: tpcalc.hxx:48
std::unique_ptr< ScDocOptions > pLocalOptions
Definition: tpcalc.hxx:39
std::unique_ptr< weld::SpinButton > m_xEdPrec
Definition: tpcalc.hxx:61
virtual ~ScTpCalcOptions() override
Definition: tpcalc.cxx:64
std::unique_ptr< weld::RadioButton > m_xBtnWildcards
Definition: tpcalc.hxx:54
std::unique_ptr< weld::RadioButton > m_xBtnDateStd
Definition: tpcalc.hxx:47
std::unique_ptr< weld::Label > m_xFtPrec
Definition: tpcalc.hxx:60
std::unique_ptr< weld::RadioButton > m_xBtnLiteral
Definition: tpcalc.hxx:56
virtual void Reset(const SfxItemSet *rCoreSet) override
Definition: tpcalc.cxx:83
std::unique_ptr< weld::CheckButton > m_xBtnIterate
Definition: tpcalc.hxx:41
ScTpCalcOptions(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rCoreSet)
Definition: tpcalc.cxx:35
std::unique_ptr< weld::CheckButton > m_xBtnGeneralPrec
Definition: tpcalc.hxx:58
std::unique_ptr< weld::CheckButton > m_xBtnMatch
Definition: tpcalc.hxx:53
std::unique_ptr< weld::CheckButton > m_xBtnCase
Definition: tpcalc.hxx:51
std::unique_ptr< weld::RadioButton > m_xBtnDate1904
Definition: tpcalc.hxx:49
std::unique_ptr< weld::CheckButton > m_xBtnLookUp
Definition: tpcalc.hxx:57
std::unique_ptr< weld::SpinButton > m_xEdSteps
Definition: tpcalc.hxx:43
void Init()
Definition: tpcalc.cxx:68
std::unique_ptr< weld::CheckButton > m_xBtnCalc
Definition: tpcalc.hxx:52
std::unique_ptr< ScDocOptions > pOldOptions
Definition: tpcalc.hxx:38
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpcalc.cxx:200
std::unique_ptr< weld::RadioButton > m_xBtnRegex
Definition: tpcalc.hxx:55
virtual bool FillItemSet(SfxItemSet *rCoreSet) override
Definition: tpcalc.cxx:162
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SfxOkDialogController * GetDialogController() const
void SetExchangeSupport()
weld::Window * GetFrameWeld() const
static const sal_uInt16 UNLIMITED_PRECISION
static std::shared_ptr< ConfigurationChanges > create()
float y
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
Reference< XComponentContext > getProcessComponentContext()
m
RESTART_REASON_THREADING
SVT_DLLPUBLIC bool executeRestartDialog(css::uno::Reference< css::uno::XComponentContext > const &context, weld::Window *parent, RestartReason reason)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
DeactivateRC
IMPL_LINK(ScTpCalcOptions, RadioClickHdl, weld::Toggleable &, rBtn, void)
Definition: tpcalc.cxx:227
RET_OK