1 <!--***********************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  ***********************************************************-->
21 <HTML>
22 <HEAD>
23 <META NAME="GENERATOR" Content="Microsoft Developer Studio">
24 <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
25 <TITLE>Document Title</TITLE>
26 </HEAD>
27 <BODY id=theBody>
28 
29 <script language="JScript">
30 function Main( id)
31 {
32 var  objServiceManager= new ActiveXObject("com.sun.star.ServiceManager");
33 
34 var objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop");
35 
36 var args= new Array();
37 
38 var objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args);
39 
40 var listener;
41 if( id == 0)
42   listener= new XEventListener_Impl();
43 else if(id == 1)
44   listener= new ActiveXObject("EventListener.EvtListener");
45 objDocument.addEventListener( listener);
46 }
47 
48 
49 function XEventListener_Impl()
50 {
51 	this._environment= "JScript";
52 	this._implementedInterfaces= new Array( "com.sun.star.lang.XEventListener");
53 
54 	//XEventListener
55 	this.disposing= XEventListener_disposing;
56 }
57 
58 function XEventListener_disposing( source)
59 {
60  alert("JScript Event Listener \n The document was closed");
61 }
62 </script>
63 
64 <script language="VBScript">
65 SUB MainVB( id)
66 Set objServiceManager= CreateObject("com.sun.star.ServiceManager")
67 
68 Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
69 
70 Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
71 
72 'Open a new empty writer document
73 Dim args()
74 Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
75 
76 Dim eventListener
77 select case id
78   case 0
79     Set eventListener= CreateObject("EventListener.EvtListener")
80   case 1
81     Set eventListener= CreateObject("VBasicEventListener.VBEventListener")
82 end select
83 
84 objDocument.addEventListener eventlistener
85 END SUB
86 
87 </script>
88 <p>
89 The script on this page creates a new StarOffice document and connects an event listener
90 to it. When the document is closed then the XEventListener::disposing method is called on the
91 listener object. How the listener is set up depends on the button being clicked.
92 </p>
93 <p>
94 The button will run JScript code that and adds an JScript event listener to the document.
95 The listener is also implemented in JScript an is on this page..
96 </p>
97 <button onclick='Main(0)'>JScript go</Button>
98 <p>
99 
100 The button runs JScript code that creates the ActiveX component EventListener.EvtListener that
101 is written in C++ and housed in a dll. Then the event listener is added to the document.
102 </p>
103 <button onclick='Main( 1)'>JScript go</Button>
104 <p>
105 The button runs VBScript code that creates the components EventListener.EvtListener and adds it
106 to the document.
107 </p>
108 <button onclick='MainVB(0)'>VBScript</Button>
109 <p>
110 Runs VBScript code that creates VBasicEventListener.VBEventListener ActiveX component which was
111 written with VB
112 </p>
113 <button onclick='MainVB(1)'>VBScript</Button>
114 
115 </body>
116 </html>
117 
118 
119