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