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