How to bind an event handler to a button on a dialog

Creating a macro - Writing a Script - Using the API

How to bind an event handler to a button on a dialog

Postby lelynx » Sun May 18, 2008 11:00 am

Hi all,

I can't manage to have the following code snippet run ok.
Could you please help me?

Purpose: to insert by code a command button onto a dialog
and attach an onclick event handler to this button.

Result: the dialog is dispayed with the button.
A click on the button will give an error message: property or method will not exist.

TIA,

Philippe

Code: Select all   Expand viewCollapse view
dim mdlg as object
' ======================================================
Sub Main
' to get a reference to Dialog1
biblio=DialogLibraries.GetByName("Standard")
oFrm=biblio.getByName("Dialog1")
' instanciate the dialog
mdlg=createUNODialog(oFrm)
' to add a button and attach an event handler
call AjoutBouton( mdlg ,"monBtn" ,3 , 3  ,1)
' show the dialog
mdlg.execute
' close the dialog
'mdlg.endExecute
End Sub

Sub AjoutBouton( dialogue as object,nomBouton as string, positionX as integer,positionY as integer)

  Dim oDialogModel As Object , oButtonModel As Object
  NomObj = nomBouton 
  oDialogModel = dialogue.Model

  oButtonModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel" )

     With oButtonModel
       .Name = NomObj
       .Label = "affecter"
       .PushButtonType="STANDARD"
       .Tabstop = True
       .PositionX = positionX 'position horizontale
       .PositionY = positionY 'position verticale
       .Width = 27 'largeur
       .Height = 14 'hauteur
     End With
     ' to insert the button into the dialog
   oDialogModel.insertByName( NomObj , oButtonModel )

       ' create a listener

   oButtonControl = dialogue.getControl(NomObj)
   cEventListenerName =NomObj
   ' oActionListener = CreateUnoListener( cEventListenerName + "_", "com.sun.star.awt.XActionListener" )
   oActionListener = CreateUnoListener( "NomBouton_","com.sun.star.awt.XActionListener" )
   oButtonControl.addActionListener( oActionListener )
End Sub

' ===============Event handler==========================
public sub NomBouton_dispose(e as object) ' I tried _click, _onclick but unsuccessfully!
'on error resume next
   msgbox "Salut :" & e.source.model.name
end sub
lelynx
 
Posts: 6
Joined: Sat May 17, 2008 3:06 pm

Re: How to bind an event handler to a button on a dialog

Postby ms777 » Sun May 18, 2008 1:00 pm

Hi,

you need to implement all functions of the XActionListenr, not only dispose. You are missing the actionPerformed function.

For an example, see http://www.oooforum.org/forum/viewtopic ... 497#205497

Good luck,

ms777
ms777
Volunteer
 
Posts: 131
Joined: Mon Oct 08, 2007 1:33 am

Re: How to bind an event handler to a button on a dialog

Postby lelynx » Mon May 19, 2008 2:32 pm

Thank you, ms77, it greatly help me!
lelynx
 
Posts: 6
Joined: Sat May 17, 2008 3:06 pm

Re: How to bind an event handler to a button on a dialog

Postby batistaj » Fri Jun 07, 2019 7:26 pm

Hi lelynx
Your question is still very pertinent nowadays cause I'm finding the same trouble being novice to Libreoffice and I can't find the link posted by ms777.
Would you please give me a tip how did you solve de problem?
Thanks
Linux Mint 19.1
OOffice 4.1.6
batistaj
 
Posts: 2
Joined: Sat May 18, 2019 12:52 pm

Re: How to bind an event handler to a button on a dialog

Postby JeJe » Sat Jun 08, 2019 2:33 pm

Look at OpenOffice.org Macros Explained Third Edition, Listing 551

http://www.pitonyak.org/book/

Its a free download
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 580
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to bind an event handler to a button on a dialog

Postby batistaj » Sat Jun 08, 2019 7:49 pm

Thank you very much for the posted link.
After a weak of searching you put me in the right direction.
I'm setting hands on it.
Linux Mint 19.1
OOffice 4.1.6
batistaj
 
Posts: 2
Joined: Sat May 18, 2019 12:52 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests