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/.
11 #undef SC_DLLIMPLEMENTATION
13 #include "tpdefaults.hxx"
15 #include "scresid.hxx"
17 #include "defaultsoptions.hxx"
18 #include "document.hxx"
21 ScTpDefaultsOptions::ScTpDefaultsOptions(Window
*pParent
, const SfxItemSet
&rCoreSet
) :
22 SfxTabPage(pParent
, ScResId(RID_SCPAGE_DEFAULTS
), rCoreSet
),
23 aFLInitSpreadSheet ( this, ScResId( FL_INIT_SPREADSHEET
) ),
24 aFtNSheets ( this, ScResId( FT_NSHEETS
) ),
25 aEdNSheets ( this, ScResId( ED_NSHEETS
) ),
26 aFtSheetPrefix ( this, ScResId( FT_SHEETPREFIX
) ),
27 aEdSheetPrefix ( this, ScResId( ED_SHEETPREFIX
) )
31 // the following computation must be modified accordingly if a third line is added to this dialog
32 long nTxtW1
= aFtNSheets
.GetCtrlTextWidth( aFtNSheets
.GetText() );
33 long nCtrlW1
= aFtNSheets
.GetSizePixel().Width();
34 long nTxtW2
= aFtSheetPrefix
.GetCtrlTextWidth(aFtSheetPrefix
.GetText() );
35 long nCtrlW2
= aFtSheetPrefix
.GetSizePixel().Width();
36 if ( nTxtW1
>= nCtrlW1
|| nTxtW2
>= nCtrlW2
)
38 long nTxtW
= std::max(nTxtW1
,nTxtW2
);
39 Size aNewSize
= aFtNSheets
.GetSizePixel();
40 aNewSize
.Width() = nTxtW
;
41 aFtNSheets
.SetSizePixel( aNewSize
);
42 aFtSheetPrefix
.SetSizePixel( aNewSize
);
43 Point aNewPoint
= aEdNSheets
.GetPosPixel();
44 aNewPoint
.X() += (nTxtW
- nCtrlW1
);
45 aEdNSheets
.SetPosPixel( aNewPoint
);
46 aNewPoint
.Y() = aEdSheetPrefix
.GetPosPixel().Y();
47 aEdSheetPrefix
.SetPosPixel( aNewPoint
);
49 aEdNSheets
.SetModifyHdl( LINK(this, ScTpDefaultsOptions
, NumModifiedHdl
) );
50 aEdSheetPrefix
.SetModifyHdl( LINK(this, ScTpDefaultsOptions
, PrefixModifiedHdl
) );
51 aEdSheetPrefix
.SetGetFocusHdl( LINK(this, ScTpDefaultsOptions
, PrefixEditOnFocusHdl
) );
54 ScTpDefaultsOptions::~ScTpDefaultsOptions()
58 SfxTabPage
* ScTpDefaultsOptions::Create(Window
*pParent
, const SfxItemSet
&rCoreAttrs
)
60 return new ScTpDefaultsOptions(pParent
, rCoreAttrs
);
63 sal_Bool
ScTpDefaultsOptions::FillItemSet(SfxItemSet
&rCoreSet
)
65 sal_Bool bRet
= false;
66 ScDefaultsOptions aOpt
;
68 SCTAB nTabCount
= static_cast<SCTAB
>(aEdNSheets
.GetValue());
69 OUString aSheetPrefix
= aEdSheetPrefix
.GetText();
72 if ( aEdNSheets
.GetSavedValue() != aEdNSheets
.GetText()
73 || aEdSheetPrefix
.GetSavedValue() != aSheetPrefix
)
75 aOpt
.SetInitTabCount( nTabCount
);
76 aOpt
.SetInitTabPrefix( aSheetPrefix
);
78 rCoreSet
.Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS
, aOpt
) );
84 void ScTpDefaultsOptions::Reset(const SfxItemSet
& rCoreSet
)
86 ScDefaultsOptions aOpt
;
87 const SfxPoolItem
* pItem
= NULL
;
89 if(SFX_ITEM_SET
== rCoreSet
.GetItemState(SID_SCDEFAULTSOPTIONS
, false , &pItem
))
90 aOpt
= ((const ScTpDefaultsItem
*)pItem
)->GetDefaultsOptions();
92 aEdNSheets
.SetValue( static_cast<sal_uInt16
>( aOpt
.GetInitTabCount()) );
93 aEdSheetPrefix
.SetText( aOpt
.GetInitTabPrefix() );
94 aEdNSheets
.SaveValue();
95 aEdSheetPrefix
.SaveValue();
98 int ScTpDefaultsOptions::DeactivatePage(SfxItemSet
* /*pSet*/)
103 void ScTpDefaultsOptions::CheckNumSheets()
105 sal_Int64 nVal
= aEdNSheets
.GetValue();
106 if (nVal
> MAXINITTAB
)
107 aEdNSheets
.SetValue(MAXINITTAB
);
108 if (nVal
< MININITTAB
)
109 aEdNSheets
.SetValue(MININITTAB
);
112 void ScTpDefaultsOptions::CheckPrefix(Edit
* pEdit
)
117 OUString aSheetPrefix
= pEdit
->GetText();
119 if ( !aSheetPrefix
.isEmpty() && !ScDocument::ValidTabName( aSheetPrefix
) )
121 // Revert to last good Prefix and also select it to
122 // indicate something illegal was typed
123 Selection
aSel( 0, maOldPrefixValue
.getLength() );
124 pEdit
->SetText( maOldPrefixValue
, aSel
);
128 OnFocusPrefixInput(pEdit
);
132 void ScTpDefaultsOptions::OnFocusPrefixInput(Edit
* pEdit
)
137 // Store Prefix in case we need to revert
138 maOldPrefixValue
= pEdit
->GetText();
142 IMPL_LINK_NOARG(ScTpDefaultsOptions
, NumModifiedHdl
)
148 IMPL_LINK( ScTpDefaultsOptions
, PrefixModifiedHdl
, Edit
*, pEdit
)
154 IMPL_LINK( ScTpDefaultsOptions
, PrefixEditOnFocusHdl
, Edit
*, pEdit
)
156 OnFocusPrefixInput(pEdit
);
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */