Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Albert Thuswaldner <albert.thuswaldner@gmail.com>
17 : : * Portions created by the Initial Developer are Copyright (C) 2011 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s):
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : :
30 : : #undef SC_DLLIMPLEMENTATION
31 : :
32 : : #include "tpdefaults.hxx"
33 : : #include "optdlg.hrc"
34 : : #include "scresid.hxx"
35 : : #include "scmod.hxx"
36 : : #include "defaultsoptions.hxx"
37 : : #include "document.hxx"
38 : :
39 : : using ::rtl::OUString;
40 : :
41 : 0 : ScTpDefaultsOptions::ScTpDefaultsOptions(Window *pParent, const SfxItemSet &rCoreSet) :
42 : : SfxTabPage(pParent, ScResId(RID_SCPAGE_DEFAULTS), rCoreSet),
43 : : aFLInitSpreadSheet ( this, ScResId( FL_INIT_SPREADSHEET ) ),
44 : : aFtNSheets ( this, ScResId( FT_NSHEETS ) ),
45 : : aEdNSheets ( this, ScResId( ED_NSHEETS ) ),
46 : : aFtSheetPrefix ( this, ScResId( FT_SHEETPREFIX ) ),
47 : 0 : aEdSheetPrefix ( this, ScResId( ED_SHEETPREFIX ) )
48 : : {
49 : 0 : FreeResource();
50 : :
51 : 0 : long nTxtW = aFtNSheets.GetCtrlTextWidth( aFtNSheets.GetText() );
52 : 0 : long nCtrlW = aFtNSheets.GetSizePixel().Width();
53 : 0 : if ( nTxtW >= nCtrlW )
54 : : {
55 : 0 : Size aNewSize = aFtNSheets.GetSizePixel();
56 : 0 : aNewSize.Width() += ( nTxtW - nCtrlW );
57 : 0 : aFtNSheets.SetSizePixel( aNewSize );
58 : 0 : Point aNewPoint = aEdNSheets.GetPosPixel();
59 : 0 : aNewPoint.X() += ( nTxtW - nCtrlW );
60 : 0 : aEdNSheets.SetPosPixel( aNewPoint );
61 : : }
62 : 0 : aEdNSheets.SetModifyHdl( LINK(this, ScTpDefaultsOptions, NumModifiedHdl) );
63 : 0 : aEdSheetPrefix.SetModifyHdl( LINK(this, ScTpDefaultsOptions, PrefixModifiedHdl) );
64 : 0 : aEdSheetPrefix.SetGetFocusHdl( LINK(this, ScTpDefaultsOptions, PrefixEditOnFocusHdl) );
65 : 0 : }
66 : :
67 : 0 : ScTpDefaultsOptions::~ScTpDefaultsOptions()
68 : : {
69 : 0 : }
70 : :
71 : 0 : SfxTabPage* ScTpDefaultsOptions::Create(Window *pParent, const SfxItemSet &rCoreAttrs)
72 : : {
73 : 0 : return new ScTpDefaultsOptions(pParent, rCoreAttrs);
74 : : }
75 : :
76 : 0 : sal_Bool ScTpDefaultsOptions::FillItemSet(SfxItemSet &rCoreSet)
77 : : {
78 : 0 : sal_Bool bRet = false;
79 : 0 : ScDefaultsOptions aOpt;
80 : :
81 : 0 : SCTAB nTabCount = static_cast<SCTAB>(aEdNSheets.GetValue());
82 : 0 : OUString aSheetPrefix = aEdSheetPrefix.GetText();
83 : :
84 : :
85 : 0 : if ( aEdNSheets.GetSavedValue() != aEdNSheets.GetText()
86 : 0 : || static_cast<OUString>(aEdSheetPrefix.GetSavedValue()) != aSheetPrefix )
87 : : {
88 : 0 : aOpt.SetInitTabCount( nTabCount );
89 : 0 : aOpt.SetInitTabPrefix( aSheetPrefix );
90 : :
91 : 0 : rCoreSet.Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS, aOpt ) );
92 : 0 : bRet = true;
93 : : }
94 : 0 : return bRet;
95 : : }
96 : :
97 : 0 : void ScTpDefaultsOptions::Reset(const SfxItemSet& rCoreSet)
98 : : {
99 : 0 : ScDefaultsOptions aOpt;
100 : 0 : const SfxPoolItem* pItem = NULL;
101 : :
102 : 0 : if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCDEFAULTSOPTIONS, false , &pItem))
103 : 0 : aOpt = ((const ScTpDefaultsItem*)pItem)->GetDefaultsOptions();
104 : :
105 : 0 : aEdNSheets.SetValue( static_cast<sal_uInt16>( aOpt.GetInitTabCount()) );
106 : 0 : aEdSheetPrefix.SetText( aOpt.GetInitTabPrefix() );
107 : 0 : aEdNSheets.SaveValue();
108 : 0 : aEdSheetPrefix.SaveValue();
109 : 0 : }
110 : :
111 : 0 : int ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
112 : : {
113 : 0 : return KEEP_PAGE;
114 : : }
115 : :
116 : 0 : void ScTpDefaultsOptions::CheckNumSheets()
117 : : {
118 : 0 : sal_Int64 nVal = aEdNSheets.GetValue();
119 : 0 : if (nVal > MAXINITTAB)
120 : 0 : aEdNSheets.SetValue(MAXINITTAB);
121 : 0 : if (nVal < MININITTAB)
122 : 0 : aEdNSheets.SetValue(MININITTAB);
123 : 0 : }
124 : :
125 : 0 : void ScTpDefaultsOptions::CheckPrefix(Edit* pEdit)
126 : : {
127 : 0 : if (!pEdit)
128 : 0 : return;
129 : :
130 : 0 : OUString aSheetPrefix = pEdit->GetText();
131 : :
132 : 0 : if ( !aSheetPrefix.isEmpty() && !ScDocument::ValidTabName( aSheetPrefix ) )
133 : : {
134 : : // Revert to last good Prefix and also select it to
135 : : // indicate something illegal was typed
136 : 0 : Selection aSel( 0, maOldPrefixValue.getLength() );
137 : 0 : pEdit->SetText( maOldPrefixValue, aSel );
138 : : }
139 : : else
140 : : {
141 : 0 : OnFocusPrefixInput(pEdit);
142 : 0 : }
143 : : }
144 : :
145 : 0 : void ScTpDefaultsOptions::OnFocusPrefixInput(Edit* pEdit)
146 : : {
147 : 0 : if (!pEdit)
148 : 0 : return;
149 : :
150 : : // Store Prefix in case we need to revert
151 : 0 : maOldPrefixValue = pEdit->GetText();
152 : : }
153 : :
154 : :
155 : 0 : IMPL_LINK_NOARG(ScTpDefaultsOptions, NumModifiedHdl)
156 : : {
157 : 0 : CheckNumSheets();
158 : 0 : return 0;
159 : : }
160 : :
161 : 0 : IMPL_LINK( ScTpDefaultsOptions, PrefixModifiedHdl, Edit*, pEdit )
162 : : {
163 : 0 : CheckPrefix(pEdit);
164 : 0 : return 0;
165 : : }
166 : :
167 : 0 : IMPL_LINK( ScTpDefaultsOptions, PrefixEditOnFocusHdl, Edit*, pEdit )
168 : : {
169 : 0 : OnFocusPrefixInput(pEdit);
170 : 0 : return 0;
171 : : }
172 : :
173 : :
174 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|