if (items[i] == item) return i;
}
return -1;
}
void initAccessible() {
final Accessible accessible = getAccessible();
accessible.addAccessibleListener(new AccessibleAdapter() {
public void getName(AccessibleEvent e) {
String name = null;
int childID = e.childID;
if (childID >= 0 && childID < items.length) {
name = items[childID].getText();
int index = name.indexOf('&');
if (index > 0) {
name = name.substring(0, index) + name.substring(index + 1);
}
}
e.result = name;
}
public void getHelp(AccessibleEvent e) {
String help = null;
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
help = getToolTipText();
} else if (childID >= 0 && childID < items.length) {
help = items[childID].getToolTipText();
}
e.result = help;
}
public void getKeyboardShortcut(AccessibleEvent e) {
String shortcut = null;
int childID = e.childID;
if (childID >= 0 && childID < items.length) {
String text = items[childID].getText();
if (text != null) {
char mnemonic = _findMnemonic(text);
if (mnemonic != '\0') {
shortcut = "Alt+"+mnemonic; //$NON-NLS-1$
}
}
}
e.result = shortcut;
}
});
accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
public void getChildAtPoint(AccessibleControlEvent e) {
Point testPoint = toControl(e.x, e.y);
int childID = ACC.CHILDID_NONE;
for (int i = 0; i < items.length; i++) {
if (items[i].getBounds().contains(testPoint)) {
childID = i;
break;
}
}
if (childID == ACC.CHILDID_NONE) {
Rectangle location = getBounds();
location.height = location.height - getClientArea().height;
if (location.contains(testPoint)) {
childID = ACC.CHILDID_SELF;
}
}
e.childID = childID;
}
public void getLocation(AccessibleControlEvent e) {
Rectangle location = null;
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
location = getBounds();
}
if (childID >= 0 && childID < items.length) {
location = items[childID].getBounds();
}
if (location != null) {
Point pt = toDisplay(location.x, location.y);
e.x = pt.x;
e.y = pt.y;
e.width = location.width;
e.height = location.height;
}
}
public void getChildCount(AccessibleControlEvent e) {
e.detail = items.length;
}
public void getDefaultAction(AccessibleControlEvent e) {
String action = null;
int childID = e.childID;
if (childID >= 0 && childID < items.length) {
action = SWT.getMessage ("SWT_Switch"); //$NON-NLS-1$
}
e.result = action;
}
public void getFocus(AccessibleControlEvent e) {
int childID = ACC.CHILDID_NONE;
if (isFocusControl()) {
if (selectedIndex == -1) {
childID = ACC.CHILDID_SELF;
} else {
childID = selectedIndex;
}
}
e.childID = childID;
}
public void getRole(AccessibleControlEvent e) {
int role = 0;
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
role = ACC.ROLE_TABFOLDER;
} else if (childID >= 0 && childID < items.length) {
role = ACC.ROLE_TABITEM;
}
e.detail = role;
}
public void getSelection(AccessibleControlEvent e) {
e.childID = (selectedIndex == -1) ? ACC.CHILDID_NONE : selectedIndex;
}
public void getState(AccessibleControlEvent e) {
int state = 0;
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
state = ACC.STATE_NORMAL;
} else if (childID >= 0 && childID < items.length) {
state = ACC.STATE_SELECTABLE;
if (isFocusControl()) {
state |= ACC.STATE_FOCUSABLE;
}
if (selectedIndex == childID) {
state |= ACC.STATE_SELECTED;
if (isFocusControl()) {
state |= ACC.STATE_FOCUSED;
}
}
}
e.detail = state;
}
public void getChildren(AccessibleControlEvent e) {
Object[] children = new Object[items.length];
for (int i = 0; i < items.length; i++) {
children[i] = new Integer(i);
}
e.children = children;
}
});
addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (isFocusControl()) {
if (selectedIndex == -1) {
accessible.setFocus(ACC.CHILDID_SELF);
} else {
accessible.setFocus(selectedIndex);
}
}
}
});
addListener(SWT.FocusIn, new Listener() {
public void handleEvent(Event event) {
if (selectedIndex == -1) {
accessible.setFocus(ACC.CHILDID_SELF);
} else {
accessible.setFocus(selectedIndex);
}
}
});
}