diff options
author | Sven de Marothy <sven@physto.se> | 2006-08-08 22:23:35 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2006-08-08 22:23:35 +0000 |
commit | 73a82f166753c34c3e1a18f2db1955c7c83679a3 (patch) | |
tree | 0f6cede23afe927f993c72607360ef69cc32514e | |
parent | c3ea0ff462ca77ee82b76647ea7f5c8c7af47d05 (diff) | |
download | classpath-73a82f166753c34c3e1a18f2db1955c7c83679a3.tar.gz |
2006-08-09 Sven de Marothy <sven@physto.se>
* gnu/java/awt/peer/gtk/GtkMainThread.java
New file.
* gnu/java/awt/peer/gtk/GtkChoicePeer.java
* gnu/java/awt/peer/gtk/GtkComponentPeer.java
Replace GtkToolkit.mainThread with GtkMainThread.mainThread.
* gnu/java/awt/peer/gtk/GtkToolkit.java
Minor style fixes; removed unused fields,
set fields to private where possible.
(createDialog, createFrame, createWindow, createEmbeddedWindow):
Call GtkMainThread.createWindow().
* gnu/java/awt/peer/gtk/GtkWindowPeer.java
(dispose): New method.
* include/gnu_java_awt_peer_gtk_GtkToolkit.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
(gtkQuit): New native method.
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkChoicePeer.java | 2 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkComponentPeer.java | 4 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkMainThread.java | 97 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkToolkit.java | 30 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkWindowPeer.java | 6 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GtkToolkit.h | 1 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c | 11 |
8 files changed, 149 insertions, 20 deletions
@@ -1,3 +1,21 @@ +2006-08-09 Sven de Marothy <sven@physto.se> + + * gnu/java/awt/peer/gtk/GtkMainThread.java + New file. + * gnu/java/awt/peer/gtk/GtkChoicePeer.java + * gnu/java/awt/peer/gtk/GtkComponentPeer.java + Replace GtkToolkit.mainThread with GtkMainThread.mainThread. + * gnu/java/awt/peer/gtk/GtkToolkit.java + Minor style fixes; removed unused fields, + set fields to private where possible. + (createDialog, createFrame, createWindow, createEmbeddedWindow): + Call GtkMainThread.createWindow(). + * gnu/java/awt/peer/gtk/GtkWindowPeer.java + (dispose): New method. + * include/gnu_java_awt_peer_gtk_GtkToolkit.h + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c + (gtkQuit): New native method. + 2006-08-08 Lillian Angel <langel@redhat.com> * java/awt/Component.java diff --git a/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/gnu/java/awt/peer/gtk/GtkChoicePeer.java index f00461f3f..d866cefd3 100644 --- a/gnu/java/awt/peer/gtk/GtkChoicePeer.java +++ b/gnu/java/awt/peer/gtk/GtkChoicePeer.java @@ -84,7 +84,7 @@ public class GtkChoicePeer extends GtkComponentPeer public void select (int position) { - if (Thread.currentThread() == GtkToolkit.mainThread) + if (Thread.currentThread() == GtkMainThread.mainThread) selectNativeUnlocked (position); else selectNative (position); diff --git a/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/gnu/java/awt/peer/gtk/GtkComponentPeer.java index c11c45e20..f96033e56 100644 --- a/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ b/gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -514,7 +514,7 @@ public class GtkComponentPeer extends GtkGenericPeer y = 0; } - if (Thread.currentThread() == GtkToolkit.mainThread) + if (Thread.currentThread() == GtkMainThread.mainThread) gtkWidgetSetCursorUnlocked(cursor.getType(), image, x, y); else gtkWidgetSetCursor(cursor.getType(), image, x, y); @@ -562,7 +562,7 @@ public class GtkComponentPeer extends GtkGenericPeer b = (bounds.width > 0) && (bounds.height > 0); } - if (Thread.currentThread() == GtkToolkit.mainThread) + if (Thread.currentThread() == GtkMainThread.mainThread) setVisibleNativeUnlocked (b); else setVisibleNative (b); diff --git a/gnu/java/awt/peer/gtk/GtkMainThread.java b/gnu/java/awt/peer/gtk/GtkMainThread.java new file mode 100644 index 000000000..19d3f1d0b --- /dev/null +++ b/gnu/java/awt/peer/gtk/GtkMainThread.java @@ -0,0 +1,97 @@ +/* GtkMainThread.java -- Wrapper for the GTK main thread, and some utilities. + Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 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; + +public class GtkMainThread extends Thread +{ + /** Count of the number of open windows */ + private static int numberOfWindows = 0; + + /** Lock for the above */ + private static Object nWindowsLock = new Object(); + + /** The main thread instance (singleton) */ + public static GtkMainThread mainThread; + + /** Constructs a main thread */ + private GtkMainThread() + { + super("GTK main thread"); + } + + public void run () + { + GtkToolkit.gtkMain (); + } + + private static void startMainThread() + { + if( mainThread == null ) + { + mainThread = new GtkMainThread(); + mainThread.start(); + } + } + + private static void endMainThread() + { + if( mainThread != null ) + GtkToolkit.gtkQuit(); + } + + public static void createWindow() + { + synchronized( nWindowsLock ) + { + if( numberOfWindows == 0 ) + startMainThread(); + numberOfWindows++; + } + } + + public static void destroyWindow() + { + synchronized( nWindowsLock ) + { + numberOfWindows--; + if( numberOfWindows == 0 ) + endMainThread(); + } + } +}
\ No newline at end of file diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java index 6aa87fc2e..3f87ca6e6 100644 --- a/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -131,37 +131,30 @@ import javax.imageio.spi.IIORegistry; public class GtkToolkit extends gnu.java.awt.ClasspathToolkit { - Hashtable containers = new Hashtable(); - static EventQueue q; - static Thread mainThread; + private static EventQueue q; static native void gtkInit(int portableNativeSync); + static native void gtkMain(); + + static native void gtkQuit(); + static { System.loadLibrary("gtkpeer"); - + int portableNativeSync; String portNatSyncProp = System.getProperty("gnu.classpath.awt.gtk.portable.native.sync"); - + if (portNatSyncProp == null) portableNativeSync = -1; // unset else if (Boolean.valueOf(portNatSyncProp).booleanValue()) portableNativeSync = 1; // true else portableNativeSync = 0; // false - + gtkInit(portableNativeSync); - - mainThread = new Thread ("GTK main thread") - { - public void run () - { - gtkMain (); - } - }; - mainThread.start (); } public GtkToolkit () @@ -169,6 +162,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit } public native void beep(); + private native void getScreenSizeDimensions(int[] xy); public int checkImage (Image image, int width, int height, @@ -462,6 +456,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit protected DialogPeer createDialog (Dialog d) { + GtkMainThread.createWindow(); return new GtkDialogPeer (d); } @@ -472,6 +467,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit protected FramePeer createFrame (Frame f) { + GtkMainThread.createWindow(); return new GtkFramePeer (f); } @@ -532,11 +528,13 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit protected WindowPeer createWindow (Window w) { + GtkMainThread.createWindow(); return new GtkWindowPeer (w); } public EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w) { + GtkMainThread.createWindow(); return new GtkEmbeddedWindowPeer (w); } @@ -661,8 +659,6 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit GdkPixbufDecoder.registerSpis(reg); } - public static native void gtkMain(); - protected MouseInfoPeer getMouseInfoPeer() { return new GtkMouseInfoPeer(); diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java index 866d9c881..1f340611e 100644 --- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java @@ -75,6 +75,12 @@ public class GtkWindowPeer extends GtkContainerPeer native boolean gtkWindowHasFocus(); native void realize (); + public void dispose() + { + super.dispose(); + GtkMainThread.destroyWindow(); + } + /** Returns the cached width of the AWT window component. */ int getX () { diff --git a/include/gnu_java_awt_peer_gtk_GtkToolkit.h b/include/gnu_java_awt_peer_gtk_GtkToolkit.h index 6cdcc622a..f1f5326cd 100644 --- a/include/gnu_java_awt_peer_gtk_GtkToolkit.h +++ b/include/gnu_java_awt_peer_gtk_GtkToolkit.h @@ -17,6 +17,7 @@ JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_sync (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors (JNIEnv *env, jobject, jintArray); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain (JNIEnv *env, jclass); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit (JNIEnv *env, jclass); JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons (JNIEnv *env, jobject); #ifdef __cplusplus diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c index 8949fa927..969b7bc5c 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c @@ -329,6 +329,17 @@ Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain gdk_threads_leave (); } +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit +(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + gdk_threads_enter (); + + gtk_main_quit (); + + gdk_threads_leave (); +} + static jint gdk_color_to_java_color (GdkColor color); |