wizards/source/sfdialogs/SF_Dialog.xba | 18 +++++++++++++----- wizards/source/sfdialogs/SF_Register.xba | 1 + wizards/source/sfdialogs/script.xlb | 10 +++++----- 3 files changed, 19 insertions(+), 10 deletions(-)
New commits: commit 69a816910d331a37d27cb88d006e5e19b59f4510 Author: Jean-Pierre Ledure <[email protected]> AuthorDate: Wed Jan 14 11:31:53 2026 +0100 Commit: Jean-Pierre Ledure <[email protected]> CommitDate: Thu Jan 15 10:15:27 2026 +0100 ScriptForge Fix dialog.Center() for dynamic dialogs This patch is for dynamic (= built by code, not in the Basic IDE) dialogs only. At creation, such dialogs are incomplete: their view contains default widths and heights. In addition, conversions from MAP APPFONTs (unit for position and size in the model) to pixels and back were not available. This made the computations for centering such a dialog in the middle of a parent window, known in pixels, erroneous. The data is transferred from model to view when the dialog is explicitly made visible: view.setVisible(True) The computations are made correct by forcing the visibility of the dialog as soon as a dialog.Center(...) is issued, while, before, it was done immediately before the dialog.Execute(...) No impact on help documentation. No impact on existing user scripts. Change-Id: Ie867239300c5d61424c408efec40fecc9b06bca8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197257 Reviewed-by: Jean-Pierre Ledure <[email protected]> Tested-by: Jenkins diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba index 8a9b7742df06..da60b3b07ed1 100644 --- a/wizards/source/sfdialogs/SF_Dialog.xba +++ b/wizards/source/sfdialogs/SF_Dialog.xba @@ -216,6 +216,7 @@ Private Sub Class_Initialize() _OnMouseDragged = "" _OnMouseMoved = "" _MouseMotionCounter = 0 + _ControlCache = Array() End Sub ' SFDialogs.SF_Dialog Constructor @@ -502,6 +503,7 @@ 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 +''' NB: centering a dynamic dialog makes it de facto visible. Static dialogs are made visible when executed. ''' Args: ''' Parent: an object, either ''' - a ScriptForge dialog object @@ -524,10 +526,10 @@ Dim oUi As Object ' ScriptForge.SF_UI Dim oObjDesc As Object ' _ObjectDescriptor type 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 oParentPosSize As Object ' Parent com.sun.star.awt.Rectangle (in pixels) 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 oPosSize As Object ' Dialog com.sun.star.awt.Rectangle (in pixels) Const cstThisSub = "SFDialogs.Dialog.Center" Const cstSubArgs = "[Parent]" @@ -551,7 +553,8 @@ Check: If oObjDesc.iVarType = ScriptForge.V_SFOBJECT Then ' ScriptForge object sObjectType = oObjDesc.sObjectType ' Document or dialog ? - If Not ScriptForge.SF_Array.Contains(Array("BASE", "CALC", "DIALOG", "DOCUMENT", "WRITER"), sObjectType, CaseSensitive := True) Then GoTo Finally + If Not ScriptForge.SF_Array.Contains(Array("BASE", "CALC", "DATASHEET", "DIALOG", "DOCUMENT", "FORMDOCUMENT", "WRITER") _ + , sObjectType, CaseSensitive := True) Then GoTo Finally If sObjectType = "DIALOG" Then Set oParent = Parent._DialogControl Set oParentPosSize = oParent.getPosSize() @@ -568,6 +571,9 @@ Check: If IsNull(oParentPosSize) Then GoTo Finally Try: + ' A dynamic dialog has no stable view before it is made visible => The top-left coordinate cannot be computed + If _BuiltFromScratch And Not _DialogControl.IsVisible() Then _DialogControl.setVisible(True) + ' The nosition is computed in pixels Set oPosSize = _DialogControl.getPosSize() With oPosSize _DialogControl.setPosSize( _ @@ -577,6 +583,7 @@ Try: , .Height _ , com.sun.star.awt.PosSize.POSSIZE) End With + bCenter = True Finally: @@ -2070,7 +2077,8 @@ Try: _Modal = True _Displayed = True ' In dynamic dialogs, injection of sizes and positions from model to view is done with setVisible() - _DialogControl.setVisible(True) + If Not _DialogControl.IsVisible() Then _DialogControl.setVisible(True) + ' Run the dialog now ! lExecute = _DialogControl.execute() Select Case lExecute Case 1 : lExecute = OKBUTTON @@ -2083,7 +2091,7 @@ Try: _Displayed = True ' To make visible an on-the-fly designed dialog when macro triggered from Python _DialogModel.DesktopAsParent = Not ( _BuiltFromScratch And _BuiltInPython ) - _DialogControl.setVisible(True) + If Not _DialogControl.IsVisible() Then _DialogControl.setVisible(True) ' Watch the window Close button Set _TopWindowListener = CreateUnoListener("SFDialogs.SF_DialogListener._SFNONMODAL_" _ , "com.sun.star.awt.XTopWindowListener") diff --git a/wizards/source/sfdialogs/SF_Register.xba b/wizards/source/sfdialogs/SF_Register.xba index 4639739089d5..773a8792ad2d 100644 --- a/wizards/source/sfdialogs/SF_Register.xba +++ b/wizards/source/sfdialogs/SF_Register.xba @@ -428,6 +428,7 @@ Try: ' Create the view and associate model and view Set oView = oProcessManager.createInstance(cstDialogView) oView.setModel(oModel) + oView.setVisible(False) ' When absent, IsVisible() returns True although it is not !? ' Initialize the basic SF_Dialog instance to return to the user script Set oDialog = New SF_Dialog diff --git a/wizards/source/sfdialogs/script.xlb b/wizards/source/sfdialogs/script.xlb index 199ba3621c19..59263472b3a1 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="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: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:library> \ No newline at end of file
