This is the second part for the old (1.0) style AWT event handling. The
problem that is fixed here is that events that are targetted at menu
components (like ActionEvents) must be forwarded along the parent chain
and finally must end up in the frame that holds the menu bar (I have an
application here that expects exactly this). Unfortunatly, the MenuBar
knows nothing about its parent frame (MenuBars are not part of the
normal component hierarchy, also they are not derived from Component).
MenuBar.getParent() returns null. So I had to add a reference to the
parent frame to MenuBar and forward the event this way.

2006-01-13  Roman Kennke  <[EMAIL PROTECTED]>

        * java/awt/MenuBar.java
        (frame): New field.
        (removeNotify): Clear frame field when beeing removed from the
        frame.
        * java/awt/Frame.java
        (setMenuBar): Store a reference of the frame in the MenuBar.
        * java/awt/MenuComponent.java
        (postEvent): Implemented to forward the call to the parent until
        a parent can handle the event.
        (dispatchEvent): Moved handling of old style events from
        dispatchEventImpl() to here.
        (dispatchEventImpl): Moved handling of old style events to
        dispatchEvent().

/Roman
Index: java/awt/MenuBar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/MenuBar.java,v
retrieving revision 1.17
diff -u -r1.17 MenuBar.java
--- java/awt/MenuBar.java	2 Jul 2005 20:32:25 -0000	1.17
+++ java/awt/MenuBar.java	13 Jan 2006 21:21:22 -0000
@@ -91,6 +91,13 @@
    */
   private transient AccessibleContext accessibleContext;
 
+  /**
+   * The frame that this menubar is associated with. We need to know this so
+   * that [EMAIL PROTECTED] MenuComponent#postEvent(Event)} can post the event to the
+   * frame if no other component processed the event.
+   */
+  Frame frame;
+
 /*************************************************************************/
 
 /*
@@ -303,6 +310,7 @@
     Menu mi = (Menu) e.nextElement();
     mi.removeNotify();
   }
+  frame = null;
   super.removeNotify();
 }
 
Index: java/awt/Frame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Frame.java,v
retrieving revision 1.34
diff -u -r1.34 Frame.java
--- java/awt/Frame.java	20 Sep 2005 01:05:28 -0000	1.34
+++ java/awt/Frame.java	13 Jan 2006 21:21:22 -0000
@@ -332,6 +332,7 @@
     invalidateTree ();
     ((FramePeer) peer).setMenuBar(menuBar);
   }
+  menuBar.frame = this;
   this.menuBar = menuBar;
 }
 
Index: java/awt/MenuComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/MenuComponent.java,v
retrieving revision 1.23
diff -u -r1.23 MenuComponent.java
--- java/awt/MenuComponent.java	3 Oct 2005 17:21:06 -0000	1.23
+++ java/awt/MenuComponent.java	13 Jan 2006 21:21:23 -0000
@@ -38,6 +38,7 @@
 
 package java.awt;
 
+import java.awt.event.ActionEvent;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 import java.awt.peer.MenuComponentPeer;
@@ -352,8 +353,21 @@
 public boolean
 postEvent(Event event)
 {
-  // This is overridden by subclasses that support events.
-  return false;
+  boolean retVal = false;
+  MenuContainer parent = getParent();
+  if (parent == null)
+    {
+      if (this instanceof MenuBar)
+        {
+          MenuBar menuBar = (MenuBar) this;
+          if (menuBar.frame != null)
+            retVal = menuBar.frame.postEvent(event);
+        }
+    }
+  else
+    retVal = parent.postEvent(event);
+
+  return retVal;
 }
 /*************************************************************************/
 
@@ -364,6 +378,13 @@
   */
 public final void dispatchEvent(AWTEvent event)
 {
+  /* Convert AWT 1.1 event to AWT 1.0 event */
+  Event oldStyleEvent = Component.translateEvent(event);
+  if (oldStyleEvent != null)
+    {
+      postEvent(oldStyleEvent);
+    }
+
   // See comment in Component.dispatchEvent().
   dispatchEventImpl(event);
 }
@@ -380,15 +401,6 @@
  */
 void dispatchEventImpl(AWTEvent event)
 {
-  Event oldStyleEvent;
-
-  // This is overridden by subclasses that support events.
-  /* Convert AWT 1.1 event to AWT 1.0 event */
-  oldStyleEvent = Component.translateEvent(event);
-  if (oldStyleEvent != null)
-    {
-      postEvent(oldStyleEvent);
-    }
   /* Do local processing */
   processEvent(event);
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to