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