OSDN Git Service

2006-08-14 Mark Wielaard <mark@klomp.org>
[pf3gnuchains/gcc-fork.git] / libjava / classpath / native / 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., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301 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 /* Does not require locking: meant to be called after the drawing
51    surface is locked. */
52 Display*
53 classpath_jawt_get_default_display (JNIEnv* env, jobject canvas)
54 {
55   GdkDisplay *display;
56   Display *xdisplay;
57   GtkWidget *widget;
58   void *ptr;
59   jobject peer;
60   jclass class_id;
61   jmethodID method_id;
62
63   /* retrieve peer object */
64   class_id = (*env)->GetObjectClass (env, canvas);
65
66   method_id = (*env)->GetMethodID (env, class_id,
67                                    "getPeer",
68                                    "()Ljava/awt/peer/ComponentPeer;");
69
70   peer = (*env)->CallObjectMethod (env, canvas, method_id);
71
72   ptr = NSA_GET_PTR (env, peer);
73
74   widget = GTK_WIDGET (ptr);
75
76   if (GTK_WIDGET_REALIZED (widget))
77     {
78       display = gtk_widget_get_display (widget);
79
80       xdisplay = GDK_DISPLAY_XDISPLAY (display);
81
82       return xdisplay;
83     }
84   else
85     return NULL;
86 }
87
88 /* Does not require locking: meant to be called after the drawing
89    surface is locked. */
90 VisualID
91 classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
92 {
93   GtkWidget *widget;
94   Visual *visual;
95   void *ptr;
96   jobject peer;
97   jclass class_id;
98   jmethodID method_id;
99
100   class_id = (*env)->GetObjectClass (env, canvas);
101
102   method_id = (*env)->GetMethodID (env, class_id,
103                                    "getPeer",
104                                    "()Ljava/awt/peer/ComponentPeer;");
105
106   peer = (*env)->CallObjectMethod (env, canvas, method_id);
107
108   ptr = NSA_GET_PTR (env, peer);
109
110   widget = GTK_WIDGET (ptr);
111
112   if (GTK_WIDGET_REALIZED (widget))
113     {
114       visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
115       g_assert (visual != NULL);
116
117       return visual->visualid;
118     }
119   else
120     return (VisualID) NULL;
121 }
122
123 /* Does not require locking: meant to be called after the drawing
124    surface is locked. */
125 Drawable
126 classpath_jawt_get_drawable (JNIEnv* env, jobject canvas)
127 {
128   GtkWidget *widget;
129   int drawable;
130   void *ptr;
131   jobject peer;
132   jclass class_id;
133   jmethodID method_id;
134
135   class_id = (*env)->GetObjectClass (env, canvas);
136
137   method_id = (*env)->GetMethodID (env, class_id,
138                                    "getPeer",
139                                    "()Ljava/awt/peer/ComponentPeer;");
140
141   peer = (*env)->CallObjectMethod (env, canvas, method_id);
142
143   ptr = NSA_GET_PTR (env, peer);
144
145   widget = GTK_WIDGET (ptr);
146
147   if (GTK_WIDGET_REALIZED (widget))
148     {
149       drawable = GDK_DRAWABLE_XID (widget->window);
150
151       return drawable;
152     }
153   else
154     return (Drawable) NULL;
155 }
156
157 jint
158 classpath_jawt_lock ()
159 {
160   gdk_threads_enter ();
161   return 0;
162 }
163
164 void
165 classpath_jawt_unlock ()
166 {
167   gdk_threads_leave ();
168 }