diff options
Diffstat (limited to 'vbahelper/source/vbahelper/vbadocumentsbase.cxx')
-rw-r--r-- | vbahelper/source/vbahelper/vbadocumentsbase.cxx | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx index f2b70ab231c7..b65a58542b92 100644 --- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx @@ -24,7 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include <vbahelper/vbadocumentsbase.hxx> + +#include "vbahelper/vbadocumentsbase.hxx" + #include <comphelper/mediadescriptor.hxx> #include <comphelper/processfactory.hxx> #include <cppuhelper/implbase1.hxx> @@ -49,10 +51,12 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <sfx2/objsh.hxx> #include <tools/urlobj.hxx> -#include <vbahelper/vbahelper.hxx> #include <hash_map> #include <osl/file.hxx> +#include "vbahelper/vbahelper.hxx" +#include "vbahelper/vbaapplicationbase.hxx" + using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -213,8 +217,39 @@ VbaDocumentsBase::VbaDocumentsBase( const uno::Reference< XHelperInterface >& xP { } +namespace { + +void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, sal_Bool bScreenUpdating, sal_Bool bInteractive ) +{ + if( !bScreenUpdating ) try + { + uno::Reference< frame::XModel >( rxComponent, uno::UNO_QUERY_THROW )->lockControllers(); + } + catch( uno::Exception& ) + { + } + + if( !bInteractive ) try + { + uno::Reference< frame::XModel > xModel( rxComponent, uno::UNO_QUERY_THROW ); + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow >( xFrame->getContainerWindow(), uno::UNO_SET_THROW )->setEnable( sal_False ); + } + catch( uno::Exception& ) + { + } +} + +} // namespace + uno::Any VbaDocumentsBase::createDocument() throw (uno::RuntimeException) { + // #163808# determine state of Application.ScreenUpdating and Application.Interactive symbols (before new document is opened) + uno::Reference< XApplicationBase > xApplication( Application(), uno::UNO_QUERY ); + sal_Bool bScreenUpdating = !xApplication.is() || xApplication->getScreenUpdating(); + sal_Bool bInteractive = !xApplication.is() || xApplication->getInteractive(); + uno::Reference< lang::XMultiComponentFactory > xSMgr( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); @@ -240,6 +275,10 @@ uno::Any VbaDocumentsBase::createDocument() throw (uno::RuntimeException) sURL , rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") ), 0, aMediaDesc.getAsConstPropertyValueList() ); + + // #163808# lock document controllers and container window if specified by application + lclSetupComponent( xComponent, bScreenUpdating, bInteractive ); + return uno::makeAny( xComponent ); } @@ -259,6 +298,11 @@ void VbaDocumentsBase::closeDocuments() throw (uno::RuntimeException) // #TODO# #FIXME# can any of the unused params below be used? uno::Any VbaDocumentsBase::openDocument( const rtl::OUString& rFileName, const uno::Any& ReadOnly, const uno::Sequence< beans::PropertyValue >& rProps ) throw (uno::RuntimeException) { + // #163808# determine state of Application.ScreenUpdating and Application.Interactive symbols (before new document is opened) + uno::Reference< XApplicationBase > xApplication( Application(), uno::UNO_QUERY ); + sal_Bool bScreenUpdating = !xApplication.is() || xApplication->getScreenUpdating(); + sal_Bool bInteractive = !xApplication.is() || xApplication->getInteractive(); + // we need to detect if this is a URL, if not then assume its a file path rtl::OUString aURL; INetURLObject aObj; @@ -282,19 +326,16 @@ uno::Any VbaDocumentsBase::openDocument( const rtl::OUString& rFileName, const u uno::Sequence< beans::PropertyValue > sProps( rProps ); sProps.realloc( sProps.getLength() + 1 ); sProps[ sProps.getLength() - 1 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode") ); - sProps[ sProps.getLength() - 1 ].Value <<= uno::makeAny( document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN ); - - sal_Int32 nIndex = sProps.getLength() - 1; + sProps[ sProps.getLength() - 1 ].Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN; if ( ReadOnly.hasValue() ) { sal_Bool bIsReadOnly = sal_False; ReadOnly >>= bIsReadOnly; if ( bIsReadOnly ) { - static const rtl::OUString sReadOnly( RTL_CONSTASCII_USTRINGPARAM("ReadOnly") ); sProps.realloc( sProps.getLength() + 1 ); - sProps[ nIndex ].Name = sReadOnly; - sProps[ nIndex++ ].Value = uno::makeAny( (sal_Bool)sal_True ); + sProps[ sProps.getLength() - 1 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ReadOnly") ); + sProps[ sProps.getLength() - 1 ].Value <<= true; } } @@ -302,6 +343,10 @@ uno::Any VbaDocumentsBase::openDocument( const rtl::OUString& rFileName, const u rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_default") ), frame::FrameSearchFlag::CREATE, sProps); + + // #163808# lock document controllers and container window if specified by application + lclSetupComponent( xComponent, bScreenUpdating, bInteractive ); + return uno::makeAny( xComponent ); } |