This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH]: handle menubar disposal
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: 27 Jan 2004 11:22:45 -0500
- Subject: [PATCH]: handle menubar disposal
- Organization:
Hi,
This patch properly removeNotify's a MenuBar and its children when the
MenuBar is removed from the Frame or the Frame is disposed of.
I did use -N but I couldn't add the file to the repository first
(checked out as anon on this machine).
Cheers,
Kim
2004-01-27 Kim Ho <kho@redhat.com>
* gnu/java/awt/peer/gtk/GtkFramePeer.java
(removeMenuBarPeer): Remove MenuBarPeer argument.
* gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
(dispose): Call native method.
* java/awt/Frame.java (setMenuBar): Create and remove
MenuBar peers only if the Frame has a peer.
(addNotify): Create the MenuBar peer if one exists.
(removeNotify): Remove MenuBar peer if one exists.
* java/awt/Menu.java: Fix imports.
(addNotify): Don't use full class name.
(removeNotify): Call removeNotify on all children.
* java/awt/MenuBar.java (removeNotify): Call
removeNotify on all children.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
(removeMenuBarPeer): Remove MenuBarPeer argument.
Iterate through children to find the Frame's MenuBar.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c
New file.
(dispose): Remove references to the MenuComponent.
Index: gnu/java/awt/peer/gtk/GtkFramePeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java,v
retrieving revision 1.12
diff -u -r1.12 GtkFramePeer.java
--- gnu/java/awt/peer/gtk/GtkFramePeer.java 26 Jan 2004 13:56:59 -0000 1.12
+++ gnu/java/awt/peer/gtk/GtkFramePeer.java 27 Jan 2004 16:12:00 -0000
@@ -58,13 +58,13 @@
native int getMenuBarHeight (MenuBarPeer bar);
native void setMenuBarPeer (MenuBarPeer bar);
- native void removeMenuBarPeer (MenuBarPeer bar);
+ native void removeMenuBarPeer ();
public void setMenuBar (MenuBar bar)
{
if (bar == null && menuBar != null)
{
- removeMenuBarPeer(menuBar);
+ removeMenuBarPeer();
menuBar = null;
insets.top -= menuBarHeight;
menuBarHeight = 0;
@@ -73,7 +73,7 @@
else if (bar != null)
{
if (menuBar != null)
- removeMenuBarPeer(menuBar);
+ removeMenuBarPeer();
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer();
setMenuBarPeer(menuBar);
menuBarHeight = getMenuBarHeight (menuBar);
Index: gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java,v
retrieving revision 1.2
diff -u -r1.2 GtkMenuComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java 13 Jul 2003 15:09:20 -0000 1.2
+++ gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java 27 Jan 2004 16:12:00 -0000
@@ -47,8 +47,6 @@
{
super (awtWidget);
}
-
- public void dispose ()
- {
- }
+
+ public native void dispose();
}
Index: java/awt/Frame.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Frame.java,v
retrieving revision 1.19
diff -u -r1.19 Frame.java
--- java/awt/Frame.java 19 Jan 2004 14:27:45 -0000 1.19
+++ java/awt/Frame.java 27 Jan 2004 16:12:00 -0000
@@ -341,11 +341,15 @@
public synchronized void
setMenuBar(MenuBar menuBar)
{
- this.menuBar = menuBar;
- if (menuBar != null)
- menuBar.addNotify();
if (peer != null)
+ {
+ if (this.menuBar != null)
+ this.menuBar.removeNotify();
+ if (menuBar != null)
+ menuBar.addNotify();
((FramePeer) peer).setMenuBar(menuBar);
+ }
+ this.menuBar = menuBar;
}
/*************************************************************************/
@@ -432,9 +436,18 @@
public void
addNotify()
{
+ if (menuBar != null)
+ menuBar.addNotify();
if (peer == null)
peer = getToolkit ().createFrame (this);
super.addNotify();
+}
+
+public void removeNotify()
+{
+ if (menuBar != null)
+ menuBar.removeNotify();
+ super.removeNotify();
}
/*************************************************************************/
Index: java/awt/Menu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Menu.java,v
retrieving revision 1.14
diff -u -r1.14 Menu.java
--- java/awt/Menu.java 19 Jan 2004 14:27:45 -0000 1.14
+++ java/awt/Menu.java 27 Jan 2004 16:12:00 -0000
@@ -41,6 +41,7 @@
import java.awt.peer.MenuPeer;
import java.io.Serializable;
import java.util.Vector;
+import java.util.Enumeration;
/**
* This class represents a pull down or tear off menu in Java's AWT.
@@ -379,7 +380,7 @@
{
if (peer == null)
peer = getToolkit().createMenu(this);
- java.util.Enumeration e = items.elements();
+ Enumeration e = items.elements();
while (e.hasMoreElements())
{
MenuItem mi = (MenuItem)e.nextElement();
@@ -396,6 +397,12 @@
public void
removeNotify()
{
+ Enumeration e = items.elements();
+ while (e.hasMoreElements())
+ {
+ MenuItem mi = (MenuItem) e.nextElement();
+ mi.removeNotify();
+ }
super.removeNotify();
}
Index: java/awt/MenuBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/MenuBar.java,v
retrieving revision 1.11
diff -u -r1.11 MenuBar.java
--- java/awt/MenuBar.java 19 Jan 2004 14:27:45 -0000 1.11
+++ java/awt/MenuBar.java 27 Jan 2004 16:12:00 -0000
@@ -279,6 +279,12 @@
public void
removeNotify()
{
+ Enumeration e = menus.elements();
+ while (e.hasMoreElements())
+ {
+ Menu mi = (Menu) e.nextElement();
+ mi.removeNotify();
+ }
super.removeNotify();
}
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c,v
retrieving revision 1.21
diff -u -r1.21 gnu_java_awt_peer_gtk_GtkWindowPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 26 Jan 2004 13:56:59 -0000 1.21
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 27 Jan 2004 16:12:07 -0000
@@ -376,18 +376,30 @@
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer
- (JNIEnv *env, jobject obj, jobject menubar)
+ (JNIEnv *env, jobject obj)
{
void *wptr;
GtkWidget *box;
GtkWidget *mptr;
+ GList* children;
wptr = NSA_GET_PTR (env, obj);
- mptr = NSA_GET_PTR (env, menubar);
gdk_threads_enter ();
box = GTK_BIN (wptr)->child;
+
+ children = gtk_container_get_children (GTK_CONTAINER (box));
+
+ while (children != NULL && !GTK_IS_MENU_SHELL (children->data))
+ {
+ children = children->next;
+ }
+
+ if (!GTK_IS_MENU_SHELL (children->data))
+ return;
+ else
+ mptr = children->data;
gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (mptr));
gdk_threads_leave();
/* gtkmenucomponentpeer.c -- Native implementation of GtkMenuBarPeer
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
#include "gtkpeer.h"
#include "gnu_java_awt_peer_gtk_GtkMenuComponentPeer.h"
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose
(JNIEnv *env, jobject obj)
{
/* For MenuComponents and its subclasses, the widgets are
automatically destroyed by Gtk when the parent MenuBar
is removed from the Frame. So we avoid the widget
destruction in GtkGenericPeer dispose() by overriding
it here. */
/* However, references to the Java objects still exist in the
state tables, so we still have to remove those. */
NSA_DEL_GLOBAL_REF (env, obj);
NSA_DEL_PTR (env, obj);
}