Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkChoicePeer.c
blobc5bf5a353ff8f17606f9c9e2e47b188a99938bc4
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., 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_GtkChoicePeer.h"
42 static jmethodID postChoiceItemEventID;
44 void
45 cp_gtk_choice_init_jni (void)
47 jclass gtkchoicepeer;
49 gtkchoicepeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
50 "gnu/java/awt/peer/gtk/GtkChoicePeer");
52 postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer,
53 "postChoiceItemEvent",
54 "(Ljava/lang/String;I)V");
57 static void selection_changed_cb (GtkComboBox *combobox, jobject peer);
59 JNIEXPORT void JNICALL
60 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create
61 (JNIEnv *env, jobject obj)
63 GtkWidget *combobox;
64 jobject *gref;
66 gdk_threads_enter ();
68 NSA_SET_GLOBAL_REF (env, obj);
69 gref = NSA_GET_GLOBAL_REF (env, obj);
71 combobox = gtk_combo_box_new_text ();
73 NSA_SET_PTR (env, obj, combobox);
75 gdk_threads_leave ();
78 JNIEXPORT void JNICALL
79 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals
80 (JNIEnv *env, jobject obj)
82 void *ptr = NULL;
83 jobject *gref = NULL;
85 gdk_threads_enter ();
87 ptr = NSA_GET_PTR (env, obj);
88 gref = NSA_GET_GLOBAL_REF (env, obj);
90 /* Choice signals */
91 g_signal_connect (G_OBJECT (ptr), "changed",
92 G_CALLBACK (selection_changed_cb), *gref);
94 /* Component signals */
95 cp_gtk_component_connect_signals (G_OBJECT (ptr), gref);
97 gdk_threads_leave ();
100 JNIEXPORT void JNICALL
101 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append
102 (JNIEnv *env, jobject obj, jobjectArray items)
104 gpointer ptr;
105 jsize count, i;
107 gdk_threads_enter ();
109 ptr = NSA_GET_PTR (env, obj);
111 count = (*env)->GetArrayLength (env, items);
113 for (i = 0; i < count; i++)
115 jobject item;
116 const char *label;
118 item = (*env)->GetObjectArrayElement (env, items, i);
119 label = (*env)->GetStringUTFChars (env, item, NULL);
121 gtk_combo_box_append_text (GTK_COMBO_BOX (ptr), label);
123 (*env)->ReleaseStringUTFChars (env, item, label);
126 gdk_threads_leave ();
129 JNIEXPORT void JNICALL
130 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd
131 (JNIEnv *env, jobject obj, jstring item, jint index)
133 void *ptr;
134 const char *label;
136 gdk_threads_enter ();
138 ptr = NSA_GET_PTR (env, obj);
140 label = (*env)->GetStringUTFChars (env, item, 0);
142 gtk_combo_box_insert_text (GTK_COMBO_BOX (ptr), index, label);
144 (*env)->ReleaseStringUTFChars (env, item, label);
146 gdk_threads_leave ();
149 JNIEXPORT void JNICALL
150 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove
151 (JNIEnv *env, jobject obj, jint index)
153 void *ptr;
155 gdk_threads_enter ();
157 ptr = NSA_GET_PTR (env, obj);
159 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), index);
161 gdk_threads_leave ();
164 JNIEXPORT void JNICALL
165 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll
166 (JNIEnv *env, jobject obj)
168 void *ptr;
169 GtkTreeModel *model;
170 gint count, i;
172 gdk_threads_enter ();
174 ptr = NSA_GET_PTR (env, obj);
176 model = gtk_combo_box_get_model (GTK_COMBO_BOX (ptr));
177 count = gtk_tree_model_iter_n_children (model, NULL);
179 /* First, unselect everything, to avoid problems when removing items. */
180 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), -1);
182 for (i = count - 1; i >= 0; i--) {
183 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr), i);
186 gdk_threads_leave ();
189 JNIEXPORT void JNICALL
190 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNative
191 (JNIEnv *env, jobject obj, jint index)
193 gdk_threads_enter ();
195 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
196 (env, obj, index);
198 gdk_threads_leave ();
201 JNIEXPORT void JNICALL
202 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
203 (JNIEnv *env, jobject obj, jint index)
205 void *ptr;
207 ptr = NSA_GET_PTR (env, obj);
209 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr), index);
212 JNIEXPORT jint JNICALL
213 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected
214 (JNIEnv *env, jobject obj)
216 void *ptr;
217 int index;
219 gdk_threads_enter ();
221 ptr = NSA_GET_PTR (env, obj);
223 index = gtk_combo_box_get_active (GTK_COMBO_BOX (ptr));
225 gdk_threads_leave ();
227 return index;
230 static void
231 selection_changed_cb (GtkComboBox *combobox, jobject peer)
233 jstring label;
234 GtkTreeModel *model;
235 GtkTreeIter iter;
236 gchar *selected;
237 gint index;
239 index = gtk_combo_box_get_active(combobox);
241 if (index >= 0)
243 model = gtk_combo_box_get_model (combobox);
244 gtk_combo_box_get_active_iter (combobox, &iter);
245 gtk_tree_model_get (model, &iter, 0, &selected, -1);
246 label = (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), selected);
248 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
249 postChoiceItemEventID,
250 label,
251 (jint) AWT_ITEM_SELECTED);