1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basctl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <ide_pch.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <vector> 34*cdf0e10cSrcweir #include <algorithm> 35*cdf0e10cSrcweir #include <basic/sbx.hxx> 36*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <iderdll.hxx> 39*cdf0e10cSrcweir #include <iderdll2.hxx> 40*cdf0e10cSrcweir #include <basobj.hxx> 41*cdf0e10cSrcweir #include <basidesh.hxx> 42*cdf0e10cSrcweir #include <objdlg.hxx> 43*cdf0e10cSrcweir #include <bastypes.hxx> 44*cdf0e10cSrcweir #include <basdoc.hxx> 45*cdf0e10cSrcweir #include <basidesh.hrc> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <baside2.hxx> 48*cdf0e10cSrcweir #include <baside3.hxx> 49*cdf0e10cSrcweir #include <basicmod.hxx> 50*cdf0e10cSrcweir #include <localizationmgr.hxx> 51*cdf0e10cSrcweir #include "dlged.hxx" 52*cdf0e10cSrcweir #include <dlgeddef.hxx> 53*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 54*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER_HPP_ 55*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer.hpp> 56*cdf0e10cSrcweir #endif 57*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainerPassword.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 59*cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx> 60*cdf0e10cSrcweir #include <rtl/uri.hxx> 61*cdf0e10cSrcweir #include <osl/process.h> 62*cdf0e10cSrcweir #include <osl/file.hxx> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir using namespace comphelper; 65*cdf0e10cSrcweir using namespace ::com::sun::star; 66*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 67*cdf0e10cSrcweir using namespace ::com::sun::star::container; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //---------------------------------------------------------------------------- 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir extern "C" { 73*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT long basicide_handle_basic_error( void* pPtr ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir return BasicIDE::HandleBasicError( (StarBASIC*)pPtr ); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir namespace BasicIDE 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir //---------------------------------------------------------------------------- 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir SbMethod* CreateMacro( SbModule* pModule, const String& rMacroName ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 86*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 87*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir if( pDispatcher ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir if ( pModule->GetMethods()->Find( rMacroName, SbxCLASS_METHOD ) ) 95*cdf0e10cSrcweir return 0; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir String aMacroName( rMacroName ); 98*cdf0e10cSrcweir if ( aMacroName.Len() == 0 ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir if ( !pModule->GetMethods()->Count() ) 101*cdf0e10cSrcweir aMacroName = String( RTL_CONSTASCII_USTRINGPARAM( "Main" ) ); 102*cdf0e10cSrcweir else 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir sal_Bool bValid = sal_False; 105*cdf0e10cSrcweir String aStdMacroText( RTL_CONSTASCII_USTRINGPARAM( "Macro" ) ); 106*cdf0e10cSrcweir //String aStdMacroText( IDEResId( RID_STR_STDMACRONAME ) ); 107*cdf0e10cSrcweir sal_uInt16 nMacro = 1; 108*cdf0e10cSrcweir while ( !bValid ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir aMacroName = aStdMacroText; 111*cdf0e10cSrcweir aMacroName += String::CreateFromInt32( nMacro ); 112*cdf0e10cSrcweir // Pruefen, ob vorhanden... 113*cdf0e10cSrcweir bValid = pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ) ? sal_False : sal_True; 114*cdf0e10cSrcweir nMacro++; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir ::rtl::OUString aOUSource( pModule->GetSource32() ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // Nicht zu viele Leerzeilen erzeugen... 122*cdf0e10cSrcweir sal_Int32 nSourceLen = aOUSource.getLength(); 123*cdf0e10cSrcweir if ( nSourceLen > 2 ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir const sal_Unicode* pStr = aOUSource.getStr(); 126*cdf0e10cSrcweir if ( pStr[ nSourceLen - 1 ] != LINE_SEP ) 127*cdf0e10cSrcweir aOUSource += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n\n" ) ); 128*cdf0e10cSrcweir else if ( pStr[ nSourceLen - 2 ] != LINE_SEP ) 129*cdf0e10cSrcweir aOUSource += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n" ) ); 130*cdf0e10cSrcweir else if ( pStr[ nSourceLen - 3 ] == LINE_SEP ) 131*cdf0e10cSrcweir aOUSource = aOUSource.copy( 0, nSourceLen-1 ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir ::rtl::OUString aSubStr; 135*cdf0e10cSrcweir aSubStr = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Sub " ) ); 136*cdf0e10cSrcweir aSubStr += aMacroName; 137*cdf0e10cSrcweir aSubStr += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n\nEnd Sub" ) ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir aOUSource += aSubStr; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // update module in library 142*cdf0e10cSrcweir ScriptDocument aDocument( ScriptDocument::NoDocument ); 143*cdf0e10cSrcweir SbxObject* pParent = pModule->GetParent(); 144*cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pParent); 145*cdf0e10cSrcweir DBG_ASSERT(pBasic, "BasicIDE::CreateMacro: No Basic found!"); 146*cdf0e10cSrcweir if ( pBasic ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic ); 149*cdf0e10cSrcweir DBG_ASSERT(pBasMgr, "BasicIDE::CreateMacro: No BasicManager found!"); 150*cdf0e10cSrcweir if ( pBasMgr ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir aDocument = ScriptDocument::getDocumentForBasicManager( pBasMgr ); 153*cdf0e10cSrcweir OSL_ENSURE( aDocument.isValid(), "BasicIDE::CreateMacro: no document for the given BasicManager!" ); 154*cdf0e10cSrcweir if ( aDocument.isValid() ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir String aLibName = pBasic->GetName(); 157*cdf0e10cSrcweir String aModName = pModule->GetName(); 158*cdf0e10cSrcweir OSL_VERIFY( aDocument.updateModule( aLibName, aModName, aOUSource ) ); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir if( pDispatcher ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_UPDATEALLMODULESOURCES ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if ( aDocument.isAlive() ) 171*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( aDocument ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir return pMethod; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //---------------------------------------------------------------------------- 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir bool RenameDialog( Window* pErrorParent, const ScriptDocument& rDocument, const String& rLibName, const String& rOldName, const String& rNewName ) 179*cdf0e10cSrcweir throw(ElementExistException, NoSuchElementException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir if ( !rDocument.hasDialog( rLibName, rOldName ) ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir OSL_ENSURE( false, "BasicIDE::RenameDialog: old module name is invalid!" ); 184*cdf0e10cSrcweir return false; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if ( rDocument.hasDialog( rLibName, rNewName ) ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir ErrorBox aError( pErrorParent, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ); 190*cdf0e10cSrcweir aError.Execute(); 191*cdf0e10cSrcweir return false; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // #i74440 195*cdf0e10cSrcweir if ( rNewName.Len() == 0 ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir ErrorBox aError( pErrorParent, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ); 198*cdf0e10cSrcweir aError.Execute(); 199*cdf0e10cSrcweir return false; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 203*cdf0e10cSrcweir IDEBaseWindow* pWin = pIDEShell ? pIDEShell->FindWindow( rDocument, rLibName, rOldName, BASICIDE_TYPE_DIALOG, sal_False ) : NULL; 204*cdf0e10cSrcweir Reference< XNameContainer > xExistingDialog; 205*cdf0e10cSrcweir if ( pWin ) 206*cdf0e10cSrcweir xExistingDialog = ((DialogWindow*)pWin)->GetEditor()->GetDialog(); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if ( xExistingDialog.is() ) 209*cdf0e10cSrcweir LocalizationMgr::renameStringResourceIDs( rDocument, rLibName, rNewName, xExistingDialog ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir if ( !rDocument.renameDialog( rLibName, rOldName, rNewName, xExistingDialog ) ) 212*cdf0e10cSrcweir return false; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir if ( pWin ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir // set new name in window 217*cdf0e10cSrcweir pWin->SetName( rNewName ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // update property browser 220*cdf0e10cSrcweir ((DialogWindow*)pWin)->UpdateBrowser(); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // update tabwriter 223*cdf0e10cSrcweir sal_uInt16 nId = (sal_uInt16)(pIDEShell->GetIDEWindowTable()).GetKey( pWin ); 224*cdf0e10cSrcweir DBG_ASSERT( nId, "No entry in Tabbar!" ); 225*cdf0e10cSrcweir if ( nId ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir BasicIDETabBar* pTabBar = (BasicIDETabBar*)pIDEShell->GetTabBar(); 228*cdf0e10cSrcweir pTabBar->SetPageText( nId, rNewName ); 229*cdf0e10cSrcweir pTabBar->Sort(); 230*cdf0e10cSrcweir pTabBar->MakeVisible( pTabBar->GetCurPageId() ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir return true; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir //---------------------------------------------------------------------------- 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir bool RemoveDialog( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 241*cdf0e10cSrcweir if ( pIDEShell ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir DialogWindow* pDlgWin = pIDEShell->FindDlgWin( rDocument, rLibName, rDlgName, sal_False ); 244*cdf0e10cSrcweir if( pDlgWin ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir Reference< container::XNameContainer > xDialogModel = pDlgWin->GetDialog(); 247*cdf0e10cSrcweir LocalizationMgr::removeResourceForDialog( rDocument, rLibName, rDlgName, xDialogModel ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir return rDocument.removeDialog( rLibName, rDlgName ); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir //---------------------------------------------------------------------------- 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir StarBASIC* FindBasic( const SbxVariable* pVar ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir const SbxVariable* pSbx = pVar; 259*cdf0e10cSrcweir while ( pSbx && !pSbx->ISA( StarBASIC ) ) 260*cdf0e10cSrcweir pSbx = pSbx->GetParent(); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir DBG_ASSERT( !pSbx || pSbx->ISA( StarBASIC ), "Find Basic: Kein Basic!" ); 263*cdf0e10cSrcweir return (StarBASIC*)pSbx; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //---------------------------------------------------------------------------- 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir BasicManager* FindBasicManager( StarBASIC* pLib ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) ); 271*cdf0e10cSrcweir for ( ScriptDocuments::const_iterator doc = aDocuments.begin(); 272*cdf0e10cSrcweir doc != aDocuments.end(); 273*cdf0e10cSrcweir ++doc 274*cdf0e10cSrcweir ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir BasicManager* pBasicMgr = doc->getBasicManager(); 277*cdf0e10cSrcweir OSL_ENSURE( pBasicMgr, "BasicIDE::FindBasicManager: no basic manager for the document!" ); 278*cdf0e10cSrcweir if ( !pBasicMgr ) 279*cdf0e10cSrcweir continue; 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames( doc->getLibraryNames() ); 282*cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength(); 283*cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; i++ ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir StarBASIC* pL = pBasicMgr->GetLib( pLibNames[ i ] ); 288*cdf0e10cSrcweir if ( pL == pLib ) 289*cdf0e10cSrcweir return pBasicMgr; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir return NULL; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir //---------------------------------------------------------------------------- 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir void MarkDocumentModified( const ScriptDocument& rDocument ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir // Muss ja nicht aus einem Document kommen... 300*cdf0e10cSrcweir if ( rDocument.isApplication() ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 303*cdf0e10cSrcweir if ( pIDEShell ) 304*cdf0e10cSrcweir pIDEShell->SetAppBasicModified(); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir else 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir rDocument.setDocumentModified(); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 312*cdf0e10cSrcweir if ( pBindings ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir pBindings->Invalidate( SID_SIGNATURE ); 315*cdf0e10cSrcweir pBindings->Invalidate( SID_SAVEDOC ); 316*cdf0e10cSrcweir pBindings->Update( SID_SAVEDOC ); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // Objectcatalog updaten... 320*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 321*cdf0e10cSrcweir ObjectCatalog* pObjCatalog = pIDEShell ? pIDEShell->GetObjectCatalog() : 0; 322*cdf0e10cSrcweir if ( pObjCatalog ) 323*cdf0e10cSrcweir pObjCatalog->UpdateEntries(); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //---------------------------------------------------------------------------- 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir void RunMethod( SbMethod* pMethod ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir SbxValues aRes; 331*cdf0e10cSrcweir aRes.eType = SbxVOID; 332*cdf0e10cSrcweir pMethod->Get( aRes ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir //---------------------------------------------------------------------------- 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir void StopBasic() 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir StarBASIC::Stop(); 340*cdf0e10cSrcweir BasicIDEShell* pShell = IDE_DLL()->GetShell(); 341*cdf0e10cSrcweir if ( pShell ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir IDEWindowTable& rWindows = pShell->GetIDEWindowTable(); 344*cdf0e10cSrcweir IDEBaseWindow* pWin = rWindows.First(); 345*cdf0e10cSrcweir while ( pWin ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir // BasicStopped von Hand rufen, da das Stop-Notify ggf. sonst nicht 348*cdf0e10cSrcweir // durchkommen kann. 349*cdf0e10cSrcweir pWin->BasicStopped(); 350*cdf0e10cSrcweir pWin = rWindows.Next(); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir BasicIDE::BasicStopped(); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir //---------------------------------------------------------------------------- 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir void BasicStopped( sal_Bool* pbAppWindowDisabled, 359*cdf0e10cSrcweir sal_Bool* pbDispatcherLocked, sal_uInt16* pnWaitCount, 360*cdf0e10cSrcweir SfxUInt16Item** ppSWActionCount, SfxUInt16Item** ppSWLockViewCount ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir // Nach einem Error oder dem expliziten abbrechen des Basics muessen 363*cdf0e10cSrcweir // ggf. einige Locks entfernt werden... 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir if ( pbAppWindowDisabled ) 366*cdf0e10cSrcweir *pbAppWindowDisabled = sal_False; 367*cdf0e10cSrcweir if ( pbDispatcherLocked ) 368*cdf0e10cSrcweir *pbDispatcherLocked = sal_False; 369*cdf0e10cSrcweir if ( pnWaitCount ) 370*cdf0e10cSrcweir *pnWaitCount = 0; 371*cdf0e10cSrcweir if ( ppSWActionCount ) 372*cdf0e10cSrcweir *ppSWActionCount = 0; 373*cdf0e10cSrcweir if ( ppSWLockViewCount ) 374*cdf0e10cSrcweir *ppSWLockViewCount = 0; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir // AppWait ? 377*cdf0e10cSrcweir sal_uInt16 nWait = 0; 378*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 379*cdf0e10cSrcweir if( pIDEShell ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir while ( pIDEShell->GetViewFrame()->GetWindow().IsWait() ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir pIDEShell->GetViewFrame()->GetWindow().LeaveWait(); 384*cdf0e10cSrcweir nWait++; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir if ( pnWaitCount ) 387*cdf0e10cSrcweir *pnWaitCount = nWait; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir /* 391*cdf0e10cSrcweir // Interactive = sal_False ? 392*cdf0e10cSrcweir if ( SFX_APP()->IsDispatcherLocked() ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir SFX_APP()->LockDispatcher( sal_False ); 395*cdf0e10cSrcweir if ( pbDispatcherLocked ) 396*cdf0e10cSrcweir *pbDispatcherLocked = sal_True; 397*cdf0e10cSrcweir } */ 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir Window* pDefParent = Application::GetDefDialogParent(); 400*cdf0e10cSrcweir if ( pDefParent && !pDefParent->IsEnabled() ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir pDefParent->Enable( sal_True ); 403*cdf0e10cSrcweir if ( pbAppWindowDisabled ) 404*cdf0e10cSrcweir *pbAppWindowDisabled = sal_True; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir //---------------------------------------------------------------------------- 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir void InvalidateDebuggerSlots() 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 414*cdf0e10cSrcweir if ( pBindings ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICSTOP ); 417*cdf0e10cSrcweir pBindings->Update( SID_BASICSTOP ); 418*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICRUN ); 419*cdf0e10cSrcweir pBindings->Update( SID_BASICRUN ); 420*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICCOMPILE ); 421*cdf0e10cSrcweir pBindings->Update( SID_BASICCOMPILE ); 422*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICSTEPOVER ); 423*cdf0e10cSrcweir pBindings->Update( SID_BASICSTEPOVER ); 424*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICSTEPINTO ); 425*cdf0e10cSrcweir pBindings->Update( SID_BASICSTEPINTO ); 426*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICSTEPOUT ); 427*cdf0e10cSrcweir pBindings->Update( SID_BASICSTEPOUT ); 428*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT ); 429*cdf0e10cSrcweir pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT ); 430*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICIDE_STAT_POS ); 431*cdf0e10cSrcweir pBindings->Update( SID_BASICIDE_STAT_POS ); 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //---------------------------------------------------------------------------- 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir long HandleBasicError( StarBASIC* pBasic ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir BasicIDEDLL::Init(); 440*cdf0e10cSrcweir BasicIDE::BasicStopped(); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // no error output during macro choosing 443*cdf0e10cSrcweir if ( IDE_DLL()->GetExtraData()->ChoosingMacro() ) 444*cdf0e10cSrcweir return 1; 445*cdf0e10cSrcweir if ( IDE_DLL()->GetExtraData()->ShellInCriticalSection() ) 446*cdf0e10cSrcweir return 2; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir long nRet = 0; 449*cdf0e10cSrcweir BasicIDEShell* pIDEShell = 0; 450*cdf0e10cSrcweir if ( SvtModuleOptions().IsBasicIDE() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic ); 453*cdf0e10cSrcweir if ( pBasMgr ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir sal_Bool bProtected = sal_False; 456*cdf0e10cSrcweir ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); 457*cdf0e10cSrcweir OSL_ENSURE( aDocument.isValid(), "BasicIDE::HandleBasicError: no document for the given BasicManager!" ); 458*cdf0e10cSrcweir if ( aDocument.isValid() ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir ::rtl::OUString aOULibName( pBasic->GetName() ); 461*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) ); 462*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 465*cdf0e10cSrcweir if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir bProtected = sal_True; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if ( !bProtected ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir pIDEShell = IDE_DLL()->GetShell(); 475*cdf0e10cSrcweir if ( !pIDEShell ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 478*cdf0e10cSrcweir SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs ); 479*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aRequest ); 480*cdf0e10cSrcweir pIDEShell = IDE_DLL()->GetShell(); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir if ( pIDEShell ) 487*cdf0e10cSrcweir nRet = pIDEShell->CallBasicErrorHdl( pBasic ); 488*cdf0e10cSrcweir else 489*cdf0e10cSrcweir ErrorHandler::HandleError( StarBASIC::GetErrorCode() ); 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir return nRet; 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir //---------------------------------------------------------------------------- 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir SfxBindings* GetBindingsPtr() 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir SfxBindings* pBindings = NULL; 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir SfxViewFrame* pFrame = NULL; 501*cdf0e10cSrcweir BasicIDEDLL* pIDEDLL = IDE_DLL(); 502*cdf0e10cSrcweir if ( pIDEDLL && pIDEDLL->GetShell() ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir pFrame = pIDEDLL->GetShell()->GetViewFrame(); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir else 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir SfxViewFrame* pView = SfxViewFrame::GetFirst(); 509*cdf0e10cSrcweir while ( pView ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir SfxObjectShell* pObjShell = pView->GetObjectShell(); 512*cdf0e10cSrcweir if ( pObjShell && pObjShell->ISA( BasicDocShell ) ) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir pFrame = pView; 515*cdf0e10cSrcweir break; 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir pView = SfxViewFrame::GetNext( *pView ); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir if ( pFrame != NULL ) 521*cdf0e10cSrcweir pBindings = &pFrame->GetBindings(); 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir return pBindings; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir } //namespace BasicIDE 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir //---------------------------------------------------------------------------- 529