vbahelper/source/vbahelper/vbaeventshelperbase.cxx |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

New commits:
commit e2abb5bbc03cca884fa89345003d013688f0d94d
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Oct 7 19:35:59 2022 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Sun Oct 9 01:07:23 2022 +0200

    tdf#148806 doc vba: accept module AutoOpen.Main
    
    This is the lowest priority way of running AutoOpen,
    and it only applies to Word, not Excel.
    
    There is some code in basic/source/classes/sb.cxx
    that was somewhat finding this before it got lost in LO 7.4
    with commit beb6c62e990599d91ac5d9183164c94d269027d3.
    
    TODO: these AutoOpens should only run with a public sub,
    not a private one.
    
    Change-Id: I8a733cde13f96636942d84a0b05520692aac3e52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141094
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx 
b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
index dbd345c9bac7..cbe8ca79bad7 100644
--- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
+++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/document/XEventBroadcaster.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/script/ModuleType.hpp>
+#include <com/sun/star/script/vba/VBAEventId.hpp>
 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
 #include <com/sun/star/script/XLibraryContainer.hpp>
 #include <com/sun/star/util/VetoException.hpp>
@@ -367,7 +368,22 @@ VbaEventsHelperBase::ModulePathMap& 
VbaEventsHelperBase::updateModulePathMap( co
     {
         const EventHandlerInfo& rInfo = rEventInfo.second;
         if( rInfo.mnModuleType == nModuleType )
-            rPathMap[ rInfo.mnEventId ] = resolveVBAMacro( mpShell, 
maLibraryName, rModuleName, rInfo.maMacroName );
+        {
+            OUString sName = resolveVBAMacro(mpShell, maLibraryName, 
rModuleName,
+                                             rInfo.maMacroName);
+            // Only in Word (with lowest priority), an Auto* module can 
execute a "Public Sub Main"
+            if (sName.isEmpty() && rModuleName.isEmpty()
+                && getImplementationName() == "SwVbaEventsHelper")
+            {
+                if (rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_NEW
+                    || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_OPEN
+                    || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_CLOSE)
+                {
+                    sName = resolveVBAMacro(mpShell, maLibraryName, 
rInfo.maMacroName, "Main");
+                }
+            }
+            rPathMap[rInfo.mnEventId] = sName;
+        }
     }
     return rPathMap;
 }

Reply via email to