1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.java.accessibility; 25 26 import javax.accessibility.AccessibleContext; 27 28 import com.sun.star.uno.*; 29 import com.sun.star.accessibility.*; 30 31 /** 32 * Specialized container for MenuBar and Popup-Menu(s) 33 * FIXME: join with Menu ? 34 */ 35 public class MenuContainer extends Container implements javax.accessibility.Accessible { 36 37 protected XAccessibleSelection unoAccessibleSelection = null; 38 MenuContainer(javax.accessibility.AccessibleRole role, XAccessible xAccessible, XAccessibleContext xAccessibleContext)39 protected MenuContainer(javax.accessibility.AccessibleRole role, XAccessible xAccessible, XAccessibleContext xAccessibleContext) { 40 super(role, xAccessible, xAccessibleContext); 41 } 42 43 protected class AccessibleMenuContainerListener extends AccessibleContainerListener { 44 AccessibleMenuContainerListener()45 protected AccessibleMenuContainerListener() { 46 super(); 47 } 48 49 /** Called by OpenOffice process to notify property changes */ notifyEvent(AccessibleEventObject event)50 public void notifyEvent(AccessibleEventObject event) { 51 switch (event.EventId) { 52 53 // #i56539# Java 1.5 does not fire ACCESSIBLE_SELECTION_PROPERTY for menus 54 case AccessibleEventId.SELECTION_CHANGED: 55 break; 56 57 default: 58 super.notifyEvent(event); 59 } 60 } 61 } 62 createEventListener()63 protected XAccessibleEventListener createEventListener() { 64 return new AccessibleMenuContainerListener(); 65 } 66 67 /** Creates the AccessibleContext associated with this object */ createAccessibleContext()68 public javax.accessibility.AccessibleContext createAccessibleContext() { 69 return new AccessibleMenuContainer(); 70 } 71 72 protected class AccessibleMenuContainer extends AccessibleContainer implements javax.accessibility.AccessibleSelection { 73 AccessibleMenuContainer()74 protected AccessibleMenuContainer() { 75 unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, 76 unoAccessibleContext); 77 } 78 79 /** Returns the AccessibleSelection interface for this object */ getAccessibleSelection()80 public javax.accessibility.AccessibleSelection getAccessibleSelection() { 81 return this; 82 } 83 84 /* 85 * AccessibleSelection 86 */ 87 88 /** Returns an Accessible representing the specified selected child of the object */ getAccessibleSelection(int i)89 public javax.accessibility.Accessible getAccessibleSelection(int i) { 90 try { 91 return (javax.accessibility.Accessible) AccessibleObjectFactory.getAccessibleComponent( 92 unoAccessibleSelection.getSelectedAccessibleChild(i)); 93 } catch (com.sun.star.uno.Exception e) { 94 return null; 95 } 96 } 97 98 /** Adds the specified Accessible child of the object to the object's selection */ addAccessibleSelection(int i)99 public void addAccessibleSelection(int i) { 100 try { 101 javax.accessibility.Accessible a = getAccessibleChild(i); 102 103 // selecting menu items invokes the click action in Java 1.5 104 if( a instanceof MenuItem ) 105 a.getAccessibleContext().getAccessibleAction().doAccessibleAction(0); 106 else 107 unoAccessibleSelection.selectAccessibleChild(i); 108 } catch (java.lang.Exception e) { 109 /* 110 * Possible exceptions are: 111 * java.lang.NullPointerException 112 * com.sun.star.uno.RuntimeException 113 * com.sun.star.lang.IndexOutOfBoundsException 114 */ 115 } 116 } 117 118 /** Clears the selection in the object, so that no children in the object are selected */ clearAccessibleSelection()119 public void clearAccessibleSelection() { 120 try { 121 unoAccessibleSelection.clearAccessibleSelection(); 122 } catch (com.sun.star.uno.RuntimeException e) { 123 } 124 } 125 126 /** Returns the number of Accessible children currently selected */ getAccessibleSelectionCount()127 public int getAccessibleSelectionCount() { 128 try { 129 return unoAccessibleSelection.getSelectedAccessibleChildCount(); 130 } catch (com.sun.star.uno.RuntimeException e) { 131 return 0; 132 } 133 } 134 135 /** Determines if the current child of this object is selected */ isAccessibleChildSelected(int i)136 public boolean isAccessibleChildSelected(int i) { 137 try { 138 return unoAccessibleSelection.isAccessibleChildSelected(i); 139 } catch (java.lang.Exception e) { 140 /* 141 * Possible exceptions are: 142 * java.lang.NullPointerException 143 * com.sun.star.uno.RuntimeException 144 * com.sun.star.lang.IndexOutOfBoundsException 145 */ 146 return false; 147 } 148 } 149 150 /** Removes the specified child of the object from the object's selection */ removeAccessibleSelection(int i)151 public void removeAccessibleSelection(int i) { 152 if (isAccessibleChildSelected(i)) { 153 clearAccessibleSelection(); 154 } 155 } 156 157 /** Causes every child of the object to be selected if the object supports multiple selection */ selectAllAccessibleSelection()158 public void selectAllAccessibleSelection() { 159 // not supported 160 } 161 } 162 } 163 164