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

Creating a macro - Writing a Script - Using the API

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

Postby BenDev » Wed Jun 12, 2019 12:22 pm

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
User avatar
BenDev
 
Posts: 40
Joined: Sat May 18, 2019 3:32 pm

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

Postby JeJe » Thu Jun 13, 2019 12:00 am

Have you tried calling .uno:UseHeaderFooterMenu with the Dispatch Helper?
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 613
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby BenDev » Thu Jun 13, 2019 10:01 am

@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   Expand viewCollapse view
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/Framework/Article/OpenOffice.org_2.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   Expand viewCollapse view
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
User avatar
BenDev
 
Posts: 40
Joined: Sat May 18, 2019 3:32 pm

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

Postby JeJe » Thu Jun 13, 2019 11:49 am

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
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 613
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby BenDev » Thu Jun 13, 2019 1:57 pm

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
User avatar
BenDev
 
Posts: 40
Joined: Sat May 18, 2019 3:32 pm

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

Postby Pashahasband » Thu Aug 01, 2019 4:24 pm

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

Postby Pashahasband » Fri Aug 02, 2019 8:50 am

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

Postby Pashahasband » Fri Aug 02, 2019 2:02 pm

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
Pashahasband
 
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

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

Postby BenDev » Thu Aug 08, 2019 10:54 am

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
User avatar
BenDev
 
Posts: 40
Joined: Sat May 18, 2019 3:32 pm

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

Postby Pashahasband » Thu Aug 08, 2019 10:59 am

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
Pashahasband
 
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

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

Postby hubert lambert » Fri Aug 09, 2019 2:10 pm

Hi,

With the help of Pashahasband:
Code: Select all   Expand viewCollapse view
    doc = thiscomponent
    vs = doc.CurrentController.ViewSettings
    vs.UseHeaderFooterMenu = False

Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
 
Posts: 132
Joined: Mon Jun 13, 2016 10:50 am

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

Postby BenDev » Mon Aug 19, 2019 2:50 pm

@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/common/ref/com/sun/star/text/ViewSettings.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
User avatar
BenDev
 
Posts: 40
Joined: Sat May 18, 2019 3:32 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests