Kaydet (Commit) b9ef6b66 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 8a2f30e5
......@@ -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()
......
......@@ -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;
......
......@@ -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);
};
}; }; };
......
......@@ -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 \
......
......@@ -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 \
......
......@@ -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 \
......
......@@ -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 \
......
......@@ -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)) )
......
......@@ -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: */
......@@ -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: */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment