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, 
&quot;SourceName&quot;, V_String, _DialogModel.getElementNames(), True) Then 
GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(SourceName, 
&quot;SourceName&quot;, V_STRING, _DialogModel.getElementNames(), True) Then 
GoTo Finally
        If Not ScriptForge.SF_Utils._Validate(Left, &quot;Left&quot;, 
ScriptForge.V_NUMERIC) Then GoTo Finally
        If Not ScriptForge.SF_Utils._Validate(Top, &quot;Top&quot;, 
ScriptForge.V_NUMERIC) Then GoTo Finally
 
 Try:
-       &apos;  All control types are presumes cloneable
+       &apos;  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    &apos;   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
+&apos;&apos;&apos;     Import and duplicate an existing control of any type 
from one dialog to the actual dialog.
+&apos;&apos;&apos;     The duplicated control is left unchanged. The new 
control can be renamed and relocated.
+&apos;&apos;&apos;     The events, when defined, may optionally be imported 
too.
+&apos;&apos;&apos;     Specific args:
+&apos;&apos;&apos;             SourceDialog: a SF_Dialog class instance.
+&apos;&apos;&apos;                     The dialog must be at least 
&quot;created&quot; (with CreateScriptService).
+&apos;&apos;&apos;             SourceName: the name of the control to import
+&apos;&apos;&apos;             ControlName: the name of the new control. It 
must not exist yet. Default = SourceName
+&apos;&apos;&apos;             Page: the page number of the new control. 
Default = 0
+&apos;&apos;&apos;             OffsetX, OffsetY: the number of pixels to add 
to the source control coordinates in &quot;Map AppFont&quot; units.
+&apos;&apos;&apos;                     The default = 0. May be negative.
+&apos;&apos;&apos;             IncludeOnProperties: when True (default = 
False) include the OnXXX event properties.
+&apos;&apos;&apos;     Returns:
+&apos;&apos;&apos;             an instance of the SF_DialogControl class or 
Nothing
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             Set myButton2 = 
dialog.ImportControl(otherdialog, &quot;Button01&quot;, &quot;Button2&quot;, 
OffsetX := 30, OffsetY := 30)
+
+Dim oControl As Object                 &apos;  Return value
+Dim oSourceModel As Object             &apos;  com.sun.star.awt.XControlModel 
of the source
+Dim oControlModel As Object            &apos;  com.sun.star.awt.XControlModel 
of the new control
+Dim vProperties As Variant             &apos;  Array of property names
+Dim sProperty As String                        &apos;  A single item in 
vProperties
+Dim oSourceControl As Object   &apos;  The SF_DialogControl instance 
representing the input control
+Dim sOnEvent As String                 &apos;  An OnEvent property
+
+Const cstThisSub = &quot;SFDialogs.Dialog.ImportControl&quot;
+Const cstSubArgs = &quot;SourceDialog, SourceName, 
[ControlName=&quot;&quot;&quot;&quot;], [Page=0], &quot; _
+                                       &amp; &quot;[OffsetX=0], [OffsetY=0], 
[IncludeOnProperties=False]&quot;
+
+Check:
+       Set oControl = Nothing
+
+       If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName = 
SourceName
+       If VarType(ControlName) = V_STRING Then                 &apos;  
Typically a Python call will pass a zero-length string
+               If ControlName = &quot;&quot; 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, 
&quot;SourceDialog&quot;, ScriptForge.V_OBJECT, , , &quot;DIALOG&quot;) Then 
GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(SourceName, 
&quot;SourceName&quot;, V_STRING, SourceDialog._DialogModel.getElementNames(), 
True) Then GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(Page, &quot;Page&quot;, 
ScriptForge.V_NUMERIC) Then GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(OffsetX, &quot;OffsetX&quot;, 
ScriptForge.V_NUMERIC) Then GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(OffsetY, &quot;OffsetY&quot;, 
ScriptForge.V_NUMERIC) Then GoTo Finally
+       If Not ScriptForge.SF_Utils._Validate(IncludeOnProperties, 
&quot;IncludeOnProperties&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
+
+Try:
+       &apos;  All control types are presumed Importable
+       Set oSourceModel = SourceDialog._DialogModel.getByName(SourceName)
+       Set oControlModel = oSourceModel.createClone()
+       oControlModel.Name = ControlName
+
+       &apos;  Create the control
+       Set oControl = _CreateNewControl(oControlModel, ControlName, _
+                                               Array(oSourceModel.PositionX + 
OffsetX, oSourceModel.PositionY + OffsetY))
+
+       &apos;  Display the control in the requested page
+       oControl.Page = Page
+
+       &apos;  Copy the OnEvent properties
+       If IncludeOnProperties Then
+               vProperties = oControl.Properties()
+               Set oSourceControl = SourceDialog.Controls(SourceName)
+               For Each sProperty In vProperties
+                       If Left(sProperty, 2) = &quot;On&quot; Then
+                               sOnEvent = 
oSourceControl._PropertyGet(sProperty, &quot;&quot;) &apos;  Default = 
zero-length string
+                               If Len(sOnEvent) &gt; 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   &apos;  SFDialogs.SF_Dialog.ImportControl
+
 REM 
-----------------------------------------------------------------------------
 Public Function Methods() As Variant
 &apos;&apos;&apos;     Return the list of public methods of the Model service 
as an array
@@ -2260,6 +2352,7 @@ Public Function Methods() As Variant
                                        , &quot;EndExecute&quot; _
                                        , &quot;Execute&quot; _
                                        , &quot;GetTextsFromL10N&quot; _
+                                       , &quot;ImportControl&quot; _
                                        , &quot;OrderTabs&quot; _
                                        , &quot;Resize&quot; _
                                        , &quot;SetPageManager&quot; _
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

Reply via email to