ScriptForge - (UI) size and position of the active window

The UI service receives next 4 new properties:
  Height
  Width
  X
  Y

They all return a Long value representing the size or position
of the active window. The active window does not need to be a
document, it may f.i. be the Basic IDE.

Those properties are read-only.
To modify the size or the position of the window,
use the the Resize() method.

They are implemented for use from Basic and Python scripts.

Change-Id: I0021663e39612f411cefa5c7ec9ec594a4cb6f39
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131444
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
This commit is contained in:
Jean-Pierre Ledure
2022-03-12 15:57:52 +01:00
parent f2d07a3b17
commit ae24ce8c63
2 changed files with 64 additions and 1 deletions

View File

@@ -118,6 +118,14 @@ Dim oComp As Object &apos; com.sun.star.lang.XComponent
End Function &apos; ScriptForge.SF_UI.ActiveWindow
REM -----------------------------------------------------------------------------
Property Get Height() As Long
&apos;&apos;&apos; Returns the height of the active window
Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
Set oPosSize = SF_UI._PosSize()
If Not IsNull(oPosSize) Then Height = oPosSize.Height Else Height = -1
End Property &apos; ScriptForge.SF_UI.Height
REM -----------------------------------------------------------------------------
Property Get MACROEXECALWAYS As Integer
&apos;&apos;&apos; Macros are always executed
@@ -148,6 +156,30 @@ Property Get ServiceName As String
ServiceName = &quot;ScriptForge.UI&quot;
End Property &apos; ScriptForge.SF_UI.ServiceName
REM -----------------------------------------------------------------------------
Property Get Width() As Long
&apos;&apos;&apos; Returns the width of the active window
Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
Set oPosSize = SF_UI._PosSize()
If Not IsNull(oPosSize) Then Width = oPosSize.Width Else Width = -1
End Property &apos; ScriptForge.SF_UI.Width
REM -----------------------------------------------------------------------------
Property Get X() As Long
&apos;&apos;&apos; Returns the X coordinate of the active window
Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
Set oPosSize = SF_UI._PosSize()
If Not IsNull(oPosSize) Then X = oPosSize.X Else X = -1
End Property &apos; ScriptForge.SF_UI.X
REM -----------------------------------------------------------------------------
Property Get Y() As Long
&apos;&apos;&apos; Returns the Y coordinate of the active window
Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
Set oPosSize = SF_UI._PosSize()
If Not IsNull(oPosSize) Then Y = oPosSize.Y Else Y = -1
End Property &apos; ScriptForge.SF_UI.Y
REM ===================================================================== METHODS
REM -----------------------------------------------------------------------------
@@ -495,6 +527,11 @@ Check:
Try:
Select Case UCase(PropertyName)
Case &quot;ACTIVEWINDOW&quot; : GetProperty = ActiveWindow()
Case &quot;HEIGHT&quot; : GetProperty = SF_UI.Height
Case &quot;WIDTH&quot; : GetProperty = SF_UI.Width
Case &quot;X&quot; : GetProperty = SF_UI.X
Case &quot;Y&quot; : GetProperty = SF_UI.Y
Case Else
End Select
@@ -827,6 +864,10 @@ Public Function Properties() As Variant
Properties = Array( _
&quot;ActiveWindow&quot; _
, &quot;Height&quot; _
, &quot;Width&quot; _
, &quot;X&quot; _
, &quot;Y&quot; _
)
End Function &apos; ScriptForge.SF_UI.Properties
@@ -1272,6 +1313,28 @@ Catch:
GoTo Finally
End Function &apos; ScriptForge.SF_UI._IdentifyWindow
REM -----------------------------------------------------------------------------
Public Function _PosSize() As Object
&apos;&apos;&apos; Returns the PosSize structure of the active window
Dim vWindow As Window &apos; A single component
Dim oContainer As Object &apos; com.sun.star.awt.XWindow
Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
Set oPosSize = Nothing
Try:
vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
If Not IsNull(vWindow.Frame) Then
Set oContainer = vWindow.Frame.ContainerWindow
Set oPosSize = oContainer.getPosSize()
End If
Finally:
Set _PosSize = oPosSize
Exit Function
End Function &apos; ScriptForge.SF_UI._PosSize
REM -----------------------------------------------------------------------------
Private Function _Repr() As String
&apos;&apos;&apos; Convert the UI instance to a readable string, typically for debugging purposes (DebugPrint ...)

View File

@@ -1511,7 +1511,7 @@ class SFScriptForge:
serviceimplementation = 'basic'
servicename = 'ScriptForge.UI'
servicesynonyms = ('ui', 'scriptforge.ui')
serviceproperties = dict(ActiveWindow = False)
serviceproperties = dict(ActiveWindow = False, Height = False, Width = False, X = False, Y = False)
# Class constants
MACROEXECALWAYS, MACROEXECNEVER, MACROEXECNORMAL = 2, 1, 0