Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMenuPeer.c
blobc23fc5bd6a4dd4ecbda7ceb650b9e95a0f1ec373
1 /* gtkmenupeer.c -- Native implementation of GtkMenuPeer
2 Copyright (C) 1999, 2004 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_GtkMenuPeer.h"
42 JNIEXPORT void JNICALL
43 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup
44 (JNIEnv *env, jobject obj, jobject parent)
46 void *ptr1, *ptr2;
48 gdk_threads_enter ();
50 ptr1 = NSA_GET_PTR (env, obj);
52 if (!parent)
54 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
55 gtk_accel_group_new ());
57 else
59 GtkAccelGroup *parent_accel;
61 ptr2 = NSA_GET_PTR (env, parent);
62 parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu));
64 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
65 parent_accel);
68 gdk_threads_leave ();
72 JNIEXPORT void JNICALL
73 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create
74 (JNIEnv *env, jobject obj, jstring label)
76 GtkWidget *menu_title, *menu, *toplevel;
77 const char *str;
79 gdk_threads_enter ();
81 NSA_SET_GLOBAL_REF (env, obj);
83 str = (*env)->GetStringUTFChars (env, label, NULL);
85 menu = gtk_menu_new ();
87 if (str != NULL)
88 menu_title = gtk_menu_item_new_with_label (str);
89 else
90 menu_title = gtk_menu_item_new();
92 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu);
94 /* Allow this menu to grab the pointer. */
95 toplevel = gtk_widget_get_toplevel (menu);
96 if (GTK_IS_WINDOW (toplevel))
98 gtk_window_group_add_window (cp_gtk_global_window_group,
99 GTK_WINDOW(toplevel));
102 gtk_widget_show (menu_title);
104 NSA_SET_PTR (env, obj, menu_title);
106 (*env)->ReleaseStringUTFChars (env, label, str);
108 gdk_threads_leave ();
111 JNIEXPORT void JNICALL
112 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addTearOff
113 (JNIEnv *env, jobject obj)
115 void *ptr1;
116 GtkWidget *menu, *item;
118 gdk_threads_enter ();
120 ptr1 = NSA_GET_PTR (env, obj);
122 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (ptr1));
123 item = gtk_tearoff_menu_item_new ();
124 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
125 gtk_widget_show (item);
127 gdk_threads_leave ();
130 JNIEXPORT void JNICALL
131 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem
132 (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift)
134 void *ptr1, *ptr2;
135 GtkWidget *menu;
137 gdk_threads_enter ();
139 ptr1 = NSA_GET_PTR (env, obj);
140 ptr2 = NSA_GET_PTR (env, menuitempeer);
142 menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1));
143 gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2));
145 if (key)
147 gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate",
148 gtk_menu_get_accel_group (GTK_MENU (menu)), key,
149 (GDK_CONTROL_MASK
150 | ((shift) ? GDK_SHIFT_MASK : 0)),
151 GTK_ACCEL_VISIBLE);
154 gdk_threads_leave ();
157 JNIEXPORT void JNICALL
158 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_delItem
159 (JNIEnv *env, jobject obj, jint index)
161 void *ptr;
162 GList *list;
163 GtkWidget *menu;
165 gdk_threads_enter ();
167 ptr = NSA_GET_PTR (env, obj);
169 menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr));
171 list = gtk_container_get_children (GTK_CONTAINER (menu));
172 list = g_list_nth (list, index);
173 gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (list->data));
175 gdk_threads_leave ();