wizards/source/sfdialogs/SF_Dialog.xba | 6 ++- wizards/source/sfdialogs/SF_DialogControl.xba | 6 ++- wizards/source/sfdialogs/SF_DialogListener.xba | 32 +++++++++++++++------ wizards/source/sfdialogs/script.xlb | 10 +++--- wizards/source/sfdocuments/SF_DocumentListener.xba | 3 + wizards/source/sfwidgets/SF_MenuListener.xba | 2 - wizards/source/sfwidgets/script.xlb | 14 ++++----- 7 files changed, 47 insertions(+), 26 deletions(-)
New commits: commit dec9f7d5b2d72e83f4feb81bc8845bca506bbe20 Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Sat Mar 1 12:45:29 2025 +0100 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Sat Mar 1 14:38:42 2025 +0100 ScriptForge (dialogs, documents, widgets) Secure listeners Listeners programmed in Basic are created with CreateUnoListener(prefix, listener) The prefix argument determines the series of routines run when an event is triggered. So far, for SF internal listeners, the prefix was chosen to minimize the risk of naming collisions with routines present in user scripts. In fact the prefix argument may be provided as Library.Module.Prefix which eliminates the risk of ambiguity or homonymy. With the actual change forcing the full qualification of prefixes, the risk is reduced from epsilon to zero. No impact on the user documentation. Change-Id: I95ef4beec80c89a074c8bec809f416479e64d8cf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182384 Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba index c204d44e1114..96035e277009 100644 --- a/wizards/source/sfdialogs/SF_Dialog.xba +++ b/wizards/source/sfdialogs/SF_Dialog.xba @@ -1989,7 +1989,8 @@ Try: _DialogModel.DesktopAsParent = Not ( _BuiltFromScratch And _BuiltInPython ) _DialogControl.setVisible(True) ' Watch the window Close button - Set oListener = CreateUnoListener("_SFNONMODAL_", "com.sun.star.awt.XTopWindowListener") + Set oListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFNONMODAL_" _ + , "com.sun.star.awt.XTopWindowListener") _DialogControl.addTopWindowListener(oListener) lExecute = 0 End If @@ -2359,7 +2360,8 @@ Dim bManager As Boolean ' Return value Dim vControls As Variant ' Array of involved controls Dim oControl As Object ' A DialogControl object Dim i As Long -Const cstPrefix = "_SFTAB_" ' Prefix of Subs to trigger when involved controls are clicked +Const cstPrefix = "SFDialogs.SF_DialogListener._SFTAB_" + ' Prefix of Subs to trigger when involved controls are clicked Const cstComma = "," Const cstThisSub = "SFDialogs.Dialog.SetPageManager" diff --git a/wizards/source/sfdialogs/SF_DialogControl.xba b/wizards/source/sfdialogs/SF_DialogControl.xba index a82a18e2e124..4ddc9e0e0608 100644 --- a/wizards/source/sfdialogs/SF_DialogControl.xba +++ b/wizards/source/sfdialogs/SF_DialogControl.xba @@ -2308,7 +2308,8 @@ Const cstSubArgs = "Value" End If ' Setup a new fresh listener If Len(pvValue) > 0 Then - Set _ExpandListener = CreateUnoListener("_SFEXP_", "com.sun.star.awt.tree.XTreeExpansionListener") + Set _ExpandListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFEXP_" _ + , "com.sun.star.awt.tree.XTreeExpansionListener") _ControlView.addTreeExpansionListener(_ExpandListener) _OnNodeExpanded = pvValue End If @@ -2326,7 +2327,8 @@ Const cstSubArgs = "Value" End If ' Setup a new fresh listener If Len(pvValue) > 0 Then - Set _SelectListener = CreateUnoListener("_SFSEL_", "com.sun.star.view.XSelectionChangeListener") + Set _SelectListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFSEL_" _ + , "com.sun.star.view.XSelectionChangeListener") _ControlView.addSelectionChangeListener(_SelectListener) _OnNodeSelected = pvValue End If diff --git a/wizards/source/sfdialogs/SF_DialogListener.xba b/wizards/source/sfdialogs/SF_DialogListener.xba index 60c5e9a34499..8975c2d8257a 100644 --- a/wizards/source/sfdialogs/SF_DialogListener.xba +++ b/wizards/source/sfdialogs/SF_DialogListener.xba @@ -564,7 +564,9 @@ Try: Case "XActionListener" ._ActionCounter = ._ActionCounter + iCounterIncrement If ._ActionCounter = 1 Then - If IsNull(._ActionListener) Then Set ._ActionListener = CreateUnoListener("_SFACTION_", cstPrefix & sListener) + If IsNull(._ActionListener) Then + Set ._ActionListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFACTION_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addActionListener(._ActionListener) ElseIf ._ActionCounter <= 0 Then If Not IsNull(._ActionListener) Then oView.removeActionListener(._ActionListener) @@ -573,7 +575,9 @@ Try: Case "XAdjustmentListener" ._AdjustmentCounter = ._AdjustmentCounter + iCounterIncrement If ._AdjustmentCounter = 1 Then - If IsNull(._AdjustmentListener) Then Set ._AdjustmentListener = CreateUnoListener("_SFADJUST_", cstPrefix & sListener) + If IsNull(._AdjustmentListener) Then + Set ._AdjustmentListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFADJUST_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addAdjustmentListener(._AdjustmentListener) ElseIf ._AdjustmentCounter <= 0 Then If Not IsNull(._AdjustmentListener) Then oView.removeAdjustmentListener(._AdjustmentListener) @@ -582,7 +586,9 @@ Try: Case "XFocusListener" ._FocusCounter = ._FocusCounter + iCounterIncrement If ._FocusCounter = 1 Then - If IsNull(._FocusListener) Then Set ._FocusListener = CreateUnoListener("_SFFOCUS_", cstPrefix & sListener) + If IsNull(._FocusListener) Then + Set ._FocusListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFFOCUS_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addFocusListener(._FocusListener) ElseIf ._FocusCounter <= 0 Then If Not IsNull(._FocusListener) Then oView.removeFocusListener(._FocusListener) @@ -591,7 +597,9 @@ Try: Case "XItemListener" ._ItemCounter = ._ItemCounter + iCounterIncrement If ._ItemCounter = 1 Then - If IsNull(._ItemListener) Then Set ._ItemListener = CreateUnoListener("_SFITEM_", cstPrefix & sListener) + If IsNull(._ItemListener) Then + Set ._ItemListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFITEM_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addItemListener(._ItemListener) ElseIf ._ItemCounter <= 0 Then If Not IsNull(._ItemListener) Then oView.removeItemListener(._ItemListener) @@ -600,7 +608,9 @@ Try: Case "XKeyListener" ._KeyCounter = ._KeyCounter + iCounterIncrement If ._KeyCounter= 1 Then - If IsNull(._KeyListener) Then Set ._KeyListener = CreateUnoListener("_SFKEY_", cstPrefix & sListener) + If IsNull(._KeyListener) Then + Set ._KeyListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFKEY_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addKeyListener(._KeyListener) ElseIf ._KeyCounter <= 0 Then If Not IsNull(._KeyListener) Then oView.removeKeyListener(._KeyListener) @@ -609,7 +619,9 @@ Try: Case "XMouseListener" ._MouseCounter = ._MouseCounter + iCounterIncrement If ._MouseCounter= 1 Then - If IsNull(._MouseListener) Then Set ._MouseListener = CreateUnoListener("_SFMOUSE_", cstPrefix & sListener) + If IsNull(._MouseListener) Then + Set ._MouseListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFMOUSE_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addMouseListener(._MouseListener) ElseIf ._MouseCounter <= 0 Then If Not IsNull(._MouseListener) Then oView.removeMouseListener(._MouseListener) @@ -618,7 +630,9 @@ Try: Case "XMouseMotionListener" ._MouseMotionCounter = ._MouseMotionCounter + iCounterIncrement If ._MouseMotionCounter = 1 Then - If IsNull(._MouseMotionListener) Then Set ._MouseMotionListener = CreateUnoListener("_SFMOVE_", cstPrefix & sListener) + If IsNull(._MouseMotionListener) Then + Set ._MouseMotionListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFMOVE_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addMouseMotionListener(._MouseMotionListener) ElseIf ._MouseMotionCounter <= 0 Then If Not IsNull(._MouseMotionListener) Then oView.removeMouseMotionListener(._MouseMotionListener) @@ -627,7 +641,9 @@ Try: Case "XTextListener" ._TextCounter = ._TextCounter + iCounterIncrement If ._TextCounter = 1 Then - If IsNull(._TextListener) Then Set ._TextListener = CreateUnoListener("_SFTEXT_", cstPrefix & sListener) + If IsNull(._TextListener) Then + Set ._TextListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFTEXT_", cstPrefix & sListener) + End If If iCounterIncrement = 1 Then oView.addTextListener(._TextListener) ElseIf ._TextCounter <= 0 Then If Not IsNull(._TextListener) Then oView.removeTextListener(._TextListener) diff --git a/wizards/source/sfdialogs/script.xlb b/wizards/source/sfdialogs/script.xlb index 59263472b3a1..199ba3621c19 100644 --- a/wizards/source/sfdialogs/script.xlb +++ b/wizards/source/sfdialogs/script.xlb @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDialogs" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="__License"/> - <library:element library:name="SF_Register"/> - <library:element library:name="SF_Dialog"/> - <library:element library:name="SF_DialogControl"/> - <library:element library:name="SF_DialogListener"/> <library:element library:name="SF_DialogUtils"/> + <library:element library:name="SF_DialogListener"/> + <library:element library:name="SF_DialogControl"/> + <library:element library:name="SF_Dialog"/> + <library:element library:name="SF_Register"/> + <library:element library:name="__License"/> </library:library> \ No newline at end of file diff --git a/wizards/source/sfdocuments/SF_DocumentListener.xba b/wizards/source/sfdocuments/SF_DocumentListener.xba index fbb0271bbc38..96afe4560951 100644 --- a/wizards/source/sfdocuments/SF_DocumentListener.xba +++ b/wizards/source/sfdocuments/SF_DocumentListener.xba @@ -47,7 +47,8 @@ Dim oController As Object ' com.sun.star.frame.Controller Dim oListener As Object ' com.sun.star.sheet.XRangeSelectionListener Dim lCountLoops As Long ' Sleep cycles counter -Const cstListenerPrefix = "_SFRGSEL_" ' Prefix used for naming events Subs +Const cstListenerPrefix = "SFDocuments.SF_DocumentListener._SFRGSEL_" + ' Prefix used for naming events Subs Const cstSleep = 50 ' Sleep steps in ms while waiting for the end of the interaction Const cstMaxSleep = (60 * 5 * 1000) / cstSleep ' Never sleep more than 5 minutes. Afterwards, processing continues diff --git a/wizards/source/sfwidgets/SF_MenuListener.xba b/wizards/source/sfwidgets/SF_MenuListener.xba index cb7839de5804..18ce2b6a977e 100644 --- a/wizards/source/sfwidgets/SF_MenuListener.xba +++ b/wizards/source/sfwidgets/SF_MenuListener.xba @@ -29,7 +29,7 @@ Dim MenuListener As Object ' com.sun.star.awt.XMenuListener REM =========================================================== PRIVATE CONSTANTS -Private Const _MenuListenerPrefix = "_SFMENU_" +Private Const _MenuListenerPrefix = "SFWidgets.SF_MenuListener._SFMENU_" Private Const _MenuListener = "com.sun.star.awt.XMenuListener" Private Const cstUnoPrefix = ".uno:" Private Const cstScriptArg = ":::" diff --git a/wizards/source/sfwidgets/script.xlb b/wizards/source/sfwidgets/script.xlb index e23174375536..cea251e83b61 100644 --- a/wizards/source/sfwidgets/script.xlb +++ b/wizards/source/sfwidgets/script.xlb @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFWidgets" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="SF_ToolbarButton"/> - <library:element library:name="SF_Toolbar"/> - <library:element library:name="SF_MenuListener"/> - <library:element library:name="SF_Menu"/> - <library:element library:name="SF_ContextMenu"/> - <library:element library:name="SF_PopupMenu"/> - <library:element library:name="SF_Register"/> <library:element library:name="__License"/> + <library:element library:name="SF_Register"/> + <library:element library:name="SF_PopupMenu"/> + <library:element library:name="SF_ContextMenu"/> + <library:element library:name="SF_Menu"/> + <library:element library:name="SF_MenuListener"/> + <library:element library:name="SF_Toolbar"/> + <library:element library:name="SF_ToolbarButton"/> </library:library> \ No newline at end of file