diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2023-03-20 16:48:55 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2023-03-21 06:35:19 +0000 |
commit | 3d94a43d28813b42c11a66fa88724aae53d5780e (patch) | |
tree | d07248ffcd1cb85aea8c7463ff05722fa1e4cbf4 /wizards/source/sfdialogs/SF_DialogControl.xba | |
parent | 8cf73a9a8227f90217c595be04519f0c3692754c (diff) |
ScriptForge - (SF_DialogControl) new Resize() method
Addition of method
control.Resize(X, Y, Width, Height)
to selectively (arguments are applicable only when present)
update the position and/or the size of any
dialog control.
Addition of updatable properties:
Height
Width
X
Y
for the same purpose.
All measures are expressed in PIXELS.
The measures for dialogs are also as from now expressed
in pixels.
Changes are applicable to Basic and Python user scripts.
Documentation should be updated.
Change-Id: I03a6c819efa6a2a67c88403f1ae644d94eb7f2d7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149174
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Diffstat (limited to 'wizards/source/sfdialogs/SF_DialogControl.xba')
-rw-r--r-- | wizards/source/sfdialogs/SF_DialogControl.xba | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/wizards/source/sfdialogs/SF_DialogControl.xba b/wizards/source/sfdialogs/SF_DialogControl.xba index d1417eb2a652..da4d044f20d0 100644 --- a/wizards/source/sfdialogs/SF_DialogControl.xba +++ b/wizards/source/sfdialogs/SF_DialogControl.xba @@ -75,6 +75,12 @@ Private _GridDataModel As Object ' com.sun.star.awt.grid.XGridDataModel Private _ImplementationName As String Private _ControlType As String ' One of the CTLxxx constants +' Control position and dimensions +Private _Left As Long +Private _Top As Long +Private _Width As Long +Private _Height As Long + ' Tree control on-select and on-expand attributes ' Tree controls may be associated with events not defined in the Basic IDE Private _OnNodeSelected As String ' Script to invoke when a node is selected @@ -167,6 +173,11 @@ Private Sub Class_Initialize() _ImplementationName = "" _ControlType = "" + _Left = -1 + _Top = -1 + _Width = -1 + _Height = -1 + _OnNodeSelected = "" _OnNodeExpanded = "" Set _SelectListener = Nothing @@ -301,6 +312,18 @@ Property Let Format(Optional ByVal pvFormat As Variant) End Property ' SFDialogs.SF_DialogControl.Format (let) REM ----------------------------------------------------------------------------- +Property Get Height() As Variant +''' The Height property refers to the height of the control + Height = _PropertyGet("Height") +End Property ' SFDialogs.SF_DialogControl.Height (get) + +REM ----------------------------------------------------------------------------- +Property Let Height(Optional ByVal pvHeight As Variant) +''' Set the updatable property Height + _PropertySet("Height", pvHeight) +End Property ' SFDialogs.SF_DialogControl.Height (let) + +REM ----------------------------------------------------------------------------- Property Get ListCount() As Long ''' The ListCount property specifies the number of rows in a list box or a combo box ListCount = _PropertyGet("ListCount", 0) @@ -650,6 +673,42 @@ Property Let Visible(Optional ByVal pvVisible As Variant) End Property ' SFDialogs.SF_DialogControl.Visible (let) REM ----------------------------------------------------------------------------- +Property Get Width() As Variant +''' The Width property refers to the Width of the control + Width = _PropertyGet("Width") +End Property ' SFDialogs.SF_DialogControl.Width (get) + +REM ----------------------------------------------------------------------------- +Property Let Width(Optional ByVal pvWidth As Variant) +''' Set the updatable property Width + _PropertySet("Width", pvWidth) +End Property ' SFDialogs.SF_DialogControl.Width (let) + +REM ----------------------------------------------------------------------------- +Property Get X() As Variant +''' The X property refers to the X coordinate of the top-left corner of the control + X = _PropertyGet("X") +End Property ' SFDialogs.SF_DialogControl.X (get) + +REM ----------------------------------------------------------------------------- +Property Let X(Optional ByVal pvX As Variant) +''' Set the updatable property X + _PropertySet("X", pvX) +End Property ' SFDialogs.SF_DialogControl.X (let) + +REM ----------------------------------------------------------------------------- +Property Get Y() As Variant +''' The Y property refers to the Y coordinate of the top-left corner of the control + Y = _PropertyGet("Y") +End Property ' SFDialogs.SF_DialogControl.Y (get) + +REM ----------------------------------------------------------------------------- +Property Let Y(Optional ByVal pvY As Variant) +''' Set the updatable property Y + _PropertySet("Y", pvY) +End Property ' SFDialogs.SF_DialogControl.Y (let) + +REM ----------------------------------------------------------------------------- Property Get XControlModel() As Object ''' The XControlModel property returns the model UNO object of the control XControlModel = _PropertyGet("XControlModel", Nothing) @@ -1043,6 +1102,7 @@ Public Function Properties() As Variant , "Default" _ , "Enabled" _ , "Format" _ + , "Height" _ , "ListCount" _ , "ListIndex" _ , "Locked" _ @@ -1074,16 +1134,91 @@ Public Function Properties() As Variant , "TripleState" _ , "Value" _ , "Visible" _ + , "Width" _ + , "X" _ , "XControlModel" _ , "XControlView" _ , "XGridColumnModel" _ , "XGridDataModel" _ , "XTreeDataModel" _ + , "Y" _ ) End Function ' SFDialogs.SF_DialogControl.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 top-left corner of a dialog control to new coordinates and/or modify its dimensions +''' All distances are expressed in pixels and are measured from the top-left corner of the parent dialog. +''' Without arguments, the method resets the initial dimensions. +''' Args: +''' Left : the horizontal distance from the top-left corner +''' Top : the vertical distance from the top-left corner +''' Width : the horizontal width of the rectangle containing the control +''' Height : the vertical height of the rectangle containing the control +''' Negative or missing arguments are left unchanged +''' Returns: +''' True when successful +''' Examples: +''' oControl.Resize(100, 200, 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 constants +Const cstThisSub = "SFDialogs.DialogControl.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 _ControlView + Set oPosSize = .getPosSize() + ' Reset factory settings + If Left = -1 And Top = -1 And Width = -1 And Height = -1 Then + Left = _Left + Top = _Top + Width = _Width + Height = _Height + End If + ' Trace the elements to change + iFlags = 0 + With com.sun.star.awt.PosSize + If CLng(Left) >= 0 Then iFlags = iFlags + .X Else Left = oPosSize.X + If CLng(Top) >= 0 Then iFlags = iFlags + .Y Else Top = oPosSize.Y + If CLng(Width) > 0 Then iFlags = iFlags + .WIDTH Else Width = oPosSize.Width + If CLng(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_DialogControl.Resize + +REM ----------------------------------------------------------------------------- Public Function SetFocus() As Boolean ''' Set the focus on the current Control instance ''' Probably called from after an event occurrence @@ -1582,6 +1717,7 @@ Public Sub _Initialize() Dim vServiceName As Variant ' Split service name Dim sType As String ' Last component of service name +Dim oPosSize As Object ' com.sun.star.awt.Rectangle Try: _ImplementationName = _ControlModel.getImplementationName() @@ -1605,6 +1741,15 @@ Try: Case Else : _ControlType = sType End Select + ' Store initial position and dimensions + Set oPosSize = _ControlView.getPosSize() + With oPosSize + _Left = .X + _Top = .Y + _Width = .Width + _Height = .Height + End With + ' Store the SF_DialogControl object in the parent cache Set _Parent._ControlCache(_IndexOfNames) = [Me] @@ -1698,6 +1843,8 @@ Const cstSubArgs = "" End If Case Else : GoTo CatchType End Select + Case UCase("Height") + If oSession.HasUNOMethod(_ControlView, "getPosSize") Then _PropertyGet = _ControlView.getPosSize().Height Case UCase("ListCount") Select Case _ControlType Case CTLCOMBOBOX, CTLLISTBOX @@ -1911,6 +2058,12 @@ Const cstSubArgs = "" _PropertyGet = vGet Case UCase("Visible") If oSession.HasUnoMethod(_ControlView, "isVisible") Then _PropertyGet = CBool(_ControlView.isVisible()) + Case UCase("Width") + If oSession.HasUNOMethod(_ControlView, "getPosSize") Then _PropertyGet = _ControlView.getPosSize().Width + Case UCase("X") + If oSession.HasUNOMethod(_ControlView, "getPosSize") Then _PropertyGet = _ControlView.getPosSize().X + Case UCase("Y") + If oSession.HasUNOMethod(_ControlView, "getPosSize") Then _PropertyGet = _ControlView.getPosSize().Y Case UCase("XControlModel") Set _PropertyGet = _ControlModel Case UCase("XControlView") @@ -2024,6 +2177,9 @@ Const cstSubArgs = "Value" End If Case Else : GoTo CatchType End Select + Case UCase("Height") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Height", ScriptForge.V_NUMERIC) Then GoTo Finally + If oSession.HasUnoMethod(_ControlView, "setPosSize") Then _ControlView.setPosSize(-1, -1, -1, CLng(pvValue), com.sun.star.awt.PosSize.HEIGHT) Case UCase("ListIndex") If Not ScriptForge.SF_Utils._Validate(pvValue, "ListIndex", ScriptForge.V_NUMERIC) Then GoTo Finally Select Case _ControlType @@ -2251,6 +2407,15 @@ Const cstSubArgs = "Value" End If _ControlView.setVisible(pvValue) End If + Case UCase("Width") + If Not ScriptForge.SF_Utils._Validate(pvValue, "Width", ScriptForge.V_NUMERIC) Then GoTo Finally + If oSession.HasUnoMethod(_ControlView, "setPosSize") Then _ControlView.setPosSize(-1, -1, CLng(pvValue), -1, com.sun.star.awt.PosSize.WIDTH) + Case "X" + If Not ScriptForge.SF_Utils._Validate(pvValue, "X", ScriptForge.V_NUMERIC) Then GoTo Finally + If oSession.HasUnoMethod(_ControlView, "setPosSize") Then _ControlView.setPosSize(CLng(pvValue), -1, -1, -1, com.sun.star.awt.PosSize.X) + Case "Y" + If Not ScriptForge.SF_Utils._Validate(pvValue, "Y", ScriptForge.V_NUMERIC) Then GoTo Finally + If oSession.HasUnoMethod(_ControlView, "setPosSize") Then _ControlView.setPosSize(-1, CLng(pvValue), -1, -1, com.sun.star.awt.PosSize.Y) Case Else bSet = False End Select |