This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: KeyEvent generation
- From: Thomas Fitzsimmons <fitzsim at redhat dot com>
- To: "java-patches at gcc dot gnu dot org" <java-patches at gcc dot gnu dot org>
- Date: 01 Aug 2003 22:28:35 -0400
- Subject: Patch: KeyEvent generation
Hello,
This patch improves gtk peer KeyEvent generation, and KeyEvent's
paramString method. With this patch, libgcj generates key event output
that matches the output generated by Sun's JVM. It was tested on a US
keyboard.
Please review and comment.
Thanks,
Tom
2003-08-01 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkComponentPeer.java (postKeyEvent):
Add keyLocation parameter.
* java/awt/event/KeyEvent.java (getKeyText): Fix "NumPad-"
string.
(paramString): Generate keyChar string according to keyChar, not
keyCode.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
(state_to_awt_mods): Handle ALT key.
(keyevent_state_to_awt_mods): New function.
(get_first_keyval_from_keymap): New function.
(keysym_to_awt_keycode): Get virtual key code from keymap.
Handle missing VK_ values.
(keysym_to_awt_keylocation): New function.
(keyevent_to_awt_keychar): New function.
(generates_key_typed_event): Handle non-text-component case.
Handle GDK_KP_Delete and GDK_KP_Enter.
(awt_event_handler): Call new functions to get postKeyEvent
parameters.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c (gtkInit):
Update postKeyEvent method signature.
* jni/gtk-peer/gtkpeer.h: Add KEY_LOCATION defines. Add missing
VK_ defines.
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 9 Jul 2003 07:50:00 -0000 1.4
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 2 Aug 2003 02:14:31 -0000
@@ -351,10 +351,10 @@
}
protected void postKeyEvent (int id, long when, int mods,
- int keyCode, char keyChar)
+ int keyCode, char keyChar, int keyLocation)
{
q.postEvent (new KeyEvent (awtComponent, id, when, mods,
- keyCode, keyChar));
+ keyCode, keyChar, keyLocation));
}
protected void postFocusEvent (int id, boolean temporary)
Index: gnu/java/awt/peer/gtk/GtkTextComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java,v
retrieving revision 1.5
diff -u -b -B -r1.5 GtkTextComponentPeer.java
Index: java/awt/event/KeyEvent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/event/KeyEvent.java,v
retrieving revision 1.10
diff -u -b -B -r1.10 KeyEvent.java
--- java/awt/event/KeyEvent.java 2 Mar 2003 19:24:49 -0000 1.10
+++ java/awt/event/KeyEvent.java 2 Aug 2003 02:14:31 -0000
@@ -1503,7 +1503,7 @@
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
- return "NumPad-" + (char) (keyCode - VK_NUMPAD0);
+ return "NumPad-" + (keyCode - VK_NUMPAD0);
case VK_F1:
case VK_F2:
case VK_F3:
@@ -1642,11 +1642,10 @@
}
/**
- * Returns a string identifying the event. This is formatted as the field
- * name of the id type, followed by the keyCode, then the keyChar (if
- * available), modifiers (if any), extModifiers (if any), and keyLocation.
- * The keyChar is available unless the keyCode is Backspace, Tab, Enter,
- * Escape, Numpad-[0-9], Delete, or a keyCode which is an action.
+ * Returns a string identifying the event. This is formatted as the
+ * field name of the id type, followed by the keyCode, then the
+ * keyChar, modifiers (if any), extModifiers (if any), and
+ * keyLocation.
*
* @return a string identifying the event
*/
@@ -1656,44 +1656,44 @@
switch (id)
{
case KEY_PRESSED:
- s.append("KEY_PRESSED,keyCode=");
+ s.append("KEY_PRESSED");
break;
case KEY_RELEASED:
- s.append("KEY_RELEASED,keyCode=");
+ s.append("KEY_RELEASED");
break;
case KEY_TYPED:
- s.append("KEY_TYPED,keyCode=");
+ s.append("KEY_TYPED");
break;
default:
- s.append("unknown type,keyCode=");
- }
- s.append(keyCode);
- switch (keyCode)
- {
- default:
- if (! isActionKey())
- {
- s.append(",keyChar='").append(keyChar).append('\'');
- break;
+ s.append("unknown type");
}
- // Fallthrough.
- case VK_BACK_SPACE:
- case VK_TAB:
- case VK_ENTER:
- case VK_ESCAPE:
- case VK_NUMPAD0:
- case VK_NUMPAD1:
- case VK_NUMPAD2:
- case VK_NUMPAD3:
- case VK_NUMPAD4:
- case VK_NUMPAD5:
- case VK_NUMPAD6:
- case VK_NUMPAD7:
- case VK_NUMPAD8:
- case VK_NUMPAD9:
- case VK_DELETE:
- s.append(',').append(getKeyText(keyCode));
+
+ s.append(",keyCode=").append(keyCode);
+
+ s.append(",keyText=").append(getKeyText(keyCode));
+
+ s.append(",keyChar=");
+ if (isActionKey()
+ || keyCode == VK_SHIFT
+ || keyCode == VK_CONTROL
+ || keyCode == VK_ALT)
+ s.append("Undefined keyChar");
+ else
+ {
+ /* This output string must be selected by examining keyChar
+ * rather than keyCode, because key code information is not
+ * included in KEY_TYPED events.
+ */
+ if (keyChar == VK_BACK_SPACE
+ || keyChar == VK_TAB
+ || keyChar == VK_ENTER
+ || keyChar == VK_ESCAPE
+ || keyChar == VK_DELETE)
+ s.append(getKeyText(keyChar));
+ else
+ s.append("'").append(keyChar).append("'");
}
+
if ((modifiers & CONVERT_MASK) != 0)
s.append(",modifiers=").append(getModifiersExText(modifiers
& CONVERT_MASK));
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c,v
retrieving revision 1.3
diff -u -b -B -r1.3 gnu_java_awt_peer_gtk_GtkComponentPeer.c
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c,v
retrieving revision 1.4
diff -u -b -B -r1.4 gnu_java_awt_peer_gtk_GtkEvents.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c 23 Jul 2003 22:26:35 -0000 1.4
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c 2 Aug 2003 02:14:31 -0000
@@ -48,7 +48,8 @@
{
jobject *peer_obj;
int nwindows;
- GdkWindow ***windows; /* array of pointers to (GdkWindow *) */
+ /* array of pointers to (GdkWindow *) */
+ GdkWindow ***windows;
};
static jint
@@ -68,68 +69,317 @@
}
static jint
-state_to_awt_mods (int mods)
+state_to_awt_mods (guint state)
{
jint result = 0;
- if (mods & (GDK_SHIFT_MASK | GDK_LOCK_MASK))
+ if (state & GDK_SHIFT_MASK)
result |= AWT_SHIFT_MASK;
- if (mods & GDK_CONTROL_MASK)
+ if (state & GDK_CONTROL_MASK)
result |= AWT_CTRL_MASK;
+ if (state & GDK_MOD1_MASK)
+ result |= AWT_ALT_MASK;
return result;
}
+/* Modifier key events need special treatment. In Sun's peer
+ implementation, when a modifier key is pressed, the KEY_PRESSED
+ event has that modifier in its modifiers list. The corresponding
+ KEY_RELEASED event's modifier list does not contain the modifier.
+ For example, pressing and releasing the shift key will produce a
+ key press event with modifiers=Shift, and a key release event with
+ no modifiers. GDK's key events behave in the exact opposite way,
+ so this translation code is needed. */
+static jint
+keyevent_state_to_awt_mods (GdkEvent *event)
+{
+ jint result = 0;
+ guint state;
+
+ if (event->type == GDK_KEY_PRESS)
+ {
+ state = event->key.state;
+
+ if (event->key.keyval == GDK_Shift_L
+ || event->key.keyval == GDK_Shift_R)
+ result |= AWT_SHIFT_MASK;
+ else
+ {
+ if (state & GDK_SHIFT_MASK)
+ result |= AWT_SHIFT_MASK;
+ }
+
+ if (event->key.keyval == GDK_Control_L
+ || event->key.keyval == GDK_Control_R)
+ result |= AWT_CTRL_MASK;
+ else
+ {
+ if (state & GDK_CONTROL_MASK)
+ result |= AWT_CTRL_MASK;
+ }
+
+ if (event->key.keyval == GDK_Alt_L
+ || event->key.keyval == GDK_Alt_R)
+ result |= AWT_ALT_MASK;
+ else
+ {
+ if (state & GDK_MOD1_MASK)
+ result |= AWT_ALT_MASK;
+ }
+ }
+ else if (event->type == GDK_KEY_RELEASE)
+ {
+ state = event->key.state;
+
+ if (event->key.keyval != GDK_Shift_L
+ && event->key.keyval != GDK_Shift_R)
+ {
+ if (state & GDK_SHIFT_MASK)
+ result |= AWT_SHIFT_MASK;
+ }
+ if (event->key.keyval != GDK_Control_L
+ && event->key.keyval != GDK_Control_R)
+ {
+ if (state & GDK_CONTROL_MASK)
+ result |= AWT_CTRL_MASK;
+ }
+
+ if (event->key.keyval != GDK_Alt_L
+ && event->key.keyval != GDK_Alt_R)
+ {
+ if (state & GDK_MOD1_MASK)
+ result |= AWT_ALT_MASK;
+ }
+ }
+
+ return result;
+}
+
+/* Get the first keyval in the keymap for this event's keycode. The
+ first keyval corresponds roughly to Java's notion of a virtual
+ key. Returns the uppercase version of the first keyval. */
+static guint
+get_first_keyval_from_keymap (GdkEvent *event)
+{
+ guint keyval;
+ guint *keyvals;
+ gint n_entries;
+
+ if (!gdk_keymap_get_entries_for_keycode (NULL,
+ event->key.hardware_keycode,
+ NULL,
+ &keyvals,
+ &n_entries))
+ {
+ g_warning ("No keyval found for hardware keycode %d\n",
+ event->key.hardware_keycode);
+ /* Try to recover by using the keyval in the event structure. */
+ keyvals = &(event->key.keyval);
+ }
+ keyval = keyvals[0];
+ g_free (keyvals);
+
+ return gdk_keyval_to_upper (keyval);
+}
+
#ifdef __GNUC__
__inline
#endif
static jint
-keysym_to_awt_keycode (guint keyval)
+keysym_to_awt_keycode (GdkEvent *event)
{
- guint vk;
+ guint ukeyval;
+ guint state;
- vk = gdk_keyval_to_upper (keyval);
+ ukeyval = get_first_keyval_from_keymap (event);
+ state = event->key.state;
- if (vk >= 0x41 && vk <= 0x5A) /* VK_A through VK_Z */
- return vk;
+ /* VK_A through VK_Z */
+ if (ukeyval >= GDK_A && ukeyval <= GDK_Z)
+ return ukeyval;
- if (vk >= 0x30 && vk <= 0x39) /* VK_0 through VK_9 */
- return vk;
+ /* VK_0 through VK_9 */
+ if (ukeyval >= GDK_0 && ukeyval <= GDK_9)
+ return ukeyval;
- switch (vk)
+ switch (ukeyval)
{
- case GDK_Alt_L:
- case GDK_Alt_R:
- return VK_ALT;
+ case GDK_Return:
+ case GDK_KP_Enter:
+ return VK_ENTER;
case GDK_BackSpace:
return VK_BACK_SPACE;
+ case GDK_Tab:
+ return VK_TAB;
case GDK_Cancel:
return VK_CANCEL;
- case GDK_Caps_Lock:
- return VK_CAPS_LOCK;
case GDK_Clear:
return VK_CLEAR;
- case GDK_bracketright:
- return VK_CLOSE_BRACKET;
- case GDK_comma:
- return VK_COMMA;
+ case GDK_Shift_L:
+ case GDK_Shift_R:
+ return VK_SHIFT;
case GDK_Control_L:
case GDK_Control_R:
return VK_CONTROL;
+ case GDK_Alt_L:
+ case GDK_Alt_R:
+ return VK_ALT;
+ case GDK_Pause:
+ return VK_PAUSE;
+ case GDK_Caps_Lock:
+ return VK_CAPS_LOCK;
+ case GDK_Escape:
+ return VK_ESCAPE;
+ case GDK_space:
+ return VK_SPACE;
+ case GDK_KP_Page_Up:
+ /* For keys on the numeric keypad, the JVM produces one of two
+ virtual keys, depending on the num lock state. */
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD9;
+ else
+ return VK_PAGE_UP;
+ case GDK_Page_Up:
+ return VK_PAGE_UP;
+ case GDK_KP_Page_Down:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD3;
+ else
+ return VK_PAGE_DOWN;
+ case GDK_Page_Down:
+ return VK_PAGE_DOWN;
+ case GDK_KP_End:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD1;
+ else
+ return VK_END;
+ case GDK_End:
+ return VK_END;
+ case GDK_KP_Home:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD7;
+ else
+ return VK_HOME;
+ case GDK_Home:
+ return VK_HOME;
+ case GDK_KP_Begin:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD5;
+ else
+ return VK_UNDEFINED;
+ case GDK_Left:
+ return VK_LEFT;
+ case GDK_Up:
+ return VK_UP;
+ case GDK_Right:
+ return VK_RIGHT;
+ case GDK_Down:
+ return VK_DOWN;
+ case GDK_comma:
+ return VK_COMMA;
+ case GDK_minus:
+ return VK_MINUS;
+ case GDK_period:
+ return VK_PERIOD;
+ case GDK_slash:
+ return VK_SLASH;
+ /*
+ return VK_0;
+ return VK_1;
+ return VK_2;
+ return VK_3;
+ return VK_4;
+ return VK_5;
+ return VK_6;
+ return VK_7;
+ return VK_8;
+ return VK_9;
+ */
+ case GDK_semicolon:
+ return VK_SEMICOLON;
+ case GDK_equal:
+ return VK_EQUALS;
+ /*
+ return VK_A;
+ return VK_B;
+ return VK_C;
+ return VK_D;
+ return VK_E;
+ return VK_F;
+ return VK_G;
+ return VK_H;
+ return VK_I;
+ return VK_J;
+ return VK_K;
+ return VK_L;
+ return VK_M;
+ return VK_N;
+ return VK_O;
+ return VK_P;
+ return VK_Q;
+ return VK_R;
+ return VK_S;
+ return VK_T;
+ return VK_U;
+ return VK_V;
+ return VK_W;
+ return VK_X;
+ return VK_Y;
+ return VK_Z;
+ */
+ case GDK_bracketleft:
+ return VK_OPEN_BRACKET;
+ case GDK_backslash:
+ return VK_BACK_SLASH;
+ case GDK_bracketright:
+ return VK_CLOSE_BRACKET;
+ case GDK_KP_0:
+ return VK_NUMPAD0;
+ case GDK_KP_1:
+ return VK_NUMPAD1;
+ case GDK_KP_2:
+ return VK_NUMPAD2;
+ case GDK_KP_3:
+ return VK_NUMPAD3;
+ case GDK_KP_4:
+ return VK_NUMPAD4;
+ case GDK_KP_5:
+ return VK_NUMPAD5;
+ case GDK_KP_6:
+ return VK_NUMPAD6;
+ case GDK_KP_7:
+ return VK_NUMPAD7;
+ case GDK_KP_8:
+ return VK_NUMPAD8;
+ case GDK_KP_9:
+ return VK_NUMPAD9;
+ case GDK_KP_Multiply:
+ return VK_MULTIPLY;
+ case GDK_KP_Add:
+ return VK_ADD;
+ /*
+ return VK_SEPARATER;
+ */
+ case GDK_KP_Separator:
+ return VK_SEPARATOR;
+ case GDK_KP_Subtract:
+ return VK_SUBTRACT;
case GDK_KP_Decimal:
return VK_DECIMAL;
- case GDK_Delete:
- return VK_DELETE;
case GDK_KP_Divide:
return VK_DIVIDE;
- case GDK_Down:
- return VK_DOWN;
- case GDK_End:
- return VK_END;
- case GDK_Return:
- return VK_ENTER;
- case GDK_Escape:
- return VK_ESCAPE;
+ case GDK_KP_Delete:
+ if (state & GDK_MOD2_MASK)
+ return VK_DECIMAL;
+ else
+ return VK_DELETE;
+ case GDK_Delete:
+ return VK_DELETE;
+ case GDK_Num_Lock:
+ return VK_NUM_LOCK;
+ case GDK_Scroll_Lock:
+ return VK_SCROLL_LOCK;
case GDK_F1:
return VK_F1;
case GDK_F2:
@@ -154,81 +404,384 @@
return VK_F11;
case GDK_F12:
return VK_F12;
- case GDK_Help:
- return VK_HELP;
- case GDK_Home:
- return VK_HOME;
+ case GDK_F13:
+ return VK_F13;
+ case GDK_F14:
+ return VK_F14;
+ case GDK_F15:
+ return VK_F15;
+ case GDK_F16:
+ return VK_F16;
+ case GDK_F17:
+ return VK_F17;
+ case GDK_F18:
+ return VK_F18;
+ case GDK_F19:
+ return VK_F19;
+ case GDK_F20:
+ return VK_F20;
+ case GDK_F21:
+ return VK_F21;
+ case GDK_F22:
+ return VK_F22;
+ case GDK_F23:
+ return VK_F23;
+ case GDK_F24:
+ return VK_F24;
+ case GDK_Print:
+ return VK_PRINTSCREEN;
+ case GDK_KP_Insert:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD0;
+ else
+ return VK_INSERT;
case GDK_Insert:
return VK_INSERT;
+ case GDK_Help:
+ return VK_HELP;
+ case GDK_Meta_L:
+ case GDK_Meta_R:
+ return VK_META;
+ case GDK_grave:
+ return VK_BACK_QUOTE;
+ case GDK_apostrophe:
+ return VK_QUOTE;
+ case GDK_KP_Up:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD8;
+ else
+ return VK_KP_UP;
+ case GDK_KP_Down:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD2;
+ else
+ return VK_KP_DOWN;
+ case GDK_KP_Left:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD4;
+ else
+ return VK_KP_LEFT;
+ case GDK_KP_Right:
+ if (state & GDK_MOD2_MASK)
+ return VK_NUMPAD6;
+ else
+ return VK_KP_RIGHT;
+ case GDK_dead_grave:
+ return VK_DEAD_GRAVE;
+ case GDK_dead_acute:
+ return VK_DEAD_ACUTE;
+ case GDK_dead_circumflex:
+ return VK_DEAD_CIRCUMFLEX;
+ case GDK_dead_tilde:
+ return VK_DEAD_TILDE;
+ case GDK_dead_macron:
+ return VK_DEAD_MACRON;
+ case GDK_dead_breve:
+ return VK_DEAD_BREVE;
+ case GDK_dead_abovedot:
+ return VK_DEAD_ABOVEDOT;
+ case GDK_dead_diaeresis:
+ return VK_DEAD_DIAERESIS;
+ case GDK_dead_abovering:
+ return VK_DEAD_ABOVERING;
+ case GDK_dead_doubleacute:
+ return VK_DEAD_DOUBLEACUTE;
+ case GDK_dead_caron:
+ return VK_DEAD_CARON;
+ case GDK_dead_cedilla:
+ return VK_DEAD_CEDILLA;
+ case GDK_dead_ogonek:
+ return VK_DEAD_OGONEK;
+ case GDK_dead_iota:
+ return VK_DEAD_IOTA;
+ case GDK_dead_voiced_sound:
+ return VK_DEAD_VOICED_SOUND;
+ case GDK_dead_semivoiced_sound:
+ return VK_DEAD_SEMIVOICED_SOUND;
+ case GDK_ampersand:
+ return VK_AMPERSAND;
+ case GDK_asterisk:
+ return VK_ASTERISK;
+ case GDK_quotedbl:
+ return VK_QUOTEDBL;
+ case GDK_less:
+ return VK_LESS;
+ case GDK_greater:
+ return VK_GREATER;
+ case GDK_braceleft:
+ return VK_BRACELEFT;
+ case GDK_braceright:
+ return VK_BRACERIGHT;
+ case GDK_at:
+ return VK_AT;
+ case GDK_colon:
+ return VK_COLON;
+ case GDK_asciicircum:
+ return VK_CIRCUMFLEX;
+ case GDK_dollar:
+ return VK_DOLLAR;
+ case GDK_EuroSign:
+ return VK_EURO_SIGN;
+ case GDK_exclam:
+ return VK_EXCLAMATION_MARK;
+ case GDK_exclamdown:
+ return VK_INVERTED_EXCLAMATION_MARK;
+ case GDK_parenleft:
+ return VK_LEFT_PARENTHESIS;
+ case GDK_numbersign:
+ return VK_NUMBER_SIGN;
+ case GDK_plus:
+ return VK_PLUS;
+ case GDK_parenright:
+ return VK_RIGHT_PARENTHESIS;
+ case GDK_underscore:
+ return VK_UNDERSCORE;
+ /*
+ return VK_FINAL;
+ return VK_CONVERT;
+ return VK_NONCONVERT;
+ return VK_ACCEPT;
+ */
+ case GDK_Mode_switch:
+ return VK_MODECHANGE;
+ /*
+ return VK_KANA;
+ */
case GDK_Kanji:
return VK_KANJI;
- case GDK_Left:
- return VK_LEFT;
+ /*
+ return VK_ALPHANUMERIC;
+ */
+ case GDK_Katakana:
+ return VK_KATAKANA;
+ case GDK_Hiragana:
+ return VK_HIRAGANA;
+ /*
+ return VK_FULL_WIDTH;
+ return VK_HALF_WIDTH;
+ return VK_ROMAN_CHARACTERS;
+ return VK_ALL_CANDIDATES;
+ */
+ case GDK_PreviousCandidate:
+ return VK_PREVIOUS_CANDIDATE;
+ case GDK_Codeinput:
+ return VK_CODE_INPUT;
+ /*
+ return VK_JAPANESE_KATAKANA;
+ return VK_JAPANESE_HIRAGANA;
+ return VK_JAPANESE_ROMAN;
+ */
+ case GDK_Kana_Lock:
+ return VK_KANA_LOCK;
+ /*
+ return VK_INPUT_METHOD_ON_OFF;
+ return VK_CUT;
+ return VK_COPY;
+ return VK_PASTE;
+ return VK_UNDO;
+ return VK_AGAIN;
+ return VK_FIND;
+ return VK_PROPS;
+ return VK_STOP;
+ return VK_COMPOSE;
+ return VK_ALT_GRAPH;
+ */
+ default:
+ return VK_UNDEFINED;
+ }
+}
+
+static jint
+keysym_to_awt_keylocation (GdkEvent *event)
+{
+ guint ukeyval;
+
+ ukeyval = get_first_keyval_from_keymap (event);
+
+ /* VK_A through VK_Z */
+ if (ukeyval >= GDK_A && ukeyval <= GDK_Z)
+ return AWT_KEY_LOCATION_STANDARD;
+
+ /* VK_0 through VK_9 */
+ if (ukeyval >= GDK_0 && ukeyval <= GDK_9)
+ return AWT_KEY_LOCATION_STANDARD;
+
+ switch (ukeyval)
+ {
+ case GDK_Shift_L:
+ case GDK_Control_L:
+ case GDK_Alt_L:
case GDK_Meta_L:
+ return AWT_KEY_LOCATION_LEFT;
+
+ case GDK_Shift_R:
+ case GDK_Control_R:
+ case GDK_Alt_R:
case GDK_Meta_R:
- return VK_META;
- case GDK_KP_Multiply:
- return VK_MULTIPLY;
- case GDK_Num_Lock:
- return VK_NUM_LOCK;
+ return AWT_KEY_LOCATION_RIGHT;
+
+ case GDK_Return:
+ case GDK_BackSpace:
+ case GDK_Tab:
+ case GDK_Cancel:
+ case GDK_Clear:
+ case GDK_Pause:
+ case GDK_Caps_Lock:
+ case GDK_Escape:
+ case GDK_space:
+ case GDK_Page_Up:
+ case GDK_Page_Down:
+ case GDK_End:
+ case GDK_Home:
+ case GDK_Left:
+ case GDK_Up:
+ case GDK_Right:
+ case GDK_Down:
+ case GDK_comma:
+ case GDK_minus:
+ case GDK_period:
+ case GDK_slash:
+ case GDK_semicolon:
+ case GDK_equal:
+ case GDK_bracketleft:
+ case GDK_backslash:
+ case GDK_bracketright:
+ case GDK_Delete:
+ case GDK_Scroll_Lock:
+ case GDK_F1:
+ case GDK_F2:
+ case GDK_F3:
+ case GDK_F4:
+ case GDK_F5:
+ case GDK_F6:
+ case GDK_F7:
+ case GDK_F8:
+ case GDK_F9:
+ case GDK_F10:
+ case GDK_F11:
+ case GDK_F12:
+ case GDK_F13:
+ case GDK_F14:
+ case GDK_F15:
+ case GDK_F16:
+ case GDK_F17:
+ case GDK_F18:
+ case GDK_F19:
+ case GDK_F20:
+ case GDK_F21:
+ case GDK_F22:
+ case GDK_F23:
+ case GDK_F24:
+ case GDK_Print:
+ case GDK_Insert:
+ case GDK_Help:
+ case GDK_grave:
+ case GDK_apostrophe:
+ case GDK_dead_grave:
+ case GDK_dead_acute:
+ case GDK_dead_circumflex:
+ case GDK_dead_tilde:
+ case GDK_dead_macron:
+ case GDK_dead_breve:
+ case GDK_dead_abovedot:
+ case GDK_dead_diaeresis:
+ case GDK_dead_abovering:
+ case GDK_dead_doubleacute:
+ case GDK_dead_caron:
+ case GDK_dead_cedilla:
+ case GDK_dead_ogonek:
+ case GDK_dead_iota:
+ case GDK_dead_voiced_sound:
+ case GDK_dead_semivoiced_sound:
+ case GDK_ampersand:
+ case GDK_asterisk:
+ case GDK_quotedbl:
+ case GDK_less:
+ case GDK_greater:
+ case GDK_braceleft:
+ case GDK_braceright:
+ case GDK_at:
+ case GDK_colon:
+ case GDK_asciicircum:
+ case GDK_dollar:
+ case GDK_EuroSign:
+ case GDK_exclam:
+ case GDK_exclamdown:
+ case GDK_parenleft:
+ case GDK_numbersign:
+ case GDK_plus:
+ case GDK_parenright:
+ case GDK_underscore:
+ case GDK_Mode_switch:
+ case GDK_Kanji:
+ case GDK_Katakana:
+ case GDK_Hiragana:
+ case GDK_PreviousCandidate:
+ case GDK_Codeinput:
+ case GDK_Kana_Lock:
+ return AWT_KEY_LOCATION_STANDARD;
+
+ case GDK_KP_Enter:
+ case GDK_KP_Page_Up:
+ case GDK_KP_Page_Down:
+ case GDK_KP_End:
+ case GDK_KP_Home:
+ case GDK_KP_Begin:
case GDK_KP_0:
- return VK_NUMPAD0;
case GDK_KP_1:
- return VK_NUMPAD1;
case GDK_KP_2:
- return VK_NUMPAD2;
case GDK_KP_3:
- return VK_NUMPAD3;
case GDK_KP_4:
- return VK_NUMPAD4;
case GDK_KP_5:
- return VK_NUMPAD5;
case GDK_KP_6:
- return VK_NUMPAD6;
case GDK_KP_7:
- return VK_NUMPAD7;
case GDK_KP_8:
- return VK_NUMPAD8;
case GDK_KP_9:
- return VK_NUMPAD9;
- case GDK_bracketleft:
- return VK_OPEN_BRACKET;
- case GDK_Page_Down:
- return VK_PAGE_DOWN;
- case GDK_Page_Up:
- return VK_PAGE_UP;
- case GDK_Pause:
- return VK_PAUSE;
- case GDK_period:
- return VK_PERIOD;
- case GDK_Print:
- return VK_PRINTSCREEN;
- case GDK_quoteright:
- return VK_QUOTE;
- case GDK_Right:
- return VK_RIGHT;
- case GDK_Scroll_Lock:
- return VK_SCROLL_LOCK;
- case GDK_semicolon:
- return VK_SEMICOLON;
+ case GDK_KP_Multiply:
+ case GDK_KP_Add:
case GDK_KP_Separator:
- return VK_SEPARATOR;
- case GDK_Shift_L:
- case GDK_Shift_R:
- return VK_SHIFT;
- case GDK_slash:
- return VK_SLASH;
- case GDK_space:
- return VK_SPACE;
case GDK_KP_Subtract:
- return VK_SUBTRACT;
+ case GDK_KP_Decimal:
+ case GDK_KP_Divide:
+ case GDK_KP_Delete:
+ case GDK_Num_Lock:
+ case GDK_KP_Insert:
+ case GDK_KP_Up:
+ case GDK_KP_Down:
+ case GDK_KP_Left:
+ case GDK_KP_Right:
+ return AWT_KEY_LOCATION_NUMPAD;
+
+ default:
+ return AWT_KEY_LOCATION_UNKNOWN;
+ }
+}
+
+static jchar
+keyevent_to_awt_keychar (GdkEvent *event)
+{
+ if (event->key.length > 0)
+ {
+ /* Translate GDK carriage return to Java linefeed. */
+ if (event->key.string[0] == 13)
+ return VK_ENTER;
+ else
+ return event->key.string[0];
+ }
+ else
+ {
+ switch (event->key.keyval)
+ {
+ case GDK_BackSpace:
+ return VK_BACK_SPACE;
case GDK_Tab:
return VK_TAB;
- case GDK_Up:
- return VK_UP;
-
+ case GDK_Delete:
+ case GDK_KP_Delete:
+ return VK_DELETE;
default:
- return VK_UNDEFINED;
+ return AWT_KEY_CHAR_UNDEFINED;
+ }
}
}
@@ -237,11 +790,22 @@
GtkIMContext "commit" signals, but that do trigger Java KEY_TYPED
events. */
static int
-generates_key_typed_event (guint keyval, GtkWidget *source)
+generates_key_typed_event (GdkEvent *event, GtkWidget *source)
{
- return (keyval == GDK_BackSpace
+ guint keyval;
+
+ if (!GTK_IS_ENTRY (source)
+ && !GTK_IS_TEXT_VIEW (source))
+ return event->key.length ? 1 : 0;
+
+ keyval = event->key.keyval;
+
+ return (keyval == GDK_Escape
+ || keyval == GDK_BackSpace
|| keyval == GDK_Delete
+ || keyval == GDK_KP_Delete
|| keyval == GDK_Return
+ || keyval == GDK_KP_Enter
|| (keyval == GDK_Tab
&& GTK_IS_TEXT_VIEW(source))) ? 1 : 0;
}
@@ -495,28 +1059,24 @@
NULL,
(guchar **)&obj_ptr);
- /* if (grab && GTK_WIDGET_HAS_DEFAULT (widget) ) */
- /* { */
(*gdk_env)->CallVoidMethod (gdk_env, *obj_ptr,
postKeyEventID,
(jint) AWT_KEY_PRESSED,
(jlong) event->key.time,
- state_to_awt_mods (event->key.state),
- keysym_to_awt_keycode (event->key.keyval),
- (jchar) (event->key.length) ?
- event->key.string[0] :
- AWT_KEY_CHAR_UNDEFINED);
+ keyevent_state_to_awt_mods (event),
+ keysym_to_awt_keycode (event),
+ keyevent_to_awt_keychar (event),
+ keysym_to_awt_keylocation (event));
- if (generates_key_typed_event (event->key.keyval, window->focus_widget))
+ if (generates_key_typed_event (event, window->focus_widget))
(*gdk_env)->CallVoidMethod (gdk_env, *obj_ptr,
postKeyEventID,
(jint) AWT_KEY_TYPED,
(jlong) event->key.time,
state_to_awt_mods (event->key.state),
VK_UNDEFINED,
- (jchar) (event->key.length) ?
- event->key.string[0] :
- AWT_KEY_CHAR_UNDEFINED);
+ keyevent_to_awt_keychar (event),
+ AWT_KEY_LOCATION_UNKNOWN);
}
}
break;
@@ -558,11 +1118,10 @@
postKeyEventID,
(jint) AWT_KEY_RELEASED,
(jlong) event->key.time,
- state_to_awt_mods (event->key.state),
- keysym_to_awt_keycode (event->key.keyval),
- (jchar) (event->key.length) ?
- event->key.string[0] :
- AWT_KEY_CHAR_UNDEFINED);
+ keyevent_state_to_awt_mods (event),
+ keysym_to_awt_keycode (event),
+ keyevent_to_awt_keychar (event),
+ keysym_to_awt_keylocation (event));
}
}
break;
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c,v
retrieving revision 1.2
diff -u -b -B -r1.2 gnu_java_awt_peer_gtk_GtkLabelPeer.c
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c,v
retrieving revision 1.4
diff -u -b -B -r1.4 gnu_java_awt_peer_gtk_GtkMainThread.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c 7 Jul 2003 21:50:47 -0000 1.4
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c 2 Aug 2003 02:14:32 -0000
@@ -155,7 +155,7 @@
postExposeEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
"postExposeEvent", "(IIII)V");
postKeyEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
- "postKeyEvent", "(IJIIC)V");
+ "postKeyEvent", "(IJIICI)V");
postFocusEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
"postFocusEvent", "(IZ)V");
postAdjustmentEventID = (*env)->GetMethodID (env, gtkscrollbarpeer,
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c,v
retrieving revision 1.4
diff -u -b -B -r1.4 gnu_java_awt_peer_gtk_GtkTextAreaPeer.c
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c,v
retrieving revision 1.4
diff -u -b -B -r1.4 gnu_java_awt_peer_gtk_GtkTextComponentPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c 23 Jul 2003 22:26:35 -0000 1.4
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c 2 Aug 2003 02:14:32 -0000
@@ -456,8 +456,6 @@
const gchar *str,
jobject peer)
{
- void *ptr;
-
/* str is a \0-terminated UTF-8 encoded character. */
gunichar2 *jc = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
@@ -473,7 +471,8 @@
/* ... and assume no modifiers. */
0,
VK_UNDEFINED,
- (jchar) jc[0]);
+ (jchar) jc[0],
+ AWT_KEY_LOCATION_UNKNOWN);
g_free (jc);
}
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c,v
retrieving revision 1.5
diff -u -b -B -r1.5 gnu_java_awt_peer_gtk_GtkTextFieldPeer.c
Index: jni/gtk-peer/gtkpeer.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gtkpeer.h,v
retrieving revision 1.2
diff -u -b -B -r1.2 gtkpeer.h
--- jni/gtk-peer/gtkpeer.h 7 Jul 2003 19:56:04 -0000 1.2
+++ jni/gtk-peer/gtkpeer.h 2 Aug 2003 02:14:32 -0000
@@ -142,77 +142,82 @@
#define AWT_KEY_PRESSED 401
#define AWT_KEY_RELEASED 402
-#define VK_UNDEFINED 0
#define AWT_KEY_CHAR_UNDEFINED 0
-#define VK_0 48
-#define VK_1 49
-#define VK_2 50
-#define VK_3 51
-#define VK_4 52
-#define VK_5 53
-#define VK_6 54
-#define VK_7 55
-#define VK_8 56
-#define VK_9 57
-#define VK_A 65
-#define VK_ACCEPT 30
-#define VK_ADD 107
-#define VK_ALT 18
-#define VK_B 66
-#define VK_BACK_QUOTE 192
-#define VK_BACK_SLASH 92
-#define VK_BACK_SPACE 8
-#define VK_C 67
+#define AWT_KEY_LOCATION_UNKNOWN 0
+#define AWT_KEY_LOCATION_STANDARD 1
+#define AWT_KEY_LOCATION_LEFT 2
+#define AWT_KEY_LOCATION_RIGHT 3
+#define AWT_KEY_LOCATION_NUMPAD 4
+
+/* Virtual Keys */
+/* This list should be kept in the same order as the VK_ field
+ declarations in KeyEvent.java. */
+#define VK_ENTER '\n'
+#define VK_BACK_SPACE '\b'
+#define VK_TAB '\t'
#define VK_CANCEL 3
-#define VK_CAPS_LOCK 20
#define VK_CLEAR 12
-#define VK_CLOSE_BRACKET 93
-#define VK_COMMA 44
+#define VK_SHIFT 16
#define VK_CONTROL 17
-#define VK_CONVERT 28
-#define VK_D 68
-#define VK_DECIMAL 110
-#define VK_DELETE 127
-#define VK_DIVIDE 111
-#define VK_DOWN 40
-#define VK_E 69
-#define VK_END 35
-#define VK_ENTER 10
+#define VK_ALT 18
+#define VK_PAUSE 19
+#define VK_CAPS_LOCK 20
#define VK_ESCAPE 27
-#define VK_F 70
-#define VK_F1 112
-#define VK_F10 121
-#define VK_F11 122
-#define VK_F12 123
-#define VK_F2 113
-#define VK_F3 114
-#define VK_F4 115
-#define VK_F5 116
-#define VK_F6 117
-#define VK_F7 118
-#define VK_F8 119
-#define VK_F9 120
-#define VK_FINAL 24
-#define VK_G 71
-#define VK_H 72
-#define VK_HELP 156
+#define VK_SPACE ' '
+#define VK_PAGE_UP 33
+#define VK_PAGE_DOWN 34
+#define VK_END 35
#define VK_HOME 36
-#define VK_I 73
-#define VK_INSERT 155
-#define VK_J 74
-#define VK_K 75
-#define VK_KANA 21
-#define VK_KANJI 25
-#define VK_L 76
#define VK_LEFT 37
-#define VK_M 77
-#define VK_META 157
-#define VK_MODECHANGE 31
-#define VK_MULTIPLY 106
-#define VK_N 78
-#define VK_NONCONVERT 29
-#define VK_NUM_LOCK 144
+#define VK_UP 38
+#define VK_RIGHT 39
+#define VK_DOWN 40
+#define VK_COMMA ','
+#define VK_MINUS '-'
+#define VK_PERIOD '.'
+#define VK_SLASH '/'
+#define VK_0 '0'
+#define VK_1 '1'
+#define VK_2 '2'
+#define VK_3 '3'
+#define VK_4 '4'
+#define VK_5 '5'
+#define VK_6 '6'
+#define VK_7 '7'
+#define VK_8 '8'
+#define VK_9 '9'
+#define VK_SEMICOLON ';'
+#define VK_EQUALS '='
+#define VK_A 'A'
+#define VK_B 'B'
+#define VK_C 'C'
+#define VK_D 'D'
+#define VK_E 'E'
+#define VK_F 'F'
+#define VK_G 'G'
+#define VK_H 'H'
+#define VK_I 'I'
+#define VK_J 'J'
+#define VK_K 'K'
+#define VK_L 'L'
+#define VK_M 'M'
+#define VK_N 'N'
+#define VK_O 'O'
+#define VK_P 'P'
+#define VK_Q 'Q'
+#define VK_R 'R'
+#define VK_S 'S'
+#define VK_T 'T'
+#define VK_U 'U'
+#define VK_V 'V'
+#define VK_W 'W'
+#define VK_X 'X'
+#define VK_Y 'Y'
+#define VK_Z 'Z'
+#define VK_OPEN_BRACKET '['
+#define VK_BACK_SLASH '\\'
+#define VK_CLOSE_BRACKET ']'
#define VK_NUMPAD0 96
#define VK_NUMPAD1 97
#define VK_NUMPAD2 98
@@ -223,35 +228,117 @@
#define VK_NUMPAD7 103
#define VK_NUMPAD8 104
#define VK_NUMPAD9 105
-#define VK_O 79
-#define VK_OPEN_BRACKET 91
-#define VK_P 80
-#define VK_PAGE_DOWN 34
-#define VK_PAGE_UP 33
-#define VK_PAUSE 19
-#define VK_PERIOD 46
-#define VK_PRINTSCREEN 154
-#define VK_Q 81
-#define VK_QUOTE 222
-#define VK_R 82
-#define VK_RIGHT 39
-#define VK_S 83
-#define VK_SCROLL_LOCK 145
-#define VK_SEMICOLON 59
+#define VK_MULTIPLY 106
+#define VK_ADD 107
+#define VK_SEPARATER 108
#define VK_SEPARATOR 108
-#define VK_SHIFT 16
-#define VK_SLASH 47
-#define VK_SPACE 32
#define VK_SUBTRACT 109
-#define VK_T 84
-#define VK_TAB 9
-#define VK_U 85
-#define VK_UP 38
-#define VK_V 86
-#define VK_W 87
-#define VK_X 88
-#define VK_Y 89
-#define VK_Z 90
+#define VK_DECIMAL 110
+#define VK_DIVIDE 111
+#define VK_DELETE 127
+#define VK_NUM_LOCK 144
+#define VK_SCROLL_LOCK 145
+#define VK_F1 112
+#define VK_F2 113
+#define VK_F3 114
+#define VK_F4 115
+#define VK_F5 116
+#define VK_F6 117
+#define VK_F7 118
+#define VK_F8 119
+#define VK_F9 120
+#define VK_F10 121
+#define VK_F11 122
+#define VK_F12 123
+#define VK_F13 61440
+#define VK_F14 61441
+#define VK_F15 61442
+#define VK_F16 61443
+#define VK_F17 61444
+#define VK_F18 61445
+#define VK_F19 61446
+#define VK_F20 61447
+#define VK_F21 61448
+#define VK_F22 61449
+#define VK_F23 61450
+#define VK_F24 61451
+#define VK_PRINTSCREEN 154
+#define VK_INSERT 155
+#define VK_HELP 156
+#define VK_META 157
+#define VK_BACK_QUOTE 192
+#define VK_QUOTE 222
+#define VK_KP_UP 224
+#define VK_KP_DOWN 225
+#define VK_KP_LEFT 226
+#define VK_KP_RIGHT 227
+#define VK_DEAD_GRAVE 128
+#define VK_DEAD_ACUTE 129
+#define VK_DEAD_CIRCUMFLEX 130
+#define VK_DEAD_TILDE 131
+#define VK_DEAD_MACRON 132
+#define VK_DEAD_BREVE 133
+#define VK_DEAD_ABOVEDOT 134
+#define VK_DEAD_DIAERESIS 135
+#define VK_DEAD_ABOVERING 136
+#define VK_DEAD_DOUBLEACUTE 137
+#define VK_DEAD_CARON 138
+#define VK_DEAD_CEDILLA 139
+#define VK_DEAD_OGONEK 140
+#define VK_DEAD_IOTA 141
+#define VK_DEAD_VOICED_SOUND 142
+#define VK_DEAD_SEMIVOICED_SOUND 143
+#define VK_AMPERSAND 150
+#define VK_ASTERISK 151
+#define VK_QUOTEDBL 152
+#define VK_LESS 153
+#define VK_GREATER 160
+#define VK_BRACELEFT 161
+#define VK_BRACERIGHT 162
+#define VK_AT 512
+#define VK_COLON 513
+#define VK_CIRCUMFLEX 514
+#define VK_DOLLAR 515
+#define VK_EURO_SIGN 516
+#define VK_EXCLAMATION_MARK 517
+#define VK_INVERTED_EXCLAMATION_MARK 518
+#define VK_LEFT_PARENTHESIS 519
+#define VK_NUMBER_SIGN 520
+#define VK_PLUS 521
+#define VK_RIGHT_PARENTHESIS 522
+#define VK_UNDERSCORE 523
+#define VK_FINAL 24
+#define VK_CONVERT 28
+#define VK_NONCONVERT 29
+#define VK_ACCEPT 30
+#define VK_MODECHANGE 31
+#define VK_KANA 21
+#define VK_KANJI 25
+#define VK_ALPHANUMERIC 240
+#define VK_KATAKANA 241
+#define VK_HIRAGANA 242
+#define VK_FULL_WIDTH 243
+#define VK_HALF_WIDTH 244
+#define VK_ROMAN_CHARACTERS 245
+#define VK_ALL_CANDIDATES 256
+#define VK_PREVIOUS_CANDIDATE 257
+#define VK_CODE_INPUT 258
+#define VK_JAPANESE_KATAKANA 259
+#define VK_JAPANESE_HIRAGANA 260
+#define VK_JAPANESE_ROMAN 261
+#define VK_KANA_LOCK 262
+#define VK_INPUT_METHOD_ON_OFF 263
+#define VK_CUT 65489
+#define VK_COPY 65485
+#define VK_PASTE 65487
+#define VK_UNDO 65483
+#define VK_AGAIN 65481
+#define VK_FIND 65488
+#define VK_PROPS 65482
+#define VK_STOP 65480
+#define VK_COMPOSE 65312
+#define VK_ALT_GRAPH 65406
+#define VK_UNDEFINED 0
#define AWT_FOCUS_LOST 1004
#define AWT_FOCUS_GAINED 1005