wizards/source/scriptforge/python/scriptforge.py | 6 + wizards/source/scriptforge/python/scriptforge.pyi | 35 +++++++ wizards/source/sfdialogs/SF_Dialog.xba | 97 +++++++++++++++++++++- wizards/source/sfdialogs/script.xlb | 10 +- 4 files changed, 141 insertions(+), 7 deletions(-)
New commits: commit 0658c51d633be105aa7e36d4bb2a7faec4a1584c Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Thu Mar 13 12:57:52 2025 +0100 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Thu Mar 13 14:48:00 2025 +0100 ScriptForge (Dialog) new ImportControl() method The ImportControl() method copies a control stored in a dialog to the actual dialog. Like in: dlg1 = CreateScriptService("Dialog", ...) dlg2 = CreateScriptService("NewDialog", ...) dlg2.ImportControl(dlg1, "thiscontrol", ...) The additional arguments contribute to optionally: - renaming the new control - storing the new control in a specific page - repositioning the control (offsetx and offsety args) - including the OnEventxxx properties One goal is to help defining individual smaller dialogs in the IDE and inserting them in a larger one, keeping them in separate pages. The function works for Basic and Python user scripts. The user documentation will have to be updated. Change-Id: I6155f58d2e8706b73fc5f72c070bb8230cdd17ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182865 Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 8d04f2a07b64..54bb6478da03 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -2170,6 +2170,12 @@ class SFDialogs: l10nobj = l10n.objectreference if isinstance(l10n, SFScriptForge.SF_L10N) else l10n return self.ExecMethod(self.vbMethod + self.flgObject, 'GetTextsFromL10N', l10nobj) + def ImportControl(self, sourcedialog, sourcename, controlname = '', page = 0, offsetx = 0, offsety = 0, + includeonproperties = False): + dialogobj = sourcedialog.objectreference if isinstance(sourcedialog, SFDialogs.SF_Dialog) else sourcedialog + return self.ExecMethod(self.vbMethod + self.flgObject, 'ImportControl', dialogobj, sourcename, + controlname, page, offsetx, offsety, includeonproperties) + def OrderTabs(self, tabslist, start = 1, increment = 1): return self.ExecMethod(self.vbMethod, 'OrderTabs', tabslist, start, increment) diff --git a/wizards/source/scriptforge/python/scriptforge.pyi b/wizards/source/scriptforge/python/scriptforge.pyi index ff3d59e8472d..e0ae4a7f8adf 100644 --- a/wizards/source/scriptforge/python/scriptforge.pyi +++ b/wizards/source/scriptforge/python/scriptforge.pyi @@ -4033,6 +4033,41 @@ class SFDialogs: """ ... + def ImportControl(self, sourcedialog: DIALOG, + sourcename: str, + controlname: str = ..., + page: int = ..., + offsetx: int = ..., + offsety: int = ..., + includeonproperties: bool = ...) -> DIALOGCONTROL: + """ + Import and duplicate an existing control of any type from one dialog to the actual dialog. + The duplicated control is left unchanged. The new control can be renamed and relocated. + The events, when defined, may optionally be imported too. + + Args + ``sourcedialog``: a ``SFDialogs.SF_Dialog`` class instance. The dialog must be at least 'created' + (with CreateScriptService). + + ``sourcename``: the name of the control to import. + + ``controlname``: the name of the new control. It must not exist yet. Default = id. ``sourcename``. + + ``page``: the page number of the new control. Default = 0. + + ``offsetx``, ``offsety``: the number of pixels to add to the source control coordinates + in "Map AppFont" units. Default = 0. Their values may be negative. + + ``includeonproperties``: when True (default = False) include the OnXXX event properties + in the import. + Returns + An instance of the ``SFDialogs.SF_DialogControl`` class or ``None``. + Note + Use the ``page`` argument to load in a multi-pages dialog individual smaller dialogs, + one per page, designed in the Basic IDE. + """ + ... + def OrderTabs(self, tabslist: Sequence[str], start: int = ..., increment: int = ...) -> bool: """ Set the tabulation index of a series of controls. diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba index 819f4c291d20..84b478b25d8b 100644 --- a/wizards/source/sfdialogs/SF_Dialog.xba +++ b/wizards/source/sfdialogs/SF_Dialog.xba @@ -616,12 +616,12 @@ Check: If Not _CheckNewControl(cstThisSub, cstSubArgs, ControlName, Place := Null) Then GoTo Finally - If Not ScriptForge.SF_Utils._Validate(SourceName, "SourceName", V_String, _DialogModel.getElementNames(), True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(SourceName, "SourceName", V_STRING, _DialogModel.getElementNames(), True) Then GoTo Finally 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 Try: - ' All control types are presumes cloneable + ' All control types are presumed cloneable Set oSourceModel = _DialogModel.getByName(SourceName) Set oControlModel = oSourceModel.createClone() oControlModel.Name = ControlName @@ -2225,6 +2225,98 @@ Catch: GoTo Finally End Function ' SFDialogs.SF_Dialog.GetTextsFromL10N +REM ----------------------------------------------------------------------------- +Public Function ImportControl(Optional ByRef SourceDialog As Variant _ + , Optional ByVal SourceName As Variant _ + , Optional ByVal ControlName As Variant _ + , Optional ByVal Page As Variant _ + , Optional ByVal OffsetX As Variant _ + , Optional ByVal OffsetY As Variant _ + , Optional ByVal IncludeOnProperties As Variant _ + ) As Object +''' Import and duplicate an existing control of any type from one dialog to the actual dialog. +''' The duplicated control is left unchanged. The new control can be renamed and relocated. +''' The events, when defined, may optionally be imported too. +''' Specific args: +''' SourceDialog: a SF_Dialog class instance. +''' The dialog must be at least "created" (with CreateScriptService). +''' SourceName: the name of the control to import +''' ControlName: the name of the new control. It must not exist yet. Default = SourceName +''' Page: the page number of the new control. Default = 0 +''' OffsetX, OffsetY: the number of pixels to add to the source control coordinates in "Map AppFont" units. +''' The default = 0. May be negative. +''' IncludeOnProperties: when True (default = False) include the OnXXX event properties. +''' Returns: +''' an instance of the SF_DialogControl class or Nothing +''' Example: +''' Set myButton2 = dialog.ImportControl(otherdialog, "Button01", "Button2", OffsetX := 30, OffsetY := 30) + +Dim oControl As Object ' Return value +Dim oSourceModel As Object ' com.sun.star.awt.XControlModel of the source +Dim oControlModel As Object ' com.sun.star.awt.XControlModel of the new control +Dim vProperties As Variant ' Array of property names +Dim sProperty As String ' A single item in vProperties +Dim oSourceControl As Object ' The SF_DialogControl instance representing the input control +Dim sOnEvent As String ' An OnEvent property + +Const cstThisSub = "SFDialogs.Dialog.ImportControl" +Const cstSubArgs = "SourceDialog, SourceName, [ControlName=""""], [Page=0], " _ + & "[OffsetX=0], [OffsetY=0], [IncludeOnProperties=False]" + +Check: + Set oControl = Nothing + + If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName = SourceName + If VarType(ControlName) = V_STRING Then ' Typically a Python call will pass a zero-length string + If ControlName = "" Then ControlName = SourceName + End If + If IsMissing(Page) Or IsEmpty(Page) Then Page = 0 + If IsMissing(OffsetX) Or IsEmpty(OffsetX) Then OffsetX = 0 + If IsMissing(OffsetY) Or IsEmpty(OffsetY) Then OffsetY = 0 + If IsMissing(IncludeOnProperties) Or IsEmpty(IncludeOnProperties) Then IncludeOnProperties = False + + If Not _CheckNewControl(cstThisSub, cstSubArgs, ControlName, Place := Null) Then GoTo Finally + + If Not ScriptForge.SF_Utils._Validate(SourceDialog, "SourceDialog", ScriptForge.V_OBJECT, , , "DIALOG") Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(SourceName, "SourceName", V_STRING, SourceDialog._DialogModel.getElementNames(), True) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(Page, "Page", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(OffsetX, "OffsetX", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(OffsetY, "OffsetY", ScriptForge.V_NUMERIC) Then GoTo Finally + If Not ScriptForge.SF_Utils._Validate(IncludeOnProperties, "IncludeOnProperties", ScriptForge.V_BOOLEAN) Then GoTo Finally + +Try: + ' All control types are presumed Importable + Set oSourceModel = SourceDialog._DialogModel.getByName(SourceName) + Set oControlModel = oSourceModel.createClone() + oControlModel.Name = ControlName + + ' Create the control + Set oControl = _CreateNewControl(oControlModel, ControlName, _ + Array(oSourceModel.PositionX + OffsetX, oSourceModel.PositionY + OffsetY)) + + ' Display the control in the requested page + oControl.Page = Page + + ' Copy the OnEvent properties + If IncludeOnProperties Then + vProperties = oControl.Properties() + Set oSourceControl = SourceDialog.Controls(SourceName) + For Each sProperty In vProperties + If Left(sProperty, 2) = "On" Then + sOnEvent = oSourceControl._PropertyGet(sProperty, "") ' Default = zero-length string + If Len(sOnEvent) > 0 Then oControl._PropertySet(sProperty, sOnEvent) + End If + Next sProperty + End If + +Finally: + Set ImportControl = oControl + ScriptForge.SF_Utils._ExitFunction(cstThisSub) + Exit Function +Catch: + GoTo Finally +End Function ' SFDialogs.SF_Dialog.ImportControl + REM ----------------------------------------------------------------------------- Public Function Methods() As Variant ''' Return the list of public methods of the Model service as an array @@ -2260,6 +2352,7 @@ Public Function Methods() As Variant , "EndExecute" _ , "Execute" _ , "GetTextsFromL10N" _ + , "ImportControl" _ , "OrderTabs" _ , "Resize" _ , "SetPageManager" _ 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