Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #undef SC_DLLIMPLEMENTATION
31 : :
32 : :
33 : :
34 : : #include "scitems.hxx"
35 : : #include <comphelper/string.hxx>
36 : : #include <svx/drawitem.hxx>
37 : : #include <svx/xtable.hxx>
38 : : #include <sfx2/objsh.hxx>
39 : : #include <unotools/useroptions.hxx>
40 : : #include <vcl/msgbox.hxx>
41 : : #include <unotools/localedatawrapper.hxx>
42 : :
43 : : #include "global.hxx"
44 : : #include "globstr.hrc"
45 : : #include "tabvwsh.hxx"
46 : : #include "viewdata.hxx"
47 : : #include "document.hxx"
48 : : #include "scresid.hxx"
49 : : #include "scendlg.hrc"
50 : : #include "scendlg.hxx"
51 : :
52 : : //========================================================================
53 : :
54 : 0 : ScNewScenarioDlg::ScNewScenarioDlg( Window* pParent, const String& rName, sal_Bool bEdit, sal_Bool bSheetProtected)
55 : :
56 : : : ModalDialog ( pParent, ScResId( RID_SCDLG_NEWSCENARIO ) ),
57 : : aFlName ( this, ScResId( FL_NAME )),
58 : : aEdName ( this, ScResId( ED_NAME ) ),
59 : : aFlComment ( this, ScResId( FL_COMMENT ) ),
60 : : aEdComment ( this, ScResId( ED_COMMENT ) ),
61 : : aFlOptions ( this, ScResId( FL_OPTIONS ) ),
62 : : aCbShowFrame ( this, ScResId( CB_SHOWFRAME ) ),
63 : : aLbColor ( this, ScResId( LB_COLOR ) ),
64 : : //aCbPrintFrame ( this, ScResId( CB_PRINTFRAME ) ),
65 : : aCbTwoWay ( this, ScResId( CB_TWOWAY ) ),
66 : : //aCbAttrib ( this, ScResId( CB_ATTRIB ) ),
67 : : //aCbValue ( this, ScResId( CB_VALUE ) ),
68 : : aCbCopyAll ( this, ScResId( CB_COPYALL ) ),
69 : : aCbProtect ( this, ScResId( CB_PROTECT ) ),
70 : : aBtnOk ( this, ScResId( BTN_OK ) ),
71 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
72 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
73 : : aDefScenarioName( rName ),
74 : 0 : bIsEdit ( bEdit )
75 : : {
76 : 0 : if (bIsEdit)
77 : 0 : SetText(String(ScResId(STR_EDIT)));
78 : :
79 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
80 : 0 : if ( pDocSh )
81 : : {
82 : 0 : const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
83 : 0 : if ( pItem )
84 : : {
85 : 0 : XColorListRef pColorList = ((SvxColorListItem*)pItem)->GetColorList();
86 : 0 : if (pColorList.is())
87 : : {
88 : 0 : aLbColor.SetUpdateMode( false );
89 : 0 : long nCount = pColorList->Count();
90 : 0 : for ( long n=0; n<nCount; n++ )
91 : : {
92 : 0 : XColorEntry* pEntry = pColorList->GetColor(n);
93 : 0 : aLbColor.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
94 : : }
95 : 0 : aLbColor.SetUpdateMode( sal_True );
96 : 0 : }
97 : : }
98 : : }
99 : :
100 : 0 : SvtUserOptions aUserOpt;
101 : :
102 : 0 : String aComment( ScResId( STR_CREATEDBY ) );
103 : :
104 : 0 : aComment += ' ';
105 : 0 : aComment += (String)aUserOpt.GetFirstName();
106 : 0 : aComment += ' ';
107 : 0 : aComment += (String)aUserOpt.GetLastName();
108 : 0 : aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
109 : 0 : aComment += String( ScResId( STR_ON ) );
110 : 0 : aComment += ' ';
111 : 0 : aComment += ScGlobal::GetpLocaleData()->getDate( Date( Date::SYSTEM ) );
112 : 0 : aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
113 : 0 : aComment += ScGlobal::GetpLocaleData()->getTime( Time( Time::SYSTEM ) );
114 : :
115 : 0 : aEdComment .SetText( aComment );
116 : 0 : aEdName .SetText( rName );
117 : 0 : aBtnOk .SetClickHdl( LINK( this, ScNewScenarioDlg, OkHdl ) );
118 : 0 : aCbShowFrame.SetClickHdl( LINK( this, ScNewScenarioDlg, EnableHdl ) );
119 : :
120 : 0 : aLbColor.SetAccessibleName(String(ScResId( STR_COLOR ) ));
121 : :
122 : 0 : FreeResource();
123 : :
124 : 0 : aLbColor.SelectEntry( Color( COL_LIGHTGRAY ) );
125 : 0 : aCbShowFrame.Check(sal_True);
126 : : //aCbPrintFrame.Check(sal_True);
127 : 0 : aCbTwoWay.Check(sal_True);
128 : : //aCbAttrib.Check(sal_False);
129 : : //aCbValue.Check(sal_False);
130 : 0 : aCbCopyAll.Check(false);
131 : 0 : aCbProtect.Check(sal_True);
132 : :
133 : 0 : if (bIsEdit)
134 : 0 : aCbCopyAll.Enable(false);
135 : : // If the Sheet is protected then we disable the Scenario Protect input
136 : : // and default it to true above. Note we are in 'Add' mode here as: if
137 : : // Sheet && scenario protection are true, then we cannot edit this dialog.
138 : 0 : if (bSheetProtected)
139 : 0 : aCbProtect.Enable(false);
140 : :
141 : : //! die drei funktionieren noch nicht...
142 : : /*
143 : : aCbPrintFrame.Enable(sal_False);
144 : : aCbAttrib.Enable(sal_False);
145 : : aCbValue.Enable(sal_False);
146 : : */
147 : :
148 : 0 : aEdComment.SetAccessibleRelationMemberOf(&aFlComment);
149 : 0 : aLbColor.SetAccessibleRelationLabeledBy(&aCbShowFrame);
150 : 0 : }
151 : :
152 : : //------------------------------------------------------------------------
153 : :
154 : 0 : ScNewScenarioDlg::~ScNewScenarioDlg()
155 : : {
156 : 0 : }
157 : :
158 : : //------------------------------------------------------------------------
159 : :
160 : 0 : void ScNewScenarioDlg::GetScenarioData( rtl::OUString& rName, rtl::OUString& rComment,
161 : : Color& rColor, sal_uInt16& rFlags ) const
162 : : {
163 : 0 : rComment = aEdComment.GetText();
164 : 0 : rName = aEdName.GetText();
165 : :
166 : 0 : if (rName.isEmpty())
167 : 0 : rName = aDefScenarioName;
168 : :
169 : 0 : rColor = aLbColor.GetSelectEntryColor();
170 : 0 : sal_uInt16 nBits = 0;
171 : 0 : if (aCbShowFrame.IsChecked())
172 : 0 : nBits |= SC_SCENARIO_SHOWFRAME;
173 : : /*
174 : : if (aCbPrintFrame.IsChecked())
175 : : nBits |= SC_SCENARIO_PRINTFRAME;
176 : : */
177 : 0 : if (aCbTwoWay.IsChecked())
178 : 0 : nBits |= SC_SCENARIO_TWOWAY;
179 : : /*
180 : : if (aCbAttrib.IsChecked())
181 : : nBits |= SC_SCENARIO_ATTRIB;
182 : : if (aCbValue.IsChecked())
183 : : nBits |= SC_SCENARIO_VALUE;
184 : : */
185 : 0 : if (aCbCopyAll.IsChecked())
186 : 0 : nBits |= SC_SCENARIO_COPYALL;
187 : 0 : if (aCbProtect.IsChecked())
188 : 0 : nBits |= SC_SCENARIO_PROTECT;
189 : 0 : rFlags = nBits;
190 : 0 : }
191 : :
192 : 0 : void ScNewScenarioDlg::SetScenarioData( const rtl::OUString& rName, const rtl::OUString& rComment,
193 : : const Color& rColor, sal_uInt16 nFlags )
194 : : {
195 : 0 : aEdComment.SetText(rComment);
196 : 0 : aEdName.SetText(rName);
197 : 0 : aLbColor.SelectEntry(rColor);
198 : :
199 : 0 : aCbShowFrame.Check ( (nFlags & SC_SCENARIO_SHOWFRAME) != 0 );
200 : 0 : EnableHdl( &aCbShowFrame );
201 : : //aCbPrintFrame.Check( (nFlags & SC_SCENARIO_PRINTFRAME) != 0 );
202 : 0 : aCbTwoWay.Check ( (nFlags & SC_SCENARIO_TWOWAY) != 0 );
203 : : //aCbAttrib.Check ( (nFlags & SC_SCENARIO_ATTRIB) != 0 );
204 : : //aCbValue.Check ( (nFlags & SC_SCENARIO_VALUE) != 0 );
205 : : // CopyAll nicht
206 : 0 : aCbProtect.Check ( (nFlags & SC_SCENARIO_PROTECT) != 0 );
207 : 0 : }
208 : :
209 : : //------------------------------------------------------------------------
210 : :
211 : 0 : IMPL_LINK_NOARG(ScNewScenarioDlg, OkHdl)
212 : : {
213 : 0 : String aName = comphelper::string::strip(aEdName.GetText(), ' ');
214 : 0 : ScDocument* pDoc = ((ScTabViewShell*)SfxViewShell::Current())->
215 : 0 : GetViewData()->GetDocument();
216 : :
217 : 0 : aEdName.SetText( aName );
218 : :
219 : 0 : if ( !pDoc->ValidTabName( aName ) )
220 : : {
221 : 0 : InfoBox( this, ScGlobal::GetRscString( STR_INVALIDTABNAME ) ).
222 : 0 : Execute();
223 : 0 : aEdName.GrabFocus();
224 : : }
225 : 0 : else if ( !bIsEdit && !pDoc->ValidNewTabName( aName ) )
226 : : {
227 : 0 : InfoBox( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE ) ).
228 : 0 : Execute();
229 : 0 : aEdName.GrabFocus();
230 : : }
231 : : else
232 : 0 : EndDialog( RET_OK );
233 : 0 : return 0;
234 : :
235 : : //! beim Editieren testen, ob eine andere Tabelle den Namen hat!
236 : : }
237 : :
238 : : //------------------------------------------------------------------------
239 : :
240 : 0 : IMPL_LINK( ScNewScenarioDlg, EnableHdl, CheckBox *, pBox )
241 : : {
242 : 0 : if( pBox == &aCbShowFrame )
243 : 0 : aLbColor.Enable( aCbShowFrame.IsChecked() );
244 : 0 : return 0;
245 : : }
246 : :
247 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|