* config/sparc/sparc.md (save_register_windowdi): Add missing mode.
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkChoicePeer.c
blob94c9c3d0c2ddb76ea0334e9cbc001fcc95e16515
1 /* gtkchoicepeer.c -- Native implementation of GtkChoicePeer
2 Copyright (C) 1998, 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_GtkChoicePeer.h"
42 static void selection_changed (GtkComboBox *combobox, gpointer data);
44 JNIEXPORT void JNICALL
45 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create
46 (JNIEnv *env, jobject obj)
48 GtkWidget *combobox;
50 NSA_SET_GLOBAL_REF (env, obj);
52 gdk_threads_enter ();
54 combobox = gtk_combo_box_new_text ();
56 g_signal_connect (combobox, "changed",
57 G_CALLBACK (selection_changed), obj);
59 gdk_threads_leave ();
61 NSA_SET_PTR (env, obj, combobox);
64 JNIEXPORT void JNICALL
65 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append
66 (JNIEnv *env, jobject obj, jobjectArray items)
68 gpointer ptr;
69 jsize count, i;
71 ptr = NSA_GET_PTR (env, obj);
73 gdk_threads_enter ();
75 count = (*env)->GetArrayLength (env, items);
77 for (i = 0; i < count; i++)
79 jobject item;
80 const char *label;
82 item = (*env)->GetObjectArrayElement (env, items, i);
83 label = (*env)->GetStringUTFChars (env, item, NULL);
85 gtk_combo_box_append_text (GTK_COMBO_BOX (ptr), label);
87 (*env)->ReleaseStringUTFChars (env, item, label);
90 gdk_threads_leave ();
93 JNIEXPORT void JNICALL
94 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd
95 (JNIEnv *env, jobject obj, jstring item, jint index)
97 void *ptr;
98 const char *label;
100 ptr = NSA_GET_PTR (env, obj);
102 label = (*env)->GetStringUTFChars (env, item, 0);
104 gdk_threads_enter ();
105 gtk_combo_box_insert_text (GTK_COMBO_BOX (ptr), index, label);
106 gdk_threads_leave ();
108 (*env)->ReleaseStringUTFChars (env, item, label);
111 JNIEXPORT void JNICALL
112 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove
113 (JNIEnv *env, jobject obj, jint index)
115 void *ptr;
117 ptr = NSA_GET_PTR (env, obj);
119 gdk_threads_enter ();
120 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), index);
121 gdk_threads_leave ();
124 JNIEXPORT void JNICALL
125 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll
126 (JNIEnv *env, jobject obj)
128 void *ptr;
129 GtkTreeModel *model;
130 gint count, i;
132 ptr = NSA_GET_PTR (env, obj);
134 gdk_threads_enter ();
136 model = gtk_combo_box_get_model (GTK_COMBO_BOX (ptr));
137 count = gtk_tree_model_iter_n_children (model, NULL);
139 /* First, unselect everything, to avoid problems when removing items. */
140 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), -1);
142 for (i = count - 1; i >= 0; i--) {
143 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), i);
146 gdk_threads_leave ();
149 JNIEXPORT void JNICALL
150 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_select
151 (JNIEnv *env, jobject obj, jint index)
153 void *ptr;
155 ptr = NSA_GET_PTR (env, obj);
157 gdk_threads_enter ();
158 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), index);
159 gdk_threads_leave ();
162 JNIEXPORT jint JNICALL
163 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected
164 (JNIEnv *env, jobject obj)
166 void *ptr;
167 int index;
169 ptr = NSA_GET_PTR (env, obj);
171 gdk_threads_enter ();
172 index = gtk_combo_box_get_active (GTK_COMBO_BOX (ptr));
173 gdk_threads_leave ();
175 return index;
178 void selection_changed (GtkComboBox *combobox, jobject peer)
180 jstring label;
181 GtkTreeModel *model;
182 GtkTreeIter iter;
183 gchar *selected;
184 gint index;
186 index = gtk_combo_box_get_active(combobox);
188 if (index >= 0)
190 model = gtk_combo_box_get_model (combobox);
192 gtk_combo_box_get_active_iter (combobox, &iter);
194 gtk_tree_model_get (model, &iter, 0, &selected, -1);
196 gdk_threads_leave ();
198 label = (*gdk_env)->NewStringUTF (gdk_env, selected);
199 (*gdk_env)->CallVoidMethod (gdk_env, peer,
200 choicePostItemEventID,
201 label,
202 (jint) AWT_ITEM_SELECTED);
203 gdk_threads_enter ();