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 #undef SC_DLLIMPLEMENTATION
12 #include <tpdefaults.hxx>
14 #include <defaultsoptions.hxx>
15 #include <document.hxx>
16 #include <officecfg/Office/Common.hxx>
17 #include <config_features.h>
19 ScTpDefaultsOptions::ScTpDefaultsOptions(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rCoreSet
)
20 : SfxTabPage(pPage
, pController
, "modules/scalc/ui/optdefaultpage.ui", "OptDefaultPage", &rCoreSet
)
21 , m_xEdNSheets(m_xBuilder
->weld_spin_button("sheetsnumber"))
22 , m_xEdSheetPrefix(m_xBuilder
->weld_entry("sheetprefix"))
23 , m_xEdJumboSheets(m_xBuilder
->weld_check_button("jumbo_sheets"))
25 m_xEdNSheets
->connect_changed( LINK(this, ScTpDefaultsOptions
, NumModifiedHdl
) );
26 m_xEdSheetPrefix
->connect_changed( LINK(this, ScTpDefaultsOptions
, PrefixModifiedHdl
) );
27 m_xEdSheetPrefix
->connect_focus_in( LINK(this, ScTpDefaultsOptions
, PrefixEditOnFocusHdl
) );
28 #if HAVE_FEATURE_JUMBO_SHEETS
29 if (!officecfg::Office::Common::Misc::ExperimentalMode::get())
31 m_xEdJumboSheets
->hide();
34 ScTpDefaultsOptions::~ScTpDefaultsOptions()
38 std::unique_ptr
<SfxTabPage
> ScTpDefaultsOptions::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rCoreAttrs
)
40 return std::make_unique
<ScTpDefaultsOptions
>(pPage
, pController
, *rCoreAttrs
);
43 bool ScTpDefaultsOptions::FillItemSet(SfxItemSet
*rCoreSet
)
46 ScDefaultsOptions aOpt
;
48 SCTAB nTabCount
= static_cast<SCTAB
>(m_xEdNSheets
->get_value());
49 OUString aSheetPrefix
= m_xEdSheetPrefix
->get_text();
50 bool bJumboSheets
= m_xEdJumboSheets
->get_state();
52 if ( m_xEdNSheets
->get_value_changed_from_saved()
53 || m_xEdSheetPrefix
->get_saved_value() != aSheetPrefix
54 || m_xEdJumboSheets
->get_saved_state() != (bJumboSheets
? TRISTATE_TRUE
: TRISTATE_FALSE
) )
56 aOpt
.SetInitTabCount( nTabCount
);
57 aOpt
.SetInitTabPrefix( aSheetPrefix
);
58 #if HAVE_FEATURE_JUMBO_SHEETS
59 aOpt
.SetInitJumboSheets( bJumboSheets
);
61 rCoreSet
->Put( ScTpDefaultsItem( std::move(aOpt
) ) );
67 void ScTpDefaultsOptions::Reset(const SfxItemSet
* rCoreSet
)
69 ScDefaultsOptions aOpt
;
71 if(const ScTpDefaultsItem
* pDefaultsItem
= rCoreSet
->GetItemIfSet(SID_SCDEFAULTSOPTIONS
, false))
72 aOpt
= pDefaultsItem
->GetDefaultsOptions();
74 m_xEdNSheets
->set_value(aOpt
.GetInitTabCount());
75 m_xEdSheetPrefix
->set_text( aOpt
.GetInitTabPrefix() );
76 m_xEdJumboSheets
->set_state( aOpt
.GetInitJumboSheets() ? TRISTATE_TRUE
: TRISTATE_FALSE
);
77 m_xEdNSheets
->save_value();
78 m_xEdSheetPrefix
->save_value();
79 m_xEdJumboSheets
->save_state();
82 DeactivateRC
ScTpDefaultsOptions::DeactivatePage(SfxItemSet
* /*pSet*/)
84 return DeactivateRC::KeepPage
;
87 void ScTpDefaultsOptions::CheckNumSheets()
89 auto nVal
= m_xEdNSheets
->get_value();
90 if (nVal
> MAXINITTAB
)
91 m_xEdNSheets
->set_value(MAXINITTAB
);
92 if (nVal
< MININITTAB
)
93 m_xEdNSheets
->set_value(MININITTAB
);
96 void ScTpDefaultsOptions::CheckPrefix()
98 OUString aSheetPrefix
= m_xEdSheetPrefix
->get_text();
100 if (!aSheetPrefix
.isEmpty() && !ScDocument::ValidTabName(aSheetPrefix
))
102 // Revert to last good Prefix and also select it to
103 // indicate something illegal was typed
104 m_xEdSheetPrefix
->set_text(maOldPrefixValue
);
105 m_xEdSheetPrefix
->select_region(0, -1);
109 OnFocusPrefixInput();
113 void ScTpDefaultsOptions::OnFocusPrefixInput()
115 // Store Prefix in case we need to revert
116 maOldPrefixValue
= m_xEdSheetPrefix
->get_text();
119 IMPL_LINK_NOARG(ScTpDefaultsOptions
, NumModifiedHdl
, weld::Entry
&, void)
124 IMPL_LINK_NOARG(ScTpDefaultsOptions
, PrefixModifiedHdl
, weld::Entry
&, void)
129 IMPL_LINK_NOARG(ScTpDefaultsOptions
, PrefixEditOnFocusHdl
, weld::Widget
&, void)
131 OnFocusPrefixInput();
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */