LibreOffice Module sc (master)  1
tpdefaults.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #undef SC_DLLIMPLEMENTATION
11 
12 #include <tpdefaults.hxx>
13 #include <sc.hrc>
14 #include <defaultsoptions.hxx>
15 #include <document.hxx>
16 #include <svtools/miscopt.hxx>
17 
19  : SfxTabPage(pPage, pController, "modules/scalc/ui/optdefaultpage.ui", "OptDefaultPage", &rCoreSet)
20  , m_xEdNSheets(m_xBuilder->weld_spin_button("sheetsnumber"))
21  , m_xEdSheetPrefix(m_xBuilder->weld_entry("sheetprefix"))
22  , m_xEdJumboSheets(m_xBuilder->weld_check_button("jumbo_sheets"))
23 {
24  m_xEdNSheets->connect_changed( LINK(this, ScTpDefaultsOptions, NumModifiedHdl) );
25  m_xEdSheetPrefix->connect_changed( LINK(this, ScTpDefaultsOptions, PrefixModifiedHdl) );
26  m_xEdSheetPrefix->connect_focus_in( LINK(this, ScTpDefaultsOptions, PrefixEditOnFocusHdl) );
27  if (!SvtMiscOptions().IsExperimentalMode())
28  m_xEdJumboSheets->hide();
29 }
30 
32 {
33 }
34 
35 std::unique_ptr<SfxTabPage> ScTpDefaultsOptions::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rCoreAttrs)
36 {
37  return std::make_unique<ScTpDefaultsOptions>(pPage, pController, *rCoreAttrs);
38 }
39 
41 {
42  bool bRet = false;
43  ScDefaultsOptions aOpt;
44 
45  SCTAB nTabCount = static_cast<SCTAB>(m_xEdNSheets->get_value());
46  OUString aSheetPrefix = m_xEdSheetPrefix->get_text();
47  bool bJumboSheets = m_xEdJumboSheets->get_state();
48 
49  if ( m_xEdNSheets->get_value_changed_from_saved()
50  || m_xEdSheetPrefix->get_saved_value() != aSheetPrefix
51  || m_xEdJumboSheets->get_saved_state() != (bJumboSheets ? TRISTATE_TRUE : TRISTATE_FALSE) )
52  {
53  aOpt.SetInitTabCount( nTabCount );
54  aOpt.SetInitTabPrefix( aSheetPrefix );
55  aOpt.SetInitJumboSheets( bJumboSheets );
56 
57  rCoreSet->Put( ScTpDefaultsItem( aOpt ) );
58  bRet = true;
59  }
60  return bRet;
61 }
62 
64 {
65  ScDefaultsOptions aOpt;
66  const SfxPoolItem* pItem = nullptr;
67 
68  if(SfxItemState::SET == rCoreSet->GetItemState(SID_SCDEFAULTSOPTIONS, false , &pItem))
69  aOpt = static_cast<const ScTpDefaultsItem*>(pItem)->GetDefaultsOptions();
70 
71  m_xEdNSheets->set_value(aOpt.GetInitTabCount());
72  m_xEdSheetPrefix->set_text( aOpt.GetInitTabPrefix() );
74  m_xEdNSheets->save_value();
75  m_xEdSheetPrefix->save_value();
76  m_xEdJumboSheets->save_state();
77 }
78 
80 {
81  return DeactivateRC::KeepPage;
82 }
83 
85 {
86  auto nVal = m_xEdNSheets->get_value();
87  if (nVal > MAXINITTAB)
88  m_xEdNSheets->set_value(MAXINITTAB);
89  if (nVal < MININITTAB)
90  m_xEdNSheets->set_value(MININITTAB);
91 }
92 
94 {
95  OUString aSheetPrefix = m_xEdSheetPrefix->get_text();
96 
97  if (!aSheetPrefix.isEmpty() && !ScDocument::ValidTabName(aSheetPrefix))
98  {
99  // Revert to last good Prefix and also select it to
100  // indicate something illegal was typed
102  m_xEdSheetPrefix->select_region(0, -1);
103  }
104  else
105  {
107  }
108 }
109 
111 {
112  // Store Prefix in case we need to revert
113  maOldPrefixValue = m_xEdSheetPrefix->get_text();
114 }
115 
117 {
118  CheckNumSheets();
119 }
120 
122 {
123  CheckPrefix();
124 }
125 
126 IMPL_LINK_NOARG(ScTpDefaultsOptions, PrefixEditOnFocusHdl, weld::Widget&, void)
127 {
128  OnFocusPrefixInput();
129 }
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB GetInitTabCount() const
std::unique_ptr< weld::Entry > m_xEdSheetPrefix
Definition: tpdefaults.hxx:40
virtual void Reset(const SfxItemSet *rCoreSet) override
Definition: tpdefaults.cxx:63
TRISTATE_TRUE
void SetInitTabPrefix(const OUString &aPrefix)
bool GetInitJumboSheets() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
IMPL_LINK_NOARG(ScTpDefaultsOptions, NumModifiedHdl, weld::Entry &, void)
Definition: tpdefaults.cxx:116
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpdefaults.cxx:79
const SCTAB MININITTAB
Definition: address.hxx:81
TRISTATE_FALSE
const OUString & GetInitTabPrefix() const
std::unique_ptr< weld::CheckButton > m_xEdJumboSheets
Definition: tpdefaults.hxx:41
void SetInitJumboSheets(bool b)
const SCTAB MAXINITTAB
Definition: address.hxx:80
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual ~ScTpDefaultsOptions() override
Definition: tpdefaults.cxx:31
static SC_DLLPUBLIC bool ValidTabName(const OUString &rName)
Definition: document.cxx:335
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
Definition: tpdefaults.cxx:35
std::unique_ptr< weld::SpinButton > m_xEdNSheets
Definition: tpdefaults.hxx:39
OUString maOldPrefixValue
Definition: tpdefaults.hxx:37
DeactivateRC
void SetInitTabCount(SCTAB nTabs)
virtual bool FillItemSet(SfxItemSet *rCoreSet) override
Definition: tpdefaults.cxx:40
sal_Int16 SCTAB
Definition: types.hxx:23
ScTpDefaultsOptions(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rCoreSet)
Definition: tpdefaults.cxx:18