如何获取 Uno CheckBox 控件的名称和标签?

How to get name & label of UnoCheckBoxControl?

我想获取 LibreOffice Basic 对话框中包含的某些控件的名称和标签。

我可以在示例控件上调用 getImplementationName()

我得到这些:stardiv.Toolkit.UnoEditControlstardiv.Toolkit.UnoCheckBoxControlstardiv.Toolkit.UnoRadioButtonControl

我感兴趣的是这些控件的名称,在使用 GUI 构建它们时进行了参数化。

这是我的代码:

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

您应该使用像 XRAY 这样的工具 (https://wiki.documentfoundation.org/Macros)。有了它,您可以详细检查对象。因此,您会发现每个包含名称的控件都有一个模型 (com.sun.star.awt.XControlModel)。

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