From 73911ed8d35294a9e15771d8aaa1e9121ef10309 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Tue, 11 Oct 2022 12:14:34 -0400 Subject: 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 Reviewed-by: Justin Luth --- vbahelper/source/vbahelper/vbaeventshelperbase.cxx | 50 ++++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'vbahelper') 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 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") -- cgit v1.2.3