Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeronika Irvine2004-08-17 16:40:25 +0000
committerVeronika Irvine2004-08-17 16:40:25 +0000
commitfda8b1f012bcf4162f6a4fb84418c5d8827941c1 (patch)
tree22d3c5d6f07f96d0e7c3bae23388b69e29709858
parenta43be214df29139f4e45357ce03bff9c555cdf99 (diff)
downloadeclipse.platform.swt-fda8b1f012bcf4162f6a4fb84418c5d8827941c1.tar.gz
eclipse.platform.swt-fda8b1f012bcf4162f6a4fb84418c5d8827941c1.tar.xz
eclipse.platform.swt-fda8b1f012bcf4162f6a4fb84418c5d8827941c1.zip
bug 69440
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java92
1 files changed, 90 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
index d2af2c49d4..1210731a76 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
@@ -383,6 +383,21 @@ void dropDown (boolean drop) {
popup.setVisible (true);
list.setFocus();
}
+/*
+ * Return the Label immediately preceding the receiver in the z-order,
+ * or null if none.
+ */
+Label getAssociatedLabel () {
+ Control[] siblings = getParent().getChildren();
+ for (int i = 0; i < siblings.length; i++) {
+ if (siblings[i] == CCombo.this) {
+ if (i > 0 && siblings[i-1] instanceof Label) {
+ return (Label) siblings[i-1];
+ }
+ }
+ }
+ return null;
+}
public Control [] getChildren () {
checkWidget();
return new Control [0];
@@ -484,6 +499,17 @@ public String [] getItems () {
checkWidget();
return list.getItems ();
}
+char getMnemonic (String string) {
+ int index = 0;
+ int length = string.length ();
+ do {
+ while ((index < length) && (string.charAt (index) != '&')) index++;
+ if (++index >= length) return '\0';
+ if (string.charAt (index) != '&') return string.charAt (index);
+ index++;
+ } while (index < length);
+ return '\0';
+}
/**
* Gets the selection.
* <p>
@@ -668,12 +694,49 @@ public int indexOf (String string, int start) {
}
void initAccessible() {
- getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ AccessibleAdapter accessibleAdapter = new AccessibleAdapter() {
+ public void getName(AccessibleEvent e) {
+ String name = null;
+ Label label = getAssociatedLabel ();
+ if (label != null) {
+ name = stripMnemonic(label.getText());
+ }
+ e.result = name;
+ }
+ public void getKeyboardShortcut(AccessibleEvent e) {
+ String shortcut = null;
+ Label label = getAssociatedLabel ();
+ if (label != null) {
+ String text = label.getText();
+ if (text != null) {
+ char mnemonic = getMnemonic(text);
+ if (mnemonic != '\0') {
+ shortcut = "Alt+"+mnemonic; //$NON-NLS-1$
+ }
+ }
+ }
+ e.result = shortcut;
+ }
public void getHelp(AccessibleEvent e) {
e.result = getToolTipText();
}
- });
+ };
+ getAccessible().addAccessibleListener(accessibleAdapter);
+ text.getAccessible().addAccessibleListener(accessibleAdapter);
+ list.getAccessible().addAccessibleListener(accessibleAdapter);
+ arrow.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ public void getName(AccessibleEvent e) {
+ e.result = isDropped () ? "Close" : "Open"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ public void getKeyboardShortcut(AccessibleEvent e) {
+ e.result = "Alt+Down Arrow"; //$NON-NLS-1$
+ }
+ public void getHelp(AccessibleEvent e) {
+ e.result = getToolTipText();
+ }
+ });
+
getAccessible().addAccessibleTextListener(new AccessibleTextAdapter() {
public void getCaretOffset(AccessibleTextEvent e) {
e.offset = text.getCaretPosition();
@@ -713,6 +776,18 @@ void initAccessible() {
e.result = getText();
}
});
+
+ text.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
+ public void getRole(AccessibleControlEvent e) {
+ e.detail = text.getEditable() ? ACC.ROLE_TEXT : ACC.ROLE_LABEL;
+ }
+ });
+
+ arrow.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
+ public void getDefaultAction(AccessibleControlEvent e) {
+ e.result = isDropped () ? "Close" : "Open"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
}
boolean isDropped () {
return popup.getVisible ();
@@ -1186,6 +1261,19 @@ public void setVisibleItemCount (int count) {
if (count < 0) return;
visibleItemCount = count;
}
+String stripMnemonic (String string) {
+ int index = 0;
+ int length = string.length ();
+ do {
+ while ((index < length) && (string.charAt (index) != '&')) index++;
+ if (++index >= length) return string;
+ if (string.charAt (index) != '&') {
+ return string.substring(0, index-1) + string.substring(index, length);
+ }
+ index++;
+ } while (index < length);
+ return string;
+}
void textEvent (Event event) {
switch (event.type) {
case SWT.FocusIn: {

Back to the top