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