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.XAccessible;
26 import com.sun.star.accessibility.XAccessibleContext;
27 import com.sun.star.accessibility.XAccessibleEventListener;
28 
29 
30 class MenuItem extends ToggleButton {
MenuItem(XAccessible xAccessible, XAccessibleContext xAccessibleContext)31     public MenuItem(XAccessible xAccessible, XAccessibleContext xAccessibleContext) {
32         super(xAccessible, xAccessibleContext);
33     }
34 
35     protected class AccessibleMenuItemListener extends AccessibleUNOComponentListener {
36 
AccessibleMenuItemListener()37         protected AccessibleMenuItemListener() {
38         }
39 
setComponentState(short state, boolean enable)40         protected void setComponentState(short state, boolean enable) {
41 
42             // #i56538# menu items in Java 1.5 are ARMED, not SELECTED
43             if( state == com.sun.star.accessibility.AccessibleStateType.SELECTED )
44                 fireStatePropertyChange(javax.accessibility.AccessibleState.ARMED, enable);
45             else
46                 super.setComponentState(state, enable);
47         }
48     };
49 
createEventListener()50     protected XAccessibleEventListener createEventListener() {
51         return new AccessibleMenuItemListener();
52     }
53 
54     /** Creates the AccessibleContext associated with this object */
createAccessibleContext()55     public javax.accessibility.AccessibleContext createAccessibleContext() {
56         return new AccessibleMenuItem();
57     }
58 
59     protected class AccessibleMenuItem extends AccessibleToggleButton {
60         /** Gets the role of this object */
getAccessibleRole()61         public javax.accessibility.AccessibleRole getAccessibleRole() {
62             return javax.accessibility.AccessibleRole.MENU_ITEM;
63         }
64 
65         /** Gets the 0-based index of this object in its accessible parent */
getAccessibleIndexInParent()66         public int getAccessibleIndexInParent() {
67             if (getAccessibleParent() instanceof Menu) {
68                 return ((Menu) getAccessibleParent()).indexOf(MenuItem.this);
69             } else {
70                 return super.getAccessibleIndexInParent();
71             }
72         }
73 
74         /**
75         * Gets the current state set of this object.
76         *
77         * @return an instance of <code>AccessibleStateSet</code>
78         *    containing the current state set of the object
79         * @see javax.accessibility.AccessibleState
80         */
getAccessibleStateSet()81         public javax.accessibility.AccessibleStateSet getAccessibleStateSet() {
82             javax.accessibility.AccessibleStateSet stateSet = super.getAccessibleStateSet();
83 
84             // #i56538# menu items in Java do not have SELECTABLE ..
85             stateSet.remove(javax.accessibility.AccessibleState.SELECTABLE);
86 
87             // .. and also ARMED insted of SELECTED
88             if( stateSet.remove(javax.accessibility.AccessibleState.SELECTED) )
89                 stateSet.add(javax.accessibility.AccessibleState.ARMED);
90 
91             return stateSet;
92         }
93 
94     }
95 }
96