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