[Solved] Use createUnoListener for checkbox

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
FDB
Posts: 14
Joined: Mon Oct 16, 2023 3:36 pm

[Solved] Use createUnoListener for checkbox

Post by FDB »

I have a dialog for querying a database. In this dialog I create a variable number of checkboxes. These checkboxes need to have a listener associated for detecting their state (on/off).
So far I managed to :

Code: Select all

for i = 1 to whatever
	checkbox = CreateUnoService ("stardiv.Toolkit.UnoCheckBoxControl")
	fixedTextModel = hDialog.Model.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
	checkbox.setModel(fixedTextModel)
	checkbox.setPosSize(430, deltaY*i+35-3, 25, 20, com.sun.star.awt.PosSize.POSSIZE)
	hDialog.addControl ("CheckBox"&format(i,"00"), checkbox)

	listener = createUnoListener("CB_", "com.sun.star.lang.XItemListener")
	cb.addItemListener(listener)
next i

Sub CB_notifyEvent(event as object)
End Sub
Sub CB_disposing(event as object)
End Sub
Sub CB_modified(event as object)
End Sub
Sub CB_itemStateChanged(event as object)
End Sub
However none of the CB_routines are triggered. I cannot find any documentation/examples of this.
Is "com.sun.star.lang.XItemListener" the correct way pf establishing a listener ?
What action routines should be declared ?

advTHANKSance
Last edited by MrProgrammer on Sat Jun 08, 2024 9:33 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.14
OSX 10.14.6 (Mojave)
JeJe
Volunteer
Posts: 2844
Joined: Wed Mar 09, 2016 2:40 pm

Re: createUnoListener for checkbox

Post by JeJe »

This is ready made for you - why not put a checkBox on the dialog in the IDE and use the item Status Changed event?

Put the maximum number of checkboxes you need on the dialog in the IDE and only show the ones required.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2844
Joined: Wed Mar 09, 2016 2:40 pm

Re: createUnoListener for checkbox

Post by JeJe »

See the attached document module 2 for your code corrected.

If you use MRI you can see you get Null for the listener and then can see you've named it wrong

Looking at the listener documentation, there is only one event

www.openoffice.org/api/docs/common/ref/ ... ckBox.html
http://www.openoffice.org/api/docs/comm ... tener.html

You also changed from "CheckBox." to "cb." in your loop.
Attachments
testCheckbox.odt
(11.89 KiB) Downloaded 24 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
FDB
Posts: 14
Joined: Mon Oct 16, 2023 3:36 pm

Re: createUnoListener for checkbox

Post by FDB »

I finally got the thing working :

Code: Select all

for i = 1 to whatever
	checkbox = CreateUnoService ("stardiv.Toolkit.UnoCheckBoxControl")
	fixedTextModel = hDialog.Model.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
	checkbox.setModel(fixedTextModel)
	checkbox.setPosSize(430, deltaY*i+35-3, 19, 20, com.sun.star.awt.PosSize.POSSIZE)	' x,y,width,height -  hiding LABEL
	listener = createUnoListener("CB_", "com.sun.star.awt.XItemListener")
	checkbox.addItemListener(listener)
	checkbox.setLabel ("CB" & format (i, "00"))
	hDialog.addControl ("CheckBox"&format(i,"00"), checkbox
next i

Sub CB_itemStateChanged(event as object)
	dim i, s
	s = event.source.model.label	' eg "CB05"
	i = cint (mid(s,3))
End Sub
OpenOffice 4.1.14
OSX 10.14.6 (Mojave)
JeJe
Volunteer
Posts: 2844
Joined: Wed Mar 09, 2016 2:40 pm

Re: createUnoListener for checkbox

Post by JeJe »

Make sure you keep the disposing sub - that's required.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply