summaryrefslogtreecommitdiff
path: root/basic/source/classes/sb.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source/classes/sb.cxx')
-rwxr-xr-x[-rw-r--r--]basic/source/classes/sb.cxx590
1 files changed, 424 insertions, 166 deletions
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index bbc44d69f8..1d2e1edcef 100644..100755
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -53,7 +53,10 @@
#include "sb.hrc"
#include <basrid.hxx>
#include <osl/mutex.hxx>
+#include <cppuhelper/implbase1.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+#include <com/sun/star/util/XCloseListener.hpp>
#include "errobject.hxx"
#include <boost/unordered_map.hpp>
@@ -67,11 +70,151 @@ TYPEINIT1(StarBASIC,SbxObject)
#define RTLNAME "@SBRTL"
// i#i68894#
+using namespace ::com::sun::star;
using com::sun::star::uno::Reference;
using com::sun::star::uno::Any;
using com::sun::star::uno::UNO_QUERY;
using com::sun::star::lang::XMultiServiceFactory;
+// ============================================================================
+
+class DocBasicItem : public ::cppu::WeakImplHelper1< util::XCloseListener >
+{
+public:
+ explicit DocBasicItem( StarBASIC& rDocBasic );
+ virtual ~DocBasicItem();
+
+ inline const SbxObjectRef& getClassModules() const { return mxClassModules; }
+ inline bool isDocClosed() const { return mbDocClosed; }
+
+ void clearDependingVarsOnDelete( StarBASIC& rDeletedBasic );
+
+ void startListening();
+ void stopListening();
+
+ virtual void SAL_CALL queryClosing( const lang::EventObject& rSource, sal_Bool bGetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException);
+ virtual void SAL_CALL notifyClosing( const lang::EventObject& rSource ) throw (uno::RuntimeException);
+ virtual void SAL_CALL disposing( const lang::EventObject& rSource ) throw (uno::RuntimeException);
+
+private:
+ StarBASIC& mrDocBasic;
+ SbxObjectRef mxClassModules;
+ bool mbDocClosed;
+ bool mbDisposed;
+};
+
+// ----------------------------------------------------------------------------
+
+DocBasicItem::DocBasicItem( StarBASIC& rDocBasic ) :
+ mrDocBasic( rDocBasic ),
+ mxClassModules( new SbxObject( String() ) ),
+ mbDocClosed( false ),
+ mbDisposed( false )
+{
+}
+
+DocBasicItem::~DocBasicItem()
+{
+ stopListening();
+}
+
+void DocBasicItem::clearDependingVarsOnDelete( StarBASIC& rDeletedBasic )
+{
+ mrDocBasic.implClearDependingVarsOnDelete( &rDeletedBasic );
+}
+
+void DocBasicItem::startListening()
+{
+ Any aThisComp;
+ mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp );
+ Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
+ if( xCloseBC.is() )
+ try { xCloseBC->addCloseListener( this ); } catch( uno::Exception& ) {}
+}
+
+void DocBasicItem::stopListening()
+{
+ if( mbDisposed ) return;
+ mbDisposed = true;
+ Any aThisComp;
+ mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp );
+ Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
+ if( xCloseBC.is() )
+ try { xCloseBC->removeCloseListener( this ); } catch( uno::Exception& ) {}
+}
+
+void SAL_CALL DocBasicItem::queryClosing( const lang::EventObject& /*rSource*/, sal_Bool /*bGetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException)
+{
+}
+
+void SAL_CALL DocBasicItem::notifyClosing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException)
+{
+ stopListening();
+ mbDocClosed = true;
+}
+
+void SAL_CALL DocBasicItem::disposing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException)
+{
+ stopListening();
+}
+
+// ----------------------------------------------------------------------------
+
+namespace {
+
+typedef ::rtl::Reference< DocBasicItem > DocBasicItemRef;
+typedef boost::unordered_map< const StarBASIC *, DocBasicItemRef > DocBasicItemMap;
+ // ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleInitDependencyMap;
+
+static DocBasicItemMap GaDocBasicItems;
+
+const DocBasicItem* lclFindDocBasicItem( const StarBASIC* pDocBasic )
+{
+ DocBasicItemMap::iterator it = GaDocBasicItems.find( pDocBasic );
+ return (it != GaDocBasicItems.end()) ? it->second.get() : 0;
+}
+
+void lclInsertDocBasicItem( StarBASIC& rDocBasic )
+{
+ DocBasicItemRef& rxDocBasicItem = GaDocBasicItems[ &rDocBasic ];
+ rxDocBasicItem.set( new DocBasicItem( rDocBasic ) );
+ rxDocBasicItem->startListening();
+}
+
+void lclRemoveDocBasicItem( StarBASIC& rDocBasic )
+{
+ DocBasicItemMap::iterator it = GaDocBasicItems.find( &rDocBasic );
+ if( it != GaDocBasicItems.end() )
+ {
+ it->second->stopListening();
+ GaDocBasicItems.erase( it );
+ }
+ DocBasicItemMap::iterator it_end = GaDocBasicItems.end();
+ for( it = GaDocBasicItems.begin(); it != it_end; ++it )
+ it->second->clearDependingVarsOnDelete( rDocBasic );
+}
+
+StarBASIC* lclGetDocBasicForModule( SbModule* pModule )
+{
+ StarBASIC* pRetBasic = NULL;
+ SbxObject* pCurParent = pModule;
+ while( pCurParent->GetParent() != NULL )
+ {
+ pCurParent = pCurParent->GetParent();
+ StarBASIC* pDocBasic = PTR_CAST( StarBASIC, pCurParent );
+ if( pDocBasic != NULL && pDocBasic->IsDocBasic() )
+ {
+ pRetBasic = pDocBasic;
+ break;
+ }
+ }
+ return pRetBasic;
+}
+
+} // namespace
+
+// ============================================================================
+
SbxObject* StarBASIC::getVBAGlobals( )
{
if ( !pVBAGlobals )
@@ -113,7 +256,7 @@ SbxVariable* StarBASIC::VBAFind( const String& rName, SbxClassType t )
// Create array for conversion SFX <-> VB error code
struct SFX_VB_ErrorItem
{
- USHORT nErrorVB;
+ sal_uInt16 nErrorVB;
SbError nErrorSFX;
};
@@ -249,7 +392,7 @@ const SFX_VB_ErrorItem SFX_VB_ErrorTab[] =
// the Modul-relationshop. But it works only when a modul is loaded.
// Can cause troubles with separately loaded properties!
-SbxBase* SbiFactory::Create( UINT16 nSbxId, UINT32 nCreator )
+SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
{
if( nCreator == SBXCR_SBX )
{
@@ -298,11 +441,11 @@ SbxObject* SbiFactory::CreateObject( const String& rClass )
class SbOLEFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
+ virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
virtual SbxObject* CreateObject( const String& );
};
-SbxBase* SbOLEFactory::Create( UINT16, UINT32 )
+SbxBase* SbOLEFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return NULL;
@@ -323,11 +466,11 @@ SbxObject* SbOLEFactory::CreateObject( const String& rClassName )
class SbFormFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
+ virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
virtual SbxObject* CreateObject( const String& );
};
-SbxBase* SbFormFactory::Create( UINT16, UINT32 )
+SbxBase* SbFormFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return NULL;
@@ -341,7 +484,18 @@ SbxObject* SbFormFactory::CreateObject( const String& rClassName )
{
if( SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pVar->GetObject() ) )
{
- pFormModule->Load();
+ bool bInitState = pFormModule->getInitState();
+ if( bInitState )
+ {
+ // Not the first instantiate, reset
+ bool bTriggerTerminateEvent = false;
+ pFormModule->ResetApiObj( bTriggerTerminateEvent );
+ pFormModule->setInitState( false );
+ }
+ else
+ {
+ pFormModule->Load();
+ }
return pFormModule->CreateInstance();
}
}
@@ -360,8 +514,8 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
// Copy the properties, not only the reference to them
SbxArray* pProps = pRet->GetProperties();
- UINT32 nCount = pProps->Count32();
- for( UINT32 i = 0 ; i < nCount ; i++ )
+ sal_uInt32 nCount = pProps->Count32();
+ for( sal_uInt32 i = 0 ; i < nCount ; i++ )
{
SbxVariable* pVar = pProps->Get32( i );
SbxProperty* pProp = PTR_CAST( SbxProperty, pVar );
@@ -378,18 +532,18 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
pDest->setHasFixedSize( pSource->hasFixedSize() );
if ( pSource->GetDims() && pSource->hasFixedSize() )
{
- INT32 lb = 0;
- INT32 ub = 0;
- for ( INT32 j = 1 ; j <= pSource->GetDims(); ++j )
+ sal_Int32 lb = 0;
+ sal_Int32 ub = 0;
+ for ( sal_Int32 j = 1 ; j <= pSource->GetDims(); ++j )
{
- pSource->GetDim32( (INT32)j, lb, ub );
+ pSource->GetDim32( (sal_Int32)j, lb, ub );
pDest->AddDim32( lb, ub );
}
}
else
pDest->unoAddDim( 0, -1 ); // variant array
- USHORT nSavFlags = pVar->GetFlags();
+ sal_uInt16 nSavFlags = pVar->GetFlags();
pNewProp->ResetFlag( SBX_FIXED );
// need to reset the FIXED flag
// when calling PutObject ( because the type will not match Object )
@@ -415,11 +569,11 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
class SbTypeFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
+ virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
virtual SbxObject* CreateObject( const String& );
};
-SbxBase* SbTypeFactory::Create( UINT16, UINT32 )
+SbxBase* SbTypeFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return NULL;
@@ -444,6 +598,7 @@ SbxObject* createUserTypeImpl( const String& rClassName )
return pRetObj;
}
+
TYPEINIT1(SbClassModuleObject,SbModule)
SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
@@ -463,8 +618,8 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
// Copy the methods from original class module
SbxArray* pClassMethods = pClassModule->GetMethods();
- UINT32 nMethodCount = pClassMethods->Count32();
- UINT32 i;
+ sal_uInt32 nMethodCount = pClassMethods->Count32();
+ sal_uInt32 i;
for( i = 0 ; i < nMethodCount ; i++ )
{
SbxVariable* pVar = pClassMethods->Get32( i );
@@ -476,7 +631,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
SbMethod* pMethod = PTR_CAST(SbMethod, pVar );
if( pMethod )
{
- USHORT nFlags_ = pMethod->GetFlags();
+ sal_uInt16 nFlags_ = pMethod->GetFlags();
pMethod->SetFlag( SBX_NO_BROADCAST );
SbMethod* pNewMethod = new SbMethod( *pMethod );
pNewMethod->ResetFlag( SBX_NO_BROADCAST );
@@ -484,7 +639,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
pNewMethod->pMod = this;
pNewMethod->SetParent( this );
pMethods->PutDirect( pNewMethod, i );
- StartListening( pNewMethod->GetBroadcaster(), TRUE );
+ StartListening( pNewMethod->GetBroadcaster(), sal_True );
}
}
}
@@ -522,14 +677,14 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
// Copy the properties from original class module
SbxArray* pClassProps = pClassModule->GetProperties();
- UINT32 nPropertyCount = pClassProps->Count32();
+ sal_uInt32 nPropertyCount = pClassProps->Count32();
for( i = 0 ; i < nPropertyCount ; i++ )
{
SbxVariable* pVar = pClassProps->Get32( i );
SbProcedureProperty* pProcedureProp = PTR_CAST( SbProcedureProperty, pVar );
if( pProcedureProp )
{
- USHORT nFlags_ = pProcedureProp->GetFlags();
+ sal_uInt16 nFlags_ = pProcedureProp->GetFlags();
pProcedureProp->SetFlag( SBX_NO_BROADCAST );
SbProcedureProperty* pNewProp = new SbProcedureProperty
( pProcedureProp->GetName(), pProcedureProp->GetType() );
@@ -538,14 +693,14 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
pNewProp->ResetFlag( SBX_NO_BROADCAST ); // except the Broadcast if it was set
pProcedureProp->SetFlags( nFlags_ );
pProps->PutDirect( pNewProp, i );
- StartListening( pNewProp->GetBroadcaster(), TRUE );
+ StartListening( pNewProp->GetBroadcaster(), sal_True );
}
else
{
SbxProperty* pProp = PTR_CAST( SbxProperty, pVar );
if( pProp )
{
- USHORT nFlags_ = pProp->GetFlags();
+ sal_uInt16 nFlags_ = pProp->GetFlags();
pProp->SetFlag( SBX_NO_BROADCAST );
SbxProperty* pNewProp = new SbxProperty( *pProp );
@@ -559,7 +714,6 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
if( pObj != NULL )
{
String aObjClass = pObj->GetClassName();
- (void)aObjClass;
SbClassModuleObject* pClassModuleObj = PTR_CAST(SbClassModuleObject,pObjBase);
if( pClassModuleObj != NULL )
@@ -594,8 +748,12 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
SbClassModuleObject::~SbClassModuleObject()
{
+ // do not trigger termination event when document is already closed
if( StarBASIC::IsRunning() )
- triggerTerminateEvent();
+ if( StarBASIC* pDocBasic = lclGetDocBasicForModule( this ) )
+ if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
+ if( !pDocBasicItem->isDocClosed() )
+ triggerTerminateEvent();
// Must be deleted by base class dtor because this data
// is not owned by the SbClassModuleObject object
@@ -606,7 +764,7 @@ SbClassModuleObject::~SbClassModuleObject()
void SbClassModuleObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
const SfxHint& rHint, const TypeId& rHintType )
{
- SbModule::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
+ handleProcedureProperties( rBC, rHint );
}
SbxVariable* SbClassModuleObject::Find( const XubString& rName, SbxClassType t )
@@ -683,8 +841,14 @@ SbClassFactory::~SbClassFactory()
void SbClassFactory::AddClassModule( SbModule* pClassModule )
{
+ SbxObjectRef xToUseClassModules = xClassModules;
+
+ if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pClassModule ) )
+ if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
+ xToUseClassModules = pDocBasicItem->getClassModules();
+
SbxObject* pParent = pClassModule->GetParent();
- xClassModules->Insert( pClassModule );
+ xToUseClassModules->Insert( pClassModule );
pClassModule->SetParent( pParent );
}
@@ -693,7 +857,7 @@ void SbClassFactory::RemoveClassModule( SbModule* pClassModule )
xClassModules->Remove( pClassModule );
}
-SbxBase* SbClassFactory::Create( UINT16, UINT32 )
+SbxBase* SbClassFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return NULL;
@@ -701,12 +865,19 @@ SbxBase* SbClassFactory::Create( UINT16, UINT32 )
SbxObject* SbClassFactory::CreateObject( const String& rClassName )
{
- SbxVariable* pVar = xClassModules->Find( rClassName, SbxCLASS_DONTCARE );
+ SbxObjectRef xToUseClassModules = xClassModules;
+
+ if( SbModule* pMod = pMOD )
+ if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pMod ) )
+ if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
+ xToUseClassModules = pDocBasicItem->getClassModules();
+
+ SbxVariable* pVar = xToUseClassModules->Find( rClassName, SbxCLASS_OBJECT );
SbxObject* pRet = NULL;
if( pVar )
{
- SbModule* pMod = (SbModule*)pVar;
- pRet = new SbClassModuleObject( pMod );
+ SbModule* pVarMod = (SbModule*)pVar;
+ pRet = new SbClassModuleObject( pVarMod );
}
return pRet;
}
@@ -718,21 +889,19 @@ SbModule* SbClassFactory::FindClass( const String& rClassName )
return pMod;
}
-StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic )
+StarBASIC::StarBASIC( StarBASIC* p, sal_Bool bIsDocBasic )
: SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic )
{
SetParent( p );
pLibInfo = NULL;
- bNoRtl = bBreak = FALSE;
- bVBAEnabled = FALSE;
+ bNoRtl = bBreak = sal_False;
+ bVBAEnabled = sal_False;
pModules = new SbxArray;
if( !GetSbData()->nInst++ )
{
pSBFAC = new SbiFactory;
AddFactory( pSBFAC );
- pUNOFAC = new SbUnoFactory;
- AddFactory( pUNOFAC );
pTYPEFAC = new SbTypeFactory;
AddFactory( pTYPEFAC );
pCLASSFAC = new SbClassFactory;
@@ -741,23 +910,31 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic )
AddFactory( pOLEFAC );
pFORMFAC = new SbFormFactory;
AddFactory( pFORMFAC );
+ pUNOFAC = new SbUnoFactory;
+ AddFactory( pUNOFAC );
}
pRtl = new SbiStdObject( String( RTL_CONSTASCII_USTRINGPARAM(RTLNAME) ), this );
// Search via StarBasic is always global
SetFlag( SBX_GBLSEARCH );
pVBAGlobals = NULL;
- bQuit = FALSE;
+ bQuit = sal_False;
+
+ if( bDocBasic )
+ lclInsertDocBasicItem( *this );
}
// #51727 Override SetModified so that the modified state
// is not given to the parent
-void StarBASIC::SetModified( BOOL b )
+void StarBASIC::SetModified( sal_Bool b )
{
SbxBase::SetModified( b );
}
StarBASIC::~StarBASIC()
{
+ // Needs to be first action as it can trigger events
+ disposeComVariablesForBasic( this );
+
if( !--GetSbData()->nInst )
{
RemoveFactory( pSBFAC );
@@ -786,18 +963,30 @@ StarBASIC::~StarBASIC()
}
#endif
}
+ else if( bDocBasic )
+ {
+ SbxError eOld = SbxBase::GetError();
+
+ lclRemoveDocBasicItem( *this );
+
+ SbxBase::ResetError();
+ if( eOld != SbxERR_OK )
+ SbxBase::SetError( eOld );
+ }
// #100326 Set Parent NULL in registered listeners
if( xUnoListeners.Is() )
{
- USHORT uCount = xUnoListeners->Count();
- for( USHORT i = 0 ; i < uCount ; i++ )
+ sal_uInt16 uCount = xUnoListeners->Count();
+ for( sal_uInt16 i = 0 ; i < uCount ; i++ )
{
SbxVariable* pListenerObj = xUnoListeners->Get( i );
pListenerObj->SetParent( NULL );
}
xUnoListeners = NULL;
}
+
+ clearUnoMethodsForBasic( this );
}
// Override new() operator, so that everyone can create a new instance
@@ -805,7 +994,7 @@ void* StarBASIC::operator new( size_t n )
{
if( n < sizeof( StarBASIC ) )
{
-// DBG_ASSERT( FALSE, "Warnung: inkompatibler BASIC-Stand!" );
+// DBG_ASSERT( sal_False, "Warnung: inkompatibler BASIC-Stand!" );
n = sizeof( StarBASIC );
}
return ::operator new( n );
@@ -816,6 +1005,27 @@ void StarBASIC::operator delete( void* p )
::operator delete( p );
}
+void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
+{
+ if( this != pDeletedBasic )
+ {
+ for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+ {
+ SbModule* p = (SbModule*)pModules->Get( i );
+ p->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
+ }
+ }
+
+ for( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
+ {
+ SbxVariable* pVar = pObjs->Get( nObj );
+ StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
+ if( pBasic && pBasic != pDeletedBasic )
+ pBasic->implClearDependingVarsOnDelete( pDeletedBasic );
+ }
+}
+
+
/**************************************************************************
*
* Creation/Managment of modules
@@ -860,7 +1070,7 @@ SbModule* StarBASIC::MakeModule32( const String& rName, const ModuleInfo& mInfo,
p->SetSource32( rSrc );
p->SetParent( this );
pModules->Insert( p, pModules->Count() );
- SetModified( TRUE );
+ SetModified( sal_True );
return p;
}
@@ -870,14 +1080,14 @@ void StarBASIC::Insert( SbxVariable* pVar )
{
pModules->Insert( pVar, pModules->Count() );
pVar->SetParent( this );
- StartListening( pVar->GetBroadcaster(), TRUE );
+ StartListening( pVar->GetBroadcaster(), sal_True );
}
else
{
- BOOL bWasModified = IsModified();
+ sal_Bool bWasModified = IsModified();
SbxObject::Insert( pVar );
if( !bWasModified && pVar->IsSet( SBX_DONTSTORE ) )
- SetModified( FALSE );
+ SetModified( sal_False );
}
}
@@ -895,17 +1105,17 @@ void StarBASIC::Remove( SbxVariable* pVar )
SbxObject::Remove( pVar );
}
-BOOL StarBASIC::Compile( SbModule* pMod )
+sal_Bool StarBASIC::Compile( SbModule* pMod )
{
- return pMod ? pMod->Compile() : FALSE;
+ return pMod ? pMod->Compile() : sal_False;
}
-BOOL StarBASIC::Disassemble( SbModule* pMod, String& rText )
+sal_Bool StarBASIC::Disassemble( SbModule* pMod, String& rText )
{
rText.Erase();
if( pMod )
pMod->Disassemble( rText );
- return BOOL( rText.Len() != 0 );
+ return sal_Bool( rText.Len() != 0 );
}
void StarBASIC::Clear()
@@ -916,7 +1126,7 @@ void StarBASIC::Clear()
SbModule* StarBASIC::FindModule( const String& rName )
{
- for( USHORT i = 0; i < pModules->Count(); i++ )
+ for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
{
SbModule* p = (SbModule*) pModules->Get( i );
if( p->GetName().EqualsIgnoreCaseAscii( rName ) )
@@ -945,15 +1155,15 @@ struct ClassModuleRunInitItem
{}
};
-typedef boost::unordered_map< ::rtl::OUString, ClassModuleRunInitItem,
- ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleInitDependencyMap;
-
-static ModuleInitDependencyMap* GpMIDMap = NULL;
+// Derive from unordered_map type instead of typedef
+// to allow forward declaration in sbmod.hxx
+class ModuleInitDependencyMap : public
+ boost::unordered_map< ::rtl::OUString, ClassModuleRunInitItem,
+ ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > >
+{};
-void SbModule::implProcessModuleRunInit( ClassModuleRunInitItem& rItem )
+void SbModule::implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem )
{
- ModuleInitDependencyMap& rMIDMap = *GpMIDMap;
-
rItem.m_bProcessing = true;
//bool bAnyDependencies = true;
@@ -968,8 +1178,8 @@ void SbModule::implProcessModuleRunInit( ClassModuleRunInitItem& rItem )
String& rStr = *it;
// Is required type a class module?
- ModuleInitDependencyMap::iterator itFind = rMIDMap.find( rStr );
- if( itFind != rMIDMap.end() )
+ ModuleInitDependencyMap::iterator itFind = rMap.find( rStr );
+ if( itFind != rMap.end() )
{
ClassModuleRunInitItem& rParentItem = itFind->second;
if( rParentItem.m_bProcessing )
@@ -980,7 +1190,7 @@ void SbModule::implProcessModuleRunInit( ClassModuleRunInitItem& rItem )
}
if( !rParentItem.m_bRunInitDone )
- implProcessModuleRunInit( rParentItem );
+ implProcessModuleRunInit( rMap, rParentItem );
}
}
}
@@ -994,8 +1204,10 @@ void SbModule::implProcessModuleRunInit( ClassModuleRunInitItem& rItem )
// Run Init-Code of all modules (including inserted libraries)
void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
{
+ SolarMutexGuard guard;
+
// Init own modules
- for ( USHORT nMod = 0; nMod < pModules->Count(); nMod++ )
+ for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
{
SbModule* pModule = (SbModule*)pModules->Get( nMod );
if( !pModule->IsCompiled() )
@@ -1008,8 +1220,7 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
// Consider required types to init in right order. Class modules
// that are required by other modules have to be initialized first.
ModuleInitDependencyMap aMIDMap;
- GpMIDMap = &aMIDMap;
- for ( USHORT nMod = 0; nMod < pModules->Count(); nMod++ )
+ for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
{
SbModule* pModule = (SbModule*)pModules->Get( nMod );
String aModuleName = pModule->GetName();
@@ -1021,12 +1232,11 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
for( it = aMIDMap.begin() ; it != aMIDMap.end(); ++it )
{
ClassModuleRunInitItem& rItem = it->second;
- SbModule::implProcessModuleRunInit( rItem );
+ SbModule::implProcessModuleRunInit( aMIDMap, rItem );
}
- GpMIDMap = NULL;
// Call RunInit on standard modules
- for ( USHORT nMod = 0; nMod < pModules->Count(); nMod++ )
+ for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
{
SbModule* pModule = (SbModule*)pModules->Get( nMod );
if( !pModule->isProxyModule() )
@@ -1035,7 +1245,7 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
// Check all objects if they are BASIC,
// if yes initialize
- for ( USHORT nObj = 0; nObj < pObjs->Count(); nObj++ )
+ for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
{
SbxVariable* pVar = pObjs->Get( nObj );
StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
@@ -1049,14 +1259,14 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
void StarBASIC::DeInitAllModules( void )
{
// Deinit own modules
- for ( USHORT nMod = 0; nMod < pModules->Count(); nMod++ )
+ for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
{
SbModule* pModule = (SbModule*)pModules->Get( nMod );
- if( pModule->pImage )
+ if( pModule->pImage && !pModule->isProxyModule() && !pModule->ISA(SbObjModule) )
pModule->pImage->bInit = false;
}
- for ( USHORT nObj = 0; nObj < pObjs->Count(); nObj++ )
+ for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
{
SbxVariable* pVar = pObjs->Get( nObj );
StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
@@ -1069,13 +1279,13 @@ void StarBASIC::DeInitAllModules( void )
void StarBASIC::ClearGlobalVars( void )
{
SbxArrayRef xProps( GetProperties() );
- USHORT nPropCount = xProps->Count();
- for ( USHORT nProp = 0 ; nProp < nPropCount ; ++nProp )
+ sal_uInt16 nPropCount = xProps->Count();
+ for ( sal_uInt16 nProp = 0 ; nProp < nPropCount ; ++nProp )
{
SbxBase* pVar = xProps->Get( nProp );
pVar->Clear();
}
- SetModified( TRUE );
+ SetModified( sal_True );
}
// This implementation at first searches within the runtime library,
@@ -1106,7 +1316,7 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
}
// Search module
if( !pRes )
- for( USHORT i = 0; i < pModules->Count(); i++ )
+ for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
{
SbModule* p = (SbModule*) pModules->Get( i );
if( p->IsVisible() )
@@ -1123,12 +1333,12 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
}
// Only variables qualified by the Module Name e.g. Sheet1.foo
// should work for Documant && Class type Modules
- INT32 nType = p->GetModuleType();
+ sal_Int32 nType = p->GetModuleType();
if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM )
continue;
// otherwise check if the element is available
// unset GBLSEARCH-Flag (due to Rekursion)
- USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
+ sal_uInt16 nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
p->ResetFlag( SBX_GBLSEARCH );
pRes = p->Find( rName, t );
p->SetFlag( nGblFlag );
@@ -1144,9 +1354,9 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
return pRes;
}
-BOOL StarBASIC::Call( const String& rName, SbxArray* pParam )
+sal_Bool StarBASIC::Call( const String& rName, SbxArray* pParam )
{
- BOOL bRes = SbxObject::Call( rName, pParam );
+ sal_Bool bRes = SbxObject::Call( rName, pParam );
if( !bRes )
{
SbxError eErr = SbxBase::GetError();
@@ -1169,7 +1379,7 @@ SbxBase* StarBASIC::FindSBXInCurrentScope( const String& rName )
// Preserve old interface
SbxVariable* StarBASIC::FindVarInCurrentScopy
-( const String& rName, USHORT& rStatus )
+( const String& rName, sal_uInt16& rStatus )
{
rStatus = 1; // Presumption: nothing found
SbxVariable* pVar = NULL;
@@ -1187,7 +1397,7 @@ SbxVariable* StarBASIC::FindVarInCurrentScopy
void StarBASIC::QuitAndExitApplication()
{
Stop();
- bQuit = TRUE;
+ bQuit = sal_True;
}
void StarBASIC::Stop()
@@ -1200,9 +1410,9 @@ void StarBASIC::Stop()
}
}
-BOOL StarBASIC::IsRunning()
+sal_Bool StarBASIC::IsRunning()
{
- return BOOL( pINST != NULL );
+ return sal_Bool( pINST != NULL );
}
/**************************************************************************
@@ -1213,7 +1423,7 @@ BOOL StarBASIC::IsRunning()
// Activation of an object. There is no need to access active objects
// with name via BASIC. If NULL is given, everything is activated.
-void StarBASIC::ActivateObject( const String* pName, BOOL bActivate )
+void StarBASIC::ActivateObject( const String* pName, sal_Bool bActivate )
{
if( pName )
{
@@ -1228,7 +1438,7 @@ void StarBASIC::ActivateObject( const String* pName, BOOL bActivate )
}
else
{
- for( USHORT i = 0; i < GetObjects()->Count(); i++ )
+ for( sal_uInt16 i = 0; i < GetObjects()->Count(); i++ )
{
SbxObject* p = (SbxObject*) GetObjects()->Get( i );
if( bActivate )
@@ -1245,7 +1455,7 @@ void StarBASIC::ActivateObject( const String* pName, BOOL bActivate )
*
**************************************************************************/
-SbMethod* StarBASIC::GetActiveMethod( USHORT nLevel )
+SbMethod* StarBASIC::GetActiveMethod( sal_uInt16 nLevel )
{
if( pINST )
return pINST->GetCaller( nLevel );
@@ -1261,41 +1471,41 @@ SbModule* StarBASIC::GetActiveModule()
return pCMOD;
}
-USHORT StarBASIC::BreakPoint( USHORT l, USHORT c1, USHORT c2 )
+sal_uInt16 StarBASIC::BreakPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
{
SetErrorData( 0, l, c1, c2 );
- bBreak = TRUE;
+ bBreak = sal_True;
if( GetSbData()->aBreakHdl.IsSet() )
- return (USHORT) GetSbData()->aBreakHdl.Call( this );
+ return (sal_uInt16) GetSbData()->aBreakHdl.Call( this );
else
return BreakHdl();
}
-USHORT StarBASIC::StepPoint( USHORT l, USHORT c1, USHORT c2 )
+sal_uInt16 StarBASIC::StepPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
{
SetErrorData( 0, l, c1, c2 );
- bBreak = FALSE;
+ bBreak = sal_False;
if( GetSbData()->aBreakHdl.IsSet() )
- return (USHORT) GetSbData()->aBreakHdl.Call( this );
+ return (sal_uInt16) GetSbData()->aBreakHdl.Call( this );
else
return BreakHdl();
}
-USHORT StarBASIC::BreakHdl()
+sal_uInt16 StarBASIC::BreakHdl()
{
- return (USHORT) ( aBreakHdl.IsSet()
+ return (sal_uInt16) ( aBreakHdl.IsSet()
? aBreakHdl.Call( this ) : SbDEBUG_CONTINUE );
}
// Calls for error handler and break handler
-USHORT StarBASIC::GetLine() { return GetSbData()->nLine; }
-USHORT StarBASIC::GetCol1() { return GetSbData()->nCol1; }
-USHORT StarBASIC::GetCol2() { return GetSbData()->nCol2; }
+sal_uInt16 StarBASIC::GetLine() { return GetSbData()->nLine; }
+sal_uInt16 StarBASIC::GetCol1() { return GetSbData()->nCol1; }
+sal_uInt16 StarBASIC::GetCol2() { return GetSbData()->nCol2; }
// Specific to error handler
SbError StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
const String& StarBASIC::GetErrorText() { return GetSbData()->aErrMsg; }
-BOOL StarBASIC::IsCompilerError() { return GetSbData()->bCompiler; }
+sal_Bool StarBASIC::IsCompilerError() { return GetSbData()->bCompiler; }
void StarBASIC::SetGlobalLanguageMode( SbLanguageMode eLanguageMode )
{
GetSbData()->eLanguageMode = eLanguageMode;
@@ -1322,9 +1532,9 @@ SbLanguageMode StarBASIC::GetLanguageMode()
// binaere search by VB-Error -> SFX-Error.
// Map back new error codes to old, Sbx-compatible
-USHORT StarBASIC::GetVBErrorCode( SbError nError )
+sal_uInt16 StarBASIC::GetVBErrorCode( SbError nError )
{
- USHORT nRet = 0;
+ sal_uInt16 nRet = 0;
if( SbiRuntime::isVBAEnabled() )
{
@@ -1349,7 +1559,7 @@ USHORT StarBASIC::GetVBErrorCode( SbError nError )
// search loop
const SFX_VB_ErrorItem* pErrItem;
- USHORT nIndex = 0;
+ sal_uInt16 nIndex = 0;
do
{
pErrItem = SFX_VB_ErrorTab + nIndex;
@@ -1364,7 +1574,7 @@ USHORT StarBASIC::GetVBErrorCode( SbError nError )
return nRet;
}
-SbError StarBASIC::GetSfxFromVBError( USHORT nError )
+SbError StarBASIC::GetSfxFromVBError( sal_uInt16 nError )
{
SbError nRet = 0L;
@@ -1396,7 +1606,7 @@ SbError StarBASIC::GetSfxFromVBError( USHORT nError )
}
}
const SFX_VB_ErrorItem* pErrItem;
- USHORT nIndex = 0;
+ sal_uInt16 nIndex = 0;
do
{
pErrItem = SFX_VB_ErrorTab + nIndex;
@@ -1416,7 +1626,7 @@ SbError StarBASIC::GetSfxFromVBError( USHORT nError )
// set Error- / Break-data
void StarBASIC::SetErrorData
-( SbError nCode, USHORT nLine, USHORT nCol1, USHORT nCol2 )
+( SbError nCode, sal_uInt16 nLine, sal_uInt16 nCol1, sal_uInt16 nCol2 )
{
SbiGlobals& aGlobals = *GetSbData();
aGlobals.nCode = nCode;
@@ -1432,26 +1642,26 @@ struct BasicStringList_Impl : private Resource
{
ResId aResId;
- BasicStringList_Impl( ResId& rErrIdP, USHORT nId)
+ BasicStringList_Impl( ResId& rErrIdP, sal_uInt16 nId)
: Resource( rErrIdP ),aResId(nId, *rErrIdP.GetResMgr() ){}
~BasicStringList_Impl() { FreeResource(); }
String GetString(){ return String( aResId ); }
- BOOL IsErrorTextAvailable( void )
+ sal_Bool IsErrorTextAvailable( void )
{ return IsAvailableRes(aResId.SetRT(RSC_STRING)); }
};
//----------------------------------------------------------------
// Flag, that prevent the activation of the SFX-Resources at a Basic error
-static BOOL bStaticSuppressSfxResource = FALSE;
+static sal_Bool bStaticSuppressSfxResource = sal_False;
-void StarBASIC::StaticSuppressSfxResource( BOOL bSuppress )
+void StarBASIC::StaticSuppressSfxResource( sal_Bool bSuppress )
{
bStaticSuppressSfxResource = bSuppress;
}
// Hack for #83750, use bStaticSuppressSfxResource as setup flag
-BOOL runsInSetup( void )
+sal_Bool runsInSetup( void )
{
return bStaticSuppressSfxResource;
}
@@ -1467,11 +1677,11 @@ void StarBASIC::MakeErrorText( SbError nId, const String& aMsg )
return;
}
- USHORT nOldID = GetVBErrorCode( nId );
+ sal_uInt16 nOldID = GetVBErrorCode( nId );
// intantiate the help class
BasResId aId( RID_BASIC_START );
- BasicStringList_Impl aMyStringList( aId, USHORT(nId & ERRCODE_RES_MASK) );
+ BasicStringList_Impl aMyStringList( aId, sal_uInt16(nId & ERRCODE_RES_MASK) );
if( aMyStringList.IsErrorTextAvailable() )
{
@@ -1479,7 +1689,7 @@ void StarBASIC::MakeErrorText( SbError nId, const String& aMsg )
String aMsg1 = aMyStringList.GetString();
// replace argument placeholder with %s
String aSrgStr( RTL_CONSTASCII_USTRINGPARAM("$(ARG1)") );
- USHORT nResult = aMsg1.Search( aSrgStr );
+ sal_uInt16 nResult = aMsg1.Search( aSrgStr );
if( nResult != STRING_NOTFOUND )
{
@@ -1500,8 +1710,8 @@ void StarBASIC::MakeErrorText( SbError nId, const String& aMsg )
}
-BOOL StarBASIC::CError
- ( SbError code, const String& rMsg, USHORT l, USHORT c1, USHORT c2 )
+sal_Bool StarBASIC::CError
+ ( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
{
SolarMutexGuard aSolarGuard;
@@ -1511,39 +1721,39 @@ BOOL StarBASIC::CError
// #109018 Check if running Basic is affected
StarBASIC* pStartedBasic = pINST->GetBasic();
if( pStartedBasic != this )
- return FALSE;
+ return sal_False;
Stop();
}
// set flag, so that GlobalRunInit notice the error
- GetSbData()->bGlobalInitErr = TRUE;
+ GetSbData()->bGlobalInitErr = sal_True;
// tinker the error message
MakeErrorText( code, rMsg );
// Implementation of the code for the string transport to SFX-Error
if( rMsg.Len() )
- code = (ULONG)*new StringErrorInfo( code, String(rMsg) );
+ code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) );
SetErrorData( code, l, c1, c2 );
- GetSbData()->bCompiler = TRUE;
- BOOL bRet;
+ GetSbData()->bCompiler = sal_True;
+ sal_Bool bRet;
if( GetSbData()->aErrHdl.IsSet() )
- bRet = (BOOL) GetSbData()->aErrHdl.Call( this );
+ bRet = (sal_Bool) GetSbData()->aErrHdl.Call( this );
else
bRet = ErrorHdl();
- GetSbData()->bCompiler = FALSE; // only true for error handler
+ GetSbData()->bCompiler = sal_False; // only true for error handler
return bRet;
}
-BOOL StarBASIC::RTError
- ( SbError code, USHORT l, USHORT c1, USHORT c2 )
+sal_Bool StarBASIC::RTError
+ ( SbError code, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
{
return RTError( code, String(), l, c1, c2 );
}
-BOOL StarBASIC::RTError( SbError code, const String& rMsg, USHORT l, USHORT c1, USHORT c2 )
+sal_Bool StarBASIC::RTError( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
{
SolarMutexGuard aSolarGuard;
@@ -1565,15 +1775,15 @@ BOOL StarBASIC::RTError( SbError code, const String& rMsg, USHORT l, USHORT c1,
aTmp += String::CreateFromInt32( SbxErrObject::getUnoErrObject()->getNumber() );
aTmp += String( RTL_CONSTASCII_USTRINGPARAM("\'\n") );
aTmp += GetSbData()->aErrMsg.Len() ? GetSbData()->aErrMsg : rMsg;
- code = (ULONG)*new StringErrorInfo( code, aTmp );
+ code = (sal_uIntPtr)*new StringErrorInfo( code, aTmp );
}
else
- code = (ULONG)*new StringErrorInfo( code, String(rMsg) );
+ code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) );
}
SetErrorData( code, l, c1, c2 );
if( GetSbData()->aErrHdl.IsSet() )
- return (BOOL) GetSbData()->aErrHdl.Call( this );
+ return (sal_Bool) GetSbData()->aErrHdl.Call( this );
else
return ErrorHdl();
}
@@ -1618,7 +1828,7 @@ String StarBASIC::GetErrorMsg()
return String();
}
-USHORT StarBASIC::GetErl()
+sal_uInt16 StarBASIC::GetErl()
{
if( pINST )
return pINST->GetErl();
@@ -1626,10 +1836,10 @@ USHORT StarBASIC::GetErl()
return 0;
}
-BOOL StarBASIC::ErrorHdl()
+sal_Bool StarBASIC::ErrorHdl()
{
- return (BOOL) ( aErrorHdl.IsSet()
- ? aErrorHdl.Call( this ) : FALSE );
+ return (sal_Bool) ( aErrorHdl.IsSet()
+ ? aErrorHdl.Call( this ) : sal_False );
}
Link StarBASIC::GetGlobalErrorHdl()
@@ -1667,16 +1877,16 @@ SbxArrayRef StarBASIC::getUnoListeners( void )
*
**************************************************************************/
-BOOL StarBASIC::LoadData( SvStream& r, USHORT nVer )
+sal_Bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
{
if( !SbxObject::LoadData( r, nVer ) )
- return FALSE;
+ return sal_False;
// #95459 Delete dialogs, otherwise endless recursion
// in SbxVarable::GetType() if dialogs are accessed
- USHORT nObjCount = pObjs->Count();
+ sal_uInt16 nObjCount = pObjs->Count();
SbxVariable** ppDeleteTab = new SbxVariable*[ nObjCount ];
- USHORT nObj;
+ sal_uInt16 nObj;
for( nObj = 0 ; nObj < nObjCount ; nObj++ )
{
@@ -1692,14 +1902,14 @@ BOOL StarBASIC::LoadData( SvStream& r, USHORT nVer )
}
delete[] ppDeleteTab;
- UINT16 nMod;
+ sal_uInt16 nMod;
pModules->Clear();
r >> nMod;
- for( USHORT i = 0; i < nMod; i++ )
+ for( sal_uInt16 i = 0; i < nMod; i++ )
{
SbModule* pMod = (SbModule*) SbxBase::Load( r );
if( !pMod )
- return FALSE;
+ return sal_False;
else if( pMod->ISA(SbJScriptModule) )
{
// assign Ref, so that pMod will be deleted
@@ -1722,26 +1932,26 @@ BOOL StarBASIC::LoadData( SvStream& r, USHORT nVer )
// Search via StarBASIC is at all times global
DBG_ASSERT( IsSet( SBX_GBLSEARCH ), "Basic ohne GBLSEARCH geladen" );
SetFlag( SBX_GBLSEARCH );
- return TRUE;
+ return sal_True;
}
-BOOL StarBASIC::StoreData( SvStream& r ) const
+sal_Bool StarBASIC::StoreData( SvStream& r ) const
{
if( !SbxObject::StoreData( r ) )
- return FALSE;
- r << (UINT16) pModules->Count();
- for( USHORT i = 0; i < pModules->Count(); i++ )
+ return sal_False;
+ r << (sal_uInt16) pModules->Count();
+ for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
{
SbModule* p = (SbModule*) pModules->Get( i );
if( !p->Store( r ) )
- return FALSE;
+ return sal_False;
}
- return TRUE;
+ return sal_True;
}
-BOOL StarBASIC::LoadOldModules( SvStream& )
+sal_Bool StarBASIC::LoadOldModules( SvStream& )
{
- return FALSE;
+ return sal_False;
}
bool StarBASIC::GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut )
@@ -1757,6 +1967,54 @@ bool StarBASIC::GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::u
return bRes;
}
+Reference< frame::XModel > StarBASIC::GetModelFromBasic( SbxObject* pBasic )
+{
+ 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 )
+ {
+ pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT );
+ pLookup = pLookup->GetParent();
+ }
+ if ( !pThisComponent )
+ {
+ OSL_TRACE("Failed to get ThisComponent");
+ // the application Basic, at the latest, should have this variable
+ return NULL;
+ }
+
+ Any aThisComponentAny( sbxToUnoValue( pThisComponent ) );
+ Reference< frame::XModel > xModel( aThisComponentAny, UNO_QUERY );
+ if ( !xModel.is() )
+ {
+ // it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller.
+ Reference< frame::XController > xController( aThisComponentAny, UNO_QUERY );
+ if ( xController.is() )
+ xModel = xController->getModel();
+ }
+
+ if ( !xModel.is() )
+ return NULL;
+
+#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
+
+ return xModel;
+}
+
+
//========================================================================
// #118116 Implementation Collection object
@@ -1766,7 +2024,7 @@ static const char pCountStr[] = "Count";
static const char pAddStr[] = "Add";
static const char pItemStr[] = "Item";
static const char pRemoveStr[] = "Remove";
-static USHORT nCountHash = 0, nAddHash, nItemHash, nRemoveHash;
+static sal_uInt16 nCountHash = 0, nAddHash, nItemHash, nRemoveHash;
SbxInfoRef BasicCollection::xAddInfo = NULL;
SbxInfoRef BasicCollection::xItemInfo = NULL;
@@ -1837,10 +2095,10 @@ void BasicCollection::SFX_NOTIFY( SfxBroadcaster& rCst, const TypeId& rId1,
const SbxHint* p = PTR_CAST(SbxHint,&rHint);
if( p )
{
- ULONG nId = p->GetId();
- BOOL bRead = BOOL( nId == SBX_HINT_DATAWANTED );
- BOOL bWrite = BOOL( nId == SBX_HINT_DATACHANGED );
- BOOL bRequestInfo = BOOL( nId == SBX_HINT_INFOWANTED );
+ sal_uIntPtr nId = p->GetId();
+ sal_Bool bRead = sal_Bool( nId == SBX_HINT_DATAWANTED );
+ sal_Bool bWrite = sal_Bool( nId == SBX_HINT_DATACHANGED );
+ sal_Bool bRequestInfo = sal_Bool( nId == SBX_HINT_INFOWANTED );
SbxVariable* pVar = p->GetVar();
SbxArray* pArg = pVar->GetParameters();
XubString aVarName( pVar->GetName() );
@@ -1875,9 +2133,9 @@ void BasicCollection::SFX_NOTIFY( SfxBroadcaster& rCst, const TypeId& rId1,
SbxObject::SFX_NOTIFY( rCst, rId1, rHint, rId2 );
}
-INT32 BasicCollection::implGetIndex( SbxVariable* pIndexVar )
+sal_Int32 BasicCollection::implGetIndex( SbxVariable* pIndexVar )
{
- INT32 nIndex = -1;
+ sal_Int32 nIndex = -1;
if( pIndexVar->GetType() == SbxSTRING )
nIndex = implGetIndexForName( pIndexVar->GetString() );
else
@@ -1885,12 +2143,12 @@ INT32 BasicCollection::implGetIndex( SbxVariable* pIndexVar )
return nIndex;
}
-INT32 BasicCollection::implGetIndexForName( const String& rName )
+sal_Int32 BasicCollection::implGetIndexForName( const String& rName )
{
- INT32 nIndex = -1;
- INT32 nCount = xItemArray->Count32();
- INT32 nNameHash = MakeHashCode( rName );
- for( INT32 i = 0 ; i < nCount ; i++ )
+ sal_Int32 nIndex = -1;
+ sal_Int32 nCount = xItemArray->Count32();
+ sal_Int32 nNameHash = MakeHashCode( rName );
+ for( sal_Int32 i = 0 ; i < nCount ; i++ )
{
SbxVariable* pVar = xItemArray->Get32( i );
if( pVar->GetHashCode() == nNameHash &&
@@ -1905,7 +2163,7 @@ INT32 BasicCollection::implGetIndexForName( const String& rName )
void BasicCollection::CollAdd( SbxArray* pPar_ )
{
- USHORT nCount = pPar_->Count();
+ sal_uInt16 nCount = pPar_->Count();
if( nCount < 2 || nCount > 5 )
{
SetError( SbxERR_WRONG_ARGS );
@@ -1931,7 +2189,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
return;
}
SbxVariable* pAfter = pPar_->Get(4);
- INT32 nAfterIndex = implGetIndex( pAfter );
+ sal_Int32 nAfterIndex = implGetIndex( pAfter );
if( nAfterIndex == -1 )
{
SetError( SbERR_BAD_ARGUMENT );
@@ -1941,7 +2199,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
}
else // if( nCount == 4 )
{
- INT32 nBeforeIndex = implGetIndex( pBefore );
+ sal_Int32 nBeforeIndex = implGetIndex( pBefore );
if( nBeforeIndex == -1 )
{
SetError( SbERR_BAD_ARGUMENT );
@@ -1990,8 +2248,8 @@ void BasicCollection::CollItem( SbxArray* pPar_ )
}
SbxVariable* pRes = NULL;
SbxVariable* p = pPar_->Get( 1 );
- INT32 nIndex = implGetIndex( p );
- if( nIndex >= 0 && nIndex < (INT32)xItemArray->Count32() )
+ sal_Int32 nIndex = implGetIndex( p );
+ if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() )
pRes = xItemArray->Get32( nIndex );
if( !pRes )
SetError( SbERR_BAD_ARGUMENT );
@@ -2008,8 +2266,8 @@ void BasicCollection::CollRemove( SbxArray* pPar_ )
}
SbxVariable* p = pPar_->Get( 1 );
- INT32 nIndex = implGetIndex( p );
- if( nIndex >= 0 && nIndex < (INT32)xItemArray->Count32() )
+ sal_Int32 nIndex = implGetIndex( p );
+ if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() )
xItemArray->Remove32( nIndex );
else
SetError( SbERR_BAD_ARGUMENT );