diff options
Diffstat (limited to 'wizards/source/sfdialogs/SF_Dialog.xba')
-rw-r--r-- | wizards/source/sfdialogs/SF_Dialog.xba | 184 |
1 files changed, 184 insertions, 0 deletions
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 @@ -302,6 +312,97 @@ Catch: 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 ''' - the list of the controls contained in the dialog @@ -634,6 +735,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 _ ) As Boolean @@ -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]) |