summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-08-07 17:37:11 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-08-13 13:26:15 +0200
commitb3edf85e0fe6ca03dc26e1bf531be82193bc9627 (patch)
tree62887e38b2f0b06ca8e74fffd126560b5b0c8049 /sc
parentc78dd0a726b32d922a0d75a26a51d4c30612368c (diff)
warn on load when a document binds an event to a macro
a) treat shared/Scripts equivalently to document scripts This doesn't automatically warn/block running those scripts when used in a freshly loaded document on its own however because DocumentMacroMode::checkMacrosOnLoading will see at... if ( m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() ) that the document contains no macros and flip the allow macros flag to true so that potentially new uses of macros added by the user during the edit are allowed to run b) so, add an additional flag to indicate existence of use of macros in a document c) for odf import, set it when a script:event-listener tag is encountered d) for html import when registerScriptEvents or SwFormatINetFormat::SetMacroTable is called e) for doc import when Read_F_Macro or StoreMacroCmds is called as well for good measure f) for xls import when registerScriptEvent or ScMacroInfo::SetMacro is called g) for oox import when VbaProject::attachMacros is called Change-Id: Ic1203d8ec7dfc217aa217135033ae9db2888e19b Reviewed-on: https://gerrit.libreoffice.org/77131 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/excel/xiescher.cxx36
-rw-r--r--sc/source/filter/inc/xiescher.hxx11
-rw-r--r--sc/source/ui/vba/vbasheetobject.cxx13
-rw-r--r--sc/source/ui/vba/vbasheetobject.hxx4
4 files changed, 56 insertions, 8 deletions
diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx
index 0335bc4928a1..610c6983cc4a 100644
--- a/sc/source/filter/excel/xiescher.cxx
+++ b/sc/source/filter/excel/xiescher.cxx
@@ -49,6 +49,7 @@
#include <vcl/window.hxx>
#include <vcl/wmf.hxx>
#include <comphelper/classids.hxx>
+#include <comphelper/documentinfo.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
@@ -174,7 +175,8 @@ XclImpDrawObjBase::XclImpDrawObjBase( const XclImpRoot& rRoot ) :
mbSimpleMacro( true ),
mbProcessSdr( true ),
mbInsertSdr( true ),
- mbCustomDff( false )
+ mbCustomDff( false ),
+ mbNotifyMacroEventRead( false )
{
}
@@ -510,7 +512,18 @@ SdrObjectUniquePtr XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffC
return xSdrObj;
}
-void XclImpDrawObjBase::PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
+void XclImpDrawObjBase::NotifyMacroEventRead()
+{
+ if (mbNotifyMacroEventRead)
+ return;
+ SfxObjectShell* pDocShell = GetDocShell();
+ if (!pDocShell)
+ return;
+ comphelper::DocumentInfo::notifyMacroEventRead(pDocShell->GetModel());
+ mbNotifyMacroEventRead = true;
+}
+
+void XclImpDrawObjBase::PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj )
{
// default: front layer, derived classes may have to set other layer in DoPreProcessSdrObj()
rSdrObj.NbcSetLayer( SC_LAYER_FRONT );
@@ -537,7 +550,10 @@ void XclImpDrawObjBase::PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrOb
{
if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( &rSdrObj, true ) )
{
- pInfo->SetMacro( XclTools::GetSbMacroUrl( maMacroName, GetDocShell() ) );
+ OUString sMacro = XclTools::GetSbMacroUrl(maMacroName, GetDocShell());
+ if (!sMacro.isEmpty())
+ NotifyMacroEventRead();
+ pInfo->SetMacro(sMacro);
pInfo->SetHlink( maHyperlink );
}
}
@@ -3285,7 +3301,8 @@ static const OUStringLiteral gaStdFormName( "Standard" ); /// Standard name of c
XclImpDffConverter::XclImpDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm ) :
XclImpSimpleDffConverter( rRoot, rDffStrm ),
oox::ole::MSConvertOCXControls( rRoot.GetDocShell()->GetModel() ),
- mnOleImpFlags( 0 )
+ mnOleImpFlags( 0 ),
+ mbNotifyMacroEventRead(false)
{
const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
if( rFilterOpt.IsMathType2Math() )
@@ -3342,7 +3359,7 @@ void XclImpDffConverter::InitializeDrawing( XclImpDrawing& rDrawing, SdrModel& r
SetModel( &xConvData->mrSdrModel, 1440 );
}
-void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj )
+void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, XclImpDrawObjBase& rDrawObj )
{
if( rDrawObj.IsProcessSdrObj() )
{
@@ -3391,6 +3408,14 @@ void XclImpDffConverter::FinalizeDrawing()
SetModel( &maDataStack.back()->mrSdrModel, 1440 );
}
+void XclImpDffConverter::NotifyMacroEventRead()
+{
+ if (mbNotifyMacroEventRead)
+ return;
+ comphelper::DocumentInfo::notifyMacroEventRead(mxModel);
+ mbNotifyMacroEventRead = true;
+}
+
SdrObjectUniquePtr XclImpDffConverter::CreateSdrObject( const XclImpTbxObjBase& rTbxObj, const tools::Rectangle& rAnchorRect )
{
SdrObjectUniquePtr xSdrObj;
@@ -3413,6 +3438,7 @@ SdrObjectUniquePtr XclImpDffConverter::CreateSdrObject( const XclImpTbxObjBase&
ScriptEventDescriptor aDescriptor;
if( (rConvData.mnLastCtrlIndex >= 0) && rTbxObj.FillMacroDescriptor( aDescriptor ) )
{
+ NotifyMacroEventRead();
Reference< XEventAttacherManager > xEventMgr( rConvData.mxCtrlForm, UNO_QUERY_THROW );
xEventMgr->registerScriptEvent( rConvData.mnLastCtrlIndex, aDescriptor );
}
diff --git a/sc/source/filter/inc/xiescher.hxx b/sc/source/filter/inc/xiescher.hxx
index f9e8d007724e..37f457920d57 100644
--- a/sc/source/filter/inc/xiescher.hxx
+++ b/sc/source/filter/inc/xiescher.hxx
@@ -125,7 +125,7 @@ public:
SdrObjectUniquePtr CreateSdrObject( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect, bool bIsDff ) const;
/** Additional processing for the passed SdrObject before insertion into
the drawing page (calls virtual DoPreProcessSdrObj() function). */
- void PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
+ void PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj );
/** Additional processing for the passed SdrObject after insertion into the
drawing page (calls virtual DoPostProcessSdrObj() function). */
void PostProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
@@ -172,6 +172,9 @@ protected:
virtual void DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
/** Derived classes may perform additional processing for the passed SdrObject after insertion. */
virtual void DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const;
+
+ /** Notify that the document contains a macro event handler */
+ void NotifyMacroEventRead();
private:
/** Reads the contents of a BIFF3 OBJ record. */
void ImplReadObj3( XclImpStream& rStrm );
@@ -202,6 +205,7 @@ private:
bool mbProcessSdr; /// true = Object is valid, do processing and insertion.
bool mbInsertSdr; /// true = Insert the SdrObject into draw page.
bool mbCustomDff; /// true = Recreate SdrObject in DFF import.
+ bool mbNotifyMacroEventRead; /// true == If we have already seen a macro event
};
class XclImpDrawObjVector
@@ -928,7 +932,7 @@ public:
/** Initially called before the objects of the passed drawing manager are converted. */
void InitializeDrawing( XclImpDrawing& rDrawing, SdrModel& rSdrModel, SdrPage& rSdrPage );
/** Processes BIFF5 drawing objects without DFF data, inserts into the passed object list. */
- void ProcessObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj );
+ void ProcessObject( SdrObjList& rObjList, XclImpDrawObjBase& rDrawObj );
/** Processes all objects in the passed list. */
void ProcessDrawing( const XclImpDrawObjVector& rDrawObjs );
/** Processes a drawing container in the passed DFF stream, converts all objects. */
@@ -1017,6 +1021,8 @@ private:
void InsertSdrObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj, SdrObject* pSdrObj );
/** Initializes the mxCtrlForm referring to the standard controls form. */
void InitControlForm();
+ /** Notify that this document contains a macro event handler */
+ void NotifyMacroEventRead();
private:
typedef std::shared_ptr< ScfProgressBar > ScfProgressBarRef;
@@ -1028,6 +1034,7 @@ private:
XclImpDffConvDataStack maDataStack; /// Stack for registered drawing managers.
sal_uInt32 mnOleImpFlags; /// Application OLE import settings.
sal_Int32 mnDefTextMargin; /// Default margin in text boxes.
+ bool mbNotifyMacroEventRead; /// If we have already seen a macro event
};
// Drawing manager ============================================================
diff --git a/sc/source/ui/vba/vbasheetobject.cxx b/sc/source/ui/vba/vbasheetobject.cxx
index 2df219af7874..469e67027d6c 100644
--- a/sc/source/ui/vba/vbasheetobject.cxx
+++ b/sc/source/ui/vba/vbasheetobject.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp>
#include <com/sun/star/style/VerticalAlignment.hpp>
+#include <comphelper/documentinfo.hxx>
#include <ooo/vba/excel/Constants.hpp>
#include <ooo/vba/excel/XlOrientation.hpp>
#include <ooo/vba/excel/XlPlacement.hpp>
@@ -298,7 +299,8 @@ ScVbaControlObjectBase::ScVbaControlObjectBase(
const uno::Reference< drawing::XControlShape >& rxControlShape ) :
ScVbaControlObject_BASE( rxParent, rxContext, rxModel, uno::Reference< drawing::XShape >( rxControlShape, uno::UNO_QUERY_THROW ) ),
mxFormIC( rxFormIC, uno::UNO_SET_THROW ),
- mxControlProps( rxControlShape->getControl(), uno::UNO_QUERY_THROW )
+ mxControlProps( rxControlShape->getControl(), uno::UNO_QUERY_THROW ),
+ mbNotifyMacroEventRead(false)
{
}
@@ -334,6 +336,14 @@ OUString SAL_CALL ScVbaControlObjectBase::getOnAction()
return OUString();
}
+void ScVbaControlObjectBase::NotifyMacroEventRead()
+{
+ if (mbNotifyMacroEventRead)
+ return;
+ comphelper::DocumentInfo::notifyMacroEventRead(mxModel);
+ mbNotifyMacroEventRead = true;
+}
+
void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName )
{
uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW );
@@ -353,6 +363,7 @@ void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName )
aDescriptor.EventMethod = gaEventMethod;
aDescriptor.ScriptType = "Script";
aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.msResolvedMacro );
+ NotifyMacroEventRead();
xEventMgr->registerScriptEvent( nIndex, aDescriptor );
}
}
diff --git a/sc/source/ui/vba/vbasheetobject.hxx b/sc/source/ui/vba/vbasheetobject.hxx
index e53418ab0481..94d88fbb416b 100644
--- a/sc/source/ui/vba/vbasheetobject.hxx
+++ b/sc/source/ui/vba/vbasheetobject.hxx
@@ -153,6 +153,9 @@ public:
virtual sal_Bool SAL_CALL getAutoSize() override;
virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) override;
+ /// Notify that the document contains a macro event handler
+ void NotifyMacroEventRead();
+
protected:
/// @throws css::uno::RuntimeException
sal_Int32 getModelIndexInForm() const;
@@ -160,6 +163,7 @@ protected:
protected:
css::uno::Reference< css::container::XIndexContainer > mxFormIC;
css::uno::Reference< css::beans::XPropertySet > mxControlProps;
+ bool mbNotifyMacroEventRead;
};
typedef ::cppu::ImplInheritanceHelper< ScVbaControlObjectBase, ov::excel::XButton > ScVbaButton_BASE;