tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / optdlg / tpdefaults.cxx
blob8cb4c4609405acd6d852319d9bbf098b23ac3140
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 #undef SC_DLLIMPLEMENTATION
12 #include <tpdefaults.hxx>
13 #include <sc.hrc>
14 #include <defaultsoptions.hxx>
15 #include <document.hxx>
16 #include <officecfg/Office/Common.hxx>
17 #include <officecfg/Office/Calc.hxx>
18 #include <config_features.h>
20 ScTpDefaultsOptions::ScTpDefaultsOptions(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rCoreSet)
21 : SfxTabPage(pPage, pController, u"modules/scalc/ui/optdefaultpage.ui"_ustr, u"OptDefaultPage"_ustr, &rCoreSet)
22 , m_xEdNSheets(m_xBuilder->weld_spin_button(u"sheetsnumber"_ustr))
23 , m_xEdNSheetsImg(m_xBuilder->weld_widget(u"locksheetsnumber"_ustr))
24 , m_xEdSheetPrefix(m_xBuilder->weld_entry(u"sheetprefix"_ustr))
25 , m_xEdSheetPrefixImg(m_xBuilder->weld_widget(u"locksheetprefix"_ustr))
26 , m_xEdJumboSheets(m_xBuilder->weld_check_button(u"jumbo_sheets"_ustr))
27 , m_xEdJumboSheetsImg(m_xBuilder->weld_widget(u"lockjumbo_sheets"_ustr))
29 m_xEdNSheets->connect_changed( LINK(this, ScTpDefaultsOptions, NumModifiedHdl) );
30 m_xEdSheetPrefix->connect_changed( LINK(this, ScTpDefaultsOptions, PrefixModifiedHdl) );
31 m_xEdSheetPrefix->connect_focus_in( LINK(this, ScTpDefaultsOptions, PrefixEditOnFocusHdl) );
32 #if HAVE_FEATURE_JUMBO_SHEETS
33 if (!officecfg::Office::Common::Misc::ExperimentalMode::get())
34 #endif
35 m_xEdJumboSheets->hide();
38 ScTpDefaultsOptions::~ScTpDefaultsOptions()
42 std::unique_ptr<SfxTabPage> ScTpDefaultsOptions::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rCoreAttrs)
44 return std::make_unique<ScTpDefaultsOptions>(pPage, pController, *rCoreAttrs);
47 OUString ScTpDefaultsOptions::GetAllStrings()
49 OUString sAllStrings;
50 OUString labels[] = { u"label1"_ustr, u"textsheetsnumber"_ustr, u"textsheetprefix"_ustr };
52 for (const auto& label : labels)
54 if (const auto pString = m_xBuilder->weld_label(label))
55 sAllStrings += pString->get_label() + " ";
58 sAllStrings += m_xEdJumboSheets->get_label() + " ";
60 return sAllStrings.replaceAll("_", "");
63 bool ScTpDefaultsOptions::FillItemSet(SfxItemSet *rCoreSet)
65 bool bRet = false;
66 ScDefaultsOptions aOpt;
68 SCTAB nTabCount = static_cast<SCTAB>(m_xEdNSheets->get_value());
69 OUString aSheetPrefix = m_xEdSheetPrefix->get_text();
70 bool bJumboSheets = m_xEdJumboSheets->get_state();
72 if ( m_xEdNSheets->get_value_changed_from_saved()
73 || m_xEdSheetPrefix->get_saved_value() != aSheetPrefix
74 || m_xEdJumboSheets->get_saved_state() != (bJumboSheets ? TRISTATE_TRUE : TRISTATE_FALSE) )
76 aOpt.SetInitTabCount( nTabCount );
77 aOpt.SetInitTabPrefix( aSheetPrefix );
78 #if HAVE_FEATURE_JUMBO_SHEETS
79 aOpt.SetInitJumboSheets( bJumboSheets );
80 #endif
81 rCoreSet->Put( ScTpDefaultsItem( std::move(aOpt) ) );
82 bRet = true;
84 return bRet;
87 void ScTpDefaultsOptions::Reset(const SfxItemSet* rCoreSet)
89 ScDefaultsOptions aOpt;
91 if(const ScTpDefaultsItem* pDefaultsItem = rCoreSet->GetItemIfSet(SID_SCDEFAULTSOPTIONS, false))
92 aOpt = pDefaultsItem->GetDefaultsOptions();
94 m_xEdNSheets->set_value(aOpt.GetInitTabCount());
95 m_xEdSheetPrefix->set_text( aOpt.GetInitTabPrefix() );
96 m_xEdJumboSheets->set_state( aOpt.GetInitJumboSheets() ? TRISTATE_TRUE : TRISTATE_FALSE );
98 bool bReadOnly = officecfg::Office::Calc::Defaults::Sheet::SheetCount::isReadOnly();
99 m_xEdNSheets->set_sensitive(!bReadOnly);
100 m_xEdNSheetsImg->set_visible(bReadOnly);
102 bReadOnly = officecfg::Office::Calc::Defaults::Sheet::SheetPrefix::isReadOnly();
103 m_xEdSheetPrefix->set_sensitive(!bReadOnly);
104 m_xEdSheetPrefixImg->set_visible(bReadOnly);
106 if (m_xEdJumboSheets->is_visible())
108 bReadOnly = officecfg::Office::Calc::Defaults::Sheet::JumboSheets::isReadOnly();
109 m_xEdJumboSheets->set_sensitive(!bReadOnly);
110 m_xEdJumboSheetsImg->set_visible(bReadOnly);
113 m_xEdNSheets->save_value();
114 m_xEdSheetPrefix->save_value();
115 m_xEdJumboSheets->save_state();
118 DeactivateRC ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
120 return DeactivateRC::KeepPage;
123 void ScTpDefaultsOptions::CheckNumSheets()
125 auto nVal = m_xEdNSheets->get_value();
126 if (nVal > MAXINITTAB)
127 m_xEdNSheets->set_value(MAXINITTAB);
128 if (nVal < MININITTAB)
129 m_xEdNSheets->set_value(MININITTAB);
132 void ScTpDefaultsOptions::CheckPrefix()
134 OUString aSheetPrefix = m_xEdSheetPrefix->get_text();
136 if (!aSheetPrefix.isEmpty() && !ScDocument::ValidTabName(aSheetPrefix))
138 // Revert to last good Prefix and also select it to
139 // indicate something illegal was typed
140 m_xEdSheetPrefix->set_text(maOldPrefixValue);
141 m_xEdSheetPrefix->select_region(0, -1);
143 else
145 OnFocusPrefixInput();
149 void ScTpDefaultsOptions::OnFocusPrefixInput()
151 // Store Prefix in case we need to revert
152 maOldPrefixValue = m_xEdSheetPrefix->get_text();
155 IMPL_LINK_NOARG(ScTpDefaultsOptions, NumModifiedHdl, weld::Entry&, void)
157 CheckNumSheets();
160 IMPL_LINK_NOARG(ScTpDefaultsOptions, PrefixModifiedHdl, weld::Entry&, void)
162 CheckPrefix();
165 IMPL_LINK_NOARG(ScTpDefaultsOptions, PrefixEditOnFocusHdl, weld::Widget&, void)
167 OnFocusPrefixInput();
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */