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_basctl.hxx" 30 31 32 #include <ide_pch.hxx> 33 34 35 #include <svheader.hxx> 36 #include <sfx2/app.hxx> 37 #include <sfx2/dispatch.hxx> 38 #include <sfx2/genlink.hxx> 39 40 41 #include <svl/solar.hrc> 42 #include <iderdll.hxx> 43 #include <iderdll2.hxx> 44 #include <iderid.hxx> 45 #include <svx/svxids.hrc> 46 #include <basidesh.hxx> 47 #include <basidesh.hrc> 48 #include <basobj.hxx> 49 #include <bastypes.hxx> 50 #include <basdoc.hxx> 51 #include <basicmod.hxx> 52 #include <propbrw.hxx> 53 54 55 #define ITEMID_SEARCH 0 56 #include <svl/srchitem.hxx> 57 #include <com/sun/star/script/XLibraryContainerPassword.hpp> 58 59 using ::rtl::OUString; 60 using namespace ::com::sun::star; 61 using namespace ::com::sun::star::uno; 62 63 64 static BasicIDEDLL* pBasicIDEDLL = 0; 65 66 BasicIDEDLL* BasicIDEDLL::GetDLL() 67 { 68 return pBasicIDEDLL; 69 } 70 71 IDEResId::IDEResId( sal_uInt16 nId ): 72 ResId( nId, *(*(BasicIDEModule**)GetAppData(SHL_IDE))->GetResMgr() ) 73 { 74 } 75 76 BasicIDEDLL::BasicIDEDLL() 77 { 78 pBasicIDEDLL = this; 79 pShell = 0; 80 pExtraData = 0; 81 82 GetExtraData(); // damit GlobalErrorHdl gesetzt wird. 83 } 84 85 BasicIDEDLL::~BasicIDEDLL() 86 { 87 delete pExtraData; 88 *(BasicIDEDLL**)GetAppData(SHL_IDE) = NULL; 89 } 90 91 void BasicIDEDLL::Init() 92 { 93 if ( pBasicIDEDLL ) 94 return; 95 96 SfxObjectFactory* pFact = &BasicDocShell::Factory(); 97 (void)pFact; 98 99 ByteString aResMgrName( "basctl" ); 100 ResMgr* pMgr = ResMgr::CreateResMgr( 101 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); 102 103 BASIC_MOD() = new BasicIDEModule( pMgr, &BasicDocShell::Factory() ); 104 105 new BasicIDEDLL; 106 SfxModule* pMod = BASIC_MOD(); 107 108 SfxObjectFactory& rFactory = BasicDocShell::Factory(); 109 rFactory.SetDocumentServiceName( String::CreateFromAscii( "com.sun.star.script.BasicIDE" ) ); 110 111 BasicDocShell::RegisterInterface( pMod ); 112 BasicIDEShell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH ); 113 BasicIDEShell::RegisterInterface( pMod ); 114 115 PropBrwMgr::RegisterChildWindow(); 116 } 117 118 /************************************************************************* 119 |* 120 |* Deinitialisierung 121 |* 122 \************************************************************************/ 123 void BasicIDEDLL::Exit() 124 { 125 // the BasicIDEModule must be destroyed 126 BasicIDEModule** ppShlPtr = (BasicIDEModule**) GetAppData(SHL_IDE); 127 delete (*ppShlPtr); 128 (*ppShlPtr) = NULL; 129 DELETEZ( pBasicIDEDLL ); 130 } 131 132 BasicIDEData* BasicIDEDLL::GetExtraData() 133 { 134 if ( !pExtraData ) 135 pExtraData = new BasicIDEData; 136 return pExtraData; 137 } 138 139 BasicIDEData::BasicIDEData() : aObjCatPos( INVPOSITION, INVPOSITION ) 140 { 141 nBasicDialogCount = 0; 142 bChoosingMacro = sal_False; 143 bShellInCriticalSection = sal_False; 144 pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM ); 145 146 StarBASIC::SetGlobalBreakHdl( LINK( this, BasicIDEData, GlobalBasicBreakHdl ) ); 147 148 pAccelerator = 0; 149 } 150 151 BasicIDEData::~BasicIDEData() 152 { 153 // ErrorHdl zuruecksetzen ist zwar sauberer, aber diese Instanz wird 154 // sowieso sehr spaet, nach dem letzten Basic, zerstoert. 155 // Durch den Aufruf werden dann aber wieder AppDaten erzeugt und nicht 156 // mehr zerstoert => MLK's beim Purify 157 // StarBASIC::SetGlobalErrorHdl( Link() ); 158 // StarBASIC::SetGlobalBreakHdl( Link() ); 159 // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() ); 160 161 delete pSearchItem; 162 //delete pAccelerator; 163 } 164 165 SvxSearchItem& BasicIDEData::GetSearchItem() const 166 { 167 return *pSearchItem; 168 } 169 170 void BasicIDEData::SetSearchItem( const SvxSearchItem& rItem ) 171 { 172 delete pSearchItem; 173 pSearchItem = (SvxSearchItem*)rItem.Clone(); 174 } 175 176 IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic ) 177 { 178 long nRet = 0; 179 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 180 if ( pIDEShell ) 181 { 182 BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic ); 183 if ( pBasMgr ) 184 { 185 // Hier lande ich zweimal, wenn Step into protected Basic 186 // => schlecht, wenn Passwortabfrage 2x, ausserdem sieht man in 187 // dem PasswordDlg nicht, fuer welche Lib... 188 // => An dieser Stelle keine Passwort-Abfrage starten 189 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); 190 OSL_ENSURE( aDocument.isValid(), "BasicIDEData::GlobalBasicBreakHdl: no document for the basic manager!" ); 191 if ( aDocument.isValid() ) 192 { 193 ::rtl::OUString aOULibName( pBasic->GetName() ); 194 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 195 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 196 { 197 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 198 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) ) 199 { 200 // Ein Step-Out muesste mich aus den geschuetzten Bereich befoerdern... 201 nRet = SbDEBUG_STEPOUT; 202 } 203 else 204 { 205 nRet = pIDEShell->CallBasicBreakHdl( pBasic ); 206 } 207 } 208 } 209 } 210 } 211 212 return nRet; 213 } 214