From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/text/sbasic/shared/03132000.xhp | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 helpcontent2/source/text/sbasic/shared/03132000.xhp (limited to 'helpcontent2/source/text/sbasic/shared/03132000.xhp') diff --git a/helpcontent2/source/text/sbasic/shared/03132000.xhp b/helpcontent2/source/text/sbasic/shared/03132000.xhp new file mode 100644 index 000000000..475fd4333 --- /dev/null +++ b/helpcontent2/source/text/sbasic/shared/03132000.xhp @@ -0,0 +1,131 @@ + + + + + + + CreateUnoListener Function + /text/sbasic/shared/03132000.xhp + + + + + + +
+ + CreateUnoListener function + + + +CreateUnoListener Function +Creates a Listener instance. +
+Many Uno interfaces let you register listeners on a special listener interface. This allows you to listen for specific events and call up the appropriate listener method. The CreateUnoListener function waits for the called listener interface and then passes the interface an object that the interface supports. This object is then passed to the method to register the listener. + +oListener = CreateUnoListener( Prefixname, ListenerInterfaceName ) + +The following example is based on a Basic library object. + +Dim oListener +oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" ) + +The CreateUnoListener method requires two parameters. The first is a prefix and is explained in detail below. The second parameter is the fully qualified name of the Listener interface that you want to use. +The Listener must then be added to the Broadcaster Object. This is done by calling the appropriate method for adding a Listener. These methods always follow the pattern "addFooListener", where "Foo" is the Listener Interface Type, without the 'X'. In this example, the addContainerListener method is called to register the XContainerListener: + +Dim oLib +oLib = BasicLibraries.Library1 ' Library1 must exist! +oLib.addContainerListener( oListener ) ' Register the listener + +The Listener is now registered. When an event occurs, the corresponding Listener calls the appropriate method from the com.sun.star.container.XContainerListener Interface. +The prefix calls registered Listeners from Basic-subroutines. The Basic run-time system searches for Basic-subroutines or functions that have the name "PrefixListenerMethode" and calls them when found. Otherwise, a run-time error occurs. +In this example, the Listener-Interface uses the following methods: + + + + disposing: + + + Listener base interface (com.sun.star.lang.XEventListener): base interface for all Listener Interfaces + + + elementInserted: + + + Method of the com.sun.star.container.XContainerListener interface + + + elementRemoved: + + + Method of the com.sun.star.container.XContainerListener interface + + + elementReplaced: + + + Method of the com.sun.star.container.XContainerListener interface + +In this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic: + + + + ContListener_disposing + + + ContListener_elementInserted + + + ContListener_elementRemoved + + + ContListener_elementReplaced + +An event structure type that contains information about an event exists for every Listener type. When a Listener method is called, an instance of this event is passed to the method as a parameter. Basic Listener methods can also call these event objects, so long as the appropriate parameter is passed in the Sub declaration. For example: + +Sub ContListener_disposing( oEvent ) + MsgBox "disposing" + MsgBox oEvent.Dbg_Properties +End Sub + +Sub ContListener_elementInserted( oEvent ) + MsgBox "elementInserted" + MsgBox oEvent.Dbg_Properties +End Sub + +Sub ContListener_elementRemoved( oEvent ) + MsgBox "elementRemoved" + MsgBox oEvent.Dbg_Properties +End Sub + +Sub ContListener_elementReplaced( oEvent ) + MsgBox "elementReplaced" + MsgBox oEvent.Dbg_Properties +End Sub + +You do not need to include the parameter of an event object if the object is not used: + +' Minimal implementation of Sub disposing +Sub ContListener_disposing +End Sub + +Listener methods must always be implemented to avoid Basic run-time errors. + + +
-- cgit v1.2.3