1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scendlg.cxx,v $
10 * $Revision: 1.16.296.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 #include "scitems.hxx"
39 #include <svx/drawitem.hxx>
40 #include <svx/xtable.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <svtools/useroptions.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <unotools/localedatawrapper.hxx>
47 #include "globstr.hrc"
48 #include "tabvwsh.hxx"
49 #include "viewdata.hxx"
50 #include "document.hxx"
51 #include "scresid.hxx"
52 #include "scendlg.hrc"
53 #include "scendlg.hxx"
55 //========================================================================
57 ScNewScenarioDlg::ScNewScenarioDlg( Window
* pParent
, const String
& rName
, BOOL bEdit
, BOOL bSheetProtected
)
59 : ModalDialog ( pParent
, ScResId( RID_SCDLG_NEWSCENARIO
) ),
60 aFlName ( this, ScResId( FL_NAME
)),
61 aEdName ( this, ScResId( ED_NAME
) ),
62 aFlComment ( this, ScResId( FL_COMMENT
) ),
63 aEdComment ( this, ScResId( ED_COMMENT
) ),
64 aFlOptions ( this, ScResId( FL_OPTIONS
) ),
65 aCbShowFrame ( this, ScResId( CB_SHOWFRAME
) ),
66 aLbColor ( this, ScResId( LB_COLOR
) ),
67 //aCbPrintFrame ( this, ScResId( CB_PRINTFRAME ) ),
68 aCbTwoWay ( this, ScResId( CB_TWOWAY
) ),
69 //aCbAttrib ( this, ScResId( CB_ATTRIB ) ),
70 //aCbValue ( this, ScResId( CB_VALUE ) ),
71 aCbCopyAll ( this, ScResId( CB_COPYALL
) ),
72 aCbProtect ( this, ScResId( CB_PROTECT
) ),
73 aBtnOk ( this, ScResId( BTN_OK
) ),
74 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
75 aBtnHelp ( this, ScResId( BTN_HELP
) ),
76 aDefScenarioName( rName
),
80 SetText(String(ScResId(STR_EDIT
)));
82 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
85 const SfxPoolItem
* pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
);
88 XColorTable
* pColorTable
= ((SvxColorTableItem
*)pItem
)->GetColorTable();
91 aLbColor
.SetUpdateMode( FALSE
);
92 long nCount
= pColorTable
->Count();
93 for ( long n
=0; n
<nCount
; n
++ )
95 XColorEntry
* pEntry
= pColorTable
->GetColor(n
);
96 aLbColor
.InsertEntry( pEntry
->GetColor(), pEntry
->GetName() );
98 aLbColor
.SetUpdateMode( TRUE
);
103 SvtUserOptions aUserOpt
;
105 String
aComment( ScResId( STR_CREATEDBY
) );
108 aComment
+= (String
)aUserOpt
.GetFirstName();
110 aComment
+= (String
)aUserOpt
.GetLastName();
111 aComment
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
112 aComment
+= String( ScResId( STR_ON
) );
114 aComment
+= ScGlobal::GetpLocaleData()->getDate( Date() );//CHINA001 aComment += ScGlobal::pLocaleData->getDate( Date() );
115 aComment
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
116 aComment
+= ScGlobal::GetpLocaleData()->getTime( Time() );//CHINA001 aComment += ScGlobal::pLocaleData->getTime( Time() );
118 aEdComment
.SetText( aComment
);
119 aEdName
.SetText( rName
);
120 aBtnOk
.SetClickHdl( LINK( this, ScNewScenarioDlg
, OkHdl
) );
121 aCbShowFrame
.SetClickHdl( LINK( this, ScNewScenarioDlg
, EnableHdl
) );
125 aLbColor
.SelectEntry( Color( COL_LIGHTGRAY
) );
126 aCbShowFrame
.Check(TRUE
);
127 //aCbPrintFrame.Check(TRUE);
128 aCbTwoWay
.Check(TRUE
);
129 //aCbAttrib.Check(FALSE);
130 //aCbValue.Check(FALSE);
131 aCbCopyAll
.Check(FALSE
);
132 aCbProtect
.Check(TRUE
);
135 aCbCopyAll
.Enable(FALSE
);
136 // If the Sheet is protected then we disable the Scenario Protect input
137 // and default it to true above. Note we are in 'Add' mode here as: if
138 // Sheet && scenario protection are true, then we cannot edit this dialog.
140 aCbProtect
.Enable(FALSE
);
142 //! die drei funktionieren noch nicht...
144 aCbPrintFrame.Enable(FALSE);
145 aCbAttrib.Enable(FALSE);
146 aCbValue.Enable(FALSE);
150 //------------------------------------------------------------------------
152 __EXPORT
ScNewScenarioDlg::~ScNewScenarioDlg()
156 //------------------------------------------------------------------------
158 void ScNewScenarioDlg::GetScenarioData( String
& rName
, String
& rComment
,
159 Color
& rColor
, USHORT
& rFlags
) const
161 rComment
= aEdComment
.GetText();
162 rName
= aEdName
.GetText();
164 if ( rName
.Len() == 0 )
165 rName
= aDefScenarioName
;
167 rColor
= aLbColor
.GetSelectEntryColor();
169 if (aCbShowFrame
.IsChecked())
170 nBits
|= SC_SCENARIO_SHOWFRAME
;
172 if (aCbPrintFrame.IsChecked())
173 nBits |= SC_SCENARIO_PRINTFRAME;
175 if (aCbTwoWay
.IsChecked())
176 nBits
|= SC_SCENARIO_TWOWAY
;
178 if (aCbAttrib.IsChecked())
179 nBits |= SC_SCENARIO_ATTRIB;
180 if (aCbValue.IsChecked())
181 nBits |= SC_SCENARIO_VALUE;
183 if (aCbCopyAll
.IsChecked())
184 nBits
|= SC_SCENARIO_COPYALL
;
185 if (aCbProtect
.IsChecked())
186 nBits
|= SC_SCENARIO_PROTECT
;
190 void ScNewScenarioDlg::SetScenarioData( const String
& rName
, const String
& rComment
,
191 const Color
& rColor
, USHORT nFlags
)
193 aEdComment
.SetText(rComment
);
194 aEdName
.SetText(rName
);
195 aLbColor
.SelectEntry(rColor
);
197 aCbShowFrame
.Check ( (nFlags
& SC_SCENARIO_SHOWFRAME
) != 0 );
198 EnableHdl( &aCbShowFrame
);
199 //aCbPrintFrame.Check( (nFlags & SC_SCENARIO_PRINTFRAME) != 0 );
200 aCbTwoWay
.Check ( (nFlags
& SC_SCENARIO_TWOWAY
) != 0 );
201 //aCbAttrib.Check ( (nFlags & SC_SCENARIO_ATTRIB) != 0 );
202 //aCbValue.Check ( (nFlags & SC_SCENARIO_VALUE) != 0 );
204 aCbProtect
.Check ( (nFlags
& SC_SCENARIO_PROTECT
) != 0 );
207 //------------------------------------------------------------------------
209 IMPL_LINK( ScNewScenarioDlg
, OkHdl
, OKButton
*, EMPTYARG
)
211 String
aName ( aEdName
.GetText() );
212 ScDocument
* pDoc
= ((ScTabViewShell
*)SfxViewShell::Current())->
213 GetViewData()->GetDocument();
215 aName
.EraseLeadingChars( ' ' );
216 aName
.EraseTrailingChars( ' ' );
217 aEdName
.SetText( aName
);
219 if ( !pDoc
->ValidTabName( aName
) )
221 InfoBox( this, ScGlobal::GetRscString( STR_INVALIDTABNAME
) ).
225 else if ( !bIsEdit
&& !pDoc
->ValidNewTabName( aName
) )
227 InfoBox( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE
) ).
235 //! beim Editieren testen, ob eine andere Tabelle den Namen hat!
238 //------------------------------------------------------------------------
240 IMPL_LINK( ScNewScenarioDlg
, EnableHdl
, CheckBox
*, pBox
)
242 if( pBox
== &aCbShowFrame
)
243 aLbColor
.Enable( aCbShowFrame
.IsChecked() );