Tenesta SFDialogs.DialogControl

Tenesta DialogControl handsamar dei kontrollelementa som høyrer til eit dialogvindauge som er definert med Dialog Editor i Basic. Kvar førekomst av den gjeldande tenesta representerer eitt kontrollelement i eit dialogvindauge.

Fokus vert sett på å hente verdiane som vert viste av kontrollelementa i dialogvindauget. Formatering er tilgjengeleg via eigenskapane XControlModel og XControlView.

Merk at innhaldet av den unike eigenskapen DialogControl.Value varierer i høve til type kontrollelement.

Kontrollar av typen trekontroll får spesiell merksemd. Det er enkelt å fylla eit tre, anten forgreina etter grein eller med eit sett med greiner samstundes. Utfylling av ein trekontroll kan gjerast statisk eller dynamisk.

tip

Tenesta SFDialogs.DialogControl er i nær slekt med tenesta SFDialogs.Dialog.


Oppkall av tenester

Tenesta DialogControl vert opna frå ei Dialog-teneste som finst frå før, med Controls() -metoden. Dialogvindauget må opnast med tenesta SFDialogs.Dialog.


      Dim myDialog As Object, myControl As Object
      Set myDialog = CreateScriptService("SFDialogs.Dialog", "GlobalScope", myLibrary, DialogName)
      Set myControl = myDialog.Controls("myTextBox")
      myControl.Value = "Dialogvindauget byrja " & Now()
      myDialog.Execute()
      ' … handsamar dei aktuelle verdiane for kontrollelementet
      myDialog.Terminate()
   

     from time import localtime, strftime
     dlg = CreateScriptService('SFDialogs.Dialog', 'GlobalScope', lib_name, dlg_name)
     text = dlg.Controls('myTextBox')
     text.Value = "Dialogvindauget byrja " + strftime("%a, %d %b %Y %H:%M:%S", localtime())
     dlg.Execute()
     ' … handsamar dei aktuelle verdiane for kontrollelementet
     dlg.Terminate()
   

Alternativt kan ein kontrollførekomst hentast via tenesta SFDialogs.DialogEvent viss dialogvindauget vart initiert med tenesta Dialog. DialogEvent returnerer den førekomsten av tenesta SFDialogs.Dialog som utløyste hendinga.


      Sub SomeEvent(ByRef poEvent As Object)
          Dim oControl As Object
          Set oControl = CreateScriptService("SFDialogs.DialogEvent", poEvent)
          ' ...
      End Sub
   

     def some_event(event: uno):
         ctrl = CreateScriptService('SFDialogs.DialogEvent', event)
         # ...
   

Merk at i dei tidlegare eksempla kan prefikset "SFDialogs." sløyfast.

Kontrolltypar

Tenesta DialogControl er tilgjengeleg for desse kontrolltypane:

Eigenskapar

Namn

Skriveverna

Type

Gjeld for

Beskriving

Cancel

Nei

Boolean

Button

Bestemmer om ein kommandoknapp har eller ikkje har verkemåten til ein Avbryt-knapp.

Caption

Nei

String

Button, CheckBox, FixedLine, FixedText, GroupBox, RadioButton

Viser teksten som er knytt til kontrollen.

ControlType

Ja

String

Alle

Ein av typane lista opp ovanfor.

CurrentNode

Nei

UNO
objekt

TreeControl

Den øvste noden som er vald i trekontrollen. Sjå XmutableTreeNode i dokumentasjonen til Application Programming Interface (API).

note

Denne eigenskapen er tilgjengeleg frå LibreOffice 7.2 og høgare.


Default

Nei

Boolean

Button

Viser om ein kommandoknapp er standardknappen (OK).

Enabled

Nei

Boolean

Alle

Viser om kontrollen er tilgjengeleg med markøren.

Format

Nei

String

DateField, TimeField, FormattedField

(skriveverna)

Specifies the format used to display dates and times. It must be one these strings:

For dates: "Standard (short)", "Standard (short YY)", "Standard (short YYYY)", "Standard (long)", "DD/MM/YY", "MM/DD/YY", "YY/MM/DD", "DD/MM/YYYY", "MM/DD/YYYY" , "YYYY/MM/DD", "YY-MM-DD", "YYYY-MM-DD".

For times: "24h short", "24h long", "12h short", "12h long".

ListCount

Yes

Long

ComboBox, ListBox

Specifies the number of rows in a list box or a combo box.

ListIndex

No

Long

ComboBox, ListBox

Specifies which item is selected in a list box or combo box.

Locked

No

Boolean

ComboBox, CurrencyField, DateField, FileControl, FormattedField, ListBox, NumericField, PatternField, TextField, TimeField

Specifies if the control is read-only.

MultiSelect

No

Boolean

ListBox

Specifies whether a user can make multiple selections in a listbox.

Name

Yes

String

All

The name of the control.

Page

No

Integer

All

A dialog may have several pages that can be traversed by the user step by step. The Page property of the Dialog object defines which page of the dialog is active.

The Page property of a control defines the page of the dialog on which the control is visible.

Parent

Yes

Dialog
service

All

The parent SFDialogs.Dialog class object instance.

Picture

No

String

Button, ImageControl

Specifies the file name containing a bitmap or other type of graphic to be displayed on the specified control. The filename must comply with the FileNaming attribute of the ScriptForge.FileSystem service.

RootNode

Yes

UNO
object

TreeControl

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.

note

Denne eigenskapen er tilgjengeleg frå LibreOffice 7.2 og høgare.


RowSource

No

Array of strings

ComboBox, ListBox

Specifies the data contained in a combobox or a listbox.

Text

Yes

String

ComboBox, FileControl, FormattedField, PatternField, TextField

Gives access to the text being displayed by the control.

TipText

No

String

All

Specifies the text that appears as a tooltip when you hold the mouse pointer over the control.

TripleState

No

Boolean

CheckBox

Specifies if the checkbox control may appear dimmed (grayed) or not.

Value

No

Variant

Refer to Value property

Visible

No

Boolean

All

Specifies if the control is hidden or visible.

XControlModel

Yes

UNO
object

All

The UNO object representing the control model. Refer to XControlModel and UnoControlDialogModel in Application Programming Interface (API) documentation for detailed information.

XControlView

Yes

UNO
object

All

The UNO object representing the control view. Refer to XControl and UnoControlDialog in Application Programming Interface (API) documentation for detailed information.

XTreeDataModel

Yes

UNO
object

TreeControl

The UNO object representing the tree control data model. Refer to XMutableTreeDataModel in Application Programming Interface (API) documentation for detailed information.

note

Denne eigenskapen er tilgjengeleg frå LibreOffice 7.2 og høgare.



The Value property

Control type

Type

Beskriving

Button

Boolean

For toggle buttons only

CheckBox

Boolean or Integer

0, False: not checked
1, True: checked
2: grayed, don't know

ComboBox

String

The selected value. The ListIndex property is an alternate option.

CurrencyField

Numeric

DateField

Date

FileControl

String

A file name formatted in accordance with the FileNaming property of the ScriptForge.FileSystem service

FormattedField

String or Numeric

ListBox

String or array of strings

The selected row(s) as a scalar or as an array depending on the MultiSelect attribute

NumericField

Numeric

PatternField

String

ProgressBar

Numeric

Must be within the predefined bounds

RadioButton

Boolean

Each button has its own name. They are linked together if their TAB positions are contiguous. If a radiobutton is set to True, the other related buttons are automatically set to False

ScrollBar

Numeric

Must be within the predefined bounds

TextField

String

The text appearing in the field

TimeField

Date


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.

note

Denne hendingseigenskapen er tilgjengeleg frå LibreOffice 7.2 og høgare.


Name

Skriveverna

Beskriving ut frå etiketten i Basic IDE

OnActionPerformed

Yes

Execute action

OnAdjustmentValueChanged

Yes

While adjusting

OnFocusGained

Yes

When receiving focus

OnFocusLost

Yes

When losing focus

OnItemStateChanged

Yes

Item status changed

OnKeyPressed

Yes

Key pressed

OnKeyReleased

Yes

Key released

OnMouseDragged

Yes

Mouse moved while key presses

OnMouseEntered

Yes

Mouse inside

OnMouseExited

Yes

Mouse outside

OnMouseMoved

Yes

Mouse moved

OnMousePressed

Yes

Mouse button pressed

OnMouseReleased

Yes

Mouse button released

OnNodeExpanded

No

(Not in Basic IDE) when the expansion button is pressed on a node in a tree control

OnNodeSelected

No

(Not in Basic IDE) when a node in a tree control is selected

OnTextChanged

Yes

Text modified


Methods

List of Methods in the DialogControl Service

AddSubNode
AddSubTree

CreateRoot
FindNode

SetFocus
WriteLine


note

Denne metoden er tilgjengeleg frå LibreOffice 7.2 og høgare.


AddSubNode

Create and return a new node of the tree control as a UNO object subordinate to a parent node. Refer to XMutableTreeNode in Application Programming Interface (API) documentation for detailed information.

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.

Syntaks:

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

Parametrar:

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.

Eksempel:

LibreOffice 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")
      Set myTree = oDlg.Controls("myTreeControl")
      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

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.

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.

Syntaks:

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

Parametrar:

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.


      Flat tree    >>>>    Resulting subtree
      A1	B1	C1             |__   A1	
      A1	B1	C2                   |__   B1
      A1	B2	C3                         |__  C1
      A2	B3	C4                         |__  C2
      A2	B3	C5                   |__   B2
      A3	B4	C6                         |__  C3
                             |__   A2
                                   |__   B3
                                         |__  C4
                                         |__  C5
                             |__   A3
                                   |__   B4
                                         |__  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, ...

Eksempel:


      Dim myTree As Object, theRoot As Object, oDb As Object, vData As Variant
      Set myTree = myDialog.Controls("myTreeControl")
      Set theRoot = myTree.CreateRoot("By product category")
      Set oDb = CreateScriptService("SFDatabases.Database", "/home/.../mydatabase.odb")
      vData = oDb.GetRows("SELECT [Category].[Name], [Category].[ID], [Product].[Name], [Product].[ID] " _
          & "FROM [Category], [Product] WHERE [Product].[CategoryID] = [Category].[ID] " _
          & "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] \
         ORDER BY [Category].[Name], [Product].[Name]"
     tree = dlg.Controls('myTreeControl')
     root = tree.CreateRoot('By Product category')
     db = CreateScriptService('SFDatabases.Database', '/home/.../mydatabase.odb')
     sub_tree = db.GetRows(SQL_STMT)
     tree.AddSubTree(root, sub_tree, withdatavalue=True)
   

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. Refer to XMutableTreeNode in Application Programming Interface (API) documentation for detailed information.

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.

Syntaks:

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

Parametrar:

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.

Eksempel:


      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

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. Refer to XMutableTreeNode in Application Programming Interface (API) documentation for detailed information.

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.

Syntaks:

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

Parametrar:

One argument out of displayvalue or datavalue must be specified. If both present, one match is sufficient to select the node.

visingsverdi: Mønsteret som skal samsvara. Sjå ei liste over moglege jokerteikn i metoden SF_String.IsLike() . Når denne visingsverdien er lik den tomme strengen (standard), vert det ikkje søkt etter denne visingsverdien.

datavalue: Any value associated with the new node. datavalue may be a string, a number or a date. Omit the argument when not applicable.

Store-og-små: Standardverdien er Usann

Eksempel:


      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

Set fokus på kontrollelementet. Returner Sann viss fokuseringa lukkast.

Denne metoden vert ofte kalla opp frå ei dialogvindauge- eller kontrollhending.

Syntaks:

svc.SetFocus(): bool

Eksempel:


      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

Legg til ei ny linje på slutten av eit tekstfelt med fleire linjer. Der vert sett inn eit linjeskiftteikn når det høver. Metoden returnerer Sann når han lukkast.

Det oppstår ein feil viss den faktiske kontrollen ikkje er av typen TextField eller ikkje har fleire linjer.

Syntaks:

svc.WriteLine(opt line: str): bool


      oControl.WriteLine([Line As String]) As Boolean
   

Parametrar:

Linje: Strengen som skal setjast inn. Standard er ei tom linje.

Eksempel:


      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")
   
warning

Alle Basic-rutinane og -identifikatorane i ScriptForge som vert innleidde med understrek «_» er reserverte for internt bruk. Dei er ikkje tenkt brukte i Basic-makroar.