2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkButtonPeer.c
blobe16b2d457d679bab11009c8927c9dcf97275691e
1 /* gtkbuttonpeer.c -- Native implementation of GtkButtonPeer
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_GtkComponentPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkButtonPeer.h"
43 JNIEXPORT void JNICALL
44 Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create
45 (JNIEnv *env, jobject obj)
47 GtkWidget *button;
49 /* Create global reference and save it for future use */
50 NSA_SET_GLOBAL_REF (env, obj);
52 gdk_threads_enter ();
54 button = gtk_button_new();
55 gtk_widget_show (button);
57 gdk_threads_leave ();
59 NSA_SET_PTR (env, obj, button);
62 JNIEXPORT void JNICALL
63 Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectJObject
64 (JNIEnv *env, jobject obj)
66 void *ptr;
68 ptr = NSA_GET_PTR (env, obj);
70 gdk_threads_enter ();
72 gtk_widget_realize (GTK_WIDGET (ptr));
74 connect_awt_hook (env, obj, 1, GTK_BUTTON(ptr)->event_window);
76 gdk_threads_leave ();
79 JNIEXPORT void JNICALL
80 Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals
81 (JNIEnv *env, jobject obj)
83 /* FIXME: Do we need to connect any signals here? Otherwise just do not
84 override parent method. */
86 /* Connect the superclass signals. */
87 Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj);
90 JNIEXPORT void JNICALL
91 Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetFont
92 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
94 const char *font_name;
95 void *ptr;
96 GtkWidget *button;
97 GtkWidget *label;
98 PangoFontDescription *font_desc;
100 ptr = NSA_GET_PTR (env, obj);
102 button = GTK_WIDGET (ptr);
103 label = gtk_bin_get_child (GTK_BIN(button));
105 if (!label)
106 return;
108 font_name = (*env)->GetStringUTFChars (env, name, NULL);
110 gdk_threads_enter();
112 font_desc = pango_font_description_from_string (font_name);
113 pango_font_description_set_size (font_desc, size * PANGO_SCALE);
115 if (style & AWT_STYLE_BOLD)
116 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
118 if (style & AWT_STYLE_ITALIC)
119 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
121 gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
123 pango_font_description_free (font_desc);
125 gdk_threads_leave();
127 (*env)->ReleaseStringUTFChars (env, name, font_name);
130 JNIEXPORT void JNICALL
131 Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetForeground
132 (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
134 GdkColor color;
135 GtkWidget *label;
136 void *ptr;
138 ptr = NSA_GET_PTR (env, obj);
140 color.red = (red / 255.0) * 65535;
141 color.green = (green / 255.0) * 65535;
142 color.blue = (blue / 255.0) * 65535;
144 gdk_threads_enter ();
146 label = gtk_bin_get_child (GTK_BIN(ptr));
148 if (!label)
149 return;
151 gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color);
152 gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, &color);
153 gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color);
155 gdk_threads_leave ();