2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMainThread.c
blobbad4a5168844cb8727f5adc7bc9c228f9cd2806a
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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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. */
39 #include "gtkpeer.h"
40 #include "gnu_java_awt_peer_gtk_GtkMainThread.h"
41 #include "gthread-jni.h"
43 #ifdef JVM_SUN
44 struct state_table *native_state_table;
45 struct state_table *native_global_ref_table;
46 #endif
48 jmethodID setBoundsCallbackID;
50 jmethodID postActionEventID;
51 jmethodID postMenuActionEventID;
52 jmethodID postMouseEventID;
53 jmethodID postConfigureEventID;
54 jmethodID postExposeEventID;
55 jmethodID postKeyEventID;
56 jmethodID postFocusEventID;
57 jmethodID postAdjustmentEventID;
58 jmethodID postItemEventID;
59 jmethodID choicePostItemEventID;
60 jmethodID postListItemEventID;
61 jmethodID postTextEventID;
62 jmethodID postWindowEventID;
64 JNIEnv *gdk_env;
66 #ifdef PORTABLE_NATIVE_SYNC
67 JavaVM *gdk_vm;
68 #endif
70 GtkWindowGroup *global_gtk_window_group;
73 * Call gtk_init. It is very important that this happen before any other
74 * gtk calls.
77 JNIEXPORT void JNICALL
78 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
80 int argc = 1;
81 char **argv;
82 char *homedir, *rcpath = NULL;
83 /* jclass gtkgenericpeer; */
84 jclass gtkcomponentpeer, gtkchoicepeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer,
85 gtkmenuitempeer, gtktextcomponentpeer, window;
87 NSA_INIT (env, clazz);
89 /* GTK requires a program's argc and argv variables, and requires that they
90 be valid. */
92 argv = (char **) malloc (sizeof (char *) * 2);
93 argv[0] = "";
94 argv[1] = NULL;
96 /* until we have JDK 1.2 JNI, assume we have a VM with threads that
97 match what GLIB was compiled for */
98 #ifdef PORTABLE_NATIVE_SYNC
99 (*env)->GetJavaVM( env, &gdk_vm );
100 g_thread_init ( &g_thread_jni_functions );
101 printf("called gthread init\n");
102 #else
103 g_thread_init ( NULL );
104 #endif
106 /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
107 gdk_threads_init();
109 gtk_init (&argc, &argv);
111 gdk_rgb_init ();
112 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
113 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
115 /* Make sure queued calls don't get sent to GTK/GDK while
116 we're shutting down. */
117 atexit (gdk_threads_enter);
119 gdk_env = env;
120 gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL);
122 if ((homedir = getenv ("HOME")))
124 rcpath = (char *) malloc (strlen (homedir) + strlen (RC_FILE) + 2);
125 sprintf (rcpath, "%s/%s", homedir, RC_FILE);
128 gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);
130 if (rcpath)
131 free (rcpath);
133 free (argv);
135 /* setup cached IDs for posting GTK events to Java */
136 /* gtkgenericpeer = (*env)->FindClass (env, */
137 /* "gnu/java/awt/peer/gtk/GtkGenericPeer"); */
139 window = (*env)->FindClass (env, "java/awt/Window");
141 gtkcomponentpeer = (*env)->FindClass (env,
142 "gnu/java/awt/peer/gtk/GtkComponentPeer");
143 gtkchoicepeer = (*env)->FindClass (env,
144 "gnu/java/awt/peer/gtk/GtkChoicePeer");
145 gtkwindowpeer = (*env)->FindClass (env,
146 "gnu/java/awt/peer/gtk/GtkWindowPeer");
147 gtkscrollbarpeer = (*env)->FindClass (env,
148 "gnu/java/awt/peer/gtk/GtkScrollbarPeer");
149 gtklistpeer = (*env)->FindClass (env, "gnu/java/awt/peer/gtk/GtkListPeer");
150 gtkmenuitempeer = (*env)->FindClass (env,
151 "gnu/java/awt/peer/gtk/GtkMenuItemPeer");
152 gtktextcomponentpeer = (*env)->FindClass (env,
153 "gnu/java/awt/peer/gtk/GtkTextComponentPeer");
154 /* gdkColor = (*env)->FindClass (env, */
155 /* "gnu/java/awt/peer/gtk/GdkColor"); */
156 /* gdkColorID = (*env)->GetMethodID (env, gdkColor, "<init>", "(III)V"); */
157 /* postActionEventID = (*env)->GetMethodID (env, gtkgenericpeer, */
158 /* "postActionEvent", */
159 /* "(Ljava/lang/String;I)V"); */
161 setBoundsCallbackID = (*env)->GetMethodID (env, window,
162 "setBoundsCallback",
163 "(IIII)V");
165 postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer,
166 "postMenuActionEvent",
167 "()V");
168 postMouseEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
169 "postMouseEvent", "(IJIIIIZ)V");
170 postConfigureEventID = (*env)->GetMethodID (env, gtkwindowpeer,
171 "postConfigureEvent", "(IIIIIIII)V");
172 postWindowEventID = (*env)->GetMethodID (env, gtkwindowpeer,
173 "postWindowEvent",
174 "(ILjava/awt/Window;I)V");
175 postExposeEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
176 "postExposeEvent", "(IIII)V");
177 postKeyEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
178 "postKeyEvent", "(IJIICI)V");
179 postFocusEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
180 "postFocusEvent", "(IZ)V");
181 postAdjustmentEventID = (*env)->GetMethodID (env, gtkscrollbarpeer,
182 "postAdjustmentEvent",
183 "(II)V");
184 postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
185 "postItemEvent",
186 "(Ljava/lang/Object;I)V");
187 choicePostItemEventID = (*env)->GetMethodID (env, gtkchoicepeer,
188 "choicePostItemEvent",
189 "(Ljava/lang/String;I)V");
190 postListItemEventID = (*env)->GetMethodID (env, gtklistpeer,
191 "postItemEvent",
192 "(II)V");
193 postTextEventID = (*env)->GetMethodID (env, gtktextcomponentpeer,
194 "postTextEvent",
195 "()V");
196 global_gtk_window_group = gtk_window_group_new ();
200 * Run gtk_main and block.
202 JNIEXPORT void JNICALL
203 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain
204 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
206 gdk_threads_enter ();
207 gtk_main ();
208 gdk_threads_leave ();