2004-01-27 Kim Ho <kho@redhat.com>
authorKim Ho <kho@redhat.com>
Tue, 27 Jan 2004 19:29:57 +0000 (19:29 +0000)
committerKim Ho <kho@gcc.gnu.org>
Tue, 27 Jan 2004 19:29:57 +0000 (19:29 +0000)
        * 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.

From-SVN: r76740

libjava/ChangeLog
libjava/Makefile.am
libjava/Makefile.in
libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java
libjava/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java
libjava/java/awt/Frame.java
libjava/java/awt/Menu.java
libjava/java/awt/MenuBar.java
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c [new file with mode: 0644]
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c

index f0ce89823421755ff08f104260f04630e857f7c9..7d16e2266a5ec2d52fb4d9b63b6c91394bc56e13 100644 (file)
@@ -1,3 +1,25 @@
+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.
+
 2004-01-27  Michael Koch  <konqueror@gmx.de>
 
        * javax/swing/AbstractCellEditor.java: Reformated.
index 43cb2bcdadc435c4d0f72af2f148e3a780a1d7da..365fe9ec84f2caa3dbcd5661497aa77d09ac0673 100644 (file)
@@ -200,6 +200,7 @@ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \
+jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c \
index 2b2c3a0befb917e917dad2d43c48c033385b8605..ff53a32c2e9b4dc03647a7b5ca7be635d7761abb 100644 (file)
@@ -292,6 +292,7 @@ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c \
+jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c \
@@ -2794,6 +2795,7 @@ lib_gnu_java_awt_peer_gtk_la_DEPENDENCIES =
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.lo \
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.lo \
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.lo \
+@GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.lo \
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.lo \
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.lo \
 @GTK_CAIRO_FALSE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.lo \
@@ -2874,6 +2876,7 @@ lib_gnu_java_awt_peer_gtk_la_DEPENDENCIES =
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.lo \
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.lo \
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.lo \
+@GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.lo \
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.lo \
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.lo \
 @GTK_CAIRO_TRUE@jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.lo \
@@ -4581,6 +4584,7 @@ DEP_FILES =  .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.P \
+.deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.P \
 .deps/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.P \
index 6bc1ca94d29b7ecea2c4624be9ddc5efcdea43ff..8fd96b45a5707fe54abb4c165e7f635cd4254969 100644 (file)
@@ -58,7 +58,7 @@ public class GtkFramePeer extends GtkWindowPeer
   native int getMenuBarHeight (MenuBarPeer bar);
 
   native void setMenuBarPeer (MenuBarPeer bar);
-  native void removeMenuBarPeer (MenuBarPeer bar);
+  native void removeMenuBarPeer ();
   native void moveLayout (int offset);
 
   public void setMenuBar (MenuBar bar)
@@ -67,7 +67,7 @@ public class GtkFramePeer extends GtkWindowPeer
     {    
       if (menuBar != null)
       {
-        removeMenuBarPeer(menuBar); 
+        removeMenuBarPeer(); 
         menuBar = null;
         moveLayout(menuBarHeight);
         insets.top -= menuBarHeight;
@@ -80,7 +80,7 @@ public class GtkFramePeer extends GtkWindowPeer
       int oldHeight = 0;
       if (menuBar != null)
       {
-        removeMenuBarPeer(menuBar);
+        removeMenuBarPeer();
         oldHeight = menuBarHeight;
         insets.top -= menuBarHeight;
       }
index eeef383ebd37f19d33aef613f6a7e69ad2ceb782..92f02230621a755ae5bf752bd8d6c6a54fb149dd 100644 (file)
@@ -47,8 +47,6 @@ public class GtkMenuComponentPeer extends GtkGenericPeer
   {
     super (awtWidget);
   }
-
-  public void dispose ()
-  {
-  }
+  
+  public native void dispose();
 }
index 7a5c9d98f8e59c89fde214d81faf74f67f96a469..c92585a6f6b9421386df0165f096c3bca750cc39 100644 (file)
@@ -341,11 +341,15 @@ getMenuBar()
 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,11 +436,20 @@ remove(MenuComponent menu)
 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 6fdc22c8ccd470228f01da1371309a8d21ee3690..7fb2931184e65e8f2b816a386c9aa2048caed8ff 100644 (file)
@@ -41,6 +41,7 @@ package java.awt;
 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 @@ addNotify()
 {
   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 @@ addNotify()
 public void
 removeNotify()
 {
+  Enumeration e = items.elements();
+  while (e.hasMoreElements())
+  {
+    MenuItem mi = (MenuItem) e.nextElement();
+    mi.removeNotify();
+  }
   super.removeNotify();
 }
 
index af5c9121b21609e0e584b5474ff9f9d3c5b0021c..9c278dfde0d4db80ac51e0b353bc3d5d0b4a5727 100644 (file)
@@ -279,6 +279,12 @@ addNotify()
 public void
 removeNotify()
 {
+  Enumeration e = menus.elements();
+  while (e.hasMoreElements())
+  {
+    Menu mi = (Menu) e.nextElement();
+    mi.removeNotify();
+  }
   super.removeNotify();
 }
 
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuComponentPeer.c
new file mode 100644 (file)
index 0000000..c30ac29
--- /dev/null
@@ -0,0 +1,56 @@
+/* gtkmenucomponentpeer.c -- Native implementation of GtkMenuComponentPeer
+   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);  
+}
index 970380683ba2d356302c07ba5935cd417be5aa39..fb82aed82f560df72a4c37827780f0325ca24b01 100644 (file)
@@ -376,18 +376,37 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_nativeSetBounds
 
 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 there isn't a MenuBar in this Frame's list of children
+     then we can just return. */
+  if (!GTK_IS_MENU_SHELL (children->data))
+    return;
+  else
+    mptr = children->data;
+    
+  /* This will actually destroy the MenuBar. By removing it from
+     its parent, the reference count for the MenuBar widget will
+     decrement to 0. The widget will be automatically destroyed 
+     by Gtk. */
   gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (mptr));  
   
   gdk_threads_leave();