Merge from the pain train
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMenuPeer.c
blobdd5511cf679ac0f6b21a5068386e4285bf47ec5b
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., 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_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 ptr1 = NSA_GET_PTR (env, obj);
50 gdk_threads_enter ();
51 if (!parent)
53 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
54 gtk_accel_group_new ());
56 else
58 GtkAccelGroup *parent_accel;
60 ptr2 = NSA_GET_PTR (env, parent);
61 parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu));
63 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
64 parent_accel);
67 gdk_threads_leave ();
71 JNIEXPORT void JNICALL
72 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create
73 (JNIEnv *env, jobject obj, jstring label)
75 GtkWidget *menu_title, *menu, *toplevel;
76 const char *str;
78 NSA_SET_GLOBAL_REF (env, obj);
80 str = (*env)->GetStringUTFChars (env, label, NULL);
82 gdk_threads_enter ();
84 menu = gtk_menu_new ();
86 if (str != NULL)
87 menu_title = gtk_menu_item_new_with_label (str);
88 else
89 menu_title = gtk_menu_item_new();
91 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu);
93 /* Allow this menu to grab the pointer. */
94 toplevel = gtk_widget_get_toplevel (menu);
95 if (GTK_IS_WINDOW (toplevel))
97 gtk_window_group_add_window (global_gtk_window_group,
98 GTK_WINDOW(toplevel));
101 gtk_widget_show (menu_title);
103 NSA_SET_PTR (env, obj, menu_title);
105 gdk_threads_leave ();
107 (*env)->ReleaseStringUTFChars (env, label, str);
110 JNIEXPORT void JNICALL
111 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addTearOff
112 (JNIEnv *env, jobject obj)
114 void *ptr1;
115 GtkWidget *menu, *item;
117 ptr1 = NSA_GET_PTR (env, obj);
119 gdk_threads_enter ();
121 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (ptr1));
122 item = gtk_tearoff_menu_item_new ();
123 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
124 gtk_widget_show (item);
126 gdk_threads_leave ();
129 JNIEXPORT void JNICALL
130 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem
131 (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift)
133 void *ptr1, *ptr2;
134 GtkWidget *menu;
136 ptr1 = NSA_GET_PTR (env, obj);
137 ptr2 = NSA_GET_PTR (env, menuitempeer);
139 gdk_threads_enter ();
141 menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1));
142 gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2));
144 if (key)
146 gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate",
147 gtk_menu_get_accel_group (GTK_MENU (menu)), key,
148 (GDK_CONTROL_MASK
149 | ((shift) ? GDK_SHIFT_MASK : 0)),
150 GTK_ACCEL_VISIBLE);
153 gdk_threads_leave ();
156 JNIEXPORT void JNICALL
157 Java_gnu_java_awt_peer_gtk_GtkMenuPeer_delItem
158 (JNIEnv *env, jobject obj, jint index)
160 void *ptr;
161 GList *list;
163 ptr = NSA_GET_PTR (env, obj);
165 gdk_threads_enter ();
166 list = gtk_container_children (GTK_CONTAINER (ptr));
167 list = g_list_nth (list, index);
168 gtk_container_remove (GTK_CONTAINER (ptr), GTK_WIDGET (list->data));
169 gdk_threads_leave ();