OSDN Git Service

* gnu/java/awt/peer/gtk/GtkTextComponentPeer.java
[pf3gnuchains/gcc-fork.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMainThread.c
1 /* gtkmainthread.c -- Native implementation of GtkMainThread
2    Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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.
20
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.
25
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. */
37
38
39 #include "gtkpeer.h"
40 #include "gnu_java_awt_peer_gtk_GtkMainThread.h"
41 #include "gthread-jni.h"
42
43 #ifdef JVM_SUN
44   struct state_table *native_state_table;
45 #endif
46
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;
58 JNIEnv *gdk_env;
59
60 #ifdef PORTABLE_NATIVE_SYNC
61 JavaVM *gdk_vm;
62 #endif
63
64 /*
65  * Call gtk_init.  It is very important that this happen before any other
66  * gtk calls.
67  */
68
69 JNIEXPORT void JNICALL 
70 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz)
71 {
72   int argc = 1;
73   char **argv;
74   char *homedir, *rcpath = NULL;
75 /*    jclass gtkgenericpeer; */
76   jclass gtkcomponentpeer, gtkwindowpeer, gtkscrollbarpeer, gtklistpeer,
77     gtkmenuitempeer, gtktextcomponentpeer;
78
79   NSA_INIT (env, clazz);
80
81   /* GTK requires a program's argc and argv variables, and requires that they
82      be valid.  */
83
84   argv = (char **) malloc (sizeof (char *) * 2);
85   argv[0] = "";
86   argv[1] = NULL;
87
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");
94 #else
95   g_thread_init ( NULL );
96 #endif
97
98   /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
99   gdk_threads_init();
100
101   gtk_init (&argc, &argv);
102
103   gdk_rgb_init ();
104   gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
105   gtk_widget_set_default_visual (gdk_rgb_get_visual ());
106
107   /* Make sure queued calls don't get sent to GTK/GDK while 
108      we're shutting down. */
109   atexit (gdk_threads_enter);
110
111   gdk_env = env;
112   gdk_event_handler_set ((GdkEventFunc)awt_event_handler, NULL, NULL);
113
114   if ((homedir = getenv ("HOME")))
115     {
116       rcpath = (char *) malloc (strlen (homedir) + strlen (RC_FILE) + 2);
117       sprintf (rcpath, "%s/%s", homedir, RC_FILE);
118     }
119   
120   gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);
121
122   if (rcpath)
123     free (rcpath);
124
125   free (argv);
126
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"); */
145
146   postMenuActionEventID = (*env)->GetMethodID (env, gtkmenuitempeer,
147                                                "postMenuActionEvent",
148                                                "()V");
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", 
161                                                "(II)V");
162   postItemEventID = (*env)->GetMethodID (env, gtkcomponentpeer,
163                                          "postItemEvent", 
164                                          "(Ljava/lang/Object;I)V");
165   postListItemEventID = (*env)->GetMethodID (env, gtklistpeer,
166                                              "postItemEvent",
167                                              "(II)V");
168   postTextEventID = (*env)->GetMethodID (env, gtktextcomponentpeer,
169                                              "postTextEvent",
170                                              "()V");
171 }
172
173 /*
174  * Run gtk_main and block.
175  */ 
176 JNIEXPORT void JNICALL 
177 Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain (JNIEnv *env, jobject obj)
178 {
179   gdk_threads_enter ();
180   gtk_main ();
181   gdk_threads_leave ();
182 }