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