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/.
10 #include <sal/config.h>
12 #include <officecfg/Office/Calc.hxx>
14 #include <calcconfig.hxx>
15 #include "calcoptionsdlg.hxx"
19 formula::FormulaGrammar::AddressConvention
toAddressConvention(sal_Int32 nPos
)
24 return formula::FormulaGrammar::CONV_OOO
;
26 return formula::FormulaGrammar::CONV_XL_A1
;
28 return formula::FormulaGrammar::CONV_XL_R1C1
;
30 return formula::FormulaGrammar::CONV_A1_XL_A1
;
36 return formula::FormulaGrammar::CONV_UNSPECIFIED
;
39 sal_Int32
toSelectedItem( formula::FormulaGrammar::AddressConvention eConv
)
43 case formula::FormulaGrammar::CONV_OOO
:
45 case formula::FormulaGrammar::CONV_XL_A1
:
47 case formula::FormulaGrammar::CONV_XL_R1C1
:
49 case formula::FormulaGrammar::CONV_A1_XL_A1
:
59 ScCalcOptionsDialog::ScCalcOptionsDialog(weld::Window
* pParent
, const ScCalcConfig
& rConfig
, bool bWriteConfig
)
60 : GenericDialogController(pParent
, u
"modules/scalc/ui/formulacalculationoptions.ui"_ustr
, u
"FormulaCalculationOptions"_ustr
)
62 , mbSelectedEmptyStringAsZero(rConfig
.mbEmptyStringAsZero
)
63 , mbWriteConfig(bWriteConfig
)
64 , mxEmptyAsZero(m_xBuilder
->weld_check_button(u
"checkEmptyAsZero"_ustr
))
65 , mxConversion(m_xBuilder
->weld_combo_box(u
"comboConversion"_ustr
))
66 , mxCurrentDocOnly(m_xBuilder
->weld_check_button(u
"current_doc"_ustr
))
67 , mxSyntax(m_xBuilder
->weld_combo_box(u
"comboSyntaxRef"_ustr
))
69 mxConversion
->set_active(static_cast<int>(rConfig
.meStringConversion
));
70 mxConversion
->connect_changed(LINK(this, ScCalcOptionsDialog
, ConversionModifiedHdl
));
71 mxConversion
->set_sensitive( !officecfg::Office::Calc::Formula::Syntax::StringConversion::isReadOnly() );
73 mxEmptyAsZero
->set_active(rConfig
.mbEmptyStringAsZero
);
74 mxEmptyAsZero
->connect_toggled(LINK(this, ScCalcOptionsDialog
, AsZeroModifiedHdl
));
75 CoupleEmptyAsZeroToStringConversion();
76 mxEmptyAsZero
->set_sensitive ( !officecfg::Office::Calc::Formula::Syntax::EmptyStringAsZero::isReadOnly() );
78 mxSyntax
->set_active(toSelectedItem(rConfig
.meStringRefAddressSyntax
));
79 mxSyntax
->connect_changed(LINK(this, ScCalcOptionsDialog
, SyntaxModifiedHdl
));
80 mxSyntax
->set_sensitive ( !officecfg::Office::Calc::Formula::Syntax::StringRefAddressSyntax::isReadOnly() );
82 mxCurrentDocOnly
->set_active(!mbWriteConfig
);
83 mxCurrentDocOnly
->connect_toggled(LINK(this, ScCalcOptionsDialog
, CurrentDocOnlyHdl
));
86 ScCalcOptionsDialog::~ScCalcOptionsDialog()
90 void ScCalcOptionsDialog::CoupleEmptyAsZeroToStringConversion()
92 switch (maConfig
.meStringConversion
)
94 case ScCalcConfig::StringConversion::ILLEGAL
:
95 maConfig
.mbEmptyStringAsZero
= false;
96 mxEmptyAsZero
->set_active(false);
97 mxEmptyAsZero
->set_sensitive(false);
99 case ScCalcConfig::StringConversion::ZERO
:
100 maConfig
.mbEmptyStringAsZero
= true;
101 mxEmptyAsZero
->set_active(true);
102 mxEmptyAsZero
->set_sensitive(false);
104 case ScCalcConfig::StringConversion::UNAMBIGUOUS
:
105 case ScCalcConfig::StringConversion::LOCALE
:
106 // Reset to the value the user selected before.
107 maConfig
.mbEmptyStringAsZero
= mbSelectedEmptyStringAsZero
;
108 mxEmptyAsZero
->set_sensitive(true);
109 mxEmptyAsZero
->set_active(mbSelectedEmptyStringAsZero
);
114 IMPL_LINK(ScCalcOptionsDialog
, AsZeroModifiedHdl
, weld::Toggleable
&, rCheckBox
, void )
116 maConfig
.mbEmptyStringAsZero
= mbSelectedEmptyStringAsZero
= rCheckBox
.get_active();
119 IMPL_LINK(ScCalcOptionsDialog
, ConversionModifiedHdl
, weld::ComboBox
&, rConv
, void)
121 maConfig
.meStringConversion
= static_cast<ScCalcConfig::StringConversion
>(rConv
.get_active());
122 CoupleEmptyAsZeroToStringConversion();
125 IMPL_LINK(ScCalcOptionsDialog
, SyntaxModifiedHdl
, weld::ComboBox
&, rSyntax
, void)
127 maConfig
.SetStringRefSyntax(toAddressConvention(rSyntax
.get_active()));
130 IMPL_LINK(ScCalcOptionsDialog
, CurrentDocOnlyHdl
, weld::Toggleable
&, rCheckBox
, void)
132 mbWriteConfig
= !rCheckBox
.get_active();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */