diff options
-rw-r--r-- | extensions/source/ole/servprov.cxx | 16 | ||||
-rw-r--r-- | oovbaapi/ooo/vba/excel/XApplication.idl | 2 | ||||
-rw-r--r-- | oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl | 2 | ||||
-rw-r--r-- | sc/Library_sc.mk | 6 | ||||
-rw-r--r-- | sc/Library_scd.mk | 6 | ||||
-rw-r--r-- | sc/Library_scfilt.mk | 6 | ||||
-rw-r--r-- | sc/Library_scui.mk | 6 | ||||
-rw-r--r-- | sc/inc/scmod.hxx | 7 | ||||
-rw-r--r-- | sc/source/ui/app/scmod.cxx | 11 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaapplication.cxx | 102 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaapplication.hxx | 23 |
11 files changed, 182 insertions, 5 deletions
diff --git a/extensions/source/ole/servprov.cxx b/extensions/source/ole/servprov.cxx index 2fccd9a59b9f..45e693b20982 100644 --- a/extensions/source/ole/servprov.cxx +++ b/extensions/source/ole/servprov.cxx @@ -54,6 +54,10 @@ DEFINE_GUID(OID_ServiceManager, 0x82154420, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50 // {82154421-0FBF-11d4-8313-005004526AB4} DEFINE_GUID(OID_LibreOfficeWriterApplication, 0x82154421, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4); +// For Calc +// {82154425-0FBF-11d4-8313-005004526AB4} +DEFINE_GUID(OID_LibreOfficeCalcApplication, 0x82154425, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4); + OneInstanceOleWrapper::OneInstanceOleWrapper( const Reference<XMultiServiceFactory>& smgr, std::function<const Reference<XInterface>()> xInstFunction ) : m_refCount(0) @@ -488,6 +492,18 @@ OleServer::OleServer( const Reference<XMultiServiceFactory>& smgr): return xApplication; }, &OID_LibreOfficeWriterApplication ); + + (void) provideInstance( [&] + { + // Ditto for sc + static const Reference<XInterface> xCalcGlobals = m_smgr->createInstance("ooo.vba.excel.Globals"); + const Reference<ooo::vba::XHelperInterface> xHelperInterface(xCalcGlobals, UNO_QUERY); + Any aApplication = xHelperInterface->Application(); + Reference<XInterface> xApplication; + aApplication >>= xApplication; + return xApplication; + }, + &OID_LibreOfficeCalcApplication ); } OleServer::~OleServer() diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index e315b27ddaf3..ceceaf777d97 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -30,6 +30,8 @@ interface XApplication interface ::com::sun::star::beans::XExactName; interface ::com::sun::star::script::XInvocation; + interface XConnectable; + // interface ::ooo::vba::XHelperInterface; [attribute, readonly] any Selection; diff --git a/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl b/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl index d9b1da42bc4b..9e601c5331d6 100644 --- a/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl +++ b/oovbaapi/ooo/vba/excel/XApplicationOutgoing.idl @@ -25,6 +25,8 @@ module ooo { module vba { module excel { interface XApplicationOutgoing : XInterfaceWithIID { + void WorkbookOpen([in] any Wb); + void WorkbookBeforeClose([in] any Wb, [out] any Cancel); }; }; }; }; diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 00db6e4a44c0..2f4f06b6ea25 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -40,7 +40,11 @@ $(eval $(call gb_Library_use_custom_headers,sc,\ officecfg/registry \ )) -$(eval $(call gb_Library_use_sdk_api,sc)) +$(eval $(call gb_Library_use_api,sc,\ + udkapi \ + offapi \ + oovbaapi \ +)) $(eval $(call gb_Library_use_externals,sc,\ boost_headers \ diff --git a/sc/Library_scd.mk b/sc/Library_scd.mk index 1b491afc5cd8..1a6a132f74f9 100644 --- a/sc/Library_scd.mk +++ b/sc/Library_scd.mk @@ -18,7 +18,11 @@ $(eval $(call gb_Library_set_include,scd,\ $(eval $(call gb_Library_use_external,scd,boost_headers)) -$(eval $(call gb_Library_use_sdk_api,scd)) +$(eval $(call gb_Library_use_api,scd,\ + udkapi \ + offapi \ + oovbaapi \ +)) $(eval $(call gb_Library_use_libraries,scd,\ comphelper \ diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk index e4b6fe154e89..4766ed02f096 100644 --- a/sc/Library_scfilt.mk +++ b/sc/Library_scfilt.mk @@ -21,7 +21,11 @@ $(eval $(call gb_Library_set_include,scfilt,\ $(eval $(call gb_Library_set_precompiled_header,scfilt,$(SRCDIR)/sc/inc/pch/precompiled_scfilt)) -$(eval $(call gb_Library_use_sdk_api,scfilt)) +$(eval $(call gb_Library_use_api,scfilt,\ + udkapi \ + offapi \ + oovbaapi \ +)) $(eval $(call gb_Library_use_custom_headers,scfilt,\ oox/generated \ diff --git a/sc/Library_scui.mk b/sc/Library_scui.mk index d576ca51a5c1..7105f59e11db 100644 --- a/sc/Library_scui.mk +++ b/sc/Library_scui.mk @@ -28,7 +28,11 @@ $(eval $(call gb_Library_use_custom_headers,scui,\ officecfg/registry \ )) -$(eval $(call gb_Library_use_sdk_api,scui)) +$(eval $(call gb_Library_use_api,scui,\ + udkapi \ + offapi \ + oovbaapi \ +)) $(eval $(call gb_Library_use_externals,scui,\ boost_headers \ diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx index e38c07dccca5..be90897627be 100644 --- a/sc/inc/scmod.hxx +++ b/sc/inc/scmod.hxx @@ -28,6 +28,7 @@ #include "global.hxx" #include "shellids.hxx" #include <unotools/options.hxx> +#include <ooo/vba/XSinkCaller.hpp> #include <com/sun/star/datatransfer/XTransferable2.hpp> @@ -107,6 +108,9 @@ class ScModule: public SfxModule, public SfxListener, public utl::ConfigurationL bool m_bIsInSharedDocSaving:1; std::map<sal_uInt16, std::vector<VclPtr<vcl::Window> > > m_mapRefWindow; + + css::uno::Reference< ooo::vba::XSinkCaller > mxAutomationApplicationEventsCaller; + public: SFX_DECL_INTERFACE(SCID_APP) @@ -245,6 +249,9 @@ public: SC_DLLPUBLIC void RegisterRefWindow( sal_uInt16 nSlotId, vcl::Window *pWnd ); SC_DLLPUBLIC void UnregisterRefWindow( sal_uInt16 nSlotId, vcl::Window *pWnd ); SC_DLLPUBLIC vcl::Window * Find1RefWindow( sal_uInt16 nSlotId, vcl::Window *pWndAncestor ); + + SC_DLLPUBLIC void RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller); + SC_DLLPUBLIC void CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments); }; #define SC_MOD() ( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule::Calc)) ) diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index 26652ddf1808..fcf1e889bc05 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -2288,4 +2288,15 @@ SfxStyleFamilies* ScModule::CreateStyleFamilies() return pStyleFamilies; } +void ScModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller) +{ + mxAutomationApplicationEventsCaller = xCaller; +} + +void ScModule::CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments) +{ + if (mxAutomationApplicationEventsCaller.is()) + mxAutomationApplicationEventsCaller->CallSinks(Method, Arguments); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 25f125f90ba4..fde8c942a172 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/util/PathSettings.hpp> #include <com/sun/star/view/XSelectionSupplier.hpp> #include <ooo/vba/XExecutableDialog.hpp> +#include <ooo/vba/excel/XApplicationOutgoing.hpp> #include <ooo/vba/excel/XlCalculation.hpp> #include <ooo/vba/excel/XlMousePointer.hpp> #include <ooo/vba/office/MsoShapeType.hpp> @@ -125,6 +126,41 @@ ScVbaAppSettings::ScVbaAppSettings() : struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {}; +class ScVbaApplicationOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint> +{ +private: + ScVbaApplication* mpApp; + +public: + ScVbaApplicationOutgoingConnectionPoint( ScVbaApplication* pApp ); + + // XConnectionPoint + sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override; + void SAL_CALL Unadvise( sal_uInt32 Cookie ) override; +}; + +sal_uInt32 +ScVbaApplication::AddSink( const uno::Reference< XSink >& xSink ) +{ + { + SolarMutexGuard aGuard; + ScDLL::Init(); + } + // No harm in potentially calling this several times + SC_MOD()->RegisterAutomationApplicationEventsCaller( uno::Reference< XSinkCaller >(this) ); + mvSinks.push_back(xSink); + return mvSinks.size();; +} + +void +ScVbaApplication::RemoveSink( sal_uInt32 nNumber ) +{ + if (nNumber < 1 || nNumber > mvSinks.size()) + return; + + mvSinks[nNumber-1] = uno::Reference< XSink >(); +} + ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) : ScVbaApplication_BASE( xContext ), mrAppSettings( ScVbaStaticAppSettings::get() ), @@ -1380,6 +1416,52 @@ void SAL_CALL ScVbaApplication::Undo() dispatchExecute( pViewShell, SID_UNDO ); } +// XInterfaceWithIID + +OUString SAL_CALL +ScVbaApplication::getIID() +{ + return OUString("{82154425-0FBF-11d4-8313-005004526AB4}"); +} + +// XConnectable + +OUString SAL_CALL +ScVbaApplication::GetIIDForClassItselfNotCoclass() +{ + return OUString("{82154426-0FBF-11D4-8313-005004526AB4}"); +} + +TypeAndIID SAL_CALL +ScVbaApplication::GetConnectionPoint() +{ + TypeAndIID aResult = + { excel::XApplicationOutgoing::static_type(), + "{82154427-0FBF-11D4-8313-005004526AB4}" + }; + + return aResult; +} + +uno::Reference<XConnectionPoint> SAL_CALL +ScVbaApplication::FindConnectionPoint() +{ + uno::Reference<XConnectionPoint> xCP(new ScVbaApplicationOutgoingConnectionPoint(this)); + return xCP; +} + +// XSinkCaller + +void SAL_CALL +ScVbaApplication::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments ) +{ + for (auto& i : mvSinks) + { + if (i.is()) + i->Call(Method, Arguments); + } +} + OUString ScVbaApplication::getServiceImplName() { @@ -1408,4 +1490,24 @@ sdecl::ServiceDecl const serviceDecl( "ooo.vba.excel.Application" ); } +// ScVbaApplicationOutgoingConnectionPoint + +ScVbaApplicationOutgoingConnectionPoint::ScVbaApplicationOutgoingConnectionPoint( ScVbaApplication* pApp ) : + mpApp(pApp) +{ +} + +// XConnectionPoint +sal_uInt32 SAL_CALL +ScVbaApplicationOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink ) +{ + return mpApp->AddSink(Sink); +} + +void SAL_CALL +ScVbaApplicationOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie ) +{ + mpApp->RemoveSink( Cookie ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index 9a0d3137febb..6c9c58588ada 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -19,6 +19,10 @@ #ifndef INCLUDED_SC_SOURCE_UI_VBA_VBAAPPLICATION_HXX #define INCLUDED_SC_SOURCE_UI_VBA_VBAAPPLICATION_HXX +#include <vector> + +#include <ooo/vba/XSink.hpp> +#include <ooo/vba/XSinkCaller.hpp> #include <ooo/vba/excel/XWorksheetFunction.hpp> #include <ooo/vba/excel/XApplication.hpp> #include <ooo/vba/excel/XFileDialog.hpp> @@ -28,7 +32,7 @@ #include <vbahelper/vbaapplicationbase.hxx> #include <cppuhelper/implbase.hxx> -typedef cppu::ImplInheritanceHelper< VbaApplicationBase, ov::excel::XApplication > ScVbaApplication_BASE; +typedef cppu::ImplInheritanceHelper< VbaApplicationBase, ov::excel::XApplication, ov::XSinkCaller > ScVbaApplication_BASE; struct ScVbaAppSettings; @@ -45,6 +49,8 @@ private: /// @throws css::uno::RuntimeException OUString getOfficePath( const OUString& sPath ); + std::vector<css::uno::Reference< ooo::vba::XSink >> mvSinks; + protected: virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() override; @@ -55,6 +61,9 @@ public: /** Returns true, if VBA document events are enabled. */ static bool getDocumentEventsEnabled(); + sal_uInt32 AddSink( const css::uno::Reference< ooo::vba::XSink >& xSink ); + void RemoveSink( sal_uInt32 nNumber ); + // XExactName virtual OUString SAL_CALL getExactName( const OUString& aApproximateName ) override; @@ -136,9 +145,21 @@ public: virtual css::uno::Any SAL_CALL MenuBars( const css::uno::Any& aIndex ) override; virtual css::uno::Any SAL_CALL Caller( const css::uno::Any& aIndex ) override; virtual void SAL_CALL Undo() override; + // XHelperInterface virtual OUString getServiceImplName() override; virtual css::uno::Sequence<OUString> getServiceNames() override; + + // XInterfaceWithIID + virtual OUString SAL_CALL getIID() override; + + // XConnectable + virtual OUString SAL_CALL GetIIDForClassItselfNotCoclass() override; + virtual ov::TypeAndIID SAL_CALL GetConnectionPoint() override; + virtual css::uno::Reference<ov::XConnectionPoint> SAL_CALL FindConnectionPoint() override; + + // XSinkCaller + virtual void SAL_CALL CallSinks( const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments ) override; }; #endif // INCLUDED_SC_SOURCE_UI_VBA_VBAAPPLICATION_HXX |