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