1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 #undef SC_DLLIMPLEMENTATION 32 33 34 35 #include "scitems.hxx" 36 #include <svx/drawitem.hxx> 37 #include <svx/xtable.hxx> 38 #include <sfx2/objsh.hxx> 39 #include <unotools/useroptions.hxx> 40 #include <vcl/msgbox.hxx> 41 #include <unotools/localedatawrapper.hxx> 42 43 #include "global.hxx" 44 #include "globstr.hrc" 45 #include "tabvwsh.hxx" 46 #include "viewdata.hxx" 47 #include "document.hxx" 48 #include "scresid.hxx" 49 #include "scendlg.hrc" 50 #include "scendlg.hxx" 51 52 //======================================================================== 53 54 ScNewScenarioDlg::ScNewScenarioDlg( Window* pParent, const String& rName, sal_Bool bEdit, sal_Bool bSheetProtected) 55 56 : ModalDialog ( pParent, ScResId( RID_SCDLG_NEWSCENARIO ) ), 57 aFlName ( this, ScResId( FL_NAME )), 58 aEdName ( this, ScResId( ED_NAME ) ), 59 aFlComment ( this, ScResId( FL_COMMENT ) ), 60 aEdComment ( this, ScResId( ED_COMMENT ) ), 61 aFlOptions ( this, ScResId( FL_OPTIONS ) ), 62 aCbShowFrame ( this, ScResId( CB_SHOWFRAME ) ), 63 aLbColor ( this, ScResId( LB_COLOR ) ), 64 //aCbPrintFrame ( this, ScResId( CB_PRINTFRAME ) ), 65 aCbTwoWay ( this, ScResId( CB_TWOWAY ) ), 66 //aCbAttrib ( this, ScResId( CB_ATTRIB ) ), 67 //aCbValue ( this, ScResId( CB_VALUE ) ), 68 aCbCopyAll ( this, ScResId( CB_COPYALL ) ), 69 aCbProtect ( this, ScResId( CB_PROTECT ) ), 70 aBtnOk ( this, ScResId( BTN_OK ) ), 71 aBtnCancel ( this, ScResId( BTN_CANCEL ) ), 72 aBtnHelp ( this, ScResId( BTN_HELP ) ), 73 aDefScenarioName( rName ), 74 bIsEdit ( bEdit ) 75 { 76 if (bIsEdit) 77 SetText(String(ScResId(STR_EDIT))); 78 79 SfxObjectShell* pDocSh = SfxObjectShell::Current(); 80 if ( pDocSh ) 81 { 82 const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE ); 83 if ( pItem ) 84 { 85 XColorTable* pColorTable = ((SvxColorTableItem*)pItem)->GetColorTable(); 86 if (pColorTable) 87 { 88 aLbColor.SetUpdateMode( sal_False ); 89 long nCount = pColorTable->Count(); 90 for ( long n=0; n<nCount; n++ ) 91 { 92 XColorEntry* pEntry = pColorTable->GetColor(n); 93 aLbColor.InsertEntry( pEntry->GetColor(), pEntry->GetName() ); 94 } 95 aLbColor.SetUpdateMode( sal_True ); 96 } 97 } 98 } 99 100 SvtUserOptions aUserOpt; 101 102 String aComment( ScResId( STR_CREATEDBY ) ); 103 104 aComment += ' '; 105 aComment += (String)aUserOpt.GetFirstName(); 106 aComment += ' '; 107 aComment += (String)aUserOpt.GetLastName(); 108 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " )); 109 aComment += String( ScResId( STR_ON ) ); 110 aComment += ' '; 111 aComment += ScGlobal::GetpLocaleData()->getDate( Date() );//CHINA001 aComment += ScGlobal::pLocaleData->getDate( Date() ); 112 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " )); 113 aComment += ScGlobal::GetpLocaleData()->getTime( Time() );//CHINA001 aComment += ScGlobal::pLocaleData->getTime( Time() ); 114 115 aEdComment .SetText( aComment ); 116 aEdName .SetText( rName ); 117 aBtnOk .SetClickHdl( LINK( this, ScNewScenarioDlg, OkHdl ) ); 118 aCbShowFrame.SetClickHdl( LINK( this, ScNewScenarioDlg, EnableHdl ) ); 119 120 aLbColor.SetAccessibleName(String(ScResId( STR_COLOR ) )); 121 122 FreeResource(); 123 124 aLbColor.SelectEntry( Color( COL_LIGHTGRAY ) ); 125 aCbShowFrame.Check(sal_True); 126 //aCbPrintFrame.Check(sal_True); 127 aCbTwoWay.Check(sal_True); 128 //aCbAttrib.Check(sal_False); 129 //aCbValue.Check(sal_False); 130 aCbCopyAll.Check(sal_False); 131 aCbProtect.Check(sal_True); 132 133 if (bIsEdit) 134 aCbCopyAll.Enable(sal_False); 135 // If the Sheet is protected then we disable the Scenario Protect input 136 // and default it to true above. Note we are in 'Add' mode here as: if 137 // Sheet && scenario protection are true, then we cannot edit this dialog. 138 if (bSheetProtected) 139 aCbProtect.Enable(sal_False); 140 141 //! die drei funktionieren noch nicht... 142 /* 143 aCbPrintFrame.Enable(sal_False); 144 aCbAttrib.Enable(sal_False); 145 aCbValue.Enable(sal_False); 146 */ 147 148 aEdComment.SetAccessibleRelationMemberOf(&aFlComment); 149 aLbColor.SetAccessibleRelationLabeledBy(&aCbShowFrame); 150 } 151 152 //------------------------------------------------------------------------ 153 154 __EXPORT ScNewScenarioDlg::~ScNewScenarioDlg() 155 { 156 } 157 158 //------------------------------------------------------------------------ 159 160 void ScNewScenarioDlg::GetScenarioData( String& rName, String& rComment, 161 Color& rColor, sal_uInt16& rFlags ) const 162 { 163 rComment = aEdComment.GetText(); 164 rName = aEdName.GetText(); 165 166 if ( rName.Len() == 0 ) 167 rName = aDefScenarioName; 168 169 rColor = aLbColor.GetSelectEntryColor(); 170 sal_uInt16 nBits = 0; 171 if (aCbShowFrame.IsChecked()) 172 nBits |= SC_SCENARIO_SHOWFRAME; 173 /* 174 if (aCbPrintFrame.IsChecked()) 175 nBits |= SC_SCENARIO_PRINTFRAME; 176 */ 177 if (aCbTwoWay.IsChecked()) 178 nBits |= SC_SCENARIO_TWOWAY; 179 /* 180 if (aCbAttrib.IsChecked()) 181 nBits |= SC_SCENARIO_ATTRIB; 182 if (aCbValue.IsChecked()) 183 nBits |= SC_SCENARIO_VALUE; 184 */ 185 if (aCbCopyAll.IsChecked()) 186 nBits |= SC_SCENARIO_COPYALL; 187 if (aCbProtect.IsChecked()) 188 nBits |= SC_SCENARIO_PROTECT; 189 rFlags = nBits; 190 } 191 192 void ScNewScenarioDlg::SetScenarioData( const String& rName, const String& rComment, 193 const Color& rColor, sal_uInt16 nFlags ) 194 { 195 aEdComment.SetText(rComment); 196 aEdName.SetText(rName); 197 aLbColor.SelectEntry(rColor); 198 199 aCbShowFrame.Check ( (nFlags & SC_SCENARIO_SHOWFRAME) != 0 ); 200 EnableHdl( &aCbShowFrame ); 201 //aCbPrintFrame.Check( (nFlags & SC_SCENARIO_PRINTFRAME) != 0 ); 202 aCbTwoWay.Check ( (nFlags & SC_SCENARIO_TWOWAY) != 0 ); 203 //aCbAttrib.Check ( (nFlags & SC_SCENARIO_ATTRIB) != 0 ); 204 //aCbValue.Check ( (nFlags & SC_SCENARIO_VALUE) != 0 ); 205 // CopyAll nicht 206 aCbProtect.Check ( (nFlags & SC_SCENARIO_PROTECT) != 0 ); 207 } 208 209 //------------------------------------------------------------------------ 210 211 IMPL_LINK( ScNewScenarioDlg, OkHdl, OKButton *, EMPTYARG ) 212 { 213 String aName ( aEdName.GetText() ); 214 ScDocument* pDoc = ((ScTabViewShell*)SfxViewShell::Current())-> 215 GetViewData()->GetDocument(); 216 217 aName.EraseLeadingChars( ' ' ); 218 aName.EraseTrailingChars( ' ' ); 219 aEdName.SetText( aName ); 220 221 if ( !pDoc->ValidTabName( aName ) ) 222 { 223 InfoBox( this, ScGlobal::GetRscString( STR_INVALIDTABNAME ) ). 224 Execute(); 225 aEdName.GrabFocus(); 226 } 227 else if ( !bIsEdit && !pDoc->ValidNewTabName( aName ) ) 228 { 229 InfoBox( this, ScGlobal::GetRscString( STR_NEWTABNAMENOTUNIQUE ) ). 230 Execute(); 231 aEdName.GrabFocus(); 232 } 233 else 234 EndDialog( RET_OK ); 235 return 0; 236 237 //! beim Editieren testen, ob eine andere Tabelle den Namen hat! 238 } 239 240 //------------------------------------------------------------------------ 241 242 IMPL_LINK( ScNewScenarioDlg, EnableHdl, CheckBox *, pBox ) 243 { 244 if( pBox == &aCbShowFrame ) 245 aLbColor.Enable( aCbShowFrame.IsChecked() ); 246 return 0; 247 } 248 249