Bug 144162

Summary: Document event binding for "LibreOffice" is not regarded if the execution of document macros was disallowed.
Product: LibreOffice Reporter: Wolfgang Jäger <jag>
Component: BASICAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: normal CC: ilmari.lauhakangas, jag
Priority: medium    
Version: 7.2.0.4 release   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: containing local code and a tiny "Hello World" macro.
The announced archive as a fake .odg

Description Wolfgang Jäger 2021-08-29 16:37:23 UTC
The document events I'm using on a regular basis (currently with all my documents) are:
OnViewCreated
OnDocumentHasBeenSaved
OnDocumentHasBeenSavedAs

If a document is containing macros, and macro execution was not permitted when opening it (Security Options), the Sub stored to the local Standard library, and assigned to the mentioned events, are not called.  

Steps to reproduce:

Edit Basic macros for LibO. (No document opened.)
Create an arbitrary hello-world-macro in a module of the local Standard library.
Assign this macro to 'On View Created' via >Tools>Customize>Events (LibreOffice as target). 

Have at hand any document containing a macro.
Open it with either Macro Security 'High' or 'Medium' and macros not permitted.  
Expected: The mentioned hello-world-macro is executed.
Experienced: No action.

Open the same document permitting the execution of document macros.
Expected: The mentioned hello-world-macro is executed.
Experienced: As expected.

The bug:
Macro security should only concern document macros. Local macros and their bindings to events shouldn't be afflicted.  

Since the bug depends on the local settings and event bindings, it can't be demonstrated by an example file.
Comment 1 Buovjaga 2022-05-25 13:19:01 UTC
I added a Calc Hello World macro to My Macros > Standard > Module1 and it works with View Created even with High macro security.

I got the macro from https://www.debugpoint.com/2014/09/writing-a-macro-in-libreoffice-calc-getting-started/

I tested both with 7.2.0 and the latest master.

Arch Linux 64-bit
Version: 7.4.0.0.alpha1+ / LibreOffice Community
Build ID: ff2b4bff61d2e1679bb525d754c960c48b81c495
CPU threads: 8; OS: Linux 5.17; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Built on 25 May 2022

Macro:

REM  *****  BASIC  *****
sub hello_world
	dim document   as object
	dim dispatcher as object
	
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	
	dim args1(0) as new com.sun.star.beans.PropertyValue
	dim args2(0) as new com.sun.star.beans.PropertyValue
	
	args1(0).Name = "ToPoint"
	args1(0).Value = "$A$1"
	dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
	
	args2(0).Name = "StringName"
	args2(0).Value = "Hello World!"
	dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args2())
   msgbox "Completed!"
end sub
Comment 2 Wolfgang Jäger 2022-05-25 14:18:00 UTC
Created attachment 180375 [details]
containing local code and a tiny "Hello World" macro.

(In reply to Buovjaga from comment #1)
> I added a Calc Hello World macro to My Macros > Standard > Module1 and it
> works with View Created even with High macro security.
...
I did neither see reasons for using a recorded macro for the test nor for using one specialized on Calc. It is expected to throw an error if a different doctype has created its view.

The macro actually bound to onViewCreated by customization on my Win 10 system currently working with LibO V 7.3.3.2 is:

Sub onViewCreated(pEvent)
showFileLocationInTitleBar(pEvent.Source, preferredPathStyle, preferredLastModifiedFormat, queryPartContent)
End Sub

where the called macro does NOT call in turn any document macros. 
You will find every detail of probable interest in the attached example.
I do not attach, however, my complete buser profile. ;-)

If I open exactly this attached document on my customized install for which macro security is set to 'Medium', I experience the originallky reported bug:

Having permitted the execution of dopcument macros I get all the additional information I want to see in the titlke bar.
Having prohibited the execution of document macro no info is appeneded: The onViewCreated() macro simply is not called.
Comment 3 Buovjaga 2022-05-25 15:44:25 UTC
I had forgotten to test with a document containing a macro, so I did a new test. I can reproduce.
Comment 4 QA Administrators 2024-05-25 03:27:53 UTC Comment hidden (obsolete)
Comment 5 Wolfgang Jäger 2024-05-25 13:04:55 UTC
Created attachment 194347 [details]
The announced archive as a fake .odg

(In reply to QA Administrators from comment #4)
> Dear Wolfgang Jäger,
...
> Warm Regards,
> QA Team
> 
> MassPing-UntouchedBug

As far as I can see the bug is living happily in V 24.2.2.2.

For easing your checks I attach as a ".fake.odg" a 7z-archived folder containing two excample files and a user profile which was virgin a few hours ago, and only got included the two "MyMacros" routines, language settings, and the 
Medium/Prompt setting for macro security.

unpack the archive to an empty folder and call soffice with 
-env:UserInstallation=file:///symbolicPathToYourEmptyFolder/tdf_144162

(I made this all under Win 10.)

Regards