summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/guisaveas.cxx
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-04-03 10:24:49 +0100
commit861b9d44d1ad956f621a6fa77d61f2baaa65e6e8 (patch)
tree1a22c45ccbbcda3472801f1503363677298feb30 /sfx2/source/doc/guisaveas.cxx
parent8f5c438e42421f31b194ebc00901b0ebe1083898 (diff)
raise warning when saving macro laden doc as a macro-free format bnc#791777
Change-Id: Ic947ceef71c86e31fbf0bce74b064aaf91f47178 (cherry picked from commit ec583253c3d761847c93a77fa10c065fc334fab9)
Diffstat (limited to 'sfx2/source/doc/guisaveas.cxx')
-rw-r--r--sfx2/source/doc/guisaveas.cxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index c6af31615da8..6748973d22f7 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
@@ -706,6 +713,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;
@@ -753,6 +773,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;
}