2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkMenuPeer.c
blob63e6a740158aa8890efed958bef9ad46b6180cd5
1 /* gtkmenupeer.c -- Native implementation of GtkMenuPeer
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_GtkMenuPeer.h"
42 static void
43 accel_attach (GtkMenuItem *menu_item,
44 gpointer *user_data __attribute__((unused)))
46 GtkAccelGroup *accel;
48 accel = gtk_menu_get_accel_group (GTK_MENU (menu_item->submenu));
49 _gtk_accel_group_attach (accel,
50 G_OBJECT (gtk_widget_get_toplevel (GTK_WIDGET(menu_item))));
53 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_setupAccelGroup
54 (JNIEnv *env, jobject obj, jobject parent)
56 void *ptr1, *ptr2;
58 ptr1 = NSA_GET_PTR (env, obj);
60 gdk_threads_enter ();
61 if (!parent)
63 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
64 gtk_accel_group_new ());
66 if (GTK_WIDGET_REALIZED (GTK_WIDGET (ptr1)))
67 accel_attach (GTK_MENU_ITEM (ptr1), NULL);
68 else
69 g_signal_connect (G_OBJECT (ptr1),
70 "realize",
71 GTK_SIGNAL_FUNC (accel_attach),
72 NULL);
74 else
76 GtkAccelGroup *parent_accel;
78 ptr2 = NSA_GET_PTR (env, parent);
79 parent_accel = gtk_menu_get_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr2)->submenu));
81 gtk_menu_set_accel_group (GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu),
82 parent_accel);
85 gdk_threads_leave ();
89 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create
90 (JNIEnv *env, jobject obj, jstring label)
92 GtkWidget *menu_title, *menu;
93 const char *str;
95 /* Create global reference and save it for future use */
96 NSA_SET_GLOBAL_REF (env, obj);
98 str = (*env)->GetStringUTFChars (env, label, NULL);
100 gdk_threads_enter ();
102 menu = gtk_menu_new ();
104 menu_title = gtk_menu_item_new_with_label (str);
105 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu);
107 gtk_widget_show (menu);
108 gtk_widget_show (menu_title);
110 NSA_SET_PTR (env, obj, menu_title);
112 gdk_threads_leave ();
114 (*env)->ReleaseStringUTFChars (env, label, str);
117 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem
118 (JNIEnv *env, jobject obj, jobject menuitempeer, jint key, jboolean shift)
120 void *ptr1, *ptr2;
121 GtkMenu *menu;
123 ptr1 = NSA_GET_PTR (env, obj);
124 ptr2 = NSA_GET_PTR (env, menuitempeer);
126 gdk_threads_enter ();
128 menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu);
129 gtk_menu_append (menu, GTK_WIDGET (ptr2));
131 if (key)
133 gtk_widget_add_accelerator (GTK_WIDGET (ptr2), "activate",
134 gtk_menu_get_accel_group (menu), key,
135 (GDK_CONTROL_MASK
136 | ((shift) ? GDK_SHIFT_MASK : 0)),
137 GTK_ACCEL_VISIBLE);
140 gdk_threads_leave ();
143 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_delItem
144 (JNIEnv *env, jobject obj, jint index)
146 void *ptr;
147 GList *list;
149 ptr = NSA_GET_PTR (env, obj);
151 gdk_threads_enter ();
152 list = gtk_container_children (GTK_CONTAINER (ptr));
153 list = g_list_nth (list, index);
154 gtk_container_remove (GTK_CONTAINER (ptr), GTK_WIDGET (list->data));
155 gdk_threads_leave ();