Hi, We were using some tricks in MenuBar and MenuComponent to forward events to the Frame that contained the MenuBar. That was only necessary because we weren't properly updating the MenuBar parent. This patch cleans this up:
2006-02-14 Mark Wielaard <[EMAIL PROTECTED]>
* java/awt/Frame.java (setMenuBar): Update MenuBar parent.
(remove): If menu component is the current MenuBar remove it,
otherwise call super.remove().
* java/awt/MenuBar.java (frame): Remove field.
* java/awt/MenuComponent.java (postEvent): Use getParent() always.
I added some Mauve tests that now pass with this patch.
Committed,
Mark
Index: java/awt/Frame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Frame.java,v
retrieving revision 1.36
diff -u -r1.36 Frame.java
--- java/awt/Frame.java 13 Jan 2006 22:01:19 -0000 1.36
+++ java/awt/Frame.java 14 Feb 2006 16:24:54 -0000
@@ -1,5 +1,6 @@
/* Frame.java -- AWT toplevel window
- Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -320,23 +321,33 @@
}
/**
- * Sets this frame's menu bar.
+ * Sets this frame's menu bar. Removes any existing menu bar. If the
+ * given menu bar is part of another frame it will be removed from
+ * that frame.
*
* @param menuBar the new menu bar for this frame
*/
public synchronized void setMenuBar(MenuBar menuBar)
{
- if (peer != null)
+ if (this.menuBar != null)
+ remove(this.menuBar);
+
+ this.menuBar = menuBar;
+ if (menuBar != null)
{
- if (this.menuBar != null)
- this.menuBar.removeNotify();
- if (menuBar != null)
- menuBar.addNotify();
- invalidateTree ();
- ((FramePeer) peer).setMenuBar(menuBar);
+ MenuContainer parent = menuBar.getParent();
+ if (parent != null)
+ parent.remove(menuBar);
+ menuBar.setParent(this);
+
+ if (peer != null)
+ {
+ if (menuBar != null)
+ menuBar.addNotify();
+ invalidateTree();
+ ((FramePeer) peer).setMenuBar(menuBar);
+ }
}
- menuBar.frame = this;
- this.menuBar = menuBar;
}
/**
@@ -391,13 +402,30 @@
}
/**
- * Removes the specified component from this frame's menu.
+ * Removes the specified menu component from this frame. If it is
+ * the current MenuBar it is removed from the frame. If it is a
+ * Popup it is removed from this component. If it is any other menu
+ * component it is ignored.
*
* @param menu the menu component to remove
*/
public void remove(MenuComponent menu)
{
- menuBar.remove(menu);
+ if (menu == menuBar)
+ {
+ if (menuBar != null)
+ {
+ if (peer != null)
+ {
+ ((FramePeer) peer).setMenuBar(null);
+ menuBar.removeNotify();
+ }
+ menuBar.setParent(null);
+ }
+ menuBar = null;
+ }
+ else
+ super.remove(menu);
}
public void addNotify()
Index: java/awt/MenuBar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/MenuBar.java,v
retrieving revision 1.20
diff -u -r1.20 MenuBar.java
--- java/awt/MenuBar.java 13 Jan 2006 21:47:00 -0000 1.20
+++ java/awt/MenuBar.java 14 Feb 2006 16:24:54 -0000
@@ -1,5 +1,6 @@
/* MenuBar.java -- An AWT menu bar class
- Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -73,13 +74,6 @@
private Vector menus = new Vector();
/**
- * 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;
-
- /**
* Initializes a new instance of <code>MenuBar</code>.
*
* @throws HeadlessException if GraphicsEnvironment.isHeadless() is true
@@ -250,7 +244,6 @@
Menu mi = (Menu) e.nextElement();
mi.removeNotify();
}
- frame = null;
super.removeNotify();
}
Index: java/awt/MenuComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/MenuComponent.java,v
retrieving revision 1.25
diff -u -r1.25 MenuComponent.java
--- java/awt/MenuComponent.java 13 Jan 2006 22:20:57 -0000 1.25
+++ java/awt/MenuComponent.java 14 Feb 2006 16:24:55 -0000
@@ -1,5 +1,6 @@
/* MenuComponent.java -- Superclass of all AWT menu components
- Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -308,16 +309,7 @@
{
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
+ if (parent != null)
retVal = parent.postEvent(event);
return retVal;
signature.asc
Description: This is a digitally signed message part
