How to access the settings under the 'Events' tab of a form control to get / set the routines?

I tried to put all the keywords into the subject here, and therefore there isn’t much detail to add.
If I didn’t word the question clear enough, please tell what’s missing.

===Edit 2020-01-04 about 11:30UTC===
This may be regarded a new question, but in fact I got answers concerning how to set an event method for a given EventType, but not about how the EventTypes available for a specific control can be listed.
Or is it “simple”, and the ListenerTypes are always just 3 (XApproveActionListener, XActionListener, XMouseListener) - and the rest is left to the called code.

I’m not sure it this helps you:

Sub AddButton(oDoc, oSheet, oCol%, oRow%, nam$, label$, macro$)
Dim vCell, oDrawPage, oControlShape, oButtonModel, sScriptURL$, oForm, oSize
Dim aEvent As new com.sun.star.script.ScriptEventDescriptor

	oDrawPage = oSheet.DrawPage

	oControlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape") 
	vCell = oSheet.getCellByPosition(oCol, oRow)
	oControlShape.setPosition(vCell.Position)
	oSize = vCell.Size
	oSize.Height = oSize.Height - 50
	oControlShape.setSize(oSize)

	oButtonModel = CreateUnoService("com.sun.star.form.component.CommandButton") 
	oButtonModel.Label = label
	oButtonModel.VerticalAlign = com.sun.star.style.VerticalAlignment.MIDDLE
	oButtonModel.Name = nam
	oButtonModel.Tag = "1234567889r565"
	oButtonModel.Printable = False

	oControlShape.setControl(oButtonModel)
	oDrawPage.add(oControlShape)

	sScriptURL = "vnd.sun.star.script:MyLibrary." & macro & "?language=Basic&location=document"
	oForm = oDrawPage.getForms().getByIndex(0)
	With aEvent
		.AddListenerParam = ""
		.EventMethod = "actionPerformed"
		.ListenerType = "XActionListener"
		.ScriptCode = sScriptURL
		.ScriptType = "Script"
	End With
	oForm.registerScriptEvent(oForm.Count-1, aEvent)

	oControlShape.Anchor = vCell
	oControlShape.MoveProtect = True

	oDoc.CurrentController.setFormDesignMode(false)
End Sub

(adapted from Возможно ли создать многостраничную форму в LO Base : Открытые офисные пакеты. Форум поддержки пользователей)

Hmmm. I didn’t completely understand the Russian posts. :wink:
Thanks. This seems to affirm that the second tab of the UI window ‘Control Properties…’ doesn’t show properties accessible via the API from the control object, but an extract from the properties of the Form the control is contained in, ruled by the index of the control which must be obtained going a devious way in the user code. I wonder for what reason it’s done this way.
(Sorry for being late.)

Hello,

Have worked a bit with this based upon this post → How to programmatically get/set a form control’s events.

Have attached a sample Calc file based upon this to demo. Has four buttons. First is to display a message on click. Second and third buttons are to modify what macro is called by the first button and the message changes accordingly. The last button is to clear the macro completely from the first button. This is a problem as sometimes the clear button must be clicked two or even three times. Have tried various failed remedies in the macro but no complete resolution.

Also on a Sheet 2 of the document are most of the controls with associated Listener, Event Method and Control Event.

Edit:

Corrected sample -------------- ModifyButtonEvents.ods

Code cleaned up and fix applied to last button:

As the answer in the link states:

…you can’t just update the .ScriptCode property. You need to remove, then re-add the event.

Edit 2020-01-04:

@Lupp in regard to the listing of event types I will try to explain what I found.

There are more than three Listener Types. Have noted that in my sample provided there is a second sheet which lists most controls with the associated Listener, Event Method and Control Event. I have found no method to get these by simply examining a control. I actually created this listing by generating a control and attaching a macro to every event in that control.

After obtaining the index of the control (as you have in code in comment) used a simple routine to list the information:

aControlEvents = oObj1.getScriptEvents(controlIndex)
	LowBound = LBound(aControlEvents)
	UpBound = UBound(aControlEvents)
Row = 50
For x = LowBound to UpBound
    with aControlEvents(x)
        oSheet.GetCellRangeByName("C" & Row).String = .ListenerType
        oSheet.GetCellRangeByName("D" & Row).String = .EventMethod
        oSheet.GetCellRangeByName("E" & Row).String = .AddListenerParam
        oSheet.GetCellRangeByName("F" & Row).String = .ScriptType
        oSheet.GetCellRangeByName("G" & Row).String = .ScriptCode
    end with
    Row = Row + 1
Next

Did this for every control listed on Sheet2 of the sample and created the resulting matrix.

Edit #2 2020-01-04:

Updated sample ----- ModifyButtonEvents.ods

The mods were to Sheet2 which contain the events and now has all controls and added ClassID (control constant).

There are no events for a Hidden Control.

There are two ClassID #9’s - Text Box and Formatted Field.

(Sorry for being late.)
Thanks for the example.

Since it is approved now that the API doesn’t directly give access to the events assignet to a control:
I would prefer to get the needed index into the Form on a different way not relying on the .Name property:

Function getControlIndexIntoForm(pControlModel)
getControlIndexIntoForm = -1
On Local Error Goto fail
container = pControlModel.Parent
n = container.Count
For index = 0 To n - 1
  If EqualUnoObjects(pControlModel, container(index)) Then Exit For
Next index
getControlIndexIntoForm = index
fail:
End Function

@Ratslinger: Yes I saw the contingency matrix on Sheet2. Will take it to my _doc folder concerning LibO.Great thing. Myself I was much too lazy to do this.
This API reference page is listing 22 FormComponentType Constants, one of them a filler.
I couldn’t yet nap the differing names unambiguously.