summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/optdlg/calcoptionsdlg.cxx
blob: ec65fb9d8014c873f0e661bfd423346a789ca5a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/config.h>

#include <officecfg/Office/Calc.hxx>

#include <calcconfig.hxx>
#include "calcoptionsdlg.hxx"

namespace {

formula::FormulaGrammar::AddressConvention toAddressConvention(sal_Int32 nPos)
{
    switch (nPos)
    {
        case 1:
            return formula::FormulaGrammar::CONV_OOO;
        case 2:
            return formula::FormulaGrammar::CONV_XL_A1;
        case 3:
            return formula::FormulaGrammar::CONV_XL_R1C1;
        case 4:
            return formula::FormulaGrammar::CONV_A1_XL_A1;
        case 0:
        default:
            ;
    }

    return formula::FormulaGrammar::CONV_UNSPECIFIED;
}

sal_Int32 toSelectedItem( formula::FormulaGrammar::AddressConvention eConv )
{
    switch (eConv)
    {
        case formula::FormulaGrammar::CONV_OOO:
            return 1;
        case formula::FormulaGrammar::CONV_XL_A1:
            return 2;
        case formula::FormulaGrammar::CONV_XL_R1C1:
            return 3;
        case formula::FormulaGrammar::CONV_A1_XL_A1:
            return 4;
        default:
            ;
    }
    return 0;
}

}

ScCalcOptionsDialog::ScCalcOptionsDialog(weld::Window* pParent, const ScCalcConfig& rConfig, bool bWriteConfig)
    : GenericDialogController(pParent, "modules/scalc/ui/formulacalculationoptions.ui", "FormulaCalculationOptions")
    , maConfig(rConfig)
    , mbSelectedEmptyStringAsZero(rConfig.mbEmptyStringAsZero)
    , mbWriteConfig(bWriteConfig)
    , mxEmptyAsZero(m_xBuilder->weld_check_button("checkEmptyAsZero"))
    , mxConversion(m_xBuilder->weld_combo_box("comboConversion"))
    , mxCurrentDocOnly(m_xBuilder->weld_check_button("current_doc"))
    , mxSyntax(m_xBuilder->weld_combo_box("comboSyntaxRef"))
{
    mxConversion->set_active(static_cast<int>(rConfig.meStringConversion));
    mxConversion->connect_changed(LINK(this, ScCalcOptionsDialog, ConversionModifiedHdl));
    mxConversion->set_sensitive( !officecfg::Office::Calc::Formula::Syntax::StringConversion::isReadOnly() );

    mxEmptyAsZero->set_active(rConfig.mbEmptyStringAsZero);
    mxEmptyAsZero->connect_toggled(LINK(this, ScCalcOptionsDialog, AsZeroModifiedHdl));
    CoupleEmptyAsZeroToStringConversion();
    mxEmptyAsZero->set_sensitive ( !officecfg::Office::Calc::Formula::Syntax::EmptyStringAsZero::isReadOnly() );

    mxSyntax->set_active(toSelectedItem(rConfig.meStringRefAddressSyntax));
    mxSyntax->connect_changed(LINK(this, ScCalcOptionsDialog, SyntaxModifiedHdl));
    mxSyntax->set_sensitive ( !officecfg::Office::Calc::Formula::Syntax::StringRefAddressSyntax::isReadOnly() );

    mxCurrentDocOnly->set_active(!mbWriteConfig);
    mxCurrentDocOnly->connect_toggled(LINK(this, ScCalcOptionsDialog, CurrentDocOnlyHdl));
}

ScCalcOptionsDialog::~ScCalcOptionsDialog()
{
}

void ScCalcOptionsDialog::CoupleEmptyAsZeroToStringConversion()
{
    switch (maConfig.meStringConversion)
    {
        case ScCalcConfig::StringConversion::ILLEGAL:
            maConfig.mbEmptyStringAsZero = false;
            mxEmptyAsZero->set_active(false);
            mxEmptyAsZero->set_sensitive(false);
            break;
        case ScCalcConfig::StringConversion::ZERO:
            maConfig.mbEmptyStringAsZero = true;
            mxEmptyAsZero->set_active(true);
            mxEmptyAsZero->set_sensitive(false);
            break;
        case ScCalcConfig::StringConversion::UNAMBIGUOUS:
        case ScCalcConfig::StringConversion::LOCALE:
            // Reset to the value the user selected before.
            maConfig.mbEmptyStringAsZero = mbSelectedEmptyStringAsZero;
            mxEmptyAsZero->set_sensitive(true);
            mxEmptyAsZero->set_active(mbSelectedEmptyStringAsZero);
            break;
    }
}

IMPL_LINK(ScCalcOptionsDialog, AsZeroModifiedHdl, weld::Toggleable&, rCheckBox, void )
{
    maConfig.mbEmptyStringAsZero = mbSelectedEmptyStringAsZero = rCheckBox.get_active();
}

IMPL_LINK(ScCalcOptionsDialog, ConversionModifiedHdl, weld::ComboBox&, rConv, void)
{
    maConfig.meStringConversion = static_cast<ScCalcConfig::StringConversion>(rConv.get_active());
    CoupleEmptyAsZeroToStringConversion();
}

IMPL_LINK(ScCalcOptionsDialog, SyntaxModifiedHdl, weld::ComboBox&, rSyntax, void)
{
    maConfig.SetStringRefSyntax(toAddressConvention(rSyntax.get_active()));
}

IMPL_LINK(ScCalcOptionsDialog, CurrentDocOnlyHdl, weld::Toggleable&, rCheckBox, void)
{
    mbWriteConfig = !rCheckBox.get_active();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */