wizards/source/scriptforge/SF_PythonHelper.xba |    6 
 wizards/source/scriptforge/SF_Session.xba      |   14 --
 wizards/source/scriptforge/SF_Utils.xba        |  166 +++++++++++++++++--------
 wizards/source/sfdatabases/SF_Database.xba     |    2 
 wizards/source/sfdialogs/SF_Dialog.xba         |    9 -
 wizards/source/sfdocuments/SF_Chart.xba        |    3 
 wizards/source/sfwidgets/SF_Menu.xba           |    2 
 wizards/source/sfwidgets/SF_MenuListener.xba   |    3 
 8 files changed, 135 insertions(+), 70 deletions(-)

New commits:
commit 2e3c34521d78cb738755ca93bebe606b0f627535
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Mon Apr 4 17:12:39 2022 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Tue Apr 5 18:52:05 2022 +0200

    ScriptForge - (SF_Utils) new _VarTypeObj() method
    
    The method is for internal use by the ScriptForge core only.
    
    The only argument is an object with VarType() = V_OBJECT.
    
    The purpose is to inspect thoroughly the argument
    and to return a
       Type _ObjectDescriptor
          iVarType As Integer
          sObjectType As String
       End Type
    The iVarType indicates if the object is either
     - a UNO object => sObjectType contains the UNO type ("com.sun.star. ...")
     - a ScriptForge class instance => sObjectType contains the class
     - another Basic object
     - Nothing (different from Null)
    
    Several existing methods benefit from the new method and are part
    of the commit.
    
    No effect on help pages.
    No effect on Python code.
    
    Change-Id: I69565d335b3aeb7c08c48cbccfc13d3d82f11ae1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132525
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba 
b/wizards/source/scriptforge/SF_PythonHelper.xba
index f8794673ee2e..c3d67d8764fc 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -192,7 +192,7 @@ Public Function PyDateAdd(ByVal Add As Variant _
 &apos;&apos;&apos;     Args:
 &apos;&apos;&apos;             Add: The unit to add
 &apos;&apos;&apos;             Count: how many times to add (might be negative)
-&apos;&apos;&apos;             DateArg: a date as a string in iso format
+&apos;&apos;&apos;             DateArg: a date as a com.sun.star.util.DateTime 
UNO structure
 &apos;&apos;&apos;     Returns:
 &apos;&apos;&apos;             The new date as a string in iso format
 &apos;&apos;&apos;     Example: (Python code)
@@ -597,6 +597,7 @@ Dim sServiceName As String                  &apos;  Alias 
of BasicObject.ServiceName
 Dim bBasicClass As Boolean                     &apos;  True when BasicObject 
is a class
 Dim sLibrary As String                         &apos;  Library where the 
object belongs to
 Dim bUno As Boolean                                    &apos;  Return value is 
a UNO object
+Dim oObjDesc As Object                         &apos;  _ObjectDescriptor type
 Dim iDims As Integer                           &apos;  # of dims of vReturn
 Dim sess As Object                                     :       Set sess = 
ScriptForge.SF_Session
 Dim i As Long, j As Long
@@ -901,7 +902,8 @@ Try:
                &apos;  Uno or not Uno ?
                bUno = False
                If (CallType And cstUno) = cstUno Then          &apos;  UNO 
considered only when pre-announced in CallType
-                       If Len(sess.UnoObjectType(vReturn)) &gt; 0 Then bUno = 
True
+                       Set oObjDesc = SF_Utils._VarTypeObj(vReturn)
+                       bUno = ( oObjDesc.iVarType = V_UNOOBJECT )
                End If
                If bUno Then
                        ReDim vReturnArray(0 To 2)
diff --git a/wizards/source/scriptforge/SF_Session.xba 
b/wizards/source/scriptforge/SF_Session.xba
index f02a958768ce..dc15fe72c04a 100644
--- a/wizards/source/scriptforge/SF_Session.xba
+++ b/wizards/source/scriptforge/SF_Session.xba
@@ -873,8 +873,7 @@ Public Function UnoObjectType(Optional ByRef UnoObject As 
Variant) As String
 &apos;&apos;&apos;             com.sun.star. ... as a string
 &apos;&apos;&apos;             a zero-length string if identification was not 
successful
 
-Dim oService As Object                 &apos;  
com.sun.star.reflection.CoreReflection
-Dim vClass as Variant                  &apos;  
com.sun.star.reflection.XIdlClass
+Dim oObjDesc As Object                 &apos;  _ObjectDescriptor type
 Dim sObjectType As String              &apos;  Return value
 Const cstThisSub = &quot;Session.UnoObjectType&quot;
 Const cstSubArgs = &quot;UnoObject&quot;
@@ -887,15 +886,8 @@ Check:
        If IsNull(UnoObject) Then GoTo Finally
 
 Try:
-       On Local Error Resume Next
-       &apos;  Try usual ImplementationName method
-       sObjectType = UnoObject.getImplementationName()
-       If sObjectType = &quot;&quot; Then
-               &apos;  Now try CoreReflection trick
-               Set oService = 
SF_Utils._GetUNOService(&quot;CoreReflection&quot;)
-               vClass = oService.getType(UnoObject)
-               If vClass.TypeClass &gt;= com.sun.star.uno.TypeClass.STRUCT  
Then sObjectType = vClass.Name
-       End If
+       Set oObjDesc = SF_Utils._VarTypeObj(UnoObject)
+       If oObjDesc.iVarType = V_UNOOBJECT Then sObjectType = 
oObjDesc.sObjectType
 
 Finally:
        UnoObjectType = sObjectType
diff --git a/wizards/source/scriptforge/SF_Utils.xba 
b/wizards/source/scriptforge/SF_Utils.xba
index bcf0c81d76a5..127329c7e78b 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -24,26 +24,36 @@ Global _SF_         As Variant              &apos;  SF_Root 
(Basic) object)
 Const SF_Version = &quot;7.4&quot;
 
 &apos;&apos;&apos;     Standard symbolic names for VarTypes
-&apos;                         V_EMPTY = 0
-&apos;                         V_NULL = 1
-&apos;                         V_INTEGER = 2
-&apos;                         V_LONG = 3
-&apos;                         V_SINGLE = 4
-&apos;                         V_DOUBLE = 5
-&apos;                         V_CURRENCY = 6
-&apos;                         V_DATE = 7
-&apos;                         V_STRING = 8
+&apos;                         V_EMPTY                 = 0
+&apos;                         V_NULL                  = 1
+&apos;                         V_INTEGER               = 2
+&apos;                         V_LONG                  = 3
+&apos;                         V_SINGLE                = 4
+&apos;                         V_DOUBLE                = 5
+&apos;                         V_CURRENCY              = 6
+&apos;                         V_DATE                  = 7
+&apos;                         V_STRING                = 8
 &apos;&apos;&apos;     Additional symbolic names for VarTypes
-Global Const   V_OBJECT = 9
-Global Const   V_BOOLEAN = 11
-Global Const   V_VARIANT = 12
-Global Const   V_BYTE = 17
-Global Const   V_USHORT = 18
-Global Const   V_ULONG = 19
-Global Const   V_BIGINT = 35
-Global Const   V_DECIMAL = 37
-Global Const   V_ARRAY = 8192
-Global Const   V_NUMERIC = 99          &apos; Fictive VarType synonym of any 
numeric value
+Global Const   V_OBJECT                = 9
+Global Const   V_BOOLEAN               = 11
+Global Const   V_VARIANT               = 12
+Global Const   V_BYTE                  = 17
+Global Const   V_USHORT                = 18
+Global Const   V_ULONG                 = 19
+Global Const   V_BIGINT                = 35
+Global Const   V_DECIMAL               = 37
+Global Const   V_ARRAY                 = 8192
+&apos;&apos;&apos;     Fictive VarTypes
+Global Const   V_NUMERIC               = 99    &apos; Synonym of any numeric 
value [returned by _VarTypeExt()]
+Global Const   V_NOTHING               = 101   &apos; Object categories 
[returned by _VarTypeObj()]            Null object
+Global Const   V_UNOOBJECT             = 102   &apos;                          
                                                                        Uno 
object or Uno structure
+Global Const   V_SFOBJECT              = 103   &apos;                          
                                                                        
ScriptForge object: has ObjectType and ServiceName properties
+Global Const   V_BASICOBJECT   = 104   &apos;                                  
                                                                User Basic 
object
+
+Type _ObjectDescriptor                                 &apos; Returned by the 
_VarTypeObj() method
+       iVarType        As Integer                              &apos; One of 
the V_NOTHING, V_xxxOBJECT constants
+       sObjectType     As String                               &apos; Either 
&quot;&quot; or &quot;com.sun.star...&quot; or a ScriptForge object type (ex. 
&quot;SF_SESSION&quot; or &quot;DICTIONARY&quot;)
+End Type
 
 REM ================================================================== 
EXCEPTIONS
 
@@ -545,8 +555,7 @@ Public Function _Repr(ByVal pvArg As Variant, Optional 
ByVal plMax As Long) As S
 
 Dim sArg As String                     &apos;  Return value
 Dim oObject As Object          &apos;  Alias of argument to avoid &quot;Object 
variable not set&quot;
-Dim sObject As String          &apos;  Object representation
-Dim sObjectType As String      &apos;  ObjectType attribute of Basic objects
+Dim oObjectDesc As Object      &apos;  Object descriptor
 Dim sLength As String          &apos;  String length as a string
 Dim i As Long
 Const cstBasicObject = &quot;com.sun.star.script.NativeObjectWrapper&quot;
@@ -564,28 +573,22 @@ Const cstEtc = &quot; … &quot;
                        Case V_EMPTY                    :               sArg = 
&quot;[EMPTY]&quot;
                        Case V_NULL                             :               
sArg = &quot;[NULL]&quot;
                        Case V_OBJECT
-                               If IsNull(pvArg) Then
-                                       sArg = &quot;[NULL]&quot;
-                               Else
-                                       sObject = 
SF_Session.UnoObjectType(pvArg)
-                                       If sObject = &quot;&quot; Or sObject = 
cstBasicObject Then      &apos;  Not a UNO object
-                                               &apos;  Test if argument is a 
ScriptForge object
-                                               sObjectType = &quot;&quot;
-                                               On Local Error Resume Next
-                                               Set oObject = pvArg
-                                               sObjectType = oObject.ObjectType
-                                               On Error GoTo 0
-                                               If sObjectType = &quot;&quot; 
Then
+                               Set oObjectDesc = SF_Utils._VarTypeObj(pvArg)
+                               With oObjectDesc
+                                       Select Case .iVarType
+                                               Case V_NOTHING          :       
sArg = &quot;[NOTHING]&quot;
+                                               Case V_OBJECT, V_BASICOBJECT
                                                        sArg = 
&quot;[OBJECT]&quot;
-                                               ElseIf Left(sObjectType, 3) = 
&quot;SF_&quot; Then
-                                                       sArg = &quot;[&quot; 
&amp; sObjectType &amp; &quot;]&quot;
-                                               Else
-                                                       sArg = oObject._Repr()
-                                               End If
-                                       Else
-                                               sArg = &quot;[&quot; &amp; 
sObject &amp; &quot;]&quot;
-                                       End If
-                               End If
+                                               Case V_UNOOBJECT        :       
sArg = &quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
+                                               Case V_SFOBJECT
+                                                       If Left(.sObjectType, 
3) = &quot;SF_&quot; Then &apos;  Standard module
+                                                               sArg = 
&quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
+                                                       Else                    
                                                &apos;  Class module must have 
a _Repr() method
+                                                               Set oObject = 
pvArg
+                                                               sArg = 
oObject._Repr()
+                                                       End If
+                                       End Select
+                               End With
                        Case V_VARIANT                  :               sArg = 
&quot;[VARIANT]&quot;
                        Case V_STRING
                                sArg = SF_String._Repr(pvArg)
@@ -734,9 +737,9 @@ Public Function _Validate(Optional ByRef pvArgument As 
Variant _
 &apos;&apos;&apos;     Exceptions:
 &apos;&apos;&apos;             ARGUMENTERROR
 
-Dim iVarType As Integer                &apos;  Extended VarType of argument
-Dim bValid As Boolean          &apos;  Returned value
-Dim oArgument As Variant       &apos;  Workaround &quot;Object variable not 
set&quot; error on 1st executable statement
+Dim iVarType As Integer                        &apos;  Extended VarType of 
argument
+Dim bValid As Boolean                  &apos;  Returned value
+Dim oObjectDescriptor As Object        &apos;  _ObjectDescriptor type
 Const cstMaxLength = 256       &apos;  Maximum length of readable value
 Const cstMaxValues = 10                &apos;  Maximum number of allowed items 
to list in an error message 
 
@@ -772,8 +775,10 @@ Try:
                End If
                &apos;  Check instance types
                If bValid And Len(pvObjectType) &gt; 0 And iVarType = V_OBJECT 
Then
-                       Set oArgument = pvArgument
-                       bValid = ( pvObjectType = oArgument.ObjectType )
+                       &apos;Set oArgument = pvArgument
+                       Set oObjectDescriptor = SF_Utils._VarTypeObj(pvArgument)
+                       bValid = ( oObjectDescriptor.iVarType = V_SFOBJECT )
+                       If bValid Then bValid = ( oObjectDescriptor.sObjectType 
= pvObjectType )
                End If
        End If
 
@@ -1034,5 +1039,72 @@ Dim iType As Integer     &apos;  VarType of argument
 
 End Function   &apos;  ScriptForge.SF_Utils._VarTypeExt
 
+REM 
-----------------------------------------------------------------------------
+Public Function _VarTypeObj(ByRef pvValue As Variant) As Object
+&apos;&apos;&apos;     Inspect the argument that is supposed to be an Object
+&apos;&apos;&apos;     Return the internal type of object as one of the values
+&apos;&apos;&apos;             V_NOTHING               Null object
+&apos;&apos;&apos;             V_UNOOBJECT             Uno object or Uno 
structure
+&apos;&apos;&apos;             V_SFOBJECT              ScriptForge object: has 
ObjectType and ServiceName properties
+&apos;&apos;&apos;             V_BASICOBJECT   User Basic object
+&apos;&apos;&apos;     coupled withe object type as a string 
(&quot;com.sun.star...&quot; or &quot;SF_...&quot; or &quot;... ScriptForge 
class ...&quot;)
+&apos;&apos;&apos;     When the argument is not an Object, return the usual 
VarType() of the argument
+
+Dim oObjDesc As _ObjectDescriptor      &apos;  Return value
+Dim oValue As Object                           &apos;  Alias of pvValue used 
to avoid &quot;Object variable not set&quot; error
+Dim sObjType As String                         &apos;  The type of object is 
first derived as a string
+Dim oReflection As Object                      &apos;  
com.sun.star.reflection.CoreReflection
+Dim vClass As Variant                          &apos;  
com.sun.star.reflection.XIdlClass
+Dim bUno As Boolean                                    &apos;  True when 
object recognized as UNO object
+
+Const cstBasicClass = &quot;com.sun.star.script.NativeObjectWrapper&quot;      
        &apos;  Way to recognize Basic objects
+
+       On Local Error Resume Next      &apos;  Object type is established by 
trial and error
+
+Try:
+       With oObjDesc
+               .iVarType = VarType(pvValue)
+               .sObjectType = &quot;&quot;
+               bUno = False
+               If .iVarType = V_OBJECT Then
+                       If IsNull(pvValue) Then
+                               .iVarType = V_NOTHING
+                       Else
+                               Set oValue = pvValue
+                               &apos;  Try UNO type with usual 
ImplementationName property
+                               .sObjectType = oValue.getImplementationName()
+                               If .sObjectType = &quot;&quot; Then
+                                       &apos;  Try UNO type with alternative 
CoreReflection trick
+                                       Set oReflection = 
SF_Utils._GetUNOService(&quot;CoreReflection&quot;)
+                                       vClass = oReflection.getType(oValue)
+                                       If vClass.TypeClass &gt;= 
com.sun.star.uno.TypeClass.STRUCT  Then
+                                               .sObjectType = vClass.Name
+                                               bUno = True
+                                       End If
+                               Else
+                                       bUno = True
+                               End If
+                               &apos;  Identify Basic objects
+                               If .sObjectType = cstBasicClass Then
+                                       bUno = False
+                                       &apos;  Try if the Basic object has an 
ObjectType property
+                                       .sObjectType = oValue.ObjectType
+                               End If
+                               &apos;  Derive the return value from the object 
type
+                               Select Case True
+                                       Case Len(.sObjectType) = 0              
        &apos;  Do nothing (return V_OBJECT)
+                                       Case .sObjectType = cstBasicClass       
:       .iVarType = V_BASICOBJECT
+                                       Case bUno                               
                        :       .iVarType = V_UNOOBJECT
+                                       Case Else                               
                        :       .iVarType = V_SFOBJECT
+                               End Select
+                       End If
+               End If
+       End With
+
+Finally:
+       Set _VarTypeObj = oObjDesc
+       Exit Function
+End Function   &apos;  ScriptForge.SF_Utils._VarTypeObj
+
 REM ================================================= END OF 
SCRIPTFORGE.SF_UTILS
 </script:module>
\ No newline at end of file
diff --git a/wizards/source/sfdatabases/SF_Database.xba 
b/wizards/source/sfdatabases/SF_Database.xba
index 6d3aa99f6381..804084aff28e 100644
--- a/wizards/source/sfdatabases/SF_Database.xba
+++ b/wizards/source/sfdatabases/SF_Database.xba
@@ -822,4 +822,4 @@ Private Function _Repr() As String
 End Function   &apos;  SFDatabases.SF_Database._Repr
 
 REM ============================================ END OF SFDATABASES.SF_DATABASE
-</script:module>
+</script:module>
\ No newline at end of file
diff --git a/wizards/source/sfdialogs/SF_Dialog.xba 
b/wizards/source/sfdialogs/SF_Dialog.xba
index fea3eac98f8f..beb865b6a2dd 100644
--- a/wizards/source/sfdialogs/SF_Dialog.xba
+++ b/wizards/source/sfdialogs/SF_Dialog.xba
@@ -333,8 +333,8 @@ Public Function Center(Optional ByRef Parent As Variant) As 
Boolean
 &apos;&apos;&apos;             End Sub
 
 Dim bCenter As Boolean                         &apos;  Return value
-Dim oSession As Object                         &apos;  ScriptForge.SF_Session
 Dim oUi As Object                                      &apos;  
ScriptForge.SF_UI
+Dim oObjDesc As Object                         &apos;  _ObjectDescriptor type
 Dim sObjectType As String                      &apos;  Can be uno or sf object 
type
 Dim oParent As Object                          &apos;  UNO alias of parent
 Dim oParentPosSize As Object           &apos;  Parent 
com.sun.star.awt.Rectangle
@@ -356,15 +356,14 @@ Check:
 
        Set oParentPosSize = Nothing
        lParentX = 0    :       lParentY = 0
-       Set oSession = CreateScriptService(&quot;Session&quot;)
        If IsNull(Parent) Then
                Set oUi = CreateScriptService(&quot;UI&quot;)
                Set oParentPosSize = oUi._PosSize()     &apos;  Return the 
position and dimensions of the active window
        Else
                &apos;  Determine the object type
-               sObjectType = oSession.UnoObjectType(Parent)
-               If sObjectType = 
&quot;com.sun.star.script.NativeObjectWrapper&quot; Then               &apos;  
Basic object
-                       sObjectType = Parent.ObjectType
+               Set oObjDesc = ScriptForge.SF_Utils._VarTypeObj(Parent)
+               If oObjDesc.iVarType = ScriptForge.V_SFOBJECT Then              
&apos;  ScriptForge object
+                       sObjectType = oObjDesc.sObjectType
                        &apos;  Document or dialog ?
                        If Not 
ScriptForge.SF_Array.Contains(Array(&quot;BASE&quot;, &quot;CALC&quot;, 
&quot;DIALOG&quot;, &quot;DOCUMENT&quot;, &quot;WRITER&quot;), sObjectType, 
CaseSensitive := True) Then GoTo Finally
                        If sObjectType = &quot;DIALOG&quot; Then
diff --git a/wizards/source/sfdocuments/SF_Chart.xba 
b/wizards/source/sfdocuments/SF_Chart.xba
index a4cbf2f2ba28..0538fb8af758 100644
--- a/wizards/source/sfdocuments/SF_Chart.xba
+++ b/wizards/source/sfdocuments/SF_Chart.xba
@@ -429,10 +429,9 @@ Public Function Resize(Optional ByVal XPos As Variant _
 &apos;&apos;&apos;     Returns:
 &apos;&apos;&apos;             True when successful
 &apos;&apos;&apos;     Examples:
-&apos;&apos;&apos;             oChart.Resize(1000, 2000, Height = 6000)        
&apos;  Width is not changed
+&apos;&apos;&apos;             oChart.Resize(1000, 2000, Height := 6000)       
&apos;  Width is not changed
 
 Dim bResize As Boolean                         &apos;  Return value
-Dim oAddress As Object                         &apos;  Alias of Range
 Dim oPosition As Object                                &apos;  
com.sun.star.awt.Point
 Dim oSize As Object                                    &apos;  
com.sun.star.awt.Size
 Const cstThisSub = &quot;SFDocuments.Chart.Resize&quot;
diff --git a/wizards/source/sfwidgets/SF_Menu.xba 
b/wizards/source/sfwidgets/SF_Menu.xba
index d9f0bde0358a..c5f7ea6ad43a 100644
--- a/wizards/source/sfwidgets/SF_Menu.xba
+++ b/wizards/source/sfwidgets/SF_Menu.xba
@@ -587,4 +587,4 @@ Private Function _Repr() As String
 End Function   &apos;  SFWidgets.SF_Menu._Repr
 
 REM ============================================ END OF SFWIDGETS.SF_MENU
-</script:module>
+</script:module>
\ No newline at end of file
diff --git a/wizards/source/sfwidgets/SF_MenuListener.xba 
b/wizards/source/sfwidgets/SF_MenuListener.xba
index 462816cba4f5..6045f2dd8d96 100644
--- a/wizards/source/sfwidgets/SF_MenuListener.xba
+++ b/wizards/source/sfwidgets/SF_MenuListener.xba
@@ -93,6 +93,7 @@ Try:
                        Set oFrame = 
StarDesktop.CurrentComponent.CurrentController.Frame       &apos;  A menu has 
been clicked necessarily in the current window
                        Set oDispatcher = 
ScriptForge.SF_Utils._GetUNOService(&quot;DispatchHelper&quot;)
                        oDispatcher.executeDispatch(oFrame, sCommand, 
&quot;&quot;, 0, oArgs())
+                       oFrame.activate()
                Else
                        &apos;  Execute script
                        Set oSession = 
ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
@@ -125,4 +126,4 @@ Sub _SFMENU_disposing(Optional poEvent As Object)           
        &apos;  com.sun.star.awt.Menu
 End Sub                        &apos;  
SFWidgets.SF_MenuListener._SFMENU_disposing
 
 REM ============================================ END OF 
SFDIALOGS.SF_DIALOGLISTENER
-</script:module>
+</script:module>
\ No newline at end of file

Reply via email to