diff options
Diffstat (limited to 'sfx2/source/doc/docmacromode.cxx')
-rw-r--r-- | sfx2/source/doc/docmacromode.cxx | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index 613d90cb17..238618ed97 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -38,6 +38,8 @@ #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp> #include <com/sun/star/task/InteractionClassification.hpp> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> +#include <com/sun/star/script/XLibraryQueryExecutable.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> /** === end UNO includes === **/ #include <comphelper/componentcontext.hxx> @@ -73,8 +75,11 @@ namespace sfx2 using ::com::sun::star::document::XEmbeddedScripts; using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::script::XLibraryContainer; + using ::com::sun::star::script::XLibraryQueryExecutable; + using ::com::sun::star::script::vba::XVBACompatibility; using ::com::sun::star::container::XNameAccess; using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_QUERY; /** === end UNO using === **/ namespace MacroExecMode = ::com::sun::star::document::MacroExecMode; @@ -336,6 +341,8 @@ namespace sfx2 if ( xScripts.is() ) xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW ); + Reference< XVBACompatibility > xDocVBAMode( xContainer, UNO_QUERY ); + sal_Bool bIsVBAMode = ( xDocVBAMode.is() && xDocVBAMode->getVBACompatibilityMode() ); if ( xContainer.is() ) { // a library container exists; check if it's empty @@ -350,23 +357,46 @@ namespace sfx2 Sequence< ::rtl::OUString > aElements = xContainer->getElementNames(); if ( aElements.getLength() ) { - if ( aElements.getLength() > 1 || !aElements[0].equals( aStdLibName ) ) + // old check, if more than 1 library or the first library isn't the expected 'Standard' + // trigger the security 'nag' dialog + if ( !bIsVBAMode && ( aElements.getLength() > 1 || !aElements[0].equals( aStdLibName ) ) ) bHasMacroLib = sal_True; - else + else { - // usually a "Standard" library is always present (design) - // for this reason we must check if it's empty - // - // Note: Since #i73229#, this is not true anymore. There's no default - // "Standard" lib anymore. Wouldn't it be time to get completely - // rid of the "Standard" thingie - this shouldn't be necessary - // anymore, should it? - // 2007-01-25 / frank.schoenheit@sun.com - Reference < XNameAccess > xLib; - Any aAny = xContainer->getByName( aStdLibName ); - aAny >>= xLib; + // other wise just check all libraries for executeable code + Reference< XLibraryQueryExecutable > xLib( xContainer, UNO_QUERY ); if ( xLib.is() ) - bHasMacroLib = xLib->hasElements(); + { + Sequence< ::rtl::OUString > aElements = xContainer->getElementNames(); + sal_Int32 nElementCount = aElements.getLength(); + const ::rtl::OUString* pElementName = aElements.getConstArray(); + for ( sal_Int32 index = 0; index < nElementCount; index++ ) + { + bHasMacroLib = xLib->HasExecutableCode( pElementName[index] ); + if ( bHasMacroLib ) + break; + } + } + } + } + } + } + if ( bIsVBAMode && !bHasMacroLib && xScripts.is() ) + { + Reference< XLibraryContainer > xDlgContainer( xScripts->getDialogLibraries(), UNO_QUERY ); + if ( xDlgContainer.is() && xDlgContainer->hasElements() ) + { + Sequence< ::rtl::OUString > aElements = xDlgContainer->getElementNames(); + sal_Int32 nElementCount = aElements.getLength(); + const ::rtl::OUString* pElementName = aElements.getConstArray(); + for ( sal_Int32 index = 0; index < nElementCount; index++ ) + { + Reference< XNameAccess > xNameAccess; + xDlgContainer->getByName( pElementName[index] ) >>= xNameAccess; + if ( xNameAccess.is() && xNameAccess->hasElements() ) + { + bHasMacroLib = sal_True; + break; } } } |