<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VickyVi</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VickyVi"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/VickyVi"/>
	<updated>2026-12-04T11:50:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Forms/Scripting_and_Events&amp;diff=190935</id>
		<title>Documentation/DevGuide/Forms/Scripting and Events</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Forms/Scripting_and_Events&amp;diff=190935"/>
		<updated>2010-12-30T12:14:04Z</updated>

		<summary type="html">&lt;p&gt;VickyVi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Documentation/DevGuide/FormsTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|PrevPage=Documentation/DevGuide/Forms/Validation and Bindings&lt;br /&gt;
|NextPage=Documentation/DevGuide/Forms/Common Tasks&lt;br /&gt;
}}&lt;br /&gt;
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Forms/{{SUBPAGENAME}}}} &lt;br /&gt;
 {{DISPLAYTITLE:Scripting and Events}}&lt;br /&gt;
To create form documents that are able to do more than just reading and writing plain data, it is often necessary to enhance the form with scripting functionality. That is, for a given form component, you want to declare that a certain script should be called, when a certain event occurs.&lt;br /&gt;
&lt;br /&gt;
For example, you may need a check box control, which calls a certain macro when its check state changes. Within this macro, you can, for instance, enable or disable other controls that depend on the check box being checked.&lt;br /&gt;
&lt;br /&gt;
One possible solution is to use a completely programmatic approach: just bind a script to the OnLoad event of the whole document, create an &amp;lt;idls&amp;gt;com.sun.star.awt.XItemListener&amp;lt;/idls&amp;gt;, and register it at the check box control in question, using the &amp;lt;idls&amp;gt;com.sun.star.awt.XCheckBox&amp;lt;/idls&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
However, this method is inefficient, because the whole scripting engine starts when the document is loaded. The scripting engine should start at the latest possible point, which is the moment the user clicks the check box for the first time.&lt;br /&gt;
&lt;br /&gt;
Form components feature a mechanism that is more efficient. For every form component part of a hierarchy of form components, you can specify a script to be called upon a certain event. You only specify this once, at the time the form component is created and placed in the document.,&lt;br /&gt;
&lt;br /&gt;
Look at the &amp;lt;idl&amp;gt;com.sun.star.form.FormComponents&amp;lt;/idl&amp;gt; service, which was encountered previously. The service includes the interface &amp;lt;idl&amp;gt;com.sun.star.script.XEventAttacherManager&amp;lt;/idl&amp;gt;. This interface allows you to manage the events that are associated with the elements in the &amp;lt;idls&amp;gt;com.sun.star.form.FormComponents&amp;lt;/idls&amp;gt; container.&lt;br /&gt;
&lt;br /&gt;
Note that an event together with an associated script is described by the &amp;lt;idls&amp;gt;com.sun.star.script.ScriptEventDescriptor&amp;lt;/idls&amp;gt;, with the following elements:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=4 style=&amp;quot;border-collapse:collapse;&amp;quot;&lt;br /&gt;
|-bgcolor=#EDEDED&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Properties of &amp;lt;idl&amp;gt;com.sun.star.script.ScriptEventDescriptor&amp;lt;/idl&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.script.ScriptEventDescriptor:ListenerType&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|Specifies the completely qualified name of a listener interface. This implies that you can only register scripts for events that are notified using UNO. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.script.ScriptEventDescriptor:EventMethod&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|Specifies a method of the &amp;lt;code&amp;gt;ListenerType&amp;lt;/code&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
Together with the &amp;lt;code&amp;gt;ListenerType&amp;lt;/code&amp;gt; member, this completely describes the event for which a script is to be registered. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.script.ScriptEventDescriptor:AddListenerParam&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|Specifies a parameter that is to be used when adding listeners, as described by the &amp;lt;code&amp;gt;ListenerType&amp;lt;/code&amp;gt; element) For most listener types, this is not necessary. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.script.ScriptEventDescriptor:ScriptType&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|Specifies which type of script is to be associated with the event. &amp;lt;idl&amp;gt;com.sun.star.form.FormComponents&amp;lt;/idl&amp;gt; currently only support &amp;lt;code&amp;gt;StarBasic&amp;lt;/code&amp;gt; here. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.script.ScriptEventDescriptor:ScriptCode&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|Specifies which script code to call. In case of &amp;lt;code&amp;gt;ScriptType&amp;lt;/code&amp;gt; being &amp;lt;code&amp;gt;StarBasic&amp;lt;/code&amp;gt;, this must specify a Basic procedure or function, either within the application-wide code repository, or within the document which the form component belongs to. In the first case, the script code starts with &amp;quot;&amp;lt;code&amp;gt;application:&amp;lt;/code&amp;gt;&amp;quot;, else with &amp;quot;&amp;lt;code&amp;gt;document:&amp;lt;/code&amp;gt;&amp;quot;. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example registers a certain Basic procedure for the event which is triggered when the state of a radio button control changes, for example, when a radio button has been selected or deselected:&lt;br /&gt;
&lt;br /&gt;
  Dim oEvent as new com.sun.star.script.ScriptEventDescriptor&lt;br /&gt;
  oEvent.ListenerType = &amp;quot;com.sun.star.awt.XItemListener&amp;quot;&lt;br /&gt;
  oEvent.EventMethod = &amp;quot;itemStateChanged&amp;quot;&lt;br /&gt;
  oEvent.ScriptType = &amp;quot;StarBasic&amp;quot;&lt;br /&gt;
  oEvent.ScriptCode = &amp;quot;application:Standard.macro_assignment.onColorChange&amp;quot;&lt;br /&gt;
  oSampleForm.registerScriptEvent( i, oEvent )[http://www.online-poker-spielen.biz/mansion-poker-review/ mansion poker] is under construction&lt;br /&gt;
&lt;br /&gt;
For the i&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; sub component of &amp;lt;code&amp;gt;oSampleForm&amp;lt;/code&amp;gt;, this associates the macro &amp;lt;code&amp;gt;onColorChange&amp;lt;/code&amp;gt;, located in the module &amp;lt;code&amp;gt;macro_assignment&amp;lt;/code&amp;gt; of the application-wide library &amp;lt;code&amp;gt;Standard&amp;lt;/code&amp;gt;, with the &amp;lt;idlm&amp;gt;com.sun.star.awt.XItemListener:itemStateChanged&amp;lt;/idlm&amp;gt; event. You can use this with every form component which supports notification of &amp;lt;idls&amp;gt;com.sun.star.awt.XItemListener&amp;lt;/idls&amp;gt;s, in particular with radio buttons (&amp;lt;idls&amp;gt;com.sun.star.awt.XRadioButton&amp;lt;/idls&amp;gt;) and check boxes (&amp;lt;idls&amp;gt;com.sun.star.awt.XCheckBox&amp;lt;/idls&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that simply registering script events at a &amp;lt;idls&amp;gt;com.sun.star.form.FormComponents&amp;lt;/idls&amp;gt; instance does not do anything. In particular, registering script events does not yet mean that the script will be called automatically. In fact, the &amp;lt;idls&amp;gt;com.sun.star.script.XEventAttacherManager&amp;lt;/idls&amp;gt; interface merely acts as a container to remember the associated events. In a living form document, there are controller instances involved, which take care of the scripts that are really being called, by adding themselves as &amp;lt;idls&amp;gt;com.sun.star.script.XScriptListener&amp;lt;/idls&amp;gt; to the event attacher manager.&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation/Developer&amp;#039;s Guide/Forms]]&lt;/div&gt;</summary>
		<author><name>VickyVi</name></author>
	</entry>
</feed>