Adressing the Ok Button in the OptionsPage

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Niklas.Ardey
Posts: 56
Joined: Mon Oct 19, 2015 2:34 pm

Adressing the Ok Button in the OptionsPage

Post by Niklas.Ardey »

Hello,

I hope you can help me solving this Problem. I have made my own OptionsPage and want to adress the OK Button on the Bottom of the Settings Window.
Can someone of you tell me how i can add my function to this Button ?

Thanks for helping
Last edited by Niklas.Ardey on Fri Oct 14, 2016 9:36 am, edited 1 time in total.
OpenOffice 4.1.1 same with the SDK
Operation System is Windows 8.1
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Adressing the Ok Button in the OptionsPage

Post by UnklDonald418 »

I'm assuming OptionsPage is a dialog.
Buttons on a dialog page have properties.
Open the Button Properties dialog and select Events. You should see a list of button related events that your function can be attached to.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Niklas.Ardey
Posts: 56
Joined: Mon Oct 19, 2015 2:34 pm

Re: Adressing the Ok Button in the OptionsPage

Post by Niklas.Ardey »

UnklDonald418 wrote:I'm assuming OptionsPage is a dialog.
Buttons on a dialog page have properties.
Open the Button Properties dialog and select Events. You should see a list of button related events that your function can be attached to.
Yeah thanks.
But I do not want to do this that way cause i want to do it in Java because i have to attache my coded function that i use there to the Button. And i do not know how i can access the button using Java.

Thanks anyways
OpenOffice 4.1.1 same with the SDK
Operation System is Windows 8.1
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Adressing the Ok Button in the OptionsPage

Post by UnklDonald418 »

Have you looked at:
https://wiki.openoffice.org/wiki/Docume ... at_Runtime
It shows:

Code: Select all

// add an action listener to the button control
XControlContainer xControlCont = (XControlContainer)UnoRuntime.queryInterface(XControlContainer.class, dialog); 
Object objectButton = xControlCont.getControl("Button1");
XButton xButton = (XButton)UnoRuntime.queryInterface(XButton.class, objectButton);
xButton.addActionListener(new ActionListenerImpl(xControlCont));
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Niklas.Ardey
Posts: 56
Joined: Mon Oct 19, 2015 2:34 pm

Re: Adressing the Ok Button in the OptionsPage

Post by Niklas.Ardey »

UnklDonald418 wrote:Have you looked at:
https://wiki.openoffice.org/wiki/Docume ... at_Runtime
It shows:

Code: Select all

// add an action listener to the button control
XControlContainer xControlCont = (XControlContainer)UnoRuntime.queryInterface(XControlContainer.class, dialog); 
Object objectButton = xControlCont.getControl("Button1");
XButton xButton = (XButton)UnoRuntime.queryInterface(XButton.class, objectButton);
xButton.addActionListener(new ActionListenerImpl(xControlCont));

Thanks but no,
I already have my own dialog and I only want to adress the button at the Bottom of the window. On every OptionsDialog there is an "OK-Button" at the Bottom of the Window. I need to adress that Button because often a user forgetts to klick my "Save" Button so i want to attach that save function to this Ok Button.
OpenOffice 4.1.1 same with the SDK
Operation System is Windows 8.1
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Adressing the Ok Button in the OptionsPage

Post by hanya »

Why don't you save data in your code? If your service supports callHandlerMethod method for the option page hander which implements com.sun.star.awt.XContainerWindowEventHandler interface, you can obtain event notification when user push OK button on the options page. Like the following in Python:

Code: Select all

    def callHandlerMethod(self, window, ev, name):
        if name == "external_event":
            self.handle(window, ev)
    
    def handle(self, dialog, ev):
        self.dialog = dialog
        if ev == "ok":
            self.confirm()
        elif ev == "back":
            self.init()
        elif ev == "initialize":
            self.init(first_time=True)
        return True
Third argument of callHandlerMethod method gives you event name happen on the options dialog.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Niklas.Ardey
Posts: 56
Joined: Mon Oct 19, 2015 2:34 pm

Re: Adressing the Ok Button in the OptionsPage

Post by Niklas.Ardey »

hanya wrote:Why don't you save data in your code? If your service supports callHandlerMethod method for the option page hander which implements com.sun.star.awt.XContainerWindowEventHandler interface, you can obtain event notification when user push OK button on the options page. Like the following in Python:

Code: Select all

    def callHandlerMethod(self, window, ev, name):
        if name == "external_event":
            self.handle(window, ev)
    
    def handle(self, dialog, ev):
        self.dialog = dialog
        if ev == "ok":
            self.confirm()
        elif ev == "back":
            self.init()
        elif ev == "initialize":
            self.init(first_time=True)
        return True
Third argument of callHandlerMethod method gives you event name happen on the options dialog.
Thanks,

But from the Documentation on the OpenOffice Website I assume that this only works if i Created a completly seperate window.
My problem is that the window already exsists and that i just added a Dialog to the settingspage(Settingswindow).
So i guess that this wont work for what I need to do :S
Thanks anyways

Btw I am doing this in Java.
OpenOffice 4.1.1 same with the SDK
Operation System is Windows 8.1
Post Reply