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