From 26b5b4754fce269994a1f20938ebd0e4fa7c7c9c Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Sat, 4 Dec 2021 00:29:59 +0200 Subject: Document new TableControl methods and properties Change-Id: I8623a11f5fb710332765b8db3914a36b51285b7a Reviewed-on: https://gerrit.libreoffice.org/c/help/+/126294 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure (cherry picked from commit 73228ff72af0e4f8ca7e29b4dca388741804cb06) Reviewed-on: https://gerrit.libreoffice.org/c/help/+/126936 Reviewed-by: Olivier Hallot --- source/text/sbasic/shared/03/sf_dialogcontrol.xhp | 232 +++++++++++++++------- 1 file changed, 165 insertions(+), 67 deletions(-) diff --git a/source/text/sbasic/shared/03/sf_dialogcontrol.xhp b/source/text/sbasic/shared/03/sf_dialogcontrol.xhp index f21fcef6cd..21ed4c301c 100644 --- a/source/text/sbasic/shared/03/sf_dialogcontrol.xhp +++ b/source/text/sbasic/shared/03/sf_dialogcontrol.xhp @@ -118,6 +118,9 @@ ScrollBar + + TableControl + TextField @@ -126,7 +129,6 @@ TreeControl -

Properties

@@ -214,7 +216,6 @@ The currently upmost node selected in the tree control. Refer to XmutableTreeNode in Application Programming Interface (API) documentation for detailed information. - @@ -282,10 +283,10 @@ Long - ComboBox, ListBox + ComboBox, ListBox, TableControl - Specifies the number of rows in a list box or a combo box. + Specifies the number of rows in a ListBox, a ComboBox or a TableControl. @@ -299,10 +300,10 @@ Long - ComboBox, ListBox + ComboBox, ListBox, TableControl - Specifies which item is selected in a list box or combo box. + Specifies which item is selected in a ListBox, a ComboBox or a TableControl. @@ -423,7 +424,6 @@ An object representing the lowest root node (usually there is only one such root node). Refer to XmutableTreeNode in Application Programming Interface (API) documentation for detailed information. - @@ -575,7 +575,6 @@ The UNO object representing the tree control data model. Refer to XMutableTreeDataModel in Application Programming Interface (API) documentation for detailed information. - @@ -731,6 +730,17 @@ Must be within the predefined bounds + + + TableControl + + + Array + + + One-dimensional array with the data of the currently selected row. + + TextField @@ -755,7 +765,6 @@

Event properties

Returns a URI string with the reference to the script triggered by the event. Read its specification in the scripting framework URI specification. - @@ -954,23 +963,23 @@ - AddSubNode
- AddSubTree + AddSubNode
+ AddSubTree
+ CreateRoot
- CreateRoot
- FindNode + FindNode
+ SetFocus

- SetFocus
- WriteLine + SetTableData
+ WriteLine

- -
- AddSubNode -------------------------------------------------------------------------------------------------------------------------- +
+ AddSubNode -------------------------------------------------------------------------------------------- DialogControl service;AddSubNode @@ -979,16 +988,19 @@
This method may be called before displaying the dialog box to build the initial tree. It may also be called from a dialog or control event - using the OnNodeExpanded event - to complete the tree dynamically.
-

- svc.AddSubNode(parentnode: uno, displayvalue: str, opt datavalue: any): uno -

+ + + svc.AddSubNode(parentnode: uno, displayvalue: str, opt datavalue: any): uno + + parentnode: A node UNO object, of type com.sun.star.awt.tree.XMutableTreeNode. displayvalue: The text appearing in the tree control box.
datavalue: Any value associated with the new node. datavalue may be a string, a number or a date. Omit the argument when not applicable.
-

+ %PRODUCTNAME Basic and Python examples pick up current document's myDialog dialog from Standard library. + Dim oDlg As Object, myTree As Object, myNode As Object, theRoot As Object Set oDlg = CreateScriptService("Dialog",,, "myDialog") @@ -996,25 +1008,28 @@ Set theRoot = myTree.CreateRoot("Tree top") Set myNode = myTree.AddSubNode(theRoot, "A branch ...") + dlg = CreateScriptService('SFDialogs.Dialog', None, None, 'myDialog') tree = dlg.Controls('myTreeControl') root = tree.CreateRoot('Tree top') node = tree.AddSubNode(root, 'A branch ...') -
+
-
- AddSubTree -------------------------------------------------------------------------------------------------------------------------- +
+ AddSubTree -------------------------------------------------------------------------------------------- DialogControl service;AddSubTree

AddSubTree

Return True when a subtree, subordinate to a parent node, could be inserted successfully in a tree control. If the parent node had already child nodes before calling this method, the child nodes are erased. -

- svc.AddSubTree(parentnode: uno, flattree: any, opt withdatavalue: bool): bool -

+ + + svc.AddSubTree(parentnode: uno, flattree: any, opt withdatavalue: bool): bool + + parentnode: A node UNO object, of type com.sun.star.awt.tree.XMutableTreeNode. flattree: a two dimension array sorted on the columns containing the display values. 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 Empty or Null, no new subnode is created and the remainder of the row is skipped. @@ -1034,7 +1049,8 @@ |__ C6 withdatavalue: When False default value is used, 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, ... while the data values (datavalue) are in columns 1, 3, 5, ... -

+ + Dim myTree As Object, theRoot As Object, oDb As Object, vData As Variant Set myTree = myDialog.Controls("myTreeControl") @@ -1045,6 +1061,7 @@ & "ORDER BY [Category].[Name], [Product].[Name]") myTree.AddSubTree(theRoot, vData, WithDataValue := True) + SQL_STMT = "SELECT [Category].[Name], [Category].[ID], [Product].[Name], [Product].[ID] \ FROM [Category], [Product] WHERE [Product].[CategoryID] = [Category].[ID] \ @@ -1055,35 +1072,39 @@ sub_tree = db.GetRows(SQL_STMT) tree.AddSubTree(root, sub_tree, withdatavalue=True) -
+
-
- CreateRoot -------------------------------------------------------------------------------------------------------------------------- +
+ CreateRoot ------------------------------------------------------------------------------------------- DialogControl service;CreateRoot

CreateRoot

Returns a new root node of the tree control, as a node UNO object of type com.sun.star.awt.tree.XMutableTreeNode. The new tree root is inserted below pre-existing root nodes. This method may be called before displaying the dialog box to build the initial tree. It may also be called from a dialog or control event to complete the tree dynamically. -

- svc.CreateRoot(displayvalue: str, opt datavalue: any): uno -

+ + + svc.CreateRoot(displayvalue: str, opt datavalue: any): uno + + displayvalue: The text appearing in the tree control box. -

+ + Dim myTree As Object, myNode As Object Set myTree = myDialog.Controls("myTreeControl") Set myNode = myTree.CreateRoot("Tree starts here ...") + tree = dlg.Controls('myTreeControl') node = tree.CreateRoot('Tree starts here ...') -
+
-
- FindNode -------------------------------------------------------------------------------------------------------------------------- +
+ FindNode ---------------------------------------------------------------------------------------------- DialogControl service;FindNode @@ -1091,82 +1112,159 @@ Traverses the tree and finds recursively, starting from the root, a node meeting some criteria. Either - 1 match is enough - having its display value matching displayvalue pattern or having its data value equal to datavalue. The comparisons may be or not case-sensitive. The first matching occurrence is returned as a node UNO object of type com.sun.star.awt.tree.XMutableTreeNode. When not found, the method returns Nothing, to be tested with the IsNull() builtin function. This method may be called before displaying the dialog box to build the initial tree. It may also be called from a dialog or control event. -

- svc.FindNode(displayvalue: str = '', opt datavalue: any, casesensitive = False): uno -

+ + + svc.FindNode(displayvalue: str = '', opt datavalue: any, casesensitive = False): uno + + One argument out of displayvalue or datavalue must be specified. If both present, one match is sufficient to select the node. displayvalue: The pattern to be matched. Refer to SF_String.IsLike() method for the list of possible wildcards. When equal to the zero-length string (default), this display value is not searched for. casesensitive: Default value is False -

+ + Dim myTree As Object, myNode As Object Set myTree = myDialog.Controls("myTreeControl") Set myNode = myTree.FindNode("*Sophie*", CaseSensitive := True) + tree = dlg.Controls('myTreeControl') node = FindNode('*Sophie*', casesensitive=True) if node is None: # ... -
-
- SetFocus -------------------------------------------------------------------------------------------------------------------------- +
+ +
+ SetFocus ---------------------------------------------------------------------------------------------- DialogControl service;SetFocus

SetFocus

Set the focus on the control. Return True if focusing was successful. This method is often called from a dialog or control event. -

- svc.SetFocus(): bool -

+ + + svc.SetFocus(): bool + + + Dim oControl As Object Set oDlg = CreateScriptService("SFDialogs.Dialog",,, "myDialog") Set oControl = oDlg.Controls("thisControl") oControl.SetFocus() + dlg = CreateScriptService('Dialog', None, None, 'myDialog') ctrl = dlg.Controls('thisControl') ctrl.SetFocus() -
-
- WriteLine -------------------------------------------------------------------------------------------------------------------------- +
+ +
+ SetTableData ------------------------------------------------------------------------------------------ + + DialogControl service;SetTableData + +

SetTableData

+ Fills a TableControl with the given data. All preexisting data is cleared before inserting the new data passed as argument. + When the TableControl is added to the dialog, it is possible to use the Basic IDE to define whether column and row headers will be shown in the table. If the TableControl has column and/or row headers, the first column and/or row in the provided data array are used as labels for the table headers. + This method returns True when successful. + + + svc.SetTableData(dataarray: any[0..*, 0..*], widths: int[0..*], alignments: str): bool + + + dataarray: Data to be entered into the table represented as an Array of Arrays in Basic or a tuple of tuples in Python. The data must include column and row headers if they are to be displayed by the TableControl. + widths: Array containing the relative widths of each column. In other words, widths = Array(1, 2) means that the second column is twice as wide as the first one. If the number of values in the array is smaller than the number of columns in the table, then the last value in the array is used to define the width of the remaining columns. + alignments: Defines the alignment in each column as a string in which each character can be "L" (Left), "C" (Center), "R" (Right) or " " (whitespace, default, meaning left for strings and right for numeric values). If the length of the string is shorter than the number of columns in the table, then the last character in the string is used to define the alignment of the remaining columns. + + + The following example assumes that the dialog myDialog has a TableControl named Grid1 with "Show header row" and "Show column row" properties set to "Yes". + + Dim myDialog As Object, oTable As Object, tableData As Variant + myDialog = CreateScriptService("Dialog", "GlobalScope", "Standard", "myDialog") + oTable = myDialog.Controls("Grid1") + tableData = Array("Column A", "Column B", "Column C") + tableData = SF_Array.AppendRow(tableData, Array("Row 1", 1, 2)) + tableData = SF_Array.AppendRow(tableData, Array("Row 2", 3, 4)) + tableData = SF_Array.AppendRow(tableData, Array("Row 3", 5, 6)) + vAlignments = "LCC" + vWidths = Array(2, 1, 1) + oTable.SetTableData(tableData, vWidths, vAlignments) + myDialog.Execute() + + The Value property returns the selected row in the table. If no row is selected, an empty Array object is returned. The following code snippet shows how to test if any row is selected in the table. + + rowValues = oTable.Value + If UBound(rowValues) < 0 Then + MsgBox "No row selected." + Else + MsgBox "Row " & oTable.ListIndex & " is selected." + End If + + + + dlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "myDialog") + table_control = dlg.Controls("Grid1") + table_data = (("Column A", "Column B", "Column C"), + ("Row 1", 1, 2), + ("Row 2", 3, 4), + ("Row 3", 5, 6)) + alignments = "LCC" + widths = (100, 50, 50) + table_control.SetTableData(table_data, widths, alignments) + dlg.Execute() + + + bas = CreateScriptService("Basic") + row_values = table_control.Value + if len(row_values) == 0: + bas.MsgBox("No row selected.") + else: + bas.MsgBox(f"Row {table_control.ListIndex} is selected.") + +
+ +
+ WriteLine -------------------------------------------------------------------------------------------- DialogControl service;WriteLine

WriteLine

Add a new line at the end of a multiline text field. A newline character will be inserted when appropriate. The method returns True when successful. An error is raised if the actual control is not of the type TextField or is not multiline. -

- svc.WriteLine(opt line: str): bool - - oControl.WriteLine([Line As String]) As Boolean - -

+ + + svc.WriteLine(opt line: str): bool + + Line: The string to insert. Default is an empty line. -

+ + Dim oDlg As Object, oControl As Object Set oDlg = CreateScriptService("SFDialogs.Dialog",,, "myDialog") Set oControl = oDlg.Controls("thisControl") oControl.WriteLine("a new line") + dlg = CreateScriptService('SFDialogs.Dialog', None, None, 'myDialog') ctrl = dlg.Controls('thisControl') ctr.WriteLine("a new line") -
- -
- - - -
+
+ + +
+ + + +
- \ No newline at end of file + -- cgit option value='libreoffice-7-5-4'>libreoffice-7-5-4 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author