OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [gtk-peer/] [gnu_java_awt_peer_gtk_GtkChoicePeer.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gtkchoicepeer.c -- Native implementation of GtkChoicePeer
2
   Copyright (C) 1998, 1999, 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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.
20
 
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.
25
 
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. */
37
 
38
 
39
#include "gtkpeer.h"
40
#include "gnu_java_awt_peer_gtk_GtkChoicePeer.h"
41
 
42
static jmethodID postChoiceItemEventID;
43
static GtkWidget *choice_get_widget (GtkWidget *widget);
44
 
45
void
46
cp_gtk_choice_init_jni (void)
47
{
48
  jclass gtkchoicepeer;
49
 
50
  gtkchoicepeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
51
                                        "gnu/java/awt/peer/gtk/GtkChoicePeer");
52
 
53
  postChoiceItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkchoicepeer,
54
                                               "postChoiceItemEvent",
55
                                               "(I)V");
56
}
57
 
58
static void selection_changed_cb (GtkComboBox *combobox, jobject peer);
59
 
60
JNIEXPORT void JNICALL
61
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create
62
  (JNIEnv *env, jobject obj)
63
{
64
  GtkWidget *combobox;
65
  GtkWidget *eventbox;
66
 
67
  gdk_threads_enter ();
68
 
69
  gtkpeer_set_global_ref (env, obj);
70
 
71
  eventbox = gtk_event_box_new ();
72
  combobox = gtk_combo_box_new_text ();
73
  gtk_container_add (GTK_CONTAINER (eventbox), combobox);
74
  gtk_widget_show (combobox);
75
 
76
  gtkpeer_set_widget (env, obj, eventbox);
77
 
78
  gdk_threads_leave ();
79
}
80
 
81
JNIEXPORT void JNICALL
82
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_connectSignals
83
  (JNIEnv *env, jobject obj)
84
{
85
  void *ptr = NULL;
86
  jobject gref;
87
  GtkWidget *bin;
88
 
89
  gdk_threads_enter ();
90
 
91
  ptr = gtkpeer_get_widget (env, obj);
92
  gref = gtkpeer_get_global_ref (env, obj);
93
 
94
  bin = choice_get_widget (GTK_WIDGET (ptr));
95
 
96
  /* Choice signals */
97
  g_signal_connect (G_OBJECT (bin), "changed",
98
                    G_CALLBACK (selection_changed_cb), gref);
99
 
100
  /* Component signals */
101
  cp_gtk_component_connect_signals (G_OBJECT (bin), gref);
102
 
103
  gdk_threads_leave ();
104
}
105
 
106
JNIEXPORT void JNICALL
107
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_add
108
  (JNIEnv *env, jobject obj, jstring item, jint index)
109
{
110
  void *ptr;
111
  const char *label;
112
  GtkWidget *bin;
113
 
114
  gdk_threads_enter ();
115
 
116
  ptr = gtkpeer_get_widget (env, obj);
117
  bin = choice_get_widget (GTK_WIDGET (ptr));
118
 
119
  label = (*env)->GetStringUTFChars (env, item, 0);
120
 
121
  gtk_combo_box_insert_text (GTK_COMBO_BOX (bin), index, label);
122
 
123
  (*env)->ReleaseStringUTFChars (env, item, label);
124
 
125
  gdk_threads_leave ();
126
}
127
 
128
JNIEXPORT void JNICALL
129
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemove
130
  (JNIEnv *env, jobject obj, jint index)
131
{
132
  void *ptr;
133
  GtkWidget *bin;
134
 
135
  gdk_threads_enter ();
136
 
137
  ptr = gtkpeer_get_widget (env, obj);
138
  bin = choice_get_widget (GTK_WIDGET (ptr));
139
 
140
  /* First, unselect everything, to avoid problems when removing items. */
141
  gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1);
142
  gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), index);
143
 
144
  gdk_threads_leave ();
145
}
146
 
147
JNIEXPORT void JNICALL
148
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeRemoveAll
149
  (JNIEnv *env, jobject obj)
150
{
151
  void *ptr;
152
  GtkTreeModel *model;
153
  GtkWidget *bin;
154
  gint count, i;
155
 
156
  gdk_threads_enter ();
157
 
158
  ptr = gtkpeer_get_widget (env, obj);
159
  bin = choice_get_widget (GTK_WIDGET (ptr));
160
 
161
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (bin));
162
  count = gtk_tree_model_iter_n_children (model, NULL);
163
 
164
  /* First, unselect everything, to avoid problems when removing items. */
165
  gtk_combo_box_set_active (GTK_COMBO_BOX (bin), -1);
166
 
167
  for (i = count - 1; i >= 0; i--) {
168
    gtk_combo_box_remove_text (GTK_COMBO_BOX (bin), i);
169
  }
170
 
171
  gdk_threads_leave ();
172
}
173
 
174
JNIEXPORT void JNICALL
175
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNative
176
  (JNIEnv *env, jobject obj, jint index)
177
{
178
  gdk_threads_enter ();
179
 
180
  Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
181
    (env, obj, index);
182
 
183
  gdk_threads_leave ();
184
}
185
 
186
JNIEXPORT void JNICALL
187
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_selectNativeUnlocked
188
  (JNIEnv *env, jobject obj, jint index)
189
{
190
  void *ptr;
191
  GtkWidget *bin;
192
 
193
  ptr = gtkpeer_get_widget (env, obj);
194
  bin = choice_get_widget (GTK_WIDGET (ptr));
195
  gtk_combo_box_set_active (GTK_COMBO_BOX (bin), (gint)index);
196
}
197
 
198
JNIEXPORT jint JNICALL
199
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_nativeGetSelected
200
  (JNIEnv *env, jobject obj)
201
{
202
  void *ptr;
203
  int index;
204
  GtkWidget *bin;
205
 
206
  gdk_threads_enter ();
207
 
208
  ptr = gtkpeer_get_widget (env, obj);
209
  bin = choice_get_widget (GTK_WIDGET (ptr));
210
 
211
  index = gtk_combo_box_get_active (GTK_COMBO_BOX (bin));
212
 
213
  gdk_threads_leave ();
214
 
215
  return index;
216
}
217
 
218
static void
219
selection_changed_cb (GtkComboBox *combobox, jobject peer)
220
{
221
  gint index = gtk_combo_box_get_active(combobox);
222
 
223
  if (index >= 0)
224
    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
225
                                         postChoiceItemEventID, (jint)index );
226
}
227
 
228
static GtkWidget *
229
choice_get_widget (GtkWidget *widget)
230
{
231
  GtkWidget *wid;
232
 
233
  g_assert (GTK_IS_EVENT_BOX (widget));
234
  wid = gtk_bin_get_child (GTK_BIN(widget));
235
 
236
  return wid;
237
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.