1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <svl/numformat.hxx>
26 #include <globstr.hrc>
27 #include <scresid.hxx>
28 #include <docoptio.hxx>
30 #include <officecfg/Office/Calc.hxx>
31 #include <svtools/restartdialog.hxx>
35 ScTpCalcOptions::ScTpCalcOptions(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rCoreAttrs
)
36 : SfxTabPage(pPage
, pController
, u
"modules/scalc/ui/optcalculatepage.ui"_ustr
, u
"OptCalculatePage"_ustr
, &rCoreAttrs
)
37 , pOldOptions(new ScDocOptions(
38 rCoreAttrs
.Get(SID_SCDOCOPTIONS
).GetDocOptions()))
39 , pLocalOptions(new ScDocOptions
)
40 , m_xBtnIterate(m_xBuilder
->weld_check_button(u
"iterate"_ustr
))
41 , m_xBtnIterateImg(m_xBuilder
->weld_widget(u
"lockiterate"_ustr
))
42 , m_xFtSteps(m_xBuilder
->weld_label(u
"stepsft"_ustr
))
43 , m_xEdSteps(m_xBuilder
->weld_spin_button(u
"steps"_ustr
))
44 , m_xEdStepsImg(m_xBuilder
->weld_widget(u
"locksteps"_ustr
))
45 , m_xFtEps(m_xBuilder
->weld_label(u
"minchangeft"_ustr
))
46 , m_xEdEps(new ScDoubleField(m_xBuilder
->weld_entry(u
"minchange"_ustr
)))
47 , m_xEdEpsImg(m_xBuilder
->weld_widget(u
"lockminchange"_ustr
))
48 , m_xBtnDateStd(m_xBuilder
->weld_radio_button(u
"datestd"_ustr
))
49 , m_xBtnDateSc10(m_xBuilder
->weld_radio_button(u
"datesc10"_ustr
))
50 , m_xBtnDate1904(m_xBuilder
->weld_radio_button(u
"date1904"_ustr
))
51 , m_xDateImg(m_xBuilder
->weld_widget(u
"lockdate"_ustr
))
52 , m_xBtnCase(m_xBuilder
->weld_check_button(u
"case"_ustr
))
53 , m_xBtnCaseImg(m_xBuilder
->weld_widget(u
"lockcase"_ustr
))
54 , m_xBtnCalc(m_xBuilder
->weld_check_button(u
"calc"_ustr
))
55 , m_xBtnCalcImg(m_xBuilder
->weld_widget(u
"lockcalc"_ustr
))
56 , m_xBtnMatch(m_xBuilder
->weld_check_button(u
"match"_ustr
))
57 , m_xBtnMatchImg(m_xBuilder
->weld_widget(u
"lockmatch"_ustr
))
58 , m_xBtnWildcards(m_xBuilder
->weld_radio_button(u
"formulawildcards"_ustr
))
59 , m_xBtnRegex(m_xBuilder
->weld_radio_button(u
"formularegex"_ustr
))
60 , m_xBtnLiteral(m_xBuilder
->weld_radio_button(u
"formulaliteral"_ustr
))
61 , m_xFormulaImg(m_xBuilder
->weld_widget(u
"lockformulawild"_ustr
))
62 , m_xBtnLookUp(m_xBuilder
->weld_check_button(u
"lookup"_ustr
))
63 , m_xBtnLookUpImg(m_xBuilder
->weld_widget(u
"locklookup"_ustr
))
64 , m_xBtnGeneralPrec(m_xBuilder
->weld_check_button(u
"generalprec"_ustr
))
65 , m_xBtnGeneralPrecImg(m_xBuilder
->weld_widget(u
"lockgeneralprec"_ustr
))
66 , m_xFtPrec(m_xBuilder
->weld_label(u
"precft"_ustr
))
67 , m_xEdPrec(m_xBuilder
->weld_spin_button(u
"prec"_ustr
))
68 , m_xEdPrecImg(m_xBuilder
->weld_widget(u
"lockprec"_ustr
))
69 , m_xBtnThread(m_xBuilder
->weld_check_button(u
"threadingenabled"_ustr
))
70 , m_xBtnThreadImg(m_xBuilder
->weld_widget(u
"lockthreadingenabled"_ustr
))
75 const css::uno::Reference
< css::uno::XComponentContext
>& xContext(::comphelper::getProcessComponentContext());
76 m_xReadWriteAccess
= css::configuration::ReadWriteAccess::create(xContext
, u
"*"_ustr
);
79 ScTpCalcOptions::~ScTpCalcOptions()
83 void ScTpCalcOptions::Init()
85 m_xBtnIterate
->connect_toggled( LINK( this, ScTpCalcOptions
, CheckClickHdl
) );
86 m_xBtnGeneralPrec
->connect_toggled( LINK(this, ScTpCalcOptions
, CheckClickHdl
) );
87 m_xBtnDateStd
->connect_toggled( LINK( this, ScTpCalcOptions
, RadioClickHdl
) );
88 m_xBtnDateSc10
->connect_toggled( LINK( this, ScTpCalcOptions
, RadioClickHdl
) );
89 m_xBtnDate1904
->connect_toggled( LINK( this, ScTpCalcOptions
, RadioClickHdl
) );
90 m_xBtnThread
->connect_toggled( LINK( this, ScTpCalcOptions
, CheckClickHdl
) );
93 std::unique_ptr
<SfxTabPage
> ScTpCalcOptions::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
95 return std::make_unique
<ScTpCalcOptions
>( pPage
, pController
, *rAttrSet
);
98 void ScTpCalcOptions::Reset(const SfxItemSet
* rCoreAttrs
)
103 pOldOptions
.reset(new ScDocOptions(
104 rCoreAttrs
->Get(SID_SCDOCOPTIONS
).GetDocOptions()));
106 *pLocalOptions
= *pOldOptions
;
108 bool bReadOnly
= officecfg::Office::Calc::Calculate::Other::CaseSensitive::isReadOnly();
109 m_xBtnCase
->set_active( !pLocalOptions
->IsIgnoreCase() );
110 m_xBtnCase
->set_sensitive(!bReadOnly
);
111 m_xBtnCaseImg
->set_visible(bReadOnly
);
113 bReadOnly
= officecfg::Office::Calc::Calculate::Other::Precision::isReadOnly();
114 m_xBtnCalc
->set_active( pLocalOptions
->IsCalcAsShown() );
115 m_xBtnCalc
->set_sensitive(!bReadOnly
);
116 m_xBtnCalcImg
->set_visible(bReadOnly
);
118 bReadOnly
= officecfg::Office::Calc::Calculate::Other::SearchCriteria::isReadOnly();
119 m_xBtnMatch
->set_active( pLocalOptions
->IsMatchWholeCell() );
120 m_xBtnMatch
->set_sensitive(!bReadOnly
);
121 m_xBtnMatchImg
->set_visible(bReadOnly
);
123 bool bWildcards
= pLocalOptions
->IsFormulaWildcardsEnabled();
124 bool bRegex
= pLocalOptions
->IsFormulaRegexEnabled();
125 // If both, Wildcards and Regex, are set then Wildcards shall take
126 // precedence. This is also how other code calling Search handles it. Both
127 // simultaneously couldn't be set using UI but editing the configuration.
128 if (bWildcards
&& bRegex
)
130 m_xBtnWildcards
->set_active( bWildcards
);
131 m_xBtnRegex
->set_active( bRegex
);
132 m_xBtnWildcards
->set_sensitive( !officecfg::Office::Calc::Calculate::Other::Wildcards::isReadOnly() );
133 m_xBtnRegex
->set_sensitive( !officecfg::Office::Calc::Calculate::Other::RegularExpressions::isReadOnly() );
134 m_xBtnLiteral
->set_active( !bWildcards
&& !bRegex
);
135 m_xBtnLiteral
->set_sensitive( m_xBtnWildcards
->get_sensitive() || m_xBtnRegex
->get_sensitive() );
136 // if either regex or wildcards radio button is set and read-only, disable all three
137 if ( (!m_xBtnWildcards
->get_sensitive() && bWildcards
) || (!m_xBtnRegex
->get_sensitive() && bRegex
) )
139 m_xBtnWildcards
->set_sensitive( false );
140 m_xBtnRegex
->set_sensitive( false );
141 m_xBtnLiteral
->set_sensitive( false );
143 bReadOnly
= officecfg::Office::Calc::Calculate::Other::Wildcards::isReadOnly() ||
144 officecfg::Office::Calc::Calculate::Other::RegularExpressions::isReadOnly();
145 m_xFormulaImg
->set_visible(bReadOnly
);
147 bReadOnly
= officecfg::Office::Calc::Calculate::Other::FindLabel::isReadOnly();
148 m_xBtnLookUp
->set_active( pLocalOptions
->IsLookUpColRowNames() );
149 m_xBtnLookUp
->set_sensitive(!bReadOnly
);
150 m_xBtnLookUpImg
->set_visible(bReadOnly
);
152 bReadOnly
= officecfg::Office::Calc::Calculate::IterativeReference::Iteration::isReadOnly();
153 m_xBtnIterate
->set_active( pLocalOptions
->IsIter() );
154 m_xBtnIterate
->set_sensitive(!bReadOnly
);
155 m_xBtnIterateImg
->set_visible(bReadOnly
);
157 m_xEdSteps
->set_value( pLocalOptions
->GetIterCount() );
158 m_xEdEps
->SetValue( pLocalOptions
->GetIterEps(), 6 );
160 pLocalOptions
->GetDate( d
, m
, y
);
165 m_xBtnDateStd
->set_active(true);
168 m_xBtnDateSc10
->set_active(true);
171 m_xBtnDate1904
->set_active(true);
175 // TODO: these option settings need to be simplified.
177 OUString aDateConfPath
= officecfg::Office::Calc::Calculate::Other::path() + "/Date/DD";
178 if (m_xReadWriteAccess
->hasPropertyByHierarchicalName(aDateConfPath
))
180 css::beans::Property aProperty
= m_xReadWriteAccess
->getPropertyByHierarchicalName(aDateConfPath
);
181 bReadOnly
= (aProperty
.Attributes
& css::beans::PropertyAttribute::READONLY
) != 0;
186 aDateConfPath
= officecfg::Office::Calc::Calculate::Other::path() + "/Date/MM";
187 if (m_xReadWriteAccess
->hasPropertyByHierarchicalName(aDateConfPath
))
189 css::beans::Property aProperty
= m_xReadWriteAccess
->getPropertyByHierarchicalName(aDateConfPath
);
190 bReadOnly
= (aProperty
.Attributes
& css::beans::PropertyAttribute::READONLY
) != 0;
196 aDateConfPath
= officecfg::Office::Calc::Calculate::Other::path() + "/Date/YY";
197 if (m_xReadWriteAccess
->hasPropertyByHierarchicalName(aDateConfPath
))
199 css::beans::Property aProperty
= m_xReadWriteAccess
->getPropertyByHierarchicalName(aDateConfPath
);
200 bReadOnly
= (aProperty
.Attributes
& css::beans::PropertyAttribute::READONLY
) != 0;
206 m_xBtnDateStd
->set_sensitive(false);
207 m_xBtnDateSc10
->set_sensitive(false);
208 m_xBtnDate1904
->set_sensitive(false);
209 m_xDateImg
->set_visible(true);
212 sal_uInt16 nPrec
= pLocalOptions
->GetStdPrecision();
213 bReadOnly
= officecfg::Office::Calc::Calculate::Other::DecimalPlaces::isReadOnly();
214 if (nPrec
== SvNumberFormatter::UNLIMITED_PRECISION
)
216 m_xFtPrec
->set_sensitive(false);
217 m_xEdPrec
->set_sensitive(false);
218 m_xBtnGeneralPrec
->set_active(false);
219 m_xEdPrec
->set_value(0);
223 m_xBtnGeneralPrec
->set_active(true);
224 m_xFtPrec
->set_sensitive(true);
225 m_xEdPrec
->set_sensitive(!bReadOnly
);
226 m_xEdPrec
->set_value(nPrec
);
228 m_xBtnGeneralPrec
->set_sensitive(!bReadOnly
);
229 m_xBtnGeneralPrecImg
->set_visible(bReadOnly
);
230 m_xEdPrecImg
->set_visible(bReadOnly
);
232 bReadOnly
= officecfg::Office::Calc::Calculate::IterativeReference::Steps::isReadOnly();
233 m_xEdSteps
->set_sensitive(!bReadOnly
);
234 m_xEdStepsImg
->set_visible(bReadOnly
);
236 bReadOnly
= officecfg::Office::Calc::Calculate::IterativeReference::MinimumChange::isReadOnly();
237 m_xEdEps
->set_sensitive(!bReadOnly
);
238 m_xEdEpsImg
->set_visible(bReadOnly
);
240 bReadOnly
= officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::isReadOnly();
241 m_xBtnThread
->set_sensitive(!bReadOnly
);
242 m_xBtnThreadImg
->set_visible(bReadOnly
);
243 m_xBtnThread
->set_active( officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get() );
245 CheckClickHdl(*m_xBtnIterate
);
248 OUString
ScTpCalcOptions::GetAllStrings()
250 OUString sAllStrings
;
252 = { u
"label5"_ustr
, u
"label1"_ustr
, u
"precft"_ustr
, u
"label2"_ustr
, u
"stepsft"_ustr
, u
"minchangeft"_ustr
, u
"label4"_ustr
, u
"label3"_ustr
};
254 for (const auto& label
: labels
)
256 if (const auto pString
= m_xBuilder
->weld_label(label
))
257 sAllStrings
+= pString
->get_label() + " ";
260 OUString checkButton
[]
261 = { u
"case"_ustr
, u
"calc"_ustr
, u
"match"_ustr
, u
"lookup"_ustr
, u
"generalprec"_ustr
, u
"iterate"_ustr
, u
"threadingenabled"_ustr
};
263 for (const auto& check
: checkButton
)
265 if (const auto pString
= m_xBuilder
->weld_check_button(check
))
266 sAllStrings
+= pString
->get_label() + " ";
269 OUString radioButton
[] = { u
"formulawildcards"_ustr
, u
"formularegex"_ustr
, u
"formulaliteral"_ustr
,
270 u
"datestd"_ustr
, u
"datesc10"_ustr
, u
"date1904"_ustr
};
272 for (const auto& radio
: radioButton
)
274 if (const auto pString
= m_xBuilder
->weld_radio_button(radio
))
275 sAllStrings
+= pString
->get_label() + " ";
278 return sAllStrings
.replaceAll("_", "");
281 bool ScTpCalcOptions::FillItemSet( SfxItemSet
* rCoreAttrs
)
283 // every other options are updated in handlers
284 pLocalOptions
->SetIterCount( static_cast<sal_uInt16
>(m_xEdSteps
->get_value()) );
285 pLocalOptions
->SetIgnoreCase( !m_xBtnCase
->get_active() );
286 pLocalOptions
->SetCalcAsShown( m_xBtnCalc
->get_active() );
287 pLocalOptions
->SetMatchWholeCell( m_xBtnMatch
->get_active() );
288 pLocalOptions
->SetFormulaWildcardsEnabled( m_xBtnWildcards
->get_active() );
289 pLocalOptions
->SetFormulaRegexEnabled( m_xBtnRegex
->get_active() );
290 pLocalOptions
->SetLookUpColRowNames( m_xBtnLookUp
->get_active() );
292 if (m_xBtnGeneralPrec
->get_active())
293 pLocalOptions
->SetStdPrecision(
294 static_cast<sal_uInt16
>(m_xEdPrec
->get_value()) );
296 pLocalOptions
->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION
);
298 bool bShouldEnableThreading
= m_xBtnThread
->get_active();
299 if (bShouldEnableThreading
!= officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get())
301 std::shared_ptr
<comphelper::ConfigurationChanges
> xBatch(comphelper::ConfigurationChanges::create());
302 officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::set(bShouldEnableThreading
, xBatch
);
304 SolarMutexGuard aGuard
;
305 if (svtools::executeRestartDialog(
306 comphelper::getProcessComponentContext(), GetFrameWeld(),
307 svtools::RESTART_REASON_THREADING
))
308 GetDialogController()->response(RET_OK
);
310 if ( *pLocalOptions
!= *pOldOptions
)
312 rCoreAttrs
->Put( ScTpCalcItem( SID_SCDOCOPTIONS
, *pLocalOptions
) );
319 DeactivateRC
ScTpCalcOptions::DeactivatePage( SfxItemSet
* pSetP
)
321 DeactivateRC nReturn
= DeactivateRC::KeepPage
;
324 if( m_xEdEps
->GetValue( fEps
) && (fEps
> 0.0) )
326 pLocalOptions
->SetIterEps( fEps
);
327 nReturn
= DeactivateRC::LeavePage
;
330 if ( nReturn
== DeactivateRC::KeepPage
)
332 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning
,
333 VclButtonsType::Ok
, ScResId(STR_INVALID_EPS
)));
336 m_xEdEps
->grab_focus();
339 FillItemSet( pSetP
);
346 IMPL_LINK( ScTpCalcOptions
, RadioClickHdl
, weld::Toggleable
&, rBtn
, void )
348 if (!rBtn
.get_active())
350 if (m_xBtnDateStd
->get_active())
352 pLocalOptions
->SetDate( 30, 12, 1899 );
354 else if (m_xBtnDateSc10
->get_active())
356 pLocalOptions
->SetDate( 1, 1, 1900 );
358 else if (m_xBtnDate1904
->get_active())
360 pLocalOptions
->SetDate( 1, 1, 1904 );
364 IMPL_LINK(ScTpCalcOptions
, CheckClickHdl
, weld::Toggleable
&, rBtn
, void)
366 if (&rBtn
== m_xBtnGeneralPrec
.get())
368 if (rBtn
.get_active())
370 m_xEdPrec
->set_sensitive(!officecfg::Office::Calc::Calculate::Other::DecimalPlaces::isReadOnly());
371 m_xFtPrec
->set_sensitive(true);
375 m_xEdPrec
->set_sensitive(false);
376 m_xFtPrec
->set_sensitive(false);
379 else if (&rBtn
== m_xBtnIterate
.get())
381 if (rBtn
.get_active())
383 pLocalOptions
->SetIter( true );
384 m_xFtSteps
->set_sensitive(true); m_xEdSteps
->set_sensitive(!officecfg::Office::Calc::Calculate::IterativeReference::Steps::isReadOnly());
385 m_xFtEps
->set_sensitive(true); m_xEdEps
->set_sensitive(!officecfg::Office::Calc::Calculate::IterativeReference::MinimumChange::isReadOnly());
389 pLocalOptions
->SetIter( false );
390 m_xFtSteps
->set_sensitive(false); m_xEdSteps
->set_sensitive(false);
391 m_xFtEps
->set_sensitive(false); m_xEdEps
->set_sensitive(false);
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */