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 ************************************************************************/
31 import com
.sun
.star
.accessibility
.AccessibleRole
;
32 import com
.sun
.star
.accessibility
.XAccessible
;
33 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
34 import com
.sun
.star
.accessibility
.XAccessibleContext
;
35 import com
.sun
.star
.awt
.Point
;
36 import com
.sun
.star
.awt
.Rectangle
;
37 import com
.sun
.star
.awt
.XExtendedToolkit
;
38 import com
.sun
.star
.awt
.XWindow
;
39 import com
.sun
.star
.frame
.XModel
;
40 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.ui
.XContextMenuInterception
;
43 import com
.sun
.star
.ui
.XContextMenuInterceptor
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import helper
.ContextMenuInterceptor
;
47 import java
.awt
.Robot
;
48 import java
.awt
.event
.InputEvent
;
49 import lib
.MultiMethodTest
;
51 import lib
.StatusException
;
52 import util
.AccessibilityTools
;
53 import util
.DesktopTools
;
56 public class _XContextMenuInterception
extends MultiMethodTest
{
58 private XModel docModel
= null;
59 private XContextMenuInterceptor xCI
= null;
60 public XContextMenuInterception oObj
= null;
61 private XWindow xWindow
= null;
62 private XMultiServiceFactory xMSF
= null;
63 private Point point
= null;
65 public void before() {
66 docModel
= (XModel
) UnoRuntime
.queryInterface(
67 XModel
.class,tEnv
.getObjRelation("FirstModel"));
69 xCI
= (XContextMenuInterceptor
) UnoRuntime
.queryInterface(
70 XContextMenuInterceptor
.class, new ContextMenuInterceptor());
72 xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
74 //ensure that the first model is focused
76 log
.println("ensure that the first model is focused");
77 DesktopTools
.bringWindowToFront(docModel
);
79 utils
.shortWait(3000);
84 oObj
.releaseContextMenuInterceptor(xCI
);
88 public void _registerContextMenuInterceptor() {
89 oObj
.registerContextMenuInterceptor(xCI
);
90 openContextMenu(docModel
);
91 boolean res
= checkHelpEntry();
93 tRes
.tested("registerContextMenuInterceptor()",res
);
96 public void _releaseContextMenuInterceptor() {
97 requiredMethod("registerContextMenuInterceptor()");
98 oObj
.releaseContextMenuInterceptor(xCI
);
99 openContextMenu(docModel
);
100 boolean res
= checkHelpEntry();
102 tRes
.tested("releaseContextMenuInterceptor()",!res
);
105 private boolean checkHelpEntry(){
106 XInterface toolkit
= null;
109 log
.println("get accesibility...");
111 toolkit
= (XInterface
) xMSF
.createInstance("com.sun.star.awt.Toolkit");
112 } catch (com
.sun
.star
.uno
.Exception e
){
113 log
.println("could not get Toolkit " + e
.toString());
115 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
116 XExtendedToolkit
.class, toolkit
);
118 XAccessible xRoot
= null;
120 AccessibilityTools at
= new AccessibilityTools();
123 xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
126 xRoot
= at
.getAccessibleObject(xWindow
);
127 at
.printAccessibleTree(log
, xRoot
, tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
128 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
129 log
.println("Couldn't get Window");
132 XAccessibleContext oPopMenu
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.POPUP_MENU
,true);
134 log
.println("ImplementationName: " + util
.utils
.getImplName(oPopMenu
));
136 XAccessible xHelp
= null;
138 log
.println("Try to get second entry of context menu...");
139 xHelp
= oPopMenu
.getAccessibleChild(1);
141 } catch (IndexOutOfBoundsException e
){
142 throw new StatusException("Not possible to get second entry of context menu",e
);
145 if (xHelp
== null) throw new StatusException(new Status("second entry of context menu is NULL", false));
147 XAccessibleContext xHelpCont
= xHelp
.getAccessibleContext();
149 if ( xHelpCont
== null )
150 throw new StatusException(new Status("No able to retrieve accessible context from first entry of context menu",false));
152 String aAccessibleName
= xHelpCont
.getAccessibleName();
153 if ( !aAccessibleName
.equals( "Help" )) {
154 log
.println("Accessible name found = "+aAccessibleName
);
155 log
.println("Second entry of context menu is not from context menu interceptor");
163 private void openContextMenu(XModel xModel
){
165 log
.println("try to open contex menu...");
166 AccessibilityTools at
= new AccessibilityTools();
168 xWindow
= at
.getCurrentWindow(xMSF
, xModel
);
170 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
172 XInterface oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
);
174 XAccessibleComponent window
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
175 XAccessibleComponent
.class, oObj
);
177 point
= window
.getLocationOnScreen();
178 Rectangle rect
= window
.getBounds();
180 log
.println("klick mouse button...");
182 Robot rob
= new Robot();
183 int x
= point
.X
+ (rect
.Width
/ 2);
184 int y
= point
.Y
+ (rect
.Height
/ 2);
186 System
.out
.println("Press Button");
187 rob
.mousePress(InputEvent
.BUTTON3_MASK
);
188 System
.out
.println("Release Button");
189 rob
.mouseRelease(InputEvent
.BUTTON3_MASK
);
190 System
.out
.println("done");
191 } catch (java
.awt
.AWTException e
) {
192 log
.println("couldn't press mouse button");
195 utils
.shortWait(1000);
199 private void releasePopUp() {
200 log
.println("release the popup menu");
202 Robot rob
= new Robot();
206 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
207 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
208 } catch (java
.awt
.AWTException e
) {
209 log
.println("couldn't press mouse button");