tdf#148806 sw vba: fix GetVbaEventProcessor
I've decided this is not an API change because there exists
offapi/com/sun/star/script/vba/VBATextEventProcessor.idl
This patch allows New, Open, and Close events to be
sent to VBA macro event handlers.
I tested with DOCUMENT_OPEN.
Amazing - all this stuff is here in place,
but isn't properly wired up. How can so much
ground-work be done without it ever being functional?
I don't think this has ever worked,
and the same problem/code is seen in OpenOffice.
The service names were already mismatched in the initial patch:
commit fc135411fa926f4d89e98378d113f597af79e2a2
Author: Daniel Rentz on Tue Jul 6 19:34:53 2010 +0200
mib17: #i112634# add VBA sheet event handling,
based on a patch from Noel Power
https://bz.apache.org/ooo/show_bug.cgi?id=112634
says "Additionally I added the hooks for vba for word
( but they are compiled out for now )"
Enabling this will open up the doors to a lot of
untested code I think.
I had to move initialization of mxVbaEvents
because it was being set without a VBA project,
but it didn't work to put it in VbaGlobals like Calc does.
Change-Id: I08cc0e33444dc7dfaac82cf6cebb1a89dbb69faa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140801
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 4ee71e7..5e552cf 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1628,6 +1628,7 @@ public:
const css::uno::Reference< ooo::vba::word::XFind >& getVbaFind() const { return mxVbaFind; }
void setVbaFind( const css::uno::Reference< ooo::vba::word::XFind > &xFind) { mxVbaFind = xFind; }
css::uno::Reference< css::script::vba::XVBAEventProcessor > const & GetVbaEventProcessor();
void SetVbaEventProcessor();
void SetVBATemplateToProjectCache( css::uno::Reference< css::container::XNameContainer > const & xCache ) { m_xTemplateToProjectCache = xCache; };
const css::uno::Reference< css::container::XNameContainer >& GetVBATemplateToProjectCache() const { return m_xTemplateToProjectCache; };
::sfx2::IXmlIdRegistry& GetXmlIdRegistry();
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 3d2cbca..6206450 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1796,8 +1796,13 @@ void SwDoc::ChkCondColls()
uno::Reference< script::vba::XVBAEventProcessor > const &
SwDoc::GetVbaEventProcessor()
{
return mxVbaEvents;
}
void SwDoc::SetVbaEventProcessor()
{
#if HAVE_FEATURE_SCRIPTING
if( !mxVbaEvents.is() && mpDocShell && ooo::vba::isAlienWordDoc( *mpDocShell ) )
if (mpDocShell && ooo::vba::isAlienWordDoc(*mpDocShell))
{
try
{
@@ -1810,7 +1815,6 @@ SwDoc::GetVbaEventProcessor()
}
}
#endif
return mxVbaEvents;
}
void SwDoc::SetMissingDictionaries( bool bIsMissing )
diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx
index 79faf58f..969b893 100644
--- a/sw/source/ui/vba/vbadocument.cxx
+++ b/sw/source/ui/vba/vbadocument.cxx
@@ -46,6 +46,7 @@
#include <ooo/vba/word/XDocumentOutgoing.hpp>
#include "wordvbahelper.hxx"
#include <doc.hxx>
#include <docsh.hxx>
#include "vbatemplate.hxx"
#include "vbaparagraph.hxx"
@@ -99,7 +100,9 @@ SwVbaDocument::~SwVbaDocument()
void SwVbaDocument::Initialize()
{
mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
word::getDocShell( mxModel )->RegisterAutomationDocumentObject( this );
SwDocShell& rDocSh = *word::getDocShell(mxModel);
rDocSh.RegisterAutomationDocumentObject(this);
rDocSh.GetDoc()->SetVbaEventProcessor();
}
sal_uInt32
diff --git a/sw/source/ui/vba/vbaeventshelper.cxx b/sw/source/ui/vba/vbaeventshelper.cxx
index c1273b5..6e9e510 100644
--- a/sw/source/ui/vba/vbaeventshelper.cxx
+++ b/sw/source/ui/vba/vbaeventshelper.cxx
@@ -92,7 +92,7 @@ sal_Bool SwVbaEventsHelper::supportsService( const OUString& ServiceName )
}
css::uno::Sequence< OUString > SwVbaEventsHelper::getSupportedServiceNames()
{
return { "com.sun.star.document.vba.VBATextEventProcessor" };
return { "com.sun.star.script.vba.VBATextEventProcessor" };
}
diff --git a/sw/source/ui/vba/vbaglobals.cxx b/sw/source/ui/vba/vbaglobals.cxx
index 6492b26..f1c948c 100644
--- a/sw/source/ui/vba/vbaglobals.cxx
+++ b/sw/source/ui/vba/vbaglobals.cxx
@@ -21,6 +21,8 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <comphelper/sequence.hxx>
#include "vbaapplication.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -189,15 +191,12 @@ SwVbaGlobals::getServiceNames()
uno::Sequence< OUString >
SwVbaGlobals::getAvailableServiceNames( )
{
static uno::Sequence< OUString > const serviceNames = [&]()
{
uno::Sequence< OUString > tmp = SwVbaGlobals_BASE::getAvailableServiceNames();
tmp.realloc( tmp.getLength() + 1 );
tmp.getArray()[ tmp.getLength() - 1 ] = "ooo.vba.word.Document";
// #FIXME #TODO make Application a proper service
// OUString( "ooo.vba.word.Application" ),
return tmp;
}();
static const uno::Sequence<OUString> serviceNames = comphelper::concatSequences(
SwVbaGlobals_BASE::getAvailableServiceNames(),
uno::Sequence<OUString>{ "ooo.vba.word.Document",
// "ooo.vba.word.Globals",
// "ooo.vba.word.WrapFormat",
"com.sun.star.script.vba.VBATextEventProcessor" });
return serviceNames;
}
diff --git a/sw/util/vbaswobj.component b/sw/util/vbaswobj.component
index 99ea114..ea6f15e 100644
--- a/sw/util/vbaswobj.component
+++ b/sw/util/vbaswobj.component
@@ -23,7 +23,7 @@
<service name="ooo.vba.word.Document"/>
</implementation>
<implementation name="SwVbaEventsHelper" constructor="Writer_SwVbaEventsHelper_get_implementation">
<service name="com.sun.star.document.vba.VBATextEventProcessor"/>
<service name="com.sun.star.script.vba.VBATextEventProcessor"/>
</implementation>
<implementation name="SwVbaGlobals" constructor="Writer_SwVbaGlobals_get_implementation">
<service name="ooo.vba.word.Globals"/>