This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkToolkit.c
blob6234b29c9134bbf4874e03c8ce540d5f8a3149a0
1 /* gtktoolkit.c -- Native portion of GtkToolkit
2 Copyright (C) 1998, 1999 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_GtkToolkit.h"
42 static jint gdk_color_to_java_color (GdkColor color);
44 JNIEXPORT void JNICALL
45 Java_gnu_java_awt_peer_gtk_GtkToolkit_beep
46 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
48 gdk_threads_enter ();
49 gdk_beep ();
50 gdk_threads_leave ();
53 JNIEXPORT void JNICALL
54 Java_gnu_java_awt_peer_gtk_GtkToolkit_sync
55 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
57 gdk_threads_enter ();
58 gdk_flush ();
59 gdk_threads_leave ();
62 JNIEXPORT void JNICALL
63 Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions
64 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
65 jintArray jdims)
67 jint *dims = (*env)->GetIntArrayElements (env, jdims, 0);
69 gdk_threads_enter ();
71 dims[0] = gdk_screen_width ();
72 dims[1] = gdk_screen_height ();
74 gdk_threads_leave ();
76 (*env)->ReleaseIntArrayElements(env, jdims, dims, 0);
79 JNIEXPORT jint JNICALL
80 Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution
81 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
83 jint res;
85 gdk_threads_enter ();
87 res = gdk_screen_width () / (gdk_screen_width_mm () / 25.4);
89 gdk_threads_leave ();
90 return res;
93 #define CONVERT(type, state) \
94 gdk_color_to_java_color (style->type[GTK_STATE_ ## state])
96 JNIEXPORT void JNICALL
97 Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors
98 (JNIEnv *env, jobject obj __attribute__((unused)),
99 jintArray jcolors)
101 jint *colors;
102 GtkStyle *style;
104 colors = (*env)->GetIntArrayElements (env, jcolors, 0);
106 gdk_threads_enter ();
108 style = gtk_widget_get_default_style ();
110 colors[AWT_DESKTOP] = CONVERT (bg, SELECTED);
111 colors[AWT_ACTIVE_CAPTION] = CONVERT (bg, SELECTED);
112 colors[AWT_ACTIVE_CAPTION_TEXT] = CONVERT (text, SELECTED);
113 colors[AWT_ACTIVE_CAPTION_BORDER] = CONVERT (fg, NORMAL);
114 colors[AWT_INACTIVE_CAPTION] = CONVERT (base, INSENSITIVE);
115 colors[AWT_INACTIVE_CAPTION_TEXT] = CONVERT (fg, INSENSITIVE);
116 colors[AWT_INACTIVE_CAPTION_BORDER] = CONVERT (fg, INSENSITIVE);
117 colors[AWT_WINDOW] = CONVERT (bg, NORMAL);
118 colors[AWT_WINDOW_BORDER] = CONVERT (fg, NORMAL);
119 colors[AWT_WINDOW_TEXT] = CONVERT (fg, NORMAL);
120 colors[AWT_MENU] = CONVERT (bg, NORMAL);
121 colors[AWT_MENU_TEXT] = CONVERT (fg, NORMAL);
122 colors[AWT_TEXT] = CONVERT (bg, NORMAL);
123 colors[AWT_TEXT_TEXT] = CONVERT (fg, NORMAL);
124 colors[AWT_TEXT_HIGHLIGHT] = CONVERT (bg, SELECTED);
125 colors[AWT_TEXT_HIGHLIGHT_TEXT] = CONVERT (fg, SELECTED);
126 colors[AWT_TEXT_INACTIVE_TEXT] = CONVERT (bg, INSENSITIVE);
127 colors[AWT_CONTROL] = CONVERT (bg, NORMAL);
128 colors[AWT_CONTROL_TEXT] = CONVERT (fg, NORMAL);
129 colors[AWT_CONTROL_HIGHLIGHT] = CONVERT (base, ACTIVE);
130 colors[AWT_CONTROL_LT_HIGHLIGHT] = CONVERT (bg, PRELIGHT);
131 colors[AWT_CONTROL_SHADOW] = CONVERT (bg, ACTIVE);
132 colors[AWT_CONTROL_DK_SHADOW] = CONVERT (fg, INSENSITIVE);
133 colors[AWT_SCROLLBAR] = CONVERT (base, INSENSITIVE);
134 colors[AWT_INFO] = CONVERT (bg, NORMAL);
135 colors[AWT_INFO_TEXT] = CONVERT (fg, NORMAL);
137 gdk_threads_leave ();
139 (*env)->ReleaseIntArrayElements(env, jcolors, colors, 0);
142 #undef CONVERT
144 static jint
145 gdk_color_to_java_color (GdkColor gdk_color)
147 guchar red;
148 guchar green;
149 guchar blue;
150 float factor;
152 factor = 255.0 / 65535.0;
154 red = (float) gdk_color.red * factor;
155 green = (float) gdk_color.green * factor;
156 blue = (float) gdk_color.blue * factor;
158 return (jint) (0xff000000 | (red << 16) | (green << 8) | blue);