Difference between revisions of "NL/Documentation/BASIC Guide/Working With Forms"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Created page with "{{NL/Documentation/BASICGuideTOC/v2 |ShowPrevNext=block |ShowPrevPage=block |PrevPage=NL/Documentation/BASIC Guide/Forms |NextPage=NL/Documentation/BASIC Guide/Control Element..." (tussenstap opslaan))
 
Line 44: Line 44:
 
</source>
 
</source>
  
As is already suggested by the <tt>GetByIndex</tt> method name, a document may contain several forms. This is useful, for example, if the contents of different databases are displayed within one document, or if a 1:n database relationship is displayed within a form. The option of creating sub-forms is also provided for this purpose.
+
Zoals al werd gesuggereerd door de methodenaam <tt>GetByIndex</tt> kan een document verschillende formulieren bevatten. Dit is bijvoorbeeld handig als de inhoud van verschillende gegevensbronnen worden weergegeven binnen één document, of als een relatie van een gegevensbron wordt weergegeven binnen een formulier. De optie voor het maken van sub-formulieren wordt mede voor dit doel verschaft.
  
== The Three Aspects of a Control Element Form ==
+
== De drie aspecten van een besturingselement van een formulier ==
  
A control element of a form has three aspects:
+
Een besturingselement van een formulier heeft drie aspecten:
  
* The '''Model''' of the control element is the key object for the {{OOo}} Basic-programmer when working with control element forms.
+
* Het '''Model''' van het besturingselement is het sleutel-object voor de programmeur in {{OOo}} BASIC bij het werken met besturingselementen voor formulieren.
* The counterpart to this is the '''View''' of the control element, which administers the display information.
+
* Het tegengestelde hiervan is de '''View''' van het besturingselement, dat de informatie voor de weergave beheert.
* Since control element forms within the documents are administered like a special drawing element, there is also a '''Shape object''' which reflects the drawing element-specific properties of the control element (in particular its position and size).
+
* Omdat besturingselement formulieren binnen de documenten worden beheerd als een speciaal tekenelement, is er ook een '''object Shape''' dat de tekenelement-specifieke eigenschappen van het besturingselement weergeeft (in het bijzonder zijn positie en grootte).
  
 
== Accessing the Model of Control Element Forms ==
 
== Accessing the Model of Control Element Forms ==

Revision as of 17:43, 19 March 2013

Book.png


Apache OpenOffice formulieren mogen tekstvelden, keuzelijsten, radioknoppen en een scala aan andere besturingselementen bevatten, welke direct worden ingevoegd in een tekst- of werkbladdocument. De werkbalk Besturingselementen wordt gebruikt voor het bewerken van formulieren.

Een formulier in Apache OpenOfficekan één van twee modi aannemen: de ontwerp-modus en de weergave- modus. In ontwerpmodus kan de positie van besturingselementen worden gewijzigd en hun eigenschappen kunnen worden bewerkt met behulp van een venster voor eigenschappen.

De werkbalk Besturingselementen wordt ook gebruikt voor het schakelen tussen die modi.

Bepalen van object Formulieren

Apache OpenOffice plaatst de besturingselementen van een formulier op het niveau van een object van een tekening. Het actuele object formulier kan worden benaderd via de lijst Forms op niveau van het object tekening. De objecten worden als volgt benaderd in tekstdocumenten:

Dim Doc As Object
Dim DrawPage As Object
Dim Formulier As Object
 
Doc = ThisComponent
DrawPage = Doc.DrawPage
Formulier = DrawPage.Forms.GetByIndex(0)

De methode GetByIndex geeft het formulier weer met het index-getal 0.

Bij het werken met werkbladdocumenten is een tussenstation nodig, de lijst Sheets, omdat de niveau's voor de tekeningen niet direct in het document zijn gelegen, maar in de individuele werkbladen:

Dim Doc As Object
Dim Blad As Object
Dim DrawPage As Object
Dim Formulier As Object
 
Doc = ThisComponent
Blad = Doc.Sheets.GetByIndex(0)
DrawPage = Blad.DrawPage
Formulier = DrawPage.Forms.GetByIndex(0)

Zoals al werd gesuggereerd door de methodenaam GetByIndex kan een document verschillende formulieren bevatten. Dit is bijvoorbeeld handig als de inhoud van verschillende gegevensbronnen worden weergegeven binnen één document, of als een relatie van een gegevensbron wordt weergegeven binnen een formulier. De optie voor het maken van sub-formulieren wordt mede voor dit doel verschaft.

De drie aspecten van een besturingselement van een formulier

Een besturingselement van een formulier heeft drie aspecten:

  • Het Model van het besturingselement is het sleutel-object voor de programmeur in Apache OpenOffice BASIC bij het werken met besturingselementen voor formulieren.
  • Het tegengestelde hiervan is de View van het besturingselement, dat de informatie voor de weergave beheert.
  • Omdat besturingselement formulieren binnen de documenten worden beheerd als een speciaal tekenelement, is er ook een object Shape dat de tekenelement-specifieke eigenschappen van het besturingselement weergeeft (in het bijzonder zijn positie en grootte).

Accessing the Model of Control Element Forms

The models of the control elements of a form are available through the GetByName method of the Object form:

Dim Doc As Object
Dim Form As Object
Dim Ctl As Object
 
Doc = ThisComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
Ctl = Form.getByName("MyListBox")

The example determines the model of the MyListBox control element, which is located in the first form of the text document currently open.

If you are not sure of the form of a control element, you can use the option for searching through all forms for the control element required.

Dim Doc As Object
Dim Forms As Object
Dim Form As Object
Dim Ctl As Object
Dim I as Integer
 
Doc = ThisComponent
Forms = Doc.Drawpage.Forms
 
For I = 0 To Forms.Count - 1
  Form = Forms.GetbyIndex(I)
  If Form.HasByName("MyListBox") Then
    Ctl = Form.GetbyName("MyListBox")
    Exit Function
  End If
Next I

The example uses the HasByName method to check all forms of a text document to determine whether they contain a control element model called MyListBox. If a corresponding model is found, then a reference to this is saved in the Ctl variable and the search is terminated. The example is shown as in-line code, for clarity; in practice, the search would be inside a function, called with the name as a string parameter, and include error processing.

Accessing the View of Control Element Forms

To access the view of a control element form, you need the associated model. The view of the control element can then be determined with the assistance of the model and using the document controller.

Dim Doc As Object
Dim DocCrl As Object
Dim Forms As Object
Dim Form As Object
Dim Ctl As Object
Dim CtlView As Object
Dim I as Integer
 
Doc = ThisComponent
DocCrl = Doc.getCurrentController()
Forms = Doc.Drawpage.Forms
 
For I = 0 To Forms.Count - 1
  Form = Forms.GetbyIndex(I)
  If Form.HasByName("MyListBox") Then
    Ctl = Form.GetbyName("MyListBox")
    CtlView = DocCrl.GetControl(Ctl)
    Exit Function
  End If
Next I

The code listed in the example is very similar to the code listed in the previous example for determining a control element model. It uses not only the Doc document object but also the DocCrl document controller object which makes reference to the current document window. With the help of this controller object and the model of the control element, it then uses the GetControl method to determine the view (CtlView variable) of the control element form.

Accessing the Shape Object of Control Element Forms

The method for accessing the shape objects of a control element also uses the corresponding drawing level of the document. To determine a special control element, all drawing elements of the drawing level must be searched through.

Dim Doc As Object
Dim Shape as Object
Dim I as integer
 
Doc = ThisComponent
 
For i = 0 to Doc.DrawPage.Count - 1
  Shape = Doc.DrawPage(i)
  If HasUnoInterfaces(Shape, "com.sun.star.drawing.XControlShape") Then
    If Shape.Control.Name = "MyListBox" Then
      Exit Function
    End If
  End If
Next

The example checks all drawing elements to determine whether they support the com.sun.star.drawing.XControlShape interface needed for control element forms. If this is the case, the Control.Name property then checks whether the name of the control element is MyListBox. If this is true, the function ends the search.

Determining the Size and Position of Control Elements

As already mentioned, the size and position of control elements can be determined using the associated shape object. The control element shape, like all other shape objects, provides the Size and Position properties for this purpose:

Size (struct)
size of control element (com.sun.star.awt.Size data structure)
Position (struct)
position of control element (com.sun.star.awt.Point data structure)

The following example shows how the position and size of a control element can be set using the associated shape object:

Dim Shape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
' ... Initialize Shape object, as previously shown ...
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Shape.Size = Size
Shape.Position = Point

The shape object of the control element must already be known if the code is to function. If this is not the case, it must be determined using the preceding code.


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools