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]

Patch: Embedded Window Support


Hello,

This patch reworks Michael Koch's initial patch for embedded window
support.  The changes are:

- EmbeddedWindow is derived from Window

- a new class: GtkEmbeddedWindowPeer

- the construction process is the same as for other widgets --
specifically, addNotify is called to instantiate the peer.

Please review and comment.

Thanks,
Tom

2003-07-18  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* Makefile.am (gtk_c_source_files): Add
	jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c.
	(gtk_awt_peer_sources): Add
	gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java.
	(nat_source_files): Remove gnu/java/awt/natEmbeddedWindow.cc.
	* gnu/java/awt/EmbeddedWindow.java: New implementation.
	* gnu/java/awt/EmbeddedWindowSupport.java (createEmbeddedWindow):
	Replace window_id, width and height parameters with EmbeddedWindow
	parameter.
	* gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java: New file.
	* gnu/java/awt/peer/gtk/GtkToolkit.java (createEmbeddedWindow):
	New method.
	* java/awt/Window.java (Window(III)): Remove method.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c: New
	file.

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.308
diff -u -b -B -r1.308 Makefile.am
--- Makefile.am	13 Jul 2003 16:53:04 -0000	1.308
+++ Makefile.am	18 Jul 2003 06:10:07 -0000
@@ -165,6 +165,7 @@
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c \
+jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c \
 jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImagePainter.c \
@@ -205,6 +206,7 @@
 gnu/java/awt/peer/gtk/GtkComponentPeer.java \
 gnu/java/awt/peer/gtk/GtkContainerPeer.java \
 gnu/java/awt/peer/gtk/GtkDialogPeer.java \
+gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java \
 gnu/java/awt/peer/gtk/GtkFileDialogPeer.java \
 gnu/java/awt/peer/gtk/GtkFontPeer.java \
 gnu/java/awt/peer/gtk/GtkFramePeer.java	\
@@ -2575,7 +2577,6 @@
 gnu/gcj/runtime/natStackTrace.cc \
 gnu/gcj/runtime/natStringBuffer.cc \
 gnu/gcj/runtime/natVMClassLoader.cc \
-gnu/java/awt/natEmbeddedWindow.cc \
 gnu/java/nio/natFileLockImpl.cc \
 gnu/java/nio/natSelectorImpl.cc \
 java/io/natFile.cc \
Index: gnu/java/awt/EmbeddedWindow.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/EmbeddedWindow.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 EmbeddedWindow.java
--- gnu/java/awt/EmbeddedWindow.java	13 Jul 2003 14:39:41 -0000	1.1
+++ gnu/java/awt/EmbeddedWindow.java	18 Jul 2003 06:10:12 -0000
@@ -39,24 +39,55 @@
 package gnu.java.awt;
 
 import java.awt.Window;
+import java.awt.Toolkit;
 
 /**
- * This class represents an AWT window embedded into another graphical
- * toolkit or anther application.
+ * Represents an AWT window that can be embedded into another
+ * application.
  * 
  * @author Michael Koch <konqueror@gmx.de>
  */
 public class EmbeddedWindow extends Window
 {
+  private int window_id;
+
+  /**
+   * Creates a window to be embedded into another application.
+   *
+   * @param window_id The native handle to the screen area where the
+   * AWT window should be embedded.
+   */
+  public EmbeddedWindow(int window_id)
+  {
+    super();
+    this.window_id = window_id;
+  }
+
+  /**
+   * Creates the native peer for this embedded window.
+   */
+  public void addNotify()
+  {
+    Toolkit tk = getToolkit();
+
+    if (!(tk instanceof EmbeddedWindowSupport))
+      throw new UnsupportedOperationException
+	("Embedded windows are not supported by the current peers: " + tk.getClass());
+
+    if (peer == null)
+      peer = ((EmbeddedWindowSupport)tk).createEmbeddedWindow (this);
+
+    super.addNotify();
+  }
+
   /**
-   * Creates an window embedded into another application of graphical toolkit.
+   * Gets the native handle of the screen area where the window will
+   * be embedded.
    *
-   * @param window_id The native handle to the screen area where the AWT window
-   * should be embedded.
-   * @param width The width of the screen area.
-   * @param height The height of the screen area.
+   * @return The native handle that was passed to the constructor.
    */
-  // This method is only made native to circumvent the package-privateness of
-  // an internal java.awt.Window constructor.
-  public static native Window create (int window_id, int width, int height);
+  public int getHandle()
+  {
+    return window_id;
+  }
 }
Index: gnu/java/awt/EmbeddedWindowSupport.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/EmbeddedWindowSupport.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 EmbeddedWindowSupport.java
--- gnu/java/awt/EmbeddedWindowSupport.java	13 Jul 2003 14:39:41 -0000	1.1
+++ gnu/java/awt/EmbeddedWindowSupport.java	18 Jul 2003 06:10:12 -0000
@@ -41,11 +41,12 @@
 import java.awt.peer.WindowPeer;
 
 /**
- * This interface defines a method for creating embedded windows.
+ * Declares a method for creating native embedded window peers.
  *
- * All classes inherited from java.awt.Toolkit that implement this interface
- * are assumed to support embedded windows. To embed the real embedded window
- * you need to use gnu.java.awt.EmbeddedWindow.
+ * All classes inherited from java.awt.Toolkit that implement this
+ * interface are assumed to support the creation of embedded window
+ * peers.  To create an embedded window, use
+ * gnu.java.awt.EmbeddedWindow.
  *
  * @see gnu.java.awt.EmbeddedWindow
  * @see java.awt.Toolkit
@@ -55,13 +56,10 @@
 public interface EmbeddedWindowSupport
 {
   /**
-   * This method creates an embedded window in an application.
+   * Creates an embedded window peer, and associates it with an
+   * EmbeddedWindow object.
    *
-   * @param window_id The native handle of a screen area to display an
-   * AWT window in it.
-   * @param width The width of the screen area.
-   * @param height The height of the screen area.
+   * @param w The embedded window with which to associate a peer.
    */
-  public WindowPeer createEmbeddedWindow (int window_id,
-					  int width, int height);
+  public WindowPeer createEmbeddedWindow (EmbeddedWindow w);
 }
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 GtkComponentPeer.java
Index: gnu/java/awt/peer/gtk/GtkContainerPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 GtkContainerPeer.java
Index: gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java
===================================================================
RCS file: gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java
diff -N gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java	18 Jul 2003 06:10:12 -0000
@@ -0,0 +1,55 @@
+/* GtkEmbeddedWindowPeer.java -- Implements WindowPeer using a GtkPlug
+   Copyright (C) 1998, 1999, 2002 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. */
+
+package gnu.java.awt.peer.gtk;
+
+import java.awt.peer.WindowPeer;
+import gnu.java.awt.EmbeddedWindow;
+
+public class GtkEmbeddedWindowPeer extends GtkWindowPeer
+  implements WindowPeer
+{
+  native void create ();
+
+  native void construct (int window_id);
+
+  public GtkEmbeddedWindowPeer (EmbeddedWindow window)
+  {
+    super (window);
+    construct (window.getHandle());
+  }
+}
Index: gnu/java/awt/peer/gtk/GtkToolkit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 GtkToolkit.java
--- gnu/java/awt/peer/gtk/GtkToolkit.java	17 Jul 2003 20:26:51 -0000	1.2
+++ gnu/java/awt/peer/gtk/GtkToolkit.java	18 Jul 2003 06:10:12 -0000
@@ -52,6 +52,8 @@
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.Properties;
+import gnu.java.awt.EmbeddedWindow;
+import gnu.java.awt.EmbeddedWindowSupport;
 import gnu.classpath.Configuration;
 
 /* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer().
@@ -61,7 +63,7 @@
    this class.  If getPeer() ever goes away, we can implement a hash table
    that will keep up with every window's peer, but for now this is faster. */
 
-public class GtkToolkit extends java.awt.Toolkit
+public class GtkToolkit extends Toolkit implements EmbeddedWindowSupport
 {
   GtkMainThread main;
   Hashtable containers = new Hashtable();
@@ -297,6 +299,11 @@
   protected WindowPeer createWindow (Window w)
   {
     return new GtkWindowPeer (w);
+  }
+
+  public WindowPeer createEmbeddedWindow (EmbeddedWindow w)
+  {
+    return new GtkEmbeddedWindowPeer (w);
   }
 
   protected FontPeer getFontPeer (String name, int style) 
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.25
diff -u -b -B -r1.25 Window.java
--- java/awt/Window.java	13 Jul 2003 14:39:41 -0000	1.25
+++ java/awt/Window.java	18 Jul 2003 06:10:15 -0000
@@ -94,19 +94,6 @@
     graphicsConfiguration = gc;
   }
 
-  Window(int window_id, int width, int height)
-  {
-    this();
-
-    Toolkit tk = getToolkit();
-    if (!(tk instanceof EmbeddedWindowSupport))
-      throw new UnsupportedOperationException
-	("Embedded windows not supported by the current peers: " + tk.getClass());
-    
-    peer = ((EmbeddedWindowSupport) getToolkit())
-	    .createEmbeddedWindow (window_id, width, height);
-  }
-    
   /**
    * Initializes a new instance of <code>Window</code> with the specified
    * parent.  The window will initially be invisible.
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c
===================================================================
RCS file: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c
diff -N jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c	18 Jul 2003 06:10:18 -0000
@@ -0,0 +1,80 @@
+/* gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer.c -- Native
+   implementation of GtkEmbeddedWindowPeer
+   Copyright (C) 1998, 1999, 2002 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_GtkEmbeddedWindowPeer.h"
+
+JNIEXPORT void JNICALL 
+Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_create
+  (JNIEnv *env, jobject obj)
+{
+  gpointer window;
+  GtkWidget *vbox, *layout;
+
+  gdk_threads_enter ();
+
+  /* Create an "unplugged" GtkPlug. */
+  window = gtk_plug_new (0);
+
+  vbox = gtk_vbox_new (0, 0);
+  layout = gtk_layout_new (NULL, NULL);
+  gtk_box_pack_end (GTK_BOX (vbox), layout, 1, 1, 0);
+  gtk_container_add (GTK_CONTAINER (window), vbox);
+
+  gtk_widget_show (layout);
+  gtk_widget_show (vbox);
+
+  gdk_threads_leave ();
+
+  NSA_SET_PTR (env, obj, window);
+}
+
+JNIEXPORT void JNICALL 
+Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_construct
+  (JNIEnv *env, jobject obj, jint window_id)
+{
+  void *ptr;
+  ptr = NSA_GET_PTR (env, obj);
+
+  gdk_threads_enter ();
+
+  gtk_plug_construct (GTK_PLUG(ptr), window_id);
+
+  gdk_threads_leave ();
+}
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.2
diff -u -b -B -r1.2 gnu_java_awt_peer_gtk_GtkWindowPeer.c

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