Commits

Anonymous committed fe59354

mib19: #163689# On deletion of doc basic clear dependencies in other basic instances

  • Participants
  • Parent commits 656e3ae

Comments (0)

Files changed (4)

File basic/inc/basic/sbmod.hxx

 	SbModuleImpl*	mpSbModuleImpl;		// Impl data
     std::vector< String > mModuleVariableNames;
 
+	void 			implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic );
+
 protected:
     com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper;
     ::rtl::OUString     aOUSource;
 	USHORT 			Run( SbMethod* );
 	void			RunInit();
 	void 			ClearPrivateVars();
+	void 			ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic );
 	void			GlobalRunInit( BOOL bBasicStart );	// for all modules
 	void			GlobalRunDeInit( void );
 	const BYTE* 	FindNextStmnt( const BYTE*, USHORT&, USHORT& ) const;

File basic/inc/basic/sbstar.hxx

 	SbxObjectRef pVBAGlobals; 
 	SbxObject* getVBAGlobals( );
 
+	void implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic );
+
 protected:
 	BOOL 			CError( SbError, const String&, xub_StrLen, xub_StrLen, xub_StrLen );
 private:

File basic/source/classes/sb.cxx

 	return pMod;
 }
 
+typedef std::vector< StarBASIC* > DocBasicVector;
+static DocBasicVector GaDocBasics;
+
 StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic  )
 	: SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic )
 {
 	SetFlag( SBX_GBLSEARCH );
 	pVBAGlobals = NULL;
 	bQuit = FALSE;
+
+	if( bDocBasic )
+		GaDocBasics.push_back( this );
 }
 
 // #51727 Override SetModified so that the modified state
 	}
 #endif
 	}
+	else if( bDocBasic )
+	{
+	    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 );
+		}
+
+		SbxBase::ResetError();
+		if( eOld != SbxERR_OK )
+			SbxBase::SetError( eOld );
+	}
 
     // #100326 Set Parent NULL in registered listeners
     if( xUnoListeners.Is() )
 	::operator delete( p );
 }
 
+void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
+{
+	if( this != pDeletedBasic )
+	{
+		for( USHORT i = 0; i < pModules->Count(); i++ )
+		{
+			SbModule* p = (SbModule*)pModules->Get( i );
+			p->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
+		}
+	}
+
+	for( USHORT 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

File basic/source/classes/sbxmod.cxx

 	}
 }
 
+void SbModule::implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic )
+{
+	if( pVar->SbxValue::GetType() != SbxOBJECT || pVar->ISA( SbProcedureProperty ) )
+		return;
+
+	SbxObject* pObj = PTR_CAST(SbxObject,pVar->GetObject());
+	if( pObj != NULL )
+	{
+		SbxObject* p = pObj;
+
+		SbModule* pMod = PTR_CAST( SbModule, p );
+		if( pMod != NULL )
+			pMod->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
+
+		while( (p = p->GetParent()) != NULL )
+		{
+			StarBASIC* pBasic = PTR_CAST( StarBASIC, p );
+			if( pBasic != NULL && pBasic == pDeletedBasic )
+			{
+				pVar->SbxValue::Clear();
+				break;
+			}
+		}
+	}
+}
+
+void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic )
+{
+	(void)pDeletedBasic;
+
+	for( USHORT i = 0 ; i < pProps->Count() ; i++ )
+	{
+		SbProperty* p = PTR_CAST(SbProperty,pProps->Get( i ) );
+		if( p )
+		{
+			if( p->GetType() & SbxARRAY )
+			{
+				SbxArray* pArray = PTR_CAST(SbxArray,p->GetObject());
+				if( pArray )
+				{
+					for( USHORT j = 0 ; j < pArray->Count() ; j++ )
+					{
+						SbxVariable* pVar = PTR_CAST(SbxVariable,pArray->Get( j ));
+						implClearIfVarDependsOnDeletedBasic( pVar, pDeletedBasic );
+					}
+				}
+			}
+			else
+			{
+				implClearIfVarDependsOnDeletedBasic( p, pDeletedBasic );
+			}
+		}
+	}
+}
+
 // Zunaechst in dieses Modul, um 358-faehig zu bleiben
 // (Branch in sb.cxx vermeiden)
 void StarBASIC::ClearAllModuleVars( void )
 				}			
 			}		
 		}
-    	
-    	mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ) );
+
+		mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ) );
 #endif
     }
 	//liuchen 2009-7-21
 {
     try
     {
-
         String aHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
         SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); 
         if ( m_xModel.is() && pGlobs )