diff options
author | Felipe Heidrich <fheidric> | 2009-10-02 15:35:10 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2009-10-02 15:35:10 +0000 |
commit | 90a3777b7aba5ac2320594cf8fe9b9694d9b3be8 (patch) | |
tree | 7733d13ea7efee8296ec3505d6223be331eaf6ef | |
parent | cc545d4fcf615c0c01844633d101e3a47d10af75 (diff) | |
download | eclipse.platform.swt-90a3777b7aba5ac2320594cf8fe9b9694d9b3be8.tar.gz eclipse.platform.swt-90a3777b7aba5ac2320594cf8fe9b9694d9b3be8.tar.xz eclipse.platform.swt-90a3777b7aba5ac2320594cf8fe9b9694d9b3be8.zip |
Bug 143911 - differentiate left and right modifier keys in keyPressed event [new API]
5 files changed, 79 insertions, 71 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index be71c17daf..e38fd9669a 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -1697,6 +1697,10 @@ public class SWT { * This is a synonym for LEAD (value is 1<<14). Newer * applications should use LEAD instead of LEFT to make code more * understandable on right-to-left platforms. + * <p> + * This constant can also be used to representing the left keyboard + * location during a key event. + * </p> */ public static final int LEFT = LEAD; @@ -1719,6 +1723,10 @@ public class SWT { * This is a synonym for TRAIL (value is 1<<17). Newer * applications should use TRAIL instead of RIGHT to make code more * understandable on right-to-left platforms. + * <p> + * This constant can also be used to representing the right keyboard + * location during a key event. + * </p> */ public static final int RIGHT = TRAIL; @@ -2052,45 +2060,6 @@ public class SWT { public static final int BUTTON_MASK; /** - * Keyboard event mask indicating the key event was generated by a key - * on the right side of the keyboard. (value is 1<<1). - * - * @since 3.6 - */ - public static final int LOCATION_RIGHT = 1 << 1; - - /** - * Keyboard event mask indicating the key event was generated by a key - * on the left side of the keyboard. (value is 1<<2). - * - * @since 3.6 - */ - public static final int LOCATION_LEFT = 1 << 2; - - /** - * Keyboard event mask indicating the key event was generated by a key - * on the keypad. (value is 1<<3). - * - * @since 3.6 - */ - public static final int LOCATION_KEYPAD = 1 << 3; - - /** - * Keyboard event mask indicating all possible key locations. - * - * To allow for the future, this mask is intended to be used - * in place of code that references each individual location mask. - * For example, the following expression will determine whether - * the key location is set and will continue to work as new location - * masks are added. - * - * <code>(stateMask & SWT.LOCATION_MASK) != 0</code>. - * - * @since 3.6 - */ - public static final int LOCATION_MASK; - - /** * Keyboard and/or mouse event mask indicating that the MOD1 key * was pushed on the keyboard when the event was generated. * @@ -2373,7 +2342,15 @@ public class SWT { * @since 3.6 */ public static final int F20 = KEYCODE_BIT + 29; - + + /** + * Keyboard event constant representing the keypad location. + * (value is 1<<1). + * + * @since 3.6 + */ + public static final int KEYPAD = 1 << 1; + /** * Keyboard event constant representing the numeric key * pad multiply key (value is (1<<24)+42). @@ -4038,7 +4015,6 @@ static { */ BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3 | BUTTON4 | BUTTON5; MODIFIER_MASK = ALT | SHIFT | CTRL | COMMAND; - LOCATION_MASK = LOCATION_LEFT | LOCATION_RIGHT | LOCATION_KEYPAD; /* * These values can be different on different platforms. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java index 417d357152..82ea3deedf 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java @@ -59,18 +59,33 @@ public class KeyEvent extends TypedEvent { public int keyCode; /** + * depending on the event, the location of key specified by the + * keyCode or character. The possible values for this field are + * <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, <code>SWT.KEYPAD</code>, + * or <code>SWT.NONE</code> representing the main keyboard area. + * <p> + * The location field can be used to differentiate key events that have + * the same key code and character but are generated by different keys + * in the keyboard. For example, a key down event with the key code equals + * to SWT.SHIFT can be generated by the left and the right shift keys in the + * keyboard. The location field can only be used to determine the location + * of the key code or character in the current event. It does not + * include information about the location of modifiers in state + * mask. + * </p> + * + * @see org.eclipse.swt.SWT#LEFT + * @see org.eclipse.swt.SWT#RIGHT + * @see org.eclipse.swt.SWT#KEYPAD + * + * @since 3.6 + */ + public int keyLocation; + + /** * the state of the keyboard modifier keys at the time * the event was generated, as defined by the key code * constants in class <code>SWT</code>. - * The stateMask can also contain a location mask. - * The location mask is set when the same key event can be - * generated by different keys in the keyboard. For example, - * a key down event with the key code equals to SWT.SHIFT can - * be generated by left and right shift keys in the keyboard. - * The location mask can only be used to determine the location - * of the key code or character in the current event. It does not - * include the location for modifier keys set in the modifiers - * mask. * * @see org.eclipse.swt.SWT */ @@ -94,6 +109,7 @@ public KeyEvent(Event e) { super(e); this.character = e.character; this.keyCode = e.keyCode; + this.keyLocation = e.keyLocation; this.stateMask = e.stateMask; this.doit = e.doit; } @@ -109,6 +125,7 @@ public String toString() { return string.substring (0, string.length() - 1) // remove trailing '}' + " character='" + ((character == 0) ? "\\0" : "" + character) + "'" + " keyCode=" + keyCode + + " keyLocation=" + keyLocation + " stateMask=" + stateMask + " doit=" + doit + "}"; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java index 5bb89c6e7f..36f29691e1 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java @@ -157,17 +157,32 @@ public class Event { public int keyCode; /** + * depending on the event, the location of key specified by the + * keyCode or character. The possible values for this field are + * <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, <code>SWT.KEYPAD</code>, + * or <code>SWT.NONE</code> representing the main keyboard area. + * <p> + * The location field can be used to differentiate key events that have + * the same key code and character but are generated by different keys + * in the keyboard. For example, a key down event with the key code equals + * to SWT.SHIFT can be generated by the left and the right shift keys in the + * keyboard. The location field can only be used to determine the location + * of the key code or character in the current event. It does not + * include information about the location of modifiers in state + * mask. + * </p> + * + * @see org.eclipse.swt.SWT#LEFT + * @see org.eclipse.swt.SWT#RIGHT + * @see org.eclipse.swt.SWT#KEYPAD + * + * @since 3.6 + */ + public int keyLocation; + + /** * depending on the event, the state of the keyboard modifier * keys and mouse masks at the time the event was generated. - * The stateMask can also contain a location mask. - * The location mask is set when the same key event can be - * generated by different keys in the keyboard. For example, - * a key down event with the key code equals to SWT.SHIFT can - * be generated by left and right shift keys in the keyboard. - * The location mask can only be used to determine the location - * of the key code or character in the current event. It does not - * include the location for modifier keys set in the modifiers - * mask. * * @see org.eclipse.swt.SWT */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java index ec7f830a8a..0381947832 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java @@ -1319,15 +1319,15 @@ int setLocationMask (Event event, int type, int /*long*/ wParam, int /*long*/ lP if (display.lastVirtual) { switch (display.lastKey) { case OS.VK_SHIFT: - if (OS.GetKeyState(OS.VK_LSHIFT) < 0) location = SWT.LOCATION_LEFT; - if (OS.GetKeyState(OS.VK_RSHIFT) < 0) location = SWT.LOCATION_RIGHT; + if (OS.GetKeyState(OS.VK_LSHIFT) < 0) location = SWT.LEFT; + if (OS.GetKeyState(OS.VK_RSHIFT) < 0) location = SWT.RIGHT; break; case OS.VK_NUMLOCK: - location = SWT.LOCATION_KEYPAD; + location = SWT.KEYPAD; break; case OS.VK_CONTROL: case OS.VK_MENU: - location = (lParam & 0x1000000) == 0 ? SWT.LOCATION_LEFT : SWT.LOCATION_RIGHT; + location = (lParam & 0x1000000) == 0 ? SWT.LEFT : SWT.RIGHT; break; case OS.VK_INSERT: case OS.VK_DELETE: @@ -1340,19 +1340,19 @@ int setLocationMask (Event event, int type, int /*long*/ wParam, int /*long*/ lP case OS.VK_LEFT: case OS.VK_RIGHT: if ((lParam & 0x1000000) == 0) { - location = SWT.LOCATION_KEYPAD; + location = SWT.KEYPAD; } break; } if (display.numpadKey(display.lastKey) != 0) { - location = SWT.LOCATION_KEYPAD; + location = SWT.KEYPAD; } } else { if (display.lastKey == SWT.KEYPAD_CR) { - location = SWT.LOCATION_KEYPAD; + location = SWT.KEYPAD; } } - event.stateMask |= location; + event.keyLocation = location; return location; } diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java index 7dd9045bd8..0bbda273bb 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java @@ -130,11 +130,11 @@ public static void main (String [] args) { string += " stateMask=0x" + Integer.toHexString (e.stateMask) + stateMask (e.stateMask) + ","; string += " keyCode=0x" + Integer.toHexString (e.keyCode) + " " + keyCode (e.keyCode) + ","; string += " character=0x" + Integer.toHexString (e.character) + " " + character (e.character); - if ((e.stateMask & SWT.LOCATION_MASK) != 0) { + if (e.keyLocation != 0) { string += " location="; - if ((e.stateMask & SWT.LOCATION_LEFT) != 0) string += "LEFT"; - if ((e.stateMask & SWT.LOCATION_RIGHT) != 0) string += "RIGHT"; - if ((e.stateMask & SWT.LOCATION_KEYPAD) != 0) string += "KEYPAD"; + if (e.keyLocation == SWT.LEFT) string += "LEFT"; + if (e.keyLocation == SWT.RIGHT) string += "RIGHT"; + if (e.keyLocation == SWT.KEYPAD) string += "KEYPAD"; } System.out.println (string); } |