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 package org.openoffice.java.accessibility; 24 25 import com.sun.star.accessibility.*; 26 import com.sun.star.uno.AnyConverter; 27 import com.sun.star.uno.UnoRuntime; 28 29 import javax.accessibility.AccessibleState; 30 31 32 public abstract class DescendantManager extends Component { 33 protected XAccessibleSelection unoAccessibleSelection = null; 34 protected javax.accessibility.Accessible activeDescendant = null; 35 protected boolean multiselectable = false; 36 DescendantManager(XAccessible xAccessible, XAccessibleContext xAccessibleContext)37 protected DescendantManager(XAccessible xAccessible, 38 XAccessibleContext xAccessibleContext) { 39 super(xAccessible, xAccessibleContext); 40 } 41 DescendantManager(XAccessible xAccessible, XAccessibleContext xAccessibleContext, boolean multiselectable)42 protected DescendantManager(XAccessible xAccessible, 43 XAccessibleContext xAccessibleContext, boolean multiselectable) { 44 super(xAccessible, xAccessibleContext); 45 this.multiselectable = multiselectable; 46 } 47 48 /** 49 * Update the proxy objects appropriatly on property change events 50 */ 51 protected class AccessibleDescendantManagerListener 52 extends AccessibleUNOComponentListener { AccessibleDescendantManagerListener()53 protected AccessibleDescendantManagerListener() { 54 unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, 55 unoAccessibleContext); 56 } 57 58 /** Called by OpenOffice process to notify property changes */ notifyEvent(AccessibleEventObject event)59 public void notifyEvent(AccessibleEventObject event) { 60 switch (event.EventId) { 61 case AccessibleEventId.SELECTION_CHANGED: 62 firePropertyChange(javax.accessibility.AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, 63 null, null); 64 65 break; 66 67 default: 68 super.notifyEvent(event); 69 } 70 } 71 } 72 73 protected abstract class AccessibleDescendantManager 74 extends AccessibleUNOComponent 75 implements javax.accessibility.AccessibleSelection { AccessibleDescendantManager()76 protected AccessibleDescendantManager() { 77 unoAccessibleSelection = (XAccessibleSelection) UnoRuntime.queryInterface(XAccessibleSelection.class, 78 unoAccessibleContext); 79 } 80 81 /* 82 * AccessibleContext 83 */ 84 85 /** Returns the number of accessible children of the object */ getAccessibleChildrenCount()86 public int getAccessibleChildrenCount() { 87 try { 88 return unoAccessibleContext.getAccessibleChildCount(); 89 } catch (com.sun.star.uno.RuntimeException e) { 90 return 0; 91 } 92 } 93 94 /** Returns the AccessibleSelection interface for this object */ getAccessibleSelection()95 public javax.accessibility.AccessibleSelection getAccessibleSelection() { 96 return (unoAccessibleSelection != null) ? this : null; 97 } 98 99 /* 100 * AccessibleSelection 101 */ 102 103 /** Adds the specified Accessible child of the object to the object's selection */ addAccessibleSelection(int i)104 public void addAccessibleSelection(int i) { 105 try { 106 unoAccessibleSelection.selectAccessibleChild(i); 107 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 108 } catch (com.sun.star.uno.RuntimeException e) { 109 } 110 } 111 112 /** Clears the selection in the object, so that no children in the object are selected */ clearAccessibleSelection()113 public void clearAccessibleSelection() { 114 try { 115 unoAccessibleSelection.clearAccessibleSelection(); 116 } catch (com.sun.star.uno.RuntimeException e) { 117 } 118 } 119 120 /** Returns the number of Accessible children currently selected */ getAccessibleSelectionCount()121 public int getAccessibleSelectionCount() { 122 try { 123 return unoAccessibleSelection.getSelectedAccessibleChildCount(); 124 } catch (com.sun.star.uno.RuntimeException e) { 125 return 0; 126 } 127 } 128 129 /** Determines if the current child of this object is selected */ isAccessibleChildSelected(int i)130 public boolean isAccessibleChildSelected(int i) { 131 try { 132 return unoAccessibleSelection.isAccessibleChildSelected(i); 133 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 134 return false; 135 } catch (com.sun.star.uno.RuntimeException e) { 136 return false; 137 } 138 } 139 140 /** Removes the specified child of the object from the object's selection */ removeAccessibleSelection(int i)141 public void removeAccessibleSelection(int i) { 142 try { 143 unoAccessibleSelection.deselectAccessibleChild(i); 144 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 145 } catch (com.sun.star.uno.RuntimeException e) { 146 } 147 } 148 149 /** Causes every child of the object to be selected if the object supports multiple selection */ selectAllAccessibleSelection()150 public void selectAllAccessibleSelection() { 151 try { 152 unoAccessibleSelection.selectAllAccessibleChildren(); 153 } catch (com.sun.star.uno.RuntimeException e) { 154 } 155 } 156 } 157 } 158