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 setBoundsCallbackID;
49 jmethodID postActionEventID;
50 jmethodID postMenuActionEventID;
51 jmethodID postMouseEventID;
52 jmethodID postConfigureEventID;
53 jmethodID postExposeEventID;
54 jmethodID postKeyEventID;
55 jmethodID postFocusEventID;
56 jmethodID postAdjustmentEventID;
57 jmethodID postItemEventID;
58 jmethodID postListItemEventID;
59 jmethodID postTextEventID;
62 #ifdef PORTABLE_NATIVE_SYNC
67 * Call gtk_init. It is very important that this happen before any other
71 JNIEXPORT void JNICALL
72 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
76 char *homedir, *rcpath = NULL;
77 /* jclass gtkgenericpeer; */
78 jclass gtkcomponentpeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer,
79 gtkmenuitempeer, gtktextcomponentpeer, window;
81 NSA_INIT (env, clazz);
83 /* GTK requires a program's argc and argv variables, and requires that they
86 argv = (char **) malloc (sizeof (char *) * 2);
90 /* until we have JDK 1.2 JNI, assume we have a VM with threads that
91 match what GLIB was compiled for */
92 #ifdef PORTABLE_NATIVE_SYNC
93 (*env)->GetJavaVM( env, &gdk_vm );
94 g_thread_init ( &g_thread_jni_functions );
95 printf("called gthread init\n");
97 g_thread_init ( NULL );
100 /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
103 gtk_init (&argc, &argv);
106 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
107 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
109 /* Make sure queued calls don't get sent to GTK/GDK while
110 we're shutting down. */
111 atexit (gdk_threads_enter);
114 gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL);
116 if ((homedir = getenv ("HOME")))
118 rcpath = (char *) malloc (strlen (homedir) + strlen (RC_FILE) + 2);
119 sprintf (rcpath, "%s/%s", homedir, RC_FILE);
122 gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);
129 /* setup cached IDs for posting GTK events to Java */
130 /* gtkgenericpeer = (*env)->FindClass (env, */
131 /* "gnu/java/awt/peer/gtk/GtkGenericPeer"); */
133 window = (*env)->FindClass (env, "java/awt/Window");
135 gtkcomponentpeer = (*env)->FindClass (env,
136 "gnu/java/awt/peer/gtk/GtkComponentPeer");
137 gtkwindowpeer = (*env)->FindClass (env,
138 "gnu/java/awt/peer/gtk/GtkWindowPeer");
139 gtkscrollbarpeer = (*env)->FindClass (env,
140 "gnu/java/awt/peer/gtk/GtkScrollbarPeer");
141 gtklistpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkListPeer");
142 gtkmenuitempeer = (*env)->FindClass (env,
143 "gnu/java/awt/peer/gtk/GtkMenuItemPeer");
144 gtktextcomponentpeer = (*env)->FindClass (env,
145 "gnu/java/awt/peer/gtk/GtkTextComponentPeer");
146 /* gdkColor = (*env)->FindClass (env, */
147 /* "gnu/java/awt/peer/gtk/GdkColor"); */
148 /* gdkColorID = (*env)->GetMethodID (env, gdkColor, "<init>", "(III)V"); */
149 /* postActionEventID = (*env)->GetMethodID (env, gtkgenericpeer, */
150 /* "postActionEvent", */
151 /* "(Ljava/lang/String;I)V"); */
153 setBoundsCallbackID = (*env)->GetMethodID (env, window,
157 postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer,
158 "postMenuActionEvent",
160 postMouseEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
161 "postMouseEvent", "(IJIIIIZ)V");
162 postConfigureEventID = (*env)->GetMethodID (env, gtkwindowpeer,
163 "postConfigureEvent", "(IIIIIIII)V");
164 postExposeEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
165 "postExposeEvent", "(IIII)V");
166 postKeyEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
167 "postKeyEvent", "(IJIICI)V");
168 postFocusEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
169 "postFocusEvent", "(IZ)V");
170 postAdjustmentEventID = (*env)->GetMethodID (env, gtkscrollbarpeer,
171 "postAdjustmentEvent",
173 postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
175 "(Ljava/lang/Object;I)V");
176 postListItemEventID = (*env)->GetMethodID (env, gtklistpeer,
179 postTextEventID = (*env)->GetMethodID (env, gtktextcomponentpeer,
185 * Run gtk_main and block.
187 JNIEXPORT void JNICALL
188 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain (JNIEnv *env, jobject obj)
190 gdk_threads_enter ();
192 gdk_threads_leave ();