Bug 144162 - Document event binding for "LibreOffice" is not regarded if the execution of document macros was disallowed.
Summary: Document event binding for "LibreOffice" is not regarded if the execution of ...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.2.0.4 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-29 16:37 UTC by Wolfgang Jäger
Modified: 2022-05-25 15:44 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
containing local code and a tiny "Hello World" macro. (36.75 KB, application/vnd.oasis.opendocument.text)
2022-05-25 14:18 UTC, Wolfgang Jäger
Details

Note You need to log in before you can comment on or make changes to this bug.
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.