summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/optdlg/tpcompatibility.cxx
blob: cc54635f3300753af1a48d99505dcc9a9dd5dfca (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
/* -*- 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/.
 */

#undef SC_DLLIMPLEMENTATION

#include <svl/intitem.hxx>
#include <svl/eitem.hxx>

#include <tpcompatibility.hxx>
#include <sc.hrc>
#include <optutil.hxx>

ScTpCompatOptions::ScTpCompatOptions(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rCoreAttrs)
    : SfxTabPage(pPage, pController, "modules/scalc/ui/optcompatibilitypage.ui", "OptCompatibilityPage", &rCoreAttrs)
    , m_xLbKeyBindings(m_xBuilder->weld_combo_box("keybindings"))
    , m_xBtnLink(m_xBuilder->weld_check_button("cellLinkCB"))
{
}

ScTpCompatOptions::~ScTpCompatOptions()
{
}

std::unique_ptr<SfxTabPage> ScTpCompatOptions::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rCoreAttrs)
{
    return std::make_unique<ScTpCompatOptions>(pPage, pController, *rCoreAttrs);
}

OUString ScTpCompatOptions::GetAllStrings()
{
    OUString sAllStrings;
    OUString labels[] = { "label1", "label2" };

    for (const auto& label : labels)
    {
        if (const auto& pString = m_xBuilder->weld_label(label))
            sAllStrings += pString->get_label() + " ";
    }

    // id "keybindings" GtkComboBoxText is not included

    return sAllStrings.replaceAll("_", "");
}

bool ScTpCompatOptions::FillItemSet(SfxItemSet *rCoreAttrs)
{
    bool bRet = false;
    if (m_xLbKeyBindings->get_value_changed_from_saved())
    {
        rCoreAttrs->Put(
            SfxUInt16Item(
                SID_SC_OPT_KEY_BINDING_COMPAT, m_xLbKeyBindings->get_active()));
        bRet = true;
    }
    if (m_xBtnLink->get_state_changed_from_saved())
    {
        rCoreAttrs->Put(SfxBoolItem(SID_SC_OPT_LINKS, m_xBtnLink->get_active()));
        bRet = true;
    }

    return bRet;
}

void ScTpCompatOptions::Reset(const SfxItemSet *rCoreAttrs)
{
    if (const SfxUInt16Item* p16Item = rCoreAttrs->GetItemIfSet(SID_SC_OPT_KEY_BINDING_COMPAT))
    {
        ScOptionsUtil::KeyBindingType eKeyB =
            static_cast<ScOptionsUtil::KeyBindingType>(p16Item->GetValue());

        switch (eKeyB)
        {
            case ScOptionsUtil::KEY_DEFAULT:
                m_xLbKeyBindings->set_active(0);
            break;
            case ScOptionsUtil::KEY_OOO_LEGACY:
                m_xLbKeyBindings->set_active(1);
            break;
            default:
                ;
        }
    }
    m_xLbKeyBindings->save_value();

    if (const SfxBoolItem* pbItem = rCoreAttrs->GetItemIfSet(SID_SC_OPT_LINKS))
    {
        m_xBtnLink->set_active(pbItem->GetValue());
    }
    m_xBtnLink->save_state();
}

DeactivateRC ScTpCompatOptions::DeactivatePage(SfxItemSet* /*pSet*/)
{
    return DeactivateRC::KeepPage;
}

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