tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / optdlg / calcoptionsdlg.cxx
blob794c850c229e3d9731abab11722e2b4f574f7a71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/config.h>
12 #include <officecfg/Office/Calc.hxx>
14 #include <calcconfig.hxx>
15 #include "calcoptionsdlg.hxx"
17 namespace {
19 formula::FormulaGrammar::AddressConvention toAddressConvention(sal_Int32 nPos)
21 switch (nPos)
23 case 1:
24 return formula::FormulaGrammar::CONV_OOO;
25 case 2:
26 return formula::FormulaGrammar::CONV_XL_A1;
27 case 3:
28 return formula::FormulaGrammar::CONV_XL_R1C1;
29 case 4:
30 return formula::FormulaGrammar::CONV_A1_XL_A1;
31 case 0:
32 default:
36 return formula::FormulaGrammar::CONV_UNSPECIFIED;
39 sal_Int32 toSelectedItem( formula::FormulaGrammar::AddressConvention eConv )
41 switch (eConv)
43 case formula::FormulaGrammar::CONV_OOO:
44 return 1;
45 case formula::FormulaGrammar::CONV_XL_A1:
46 return 2;
47 case formula::FormulaGrammar::CONV_XL_R1C1:
48 return 3;
49 case formula::FormulaGrammar::CONV_A1_XL_A1:
50 return 4;
51 default:
54 return 0;
59 ScCalcOptionsDialog::ScCalcOptionsDialog(weld::Window* pParent, const ScCalcConfig& rConfig, bool bWriteConfig)
60 : GenericDialogController(pParent, u"modules/scalc/ui/formulacalculationoptions.ui"_ustr, u"FormulaCalculationOptions"_ustr)
61 , maConfig(rConfig)
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);
98 break;
99 case ScCalcConfig::StringConversion::ZERO:
100 maConfig.mbEmptyStringAsZero = true;
101 mxEmptyAsZero->set_active(true);
102 mxEmptyAsZero->set_sensitive(false);
103 break;
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);
110 break;
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: */