summaryrefslogtreecommitdiff
path: root/basic/source
diff options
context:
space:
mode:
authorAndreas Bregas <ab@openoffice.org>2011-02-11 15:06:12 +0100
committerAndreas Bregas <ab@openoffice.org>2011-02-11 15:06:12 +0100
commitfcad8a5c8b77bfc6b3cb41d7465147ad157d0124 (patch)
tree0c770581341174ac2eaf844d29265be34110f63b /basic/source
parentd646413d464dc5d6518f87daa8538cd0c600797f (diff)
ab80: Adding changes of cws mib21, ab77, ab77run2, dr77i to dev300
ab77: #163789# Handle class module factories document specific ab77: #163732# Defer removal of documents until XCloseListener::notifyClosing ab77: #163808# make VBA symbols Application.ScreenUpdating and Application.Interactive work globally on all documents ab77: wae ab77: #163840# read UTF-8 BOM ab77: #163732# VBA UserForm_Terminate triggered too late while closing document ab77: minor correction ab77: assertion: do not call ::rtl::OUString::copy() with negative index ab77run2: #163869# do not call Class_Terminate VBA macros when document disposes dr77i: #163941# do not update drawing layer when pasting from clipboard after cut mib21: #163944# ignore trailing whitespace in Basic source lines mib21: #163948# allow to manually pack MSVC DLLs into extensions mib21: #163948# multiprocess build fix Authors: Andreas Bregas <ab@openoffice.org> Daniel Rentz [dr] <daniel.rentz@oracle.com> Eike Rathke [er] <eike.rathke@oracle.com>
Diffstat (limited to 'basic/source')
-rw-r--r--basic/source/basmgr/makefile.mk3
-rw-r--r--basic/source/classes/sb.cxx193
-rwxr-xr-xbasic/source/classes/sbxmod.cxx103
-rw-r--r--basic/source/comp/scanner.cxx20
4 files changed, 255 insertions, 64 deletions
diff --git a/basic/source/basmgr/makefile.mk b/basic/source/basmgr/makefile.mk
index e08e9cc753bd..d177379f32b8 100644
--- a/basic/source/basmgr/makefile.mk
+++ b/basic/source/basmgr/makefile.mk
@@ -39,7 +39,8 @@ ENABLE_EXCEPTIONS=TRUE
SLOFILES= \
$(SLO)$/basmgr.obj \
- $(SLO)$/basicmanagerrepository.obj
+ $(SLO)$/basicmanagerrepository.obj \
+ $(SLO)$/vbahelper.obj
# --- Targets -------------------------------------------------------------
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 30e01892fab9..87c26805b18f 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -55,8 +55,12 @@
#include "sb.hrc"
#include <basrid.hxx>
#include <vos/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 <map>
#include <hash_map>
#include <com/sun/star/script/ModuleType.hpp>
@@ -80,6 +84,143 @@ using com::sun::star::lang::XMultiServiceFactory;
const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
+// ============================================================================
+
+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 std::map< const StarBASIC*, DocBasicItemRef > DocBasicItemMap;
+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 )
@@ -461,6 +602,7 @@ SbxObject* createUserTypeImpl( const String& rClassName )
return pRetObj;
}
+
TYPEINIT1(SbClassModuleObject,SbModule)
SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
@@ -610,8 +752,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
@@ -699,8 +845,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 );
}
@@ -717,12 +869,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;
}
@@ -734,9 +893,6 @@ SbModule* SbClassFactory::FindClass( const String& rClassName )
return pMod;
}
-typedef std::vector< StarBASIC* > DocBasicVector;
-static DocBasicVector GaDocBasics;
-
StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic )
: SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic )
{
@@ -768,7 +924,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic )
bQuit = FALSE;
if( bDocBasic )
- GaDocBasics.push_back( this );
+ lclInsertDocBasicItem( *this );
}
// #51727 Override SetModified so that the modified state
@@ -780,6 +936,9 @@ void StarBASIC::SetModified( BOOL b )
StarBASIC::~StarBASIC()
{
+ // Needs to be first action as it can trigger events
+ disposeComVariablesForBasic( this );
+
if( !--GetSbData()->nInst )
{
RemoveFactory( pSBFAC );
@@ -812,20 +971,7 @@ StarBASIC::~StarBASIC()
{
SbxError eOld = SbxBase::GetError();
- DocBasicVector::iterator it;
- for( it = GaDocBasics.begin() ; it != GaDocBasics.end() ; ++it )
- {
- if( *it == this )
- {
- GaDocBasics.erase( it );
- break;
- }
- }
- for( it = GaDocBasics.begin() ; it != GaDocBasics.end() ; ++it )
- {
- StarBASIC* pBasic = *it;
- pBasic->implClearDependingVarsOnDelete( this );
- }
+ lclRemoveDocBasicItem( *this );
SbxBase::ResetError();
if( eOld != SbxERR_OK )
@@ -845,7 +991,6 @@ StarBASIC::~StarBASIC()
}
clearUnoMethodsForBasic( this );
- disposeComVariablesForBasic( this );
}
// Override new() operator, so that everyone can create a new instance
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 0f807db7cf8f..541f3d8d6c82 100755
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -54,11 +54,15 @@
#include <basic/basrdll.hxx>
#include <vos/mutex.hxx>
#include <basic/sbobjmod.hxx>
-#include <cppuhelper/implbase2.hxx>
+#include <basic/vbahelper.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <unotools/eventcfg.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/vba/XVBACompatibility.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/document/XEventBroadcaster.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
using namespace com::sun::star;
@@ -496,24 +500,18 @@ IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ )
return 0L;
}
-bool VBAUnlockControllers( StarBASIC* pBasic )
+void VBAUnlockDocuments( StarBASIC* pBasic )
{
- bool bRes = false;
if ( pBasic && pBasic->IsDocBasic() )
{
SbUnoObject* pGlobs = dynamic_cast< SbUnoObject* >( pBasic->Find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ), SbxCLASS_DONTCARE ) );
- if ( pGlobs ) try
- {
- uno::Reference< frame::XModel > xModel( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW );
- if ( xModel->hasControllersLocked() )
- xModel->unlockControllers();
- bRes = true;
- }
- catch( uno::Exception& )
+ if ( pGlobs )
{
+ uno::Reference< frame::XModel > xModel( pGlobs->getUnoAny(), uno::UNO_QUERY );
+ ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False );
+ ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True );
}
}
- return bRes;
}
/////////////////////////////////////////////////////////////////////////////
@@ -1182,7 +1180,7 @@ USHORT SbModule::Run( SbMethod* pMeth )
// VBA always ensures screenupdating is enabled after completing
if ( mbVBACompat )
- VBAUnlockControllers( PTR_CAST( StarBASIC, GetParent() ) );
+ VBAUnlockDocuments( PTR_CAST( StarBASIC, GetParent() ) );
#ifdef DBG_TRACE_BASIC
dbg_DeInitTrace();
@@ -2162,22 +2160,27 @@ void SbObjModule::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
}
-typedef ::cppu::WeakImplHelper2< awt::XTopWindowListener, awt::XWindowListener > FormObjEventListener_BASE;
+typedef ::cppu::WeakImplHelper3<
+ awt::XTopWindowListener,
+ awt::XWindowListener,
+ document::XEventListener > FormObjEventListener_BASE;
class FormObjEventListenerImpl : public FormObjEventListener_BASE
{
SbUserFormModule* mpUserForm;
uno::Reference< lang::XComponent > mxComponent;
+ uno::Reference< frame::XModel > mxModel;
bool mbDisposed;
sal_Bool mbOpened;
sal_Bool mbActivated;
sal_Bool mbShowing;
- FormObjEventListenerImpl(); // not defined
+
FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
+ FormObjEventListenerImpl& operator=(const FormObjEventListenerImpl&); // not defined
public:
- FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) :
- mpUserForm( pUserForm ), mxComponent( xComponent) ,
+ FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent, const uno::Reference< frame::XModel >& xModel ) :
+ mpUserForm( pUserForm ), mxComponent( xComponent), mxModel( xModel ),
mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False )
{
if ( mxComponent.is() )
@@ -2194,6 +2197,15 @@ public:
}
catch( uno::Exception& ) {}
}
+
+ if ( mxModel.is() )
+ {
+ try
+ {
+ uno::Reference< document::XEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->addEventListener( this );
+ }
+ catch( uno::Exception& ) {}
+ }
}
virtual ~FormObjEventListenerImpl()
@@ -2220,6 +2232,16 @@ public:
catch( uno::Exception& ) {}
}
mxComponent.clear();
+
+ if ( mxModel.is() && !mbDisposed )
+ {
+ try
+ {
+ uno::Reference< document::XEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->removeEventListener( this );
+ }
+ catch( uno::Exception& ) {}
+ }
+ mxModel.clear();
}
virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
@@ -2327,13 +2349,25 @@ public:
{
}
+ virtual void SAL_CALL notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException)
+ {
+ // early dosposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate"
+ if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ) )
+ {
+ removeListener();
+ mbDisposed = true;
+ if ( mpUserForm )
+ mpUserForm->ResetApiObj(); // will trigger "UserForm_Terminate"
+ }
+ }
+
virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
{
OSL_TRACE("** Userform/Dialog disposing");
+ removeListener();
mbDisposed = true;
- mxComponent.clear();
if ( mpUserForm )
- mpUserForm->ResetApiObj();
+ mpUserForm->ResetApiObj( false ); // pass false (too late to trigger VBA events here)
}
};
@@ -2567,30 +2601,27 @@ void SbUserFormModule::InitObject()
aArgs[ 2 ] <<= m_xModel;
aArgs[ 3 ] <<= rtl::OUString( GetParent()->GetName() );
pDocObject = new SbUnoObject( GetName(), uno::makeAny( xVBAFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.UserForm")), aArgs ) ) );
- uno::Reference< lang::XComponent > xComponent( aArgs[ 1 ], uno::UNO_QUERY_THROW );
+
+ uno::Reference< lang::XComponent > xComponent( m_xDialog, uno::UNO_QUERY_THROW );
// the dialog must be disposed at the end!
- if( xComponent.is() )
+ StarBASIC* pParentBasic = NULL;
+ SbxObject* pCurObject = this;
+ do
{
- StarBASIC* pParentBasic = NULL;
- SbxObject* pCurObject = this;
- do
- {
- SbxObject* pObjParent = pCurObject->GetParent();
- pParentBasic = PTR_CAST( StarBASIC, pObjParent );
- pCurObject = pObjParent;
- }
- while( pParentBasic == NULL && pCurObject != NULL );
-
- OSL_ASSERT( pParentBasic != NULL );
- registerComponentToBeDisposedForBasic( xComponent, pParentBasic );
+ SbxObject* pObjParent = pCurObject->GetParent();
+ pParentBasic = PTR_CAST( StarBASIC, pObjParent );
+ pCurObject = pObjParent;
}
+ while( pParentBasic == NULL && pCurObject != NULL );
+ OSL_ASSERT( pParentBasic != NULL );
+ registerComponentToBeDisposedForBasic( xComponent, pParentBasic );
- // remove old listener if it exists
- if ( m_DialogListener.get() )
+ // if old listener object exists, remove it from dialog and document model
+ if( m_DialogListener.is() )
m_DialogListener->removeListener();
- m_DialogListener = new FormObjEventListenerImpl( this, xComponent );
+ m_DialogListener.set( new FormObjEventListenerImpl( this, xComponent, m_xModel ) );
triggerInitializeEvent();
}
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 26c6af53cc56..4b917e61e179 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -152,6 +152,16 @@ static SbxDataType GetSuffixType( sal_Unicode c )
// Returnwert ist FALSE bei EOF oder Fehlern
#define BUF_SIZE 80
+namespace {
+
+/** Returns true, if the passed character is a white space character. */
+inline bool lclIsWhitespace( sal_Unicode cChar )
+{
+ return (cChar == ' ') || (cChar == '\t') || (cChar == '\f');
+}
+
+} // namespace
+
BOOL SbiScanner::NextSym()
{
// Fuer den EOLN-Fall merken
@@ -177,7 +187,11 @@ BOOL SbiScanner::NextSym()
p2 += n;
while( ( n < nLen ) && ( *p2 != '\n' ) && ( *p2 != '\r' ) )
p2++, n++;
- aLine = aBuf.copy( nBufPos, n - nBufPos );
+ // #163944# ignore trailing whitespace
+ sal_Int32 nCopyEndPos = n;
+ while( (nBufPos < nCopyEndPos) && lclIsWhitespace( aBuf[ nCopyEndPos - 1 ] ) )
+ --nCopyEndPos;
+ aLine = aBuf.copy( nBufPos, nCopyEndPos - nBufPos );
if( n < nLen )
{
if( *p2 == '\r' && *( p2+1 ) == '\n' )
@@ -193,7 +207,7 @@ BOOL SbiScanner::NextSym()
}
// Leerstellen weg:
- while( *pLine && (( *pLine == ' ' ) || ( *pLine == '\t' ) || ( *pLine == '\f' )) )
+ while( lclIsWhitespace( *pLine ) )
pLine++, nCol++, bSpaces = TRUE;
nCol1 = nCol;
@@ -230,7 +244,7 @@ BOOL SbiScanner::NextSym()
{
const sal_Unicode* pTestLine = pLine;
short nTestCol = nCol;
- while( *pTestLine && (( *pTestLine == ' ' ) || ( *pTestLine == '\t' )) )
+ while( lclIsWhitespace( *pTestLine ) )
{
pTestLine++;
nTestCol++;