sw/inc/doc.hxx                       |    1 +
 sw/source/core/doc/doc.cxx           |    8 ++++++--
 sw/source/ui/vba/vbadocument.cxx     |    5 ++++-
 sw/source/ui/vba/vbaeventshelper.cxx |    2 +-
 sw/source/ui/vba/vbaglobals.cxx      |   17 ++++++++---------
 sw/util/vbaswobj.component           |    2 +-
 6 files changed, 21 insertions(+), 14 deletions(-)

New commits:
commit acc71c3e502f23daaf2489d102dda3b00a45960a
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Sep 30 10:33:00 2022 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Sat Oct 1 08:56:13 2022 +0200

    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 <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 4ee71e762d30..5e552cfcadc9 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 3d2cbcae2796..62064507114b 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1795,9 +1795,14 @@ 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 79faf58fe4ab..969b893e5130 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 c1273b5038bf..6e9e510973af 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 6492b2628d59..f1c948c6cb5f 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 99ea11407d74..ea6f15ef721f 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"/>

Reply via email to