How to use ActionListener on my Macros

Creating a macro - Writing a Script - Using the API

How to use ActionListener on my Macros

Postby MrM_Brazilian » Thu Jul 20, 2017 5:24 am

Hi, guys. First, I need to ask to apologize for my bad English. I'm from Brazil and I've learned English on my own with the help of the internet. And now here I am rs. If it possible, I'd like very much that someone helps me with some examples of use of the Listeners such as ActionListener and others Listeners and Handlers. NOTE: I already have with me, the XMouseClickHandler and XKeyHandler samples.

Code: Select all   Expand viewCollapse view
global rogerActionListener 'global variable where i put XActionListener

sub SetupXActionListener
   DialogLibraries.loadLibrary("Standard")
   oDialogo = createUnoDialog(DialogLibraries.Standard.Dialog1)
   scrlBar = oDialogo.getControl("ListBox1")
'   objListBox = oDialogo.getModel().getByName("ListBox1") 'I don't know if this could be the correct place to register that listener
   rogerActionListener = CreateUnoListener("XActionListener_","com.sun.star.awt.XActionListener")
   oDialogo.getControl("ListBox1").AddActionListener(rogerActionListener) 'it seems which this instruction is correct to register the listener into ListBox1
'   objListBox.AddActionListener(rogerActionListener) 'Finally occurs the Listener register

   call ListBoxString 'I put this call here because if I don't pull anything in this part, invariably when this sub ends, automatically the macro goes to the method disposing and then I don't know what im doing wrong
end sub

sub removeXActionListener
   thisComponent.currentController.removeActionListener(rogerActionListener)
end sub

sub XActionListener_disposing
   removeXActionListener
end sub

function XActionListener_actionPerformed(oKeyEvent) 'In this part, the OpenOffice documentation ask the OneWay (void), however i don't understand how that parameter functions
   msgBox "Something happened" 'I can not make the macro comes until here
end function


Thank you very much at all
LibreOffice Version: 5.2.7.2
Windows 7 Ultimate Service Pack 1 x64
MrM_Brazilian
 
Posts: 2
Joined: Thu Jul 20, 2017 2:43 am

Re: How to use ActionListener on my Macros

Postby Villeroy » Fri Jul 21, 2017 9:47 am

MRI - UNO Object Inspection Tool
[Tutorial] Introduction into object inspection with MRI
Control models are like blue prints of the loaded control. When you edit a dialog in the editor tool, you are editing the control model. The model stores all the properties and the script events you can see in the dialog editor.

Method createUnoDialog loads a “living dialog” from that model. Theoretically, you can load multiple dialogs from the same model.
Contrary to script events, methods like myObject.addFoooListener(myFoooListener) adds an UNO listener to an already loaded “living dialog” at runtime.

The Basic language has no object orientation. You can not write any UNO-listeners in Basic like you can do in Python or Java or C++. Basic's helper function createUnoListener(“some_prefix_”, “XinterfaceName”) generates a hidden listener object which calls the Basic routines that are named with the given prefix in front of the method name.
Attachments
mri_ActionListener.odt
(20.91 KiB) Downloaded 9 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24079
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to use ActionListener on my Macros

Postby MrM_Brazilian » Sat Jul 22, 2017 10:43 pm

Thank you very much for the speed and promptness of the response. The example that you gave me, helped me a lot in the process to understand a few more about the concept of a listener. Although I've had little time to study better, I came to following conclusions:
1. So that the called Listener can function correctly, it is necessary that the frame (or document) to which belongs, is already instantiated and running. I noticed this while I was comparing my code with yours because I instantiated the ActionListener correctly, but I didn't execute the Dialog1 and because of that, when the sub that I used to setup the listener ended, my macro automatically went to the disposing method;
2. When you want to use a listener or handler (with the exception of the disposing method), methods that provide effective action must be used through a function instead of subs, right?

I'm still finishing my project, but as soon as I finish it, I will make it available for download. Thanks in advance for your attention!!!
LibreOffice Version: 5.2.7.2
Windows 7 Ultimate Service Pack 1 x64
MrM_Brazilian
 
Posts: 2
Joined: Thu Jul 20, 2017 2:43 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests