offapi/com/sun/star/script/vba/VBAEventId.idl      |    5 --
 sw/source/ui/vba/vbaeventshelper.cxx               |   23 ---------
 sw/source/uibase/app/docsh2.cxx                    |    6 +-
 vbahelper/source/vbahelper/vbaeventshelperbase.cxx |   50 +++++++++++++--------
 4 files changed, 37 insertions(+), 47 deletions(-)

New commits:
commit 73911ed8d35294a9e15771d8aaa1e9121ef10309
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Oct 11 12:14:34 2022 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Oct 12 01:12:17 2022 +0200

    tdf#148806 doc vba: highest priority is ThisDocument AutoOpen V2
    
    A review by Stephan Bergmann made me re-think adding a separate
    event for this. It really is only one event and not two
    (or three as I initially imagined). In the end, I like this better
    because it highlights the difference between Excel and Word
    by keeping all the differentiating logic in one place.
    
    The inability to properly document the purpose of these new events
    was the impetus to redesign this. Thanks Stephan for the prompt.
    
    Change-Id: Ic2d461c13c4a52e279224cb485d2b6c4a3c57b54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141233
    Tested-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/offapi/com/sun/star/script/vba/VBAEventId.idl 
b/offapi/com/sun/star/script/vba/VBAEventId.idl
index 00a524a1ef3b..00989fccd053 100644
--- a/offapi/com/sun/star/script/vba/VBAEventId.idl
+++ b/offapi/com/sun/star/script/vba/VBAEventId.idl
@@ -58,11 +58,6 @@ constants VBAEventId
     const long DOCUMENT_OPEN                        = 1002;
     /** Document about to be closed. No arguments. */
     const long DOCUMENT_CLOSE                       = 1003;
-    // auto* subroutines in ThisDocument have highest priority
-    const long DOCUMENT_AUTO_NEW = 1004;
-    const long DOCUMENT_AUTO_OPEN = 1005;
-    const long DOCUMENT_AUTO_CLOSE = 1006;
-
 
     // MS Excel (identifiers from 2001 to 2999)
 
diff --git a/sw/source/ui/vba/vbaeventshelper.cxx 
b/sw/source/ui/vba/vbaeventshelper.cxx
index d083940106b5..d928eaba16f2 100644
--- a/sw/source/ui/vba/vbaeventshelper.cxx
+++ b/sw/source/ui/vba/vbaeventshelper.cxx
@@ -32,13 +32,10 @@ SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< 
css::uno::Any > const& aArg
 {
     using namespace ::com::sun::star::script::ModuleType;
     registerEventHandler( DOCUMENT_NEW,     DOCUMENT,   "Document_New" );
-    registerEventHandler(DOCUMENT_AUTO_NEW, DOCUMENT, "AutoNew");
     registerEventHandler( AUTO_NEW,         NORMAL,     "AutoNew" );
     registerEventHandler( DOCUMENT_OPEN,    DOCUMENT,   "Document_Open" );
-    registerEventHandler(DOCUMENT_AUTO_OPEN, DOCUMENT, "AutoOpen");
     registerEventHandler( AUTO_OPEN,        NORMAL,     "AutoOpen" );
     registerEventHandler( DOCUMENT_CLOSE,   DOCUMENT,   "Document_Close" );
-    registerEventHandler(DOCUMENT_AUTO_CLOSE, DOCUMENT, "AutoClose");
     registerEventHandler( AUTO_CLOSE,       NORMAL,     "AutoClose" );
 }
 
@@ -46,25 +43,9 @@ SwVbaEventsHelper::~SwVbaEventsHelper()
 {
 }
 
-bool SwVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue,
-        const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs)
+bool SwVbaEventsHelper::implPrepareEvent(EventQueue& /*rEventQueue*/,
+        const EventHandlerInfo& /*rInfo*/, const uno::Sequence<uno::Any>& 
/*rArgs*/)
 {
-    switch( rInfo.mnEventId )
-    {
-        case DOCUMENT_AUTO_NEW:
-            // Only one "AutoNew" subroutine can run. ThisDocument is highest 
priority.
-            if (!hasVbaEventHandler(rInfo.mnEventId, rArgs))
-                rEventQueue.emplace_back(AUTO_NEW);
-        break;
-        case DOCUMENT_AUTO_OPEN:
-            if (!hasVbaEventHandler(rInfo.mnEventId, rArgs))
-                rEventQueue.emplace_back(AUTO_OPEN);
-        break;
-        case DOCUMENT_AUTO_CLOSE:
-            if (!hasVbaEventHandler(rInfo.mnEventId, rArgs))
-                rEventQueue.emplace_back(AUTO_CLOSE);
-        break;
-    }
     return true;
 }
 
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 51082a682c2d..a5e79881e342 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -221,11 +221,11 @@ static void lcl_processCompatibleSfxHint( const 
uno::Reference< script::vba::XVB
     switch( pSfxEventHint->GetEventId() )
     {
         case SfxEventHintId::CreateDoc:
-            xVbaEvents->processVbaEvent(DOCUMENT_AUTO_NEW, aArgs);
+            xVbaEvents->processVbaEvent(AUTO_NEW, aArgs);
             xVbaEvents->processVbaEvent(DOCUMENT_NEW, aArgs);
         break;
         case SfxEventHintId::OpenDoc:
-            xVbaEvents->processVbaEvent(DOCUMENT_AUTO_OPEN, aArgs);
+            xVbaEvents->processVbaEvent(AUTO_OPEN, aArgs);
             xVbaEvents->processVbaEvent(DOCUMENT_OPEN, aArgs);
         break;
         default: break;
@@ -387,7 +387,7 @@ bool SwDocShell::PrepareClose( bool bUI )
         {
             using namespace com::sun::star::script::vba::VBAEventId;
             uno::Sequence< uno::Any > aNoArgs;
-            xVbaEvents->processVbaEvent(DOCUMENT_AUTO_CLOSE, aNoArgs);
+            xVbaEvents->processVbaEvent(AUTO_CLOSE, aNoArgs);
             xVbaEvents->processVbaEvent(DOCUMENT_CLOSE, aNoArgs);
         }
     }
diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx 
b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
index 7d6e1bbb6ea9..13fc4d2c5daa 100644
--- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
+++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx
@@ -375,33 +375,47 @@ VbaEventsHelperBase::ModulePathMap& 
VbaEventsHelperBase::updateModulePathMap( co
         sThisWorkbook = implGetDocumentModuleName(rThisWorksheetInfo, aNoArgs);
     }
 
+    // Use DOCUMENT_OPEN as a way to get the codename for ThisDocument
+    OUString sThisDocument;
+    if (getImplementationName() == "SwVbaEventsHelper")
+    {
+        EventHandlerInfo& rThisDocumentInfo
+            = maEventInfos[css::script::vba::VBAEventId::DOCUMENT_OPEN];
+        css::uno::Sequence<css::uno::Any> aNoArgs;
+        sThisDocument = implGetDocumentModuleName(rThisDocumentInfo, aNoArgs);
+    }
+
     for( const auto& rEventInfo : maEventInfos )
     {
         const EventHandlerInfo& rInfo = rEventInfo.second;
         if( rInfo.mnModuleType == nModuleType )
         {
+            OUString sName;
+            bool bOnlyPublic = false;
             OUString sSkipModule;
-            // Only in Calc, ignore Auto_* in ThisWorkbook
-            if (getImplementationName() == "ScVbaEventsHelper"
-                && (rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_NEW
-                    || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_OPEN
-                    || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_CLOSE))
+            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)
             {
-                sSkipModule = sThisWorkbook;
+                if (getImplementationName() == "ScVbaEventsHelper")
+                {
+                    // Only in Calc, ignore Auto_* in ThisWorkbook
+                    sSkipModule = sThisWorkbook;
+                }
+                else if (getImplementationName() == "SwVbaEventsHelper")
+                {
+                    // Only in Word, Auto* only runs if defined as Public, not 
Private.
+                    bOnlyPublic = true;
+                    // Only in Word, auto* subroutines in ThisDocument have 
highest priority
+                    sName = resolveVBAMacro(mpShell, maLibraryName, 
sThisDocument,
+                                            rInfo.maMacroName, bOnlyPublic, 
sSkipModule);
+                }
             }
 
-            // Only in Word, Auto* only runs if defined as Public, not Private.
-            const bool bOnlyPublic
-                = getImplementationName() == "SwVbaEventsHelper"
-                  && (rInfo.mnEventId == 
css::script::vba::VBAEventId::DOCUMENT_AUTO_NEW
-                      || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_NEW
-                      || rInfo.mnEventId == 
css::script::vba::VBAEventId::DOCUMENT_AUTO_OPEN
-                      || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_OPEN
-                      || rInfo.mnEventId == 
css::script::vba::VBAEventId::DOCUMENT_AUTO_CLOSE
-                      || rInfo.mnEventId == 
css::script::vba::VBAEventId::AUTO_CLOSE);
-
-            OUString sName = resolveVBAMacro(mpShell, maLibraryName, 
rModuleName,
-                                             rInfo.maMacroName, bOnlyPublic, 
sSkipModule);
+            if (sName.isEmpty())
+                sName = resolveVBAMacro(mpShell, maLibraryName, rModuleName,
+                                        rInfo.maMacroName, bOnlyPublic, 
sSkipModule);
+
             // Only in Word (with lowest priority), an Auto* module can 
execute a "Public Sub Main"
             if (sName.isEmpty() && rModuleName.isEmpty()
                 && getImplementationName() == "SwVbaEventsHelper")

Reply via email to