[LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
BenDev
Posts: 46
Joined: Sat May 18, 2019 3:32 pm

[LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by BenDev »

Hi,

I'm trying to find a way to check the state of a check sub-Menu and to force the state of this sub-menu to Off if needed depending to the actual state.

The concerned Sub-Menu is this one (see the attached image) :
"Main Menu" / "Insertion" / "Header and Footer" / "Use Header/Footer Menu"

The equivalent path with commandURL is:
"private:resource/menubar/menubar" / ".uno:InsertMenu" / ".uno:InsertHeaderFooterMenu" / ".uno:UseHeaderFooterMenu"

I'm able to reach the check Sub-Menu from its properties (see the debug console log on attached image).
So I thought I could check the state of the Sub-Menu and then Set it to Off if needed.
Sadly, the state checked/unchecked of the Sub-Menu seems to be not accessible from those properties...

So I wonder how should I do this, as for now I'm not able to retrieve this sub-menu as a awt-XMenu Object, and so be able to manage some of its properties...
Attachments
CheckSubMenuProperties.png
LibreOffice 6.1.5.2 (x64) and LibreOffice 6.2.4.2 (x64)
Windows 8.1 Pro
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by JeJe »

Have you tried calling .uno:UseHeaderFooterMenu with the Dispatch Helper?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
BenDev
Posts: 46
Joined: Sat May 18, 2019 3:32 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by BenDev »

@Jeje:

Thanks for your proposition.
I had already found this as a solution to simulate a click on the concerned Sub-Menu:

Code: Select all

dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:UseHeaderFooterMenu", "", 0, Array())
But it's a one way action that doesn't check if the option is already set to On or Off.
In my case I need to set it to Off.

I've been searching for an argument that I could add for the executeDispatch to specify that the option should be turned to off.
But as oBasic documentation is a real labyrinth that turn sometimes to a real headache, I found the Command URL's page ( https://wiki.openoffice.org/wiki/Framew ... x_Commands ), but nothing about the parameters that are needed for the ones that require parameters...

So I tried some attemps by my own in case of luck like:

Code: Select all

dim argsAttempt(0) as new com.sun.star.beans.PropertyValue
argsAttempt(0).Name = "Activation"
argsAttempt(0).Value = false
dispatcher.executeDispatch(document, ".uno:UseHeaderFooterMenu", "", 0, argsAttempt())
But it's not appropriate properies...
LibreOffice 6.1.5.2 (x64) and LibreOffice 6.2.4.2 (x64)
Windows 8.1 Pro
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by JeJe »

Its a new feature that's not in my version of LO. Here's a page about it:

https://bugs.documentfoundation.org/sho ... ?id=118621
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
BenDev
Posts: 46
Joined: Sat May 18, 2019 3:32 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by BenDev »

I saw this , yeah.
The Option to disable floating header/footer menu is available since 6.2.0.

My need is to force it to be at Off state.
Because I need the user not to be able to delete the header.
LibreOffice 6.1.5.2 (x64) and LibreOffice 6.2.4.2 (x64)
Windows 8.1 Pro
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by Pashahasband »

Hi, I have the same task, did you find a solution?
LibreOffice 6.2.4.2 (x64)
Windows 10
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by Pashahasband »

Hi, it turned off through
Reference <XModel> xModelView (xTextDocument, UNO_QUERY);
Reference <XViewSettingsSupplier> xViewSettings (xModelView-> getCurrentController (), UNO_QUERY);
Reference <XPropertySet> propView = xViewSettings-> getViewSettings ();
propView-> setPropertyValue ("UseHeaderFooterMenu", :: Any (sal_Bool (false)));
LibreOffice 6.2.4.2 (x64)
Windows 10
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by Pashahasband »

We also managed to hide the menu item for the UseHeaderFooterMenu command, but you can also delete the header and footer through their default setting. Do not prompt the menu command in insert "Header and Footer"?
LibreOffice 6.2.4.2 (x64)
Windows 10
User avatar
BenDev
Posts: 46
Joined: Sat May 18, 2019 3:32 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by BenDev »

Pashahasband wrote:Hi, it turned off through
Reference <XModel> xModelView (xTextDocument, UNO_QUERY);
Reference <XViewSettingsSupplier> xViewSettings (xModelView-> getCurrentController (), UNO_QUERY);
Reference <XPropertySet> propView = xViewSettings-> getViewSettings ();
propView-> setPropertyValue ("UseHeaderFooterMenu", :: Any (sal_Bool (false)));

Hello,
Could you be more specific on this code?
Is this used in basic (as basic doesn't accept this syntax), or JavaScript, BeanShell or python?
LibreOffice 6.1.5.2 (x64) and LibreOffice 6.2.4.2 (x64)
Windows 8.1 Pro
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by Pashahasband »

Hi, I used this in .cpp, but I think you can make an analogy in any other. The main thing is to turn to XViewSettingsSupplier.
LibreOffice 6.2.4.2 (x64)
Windows 10
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by hubert lambert »

Hi,

With the help of Pashahasband:

Code: Select all

    doc = thiscomponent
    vs = doc.CurrentController.ViewSettings
    vs.UseHeaderFooterMenu = False
Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
BenDev
Posts: 46
Joined: Sat May 18, 2019 3:32 pm

Re: [LibreOffice] [Writer] Get/Set state of a Check-SubMenu

Post by BenDev »

@hubert lambert:Thanks a lot!

Well at first, I thought there would be something that easy, but my researchs brought me somewhere else with very more complex solution point of vue :shock: .

Since I'm working on LibreOffice and OpenOffice, I've found that the documentation was really dispersed and I found a little difficult to get concrete examples apart from the forums...

For example, in this case, here is the documentation I found for the use of the ViewSettings Service:
https://www.openoffice.org/api/docs/com ... tings.html

It doesn't really identify "UseHeaderFooterMenu " as an element or a Properties we can directly set from code.
Not sure that we can get this information from the use of xray or MRI?

So for example, where or how did you get the information of the direct use of UseHeaderFooterMenu as a property of ViewSettings?
LibreOffice 6.1.5.2 (x64) and LibreOffice 6.2.4.2 (x64)
Windows 8.1 Pro
Post Reply