* treelang.texi: Fix a typo.
[official-gcc.git] / libjava / jawt.c
blob08cd78cd581d54074a27997ffb8df18098cf3acc
1 /* jawt.c -- X11 implementation of the AWT Native Interface
2 Copyright (C) 2005 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 <jni.h>
40 #include <jawt.h>
41 #include <jawt_md.h>
42 #include "classpath_jawt.h"
44 static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
45 static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
46 static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo)
47 (JAWT_DrawingSurface* surface);
48 static void (JNICALL _Jv_FreeDrawingSurfaceInfo)
49 (JAWT_DrawingSurfaceInfo* surface_info);
50 static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env,
51 jobject canvas);
52 static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface);
54 JNIEXPORT jboolean JNICALL
55 JAWT_GetAWT (JNIEnv* env, JAWT* awt)
57 jint retrieved_version;
59 retrieved_version = classpath_jawt_get_awt_version ();
61 if (awt->version > retrieved_version)
62 return JNI_FALSE;
64 awt->GetDrawingSurface = _Jv_GetDrawingSurface;
65 awt->FreeDrawingSurface = _Jv_FreeDrawingSurface;
67 return JNI_TRUE;
70 /* JAWT_DrawingSurface functions */
72 static jint
73 (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface)
75 /* lock the drawing surface */
76 return classpath_jawt_lock ();
79 static void
80 (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface)
82 classpath_jawt_unlock ();
85 static JAWT_DrawingSurfaceInfo*
86 (JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface)
88 if (surface == NULL)
89 return NULL;
91 return surface->surface_info;
94 static void
95 (JNICALL _Jv_FreeDrawingSurfaceInfo) (JAWT_DrawingSurfaceInfo* surface_info)
97 JAWT_X11DrawingSurfaceInfo* surface_info_x11;
99 if (surface_info == NULL)
100 return;
102 surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
104 surface_info_x11->display = NULL;
105 surface_info_x11->drawable = 0;
107 free (surface_info);
108 surface_info = NULL;
111 /* JAWT functions */
113 static JAWT_DrawingSurface*
114 (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas)
116 JAWT_DrawingSurface* surface;
117 JAWT_X11DrawingSurfaceInfo* surface_info_x11;
119 surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface));
121 if (surface == NULL)
122 return NULL;
124 /* initialize function pointers */
125 surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo;
126 surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo;
128 surface->Lock = _Jv_Lock;
129 surface->Unlock = _Jv_Unlock;
131 surface->surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo));
133 if (surface->surface_info == NULL)
134 return NULL;
136 surface->surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo));
138 if (surface->surface_info->platformInfo == NULL)
139 return NULL;
141 surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface->surface_info->platformInfo;
143 surface_info_x11->display = classpath_jawt_get_default_display (env, canvas);
144 surface_info_x11->drawable = classpath_jawt_get_drawable (env, canvas);
146 /* FIXME: also include bounding rectangle of drawing surface */
147 /* FIXME: also include current clipping region */
149 return surface;
152 static void
153 (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
155 free (surface);