This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[Patch] Embedded window support
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 9 Jul 2003 16:11:00 +0200
- Subject: [Patch] Embedded window support
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
For my little pet project I need to embed AWT/Swing windows into a
native app. To make this possible I wrote the attached patch. It adds
a new interface and a new class in gnu.java.awt and adds support code
in java.awt.
If the currently used java.awt.Toolkit subclass implements
gnu.java.awt.EmbeddedWindowSupport this support will be activated. Of
course the peer providing the Toolkit subclass needs some code to
support it too.
Some GTK peer things are not solved yet but this will come soon.
What do you think about this design ? Okay to commit to trunk ?
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE/DCJ0WSOgCCdjSDsRAn0cAJ9Rj6md04eLbpRtTUb4wvEbgCaw3wCfZWHj
7Al6HZLT82iyPPCnVdfT4Es=
=MRaJ
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2020
diff -u -b -B -r1.2020 ChangeLog
--- ChangeLog 9 Jul 2003 07:50:00 -0000 1.2020
+++ ChangeLog 9 Jul 2003 14:05:57 -0000
@@ -1,5 +1,29 @@
2003-07-09 Michael Koch <konqueror@gmx.de>
+ * gnu/java/awt/EmbeddedWindow.java,
+ gnu/java/awt/EmbeddedWindowSupport.java:
+ New files.
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java
+ (GtkComponentPeer): New constructor.
+ * gnu/java/awt/peer/gtk/GtkContainerPeer.java
+ (GtkContainerPeer): New constructor.
+ * gnu/java/awt/peer/gtk/GtkToolkit.java
+ (GtkToolkit): Implements EmbeddedWindowSupport.
+ (createEmbeddedWindow): New method.
+ * gnu/java/awt/peer/gtk/GtkWindowPeer.java
+ (createEmbedded): New method.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+ (createEmbedded): New method.
+ * java/awt/Window.java
+ (Window): New package-private constructor
+ * Makefile.am
+ (awt_java_source_files): Added new files:
+ gnu/java/awt/EmbeddedWindow.java,
+ gnu/java/awt/EmbeddedWindowSupport.java
+ * Makefile.in: Regenerated.
+
+2003-07-09 Michael Koch <konqueror@gmx.de>
+
* gnu/java/awt/peer/gtk/GtkComponentPeer.java,
gnu/java/awt/peer/gtk/GtkContainerPeer.java,
gnu/java/awt/peer/gtk/GtkDialogPeer.java,
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.305
diff -u -b -B -r1.305 Makefile.am
--- Makefile.am 9 Jul 2003 07:11:11 -0000 1.305
+++ Makefile.am 9 Jul 2003 14:06:01 -0000
@@ -751,6 +751,8 @@
gnu/java/awt/BitMaskExtent.java \
gnu/java/awt/Buffers.java \
gnu/java/awt/ComponentDataBlitOp.java \
+gnu/java/awt/EmbeddedWindow.java \
+gnu/java/awt/EmbeddedWindowSupport.java \
gnu/java/awt/EventModifier.java \
gnu/java/awt/GLightweightPeer.java \
gnu/java/awt/image/ImageDecoder.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.330
diff -u -b -B -r1.330 Makefile.in
--- Makefile.in 9 Jul 2003 07:11:12 -0000 1.330
+++ Makefile.in 9 Jul 2003 14:06:02 -0000
@@ -522,6 +522,8 @@
gnu/java/awt/BitMaskExtent.java \
gnu/java/awt/Buffers.java \
gnu/java/awt/ComponentDataBlitOp.java \
+gnu/java/awt/EmbeddedWindow.java \
+gnu/java/awt/EmbeddedWindowSupport.java \
gnu/java/awt/EventModifier.java \
gnu/java/awt/GLightweightPeer.java \
gnu/java/awt/image/ImageDecoder.java \
Index: gnu/java/awt/EmbeddedWindow.java
===================================================================
RCS file: gnu/java/awt/EmbeddedWindow.java
diff -N gnu/java/awt/EmbeddedWindow.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/awt/EmbeddedWindow.java 9 Jul 2003 14:06:02 -0000
@@ -0,0 +1,52 @@
+/* EmbeddedWindow.java --
+ Copyright (C) 2003 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;
+
+import java.awt.Window;
+
+/**
+ * @author Michael Koch <konqueror@gmx.de>
+ */
+public class EmbeddedWindow extends Window
+{
+ public EmbeddedWindow (int window_id, int width, int height)
+ {
+ super (window_id, width, height);
+ }
+}
Index: gnu/java/awt/EmbeddedWindowSupport.java
===================================================================
RCS file: gnu/java/awt/EmbeddedWindowSupport.java
diff -N gnu/java/awt/EmbeddedWindowSupport.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/awt/EmbeddedWindowSupport.java 9 Jul 2003 14:06:02 -0000
@@ -0,0 +1,47 @@
+/* EmbeddedWindowSupport.java --
+ Copyright (C) 2003 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;
+
+import java.awt.peer.WindowPeer;
+
+public interface EmbeddedWindowSupport
+{
+ public WindowPeer createEmbeddedWindow (int window_id,
+ int width, int height);
+}
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
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 9 Jul 2003 07:50:00 -0000 1.4
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 9 Jul 2003 14:06:02 -0000
@@ -92,6 +92,11 @@
native void connectHooks ();
+ protected GtkComponentPeer (int window_id)
+ {
+ super (null);
+ }
+
protected GtkComponentPeer (Component awtComponent)
{
super (awtComponent);
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
--- gnu/java/awt/peer/gtk/GtkContainerPeer.java 9 Jul 2003 07:50:00 -0000 1.3
+++ gnu/java/awt/peer/gtk/GtkContainerPeer.java 9 Jul 2003 14:06:02 -0000
@@ -51,6 +51,13 @@
Insets insets;
Container c;
+ public GtkContainerPeer (int window_id)
+ {
+ super (window_id);
+ this.c = null;
+ insets = new Insets (0, 0, 0, 0);
+ }
+
public GtkContainerPeer(Container c)
{
super (c);
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.1
diff -u -b -B -r1.1 GtkToolkit.java
--- gnu/java/awt/peer/gtk/GtkToolkit.java 31 Jan 2003 17:54:13 -0000 1.1
+++ gnu/java/awt/peer/gtk/GtkToolkit.java 9 Jul 2003 14:06:02 -0000
@@ -39,18 +39,20 @@
package gnu.java.awt.peer.gtk;
import java.awt.*;
-import java.awt.datatransfer.*;
+import java.awt.datatransfer.Clipboard;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.im.InputMethodHighlight;
-import java.awt.image.*;
+import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
import java.awt.peer.*;
-import java.net.*;
+import java.net.URL;
import java.util.Hashtable;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
-import gnu.java.awt.image.*;
+import gnu.java.awt.EmbeddedWindowSupport;
import gnu.classpath.Configuration;
/* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer().
@@ -60,7 +62,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();
@@ -296,6 +298,11 @@
protected WindowPeer createWindow (Window w)
{
return new GtkWindowPeer (w);
+ }
+
+ public WindowPeer createEmbeddedWindow (int window_id, int width, int height)
+ {
+ return new GtkWindowPeer (window_id, width, height);
}
protected FontPeer getFontPeer (String name, int style)
Index: gnu/java/awt/peer/gtk/GtkWindowPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkWindowPeer.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 GtkWindowPeer.java
--- gnu/java/awt/peer/gtk/GtkWindowPeer.java 9 Jul 2003 07:50:00 -0000 1.2
+++ gnu/java/awt/peer/gtk/GtkWindowPeer.java 9 Jul 2003 14:06:02 -0000
@@ -57,6 +57,8 @@
create (GTK_WINDOW_POPUP);
}
+ native void createEmbedded (int window_id);
+
native void connectHooks ();
public GtkWindowPeer (Window window)
@@ -65,6 +67,14 @@
Dimension d = window.getSize ();
setBounds (0, 0, d.width, d.height);
+ }
+
+ public GtkWindowPeer (int window_id, int width, int height)
+ {
+ super (window_id);
+
+ setBounds (0, 0, width, height);
+ createEmbedded (window_id);
}
public void getArgs (Component component, GtkArgList args)
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.24
diff -u -b -B -r1.24 Window.java
--- java/awt/Window.java 27 Jun 2003 20:53:01 -0000 1.24
+++ java/awt/Window.java 9 Jul 2003 14:06:02 -0000
@@ -38,6 +38,7 @@
package java.awt;
+import gnu.java.awt.EmbeddedWindowSupport;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
@@ -93,6 +94,19 @@
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_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
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 30 Jun 2003 23:53:29 -0000 1.2
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 9 Jul 2003 14:06:02 -0000
@@ -71,6 +71,29 @@
NSA_SET_PTR (env, obj, window);
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkWindowPeer_createEmbedded
+ (JNIEnv *env, jobject obj, jint window_id)
+{
+ gpointer window;
+ GtkWidget *vbox, *layout;
+
+ gdk_threads_enter ();
+ window = gtk_plug_new (window_id);
+
+ 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_GtkWindowPeer_setVisible
(JNIEnv *env, jobject obj, jboolean visible)
{