Merged with mainline at revision 128810.
[official-gcc.git] / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMenuItemPeer.c
blob965435545807ab726c3dd4e93ffbaa1410f75822
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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 jmethodID postMenuActionEventID;
45 void
46 cp_gtk_menuitem_init_jni (void)
48 jclass gtkmenuitempeer;
50 gtkmenuitempeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
51 "gnu/java/awt/peer/gtk/GtkMenuItemPeer");
53 postMenuActionEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
54 gtkmenuitempeer,
55 "postMenuActionEvent",
56 "()V");
59 static void item_activate_cb (GtkMenuItem *item __attribute__((unused)),
60 jobject peer_obj);
62 JNIEXPORT void JNICALL
63 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create
64 (JNIEnv *env, jobject obj, jstring label)
66 GtkWidget *widget;
67 const char *str;
69 gdk_threads_enter ();
71 gtkpeer_set_global_ref (env, obj);
73 str = (*env)->GetStringUTFChars (env, label, NULL);
75 /* "-" signals that we need a separator. */
76 if (strcmp (str, "-") == 0)
77 widget = gtk_menu_item_new ();
78 else
79 widget = gtk_menu_item_new_with_label (str);
81 gtk_widget_show (widget);
83 (*env)->ReleaseStringUTFChars (env, label, str);
85 gtkpeer_set_widget (env, obj, widget);
87 gdk_threads_leave ();
90 JNIEXPORT void JNICALL
91 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals
92 (JNIEnv *env, jobject obj)
94 void *ptr;
95 jobject gref;
97 gdk_threads_enter ();
99 ptr = gtkpeer_get_widget (env, obj);
100 gref = gtkpeer_get_global_ref (env, obj);
102 g_signal_connect (G_OBJECT (ptr), "activate",
103 G_CALLBACK (item_activate_cb), gref);
105 gdk_threads_leave ();
108 JNIEXPORT void JNICALL
109 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_gtkWidgetModifyFont
110 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
112 const char *font_name;
113 void *ptr;
114 GtkWidget *label;
115 PangoFontDescription *font_desc;
117 gdk_threads_enter();
119 ptr = gtkpeer_get_widget (env, obj);
121 font_name = (*env)->GetStringUTFChars (env, name, NULL);
123 label = gtk_bin_get_child (GTK_BIN (ptr));
125 if (label)
127 font_desc = pango_font_description_from_string (font_name);
128 pango_font_description_set_size (font_desc,
129 size * cp_gtk_dpi_conversion_factor);
131 if (style & AWT_STYLE_BOLD)
132 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
134 if (style & AWT_STYLE_ITALIC)
135 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
137 gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
139 pango_font_description_free (font_desc);
142 (*env)->ReleaseStringUTFChars (env, name, font_name);
144 gdk_threads_leave();
147 JNIEXPORT void JNICALL
148 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setEnabled
149 (JNIEnv *env, jobject obj, jboolean enabled)
151 void *ptr;
153 gdk_threads_enter ();
155 ptr = gtkpeer_get_widget (env, obj);
157 gtk_widget_set_sensitive (GTK_WIDGET (ptr), enabled);
159 gdk_threads_leave ();
162 JNIEXPORT void JNICALL
163 Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel
164 (JNIEnv *env, jobject obj, jstring label)
166 void *ptr;
167 const char *str;
168 GtkAccelLabel *accel_label;
170 gdk_threads_enter ();
172 ptr = gtkpeer_get_widget (env, obj);
174 str = (*env)->GetStringUTFChars (env, label, NULL);
176 accel_label = GTK_ACCEL_LABEL (GTK_BIN (ptr)->child);
178 gtk_label_set_text (GTK_LABEL (accel_label), str);
179 gtk_accel_label_refetch (accel_label);
181 (*env)->ReleaseStringUTFChars (env, label, str);
183 gdk_threads_leave ();
186 static void
187 item_activate_cb (GtkMenuItem *item __attribute__((unused)), jobject peer_obj)
189 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj,
190 postMenuActionEventID);