You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Andrew Pitonyak <an...@pitonyak.org> on 2022/06/17 13:31:47 UTC
Re: How to access UNO_CONSTANTS definitions via OLE/COM? (Re: Windows version: ProgIDs and typelibs for OLE/COM ?
This is how I get the manager using Basic:
Get the type description manager from the default context; see section 10.4 Context, which also shows how to enumerate all of the singleton objects available.
Function GetTypeDescriptionManager()
Dim sTDMName$ ' Name of the type description manager.
sTDMName = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"
GetTypeDescriptionManager() = GetDefaultContext().getValueByName(sTDMName)
End Function
The following method enumerates all “things” in the com.sun.star.awt module.
Sub EnumerateTypesTest
Dim oTDM ' Type Description Manager.
Dim oTDE ' Type Description Enumerations.
Dim oTD ' One Type Description.
Dim typeArray ' Types for which descriptions are returned.
Dim s$ ' Utility string variable.
REM All supported types.
typeArray = Array(com.sun.star.uno.TypeClass.VOID, _
com.sun.star.uno.TypeClass.CHAR, _
com.sun.star.uno.TypeClass.BOOLEAN, _
com.sun.star.uno.TypeClass.BYTE, _
com.sun.star.uno.TypeClass.SHORT, _
com.sun.star.uno.TypeClass.UNSIGNED_SHORT, _
com.sun.star.uno.TypeClass.LONG, _
com.sun.star.uno.TypeClass.UNSIGNED_LONG, _
com.sun.star.uno.TypeClass.HYPER, _
com.sun.star.uno.TypeClass.UNSIGNED_HYPER, _
com.sun.star.uno.TypeClass.FLOAT, _
com.sun.star.uno.TypeClass.DOUBLE, _
com.sun.star.uno.TypeClass.STRING, _
com.sun.star.uno.TypeClass.TYPE, _
com.sun.star.uno.TypeClass.ANY, _
com.sun.star.uno.TypeClass.ENUM, _
com.sun.star.uno.TypeClass.TYPEDEF, _
com.sun.star.uno.TypeClass.STRUCT, _
com.sun.star.uno.TypeClass.UNION, _
com.sun.star.uno.TypeClass.EXCEPTION, _
com.sun.star.uno.TypeClass.SEQUENCE, _
com.sun.star.uno.TypeClass.ARRAY, _
com.sun.star.uno.TypeClass.INTERFACE, _
com.sun.star.uno.TypeClass.SERVICE, _
com.sun.star.uno.TypeClass.MODULE, _
com.sun.star.uno.TypeClass.INTERFACE_METHOD, _
com.sun.star.uno.TypeClass.INTERFACE_ATTRIBUTE, _
com.sun.star.uno.TypeClass.UNKNOWN, _
com.sun.star.uno.TypeClass.PROPERTY, _
com.sun.star.uno.TypeClass.CONSTANT, _
com.sun.star.uno.TypeClass.CONSTANTS, _
com.sun.star.uno.TypeClass.SINGLETON)
oTDM = GetTypeDescriptionManager()
Dim sBaseName$ : sBaseName = "com.sun.star.awt"
' Change com.sun.star.reflection.TypeDescriptionSearchDepth.ONE
' to com.sun.star.reflection.TypeDescriptionSearchDepth.INFINITE
' to traverse more than a single level.
oTDE = oTDM.createTypeDescriptionEnumeration(sBaseName, _
typeArray, _
com.sun.star.reflection.TypeDescriptionSearchDepth.ONE)
While oTDE.hasMoreElements()
oTD = oTDE.nextTypeDescription()
s$ = s & oTD.Name & CHR$(10)
Wend
MsgBox s
End Sub
To get the information on a specific fully qualified type, use the following macro (adapted from an example by Bernard Marcelly):
Function GetOOoConst(constString)
Dim sTDMName$
Dim oTDM
sTDMName = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"
oTDM = GetDefaultContext().getValueByName(sTDMName)
If oTDM.hasByHierarchicalName(constString) Then
GetOOoConst = oTDM.getByHierarchicalName(constString)
Else
MsgBox "Unrecognized name : " & constString, 16, "OOo API constant or enum"
End If
End Function
The method is usable to obtain constant and enumeration values from a text string
Print GetOOoConst("com.sun.star.awt.FontSlant.ITALIC")
This can also return an object that describes the type. This can be used to enumerate the values and the strings.
Sub EnumerateEnumerations(sName$)
Dim oTD ' One Type Description.
Dim oTDE ' Element enumeration
Dim s$ ' Utility string variable.
Dim sNames
Dim lValues
Dim i As Long
Dim iCount As Integer
oTD = GetOOoConst(sName)
If IsNull(oTD) OR IsEmpty(oTD) Then
Exit Sub
End If
If HasUnoInterfaces(oTD, "com.sun.star.reflection.XEnumTypeDescription") Then
'MsgBox Join( oTD.getEnumNames(), CHR$(10))
sNames = oTD.getEnumNames()
lValues = otd.getEnumValues()
For i = LBound(sNames) To UBound(sNames)
iCount = iCount + 1
If (iCount > 40) Then
MsgBox(s)
s = ""
End If
s = s & lValues(i) & CHR$(9) & sNames(i) & CHR$(10)
Next
ElseIf HasUnoInterfaces(oTD, "com.sun.star.reflection.XConstantsTypeDescription") Then
lValues = oTD.getConstants()
For i = LBound(lValues) To UBound(lValues)
iCount = iCount + 1
If (iCount > 40) Then
MsgBox(s)
s = ""
End If
s = s & lValues(i).getConstantValue() & CHR$(9) & lValues(i).getName() & CHR$(10)
Next
Else
'Inspect oTD
MsgBox "Unsupported type " & sName
Exit Sub
End If
MsgBox s
End Sub
This can be used to see enumerations.
EnumerateEnumerations("com.sun.star.awt.FontSlant")
This can be used to see constant groups.
EnumerateEnumerations("com.sun.star.awt.FontWeight")
Hope this helps a little!
On Friday, June 17, 2022 07:36 EDT, "Rony G. Flatscher (Apache)" <ro...@apache.org> wrote:
OK, it is possible using "/singletons/com.sun.star.reflection.theTypeDescriptionManager". (Will have
to look further into it to maybe use it also for UNO_ENUM and the like.)
---rony
On 17.06.2022 12:46, Rony G. Flatscher wrote:
> In the process of creating a few nutshell examples using OLE/COM.
>
> One open problem is how to get to the UNO_CONSTANTS via the OLE/COM bridge. Here a snippet and its
> output (the tilde is the message operator in ooRexx and could be replaced by a dot for JScript and
> the like; .nil is the singleton object with the string value "The NIL object" to represent null):
>
> factory = .OLEObject~new('com.sun.star.ServiceManager')
> coreReflection = factory~createInstance("com.sun.star.reflection.CoreReflection")
>
> clzName="com.sun.star.table.CellHoriJustify"
> say clzName":" "(UNO_ENUM)"
> type=coreReflection~forName(clzName)
> say "type:" type "type~getName:" type~getname "(forName)"
> do f over type~getFields -- iterate over all fields
> say f~getName":" f~get(.nil) -- show name and get the value
> end
> say
> type=coreReflection~getType(clzName)
> say "type:" type "type~getName:" type~getname "(getType)"
>
> say "-"~copies(79)
> say
> clzName="com.sun.star.awt.FontWeight"
> say clzName":" "(UNO_CONSTANTS)"
> type=coreReflection~forName(clzName)
> say "type:" type "(forName)"
> say
> type=coreReflection~getType(clzName)
> say "type:" type "type~getName:" type~getname "(getType)"
>
> The output is:
>
> com.sun.star.table.CellHoriJustify: (UNO_ENUM)
> type: an OLEObject type~getName: com.sun.star.table.CellHoriJustify (forName)
> STANDARD: 0
> LEFT: 1
> CENTER: 2
> RIGHT: 3
> BLOCK: 4
> REPEAT: 5
>
> type: an OLEObject type~getName: string (getType)
> -------------------------------------------------------------------------------
>
> com.sun.star.awt.FontWeight: (UNO_CONSTANTS)
> type: The NIL object (forName)
>
> type: an OLEObject type~getName: string (getType)
>
> So using CoreReflection does not allow one to reflect UNO_CONSTANTS (forName() returns null).
>
> Using getType() will return "string" for both, UNO_ENUM and UNO_CONSTANTS.
>
> ---
>
> Would anyone have an idea how to use OLE/COM to get at the fields and values for UNO_CONSTANTS
> like FontWeight (getting the UNO_CONSTANT value for BOLD other than manually via
> <https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/FontWeight.html>)?
>
> ---rony
>
> P.S.: In the process of creating OLE/COM nutshell examples for scalc, swriter and simpress.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: How to access UNO_CONSTANTS definitions via OLE/COM? (Re: Windows version: ProgIDs and typelibs for OLE/COM ?
Posted by "Rony G. Flatscher (Apache)" <ro...@apache.org>.
Hi Andrew,
thank you *very* much indeed!
Your code gives much help already to save me a lot of research, so kudos to you! (E.g. from your
code it is clear that one can use the same code for fetching constant and enum values, which is
already very helpful per se!)
Will experiment a little bit before proceeding with the nutshell OLE/COM samples. Some abilities are
not directly available in the context, if a script is run outside of AOO using OLE/COM such as
GetDefaultContext(), however it is possible to fetch it from the service manager with
serviceManager.DefaultContext(). Or it would not be possible to reference the enum values for the
TypeClass in such a handy manner. However, it is very feasible to get at that information (and
others) one way or the other.
Again, thank you very much!
---rony
On 17.06.2022 15:31, Andrew Pitonyak wrote:
> This is how I get the manager using Basic:
>
> Get the type description manager from the default context; see section 10.4 Context, which also shows how to enumerate all of the singleton objects available.
> Function GetTypeDescriptionManager()
> Dim sTDMName$ ' Name of the type description manager.
> sTDMName = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"
> GetTypeDescriptionManager() = GetDefaultContext().getValueByName(sTDMName)
> End Function
>
> The following method enumerates all “things” in the com.sun.star.awt module.
>
> Sub EnumerateTypesTest
> Dim oTDM ' Type Description Manager.
> Dim oTDE ' Type Description Enumerations.
> Dim oTD ' One Type Description.
> Dim typeArray ' Types for which descriptions are returned.
> Dim s$ ' Utility string variable.
>
> REM All supported types.
> typeArray = Array(com.sun.star.uno.TypeClass.VOID, _
> com.sun.star.uno.TypeClass.CHAR, _
> com.sun.star.uno.TypeClass.BOOLEAN, _
> com.sun.star.uno.TypeClass.BYTE, _
> com.sun.star.uno.TypeClass.SHORT, _
> com.sun.star.uno.TypeClass.UNSIGNED_SHORT, _
> com.sun.star.uno.TypeClass.LONG, _
> com.sun.star.uno.TypeClass.UNSIGNED_LONG, _
> com.sun.star.uno.TypeClass.HYPER, _
> com.sun.star.uno.TypeClass.UNSIGNED_HYPER, _
> com.sun.star.uno.TypeClass.FLOAT, _
> com.sun.star.uno.TypeClass.DOUBLE, _
> com.sun.star.uno.TypeClass.STRING, _
> com.sun.star.uno.TypeClass.TYPE, _
> com.sun.star.uno.TypeClass.ANY, _
> com.sun.star.uno.TypeClass.ENUM, _
> com.sun.star.uno.TypeClass.TYPEDEF, _
> com.sun.star.uno.TypeClass.STRUCT, _
> com.sun.star.uno.TypeClass.UNION, _
> com.sun.star.uno.TypeClass.EXCEPTION, _
> com.sun.star.uno.TypeClass.SEQUENCE, _
> com.sun.star.uno.TypeClass.ARRAY, _
> com.sun.star.uno.TypeClass.INTERFACE, _
> com.sun.star.uno.TypeClass.SERVICE, _
> com.sun.star.uno.TypeClass.MODULE, _
> com.sun.star.uno.TypeClass.INTERFACE_METHOD, _
> com.sun.star.uno.TypeClass.INTERFACE_ATTRIBUTE, _
> com.sun.star.uno.TypeClass.UNKNOWN, _
> com.sun.star.uno.TypeClass.PROPERTY, _
> com.sun.star.uno.TypeClass.CONSTANT, _
> com.sun.star.uno.TypeClass.CONSTANTS, _
> com.sun.star.uno.TypeClass.SINGLETON)
>
> oTDM = GetTypeDescriptionManager()
>
> Dim sBaseName$ : sBaseName = "com.sun.star.awt"
>
> ' Change com.sun.star.reflection.TypeDescriptionSearchDepth.ONE
> ' to com.sun.star.reflection.TypeDescriptionSearchDepth.INFINITE
> ' to traverse more than a single level.
> oTDE = oTDM.createTypeDescriptionEnumeration(sBaseName, _
> typeArray, _
> com.sun.star.reflection.TypeDescriptionSearchDepth.ONE)
>
> While oTDE.hasMoreElements()
> oTD = oTDE.nextTypeDescription()
> s$ = s & oTD.Name & CHR$(10)
> Wend
> MsgBox s
> End Sub
>
> To get the information on a specific fully qualified type, use the following macro (adapted from an example by Bernard Marcelly):
>
> Function GetOOoConst(constString)
> Dim sTDMName$
> Dim oTDM
>
> sTDMName = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"
> oTDM = GetDefaultContext().getValueByName(sTDMName)
>
> If oTDM.hasByHierarchicalName(constString) Then
> GetOOoConst = oTDM.getByHierarchicalName(constString)
> Else
> MsgBox "Unrecognized name : " & constString, 16, "OOo API constant or enum"
> End If
> End Function
>
> The method is usable to obtain constant and enumeration values from a text string
>
> Print GetOOoConst("com.sun.star.awt.FontSlant.ITALIC")
>
> This can also return an object that describes the type. This can be used to enumerate the values and the strings.
>
> Sub EnumerateEnumerations(sName$)
> Dim oTD ' One Type Description.
> Dim oTDE ' Element enumeration
> Dim s$ ' Utility string variable.
> Dim sNames
> Dim lValues
> Dim i As Long
> Dim iCount As Integer
>
>
> oTD = GetOOoConst(sName)
> If IsNull(oTD) OR IsEmpty(oTD) Then
> Exit Sub
> End If
>
> If HasUnoInterfaces(oTD, "com.sun.star.reflection.XEnumTypeDescription") Then
>
> 'MsgBox Join( oTD.getEnumNames(), CHR$(10))
> sNames = oTD.getEnumNames()
> lValues = otd.getEnumValues()
> For i = LBound(sNames) To UBound(sNames)
> iCount = iCount + 1
> If (iCount > 40) Then
> MsgBox(s)
> s = ""
> End If
> s = s & lValues(i) & CHR$(9) & sNames(i) & CHR$(10)
> Next
> ElseIf HasUnoInterfaces(oTD, "com.sun.star.reflection.XConstantsTypeDescription") Then
> lValues = oTD.getConstants()
> For i = LBound(lValues) To UBound(lValues)
> iCount = iCount + 1
> If (iCount > 40) Then
> MsgBox(s)
> s = ""
> End If
> s = s & lValues(i).getConstantValue() & CHR$(9) & lValues(i).getName() & CHR$(10)
> Next
> Else
> 'Inspect oTD
> MsgBox "Unsupported type " & sName
> Exit Sub
> End If
> MsgBox s
> End Sub
>
> This can be used to see enumerations.
>
> EnumerateEnumerations("com.sun.star.awt.FontSlant")
>
> This can be used to see constant groups.
>
> EnumerateEnumerations("com.sun.star.awt.FontWeight")
>
> Hope this helps a little!
>
>
> On Friday, June 17, 2022 07:36 EDT, "Rony G. Flatscher (Apache)" <ro...@apache.org> wrote:
> OK, it is possible using "/singletons/com.sun.star.reflection.theTypeDescriptionManager". (Will have
> to look further into it to maybe use it also for UNO_ENUM and the like.)
>
> ---rony
>
>
> On 17.06.2022 12:46, Rony G. Flatscher wrote:
>> In the process of creating a few nutshell examples using OLE/COM.
>>
>> One open problem is how to get to the UNO_CONSTANTS via the OLE/COM bridge. Here a snippet and its
>> output (the tilde is the message operator in ooRexx and could be replaced by a dot for JScript and
>> the like; .nil is the singleton object with the string value "The NIL object" to represent null):
>>
>> factory = .OLEObject~new('com.sun.star.ServiceManager')
>> coreReflection = factory~createInstance("com.sun.star.reflection.CoreReflection")
>>
>> clzName="com.sun.star.table.CellHoriJustify"
>> say clzName":" "(UNO_ENUM)"
>> type=coreReflection~forName(clzName)
>> say "type:" type "type~getName:" type~getname "(forName)"
>> do f over type~getFields -- iterate over all fields
>> say f~getName":" f~get(.nil) -- show name and get the value
>> end
>> say
>> type=coreReflection~getType(clzName)
>> say "type:" type "type~getName:" type~getname "(getType)"
>>
>> say "-"~copies(79)
>> say
>> clzName="com.sun.star.awt.FontWeight"
>> say clzName":" "(UNO_CONSTANTS)"
>> type=coreReflection~forName(clzName)
>> say "type:" type "(forName)"
>> say
>> type=coreReflection~getType(clzName)
>> say "type:" type "type~getName:" type~getname "(getType)"
>>
>> The output is:
>>
>> com.sun.star.table.CellHoriJustify: (UNO_ENUM)
>> type: an OLEObject type~getName: com.sun.star.table.CellHoriJustify (forName)
>> STANDARD: 0
>> LEFT: 1
>> CENTER: 2
>> RIGHT: 3
>> BLOCK: 4
>> REPEAT: 5
>>
>> type: an OLEObject type~getName: string (getType)
>> -------------------------------------------------------------------------------
>>
>> com.sun.star.awt.FontWeight: (UNO_CONSTANTS)
>> type: The NIL object (forName)
>>
>> type: an OLEObject type~getName: string (getType)
>>
>> So using CoreReflection does not allow one to reflect UNO_CONSTANTS (forName() returns null).
>>
>> Using getType() will return "string" for both, UNO_ENUM and UNO_CONSTANTS.
>>
>> ---
>>
>> Would anyone have an idea how to use OLE/COM to get at the fields and values for UNO_CONSTANTS
>> like FontWeight (getting the UNO_CONSTANT value for BOLD other than manually via
>> <https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/FontWeight.html>)?
>>
>> ---rony
>>
>> P.S.: In the process of creating OLE/COM nutshell examples for scalc, swriter and simpress.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org