xref: /aoo4110/main/sc/source/ui/dbgui/scendlg.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #undef SC_DLLIMPLEMENTATION
28 
29 
30 
31 #include "scitems.hxx"
32 #include <svx/drawitem.hxx>
33 #include <svx/xtable.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <unotools/useroptions.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <unotools/localedatawrapper.hxx>
38 
39 #include "global.hxx"
40 #include "globstr.hrc"
41 #include "tabvwsh.hxx"
42 #include "viewdata.hxx"
43 #include "document.hxx"
44 #include "scresid.hxx"
45 #include "scendlg.hrc"
46 #include "scendlg.hxx"
47 
48 //========================================================================
49 
ScNewScenarioDlg(Window * pParent,const String & rName,sal_Bool bEdit,sal_Bool bSheetProtected)50 ScNewScenarioDlg::ScNewScenarioDlg( Window* pParent, const String& rName, sal_Bool bEdit, sal_Bool bSheetProtected)
51 
52 	:	ModalDialog 	( pParent, ScResId( RID_SCDLG_NEWSCENARIO ) ),
53         aFlName         ( this, ScResId( FL_NAME )),
54 		aEdName 		( this, ScResId( ED_NAME ) ),
55         aFlComment      ( this, ScResId( FL_COMMENT ) ),
56 		aEdComment		( this, ScResId( ED_COMMENT ) ),
57         aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
58 		aCbShowFrame	( this, ScResId( CB_SHOWFRAME ) ),
59 		aLbColor		( this, ScResId( LB_COLOR ) ),
60 		//aCbPrintFrame	( this, ScResId( CB_PRINTFRAME ) ),
61 		aCbTwoWay		( this, ScResId( CB_TWOWAY ) ),
62 		//aCbAttrib		( this, ScResId( CB_ATTRIB ) ),
63 		//aCbValue		( this, ScResId( CB_VALUE ) ),
64 		aCbCopyAll		( this, ScResId( CB_COPYALL ) ),
65         aCbProtect      ( this, ScResId( CB_PROTECT ) ),
66 		aBtnOk			( this, ScResId( BTN_OK ) ),
67 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
68 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
69 		aDefScenarioName( rName ),
70 		bIsEdit			( bEdit )
71 {
72 	if (bIsEdit)
73 		SetText(String(ScResId(STR_EDIT)));
74 
75 	SfxObjectShell*	pDocSh = SfxObjectShell::Current();
76 	if ( pDocSh )
77 	{
78         const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
79 		if ( pItem )
80 		{
81 			XColorListSharedPtr aColorTable = static_cast< const SvxColorTableItem* >(pItem)->GetColorTable();
82 			if (aColorTable.get())
83 			{
84 				aLbColor.SetUpdateMode( sal_False );
85 				long nCount = aColorTable->Count();
86 				for ( long n=0; n<nCount; n++ )
87 				{
88 					XColorEntry* pEntry = aColorTable->GetColor(n);
89 					aLbColor.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
90 				}
91 				aLbColor.SetUpdateMode( sal_True );
92 			}
93 		}
94 	}
95 
96 	SvtUserOptions aUserOpt;
97 
98 	String aComment( ScResId( STR_CREATEDBY ) );
99 
100 	aComment += ' ';
101 	aComment += (String)aUserOpt.GetFirstName();
102 	aComment += ' ';
103 	aComment += (String)aUserOpt.GetLastName();
104 	aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
105 	aComment += String( ScResId( STR_ON ) );
106 	aComment += ' ';
107     aComment += ScGlobal::GetpLocaleData()->getDate( Date() );//CHINA001 aComment += ScGlobal::pLocaleData->getDate( Date() );
108 	aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
109     aComment += ScGlobal::GetpLocaleData()->getTime( Time() );//CHINA001  aComment += ScGlobal::pLocaleData->getTime( Time() );
110 
111 	aEdComment	.SetText( aComment );
112 	aEdName 	.SetText( rName );
113 	aBtnOk		.SetClickHdl( LINK( this, ScNewScenarioDlg, OkHdl ) );
114     aCbShowFrame.SetClickHdl( LINK( this, ScNewScenarioDlg, EnableHdl ) );
115 
116 	aLbColor.SetAccessibleName(String(ScResId( STR_COLOR ) ));
117 
118 	FreeResource();
119 
120 	aLbColor.SelectEntry( Color( COL_LIGHTGRAY ) );
121 	aCbShowFrame.Check(sal_True);
122 	//aCbPrintFrame.Check(sal_True);
123 	aCbTwoWay.Check(sal_True);
124 	//aCbAttrib.Check(sal_False);
125 	//aCbValue.Check(sal_False);
126 	aCbCopyAll.Check(sal_False);
127 	aCbProtect.Check(sal_True);
128 
129 	if (bIsEdit)
130 		aCbCopyAll.Enable(sal_False);
131     // If the Sheet is protected then we disable the Scenario Protect input
132     // and default it to true above. Note we are in 'Add' mode here as: if
133     // Sheet && scenario protection are true, then we cannot edit this dialog.
134     if (bSheetProtected)
135         aCbProtect.Enable(sal_False);
136 
137 	//!	die drei funktionieren noch nicht...
138 	/*
139 	aCbPrintFrame.Enable(sal_False);
140 	aCbAttrib.Enable(sal_False);
141 	aCbValue.Enable(sal_False);
142 	*/
143 
144 	aEdComment.SetAccessibleRelationMemberOf(&aFlComment);
145 	aLbColor.SetAccessibleRelationLabeledBy(&aCbShowFrame);
146 }
147 
148 //------------------------------------------------------------------------
149 
~ScNewScenarioDlg()150 __EXPORT ScNewScenarioDlg::~ScNewScenarioDlg()
151 {
152 }
153 
154 //------------------------------------------------------------------------
155 
GetScenarioData(String & rName,String & rComment,Color & rColor,sal_uInt16 & rFlags) const156 void ScNewScenarioDlg::GetScenarioData( String& rName, String& rComment,
157 										Color& rColor, sal_uInt16& rFlags ) const
158 {
159 	rComment = aEdComment.GetText();
160 	rName	 = aEdName.GetText();
161 
162 	if ( rName.Len() == 0 )
163 		rName = aDefScenarioName;
164 
165 	rColor = aLbColor.GetSelectEntryColor();
166 	sal_uInt16 nBits = 0;
167 	if (aCbShowFrame.IsChecked())
168 		nBits |= SC_SCENARIO_SHOWFRAME;
169 	/*
170 	if (aCbPrintFrame.IsChecked())
171 		nBits |= SC_SCENARIO_PRINTFRAME;
172 	*/
173 	if (aCbTwoWay.IsChecked())
174 		nBits |= SC_SCENARIO_TWOWAY;
175 	/*
176 	if (aCbAttrib.IsChecked())
177 		nBits |= SC_SCENARIO_ATTRIB;
178 	if (aCbValue.IsChecked())
179 		nBits |= SC_SCENARIO_VALUE;
180 	*/
181 	if (aCbCopyAll.IsChecked())
182 		nBits |= SC_SCENARIO_COPYALL;
183 	if (aCbProtect.IsChecked())
184 		nBits |= SC_SCENARIO_PROTECT;
185 	rFlags = nBits;
186 }
187 
SetScenarioData(const String & rName,const String & rComment,const Color & rColor,sal_uInt16 nFlags)188 void ScNewScenarioDlg::SetScenarioData( const String& rName, const String& rComment,
189 										const Color& rColor, sal_uInt16 nFlags )
190 {
191 	aEdComment.SetText(rComment);
192 	aEdName.SetText(rName);
193 	aLbColor.SelectEntry(rColor);
194 
195 	aCbShowFrame.Check ( (nFlags & SC_SCENARIO_SHOWFRAME)  != 0 );
196     EnableHdl( &aCbShowFrame );
197 	//aCbPrintFrame.Check( (nFlags & SC_SCENARIO_PRINTFRAME) != 0 );
198 	aCbTwoWay.Check    ( (nFlags & SC_SCENARIO_TWOWAY)     != 0 );
199 	//aCbAttrib.Check    ( (nFlags & SC_SCENARIO_ATTRIB)     != 0 );
200 	//aCbValue.Check     ( (nFlags & SC_SCENARIO_VALUE)      != 0 );
201 	//	CopyAll nicht
202 	aCbProtect.Check    ( (nFlags & SC_SCENARIO_PROTECT)     != 0 );
203 }
204 
205 //------------------------------------------------------------------------
206 
IMPL_LINK(ScNewScenarioDlg,OkHdl,OKButton *,EMPTYARG)207 IMPL_LINK( ScNewScenarioDlg, OkHdl, OKButton *, EMPTYARG )
208 {
209 	String		aName	( aEdName.GetText() );
210 	ScDocument* pDoc	= ((ScTabViewShell*)SfxViewShell::Current())->
211 								GetViewData()->GetDocument();
212 
213 	aName.EraseLeadingChars( ' ' );
214 	aName.EraseTrailingChars( ' ' );
215 	aEdName.SetText( aName );
216 
217 	if ( !pDoc->ValidTabName( aName ) )
218 	{
219 		InfoBox( this, ScGlobal::GetRscString( STR_INVALIDTABNAME ) ).
220 			Execute();
221 		aEdName.GrabFocus();
222 	}
223 	else if ( !bIsEdit && !pDoc->ValidNewTabName( aName ) )
224 	{
225 		InfoBox( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE ) ).
226 			Execute();
227 		aEdName.GrabFocus();
228 	}
229 	else
230 		EndDialog( RET_OK );
231 	return 0;
232 
233 	//!	beim Editieren testen, ob eine andere Tabelle den Namen hat!
234 }
235 
236 //------------------------------------------------------------------------
237 
IMPL_LINK(ScNewScenarioDlg,EnableHdl,CheckBox *,pBox)238 IMPL_LINK( ScNewScenarioDlg, EnableHdl, CheckBox *, pBox )
239 {
240     if( pBox == &aCbShowFrame )
241         aLbColor.Enable( aCbShowFrame.IsChecked() );
242     return 0;
243 }
244 
245