ScriptForge - (SF_Dialog) get OnEvent properties
Applied on Dialog class: OnXxx properties return the triggered script as a string or a zero-length string when not defined Change-Id: I85b6b80811e09f921f993c707002263235f70c9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106604 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
This commit is contained in:
@@ -144,6 +144,126 @@ Property Get Name() As String
|
||||
Name = _PropertyGet("Name")
|
||||
End Property ' SFDialogs.SF_Dialog.Name
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnFocusGained() As Variant
|
||||
''' Get the script associated with the OnFocusGained event
|
||||
OnFocusGained = _PropertyGet("OnFocusGained")
|
||||
End Property ' SFDialogs.SF_Dialog.OnFocusGained (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnFocusGained(Optional ByVal pvOnFocusGained As Variant)
|
||||
''' Set the updatable property OnFocusGained
|
||||
_PropertySet("OnFocusGained", pvOnFocusGained)
|
||||
End Property ' SFDialogs.SF_Dialog.OnFocusGained (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnFocusLost() As Variant
|
||||
''' Get the script associated with the OnFocusLost event
|
||||
OnFocusLost = _PropertyGet("OnFocusLost")
|
||||
End Property ' SFDialogs.SF_Dialog.OnFocusLost (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnFocusLost(Optional ByVal pvOnFocusLost As Variant)
|
||||
''' Set the updatable property OnFocusLost
|
||||
_PropertySet("OnFocusLost", pvOnFocusLost)
|
||||
End Property ' SFDialogs.SF_Dialog.OnFocusLost (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnKeyPressed() As Variant
|
||||
''' Get the script associated with the OnKeyPressed event
|
||||
OnKeyPressed = _PropertyGet("OnKeyPressed")
|
||||
End Property ' SFDialogs.SF_Dialog.OnKeyPressed (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnKeyPressed(Optional ByVal pvOnKeyPressed As Variant)
|
||||
''' Set the updatable property OnKeyPressed
|
||||
_PropertySet("OnKeyPressed", pvOnKeyPressed)
|
||||
End Property ' SFDialogs.SF_Dialog.OnKeyPressed (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnKeyReleased() As Variant
|
||||
''' Get the script associated with the OnKeyReleased event
|
||||
OnKeyReleased = _PropertyGet("OnKeyReleased")
|
||||
End Property ' SFDialogs.SF_Dialog.OnKeyReleased (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnKeyReleased(Optional ByVal pvOnKeyReleased As Variant)
|
||||
''' Set the updatable property OnKeyReleased
|
||||
_PropertySet("OnKeyReleased", pvOnKeyReleased)
|
||||
End Property ' SFDialogs.SF_Dialog.OnKeyReleased (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMouseDragged() As Variant
|
||||
''' Get the script associated with the OnMouseDragged event
|
||||
OnMouseDragged = _PropertyGet("OnMouseDragged")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseDragged (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMouseDragged(Optional ByVal pvOnMouseDragged As Variant)
|
||||
''' Set the updatable property OnMouseDragged
|
||||
_PropertySet("OnMouseDragged", pvOnMouseDragged)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseDragged (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMouseEntered() As Variant
|
||||
''' Get the script associated with the OnMouseEntered event
|
||||
OnMouseEntered = _PropertyGet("OnMouseEntered")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseEntered (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMouseEntered(Optional ByVal pvOnMouseEntered As Variant)
|
||||
''' Set the updatable property OnMouseEntered
|
||||
_PropertySet("OnMouseEntered", pvOnMouseEntered)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseEntered (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMouseExited() As Variant
|
||||
''' Get the script associated with the OnMouseExited event
|
||||
OnMouseExited = _PropertyGet("OnMouseExited")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseExited (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMouseExited(Optional ByVal pvOnMouseExited As Variant)
|
||||
''' Set the updatable property OnMouseExited
|
||||
_PropertySet("OnMouseExited", pvOnMouseExited)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseExited (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMouseMoved() As Variant
|
||||
''' Get the script associated with the OnMouseMoved event
|
||||
OnMouseMoved = _PropertyGet("OnMouseMoved")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseMoved (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMouseMoved(Optional ByVal pvOnMouseMoved As Variant)
|
||||
''' Set the updatable property OnMouseMoved
|
||||
_PropertySet("OnMouseMoved", pvOnMouseMoved)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseMoved (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMousePressed() As Variant
|
||||
''' Get the script associated with the OnMousePressed event
|
||||
OnMousePressed = _PropertyGet("OnMousePressed")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMousePressed (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMousePressed(Optional ByVal pvOnMousePressed As Variant)
|
||||
''' Set the updatable property OnMousePressed
|
||||
_PropertySet("OnMousePressed", pvOnMousePressed)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMousePressed (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OnMouseReleased() As Variant
|
||||
''' Get the script associated with the OnMouseReleased event
|
||||
OnMouseReleased = _PropertyGet("OnMouseReleased")
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseReleased (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let OnMouseReleased(Optional ByVal pvOnMouseReleased As Variant)
|
||||
''' Set the updatable property OnMouseReleased
|
||||
_PropertySet("OnMouseReleased", pvOnMouseReleased)
|
||||
End Property ' SFDialogs.SF_Dialog.OnMouseReleased (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Page() As Variant
|
||||
''' A dialog may have several pages that can be traversed by the user step by step. The Page property of the Dialog object defines which page of the dialog is active.
|
||||
@@ -437,13 +557,23 @@ End Function ' SFDialogs.SF_Dialog.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
''' Return the list or properties of the Dialog class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"Caption" _
|
||||
, "Height" _
|
||||
, "Modal" _
|
||||
, "Name" _
|
||||
, "OnFocusGained" _
|
||||
, "OnFocusLost" _
|
||||
, "OnKeyPressed" _
|
||||
, "OnKeyReleased" _
|
||||
, "OnMouseDragged" _
|
||||
, "OnMouseEntered" _
|
||||
, "OnMouseExited" _
|
||||
, "OnMouseMoved" _
|
||||
, "OnMousePressed" _
|
||||
, "OnMouseReleased" _
|
||||
, "Page" _
|
||||
, "Visible" _
|
||||
, "Width" _
|
||||
@@ -529,6 +659,42 @@ End Function ' SFDialogs.SF_Dialog.Terminate
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetEventName(ByVal psProperty As String) As String
|
||||
''' Return the LO internal event name derived from the SF property name
|
||||
''' The SF property name is not case sensitive, while the LO name is case-sensitive
|
||||
' Corrects the typo on ErrorOccur(r?)ed, if necessary
|
||||
|
||||
Dim vProperties As Variant ' Array of class properties
|
||||
Dim sProperty As String ' Correctly cased property name
|
||||
|
||||
vProperties = Properties()
|
||||
sProperty = vProperties(ScriptForge.SF_Array.IndexOf(vProperties, psProperty, SortOrder := "ASC"))
|
||||
|
||||
_GetEventName = LCase(Mid(sProperty, 3, 1)) & Right(sProperty, Len(sProperty) - 3)
|
||||
|
||||
End Function ' SFDialogs.SF_Dialog._GetEventName
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _GetListener(ByVal psEventName As String) As String
|
||||
''' Getting/Setting macros triggered by events requires a Listener-EventName pair
|
||||
''' Return the X...Listener corresponding with the event name in argument
|
||||
|
||||
Select Case UCase(psEventName)
|
||||
Case UCase("OnFocusGained"), UCase("OnFocusLost")
|
||||
_GetListener = "XFocusListener"
|
||||
Case UCase("OnKeyPressed"), UCase("OnKeyReleased")
|
||||
_GetListener = "XKeyListener"
|
||||
Case UCase("OnMouseDragged"), UCase("OnMouseMoved")
|
||||
_GetListener = "XMouseMotionListener"
|
||||
Case UCase("OnMouseEntered"), UCase("OnMouseExited"), UCase("OnMousePressed"), UCase("OnMouseReleased")
|
||||
_GetListener = "XMouseListener"
|
||||
Case Else
|
||||
_GetListener = ""
|
||||
End Select
|
||||
|
||||
End Function ' SFDialogs.SF_Dialog._GetListener
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _Initialize()
|
||||
''' Complete the object creation process:
|
||||
@@ -585,6 +751,8 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Static oSession As Object ' Alias of SF_Session
|
||||
Dim oDialogEvents As Object ' com.sun.star.container.XNameContainer
|
||||
Dim sEventName As String ' Internal event name
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
@@ -595,24 +763,34 @@ Const cstSubArgs = ""
|
||||
If Not _IsStillAlive() Then GoTo Finally
|
||||
|
||||
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
|
||||
Select Case psProperty
|
||||
Case "Caption"
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("Caption")
|
||||
If oSession.HasUNOProperty(_DialogModel, "Title") Then _PropertyGet = _DialogModel.Title
|
||||
Case "Height"
|
||||
Case UCase("Height")
|
||||
If oSession.HasUNOProperty(_DialogModel, "Height") Then _PropertyGet = _DialogModel.Height
|
||||
Case "Modal"
|
||||
Case UCase("Modal")
|
||||
_PropertyGet = _Modal
|
||||
Case "Name"
|
||||
Case UCase("Name")
|
||||
_PropertyGet = _Name
|
||||
Case "Page"
|
||||
Case UCase("OnFocusGained"), UCase("OnFocusLost"), UCase("OnKeyPressed"), UCase("OnKeyReleased") _
|
||||
, UCase("OnMouseDragged"), UCase("OnMouseEntered"), UCase("OnMouseExited"), UCase("OnMouseMoved") _
|
||||
, UCase("OnMousePressed"), UCase("OnMouseReleased")
|
||||
Set oDialogEvents = _DialogModel.getEvents()
|
||||
sEventName = "com.sun.star.awt." & _GetListener(psProperty) & "::" & _GetEventName(psProperty)
|
||||
If oDialogEvents.hasByName(sEventName) Then
|
||||
_PropertyGet = oDialogEvents.getByName(sEventName).ScriptCode
|
||||
Else
|
||||
_PropertyGet = ""
|
||||
End If
|
||||
Case UCase("Page")
|
||||
If oSession.HasUNOProperty(_DialogModel, "Step") Then _PropertyGet = _DialogModel.Step
|
||||
Case "Visible"
|
||||
Case UCase("Visible")
|
||||
If oSession.HasUnoMethod(_DialogControl, "isVisible") Then _PropertyGet = CBool(_DialogControl.isVisible())
|
||||
Case "Width"
|
||||
Case UCase("Width")
|
||||
If oSession.HasUNOProperty(_DialogModel, "Width") Then _PropertyGet = _DialogModel.Width
|
||||
Case "XDialogModel"
|
||||
Case UCase("XDialogModel")
|
||||
Set _PropertyGet = _DialogModel
|
||||
Case "XDialogView"
|
||||
Case UCase("XDialogView")
|
||||
Set _PropertyGet = _DialogControl
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
|
Reference in New Issue
Block a user