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 "scresid.hxx"
16 #include "defaultsoptions.hxx"
17 #include "document.hxx"
19 ScTpDefaultsOptions::ScTpDefaultsOptions(vcl::Window
*pParent
, const SfxItemSet
&rCoreSet
) :
20 SfxTabPage(pParent
, "OptDefaultPage", "modules/scalc/ui/optdefaultpage.ui", &rCoreSet
)
23 get( m_pEdNSheets
, "sheetsnumber");
24 get( m_pEdSheetPrefix
, "sheetprefix");
26 m_pEdNSheets
->SetModifyHdl( LINK(this, ScTpDefaultsOptions
, NumModifiedHdl
) );
27 m_pEdSheetPrefix
->SetModifyHdl( LINK(this, ScTpDefaultsOptions
, PrefixModifiedHdl
) );
28 m_pEdSheetPrefix
->SetGetFocusHdl( LINK(this, ScTpDefaultsOptions
, PrefixEditOnFocusHdl
) );
31 ScTpDefaultsOptions::~ScTpDefaultsOptions()
36 void ScTpDefaultsOptions::dispose()
39 m_pEdSheetPrefix
.clear();
40 SfxTabPage::dispose();
43 VclPtr
<SfxTabPage
> ScTpDefaultsOptions::Create(vcl::Window
*pParent
, const SfxItemSet
*rCoreAttrs
)
45 return VclPtr
<ScTpDefaultsOptions
>::Create(pParent
, *rCoreAttrs
);
48 bool ScTpDefaultsOptions::FillItemSet(SfxItemSet
*rCoreSet
)
51 ScDefaultsOptions aOpt
;
53 SCTAB nTabCount
= static_cast<SCTAB
>(m_pEdNSheets
->GetValue());
54 OUString aSheetPrefix
= m_pEdSheetPrefix
->GetText();
56 if ( m_pEdNSheets
->IsValueChangedFromSaved()
57 || m_pEdSheetPrefix
->GetSavedValue() != aSheetPrefix
)
59 aOpt
.SetInitTabCount( nTabCount
);
60 aOpt
.SetInitTabPrefix( aSheetPrefix
);
62 rCoreSet
->Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS
, aOpt
) );
68 void ScTpDefaultsOptions::Reset(const SfxItemSet
* rCoreSet
)
70 ScDefaultsOptions aOpt
;
71 const SfxPoolItem
* pItem
= NULL
;
73 if(SfxItemState::SET
== rCoreSet
->GetItemState(SID_SCDEFAULTSOPTIONS
, false , &pItem
))
74 aOpt
= static_cast<const ScTpDefaultsItem
*>(pItem
)->GetDefaultsOptions();
76 m_pEdNSheets
->SetValue( static_cast<sal_uInt16
>( aOpt
.GetInitTabCount()) );
77 m_pEdSheetPrefix
->SetText( aOpt
.GetInitTabPrefix() );
78 m_pEdNSheets
->SaveValue();
79 m_pEdSheetPrefix
->SaveValue();
82 SfxTabPage::sfxpg
ScTpDefaultsOptions::DeactivatePage(SfxItemSet
* /*pSet*/)
87 void ScTpDefaultsOptions::CheckNumSheets()
89 sal_Int64 nVal
= m_pEdNSheets
->GetValue();
90 if (nVal
> MAXINITTAB
)
91 m_pEdNSheets
->SetValue(MAXINITTAB
);
92 if (nVal
< MININITTAB
)
93 m_pEdNSheets
->SetValue(MININITTAB
);
96 void ScTpDefaultsOptions::CheckPrefix(Edit
* pEdit
)
101 OUString aSheetPrefix
= pEdit
->GetText();
103 if ( !aSheetPrefix
.isEmpty() && !ScDocument::ValidTabName( aSheetPrefix
) )
105 // Revert to last good Prefix and also select it to
106 // indicate something illegal was typed
107 Selection
aSel( 0, maOldPrefixValue
.getLength() );
108 pEdit
->SetText( maOldPrefixValue
, aSel
);
112 OnFocusPrefixInput(pEdit
);
116 void ScTpDefaultsOptions::OnFocusPrefixInput(Edit
* pEdit
)
121 // Store Prefix in case we need to revert
122 maOldPrefixValue
= pEdit
->GetText();
125 IMPL_LINK_NOARG(ScTpDefaultsOptions
, NumModifiedHdl
)
131 IMPL_LINK( ScTpDefaultsOptions
, PrefixModifiedHdl
, Edit
*, pEdit
)
137 IMPL_LINK( ScTpDefaultsOptions
, PrefixEditOnFocusHdl
, Edit
*, pEdit
)
139 OnFocusPrefixInput(pEdit
);
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */