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_sfx2.hxx" 30 #include <com/sun/star/frame/XDesktop.hpp> 31 #include <com/sun/star/script/XLibraryContainer.hpp> 32 #include <comphelper/processfactory.hxx> 33 #include <com/sun/star/uno/Reference.h> 34 #include <basic/basrdll.hxx> 35 #include <tools/urlobj.hxx> 36 #include <svl/macitem.hxx> 37 #include <basic/sbxfac.hxx> 38 #include <basic/sbx.hxx> 39 #include <vcl/gradient.hxx> 40 #include <svl/rectitem.hxx> 41 #include <svl/intitem.hxx> 42 #include <svl/eitem.hxx> 43 #include <basic/sbmod.hxx> 44 #include <svl/whiter.hxx> 45 #include <basic/sbmeth.hxx> 46 #include <basic/sbstar.hxx> 47 #include <vcl/wrkwin.hxx> 48 #include <vcl/msgbox.hxx> 49 #include <basic/sbuno.hxx> 50 #include <svtools/sfxecode.hxx> 51 #include <svtools/ehdl.hxx> 52 53 #include <unotools/undoopt.hxx> 54 #include <unotools/pathoptions.hxx> 55 #include <unotools/useroptions.hxx> 56 #include <unotools/bootstrap.hxx> 57 58 #include <sfx2/appuno.hxx> 59 #include <sfx2/module.hxx> 60 #include "arrdecl.hxx" 61 #include <sfx2/app.hxx> 62 #include "sfxtypes.hxx" 63 #include "sfx2/sfxresid.hxx" 64 #include <sfx2/msg.hxx> 65 #include <sfx2/msgpool.hxx> 66 #include <sfx2/progress.hxx> 67 #include <sfx2/objsh.hxx> 68 #include <sfx2/objitem.hxx> 69 #include <sfx2/viewfrm.hxx> 70 #include <sfx2/viewsh.hxx> 71 #include <sfx2/dispatch.hxx> 72 #include "sfx2/tplpitem.hxx" 73 #include "sfx2/minfitem.hxx" 74 #include "app.hrc" 75 #include <sfx2/evntconf.hxx> 76 #include <sfx2/request.hxx> 77 #include <sfx2/dinfdlg.hxx> 78 #include "appdata.hxx" 79 #include "appbas.hxx" 80 #include "sfx2/sfxhelp.hxx" 81 #include "sfx2/basmgr.hxx" 82 #include "sorgitm.hxx" 83 #include "appbaslib.hxx" 84 #include <basic/basicmanagerrepository.hxx> 85 86 #define ITEMID_SEARCH SID_SEARCH_ITEM 87 88 #include <svl/srchitem.hxx> 89 #include <vos/socket.hxx> 90 91 #define SFX_TYPEMAP 92 #define Selection 93 #include "sfxslots.hxx" 94 95 using namespace ::com::sun::star; 96 using namespace ::com::sun::star::uno; 97 using namespace ::com::sun::star::frame; 98 using namespace ::com::sun::star::script; 99 100 using ::basic::BasicManagerRepository; 101 102 //======================================================================== 103 104 //------------------------------------------------------------------------ 105 String lcl_GetVersionString(ResMgr* /*pAppData_ImplResMgr*/) 106 { 107 ::rtl::OUString aDefault; 108 String aVersion( utl::Bootstrap::getBuildIdData( aDefault )); 109 110 if ( aVersion.Len() == 0 ) 111 { 112 DBG_ERROR( "No BUILDID in bootstrap file found" ); 113 } 114 115 aVersion.Erase( 0, aVersion.Search( ':' ) + 1 ); 116 aVersion.Erase( aVersion.Search( ')' ) ); 117 return aVersion; 118 } 119 120 //========================================================================= 121 sal_uInt16 SfxApplication::SaveBasicManager() const 122 { 123 return 0; 124 } 125 126 //-------------------------------------------------------------------- 127 sal_uInt16 SfxApplication::SaveBasicAndDialogContainer() const 128 { 129 if ( pAppData_Impl->pBasicManager->isValid() ) 130 pAppData_Impl->pBasicManager->storeAllLibraries(); 131 return 0; 132 } 133 134 //-------------------------------------------------------------------- 135 136 void SfxApplication::RegisterBasicConstants 137 ( 138 const char*, // Prefix vor Konstanten-Namen 139 const SfxConstant*, // Array von <SfxConstant> Instanzen 140 sal_uInt16 // Anahl der Kontanten in pConsts 141 ) 142 143 /* [Beschreibung] 144 145 Diese Methode meldet Konstanten beim BASIC an. Sie sollte on-demand 146 (in GetSbxObject() der Applikation) gerufen werden. Das Array mu\s 147 alphabetisch nach den Namen sortiert sein! 148 149 Durch den Prefix kann Speicher gespart und das Suchen beschleunigt 150 werden. Im StarOffice soll der Prefix "so" verwendet werden. 151 152 153 [Beispiel] 154 155 const SfxConstant __FAR_DATA aConstants[] = 156 { 157 SFX_BOOL_CONSTANT( "False", sal_False ), 158 SFX_BOOL_CONSTANT( "True", sal_True ), 159 }; 160 161 ... 162 SFX_APP()->RegisterBasicConstants( 0, aConstants, 2 ); 163 ... 164 165 */ 166 167 { 168 // DBG_ASSERT( pAppData_Impl->pBasicMgr, "no basic available" ); 169 170 // pAppData_Impl->pBasicMgr->GetLib(0)->Insert( 171 // new SfxConstants_Impl( pPrefix, pConsts, nCount ) ); 172 } 173 174 //-------------------------------------------------------------------- 175 176 SbxVariable* MakeVariable( StarBASIC *pBas, SbxObject *pObject, 177 const char *pName, sal_uInt32 nSID, SbxDataType eType, SbxClassType eClassType ) 178 { 179 SbxVariable *pVar = pBas->Make( String::CreateFromAscii(pName), eClassType, eType ); //SbxCLASS_PROPERTY 180 pVar->SetUserData( nSID ); 181 pVar->SetFlag( SBX_DONTSTORE ); 182 pObject->StartListening( pVar->GetBroadcaster() ); 183 return pVar; 184 } 185 186 //-------------------------------------------------------------------- 187 188 BasicManager* SfxApplication::GetBasicManager() 189 { 190 return BasicManagerRepository::getApplicationBasicManager( true ); 191 } 192 193 //-------------------------------------------------------------------- 194 195 Reference< XLibraryContainer > SfxApplication::GetDialogContainer() 196 { 197 if ( !pAppData_Impl->pBasicManager->isValid() ) 198 GetBasicManager(); 199 return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS ); 200 } 201 202 //-------------------------------------------------------------------- 203 204 Reference< XLibraryContainer > SfxApplication::GetBasicContainer() 205 { 206 if ( !pAppData_Impl->pBasicManager->isValid() ) 207 GetBasicManager(); 208 return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS ); 209 } 210 211 //-------------------------------------------------------------------- 212 213 StarBASIC* SfxApplication::GetBasic() 214 { 215 return GetBasicManager()->GetLib(0); 216 } 217 218 //------------------------------------------------------------------------- 219 void SfxApplication::PropExec_Impl( SfxRequest &rReq ) 220 { 221 rReq.GetArgs(); 222 sal_uInt16 nSID = rReq.GetSlot(); 223 switch ( nSID ) 224 { 225 case SID_CREATE_BASICOBJECT: 226 { 227 SFX_REQUEST_ARG(rReq, pItem, SfxStringItem, nSID, sal_False); 228 if ( pItem ) 229 { 230 SbxObject* pObject = SbxBase::CreateObject( pItem->GetValue() ); 231 pObject->AddRef(); 232 //(mba) rReq.SetReturnValue( SfxObjectItem( 0, pObject ) ); 233 rReq.Done(); 234 } 235 break; 236 } 237 238 case SID_DELETE_BASICOBJECT: 239 { 240 SFX_REQUEST_ARG(rReq, pItem, SfxObjectItem, nSID, sal_False); 241 if ( pItem ) 242 { 243 //(mba) SbxObject* pObject = pItem->GetObject(); 244 //(mba) pObject->ReleaseRef(); 245 } 246 break; 247 } 248 249 case SID_ATTR_UNDO_COUNT: 250 { 251 SFX_REQUEST_ARG(rReq, pCountItem, SfxUInt16Item, nSID, sal_False); 252 SvtUndoOptions().SetUndoCount( pCountItem->GetValue() ); 253 break; 254 } 255 256 case SID_WIN_VISIBLE: 257 { 258 break; 259 } 260 261 case SID_STATUSBARTEXT: 262 { 263 SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False); 264 String aText = pStringItem->GetValue(); 265 if ( aText.Len() ) 266 GetpApp()->ShowStatusText( aText ); 267 else 268 GetpApp()->HideStatusText(); 269 break; 270 } 271 272 case SID_OFFICE_PRIVATE_USE: 273 case SID_OFFICE_COMMERCIAL_USE: 274 { 275 DBG_ASSERT( sal_False, "SfxApplication::PropExec_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" ); 276 break; 277 } 278 279 case SID_OFFICE_CUSTOMERNUMBER: 280 { 281 SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False); 282 283 if ( pStringItem ) 284 SvtUserOptions().SetCustomerNumber( pStringItem->GetValue() ); 285 break; 286 } 287 } 288 } 289 290 //------------------------------------------------------------------------- 291 void SfxApplication::PropState_Impl( SfxItemSet &rSet ) 292 { 293 // SfxViewFrame *pFrame = SfxViewFrame::Current(); 294 SfxWhichIter aIter(rSet); 295 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) 296 { 297 switch ( nSID ) 298 { 299 case SID_PROGNAME: 300 rSet.Put( SfxStringItem( SID_PROGNAME, GetName() ) ); 301 break; 302 303 case SID_ACTIVEDOCUMENT: 304 rSet.Put( SfxObjectItem( SID_ACTIVEDOCUMENT, SfxObjectShell::Current() ) ); 305 break; 306 307 case SID_APPLICATION: 308 rSet.Put( SfxObjectItem( SID_APPLICATION, this ) ); 309 break; 310 311 case SID_PROGFILENAME: 312 rSet.Put( SfxStringItem( SID_PROGFILENAME, Application::GetAppFileName() ) ); 313 break; 314 315 case SID_ATTR_UNDO_COUNT: 316 rSet.Put( SfxUInt16Item( SID_ATTR_UNDO_COUNT, sal::static_int_cast< sal_uInt16 >( SvtUndoOptions().GetUndoCount() ) ) ); 317 break; 318 319 case SID_UPDATE_VERSION: 320 rSet.Put( SfxUInt32Item( SID_UPDATE_VERSION, SUPD ) ); 321 break; 322 323 case SID_OFFICE_CUSTOMERNUMBER: 324 { 325 rSet.Put( SfxStringItem( nSID, SvtUserOptions().GetCustomerNumber() ) ); 326 break; 327 } 328 } 329 } 330 } 331 332