1 /* gtkmainthread.c -- Native implementation of GtkMainThread
2 Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 #include "gnu_java_awt_peer_gtk_GtkMainThread.h"
41 #include "gthread-jni.h"
44 struct state_table *native_state_table;
47 jmethodID postActionEventID;
48 jmethodID postMenuActionEventID;
49 jmethodID postMouseEventID;
50 jmethodID postConfigureEventID;
51 jmethodID postExposeEventID;
52 jmethodID postKeyEventID;
53 jmethodID postFocusEventID;
54 jmethodID postAdjustmentEventID;
55 jmethodID postItemEventID;
56 jmethodID postListItemEventID;
57 jmethodID postTextEventID;
60 #ifdef PORTABLE_NATIVE_SYNC
65 * Call gtk_init. It is very important that this happen before any other
69 JNIEXPORT void JNICALL
70 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
74 char *homedir, *rcpath = NULL;
75 /* jclass gtkgenericpeer; */
76 jclass gtkcomponentpeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer,
77 gtkmenuitempeer, gtktextcomponentpeer;
79 NSA_INIT (env, clazz);
81 /* GTK requires a program's argc and argv variables, and requires that they
84 argv = (char **) malloc (sizeof (char *) * 2);
88 /* until we have JDK 1.2 JNI, assume we have a VM with threads that
89 match what GLIB was compiled for */
90 #ifdef PORTABLE_NATIVE_SYNC
91 (*env)->GetJavaVM( env, &gdk_vm );
92 g_thread_init ( &g_thread_jni_functions );
93 printf("called gthread init\n");
95 g_thread_init ( NULL );
98 /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
101 gtk_init (&argc, &argv);
104 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
105 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
107 /* Make sure queued calls don't get sent to GTK/GDK while
108 we're shutting down. */
109 atexit (gdk_threads_enter);
112 gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL);
114 if ((homedir = getenv ("HOME")))
116 rcpath = (char *) malloc (strlen (homedir) + strlen (RC_FILE) + 2);
117 sprintf (rcpath, "%s/%s", homedir, RC_FILE);
120 gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);
127 /* setup cached IDs for posting GTK events to Java */
128 /* gtkgenericpeer = (*env)->FindClass (env, */
129 /* "gnu/java/awt/peer/gtk/GtkGenericPeer"); */
130 gtkcomponentpeer = (*env)->FindClass (env,
131 "gnu/java/awt/peer/gtk/GtkComponentPeer");
132 gtkwindowpeer = (*env)->FindClass (env,
133 "gnu/java/awt/peer/gtk/GtkWindowPeer");
134 gtkscrollbarpeer = (*env)->FindClass (env,
135 "gnu/java/awt/peer/gtk/GtkScrollbarPeer");
136 gtklistpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkListPeer");
137 gtkmenuitempeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkMenuItemPeer");
138 gtktextcomponentpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkTextComponentPeer");
139 /* gdkColor = (*env)->FindClass (env, */
140 /* "gnu/java/awt/peer/gtk/GdkColor"); */
141 /* gdkColorID = (*env)->GetMethodID (env, gdkColor, "<init>", "(III)V"); */
142 /* postActionEventID = (*env)->GetMethodID (env, gtkgenericpeer, */
143 /* "postActionEvent", */
144 /* "(Ljava/lang/String;I)V"); */
146 postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer,
147 "postMenuActionEvent",
149 postMouseEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
150 "postMouseEvent", "(IJIIIIZ)V");
151 postConfigureEventID = (*env)->GetMethodID (env, gtkwindowpeer,
152 "postConfigureEvent", "(IIIIIIII)V");
153 postExposeEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
154 "postExposeEvent", "(IIII)V");
155 postKeyEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
156 "postKeyEvent", "(IJIIC)V");
157 postFocusEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
158 "postFocusEvent", "(IZ)V");
159 postAdjustmentEventID = (*env)->GetMethodID (env, gtkscrollbarpeer,
160 "postAdjustmentEvent",
162 postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
164 "(Ljava/lang/Object;I)V");
165 postListItemEventID = (*env)->GetMethodID (env, gtklistpeer,
168 postTextEventID = (*env)->GetMethodID (env, gtktextcomponentpeer,
174 * Run gtk_main and block.
176 JNIEXPORT void JNICALL
177 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain (JNIEnv *env, jobject obj)
179 gdk_threads_enter ();
181 gdk_threads_leave ();