summaryrefslogtreecommitdiff
path: root/vbahelper
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-10-11 12:14:34 -0400
committerJustin Luth <jluth@mail.com>2022-10-12 01:12:17 +0200
commit73911ed8d35294a9e15771d8aaa1e9121ef10309 (patch)
tree440bebcb650b937b048bababf9cd7c0975377e99 /vbahelper
parentf518928c322d45cdec4163c0182b0008da0da729 (diff)
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 <jluth@mail.com> Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'vbahelper')
-rw-r--r--vbahelper/source/vbahelper/vbaeventshelperbase.cxx50
1 files changed, 32 insertions, 18 deletions
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")