This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] [PATCH] Fix ActionEvent dispatching to MenuShortcuts


Hello,

I committed the following patch to the java-gui-branch.  It fixes
ActionEvent dispatching to MenuShortcuts.  Also, it seems that menu
accelerators are working fine at the moment, so I'm removing a FIXME
regarding accelerators.

-David Jee

2004-07-30  David Jee  <djee@redhat.com>

        * java/awt/DefaultKeyboardFocusManager.java
        (postProcessKeyEvent): Only activate MenuShortcuts on KEY_PRESSED
        event.  Fix shift modifier checking.
        * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c
        (accel_attach): Remove.
        (setupAccelGroup): Remove calls to accel_attach.


Index: java/awt/DefaultKeyboardFocusManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/DefaultKeyboardFocusManager.java,v
retrieving revision 1.1.54.6
diff -u -r1.1.54.6 DefaultKeyboardFocusManager.java
--- java/awt/DefaultKeyboardFocusManager.java	11 Jul 2004 03:04:42 -0000	1.1.54.6
+++ java/awt/DefaultKeyboardFocusManager.java	30 Jul 2004 13:33:11 -0000
@@ -284,10 +284,11 @@
   {
     // Check if this event represents a menu shortcut.
 
-    // MenuShortcuts are activated by Ctrl- KeyEvents.
+    // MenuShortcuts are activated by Ctrl- KeyEvents, only on KEY_PRESSED.
     int modifiers = e.getModifiers ();
-    if ((modifiers & KeyEvent.CTRL_MASK) != 0
-        || (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0)
+    if (e.getID() == KeyEvent.KEY_PRESSED
+        && ((modifiers & KeyEvent.CTRL_MASK) != 0
+            || (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0))
       {
         Window focusedWindow = getGlobalFocusedWindow ();
         if (focusedWindow instanceof Frame)
@@ -313,15 +314,21 @@
 
                         if (shortcut != null)
                           {
-                            // Dispatch a new ActionEvent if this is a
-                            // Shift- KeyEvent and the shortcut requires
-                            // the Shift modifier, or if the shortcut
-                            // doesn't require the Shift modifier.
-                            if ((shortcut.usesShiftModifier ()
-                                 && ((modifiers & KeyEvent.SHIFT_MASK) != 0
-                                     || (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0)
-                                 || !shortcut.usesShiftModifier ())
-                                && shortcut.getKey () == e.getKeyCode ())
+                            // Dispatch a new ActionEvent if:
+                            //
+                            //     a) this is a Shift- KeyEvent, and the
+                            //        shortcut requires the Shift modifier
+                            //
+                            // or, b) this is not a Shift- KeyEvent, and the
+                            //        shortcut does not require the Shift
+                            //        modifier.
+                            if (shortcut.getKey () == e.getKeyCode ()
+                                && ((shortcut.usesShiftModifier ()
+                                     && ((modifiers & KeyEvent.SHIFT_MASK) != 0
+                                         || (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0))
+                                    || (! shortcut.usesShiftModifier ()
+                                        && (modifiers & KeyEvent.SHIFT_MASK) == 0
+                                        && (modifiers & KeyEvent.SHIFT_DOWN_MASK) == 0)))
                               {
                                 item.dispatchEvent (new ActionEvent (item,
                                                                      ActionEvent.ACTION_PERFORMED,
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c,v
retrieving revision 1.4.8.5
diff -u -r1.4.8.5 gnu_java_awt_peer_gtk_GtkMenuPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c	23 Jul 2004 15:22:54 -0000	1.4.8.5
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c	30 Jul 2004 13:33:12 -0000
@@ -39,20 +39,6 @@
 #include "gtkpeer.h"
 #include "gnu_java_awt_peer_gtk_GtkMenuPeer.h"
 
-static void
-accel_attach (GtkMenuItem *menu_item,
-	      gpointer *user_data __attribute__((unused)))
-{
-  GtkAccelGroup *accel;
-
-  accel = gtk_menu_get_accel_group (GTK_MENU (menu_item->submenu));
-  /* FIXME: update this to use GTK-2.4 GtkActions. */
-#if 0
-  _gtk_accel_group_attach (accel, 
-    G_OBJECT (gtk_widget_get_toplevel (GTK_WIDGET(menu_item))));
-#endif
-}
-
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup
   (JNIEnv *env, jobject obj, jobject parent)
 {
@@ -65,14 +51,6 @@
     {
       gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu), 
 				gtk_accel_group_new ());
-
-      if (GTK_WIDGET_REALIZED (GTK_WIDGET (ptr1)))
-	accel_attach (GTK_MENU_ITEM (ptr1), NULL);
-      else
-	g_signal_connect (G_OBJECT (ptr1),
-			    "realize",
-			    GTK_SIGNAL_FUNC (accel_attach), 
-			    NULL);
     }
   else
     {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]