wizards/source/scriptforge/SF_Region.xba | 10 - wizards/source/scriptforge/python/scriptforge.py | 9 + wizards/source/sfdialogs/SF_Dialog.xba | 184 +++++++++++++++++++++++ 3 files changed, 198 insertions(+), 5 deletions(-)
New commits: commit 7c8e9db0e488606baa27a654769a3906f35cc8cd Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Fri Apr 1 12:13:12 2022 +0200 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Fri Apr 1 14:09:40 2022 +0200 ScriptForge - (SF_Dialog) new Resize() and Center() methods The "dialog" service receives 2 new methods for easy move/resize of the concerned dialog. Resize(left, top, widt, height) Move the topleft corner of a dialog to new coordinates and/or modify its dimensions All distances are expressed in 1/100th mm Without arguments, the method resets the initial width and height Center(window) Center the actual dialog instance in the middle of a parent window Without arguments, the method centers the dialog in the middle of the active window The Parent argument can be either - a ScriptForge dialog object - a ScriptForge document (Calc, Base, ...) object Both methods are available from Basic and Python user scripts Change-Id: Ic3680739c9d518da3d76d3588943ae5ce6bad8ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132418 Tested-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> diff --git a/wizards/source/scriptforge/SF_Region.xba b/wizards/source/scriptforge/SF_Region.xba index 33a564b52a20..d3eacfae0982 100644 --- a/wizards/source/scriptforge/SF_Region.xba +++ b/wizards/source/scriptforge/SF_Region.xba @@ -13,7 +13,7 @@ Option Explicit ''' ========= ''' Singleton class implementing the "ScriptForge.Region" service ''' Implemented as a usual Basic module -''' +''' ''' A collection of functions about languages, countries and timezones ''' - Locales ''' - Currencies @@ -72,7 +72,7 @@ REM ================================================================== PROPERTIE REM ----------------------------------------------------------------------------- Property Get Country(Optional ByVal Region As Variant) As String ''' Returns the english country name applicable in the given region. -''' The region expressed either as a +''' The region expressed either as a ''' - locale combining language-COUNTRY (la-CO) ''' - country only (CO) ''' Example: @@ -83,7 +83,7 @@ End Property ' ScriptForge.SF_Region.Country (get) REM ----------------------------------------------------------------------------- Property Get Currency(Optional ByVal Region As Variant) As String ''' Returns the currency applicable in the given region. -''' The region is expressed either as a +''' The region is expressed either as a ''' - locale combining language-COUNTRY (la-CO) ''' - country only (CO) ''' Example: @@ -169,7 +169,7 @@ End Property ' ScriptForge.SF_Region.Language (get) REM ----------------------------------------------------------------------------- Property Get ListSeparator(Optional ByVal Region As Variant) As String -''' Returns the separator used in list applicable in the given region. +''' Returns the separator used in lists applicable in the given region. ''' The region is expressed as a locale combining language-COUNTRY (la-CO) ''' Example: ''' MsgBox Regio.ListSeparator("it-IT") ' ; @@ -858,4 +858,4 @@ Finally: End Function ' ScriptForge.SF_Region._PropertyGet REM ================================================ END OF SCRIPTFORGE.SF_REGION -</script:module> +</script:module> \ No newline at end of file diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 1fc666b364f3..c1261a14fc40 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1784,6 +1784,12 @@ class SFDialogs: def Activate(self): return self.ExecMethod(self.vbMethod, 'Activate') + def Center(self, parent = ScriptForge.cstSymMissing): + parentclasses = (SFDocuments.SF_Document, SFDocuments.SF_Base, SFDocuments.SF_Calc, SFDocuments.SF_Writer, + SFDialogs.SF_Dialog) + parentobj = parent.objectreference if isinstance(parent, parentclasses) else parent + return self.ExecMethod(self.vbMethod + self.flgObject, 'Center', parentobj) + def Controls(self, controlname = ''): return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Controls', controlname) @@ -1797,6 +1803,9 @@ class SFDialogs: l10nobj = l10n.objectreference if isinstance(l10n, SFScriptForge.SF_L10N) else l10n return self.ExecMethod(self.vbMethod + self.flgObject, 'GetTextsFromL10N', l10nobj) + def Resize(self, left = -1, top = -1, width = -1, height = -1): + return self.ExecMethod(self.vbMethod, 'Resize', left, top, width, height) + def Terminate(self): return self.ExecMethod(self.vbMethod, 'Terminate') diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba index b69e4b3ff5cf..c772c9d1a4b4 100644 --- a/wizards/source/sfdialogs/SF_Dialog.xba +++ b/wizards/source/sfdialogs/SF_Dialog.xba @@ -73,6 +73,12 @@ Private _DialogModel As Object ' com.sun.star.awt.XControlModel - stardiv Private _Displayed As Boolean ' True after Execute() Private _Modal As Boolean ' Set by Execute() +' Dialog position and dimensions +Private _Left As Long +Private _Top As Long +Private _Width As Long +Private _Height As Long + ' Persistent storage for controls Private _ControlCache As Variant ' Array of control objects sorted like ElementNames of the Dialog model @@ -98,6 +104,10 @@ Private Sub Class_Initialize() Set _DialogModel = Nothing _Displayed = False _Modal = True + _Left = -1 + _Top = -1 + _Width = -1 + _Height = -1 _ControlCache = Array() End Sub ' SFDialogs.SF_Dialog Constructor @@ -301,6 +311,97 @@ Catch: GoTo Finally End Function ' SFDialogs.SF_Dialog.Activate +REM ----------------------------------------------------------------------------- +Public Function Center(Optional ByRef Parent As Variant) As Boolean +''' Center the actual dialog instance in the middle of a parent window +''' Without arguments, the method centers the dialog in the middle of the current window +''' Args: +''' Parent: an object, either +''' - a ScriptForge dialog object +''' - a ScriptForge document (Calc, Base, ...) object +''' Returns: +''' True when successful +''' Examples: +''' Sub TriggerEvent(oEvent As Object) +''' Dim oDialog1 As Object, oDialog2 As Object, lExec As Long +''' Set oDialog1 = CreateScriptService("DialogEvent", oEvent) ' The dialog having caused the event +''' Set oDialog2 = CreateScriptService("Dialog", ...) ' Open a second dialog +''' oDialog2.Center(oDialog1) +''' lExec = oDialog2.Execute() +''' Select Case lExec +''' ... +''' End Sub + +Dim bCenter As Boolean ' Return value +Dim oSession As Object ' ScriptForge.SF_Session +Dim oUi As Object ' ScriptForge.SF_UI +Dim sObjectType As String ' Can be uno or sf object type +Dim oParent As Object ' UNO alias of parent +Dim oParentPosSize As Object ' Parent com.sun.star.awt.Rectangle +Dim lParentX As Long ' X position of parent dialog +Dim lParentY As Long ' Y position of parent dialog +Dim oPosSize As Object ' Dialog com.sun.star.awt.Rectangle +Dim iFlags As Integer ' com.sun.star.awt.PosSize conatnts +Const cstThisSub = "SFDialogs.Dialog.Center" +Const cstSubArgs = "[Parent]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bCenter = False + +Check: + If IsMissing(Parent) Or IsEmpty(Parent) Then Set Parent = Nothing + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not ScriptForge.SF_Utils._Validate(Parent, "Parent", ScriptForge.V_OBJECT) Then GoTo Finally + End If + + Set oParentPosSize = Nothing + lParentX = 0 : lParentY = 0 + Set oSession = CreateScriptService("Session") + If IsNull(Parent) Then + Set oUi = CreateScriptService("UI") + Set oParentPosSize = oUi._PosSize() ' Return the position and dimensions of the active window + Else + ' Determine the object type + sObjectType = oSession.UnoObjectType(Parent) + If sObjectType = "com.sun.star.script.NativeObjectWrapper" Then ' Basic object + sObjectType = Parent.ObjectType + ' Document or dialog ? + If Not ScriptForge.SF_Array.Contains(Array("BASE", "CALC", "DIALOG", "DOCUMENT", "WRITER"), sObjectType, CaseSensitive := True) Then GoTo Finally + If sObjectType = "DIALOG" Then + Set oParent = Parent._DialogControl + Set oParentPosSize = oParent.getPosSize() + lParentX = oParentPosSize.X + lParentY = oParentPosSize.Y + Else + Set oParent = Parent._Component.getCurrentController().Frame.getComponentWindow() + Set oParentPosSize = oParent.getPosSize() + End If + Else + GoTo Finally ' UNO object, do nothing + End If + End If + If IsNull(oParentPosSize) Then GoTo Finally + +Try: + Set oPosSize = _DialogControl.getPosSize() + With oPosSize + _DialogControl.setPosSize( _ + lParentX + CLng((oParentPosSize.Width - .Width) \ 2) _ + , lParentY + CLng((oParentPosSize.Height - .Height) \ 2) _ + , .Width _ + , .Height _ + , com.sun.star.awt.PosSize.POSSIZE) + End With + bCenter = True + +Finally: + Center = bCenter + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SF_Documents.SF_Dialog.Center + REM ----------------------------------------------------------------------------- Public Function Controls(Optional ByVal ControlName As Variant) As Variant ''' Return either @@ -633,6 +734,78 @@ Public Function Properties() As Variant End Function ' SFDialogs.SF_Dialog.Properties +REM ----------------------------------------------------------------------------- +Public Function Resize(Optional ByVal Left As Variant _ + , Optional ByVal Top As Variant _ + , Optional ByVal Width As Variant _ + , Optional ByVal Height As Variant _ + ) As Boolean +''' Move the topleft corner of a dialog to new coordinates and/or modify its dimensions +''' All distances are expressed in 1/100th mm +''' Without arguments, the method resets the initial dimensions +''' Args: +''' Left : the vertical distance from the topleft corner +''' Top : the horizontal distance from the topleft corner +''' Width : the horizontal width of the rectangle containing the Dialog +''' Height : the vertical height of the rectangle containing the Dialog +''' Negative or missing arguments are left unchanged +''' Returns: +''' True when successful +''' Examples: +''' oDialog.Resize(1000, 2000, Height := 6000) ' Width is not changed + +Dim bResize As Boolean ' Return value +Dim oPosSize As Object ' com.sun.star.awt.Rectangle +Dim iFlags As Integer ' com.sun.star.awt.PosSize conatnts +Const cstThisSub = "SFDialogs.Dialog.Resize" +Const cstSubArgs = "[Left], [Top], [Width], [Height]" + + If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + bResize = False + +Check: + If IsMissing(Left) Or IsEmpty(Left) Then Left = -1 + If IsMissing(Top) Or IsEmpty(Top) Then Top = -1 + If IsMissing(Height) Or IsEmpty(Height) Then Height = -1 + If IsMissing(Width) Or IsEmpty(Width) Then Width = -1 + If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not ScriptForge.SF_Utils._Validate(Left, "Left", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Top, "Top", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Width, "Width", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Height, "Height", ScriptForge.V_NUMERIC) Then GoTo Finally + End If + +Try: + With _DialogControl + Set oPosSize = .getPosSize() + ' Reset factory settings + If Left = -1 And Top = -1 And Width = -1 And Height = -1 Then + 'Left = _Left ' Initial positions determination is unstable + 'Top = _Top + Width = _Width + Height = _Height + End If + ' Trace the elements to change + iFlags = 0 + With com.sun.star.awt.PosSize + If Left >= 0 Then iFlags = iFlags + .X Else Left = oPosSize.X + If Top >= 0 Then iFlags = iFlags + .Y Else Top = oPosSize.Y + If Width > 0 Then iFlags = iFlags + .WIDTH Else Width = oPosSize.Width + If Height > 0 Then iFlags = iFlags + .HEIGHT Else Height = oPosSize.Height + End With + ' Rewrite + If iFlags > 0 Then .setPosSize(CLng(Left), CLng(Top), CLng(Width), CLng(Height), iFlags) + End With + bResize = True + +Finally: + Resize = bResize + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SF_Documents.SF_Dialog.Resize + REM ----------------------------------------------------------------------------- Public Function SetProperty(Optional ByVal PropertyName As Variant _ , Optional ByRef Value As Variant _ @@ -755,10 +928,21 @@ Public Sub _Initialize() ''' - Addition of the new object in the Dialogs buffer ''' - Initialisation of persistent storage for controls +Dim oPosSize As Object ' com.sun.star.awt.Rectangle + Try: ' Keep reference to model Set _DialogModel = _DialogControl.Model + ' Store initial position and dimensions + Set oPosSize = _DialogControl.getPosSize() + With oPosSize + _Left = .X + _Top = .Y + _Width = .Width + _Height = .Height + End With + ' Add dialog reference to cache _CacheIndex = SF_Register._AddDialogToCache(_DialogControl, [Me])