summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-04-23 20:50:43 +0300
committerTor Lillqvist <tml@collabora.com>2018-05-31 15:29:43 +0300
commitb9ef6b66e7a67a448b1a840c47146d8789a92a6d (patch)
tree8dab5043884df3ee37f31b41fab4fc268b887a17 /sc
parent8a2f30e548f930f0ddd869e07f58947616ba9ea4 (diff)
Initial steps to make also Calc usable from Automation clients
Largely parallel to what we do for Writer. Yes, there is a fair amount of duplicated code now for the outgoing ("sink") stuff in sw and sc, that should be factored out (to vbahelper, probably). Change-Id: I8df4a81c3b9043e8d6b0b206e3c04660205987c7
Diffstat (limited to 'sc')
-rw-r--r--sc/Library_sc.mk6
-rw-r--r--sc/Library_scd.mk6
-rw-r--r--sc/Library_scfilt.mk6
-rw-r--r--sc/Library_scui.mk6
-rw-r--r--sc/inc/scmod.hxx7
-rw-r--r--sc/source/ui/app/scmod.cxx11
-rw-r--r--sc/source/ui/vba/vbaapplication.cxx102
-rw-r--r--sc/source/ui/vba/vbaapplication.hxx23
8 files changed, 162 insertions, 5 deletions
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