Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XEnhancedMouseClickBroadcaster.java
blob2034bb892047364ffe6bf36491ef2144504a0d73
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package ifc.sheet;
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleComponent;
32 import com.sun.star.awt.Point;
33 import com.sun.star.awt.Rectangle;
34 import com.sun.star.awt.XEnhancedMouseClickHandler;
35 import com.sun.star.awt.XExtendedToolkit;
36 import com.sun.star.awt.XTopWindow;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.sheet.XEnhancedMouseClickBroadcaster;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 import lib.MultiMethodTest;
46 import lib.StatusException;
48 import util.AccessibilityTools;
49 import util.DesktopTools;
50 import util.utils;
52 import java.awt.Robot;
53 import java.awt.event.InputEvent;
56 public class _XEnhancedMouseClickBroadcaster extends MultiMethodTest {
57 public XEnhancedMouseClickBroadcaster oObj;
58 protected boolean mousePressed = false;
59 protected boolean mouseReleased = false;
60 protected XEnhancedMouseClickHandler listener = new MyListener();
61 private XModel docModel = null;
63 public void before() {
64 docModel = (XModel) UnoRuntime.queryInterface(
65 XModel.class,tEnv.getObjRelation("FirstModel"));
66 DesktopTools.bringWindowToFront(docModel);
69 public void _addEnhancedMouseClickHandler() {
70 oObj.addEnhancedMouseClickHandler(listener);
71 clickOnSheet();
73 //make sure that the listener is removed even if the test fails
74 if ((!mousePressed) || (!mouseReleased)) {
75 oObj.removeEnhancedMouseClickHandler(listener);
78 tRes.tested("addEnhancedMouseClickHandler()",
79 mousePressed && mouseReleased);
82 public void _removeEnhancedMouseClickHandler() {
83 requiredMethod("addEnhancedMouseClickHandler()");
84 mousePressed = false;
85 mouseReleased = false;
86 oObj.removeEnhancedMouseClickHandler(listener);
87 clickOnSheet();
88 tRes.tested("removeEnhancedMouseClickHandler()",
89 (!mousePressed) && (!mouseReleased));
92 protected boolean clickOnSheet() {
93 log.println("try to open contex menu...");
94 AccessibilityTools at = new AccessibilityTools();
96 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)tParam.getMSF(), docModel);
98 XAccessible xRoot = at.getAccessibleObject(xWindow);
100 XInterface oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
102 XAccessibleComponent window = (XAccessibleComponent) UnoRuntime.queryInterface(
103 XAccessibleComponent.class, oObj);
105 Point point = window.getLocationOnScreen();
106 Rectangle rect = window.getBounds();
108 log.println("klick mouse button...");
109 try {
110 Robot rob = new Robot();
111 int x = point.X + (rect.Width / 2)+50;
112 int y = point.Y + (rect.Height / 2)+50;
113 rob.mouseMove(x, y);
114 System.out.println("Press Button");
115 rob.mousePress(InputEvent.BUTTON3_MASK);
116 System.out.println("Release Button");
117 rob.mouseRelease(InputEvent.BUTTON3_MASK);
118 System.out.println("done");
119 System.out.println("warte");
120 shortWait();
121 System.out.println("Press Button");
122 rob.mousePress(InputEvent.BUTTON1_MASK);
123 System.out.println("Release Button");
124 rob.mouseRelease(InputEvent.BUTTON1_MASK);
125 System.out.println("done "+rob.getAutoDelay());
126 } catch (java.awt.AWTException e) {
127 log.println("couldn't press mouse button");
131 return true;
134 private void shortWait() {
135 try {
136 Thread.currentThread().sleep(2000);
137 } catch (InterruptedException e) {
138 System.out.println("While waiting :" + e);
142 protected class MyListener implements XEnhancedMouseClickHandler {
143 public void disposing(
144 com.sun.star.lang.EventObject eventObject) {
147 public boolean mousePressed(
148 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
149 log.println("mousePressed");
150 mousePressed = true;
152 return true;
155 public boolean mouseReleased(
156 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
157 log.println("mouseReleased");
158 mouseReleased = true;
160 return true;