summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorMathias Bauer <mba@openoffice.org>2009-12-05 19:29:07 +0100
committerMathias Bauer <mba@openoffice.org>2009-12-05 19:29:07 +0100
commit8d669bc21b9d1976842ba8252d2f0fb953160bdd (patch)
tree63e5a53c8ff9c4cdff33070e177eda653922f28a /basic
parentf232b25c1eceb8e1c32cfd917d666b3a16b14405 (diff)
parent875ac20478f16e5107acb222c0b851b99d2e0f27 (diff)
merge to m67
Diffstat (limited to 'basic')
-rw-r--r--basic/inc/basic/basmgr.hxx2
-rw-r--r--basic/inc/basic/sbstar.hxx9
-rw-r--r--basic/source/basmgr/basmgr.cxx10
-rw-r--r--basic/source/classes/eventatt.cxx71
-rw-r--r--basic/source/classes/sb.cxx98
-rw-r--r--basic/source/classes/sbxmod.cxx73
-rw-r--r--basic/source/runtime/step2.cxx53
7 files changed, 198 insertions, 118 deletions
diff --git a/basic/inc/basic/basmgr.hxx b/basic/inc/basic/basmgr.hxx
index c63d9b4fe260..29f2d7ebc25c 100644
--- a/basic/inc/basic/basmgr.hxx
+++ b/basic/inc/basic/basmgr.hxx
@@ -231,6 +231,8 @@ public:
::com::sun::star::uno::Any
SetGlobalUNOConstant( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rValue );
+ /** retrieves a global constant in the basic library, referring to some UNO object, returns true if a value is found ( value is in aOut ) false otherwise. */
+ bool GetGlobalUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut );
/** determines whether there are password-protected modules whose size exceedes the
legacy module size
@param _out_rModuleNames
diff --git a/basic/inc/basic/sbstar.hxx b/basic/inc/basic/sbstar.hxx
index 3ec0803eb4a9..1278972135f9 100644
--- a/basic/inc/basic/sbstar.hxx
+++ b/basic/inc/basic/sbstar.hxx
@@ -74,6 +74,11 @@ class StarBASIC : public SbxObject
BOOL bDocBasic;
BasicLibInfo* pLibInfo; // Info block for basic manager
SbLanguageMode eLanguageMode; // LanguageMode of the basic object
+ BOOL bQuit;
+
+ SbxObjectRef pVBAGlobals;
+ SbxObject* getVBAGlobals( );
+
protected:
BOOL CError( SbError, const String&, xub_StrLen, xub_StrLen, xub_StrLen );
private:
@@ -196,6 +201,10 @@ public:
SbxObjectRef getRTL( void ) { return pRtl; }
BOOL IsDocBasic() { return bDocBasic; }
+ SbxVariable* VBAFind( const String& rName, SbxClassType t );
+ bool GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut );
+ void QuitAndExitApplication();
+ BOOL IsQuitApplication() { return bQuit; };
};
#ifndef __SB_SBSTARBASICREF_HXX
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 0bbbed8f7474..0645bfb85c2a 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -47,6 +47,7 @@
#include <basic/sbuno.hxx>
#include <basic/basmgr.hxx>
+#include <sbunoobj.hxx>
#include "basrid.hxx"
#include "sbintern.hxx"
#include <sb.hrc>
@@ -1767,6 +1768,15 @@ BasicError* BasicManager::GetNextError()
DBG_CHKTHIS( BasicManager, 0 );
return pErrorMgr->GetNextError();
}
+bool BasicManager::GetGlobalUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut )
+{
+ bool bRes = false;
+ StarBASIC* pStandardLib = GetStdLib();
+ OSL_PRECOND( pStandardLib, "BasicManager::SetGlobalUNOConstant: no lib to insert into!" );
+ if ( pStandardLib )
+ bRes = pStandardLib->GetUNOConstant( _pAsciiName, aOut );
+ return bRes;
+}
Any BasicManager::SetGlobalUNOConstant( const sal_Char* _pAsciiName, const Any& _rValue )
{
diff --git a/basic/source/classes/eventatt.cxx b/basic/source/classes/eventatt.cxx
index 7776b57829c9..b0c8f4b3c36c 100644
--- a/basic/source/classes/eventatt.cxx
+++ b/basic/source/classes/eventatt.cxx
@@ -95,53 +95,48 @@ Any sbxToUnoValue( SbxVariable* pVar );
Reference< frame::XModel > getModelFromBasic( SbxObject* pBasic )
{
- Reference< frame::XModel > xModel;
-
- SbxObject* basicChosen = pBasic;
-
- if ( basicChosen == NULL)
+ OSL_PRECOND( pBasic != NULL, "getModelFromBasic: illegal call!" );
+ if ( !pBasic )
+ return NULL;
+
+ // look for the ThisComponent variable, first in the parent (which
+ // might be the document's Basic), then in the parent's parent (which might be
+ // the application Basic)
+ const ::rtl::OUString sThisComponent( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) );
+ SbxVariable* pThisComponent = NULL;
+
+ SbxObject* pLookup = pBasic->GetParent();
+ while ( pLookup && !pThisComponent )
{
- OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" );
- return xModel;
+ pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT );
+ pLookup = pLookup->GetParent();
}
- SbxObject* p = pBasic;
- SbxObject* pParent = p->GetParent();
- SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
-
- if( pParentParent )
+ if ( !pThisComponent )
{
- basicChosen = pParentParent;
+ OSL_TRACE("Failed to get ThisComponent");
+ // the application Basic, at the latest, should have this variable
+ return NULL;
}
- else if( pParent )
+
+ Any aThisComponent( sbxToUnoValue( pThisComponent ) );
+ Reference< frame::XModel > xModel( aThisComponent, UNO_QUERY );
+ if ( !xModel.is() )
{
- basicChosen = pParent;
+ // it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller.
+ Reference< frame::XController > xController( aThisComponent, UNO_QUERY );
+ if ( xController.is() )
+ xModel = xController->getModel();
}
+ if ( !xModel.is() )
+ return NULL;
- Any aModel;
- SbxVariable *pCompVar = basicChosen->Find( UniString(RTL_CONSTASCII_USTRINGPARAM("ThisComponent")), SbxCLASS_OBJECT );
+#if OSL_DEBUG_LEVEL > 0
+ OSL_TRACE("Have model ThisComponent points to url %s",
+ ::rtl::OUStringToOString( xModel->getURL(),
+ RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+#endif
- if ( pCompVar )
- {
- aModel = sbxToUnoValue( pCompVar );
- if ( sal_False == ( aModel >>= xModel ) ||
- !xModel.is() )
- {
- OSL_TRACE("Failed to extract model from thisComponent ");
- return xModel;
- }
- else
- {
- OSL_TRACE("Have model ThisComponent points to url %s",
- ::rtl::OUStringToOString( xModel->getURL(),
- RTL_TEXTENCODING_ASCII_US ).pData->buffer );
-
- }
- }
- else
- {
- OSL_TRACE("Failed to get ThisComponent");
- }
return xModel;
}
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index af056b884826..80fa3c6bb836 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -65,7 +65,29 @@ SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
TYPEINIT1(StarBASIC,SbxObject)
#define RTLNAME "@SBRTL"
+// i#i68894#
+const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
+const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
+
+SbxObject* StarBASIC::getVBAGlobals( )
+{
+ if ( !pVBAGlobals )
+ pVBAGlobals = (SbUnoObject*)Find( aVBAHook , SbxCLASS_DONTCARE );
+ return pVBAGlobals;
+}
+
+// i#i68894#
+SbxVariable* StarBASIC::VBAFind( const String& rName, SbxClassType t )
+{
+ if( rName == aThisComponent )
+ return NULL;
+ // rename to init globals
+ if ( getVBAGlobals( ) )
+ return pVBAGlobals->Find( rName, t );
+ return NULL;
+
+}
// Create array for conversion SFX <-> VB error code
struct SFX_VB_ErrorItem
{
@@ -303,32 +325,32 @@ SbxObject* SbTypeFactory::cloneTypeObjectImpl( const SbxObject& rTypeObj )
if( pProp )
{
SbxProperty* pNewProp = new SbxProperty( *pProp );
- if( pVar->GetType() & SbxARRAY )
- {
- SbxBase* pParObj = pVar->GetObject();
- SbxDimArray* pSource = PTR_CAST(SbxDimArray,pParObj);
- SbxDimArray* pDest = new SbxDimArray( pVar->GetType() );
- INT32 lb = 0;
- INT32 ub = 0;
-
- pDest->setHasFixedSize( pSource->hasFixedSize() );
- if ( pSource->GetDims() && pSource->hasFixedSize() )
- {
- for ( INT32 j = 1 ; j <= pSource->GetDims(); ++j )
- {
- pSource->GetDim32( (INT32)j, lb, ub );
- pDest->AddDim32( lb, ub );
- }
- }
- else
- pDest->unoAddDim( 0, -1 ); // variant array
-
- USHORT nSavFlags = pVar->GetFlags();
- pNewProp->ResetFlag( SBX_FIXED );
- // need to reset the FIXED flag
- // when calling PutObject ( because the type will not match Object )
- pNewProp->PutObject( pDest );
- pNewProp->SetFlags( nSavFlags );
+ if( pVar->GetType() & SbxARRAY )
+ {
+ SbxBase* pParObj = pVar->GetObject();
+ SbxDimArray* pSource = PTR_CAST(SbxDimArray,pParObj);
+ SbxDimArray* pDest = new SbxDimArray( pVar->GetType() );
+ INT32 lb = 0;
+ INT32 ub = 0;
+
+ pDest->setHasFixedSize( pSource->hasFixedSize() );
+ if ( pSource->GetDims() && pSource->hasFixedSize() )
+ {
+ for ( INT32 j = 1 ; j <= pSource->GetDims(); ++j )
+ {
+ pSource->GetDim32( (INT32)j, lb, ub );
+ pDest->AddDim32( lb, ub );
+ }
+ }
+ else
+ pDest->unoAddDim( 0, -1 ); // variant array
+
+ USHORT nSavFlags = pVar->GetFlags();
+ pNewProp->ResetFlag( SBX_FIXED );
+ // need to reset the FIXED flag
+ // when calling PutObject ( because the type will not match Object )
+ pNewProp->PutObject( pDest );
+ pNewProp->SetFlags( nSavFlags );
}
pProps->PutDirect( pNewProp, i );
}
@@ -445,8 +467,8 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
SbProcedureProperty* pNewProp = new SbProcedureProperty
( pProcedureProp->GetName(), pProcedureProp->GetType() );
// ( pProcedureProp->GetName(), pProcedureProp->GetType(), this );
- pNewProp->SetFlags( nFlags_ ); // Copy flags
- pNewProp->ResetFlag( SBX_NO_BROADCAST ); // except the Broadcast if it was set
+ pNewProp->SetFlags( nFlags_ ); // Copy flags
+ pNewProp->ResetFlag( SBX_NO_BROADCAST ); // except the Broadcast if it was set
pProcedureProp->SetFlags( nFlags_ );
pProps->PutDirect( pNewProp, i );
StartListening( pNewProp->GetBroadcaster(), TRUE );
@@ -681,6 +703,8 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic )
pRtl = new SbiStdObject( String( RTL_CONSTASCII_USTRINGPARAM(RTLNAME) ), this );
// Search via StarBasic is always global
SetFlag( SBX_GBLSEARCH );
+ pVBAGlobals = NULL;
+ bQuit = FALSE;
}
// #51727 Override SetModified so that the modified state
@@ -995,6 +1019,12 @@ SbxVariable* StarBASIC::FindVarInCurrentScopy
return pVar;
}
+void StarBASIC::QuitAndExitApplication()
+{
+ Stop();
+ bQuit = TRUE;
+}
+
void StarBASIC::Stop()
{
SbiInstance* p = pINST;
@@ -1533,6 +1563,18 @@ BOOL StarBASIC::LoadOldModules( SvStream& )
return FALSE;
}
+bool StarBASIC::GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut )
+{
+ bool bRes = false;
+ ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
+ SbUnoObject* pGlobs = dynamic_cast<SbUnoObject*>( Find( sVarName, SbxCLASS_DONTCARE ) );
+ if ( pGlobs )
+ {
+ aOut = pGlobs->getUnoAny();
+ bRes = true;
+ }
+ return bRes;
+}
//========================================================================
// #118116 Implementation Collection object
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index d4f2d16201c2..393719b71c2d 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -69,6 +69,11 @@
#endif
#include <stdio.h>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <comphelper/processfactory.hxx>
+#include <vcl/svapp.hxx>
+ using namespace ::com::sun::star;
TYPEINIT1(SbModule,SbxObject)
@@ -84,7 +89,63 @@ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
SV_IMPL_VARARR(HighlightPortions, HighlightPortion)
+class AsyncQuitHandler
+{
+ AsyncQuitHandler() {}
+ AsyncQuitHandler( const AsyncQuitHandler&);
+public:
+ static AsyncQuitHandler& instance()
+ {
+ static AsyncQuitHandler dInst;
+ return dInst;
+ }
+ void QuitApplication()
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
+ if ( xFactory.is() )
+ {
+ uno::Reference< frame::XDesktop > xDeskTop( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ) ), uno::UNO_QUERY );
+ if ( xDeskTop.is() )
+ xDeskTop->terminate();
+ }
+ }
+ DECL_LINK( OnAsyncQuit, void* );
+};
+
+IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ )
+{
+ QuitApplication();
+ return 0L;
+}
+
+#if 0
+bool UnlockControllerHack( StarBASIC* pBasic )
+{
+ bool bRes = false;
+ if ( pBasic && pBasic->IsDocBasic() )
+ {
+ uno::Any aUnoVar;
+ ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( "ThisComponent" ) );
+ SbUnoObject* pGlobs = dynamic_cast<SbUnoObject*>( pBasic->Find( sVarName, SbxCLASS_DONTCARE ) );
+ if ( pGlobs )
+ aUnoVar = pGlobs->getUnoAny();
+ uno::Reference< frame::XModel > xModel( aUnoVar, uno::UNO_QUERY);
+ if ( xModel.is() )
+ {
+ try
+ {
+ xModel->unlockControllers();
+ bRes = true;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ return bRes;
+}
+#endif
/////////////////////////////////////////////////////////////////////////////
// Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen
@@ -696,6 +757,13 @@ USHORT SbModule::Run( SbMethod* pMeth )
pINST->nCallLvl--; // Call-Level wieder runter
StarBASIC::FatalError( SbERR_STACK_OVERFLOW );
}
+
+ // VBA always ensure screenupdating is enabled after completing
+ StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent());
+#if 0
+ if ( pBasic && pBasic->IsDocBasic() && !pINST )
+ UnlockControllerHack( pBasic );
+#endif
if( bDelInst )
{
// #57841 Uno-Objekte, die in RTL-Funktionen gehalten werden,
@@ -705,6 +773,11 @@ USHORT SbModule::Run( SbMethod* pMeth )
delete pINST;
pINST = NULL;
}
+ if ( pBasic && pBasic->IsDocBasic() && pBasic->IsQuitApplication() && !pINST )
+ {
+ Application::PostUserEvent( LINK( &AsyncQuitHandler::instance(), AsyncQuitHandler, OnAsyncQuit ), NULL );
+ }
+
return nRes;
}
diff --git a/basic/source/runtime/step2.cxx b/basic/source/runtime/step2.cxx
index 413d3a6f4def..fb0b217b76c4 100644
--- a/basic/source/runtime/step2.cxx
+++ b/basic/source/runtime/step2.cxx
@@ -56,57 +56,6 @@ using com::sun::star::uno::Reference;
SbxVariable* getVBAConstant( const String& rName );
-const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
-const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
-// i#i68894#
-SbxArray* getVBAGlobals( )
-{
- static SbxArrayRef pArray;
- static bool isInitialised = false;
- if ( isInitialised )
- return pArray;
- Reference < XComponentContext > xCtx;
- Reference < XPropertySet > xProps(
- ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
- xCtx.set( xProps->getPropertyValue( rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
- UNO_QUERY_THROW );
- SbUnoObject dGlobs( String( RTL_CONSTASCII_USTRINGPARAM("ExcelGlobals") ), xCtx->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/ooo.vba.theGlobals") ) );
-
- SbxVariable *vba = dGlobs.Find( String( RTL_CONSTASCII_USTRINGPARAM("getGlobals") ) , SbxCLASS_DONTCARE );
-
- if ( vba )
- {
- pArray = static_cast<SbxArray *>(vba->GetObject());
- isInitialised = true;
- return pArray;
- }
- return NULL;
-}
-
-// i#i68894#
-SbxVariable* VBAFind( const String& rName, SbxClassType t )
-{
- if( rName == aThisComponent )
- return NULL;
-
- SbxArray *pVBAGlobals = getVBAGlobals( );
- for (USHORT i = 0; pVBAGlobals && i < pVBAGlobals->Count(); i++)
- {
- SbxVariable *pElem = pVBAGlobals->Get( i );
- if (!pElem || !pElem->IsObject())
- continue;
- SbxObject *pVba = static_cast<SbxObject *>(pElem->GetObject());
- SbxVariable *pVbaVar = pVba ? pVba->Find( rName, t ) : NULL;
- if( pVbaVar )
- {
- return pVbaVar;
- }
- }
- return NULL;
-
-}
-
// Suchen eines Elements
// Die Bits im String-ID:
// 0x8000 - Argv ist belegt
@@ -191,7 +140,7 @@ SbxVariable* SbiRuntime::FindElement
if ( bVBAEnabled )
{
// Try Find in VBA symbols space
- pElem = VBAFind( aName, SbxCLASS_DONTCARE );
+ pElem = rBasic.VBAFind( aName, SbxCLASS_DONTCARE );
if ( pElem )
bSetName = false; // don't overwrite uno name
else