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 : // the following computation must be modified accordingly if a third line is added to this dialog
52 0 : long nTxtW1 = aFtNSheets.GetCtrlTextWidth( aFtNSheets.GetText() );
53 0 : long nCtrlW1 = aFtNSheets.GetSizePixel().Width();
54 0 : long nTxtW2 = aFtSheetPrefix.GetCtrlTextWidth(aFtSheetPrefix.GetText() );
55 0 : long nCtrlW2 = aFtSheetPrefix.GetSizePixel().Width();
56 0 : if ( nTxtW1 >= nCtrlW1 || nTxtW2 >= nCtrlW2)
57 : {
58 0 : long nTxtW = std::max(nTxtW1,nTxtW2);
59 0 : Size aNewSize = aFtNSheets.GetSizePixel();
60 0 : aNewSize.Width() = nTxtW;
61 0 : aFtNSheets.SetSizePixel( aNewSize );
62 0 : aFtSheetPrefix.SetSizePixel( aNewSize );
63 0 : Point aNewPoint = aEdNSheets.GetPosPixel();
64 0 : aNewPoint.X() += (nTxtW - nCtrlW1);
65 0 : aEdNSheets.SetPosPixel( aNewPoint );
66 0 : aNewPoint.Y() = aEdSheetPrefix.GetPosPixel().Y();
67 0 : aEdSheetPrefix.SetPosPixel( aNewPoint );
68 : }
69 0 : aEdNSheets.SetModifyHdl( LINK(this, ScTpDefaultsOptions, NumModifiedHdl) );
70 0 : aEdSheetPrefix.SetModifyHdl( LINK(this, ScTpDefaultsOptions, PrefixModifiedHdl) );
71 0 : aEdSheetPrefix.SetGetFocusHdl( LINK(this, ScTpDefaultsOptions, PrefixEditOnFocusHdl) );
72 0 : }
73 :
74 0 : ScTpDefaultsOptions::~ScTpDefaultsOptions()
75 : {
76 0 : }
77 :
78 0 : SfxTabPage* ScTpDefaultsOptions::Create(Window *pParent, const SfxItemSet &rCoreAttrs)
79 : {
80 0 : return new ScTpDefaultsOptions(pParent, rCoreAttrs);
81 : }
82 :
83 0 : sal_Bool ScTpDefaultsOptions::FillItemSet(SfxItemSet &rCoreSet)
84 : {
85 0 : sal_Bool bRet = false;
86 0 : ScDefaultsOptions aOpt;
87 :
88 0 : SCTAB nTabCount = static_cast<SCTAB>(aEdNSheets.GetValue());
89 0 : OUString aSheetPrefix = aEdSheetPrefix.GetText();
90 :
91 :
92 0 : if ( aEdNSheets.GetSavedValue() != aEdNSheets.GetText()
93 0 : || static_cast<OUString>(aEdSheetPrefix.GetSavedValue()) != aSheetPrefix )
94 : {
95 0 : aOpt.SetInitTabCount( nTabCount );
96 0 : aOpt.SetInitTabPrefix( aSheetPrefix );
97 :
98 0 : rCoreSet.Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS, aOpt ) );
99 0 : bRet = true;
100 : }
101 0 : return bRet;
102 : }
103 :
104 0 : void ScTpDefaultsOptions::Reset(const SfxItemSet& rCoreSet)
105 : {
106 0 : ScDefaultsOptions aOpt;
107 0 : const SfxPoolItem* pItem = NULL;
108 :
109 0 : if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCDEFAULTSOPTIONS, false , &pItem))
110 0 : aOpt = ((const ScTpDefaultsItem*)pItem)->GetDefaultsOptions();
111 :
112 0 : aEdNSheets.SetValue( static_cast<sal_uInt16>( aOpt.GetInitTabCount()) );
113 0 : aEdSheetPrefix.SetText( aOpt.GetInitTabPrefix() );
114 0 : aEdNSheets.SaveValue();
115 0 : aEdSheetPrefix.SaveValue();
116 0 : }
117 :
118 0 : int ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
119 : {
120 0 : return KEEP_PAGE;
121 : }
122 :
123 0 : void ScTpDefaultsOptions::CheckNumSheets()
124 : {
125 0 : sal_Int64 nVal = aEdNSheets.GetValue();
126 0 : if (nVal > MAXINITTAB)
127 0 : aEdNSheets.SetValue(MAXINITTAB);
128 0 : if (nVal < MININITTAB)
129 0 : aEdNSheets.SetValue(MININITTAB);
130 0 : }
131 :
132 0 : void ScTpDefaultsOptions::CheckPrefix(Edit* pEdit)
133 : {
134 0 : if (!pEdit)
135 0 : return;
136 :
137 0 : OUString aSheetPrefix = pEdit->GetText();
138 :
139 0 : if ( !aSheetPrefix.isEmpty() && !ScDocument::ValidTabName( aSheetPrefix ) )
140 : {
141 : // Revert to last good Prefix and also select it to
142 : // indicate something illegal was typed
143 0 : Selection aSel( 0, maOldPrefixValue.getLength() );
144 0 : pEdit->SetText( maOldPrefixValue, aSel );
145 : }
146 : else
147 : {
148 0 : OnFocusPrefixInput(pEdit);
149 0 : }
150 : }
151 :
152 0 : void ScTpDefaultsOptions::OnFocusPrefixInput(Edit* pEdit)
153 : {
154 0 : if (!pEdit)
155 0 : return;
156 :
157 : // Store Prefix in case we need to revert
158 0 : maOldPrefixValue = pEdit->GetText();
159 : }
160 :
161 :
162 0 : IMPL_LINK_NOARG(ScTpDefaultsOptions, NumModifiedHdl)
163 : {
164 0 : CheckNumSheets();
165 0 : return 0;
166 : }
167 :
168 0 : IMPL_LINK( ScTpDefaultsOptions, PrefixModifiedHdl, Edit*, pEdit )
169 : {
170 0 : CheckPrefix(pEdit);
171 0 : return 0;
172 : }
173 :
174 0 : IMPL_LINK( ScTpDefaultsOptions, PrefixEditOnFocusHdl, Edit*, pEdit )
175 : {
176 0 : OnFocusPrefixInput(pEdit);
177 0 : return 0;
178 0 : }
179 :
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|