Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XEnhancedMouseClickBroadcaster.java
blob1a6a583819a8af05406a61473e6f024f96e497b9
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc.sheet;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleComponent;
23 import com.sun.star.awt.Point;
24 import com.sun.star.awt.Rectangle;
25 import com.sun.star.awt.XEnhancedMouseClickHandler;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.frame.XModel;
28 import com.sun.star.sheet.XEnhancedMouseClickBroadcaster;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 import lib.MultiMethodTest;
33 import util.AccessibilityTools;
34 import util.DesktopTools;
35 import java.awt.Robot;
36 import java.awt.event.InputEvent;
39 public class _XEnhancedMouseClickBroadcaster extends MultiMethodTest {
40 public XEnhancedMouseClickBroadcaster oObj;
41 protected boolean mousePressed = false;
42 protected boolean mouseReleased = false;
43 protected XEnhancedMouseClickHandler listener = new MyListener();
44 private XModel docModel = null;
46 @Override
47 public void before() {
48 docModel = UnoRuntime.queryInterface(
49 XModel.class,tEnv.getObjRelation("FirstModel"));
50 DesktopTools.bringWindowToFront(docModel);
53 public void _addEnhancedMouseClickHandler() {
54 oObj.addEnhancedMouseClickHandler(listener);
55 clickOnSheet();
57 //make sure that the listener is removed even if the test fails
58 if ((!mousePressed) || (!mouseReleased)) {
59 oObj.removeEnhancedMouseClickHandler(listener);
62 tRes.tested("addEnhancedMouseClickHandler()",
63 mousePressed && mouseReleased);
66 public void _removeEnhancedMouseClickHandler() {
67 requiredMethod("addEnhancedMouseClickHandler()");
68 mousePressed = false;
69 mouseReleased = false;
70 oObj.removeEnhancedMouseClickHandler(listener);
71 clickOnSheet();
72 tRes.tested("removeEnhancedMouseClickHandler()",
73 (!mousePressed) && (!mouseReleased));
76 protected boolean clickOnSheet() {
77 log.println("try to open contex menu...");
79 XWindow xWindow = AccessibilityTools.getCurrentWindow(docModel);
81 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
83 XInterface oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
85 XAccessibleComponent window = UnoRuntime.queryInterface(
86 XAccessibleComponent.class, oObj);
88 Point point = window.getLocationOnScreen();
89 Rectangle rect = window.getBounds();
91 log.println("click mouse button...");
92 try {
93 Robot rob = new Robot();
94 int x = point.X + (rect.Width / 2)+50;
95 int y = point.Y + (rect.Height / 2)+50;
96 rob.mouseMove(x, y);
97 System.out.println("Press Button");
98 rob.mousePress(InputEvent.BUTTON3_MASK);
99 System.out.println("Release Button");
100 rob.mouseRelease(InputEvent.BUTTON3_MASK);
101 System.out.println("done");
102 System.out.println("warte");
103 util.utils.pause(200);
104 System.out.println("Press Button");
105 rob.mousePress(InputEvent.BUTTON1_MASK);
106 System.out.println("Release Button");
107 rob.mouseRelease(InputEvent.BUTTON1_MASK);
108 System.out.println("done "+rob.getAutoDelay());
109 } catch (java.awt.AWTException e) {
110 log.println("couldn't press mouse button");
114 return true;
117 protected class MyListener implements XEnhancedMouseClickHandler {
118 public void disposing(
119 com.sun.star.lang.EventObject eventObject) {
122 public boolean mousePressed(
123 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
124 log.println("mousePressed");
125 mousePressed = true;
127 return true;
130 public boolean mouseReleased(
131 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
132 log.println("mouseReleased");
133 mouseReleased = true;
135 return true;