summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-03-01 17:07:06 +0000
committerNoel Power <noel.power@suse.com>2013-03-01 17:12:29 +0000
commitec583253c3d761847c93a77fa10c065fc334fab9 (patch)
tree8c93913029ade491470e75389c8426fb87795ed9 /sfx2
parent58c30a3545a5725d704eabd79071db02f1f2cb23 (diff)
raise warning when saving macro laden doc as a macro-free format bnc#791777
Change-Id: Ic947ceef71c86e31fbf0bce74b064aaf91f47178
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/inc/sfx2/docmacromode.hxx1
-rw-r--r--sfx2/source/doc/docmacromode.cxx29
-rw-r--r--sfx2/source/doc/guisaveas.cxx55
3 files changed, 78 insertions, 7 deletions
diff --git a/sfx2/inc/sfx2/docmacromode.hxx b/sfx2/inc/sfx2/docmacromode.hxx
index 86bad086ac7b..1b5857f8ae43 100644
--- a/sfx2/inc/sfx2/docmacromode.hxx
+++ b/sfx2/inc/sfx2/docmacromode.hxx
@@ -287,6 +287,7 @@ namespace sfx2
static sal_Bool
storageHasMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage );
+ static sal_Bool containerHasBasicMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xContainter );
/** checks the macro execution mode while loading the document.
This must be called when the loading is effectively finished, but before any macro action
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx
index 999ab2076aa5..6f105075b0a4 100644
--- a/sfx2/source/doc/docmacromode.cxx
+++ b/sfx2/source/doc/docmacromode.cxx
@@ -318,17 +318,11 @@ namespace sfx2
}
//--------------------------------------------------------------------
- sal_Bool DocumentMacroMode::hasMacroLibrary() const
+ sal_Bool DocumentMacroMode::containerHasBasicMacros( const Reference< XLibraryContainer >& xContainer )
{
sal_Bool bHasMacroLib = sal_False;
-#ifndef DISABLE_SCRIPTING
try
{
- Reference< XEmbeddedScripts > xScripts( m_pData->m_rDocumentAccess.getEmbeddedDocumentScripts() );
- Reference< XLibraryContainer > xContainer;
- if ( xScripts.is() )
- xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
-
if ( xContainer.is() )
{
// a library container exists; check if it's empty
@@ -368,6 +362,27 @@ namespace sfx2
{
DBG_UNHANDLED_EXCEPTION();
}
+ return bHasMacroLib;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::hasMacroLibrary() const
+ {
+ sal_Bool bHasMacroLib = sal_False;
+#ifndef DISABLE_SCRIPTING
+ try
+ {
+ Reference< XEmbeddedScripts > xScripts( m_pData->m_rDocumentAccess.getEmbeddedDocumentScripts() );
+ Reference< XLibraryContainer > xContainer;
+ if ( xScripts.is() )
+ xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
+ bHasMacroLib = containerHasBasicMacros( xContainer );
+
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
#endif
return bHasMacroLib;
}
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 1b40a74c800b..f94b809f5a8e 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -79,6 +79,13 @@
#include <sfxtypes.hxx>
#include "alienwarn.hxx"
+#include <sfx2/docmacromode.hxx>
+#include <svx/svxerr.hxx>
+#include <comphelper/interaction.hxx>
+#include <com/sun/star/task/ErrorCodeRequest.hpp>
+#include <rtl/ref.hxx>
+#include <framework/interaction.hxx>
+#include <svtools/sfxecode.hxx>
#include "../appl/app.hrc"
// flags that specify requested operation
@@ -707,6 +714,19 @@ sal_Int8 ModelData_Impl::CheckStateForSave()
return nResult;
}
+sal_Bool hasMacros( const uno::Reference< frame::XModel >& xModel )
+{
+ sal_Bool bHasMacros = sal_False;
+ uno::Reference< script::XLibraryContainer > xContainer;
+ uno::Reference< beans::XPropertySet > xProps( xModel, uno::UNO_QUERY );
+ if ( xProps.is() )
+ {
+ xProps->getPropertyValue( "BasicLibraries" ) >>= xContainer;
+ bHasMacros = sfx2::DocumentMacroMode::containerHasBasicMacros( xContainer );
+ }
+ return bHasMacros;
+}
+
sal_Int8 ModelData_Impl::CheckFilter( const ::rtl::OUString& aFilterName )
{
::comphelper::SequenceAsHashMap aFiltPropsHM;
@@ -754,6 +774,41 @@ sal_Int8 ModelData_Impl::CheckFilter( const ::rtl::OUString& aFilterName )
::rtl::OUString() );
if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
{
+ // is it possible to get these names from somewhere and not just
+ // hardcode them?
+ OUString sXLSXFilter("Calc MS Excel 2007 XML");
+ OUString sOtherXLSXFilter("Calc Office Open XML");
+ bool bHasMacros = hasMacros( GetModel() );
+ if ( bHasMacros && ( aFilterName == sXLSXFilter || aFilterName == sOtherXLSXFilter ) )
+ {
+ uno::Reference< task::XInteractionHandler > xHandler;
+ GetMediaDescr()[ OUString( "InteractionHandler" ) ] >>= xHandler;
+ bool bResult = false;
+ if ( xHandler.is() )
+ {
+ try
+ {
+ task::ErrorCodeRequest aErrorCode;
+ aErrorCode.ErrCode = ERRCODE_SFX_VBASIC_CANTSAVE_STORAGE;
+
+ uno::Any aRequest = uno::makeAny( aErrorCode );
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
+
+ ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
+ aContinuations[ 0 ] = pApprove.get();
+
+ ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
+ aContinuations[ 1 ] = pAbort.get();
+ xHandler->handle(::framework::InteractionRequest::CreateRequest (aRequest,aContinuations));
+ bResult = pApprove->wasSelected();
+ }
+ catch( const uno::Exception& )
+ {
+ }
+ if ( !bResult )
+ return STATUS_SAVEAS;
+ }
+ }
if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, sal_True ) )
return STATUS_SAVEAS_STANDARDNAME;
}