diff options
Diffstat (limited to 'sfx2/source/doc/objxtor.cxx')
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index a9a75831e2..7398ef4b23 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -134,6 +134,40 @@ DBG_NAME(SfxObjectShell) static WeakReference< XInterface > s_xCurrentComponent; +void lcl_UpdateAppBasicDocVars( const Reference< XInterface >& _rxComponent, bool bClear = false ) +{ + BasicManager* pAppMgr = SFX_APP()->GetBasicManager(); + if ( pAppMgr ) + { + uno::Reference< beans::XPropertySet > xProps( _rxComponent, uno::UNO_QUERY ); + if ( xProps.is() ) + { + try + { + // ThisVBADocObj contains a PropertyValue + // Name is ( the name of the VBA global to insert ) + // Value is the Object to insert. + // ( note: at the moment the Value is actually the model so + // it strictly is not necessary, however we do intend to store + // not the model in basic but a custom object, so we keep this + // level of indirection for future proofing ) + beans::PropertyValue aProp; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisVBADocObj") ) ) >>= aProp; + rtl::OString sTmp( rtl::OUStringToOString( aProp.Name, RTL_TEXTENCODING_UTF8 ) ); + const char* pAscii = sTmp.getStr(); + if ( bClear ) + pAppMgr->SetGlobalUNOConstant( pAscii, uno::makeAny( uno::Reference< uno::XInterface >() ) ); + else + pAppMgr->SetGlobalUNOConstant( pAscii, aProp.Value ); + + } + catch( uno::Exception& e ) + { + } + } + } +} + //========================================================================= @@ -168,6 +202,7 @@ void SAL_CALL SfxModelListener_Impl::disposing( const com::sun::star::lang::Even ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source ) { + lcl_UpdateAppBasicDocVars( SfxObjectShell::GetCurrentComponent(), true ); // remove ThisComponent reference from AppBasic SfxObjectShell::SetCurrentComponent( Reference< XInterface >() ); } @@ -919,7 +954,10 @@ void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComp BasicManager* pAppMgr = SFX_APP()->GetBasicManager(); s_xCurrentComponent = _rxComponent; if ( pAppMgr ) + { + lcl_UpdateAppBasicDocVars( _rxComponent ); pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent ) ); + } #if OSL_DEBUG_LEVEL > 0 const char* pComponentImplName = _rxComponent.get() ? typeid( *_rxComponent.get() ).name() : "void"; |