Commits

Anonymous committed 64feb95 Merge

accfixes2: merge with DEV300_m101

Comments (0)

Files changed (907)

 c70c59ba39fdbab2bcca904cbc48c19a66d2fe8a OOO330_m19
 8601acbe0e6ca2dd3797ec8289027bed264a67b7 OOO330_m20
 055aad264da0cf9598fd1b7aafbd3e144c9b8ce2 DEV300_m99
+20c5c9384888da33596d864251881e6e46bdd339 DEV300_m100
 	comphelper \
         editeng \
 	framework \
+	padmin \
 	sfx2 \
     sot \
 	svl \
 	sspretty \
 ))
 
+$(eval $(call gb_Helper_register_executables,OOO, \
+    spadmin.bin \
+))
+
 $(eval $(call gb_Helper_register_libraries,OOOLIBS, \
 	avmedia \
 	basegfx \
 	sb \
 	sfx \
 	sot \
+	spa \
 	svl \
 	svt \
 	svx \
 	jpeglib \
 	ooopathutils \
 	salcpprt \
+	vclmain \
 	zlib \
     vclmain \
 ))

accessibility/prj/build.lst

-ac  accessibility	:    l10n tools jurt offuh unoil vcl javaunohelper jvmaccess cppu sal toolkit svtools LIBXSLT:libxslt NULL
+ac  accessibility	:    L10N:l10n tools jurt offuh unoil vcl javaunohelper jvmaccess cppu sal toolkit svtools LIBXSLT:libxslt NULL
 ac	accessibility                                         	usr1	-	all	ac_mkout NULL
 ac	accessibility\inc                                      	nmake	-	all	ac_inc NULL
 ac	accessibility\bridge\org\openoffice\java\accessibility	nmake	-	w	ac_ooja ac_inc NULL

accessibility/source/extended/AccessibleGridControlTable.cxx

     ensureIsValidIndex( nChildIndex );
     sal_Int32 nColumns = m_aTable.GetColumnCount();
     sal_Int32 nRow = (nChildIndex / nColumns);
-    std::vector< sal_Int32 > selectedRows = m_aTable.GetSelectedRows();
-    selectedRows.push_back(nRow);
+    m_aTable.SelectRow( nRow, sal_True );
 }
 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
     TCSolarGuard aSolarGuard;
     ::osl::MutexGuard aGuard( getOslMutex() );
     ensureIsAlive();
-    for(unsigned int i=0;i<m_aTable.GetSelectedRows().size();i++)
-	    m_aTable.RemoveSelectedRow((sal_Int32)i);
+    m_aTable.SelectAllRows( false );
 }
 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
     throw ( uno::RuntimeException )

accessibility/source/extended/AccessibleGridControlTableBase.cxx

 
 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
 {
-	rSeq = comphelper::containerToSequence(m_aTable.GetSelectedRows());
+    sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() );
+    rSeq.realloc( selectionCount );
+    for ( sal_Int32 i=0; i<selectionCount; ++i )
+        rSeq[i] = m_aTable.GetSelectedRowIndex(i);
 }
 
 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
File contents unchanged.

automation/source/server/statemnt.cxx

 #include <svtools/valueset.hxx>
 #include <svtools/roadmap.hxx>
 #include <svtools/table/tablecontrol.hxx>
+#include <svtools/table/tablecontrolinterface.hxx>
 #include <svl/poolitem.hxx>
 #include <svtools/extensionlistbox.hxx>
 // Hat keinen Includeschutz
                                                          ValueOK( aUId, MethodString( nMethodId ), nNr2, pTC->GetRowCount() ))
                                                     {
                                                         ::svt::table::PTableModel pModel = pTC->GetModel();
-                                                        Any aCell = pModel->getCellContent()[nNr2-1][nNr1-1];
+                                                        Any aCell;
+                                                        pModel->getCellContent( nNr1-1, nNr2-1, aCell );
                                                         pRet->GenReturn ( RET_Value, aUId, String( aCell.getValueTypeName() ));
                                                     }
 											    }
                                                          ValueOK( aUId, MethodString( nMethodId ), nNr2, pTC->GetRowCount() ))
                                                     {
                                                         ::svt::table::PTableModel pModel = pTC->GetModel();
-                                                        Any aCell = pModel->getCellContent()[nNr2-1][nNr1-1];
+                                                        Any aCell;
+                                                        pModel->getCellContent( nNr1-1, nNr2-1, aCell );
                                                         /* doesn't work ATM since it gets casted to SbxDATE in VCLTestTool unfortunately
 						                                SbxVariableRef xRes = new SbxVariable( SbxVARIANT );
 						                                unoToSbxValue( xRes, aCell );
                                                             Point aPos( aSize.Width() / 2, aSize.Height() / 2 );
                                                             long nStep = aSize.Height() / 4;
                                                             ::svt::table::RowPos nLastPos;
-                                                            while ( ( nLastPos = pTC->GetCurrentRow( aPos ) ) != nNr1-1 && nStep > 0 )
+                                                            while ( ( nLastPos = pTC->getTableControlInterface().hitTest( aPos ).nRow ) != nNr1-1 && nStep > 0 )
                                                             {
                                                                 if ( nLastPos > nNr1-1 || nLastPos == ROW_INVALID )
                                                                     aPos.Y() -= nStep;
                                                                     aPos.Y() += nStep;
                                                                 nStep /= 2;
                                                             }
-                                                            if ( pTC->GetCurrentRow( aPos ) == nNr1-1 )
+                                                            if ( pTC->getTableControlInterface().hitTest( aPos ).nRow == nNr1-1 )
                                                             {
                                                                 MouseEvent aMEvnt(aPos,1,MOUSE_SIMPLECLICK|MOUSE_SELECT,MOUSE_LEFT,KEY_MOD1);
                                                                 pTC->getSelEngine()->SelMouseButtonDown( aMEvnt );
 											    }
 											    break;
 										    case M_GetSelCount :
-											    pRet->GenReturn ( RET_Value, aUId, comm_USHORT( pTC->GetSelectedRows().size() ));
+											    pRet->GenReturn ( RET_Value, aUId, comm_USHORT( pTC->GetSelectedRowCount() ));
 											    break;
 										    case M_GetSelIndex :
 											    if ( ! (nParams & PARAM_USHORT_1) )
 												    nNr1 = 1;
-											    if ( ValueOK( aUId, CUniString("GetSelIndex"), nNr1, pTC->GetSelectedRows().size() ) )
-												    pRet->GenReturn ( RET_Value, aUId, comm_USHORT( pTC->GetSelectedRows()[nNr1-1] +1 ) );
+											    if ( ValueOK( aUId, CUniString("GetSelIndex"), nNr1, pTC->GetSelectedRowCount() ) )
+												    pRet->GenReturn ( RET_Value, aUId, comm_USHORT( pTC->GetSelectedRowIndex( nNr1-1 ) +1 ) );
 											    break;
 /*										    case M_GetSelText :
 											    if ( ! (nParams & PARAM_USHORT_1) )

avmedia/prj/build.lst

-av	avmedia	:    l10n tools sfx2 LIBXSLT:libxslt NULL
+av	avmedia	:    L10N:l10n tools sfx2 LIBXSLT:libxslt NULL
 av	avmedia                 	usr1	-	all	av_mkout												NULL
 av	avmedia\prj					get		-	all	av_prj													NULL
 av	avmedia\inc					get		-	all	av_inv													NULL

basctl/prj/build.lst

-bc	basctl	: LIBXSLT:libxslt l10n svx NULL
+bc	basctl	: LIBXSLT:libxslt L10N:l10n svx NULL
 bc	basctl									usr1	-	all	bc_mkout NULL
 bc	basctl\inc								nmake	-	all	bc_inc NULL
 bc	basctl\source\inc						get		-	all	bc_sinc NULL

basic/inc/basic/sbstar.hxx

 class SbTextPortions;
 class SbMethod;
 class BasicManager;
+class DocBasicItem;
 
 class StarBASICImpl;
 
 	friend class SbiExpression; // Access to RTL
 	friend class SbiInstance;
 	friend class SbiRuntime;
+	friend class DocBasicItem;
 
 	StarBASICImpl*	mpStarBASICImpl;
 

basic/inc/basic/vbahelper.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef BASIC_VBAHELPR_HXX
+#define BASIC_VBAHELPR_HXX
+
+#include <com/sun/star/frame/XModel.hpp>
+
+namespace basic {
+namespace vba {
+
+/*  This header contains public helper functions for VBA used from this module
+    and from other VBA implementation modules such as vbahelper.
+ */
+ 
+// ============================================================================
+
+/** Locks or unlocks the controllers of all documents that have the same type
+    as the specified document.
+
+    First, the global module manager (com.sun.star.frame.ModuleManager) is
+    asked for the type of the passed model, and all open documents with the
+    same type will be locked or unlocked.
+    
+    @param rxModel
+        A document model determining the type of the documents to be locked or
+        unlocked.
+        
+    @param bLockControllers
+        Passing true will lock all controllers, passing false will unlock them.
+ */
+void lockControllersOfAllDocuments(
+    const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel,
+    sal_Bool bLockControllers );
+
+// ============================================================================
+
+/** Enables or disables the container windows of all controllers of all
+    documents that have the same type as the specified document.
+
+    First, the global module manager (com.sun.star.frame.ModuleManager) is
+    asked for the type of the passed model, and the container windows of all
+    open documents with the same type will be enabled or disabled.
+
+    @param rxModel
+        A document model determining the type of the documents to be enabled or
+        disabled.
+
+    @param bEnableWindows
+        Passing true will enable all container windows of all controllers,
+        passing false will disable them.
+ */
+void enableContainerWindowsOfAllDocuments(
+    const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel,
+    sal_Bool bEnableWindows );
+
+// ============================================================================
+
+} // namespace vba
+} // namespace basic
+
+#endif

basic/prj/build.lst

-sb	basic	:    l10n offuh oovbaapi svtools xmlscript framework salhelper LIBXSLT:libxslt NULL
+sb	basic	:    L10N:l10n offuh oovbaapi svtools xmlscript framework salhelper LIBXSLT:libxslt NULL
 sb	basic									usr1	-	all	sb_mkout NULL
 sb	basic\inc								nmake	-	all	sb_inc NULL
 sb	basic\source\app						nmake	-	all	sb_app sb_class sb_inc NULL

basic/source/basmgr/makefile.mk

 
 SLOFILES= \
         $(SLO)$/basmgr.obj \
-        $(SLO)$/basicmanagerrepository.obj
+        $(SLO)$/basicmanagerrepository.obj\
+        $(SLO)$/vbahelper.obj
 
 # --- Targets -------------------------------------------------------------
 

basic/source/basmgr/vbahelper.cxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basic.hxx"
+
+#include "basic/vbahelper.hxx"
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <comphelper/processfactory.hxx>
+
+namespace basic {
+namespace vba {
+
+using namespace ::com::sun::star;
+
+// ============================================================================
+
+namespace {
+
+/** Creates the global module manager needed to identify the type of documents.
+ */
+uno::Reference< frame::XModuleManager > lclCreateModuleManager()
+{
+    uno::Reference< frame::XModuleManager > xModuleManager;
+    try
+    {
+        uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+        xModuleManager.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ), uno::UNO_QUERY );
+    }
+    catch( uno::Exception& )
+    {
+    }
+    OSL_ENSURE( xModuleManager.is(), "::basic::vba::lclCreateModuleManager - cannot create module manager" );
+    return xModuleManager;
+}
+
+// ----------------------------------------------------------------------------
+
+/** Returns the document service name of the specified document.
+ */
+::rtl::OUString lclIdentifyDocument( const uno::Reference< frame::XModuleManager >& rxModuleManager, const uno::Reference< frame::XModel >& rxModel )
+{
+    ::rtl::OUString aServiceName;
+    if( rxModuleManager.is() )
+    {
+        try
+        {
+            aServiceName = rxModuleManager->identify( rxModel );
+        }
+        catch( uno::Exception& )
+        {
+        }
+        OSL_ENSURE( aServiceName.getLength() > 0, "::basic::vba::lclIdentifyDocument - cannot identify document" );
+    }
+    return aServiceName;
+}
+
+// ----------------------------------------------------------------------------
+
+/** Returns an enumeration of all open documents.
+ */
+uno::Reference< container::XEnumeration > lclCreateDocumentEnumeration()
+{
+    uno::Reference< container::XEnumeration > xEnumeration;
+    try
+    {
+        uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+        uno::Reference< frame::XDesktop > xDesktop( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ), uno::UNO_QUERY_THROW );
+        uno::Reference< container::XEnumerationAccess > xComponentsEA( xDesktop->getComponents(), uno::UNO_SET_THROW );
+        xEnumeration = xComponentsEA->createEnumeration();
+
+    }
+    catch( uno::Exception& )
+    {
+    }
+    OSL_ENSURE( xEnumeration.is(), "::basic::vba::lclCreateDocumentEnumeration - cannot create enumeration of all documents" );
+    return xEnumeration;
+}
+
+// ----------------------------------------------------------------------------
+
+/** Locks or unlocks the controllers of the specified document model.
+ */
+void lclLockControllers( const uno::Reference< frame::XModel >& rxModel, sal_Bool bLockControllers )
+{
+    if( rxModel.is() ) try
+    {
+        if( bLockControllers )
+            rxModel->lockControllers();
+        else
+            rxModel->unlockControllers();
+    }
+    catch( uno::Exception& )
+    {
+    }
+}
+
+// ----------------------------------------------------------------------------
+
+/** Enables or disables the container windows of all controllers of the
+    specified document model.
+ */
+void lclEnableContainerWindows( const uno::Reference< frame::XModel >& rxModel, sal_Bool bEnableWindows )
+{
+    try
+    {
+        uno::Reference< frame::XModel2 > xModel2( rxModel, uno::UNO_QUERY_THROW );
+        uno::Reference< container::XEnumeration > xControllersEnum( xModel2->getControllers(), uno::UNO_SET_THROW );
+        // iterate over all controllers
+        while( xControllersEnum->hasMoreElements() )
+        {
+            try
+            {
+                uno::Reference< frame::XController > xController( xControllersEnum->nextElement(), uno::UNO_QUERY_THROW );
+                uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
+                uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
+                xWindow->setEnable( bEnableWindows );
+            }
+            catch( uno::Exception& )
+            {
+            }
+        }
+    }
+    catch( uno::Exception& )
+    {
+    }
+}
+
+// ----------------------------------------------------------------------------
+
+typedef void (*ModifyDocumentFunc)( const uno::Reference< frame::XModel >&, sal_Bool );
+
+/** Implementation iterating over all documents that have the same type as the
+    specified model, and calling the passed functor.
+ */
+void lclIterateDocuments( ModifyDocumentFunc pModifyDocumentFunc, const uno::Reference< frame::XModel >& rxModel, sal_Bool bModificator )
+{
+    uno::Reference< frame::XModuleManager > xModuleManager = lclCreateModuleManager();
+    uno::Reference< container::XEnumeration > xDocumentsEnum = lclCreateDocumentEnumeration();
+    ::rtl::OUString aIdentifier = lclIdentifyDocument( xModuleManager, rxModel );
+    if( xModuleManager.is() && xDocumentsEnum.is() && (aIdentifier.getLength() > 0) )
+    {
+        // iterate over all open documents
+        while( xDocumentsEnum->hasMoreElements() )
+        {
+            try
+            {
+                uno::Reference< frame::XModel > xCurrModel( xDocumentsEnum->nextElement(), uno::UNO_QUERY_THROW );
+                ::rtl::OUString aCurrIdentifier = lclIdentifyDocument( xModuleManager, xCurrModel );
+                if( aCurrIdentifier == aIdentifier )
+                    pModifyDocumentFunc( xCurrModel, bModificator );
+            }
+            catch( uno::Exception& )
+            {
+            }
+        }
+    }
+    else
+    {
+        // no module manager, no documents enumeration, no identifier -> at least process the passed document
+        pModifyDocumentFunc( rxModel, bModificator );
+    }
+}
+
+} // namespace
+
+// ============================================================================
+
+void lockControllersOfAllDocuments( const uno::Reference< frame::XModel >& rxModel, sal_Bool bLockControllers )
+{
+    lclIterateDocuments( &lclLockControllers, rxModel, bLockControllers );
+}
+
+// ============================================================================
+
+void enableContainerWindowsOfAllDocuments( const uno::Reference< frame::XModel >& rxModel, sal_Bool bEnableWindows )
+{
+    lclIterateDocuments( &lclEnableContainerWindows, rxModel, bEnableWindows );
+}
+
+// ============================================================================
+
+} // namespace vba
+} // namespace basic

basic/source/classes/sb.cxx

 #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>
 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 )
 	return pRetObj;
 }
 
+
 TYPEINIT1(SbClassModuleObject,SbModule)
 
 SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
 		}
 	}
 
-	// Copy SbIfaceMapperMethod in a second step to ensure that 
+	// Copy SbIfaceMapperMethod in a second step to ensure that
 	// the corresponding base methods have already been copied
 	for( i = 0 ; i < nMethodCount ; i++ )
 	{
 				DBG_ERROR( "Found no ImplMethod copy" );
 				continue;
 			}
-			SbIfaceMapperMethod* pNewIfaceMethod = 
+			SbIfaceMapperMethod* pNewIfaceMethod =
 				new SbIfaceMapperMethod( pIfaceMethod->GetName(), pImplMethodCopy );
 			pMethods->PutDirect( pNewIfaceMethod, i );
 		}
 
 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 
+	// Must be deleted by base class dtor because this data
 	// is not owned by the SbClassModuleObject object
 	pImage = NULL;
 	pBreaks = NULL;
 
 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 );
 }
 
 
 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;
 }
 	return pMod;
 }
 
-typedef std::vector< StarBASIC* > DocBasicVector;
-static DocBasicVector GaDocBasics;
-
 StarBASIC::StarBASIC( StarBASIC* p, sal_Bool bIsDocBasic  )
 	: SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic )
 {
 	bQuit = sal_False;
 
 	if( bDocBasic )
-		GaDocBasics.push_back( this );
+        lclInsertDocBasicItem( *this );
 }
 
 // #51727 Override SetModified so that the modified state
 
 StarBASIC::~StarBASIC()
 {
+	// Needs to be first action as it can trigger events
+	disposeComVariablesForBasic( this );
+
 	if( !--GetSbData()->nInst )
 	{
 		RemoveFactory( pSBFAC );
 	{
 	    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 )
     }
 
     clearUnoMethodsForBasic( this );
-	disposeComVariablesForBasic( this );
 }