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