Search code examples
libreofficeopenoffice-basiclibreoffice-basic

How to get name & label of UnoCheckBoxControl?


I'd like to get the name and the label of some controls included in a dialog in LibreOffice Basic.

I can call getImplementationName() on my example controls.

I get these : stardiv.Toolkit.UnoEditControl, stardiv.Toolkit.UnoCheckBoxControl, stardiv.Toolkit.UnoRadioButtonControl.

What I'm interested in is the name of these controls, parametrized while building them with the GUI.

Here is my code :

Sub test()
    Dim Dlg As Object
    Dim Controls As Object
    Dim cControl As Object
    Dim I As Integer
    Dim A As String

    DialogLibraries.LoadLibrary("Standard")
    Dlg = CreateUnoDialog(DialogLibraries.Standard.BoiteDeDialogue1)

    Controls = Dlg.Controls

    I = 0
    A = ""
    For Each cControl In Controls
        I = I + 1
        A = A & cControl.getImplementationName()
        ' How to get back the name of cControl here ?
    Next cControl

    MsgBox "There is " & I & " controls in that form !" & A
End Sub

Solution

  • You should use a tool like XRAY ( https://wiki.documentfoundation.org/Macros). With this you can examine objects in detail. So you would have found that there is a Model (com.sun.star.awt.XControlModel) for each Control which contains the Name.

    ...
        For Each cControl In Controls
            I = I + 1
            'xray cControl
            A = A & cControl.getModel().Name ' To get back the name of cControl.
        Next cControl
    ...