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)
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
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
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. */
40 #include "gnu_java_awt_peer_gtk_GtkChoicePeer.h"
42 static jmethodID postChoiceItemEventID
;
45 cp_gtk_choice_init_jni (void)
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
)
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
);
78 JNIEXPORT
void JNICALL
79 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals
80 (JNIEnv
*env
, jobject obj
)
87 ptr
= NSA_GET_PTR (env
, obj
);
88 gref
= NSA_GET_GLOBAL_REF (env
, obj
);
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
);
100 JNIEXPORT
void JNICALL
101 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_append
102 (JNIEnv
*env
, jobject obj
, jobjectArray items
)
107 gdk_threads_enter ();
109 ptr
= NSA_GET_PTR (env
, obj
);
111 count
= (*env
)->GetArrayLength (env
, items
);
113 for (i
= 0; i
< count
; i
++)
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
);
124 (*env
)->DeleteLocalRef(env
, item
);
127 gdk_threads_leave ();
130 JNIEXPORT
void JNICALL
131 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeAdd
132 (JNIEnv
*env
, jobject obj
, jstring item
, jint index
)
137 gdk_threads_enter ();
139 ptr
= NSA_GET_PTR (env
, obj
);
141 label
= (*env
)->GetStringUTFChars (env
, item
, 0);
143 gtk_combo_box_insert_text (GTK_COMBO_BOX (ptr
), index
, label
);
145 (*env
)->ReleaseStringUTFChars (env
, item
, label
);
147 gdk_threads_leave ();
150 JNIEXPORT
void JNICALL
151 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove
152 (JNIEnv
*env
, jobject obj
, jint index
)
156 gdk_threads_enter ();
158 ptr
= NSA_GET_PTR (env
, obj
);
160 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr
), index
);
162 gdk_threads_leave ();
165 JNIEXPORT
void JNICALL
166 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll
167 (JNIEnv
*env
, jobject obj
)
173 gdk_threads_enter ();
175 ptr
= NSA_GET_PTR (env
, obj
);
177 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (ptr
));
178 count
= gtk_tree_model_iter_n_children (model
, NULL
);
180 /* First, unselect everything, to avoid problems when removing items. */
181 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr
), -1);
183 for (i
= count
- 1; i
>= 0; i
--) {
184 gtk_combo_box_remove_text (GTK_COMBO_BOX (ptr
), i
);
187 gdk_threads_leave ();
190 JNIEXPORT
void JNICALL
191 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNative
192 (JNIEnv
*env
, jobject obj
, jint index
)
194 gdk_threads_enter ();
196 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
199 gdk_threads_leave ();
202 JNIEXPORT
void JNICALL
203 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
204 (JNIEnv
*env
, jobject obj
, jint index
)
208 ptr
= NSA_GET_PTR (env
, obj
);
210 gtk_combo_box_set_active (GTK_COMBO_BOX (ptr
), index
);
213 JNIEXPORT jint JNICALL
214 Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected
215 (JNIEnv
*env
, jobject obj
)
220 gdk_threads_enter ();
222 ptr
= NSA_GET_PTR (env
, obj
);
224 index
= gtk_combo_box_get_active (GTK_COMBO_BOX (ptr
));
226 gdk_threads_leave ();
232 selection_changed_cb (GtkComboBox
*combobox
, jobject peer
)
240 index
= gtk_combo_box_get_active(combobox
);
244 model
= gtk_combo_box_get_model (combobox
);
245 gtk_combo_box_get_active_iter (combobox
, &iter
);
246 gtk_tree_model_get (model
, &iter
, 0, &selected
, -1);
247 label
= (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), selected
);
249 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer
,
250 postChoiceItemEventID
,
252 (jint
) AWT_ITEM_SELECTED
);