/[classpath]/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
ViewVC logotype

Diff of /classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.57 by fitzsim, Fri Aug 26 18:14:07 2005 UTC revision 1.58 by fitzsim, Tue Sep 6 03:08:54 2005 UTC
# Line 294  cp_gtk_window_init_jni (void) Line 294  cp_gtk_window_init_jni (void)
294  }  }
295    
296  /* Get the first keyval in the keymap for this event's keycode.  The  /* Get the first keyval in the keymap for this event's keycode.  The
297     first keyval corresponds roughly to Java's notion of a virtual     first keyval corresponds roughly to Java's notion of a virtual key.
298     key.  Returns the uppercase version of the first keyval. */     Returns the uppercase version of the first keyval or -1 if no
299  static guint     keyval was found for the given hardware keycode. */
300    static gint
301  get_first_keyval_from_keymap (GdkEventKey *event)  get_first_keyval_from_keymap (GdkEventKey *event)
302  {  {
303    guint keyval;    guint keyval;
# Line 309  get_first_keyval_from_keymap (GdkEventKe Line 310  get_first_keyval_from_keymap (GdkEventKe
310                                             &keyvals,                                             &keyvals,
311                                             &n_entries))                                             &n_entries))
312      {      {
313        g_warning ("No keyval found for hardware keycode %d\n",        /* No keyval found for hardware keycode */
314                   event->hardware_keycode);        return -1;
       /* Try to recover by using the keyval in the event structure. */  
       keyvals = &(event->keyval);  
315      }      }
316    keyval = keyvals[0];    keyval = keyvals[0];
317    g_free (keyvals);    g_free (keyvals);
# Line 320  get_first_keyval_from_keymap (GdkEventKe Line 319  get_first_keyval_from_keymap (GdkEventKe
319    return gdk_keyval_to_upper (keyval);    return gdk_keyval_to_upper (keyval);
320  }  }
321    
322    /* Return the AWT key code for the given keysym or -1 if no keyval was
323       found for the given hardware keycode. */
324  #ifdef __GNUC__  #ifdef __GNUC__
325  __inline  __inline
326  #endif  #endif
327  static jint  static jint
328  keysym_to_awt_keycode (GdkEventKey *event)  keysym_to_awt_keycode (GdkEventKey *event)
329  {  {
330    guint ukeyval;    gint ukeyval;
331    guint state;    guint state;
332    
333    ukeyval = get_first_keyval_from_keymap (event);    ukeyval = get_first_keyval_from_keymap (event);
334    
335      if (ukeyval < 0)
336        return -1;
337    
338    state = event->state;    state = event->state;
339    
340    /* VK_A through VK_Z */    /* VK_A through VK_Z */
# Line 728  keysym_to_awt_keycode (GdkEventKey *even Line 733  keysym_to_awt_keycode (GdkEventKey *even
733      }      }
734  }  }
735    
736    /* Return the AWT key location code for the given keysym or -1 if no
737       keyval was found for the given hardware keycode. */
738  static jint  static jint
739  keysym_to_awt_keylocation (GdkEventKey *event)  keysym_to_awt_keylocation (GdkEventKey *event)
740  {  {
741    guint ukeyval;    gint ukeyval;
742    
743    ukeyval = get_first_keyval_from_keymap (event);    ukeyval = get_first_keyval_from_keymap (event);
744    
745      if (ukeyval < 0)
746        return -1;
747    
748    /* VK_A through VK_Z */    /* VK_A through VK_Z */
749    if (ukeyval >= GDK_A && ukeyval <= GDK_Z)    if (ukeyval >= GDK_A && ukeyval <= GDK_Z)
750      return AWT_KEY_LOCATION_STANDARD;      return AWT_KEY_LOCATION_STANDARD;
# Line 1059  key_press_cb (GtkWidget *widget __attrib Line 1069  key_press_cb (GtkWidget *widget __attrib
1069                GdkEventKey *event,                GdkEventKey *event,
1070                jobject peer)                jobject peer)
1071  {  {
1072      jint keycode;
1073      jint keylocation;
1074    
1075      keycode = keysym_to_awt_keycode (event);
1076      keylocation = keysym_to_awt_keylocation (event);
1077    
1078      /* Return immediately if an error occurs translating a hardware
1079         keycode to a keyval. */
1080      if (keycode < 0 || keylocation < 0)
1081        return TRUE;
1082    
1083    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
1084                                  postKeyEventID,                                  postKeyEventID,
1085                                  (jint) AWT_KEY_PRESSED,                                  (jint) AWT_KEY_PRESSED,
1086                                  (jlong) event->time,                                  (jlong) event->time,
1087                                  keyevent_state_to_awt_mods (event),                                  keyevent_state_to_awt_mods (event),
1088                                  keysym_to_awt_keycode (event),                                  keycode,
1089                                  keyevent_to_awt_keychar (event),                                  keyevent_to_awt_keychar (event),
1090                                  keysym_to_awt_keylocation (event));                                  keylocation);
1091    
1092    /* FIXME: generation of key typed events needs to be moved    /* FIXME: generation of key typed events needs to be moved
1093       to GtkComponentPeer.postKeyEvent.  If the key in a key       to GtkComponentPeer.postKeyEvent.  If the key in a key
# Line 1082  key_release_cb (GtkWidget *widget __attr Line 1103  key_release_cb (GtkWidget *widget __attr
1103                  GdkEventKey *event,                  GdkEventKey *event,
1104                  jobject peer)                  jobject peer)
1105  {  {
1106      jint keycode;
1107      jint keylocation;
1108    
1109      keycode = keysym_to_awt_keycode (event);
1110      keylocation = keysym_to_awt_keylocation (event);
1111    
1112      /* Return immediately if an error occurs translating a hardware
1113         keycode to a keyval. */
1114      if (keycode < 0 || keylocation < 0)
1115        return TRUE;
1116    
1117    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
1118                                  postKeyEventID,                                  postKeyEventID,
1119                                  (jint) AWT_KEY_RELEASED,                                  (jint) AWT_KEY_RELEASED,
1120                                  (jlong) event->time,                                  (jlong) event->time,
1121                                  keyevent_state_to_awt_mods (event),                                  keyevent_state_to_awt_mods (event),
1122                                  keysym_to_awt_keycode (event),                                  keycode,
1123                                  keyevent_to_awt_keychar (event),                                  keyevent_to_awt_keychar (event),
1124                                  keysym_to_awt_keylocation (event));                                  keylocation);
1125    
1126    return TRUE;    return TRUE;
1127  }  }

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26