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
, "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"))
64 ScTpCalcOptions::~ScTpCalcOptions()
68 void ScTpCalcOptions::Init()
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
) );
78 std::unique_ptr
<SfxTabPage
> ScTpCalcOptions::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
80 return std::make_unique
<ScTpCalcOptions
>( pPage
, pController
, *rAttrSet
);
83 void ScTpCalcOptions::Reset(const SfxItemSet
* rCoreAttrs
)
88 pOldOptions
.reset(new ScDocOptions(
89 rCoreAttrs
->Get(SID_SCDOCOPTIONS
).GetDocOptions()));
91 *pLocalOptions
= *pOldOptions
;
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
)
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
) )
115 m_xBtnWildcards
->set_sensitive( false );
116 m_xBtnRegex
->set_sensitive( false );
117 m_xBtnLiteral
->set_sensitive( false );
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 );
125 pLocalOptions
->GetDate( d
, m
, y
);
130 m_xBtnDateStd
->set_active(true);
133 m_xBtnDateSc10
->set_active(true);
136 m_xBtnDate1904
->set_active(true);
140 sal_uInt16 nPrec
= pLocalOptions
->GetStdPrecision();
141 if (nPrec
== SvNumberFormatter::UNLIMITED_PRECISION
)
143 m_xFtPrec
->set_sensitive(false);
144 m_xEdPrec
->set_sensitive(false);
145 m_xBtnGeneralPrec
->set_active(false);
146 m_xEdPrec
->set_value(0);
150 m_xBtnGeneralPrec
->set_active(true);
151 m_xFtPrec
->set_sensitive(true);
152 m_xEdPrec
->set_sensitive(true);
153 m_xEdPrec
->set_value(nPrec
);
156 m_xBtnThread
->set_sensitive( !officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::isReadOnly() );
157 m_xBtnThread
->set_active( officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get() );
159 CheckClickHdl(*m_xBtnIterate
);
162 bool ScTpCalcOptions::FillItemSet( SfxItemSet
* rCoreAttrs
)
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() );
173 if (m_xBtnGeneralPrec
->get_active())
174 pLocalOptions
->SetStdPrecision(
175 static_cast<sal_uInt16
>(m_xEdPrec
->get_value()) );
177 pLocalOptions
->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION
);
179 bool bShouldEnableThreading
= m_xBtnThread
->get_active();
180 if (bShouldEnableThreading
!= officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get())
182 std::shared_ptr
<comphelper::ConfigurationChanges
> xBatch(comphelper::ConfigurationChanges::create());
183 officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::set(bShouldEnableThreading
, xBatch
);
185 SolarMutexGuard aGuard
;
186 if (svtools::executeRestartDialog(
187 comphelper::getProcessComponentContext(), GetFrameWeld(),
188 svtools::RESTART_REASON_THREADING
))
189 GetDialogController()->response(RET_OK
);
191 if ( *pLocalOptions
!= *pOldOptions
)
193 rCoreAttrs
->Put( ScTpCalcItem( SID_SCDOCOPTIONS
, *pLocalOptions
) );
200 DeactivateRC
ScTpCalcOptions::DeactivatePage( SfxItemSet
* pSetP
)
202 DeactivateRC nReturn
= DeactivateRC::KeepPage
;
205 if( m_xEdEps
->GetValue( fEps
) && (fEps
> 0.0) )
207 pLocalOptions
->SetIterEps( fEps
);
208 nReturn
= DeactivateRC::LeavePage
;
211 if ( nReturn
== DeactivateRC::KeepPage
)
213 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning
,
214 VclButtonsType::Ok
, ScResId(STR_INVALID_EPS
)));
217 m_xEdEps
->grab_focus();
220 FillItemSet( pSetP
);
227 IMPL_LINK( ScTpCalcOptions
, RadioClickHdl
, weld::Toggleable
&, rBtn
, void )
229 if (!rBtn
.get_active())
231 if (m_xBtnDateStd
->get_active())
233 pLocalOptions
->SetDate( 30, 12, 1899 );
235 else if (m_xBtnDateSc10
->get_active())
237 pLocalOptions
->SetDate( 1, 1, 1900 );
239 else if (m_xBtnDate1904
->get_active())
241 pLocalOptions
->SetDate( 1, 1, 1904 );
245 IMPL_LINK(ScTpCalcOptions
, CheckClickHdl
, weld::Toggleable
&, rBtn
, void)
247 if (&rBtn
== m_xBtnGeneralPrec
.get())
249 if (rBtn
.get_active())
251 m_xEdPrec
->set_sensitive(true);
252 m_xFtPrec
->set_sensitive(true);
256 m_xEdPrec
->set_sensitive(false);
257 m_xFtPrec
->set_sensitive(false);
260 else if (&rBtn
== m_xBtnIterate
.get())
262 if (rBtn
.get_active())
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);
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);
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */