OSDN Git Service

2005-05-18 Anthony Green <green@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / jni / gtk-peer / gtk_jawt.c
1 /* gtk_jawt.c -- GTK implementation of classpath_jawt.h
2    Copyright (C) 2005 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 <gtk/gtk.h>
41 #include <gdk/gdkx.h>
42 #include "classpath_jawt.h"
43
44 jint
45 classpath_jawt_get_awt_version ()
46 {
47   return CLASSPATH_JAWT_VERSION;
48 }
49
50 Display*
51 classpath_jawt_get_default_display (JNIEnv* env, jobject canvas)
52 {
53   GdkDisplay *display;
54   Display *xdisplay;
55   GtkWidget *widget;
56   void *ptr;
57   jobject peer;
58   jclass class_id;
59   jmethodID method_id;
60
61   /* retrieve peer object */
62   class_id = (*env)->GetObjectClass (env, canvas);
63
64   method_id = (*env)->GetMethodID (env, class_id,
65                                    "getPeer",
66                                    "()Ljava/awt/peer/ComponentPeer;");
67
68   peer = (*env)->CallObjectMethod (env, canvas, method_id);
69
70   ptr = NSA_GET_PTR (env, peer);
71
72   gdk_threads_enter ();
73
74   widget = GTK_WIDGET (ptr);
75
76   /* widget should be realized before Canvas.paint is called. */
77   g_assert (GTK_WIDGET_REALIZED (widget));
78
79   display = gtk_widget_get_display (widget);
80
81   xdisplay = GDK_DISPLAY_XDISPLAY (display);
82
83   gdk_threads_leave ();
84
85   return xdisplay;
86 }
87
88 VisualID
89 classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
90 {
91   GtkWidget *widget;
92   Visual *visual;
93   void *ptr;
94   jobject peer;
95   jclass class_id;
96   jmethodID method_id;
97
98   class_id = (*env)->GetObjectClass (env, canvas);
99
100   method_id = (*env)->GetMethodID (env, class_id,
101                                    "getPeer",
102                                    "()Ljava/awt/peer/ComponentPeer;");
103
104   peer = (*env)->CallObjectMethod (env, canvas, method_id);
105
106   ptr = NSA_GET_PTR (env, peer);
107
108   gdk_threads_enter ();
109
110   widget = GTK_WIDGET (ptr);
111
112   g_assert (GTK_WIDGET_REALIZED (widget));
113
114   visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
115   g_assert (visual != NULL);
116
117   gdk_threads_leave ();
118
119   return visual->visualid;
120 }
121
122 Drawable
123 classpath_jawt_get_drawable (JNIEnv* env, jobject canvas)
124 {
125   GtkWidget *widget;
126   int drawable;
127   void *ptr;
128   jobject peer;
129   jclass class_id;
130   jmethodID method_id;
131
132   class_id = (*env)->GetObjectClass (env, canvas);
133
134   method_id = (*env)->GetMethodID (env, class_id,
135                                    "getPeer",
136                                    "()Ljava/awt/peer/ComponentPeer;");
137
138   peer = (*env)->CallObjectMethod (env, canvas, method_id);
139
140   ptr = NSA_GET_PTR (env, peer);
141
142   gdk_threads_enter ();
143
144   widget = GTK_WIDGET (ptr);
145
146   g_assert (GTK_WIDGET_REALIZED (widget));
147
148   drawable = GDK_DRAWABLE_XID (widget->window);
149
150   gdk_threads_leave ();
151
152   return drawable;
153 }
154
155 jint
156 classpath_jawt_object_lock (jobject lock)
157 {
158   JNIEnv *env = gdk_env();
159   (*env)->MonitorEnter (env, lock);
160   return 0;
161 }
162
163 void
164 classpath_jawt_object_unlock (jobject lock)
165 {
166   JNIEnv *env = gdk_env();
167   (*env)->MonitorExit (env, lock);
168 }
169
170 jint
171 classpath_jawt_lock ()
172 {
173   gdk_threads_enter ();
174   return 0;
175 }
176
177 void
178 classpath_jawt_unlock ()
179 {
180   gdk_threads_leave ();
181 }
182
183 jobject
184 classpath_jawt_create_lock ()
185 {
186   JNIEnv *env = gdk_env ();
187   jobject lock = (*env)->NewStringUTF (env, "jawt-lock");
188   NSA_SET_GLOBAL_REF (env, lock);
189   return lock;
190 }
191
192 void
193 classpath_jawt_destroy_lock (jobject lock)
194 {
195   JNIEnv *env = gdk_env ();
196   NSA_DEL_GLOBAL_REF (env, lock);
197 }