1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="awt_XWindow" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32*****
33'*************************************************************************
34
35
36
37' Be sure that all variables are dimensioned:
38option explicit
39
40'*************************************************************************
41' This Interface/Service test depends on the following GLOBAL variables,
42' which must be specified in the object creation:
43
44
45'*************************************************************************
46'       Global oXWindow as Object
47'       Global oCtrlShape as Variant (could be NULL)
48
49
50Dim bCB1_windowResized As Boolean
51Dim bCB2_windowResized As Boolean
52Dim bCB1_windowMoved As Boolean
53Dim bCB2_windowMoved As Boolean
54Dim bCB1_windowHidden As Boolean
55Dim bCB2_windowHidden As Boolean
56Dim bCB1_windowShown As Boolean
57Dim bCB2_windowShown As Boolean
58Dim bCB1_disposing As Boolean
59Dim bCB2_disposing As Boolean
60Dim bCB3_focusGained As Boolean
61Dim bCB4_focusGained As Boolean
62Dim bCB3_focusLost As Boolean
63Dim bCB4_focusLost As Boolean
64
65
66Sub RunTest()
67
68'*************************************************************************
69' INTERFACE:
70' com.sun.star.awt.XWindow
71'*************************************************************************
72On Error Goto ErrHndl
73    Dim bOK As Boolean
74
75    If isNull(oXWindow) Then
76		Out.Log("Could not get relation 'oXWindow' !")
77    End If
78    Dim oListener1 As Object, oListener2 As Object
79    Dim oListener3 As Object, oListener4 As Object
80    Dim oListener5 As Object, oListener6 As Object
81    Dim oListener7 As Object, oListener8 As Object
82    Dim oListener9 As Object, oListener10 As Object
83    Dim oListener11 As Object, oListener12 As Object
84    Dim size As Variant, pos As Variant
85
86    bCB1_windowResized = false
87    bCB2_windowResized = false
88    bCB1_windowMoved = false
89    bCB2_windowMoved = false
90    bCB1_windowHidden = false
91    bCB2_windowHidden = false
92    bCB1_windowShown = false
93    bCB2_windowShown = false
94    bCB1_disposing = false
95    bCB2_disposing = false
96    bCB3_focusGained = false
97    bCB4_focusLost = false
98    bCB3_focusGained = false
99    bCB4_focusLost = false
100
101    Out.Log("create two com.sun.star.awt.XWindowListener")
102    oListener1 = createUNOListener("CB1_", "com.sun.star.awt.XWindowListener")
103    oListener2 = createUNOListener("CB2_", "com.sun.star.awt.XWindowListener")
104    Out.Log("create two  com.sun.star.awt.XFocusListener")
105    oListener3 = createUNOListener("CB3_", "com.sun.star.awt.XFocusListener")
106    oListener4 = createUNOListener("CB4_", "com.sun.star.awt.XFocusListener")
107    Out.Log("create two com.sun.star.awt.XKeyListener")
108    oListener5 = createUNOListener("CB5_", "com.sun.star.awt.XKeyListener")
109    oListener6 = createUNOListener("CB6_", "com.sun.star.awt.XKeyListener")
110    Out.Log("create two com.sun.star.awt.XMouseListener")
111    oListener7 = createUNOListener("CB7_", "com.sun.star.awt.XMouseListener")
112    oListener8 = createUNOListener("CB8_", "com.sun.star.awt.XMouseListener")
113    Out.Log("create two com.sun.star.awt.XMouseMotionListener")
114    oListener9 = createUNOListener("CB9_", "com.sun.star.awt.XMouseMotinListener")
115    oListener10 = createUNOListener("CB10_", "com.sun.star.awt.XMouseMotinListener")
116    Out.Log("create two com.sun.star.awt.XPaintListener")
117    oListener11 = createUNOListener("CB11_", "com.sun.star.awt.XPaintListener")
118    oListener12 = createUNOListener("CB12_", "com.sun.star.awt.XPaintListener")
119
120    Test.StartMethod("setPosSize()")
121    bOK = true
122    oObj.setPosSize(250,250,250,250,com.sun.star.awt.PosSize.POSSIZE)
123    Out.Log("oObj.setPosSize(250,250,250,250,com.sun.star.awt.PosSize.POSSIZE")
124    Test.StartMethod("getPosSize()")
125    Dim vRectangle As Variant
126    vRectangle = oObj.getPosSize()
127    Out.Log("Returned Values: X=" + vRectangle.X + " Y=" + vRectangle.Y _
128           + " WIDTH=" + vRectangle.WIDTH + " HEIGTH=" + vRectangle.HEIGHT
129    bOK = bOK AND vRectangle.X = 250
130    bOK = bOK AND vRectangle.Y = 250
131    bOK = bOK AND vRectangle.Width = 250
132    bOK = bOK AND vRectangle.Height = 250
133    Test.MethodTested("setPosSize()", bOK)
134    Test.MethodTested("getPosSize()", bOK)
135
136    Test.StartMethod("setVisible()")
137    bOK = true
138    oObj.setVisible(false)
139    oObj.setVisible(true)
140    Test.MethodTested("setVisible()", bOK)
141
142    Test.StartMethod("setEnable()")
143    bOK = true
144    oObj.setEnable(false)
145    oObj.setEnable(true)
146    Test.MethodTested("setEnable()", bOK)
147
148    Test.StartMethod("setFocus()")
149    bOK = true
150    oObj.setFocus()
151    oXWindow.setFocus()
152    oObj.setFocus()
153    Test.MethodTested("setFocus()", bOK)
154
155    Test.StartMethod("addWindowListener()")
156    bOK = true
157    oObj.addWindowListener(oListener1)
158    oObj.addWindowListener(oListener2)
159    oObj.setVisible(false)
160    oObj.setVisible(true)
161    if NOT isNull(oCtrlShape) then
162        size = oCtrlShape.Size
163        size.Width = size.Width + 100
164        size.Height = size.Height + 100
165        oCtrlShape.Size = size
166
167        pos = oCtrlShape.Position
168        pos.X = pos.X + 100
169        pos.Y = pos.Y + 100
170        oCtrlShape.Position = pos
171    else
172        Out.Log("oObj.setPosSize(300,300,300,300,com.sun.star.awt.PosSize.POSSIZE)")
173        oObj.setPosSize(300,300,300,300,com.sun.star.awt.PosSize.POSSIZE)
174    end if
175    wait(1000)
176    bOK = bOK AND bCB1_windowResized AND bCB2_windowResized AND bCB1_windowMoved AND _
177          bCB2_windowMoved AND bCB1_windowHidden AND bCB2_windowHidden AND _
178          bCB1_windowShown AND bCB2_windowShown AND NOT bCB1_disposing AND NOT _
179          bCB2_disposing
180    Test.MethodTested("addWindowListener()", bOK)
181
182    Test.StartMethod("removeWindowListener()")
183    bOK = true
184    bCB1_windowResized = false
185    bCB2_windowResized = false
186    bCB1_windowMoved = false
187    bCB2_windowMoved = false
188    bCB1_windowHidden = false
189    bCB2_windowHidden = false
190    bCB1_windowShown = false
191    bCB2_windowShown = false
192    bCB1_disposing = false
193    bCB2_disposing = false
194    oObj.removeWindowListener(oListener2)
195    oObj.setVisible(false)
196    oObj.setVisible(true)
197    oObj.setVisible(false)
198    oObj.setVisible(true)
199    if NOT isNull(oCtrlShape) then
200        size = oCtrlShape.Size
201        size.Width = size.Width + 100
202        size.Height = size.Height + 100
203        oCtrlShape.Size = size
204
205        pos = oCtrlShape.Position
206        pos.X = pos.X + 100
207        pos.Y = pos.Y + 100
208        oCtrlShape.Position = pos
209    else
210        Out.Log("oObj.setPosSize(300,300,300,300,com.sun.star.awt.PosSize.POSSIZE)")
211        oObj.setPosSize(301,301,301,301,com.sun.star.awt.PosSize.POSSIZE)
212    end if
213    wait(200)
214    bOK = bOK AND bCB1_windowResized AND NOT bCB2_windowResized AND bCB1_windowMoved AND NOT _
215          bCB2_windowMoved AND bCB1_windowHidden AND NOT bCB2_windowHidden AND _
216          bCB1_windowShown AND NOT bCB2_windowShown AND NOT bCB1_disposing AND NOT _
217          bCB2_disposing
218    oObj.removeWindowListener(oListener1)
219    Test.MethodTested("removeWindowListener()", bOK)
220
221    Test.StartMethod("addFocusListener()")
222    bOK = true
223    oObj.addFocusListener(oListener3)
224    oObj.addFocusListener(oListener4)
225    oObj.setFocus()
226    wait(200)
227    oXWindow.setFocus()
228    wait(200)
229    oObj.setFocus()
230    wait(200)
231    bOK = bOK AND bCB3_focusGained AND bCB4_focusLost AND bCB3_focusGained AND bCB4_focusLost
232    Test.MethodTested("addFocusListener()", bOK)
233
234    Test.StartMethod("removeFocusListener()")
235    bOK = true
236    bCB3_focusGained = false
237    bCB4_focusLost = false
238    bCB3_focusGained = false
239    bCB4_focusLost = false
240    oObj.removeFocusListener(oListener4)
241    oObj.setFocus()
242    wait(200)
243    oXWindow.setFocus()
244    wait(200)
245    oObj.setFocus()
246    wait(200)
247    bOK = bOK AND bCB3_focusGained AND NOT bCB4_focusLost AND bCB3_focusGained AND NOT bCB4_focusLost
248    oObj.removeFocusListener(oListener3)
249    Test.MethodTested("removeFocusListener()", bOK)
250
251'***************************************************************************************
252'* LISTENERS which needs interactions                                                  *
253'***************************************************************************************
254'*
255'* The following listener tests need interactions. That means i.e. a
256'* com.sun.star.awt.XKeyListener needs action from the keyboard. This is not possible in
257'* the automatic API-Testing. To test the listener you can set a breakpoint at the
258'* specific function call. Then do interaction which should call the listener. It must be
259'* pop up a message box.
260'*
261'***************************************************************************************
262
263    Test.StartMethod("addKeyListener()")
264    bOK = true
265    Out.Log("Not realy tested! Please see comments in Basic-Source.")
266    oObj.addKeyListener(oListener5)
267    oObj.addKeyListener(oListener6)
268    bOK = bOK AND true
269    Test.MethodTested("addKeyListener()", bOK)
270
271    Test.StartMethod("removeKeyListener()")
272    bOK = true
273    Out.Log("Not realy tested! Please see comments in Basic-Source.")
274    oObj.removeKeyListener(oListener5)
275    bOK = bOK AND true
276    oObj.removeKeyListener(oListener6)
277    Test.MethodTested("removeKeyListener()", bOK)
278
279    Test.StartMethod("addMouseListener()")
280    bOK = true
281    Out.Log("Not realy tested! Please see comments in Basic-Source.")
282    oObj.addMouseListener(oListener7)
283    oObj.addMouseListener(oListener8)
284    bOK = bOK AND true
285    Test.MethodTested("addMouseListener()", bOK)
286
287    Test.StartMethod("removeMouseListener()")
288    bOK = true
289    Out.Log("Not realy tested! Please see comments in Basic-Source.")
290    oObj.removeMouseListener(oListener7)
291    bOK = bOK AND true
292    oObj.removeMouseListener(oListener8)
293    Test.MethodTested("removeMouseListener()", bOK)
294
295    Test.StartMethod("addMouseMotionListener()")
296    bOK = true
297    Out.Log("Not realy tested! Please see comments in Basic-Source.")
298    oObj.addMouseMotionListener(oListener9)
299    oObj.addMouseMotionListener(oListener10)
300    bOK = bOK AND true
301    Test.MethodTested("addMouseMotionListener()", bOK)
302
303    Test.StartMethod("removeMouseMotionListener()")
304    bOK = true
305    Out.Log("Not realy tested! Please see comments in Basic-Source.")
306    oObj.removeMouseMotionListener(oListener9)
307    bOK = bOK AND true
308    oObj.removeMouseMotionListener(oListener10)
309    Test.MethodTested("removeMouseMotionListener()", bOK)
310
311    Test.StartMethod("addPaintListener()")
312    bOK = true
313    Out.Log("Not realy tested! Please see comments in Basic-Source.")
314    oObj.addPaintListener(oListener11)
315    oObj.addPaintListener(oListener12)
316    bOK = bOK AND true
317    Test.MethodTested("addPaintListener()", bOK)
318
319    Test.StartMethod("removePaintListener()")
320    bOK = true
321    Out.Log("Not realy tested! Please see comments in Basic-Source.")
322    oObj.removePaintListener(oListener11)
323    bOK = bOK AND true
324    oObj.removePaintListener(oListener12)
325    Test.MethodTested("removePaintListener()", bOK)
326
327Exit Sub
328ErrHndl:
329    Test.Exception()
330    bOK = false
331    resume next
332End Sub
333
334' Listener call backs for com.sun.star.awt.XWindowListener
335Sub CB1_windowResized
336    Out.Log("CallBack for Listener1 windowResized was called.")
337    bCB1_windowResized = true
338End Sub
339Sub CB2_windowResized
340    Out.Log("CallBack for Listener2 windowResized was called.")
341    bCB2_windowResized = true
342End Sub
343Sub CB1_windowMoved
344    Out.Log("CallBack for Listener1 windowMoved was called.")
345    bCB1_windowMoved = true
346End Sub
347Sub CB2_windowMoved
348    Out.Log("CallBack for Listener2 windowMoved was called.")
349    bCB2_windowMoved = true
350End Sub
351Sub CB1_windowHidden
352    Out.Log("CallBack for Listener1 windowHidden was called.")
353    bCB1_windowHidden = true
354End Sub
355Sub CB2_windowHidden
356    Out.Log("CallBack for Listener2 windowHidden was called.")
357    bCB2_windowHidden = true
358End Sub
359Sub CB1_windowShown
360    Out.Log("CallBack for Listener1 windowShown was called.")
361    bCB1_windowShown = true
362End Sub
363Sub CB2_windowShown
364    Out.Log("CallBack for Listener2 windowShown was called.")
365    bCB2_windowShown = true
366End Sub
367Sub CB1_disposing
368    Out.Log("CallBack for Listener1 disposing was called")
369    bCB1_disposing = true
370End Sub
371Sub CB2_disposing
372    Out.Log("CallBack for Listener2 disposing was called")
373    bCB2_disposing = true
374End Sub
375
376' Listener call backs for com.sun.star.awt.XFocusListener
377Sub CB3_focusGained
378    Out.Log("CallBack for Listener3 'focusGained' was called")
379    bCB3_focusGained = true
380End Sub
381Sub CB4_focusGained
382    Out.Log("CallBack for Listener4 'focusGained' was called")
383    bCB4_focusGained = true
384End Sub
385Sub CB3_focusLost
386    Out.Log("CallBack for Listener3 'focusLost' was called")
387    bCB3_focusLost = true
388End Sub
389Sub CB4_focusLost
390    Out.Log("CallBack for Listener4 'focusLost' was called")
391    bCB4_focusLost = true
392End Sub
393Sub CB3_disposing
394End Sub
395Sub CB4_disposing
396End Sub
397
398' Listener call backs for com.sun.star.awt.XKeyListener
399' They will never be called beause of no interaction in API-Testing
400Sub CB5_keyPressed
401  MsgBox("CallBack for Listener5 'keyPressed' was called")
402End Sub
403Sub CB6_keyPressed
404  MsgBox("CallBack for Listener6 'keyPressed' was called")
405End Sub
406Sub CB5_keyReleased
407  MsgBox("CallBack for Listener5 'keyReleased' was called")
408End Sub
409Sub CB6_keyReleased
410  MsgBox("CallBack for Listener6 'keyReleased' was called")
411End Sub
412Sub CB5_disposing
413End Sub
414Sub CB6_disposing
415End Sub
416
417
418' Listener call backs for com.sun.star.awt.XMouseListener
419' They will never be called beause of no interaction in API-Testing
420Sub CB7_mousePressed
421  MsgBox("CallBack for Listener7 'mousePressed' was called")
422End Sub
423Sub CB8_mousePressed
424  MsgBox("CallBack for Listener8 'mousePressed' was called")
425End Sub
426Sub CB7_mouseReleased
427  MsgBox("CallBack for Listener8 'mouseReleased' was called")
428End Sub
429Sub CB8_mouseReleased
430  MsgBox("CallBack for Listener8 'mouseReleased' was called")
431End Sub
432Sub CB7_mouseEntered
433  MsgBox("CallBack for Listener7 'mouseEntered' was called")
434End Sub
435Sub CB8_mouseEntered
436  MsgBox("CallBack for Listener8 'mouseEntered' was called")
437End Sub
438Sub CB7_mouseExited
439  MsgBox("CallBack for Listener7 'mouseExited' was called")
440End Sub
441Sub CB8_mouseExited
442  MsgBox("CallBack for Listener8 'mouseExited' was called")
443End Sub
444Sub CB7_disposing
445End Sub
446Sub CB8_disposing
447End Sub
448
449
450' Listener call backs for com.sun.star.awt.XMouseMotionListener
451' They will never be called beause of no interaction in API-Testing
452Sub CB9_mouseDragged
453  MsgBox("CallBack for Listener9 'mouseDragged' was called")
454End Sub
455Sub CB10_mouseDragged
456  MsgBox("CallBack for Listener10 'mouseDragged' was called")
457End Sub
458Sub CB9_mouseMoved
459  MsgBox("CallBack for Listener9 'mouseMoved' was called")
460End Sub
461Sub CB10_mouseMoved
462  MsgBox("CallBack for Listener10 'mouseMoved' was called")
463End Sub
464Sub CB9_disposing
465End Sub
466Sub CB10_disposing
467End Sub
468
469
470' Listener call backs for com.sun.star.awt.XMouseMotionListener
471' They will never be called beause of no interaction in API-Testing
472Sub CB11_windowPaint
473  MsgBox("CallBack for Listener11 'windowPaint' was called")
474End Sub
475Sub CB12_windowPaint
476  MsgBox("CallBack for Listener12 'windowPaint' was called")
477End Sub
478Sub CB11_disposing
479End Sub
480Sub CB12_disposing
481End Sub
482
483</script:module>
484