Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMenuItemPeer.c
blob1fe18f9f0646880a62836009a9e4ad93c000001d
1 /* gtkmenuitempeer.c -- Native implementation of GtkMenuItemPeer
2 Copyright (C) 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_GtkMenuItemPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
43 static void item_activate (GtkMenuItem *item __attribute__((unused)),
44 jobject peer_obj);
46 JNIEXPORT void JNICALL
47 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create
48 (JNIEnv *env, jobject obj, jstring label)
50 GtkWidget *widget;
51 const char *str;
53 NSA_SET_GLOBAL_REF (env, obj);
55 str = (*env)->GetStringUTFChars (env, label, NULL);
57 gdk_threads_enter ();
59 /* "-" signals that we need a separator. */
60 if (strcmp (str, "-") == 0)
61 widget = gtk_menu_item_new ();
62 else
63 widget = gtk_menu_item_new_with_label (str);
65 gtk_widget_show (widget);
67 gdk_threads_leave ();
69 (*env)->ReleaseStringUTFChars (env, label, str);
71 NSA_SET_PTR (env, obj, widget);
74 JNIEXPORT void JNICALL
75 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals
76 (JNIEnv *env, jobject obj)
78 void *ptr = NSA_GET_PTR (env, obj);
79 jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
80 g_assert (gref);
82 gdk_threads_enter ();
84 g_signal_connect (G_OBJECT (ptr), "activate",
85 G_CALLBACK (item_activate), *gref);
87 gdk_threads_leave ();
90 JNIEXPORT void JNICALL
91 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_gtkWidgetModifyFont
92 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
94 const char *font_name;
95 void *ptr;
96 GtkWidget *label;
97 PangoFontDescription *font_desc;
99 ptr = NSA_GET_PTR (env, obj);
101 font_name = (*env)->GetStringUTFChars (env, name, NULL);
103 gdk_threads_enter();
105 label = gtk_bin_get_child (GTK_BIN (ptr));
107 if (label)
109 font_desc = pango_font_description_from_string (font_name);
110 pango_font_description_set_size (font_desc, size * dpi_conversion_factor);
112 if (style & AWT_STYLE_BOLD)
113 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
115 if (style & AWT_STYLE_ITALIC)
116 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
118 gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
120 pango_font_description_free (font_desc);
123 gdk_threads_leave();
125 (*env)->ReleaseStringUTFChars (env, name, font_name);
128 JNIEXPORT void JNICALL
129 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setEnabled
130 (JNIEnv *env, jobject obj, jboolean enabled)
132 void *ptr;
134 ptr = NSA_GET_PTR (env, obj);
136 gdk_threads_enter ();
137 gtk_widget_set_sensitive (GTK_WIDGET (ptr), enabled);
138 gdk_threads_leave ();
141 JNIEXPORT void JNICALL
142 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel
143 (JNIEnv *env, jobject obj, jstring label)
145 void *ptr;
146 const char *str;
147 GtkAccelLabel *accel_label;
149 ptr = NSA_GET_PTR (env, obj);
151 str = (*env)->GetStringUTFChars (env, label, NULL);
153 gdk_threads_enter ();
155 accel_label = GTK_ACCEL_LABEL (GTK_BIN (ptr)->child);
157 gtk_label_set_text (GTK_LABEL (accel_label), str);
158 gtk_accel_label_refetch (accel_label);
160 gdk_threads_leave ();
162 (*env)->ReleaseStringUTFChars (env, label, str);
165 static void
166 item_activate (GtkMenuItem *item __attribute__((unused)), jobject peer_obj)
168 (*gdk_env())->CallVoidMethod (gdk_env(), peer_obj,
169 postMenuActionEventID);