summaryrefslogtreecommitdiff
path: root/wizards/source/sfdialogs
diff options
context:
space:
mode:
Diffstat (limited to 'wizards/source/sfdialogs')
-rw-r--r--wizards/source/sfdialogs/SF_Dialog.xba5
-rw-r--r--wizards/source/sfdialogs/SF_DialogControl.xba84
-rw-r--r--wizards/source/sfdialogs/SF_Register.xba47
3 files changed, 91 insertions, 45 deletions
diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba
index 3bee408bdc7b..e0b7beb11d0a 100644
--- a/wizards/source/sfdialogs/SF_Dialog.xba
+++ b/wizards/source/sfdialogs/SF_Dialog.xba
@@ -531,6 +531,8 @@ Public Function Properties() As Variant
, "Page" _
, "Visible" _
, "Width" _
+ , "XDialogModel" _
+ , "XDialogView" _
)
End Function ' SFDialogs.SF_Dialog.Properties
@@ -658,8 +660,7 @@ Public Sub _Initialize()
''' - Initialisation of persistent storage for controls
Try:
- ' Create the graphical interface
- Set _DialogControl = CreateUnoDialog(_DialogProvider)
+ ' Keep reference to model
Set _DialogModel = _DialogControl.Model
' Add dialog reference to cache
diff --git a/wizards/source/sfdialogs/SF_DialogControl.xba b/wizards/source/sfdialogs/SF_DialogControl.xba
index 161ff1d2b571..ab32abbd484f 100644
--- a/wizards/source/sfdialogs/SF_DialogControl.xba
+++ b/wizards/source/sfdialogs/SF_DialogControl.xba
@@ -576,6 +576,7 @@ Public Function AddSubTree(Optional ByRef ParentNode As Variant _
''' Typically, such an array can be issued by the GetRows method applied on the SFDatabases.Database service
''' when an array item containing the text to be displayed is = "" or is empty/null,
''' no new subnode is created and the remainder of the row is skipped
+''' When AddSubTree() is called from a Python script, FlatTree may be an array of arrays
''' WithDataValue:
''' When False (default), every column of FlatTree contains the text to be displayed in the tree control
''' When True, the texts to be displayed (DisplayValue) are in columns 0, 2, 4, ...
@@ -597,6 +598,13 @@ Dim oNode As Object ' com.sun.star.awt.tree.XMutableTreeNode
Dim oNewNode As Object ' com.sun.star.awt.tree.XMutableTreeNode
Dim lChildCount As Long ' Number of children nodes of a parent node
Dim iStep As Integer ' 1 when WithDataValue = False, 2 otherwise
+Dim iDims As Integer ' Number of dimensions of FlatTree
+Dim lMin1 As Long ' Lower bound (rows)
+Dim lMin2 As Long ' Lower bounds (cols)
+Dim lMax1 As Long ' Upper bound (rows)
+Dim lMax2 As Long ' Upper bounds (cols)
+Dim vFlatItem As Variant ' A single FlatTree item: FlatTree(i, j)
+Dim vFlatItem2 As Variant ' A single FlatTree item
Dim bChange As Boolean ' When True, the item in FlatTree is different from the item above
Dim sValue As String ' Alias for display values
Dim i As Long, j As Long
@@ -612,7 +620,7 @@ Check:
If _ControlType <> CTLTREECONTROL Then GoTo CatchType
If Not ScriptForge.SF_Utils._Validate(ParentNode, "ParentNode", V_OBJECT) Then GoTo Catch
If ScriptForge.SF_Session.UnoObjectType(ParentNode) <> "toolkit.MutableTreeNode" Then GoTo Catch
- If Not ScriptForge.SF_Utils._ValidateArray(FlatTree, "FlatTree", 2) Then GoTo Catch
+ If Not ScriptForge.SF_Utils._ValidateArray(FlatTree, "FlatTree") Then GoTo Catch ' Dimensions checked below
If Not ScriptForge.SF_Utils._Validate(WithDataValue, "WithDataValue", V_BOOLEAN) Then GoTo Catch
End If
@@ -623,34 +631,55 @@ Try:
For i = 1 To lChildCount
ParentNode.removeChildByIndex(0) ' This cleans all subtrees too
Next i
+
+ ' Determine bounds
+ iDims = ScriptForge.SF_Array.CountDims(FlatTree)
+ Select Case iDims
+ Case -1, 0 : GoTo Catch
+ Case 1 ' Called probably from Python
+ lMin1 = LBound(FlatTree, 1) : lMax1 = UBound(FlatTree, 1)
+ If Not IsArray(FlatTree(0)) Then GoTo Catch
+ If UBound(FlatTree(0)) < LBound(FlatTree(0)) Then GoTo Catch ' No columns
+ lMin2 = LBound(FlatTree(0)) : lMax2 = UBound(FlatTree(0))
+ Case 2
+ lMin1 = LBound(FlatTree, 1) : lMax1 = UBound(FlatTree, 1)
+ lMin2 = LBound(FlatTree, 2) : lMax2 = UBound(FlatTree, 2)
+ Case Else : GoTo Catch
+ End Select
+
' Build a new subtree
- If UBound(FlatTree, 1) < LBound(FlatTree, 1) Then 'Array is empty
- Else
- iStep = Iif(WithDataValue, 2, 1)
- For i = LBound(FlatTree, 1) To UBound(FlatTree, 1) ' Array rows
- bChange = ( i = 0 )
- ' Restart from the parent node at each i-iteration
- Set oNode = ParentNode
- For j = LBound(FlatTree, 2) To UBound(FlatTree, 2) Step iStep ' Array columns
- If FlatTree(i, j) = "" Or IsNull(FlatTree(i, j)) Or IsEmpty(FlatTree(i, j)) Then
- Set oNode = Nothing
- Exit For ' Exit j-loop
+ iStep = Iif(WithDataValue, 2, 1)
+ For i = lMin1 To lMax1
+ bChange = ( i = 0 )
+ ' Restart from the parent node at each i-iteration
+ Set oNode = ParentNode
+ For j = lMin2 To lMax2 Step iStep ' Array columns
+ If iDims = 1 Then vFlatItem = FlatTree(i)(j) Else vFlatItem = FlatTree(i, j)
+ If vFlatItem = "" Or IsNull(vFlatItem) Or IsEmpty(vFlatItem) Then
+ Set oNode = Nothing
+ Exit For ' Exit j-loop
+ End If
+ If Not bChange Then
+ If iDims = 1 Then vFlatItem2 = FlatTree(i - 1)(j) Else vFlatItem2 = FlatTree(i - 1, j)
+ bChange = ( vFlatItem <> vFlatItem2 )
+ End If
+ If bChange Then ' Create new subnode at tree depth = j
+ If VarType(vFlatItem) = V_STRING Then sValue = vFlatItem Else sValue = ScriptForge.SF_String.Represent(vFlatItem)
+ Set oNewNode = .createNode(sValue, True)
+ If WithDataValue Then
+ If iDims = 1 Then vFlatItem2 = FlatTree(i)(j + 1) Else vFlatItem2 = FlatTree(i, j + 1)
+ oNewNode.DataValue = vFlatItem2
End If
- If Not bChange Then bChange = ( FlatTree(i, j) <> FlatTree(i - 1, j) )
- If bChange Then ' Create new subnode at tree depth = j
- If VarType(FlatTree(i, j)) = V_STRING Then sValue = FlatTree(i, j) Else sValue = ScriptForge.SF_String.Represent(FlatTree(i, j))
- Set oNewNode = .createNode(sValue, True)
- If WithDataValue Then oNewNode.DataValue = FlatTree(i, j + 1)
- oNode.appendChild(oNewNode)
- Set oNode = oNewNode
- Else
- ' Position next current node on last child of actual current node
- lChildCount = oNode.getChildCount()
- If lChildCount > 0 Then Set oNode = oNode.getChildAt(lChildCount - 1) Else Set oNode = Nothing
- End If
- Next j
- Next i
- End If
+ oNode.appendChild(oNewNode)
+ Set oNode = oNewNode
+ Else
+ ' Position next current node on last child of actual current node
+ lChildCount = oNode.getChildCount()
+ If lChildCount > 0 Then Set oNode = oNode.getChildAt(lChildCount - 1) Else Set oNode = Nothing
+ End If
+ Next j
+ Next i
+ bSubTree = True
End With
Finally:
@@ -854,6 +883,7 @@ Public Function Properties() As Variant
, "Page" _
, "Parent" _
, "Picture" _
+ , "RootNode" _
, "RowSource" _
, "Text" _
, "TipText" _
diff --git a/wizards/source/sfdialogs/SF_Register.xba b/wizards/source/sfdialogs/SF_Register.xba
index 0bda31d48ebe..fc3dbf54008c 100644
--- a/wizards/source/sfdialogs/SF_Register.xba
+++ b/wizards/source/sfdialogs/SF_Register.xba
@@ -226,6 +226,7 @@ Public Function _NewDialog(Optional ByVal pvArgs As Variant) As Object
''' Library: the name of the library hosting the dialog. Default = "Standard"
''' DialogName: The name of the dialog
''' Library and dialog names are case-sensitive
+''' Context: When called from Python, the context must be provided : XSCRIPTCONTEXT
''' Returns: the instance or Nothing
Dim oDialog As Object ' Return value
@@ -233,11 +234,14 @@ Dim vContainer As Variant ' Alias of pvArgs(0)
Dim vLibrary As Variant ' Alias of pvArgs(1)
Dim vDialogName As Variant ' Alias of pvArgs(2)
Dim oLibraries As Object ' com.sun.star.comp.sfx2.DialogLibraryContainer
-Dim oLibrary As Object ' com.sun.star.container.XNameAccess
+Dim vContext As Variant ' com.sun.star.uno.XComponentContext
Dim oDialogProvider As Object ' com.sun.star.io.XInputStreamProvider
Dim oEnum As Object ' com.sun.star.container.XEnumeration
Dim oComp As Object ' com.sun.star.lang.XComponent
+Dim oDialogControl As Object ' com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
Dim vWindow As Window ' A single component
+Dim sScope As String ' "application" or "document"
+Dim sURI As String ' URI of the targeted dialog
Dim oUi As Object ' "UI" service
Dim bFound As Boolean ' True if WindowName is found on the desktop
Const cstService = "SFDialogs.Dialog"
@@ -255,16 +259,18 @@ Check:
If Not ScriptForge.SF_Utils._Validate(vContainer, "Container", Array(V_STRING, ScriptForge.V_OBJECT)) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(vLibrary, "Library", V_STRING) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(vDialogName, "DialogName", V_STRING) Then GoTo Finally
+ If UBound(pvArgs) >= 3 Then vContext = pvArgs(3) Else vContext = Nothing
+ If Not ScriptForge.SF_Utils._Validate(vContext, "DialogName", V_OBJECT) Then GoTo Finally
Set oDialog = Nothing
Try:
- ' Determine the container and the library hosting the dialog
- Set oLibraries = Nothing
+ ' Determine the library container hosting the dialog
+ Set oUi = ScriptForge.SF_Register.CreateScriptService("UI")
+ Set oComp = Nothing
If VarType(vContainer) = V_STRING Then
- If UCase(vContainer) = UCase(cstGlobal) Then Set oLibraries = GlobalScope.DialogLibraries
+ bFound = ( UCase(vContainer) = UCase(cstGlobal) )
End If
- If IsNull(oLibraries) Then
- Set oUi = ScriptForge.SF_Register.CreateScriptService("UI")
+ If Not bFound Then
Select Case VarType(vContainer)
Case V_STRING
If Len(vContainer) > 0 Then
@@ -294,19 +300,27 @@ Try:
End Select
If Not bFound Then GoTo CatchNotFound
If Len(vWindow.DocumentType) = 0 Then GoTo CatchNotFound
- ' The library is now fully determined
- Set oLibraries = oComp.DialogLibraries
End If
- ' Load the library and get the dialog
- With oLibraries
- If Not .hasByName(vLibrary) Then GoTo CatchNotFound
- If Not .isLibraryLoaded(vLibrary) Then .loadLibrary(vLibrary)
- Set oLibrary = .getByName(vLibrary)
- If Not oLibrary.hasByName(vDialogName) Then GoTo CatchNotFound
- Set oDialogProvider = oLibrary.getByName(vDialogName)
- End With
+ ' Determine the dialog provider
+ Select Case True
+ Case IsNull(vContext) And IsNull(oComp) ' Basic and GlobalScope
+ Set oDialogProvider = GetProcessServiceManager.createInstance("com.sun.star.awt.DialogProvider")
+ Case IsNull(vContext) And Not IsNull(oComp) ' Basic and Document
+ Set oDialogProvider = GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider", Array(oComp))
+ Case Not IsNull(vContext) And IsNull(oComp) ' Python and GlobalScope
+ Set oDialogProvider = vContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider", vContext)
+ Case Not IsNull(vContext) And Not IsNull(oComp) ' Python and Document
+ Set oDialogProvider = vContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider", Array(oComp))
+ End Select
+
+ ' Create the graphcal interface
+ sScope = Iif(IsNull(oComp), "application", "document")
+ sURI = "vnd.sun.star.script:" & vLibrary & "." & vDialogName & "?location=" & sScope
+ On Local Error GoTo CatchNotFound
+ Set oDialogControl = oDialogProvider.createDialog(sURI)
+ ' Initialize the basic SF_Dialog instance to return to the user script
Set oDialog = New SF_Dialog
With oDialog
Set .[Me] = oDialog
@@ -314,6 +328,7 @@ Try:
._Library = vLibrary
._Name = vDialogName
Set ._DialogProvider = oDialogProvider
+ Set ._DialogControl = oDialogControl
._Initialize()
End With