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_GtkButtonPeer.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gtkbuttonpeer.c -- Native implementation of GtkButtonPeer
2
   Copyright (C) 1998, 1999 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_GtkButtonPeer.h"
41
 
42
static jmethodID postActionEventID;
43
 
44
void
45
cp_gtk_button_init_jni (JNIEnv* env)
46
{
47
  jclass gtkbuttonpeer;
48
 
49
  gtkbuttonpeer = (*env)->FindClass (env,
50
                                     "gnu/java/awt/peer/gtk/GtkButtonPeer");
51
 
52
  postActionEventID = (*env)->GetMethodID (cp_gtk_gdk_env(), gtkbuttonpeer,
53
                                           "postActionEvent", "(I)V");
54
}
55
 
56
static void clicked_cb (GtkButton *button,
57
                        jobject peer);
58
 
59
JNIEXPORT void JNICALL
60
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create
61
  (JNIEnv *env, jobject obj, jstring label)
62
{
63
  const char *c_label;
64
  GtkWidget *eventbox;
65
  GtkWidget *button;
66
 
67
  gdk_threads_enter ();
68
 
69
  gtkpeer_set_global_ref (env, obj);
70
 
71
  c_label = (*env)->GetStringUTFChars (env, label, NULL);
72
 
73
  eventbox = gtk_event_box_new ();
74
  button = gtk_button_new_with_label (c_label);
75
  gtk_container_add (GTK_CONTAINER (eventbox), button);
76
  gtk_widget_show (button);
77
 
78
  (*env)->ReleaseStringUTFChars (env, label, c_label);
79
  gtkpeer_set_widget (env, obj, eventbox);
80
 
81
  gdk_threads_leave ();
82
}
83
 
84
JNIEXPORT void JNICALL
85
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetGetPreferredDimensions
86
  (JNIEnv *env, jobject obj, jintArray jdims)
87
{
88
  void *ptr;
89
  jint *dims;
90
  GtkWidget *button;
91
  GtkWidget *label;
92
  GtkRequisition current_req;
93
  GtkRequisition current_label_req;
94
  GtkRequisition natural_req;
95
 
96
  gdk_threads_enter ();
97
 
98
  ptr = gtkpeer_get_widget (env, obj);
99
 
100
  button = gtk_bin_get_child (GTK_BIN (ptr));
101
  label = gtk_bin_get_child (GTK_BIN (button));
102
 
103
  dims = (*env)->GetIntArrayElements (env, jdims, 0);
104
  dims[0] = dims[1] = 0;
105
 
106
  /* Save the button's current size request. */
107
  gtk_widget_size_request (GTK_WIDGET (button), &current_req);
108
 
109
  /* Save the label's current size request. */
110
  gtk_widget_size_request (GTK_WIDGET (label), &current_label_req);
111
 
112
  /* Get the widget's "natural" size request. */
113
  gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1);
114
  gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1);
115
 
116
  gtk_widget_size_request (GTK_WIDGET (button), &natural_req);
117
 
118
  /* Reset the button's size request. */
119
  gtk_widget_set_size_request (GTK_WIDGET (button),
120
                               current_req.width, current_req.height);
121
 
122
  /* Reset the label's size request. */
123
  gtk_widget_set_size_request (GTK_WIDGET (label),
124
                               current_label_req.width, current_label_req.height);
125
 
126
  dims[0] = natural_req.width;
127
  dims[1] = natural_req.height;
128
 
129
  (*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
130
 
131
  gdk_threads_leave ();
132
}
133
 
134
JNIEXPORT void JNICALL
135
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals
136
  (JNIEnv *env, jobject obj)
137
{
138
  GtkWidget *widget;
139
  jobject gref;
140
  GtkWidget *button;
141
 
142
  gdk_threads_enter ();
143
 
144
  widget = gtkpeer_get_widget (env, obj);
145
  gref = gtkpeer_get_global_ref (env, obj);
146
 
147
  button = gtk_bin_get_child (GTK_BIN (widget));
148
 
149
  /* Button signals */
150
  g_signal_connect (G_OBJECT (button), "clicked",
151
                    G_CALLBACK (clicked_cb), gref);
152
 
153
  /* Component signals */
154
  cp_gtk_component_connect_signals (G_OBJECT (button), gref);
155
 
156
  gdk_threads_leave ();
157
}
158
 
159
JNIEXPORT void JNICALL
160
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetLabel
161
  (JNIEnv *env, jobject obj, jstring jtext)
162
{
163
  const char *text;
164
  GtkWidget *button;
165
  GtkWidget *label;
166
  void *ptr;
167
 
168
  gdk_threads_enter ();
169
 
170
  ptr = gtkpeer_get_widget (env, obj);
171
 
172
  text = (*env)->GetStringUTFChars (env, jtext, NULL);
173
 
174
  button = gtk_bin_get_child (GTK_BIN (ptr));
175
  label = gtk_bin_get_child (GTK_BIN (button));
176
  gtk_label_set_text (GTK_LABEL (label), text);
177
 
178
  (*env)->ReleaseStringUTFChars (env, jtext, text);
179
 
180
  gdk_threads_leave ();
181
}
182
 
183
JNIEXPORT void JNICALL
184
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetModifyFont
185
  (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
186
{
187
  const char *font_name;
188
  void *ptr;
189
  GtkWidget *button;
190
  GtkWidget *label;
191
  PangoFontDescription *font_desc;
192
 
193
  gdk_threads_enter();
194
 
195
  ptr = gtkpeer_get_widget (env, obj);
196
 
197
  font_name = (*env)->GetStringUTFChars (env, name, NULL);
198
 
199
  button = gtk_bin_get_child (GTK_BIN (ptr));
200
  label = gtk_bin_get_child (GTK_BIN (button));
201
 
202
  font_desc = pango_font_description_from_string (font_name);
203
  pango_font_description_set_size (font_desc,
204
                                   size * cp_gtk_dpi_conversion_factor);
205
 
206
  if (style & AWT_STYLE_BOLD)
207
    pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
208
 
209
  if (style & AWT_STYLE_ITALIC)
210
    pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
211
 
212
  gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
213
 
214
  pango_font_description_free (font_desc);
215
 
216
  (*env)->ReleaseStringUTFChars (env, name, font_name);
217
 
218
  gdk_threads_leave();
219
}
220
 
221
JNIEXPORT void JNICALL
222
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetBackground
223
  (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
224
{
225
  GdkColor normal_color;
226
  GdkColor prelight_color;
227
  GdkColor active_color;
228
  int prelight_red;
229
  int prelight_blue;
230
  int prelight_green;
231
  GtkWidget *button;
232
  void *ptr;
233
 
234
  gdk_threads_enter ();
235
 
236
  ptr = gtkpeer_get_widget (env, obj);
237
 
238
  normal_color.red = (red / 255.0) * 65535;
239
  normal_color.green = (green / 255.0) * 65535;
240
  normal_color.blue = (blue / 255.0) * 65535;
241
 
242
  /* This calculation only approximate the active color produced by
243
     Sun's AWT. */
244
  active_color.red = 0.85 * (red / 255.0) * 65535;
245
  active_color.green = 0.85 * (green / 255.0) * 65535;
246
  active_color.blue = 0.85 * (blue / 255.0) * 65535;
247
 
248
  /* There is no separate prelight color in Motif. */
249
  prelight_red = 1.15 * (red / 255.0) * 65535;
250
  prelight_green = 1.15 * (green / 255.0) * 65535;
251
  prelight_blue = 1.15 * (blue / 255.0) * 65535;
252
 
253
  prelight_color.red = prelight_red > 65535 ? 65535 : prelight_red;
254
  prelight_color.green = prelight_green > 65535 ? 65535 : prelight_green;
255
  prelight_color.blue = prelight_blue > 65535 ? 65535 : prelight_blue;
256
 
257
  button = gtk_bin_get_child (GTK_BIN (ptr));
258
 
259
  gtk_widget_modify_bg (button, GTK_STATE_NORMAL, &normal_color);
260
  gtk_widget_modify_bg (button, GTK_STATE_ACTIVE, &active_color);
261
  gtk_widget_modify_bg (button, GTK_STATE_PRELIGHT, &prelight_color);
262
 
263
  gdk_threads_leave ();
264
}
265
 
266
JNIEXPORT void JNICALL
267
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetForeground
268
  (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
269
{
270
  GdkColor color;
271
  GtkWidget *button;
272
  GtkWidget *label;
273
  void *ptr;
274
 
275
  gdk_threads_enter ();
276
 
277
  ptr = gtkpeer_get_widget (env, obj);
278
 
279
  color.red = (red / 255.0) * 65535;
280
  color.green = (green / 255.0) * 65535;
281
  color.blue = (blue / 255.0) * 65535;
282
 
283
  button = gtk_bin_get_child (GTK_BIN (ptr));
284
  label = gtk_bin_get_child (GTK_BIN (button));
285
 
286
  gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color);
287
  gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, &color);
288
  gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color);
289
 
290
  gdk_threads_leave ();
291
}
292
 
293
JNIEXPORT void JNICALL
294
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkActivate
295
  (JNIEnv *env, jobject obj)
296
{
297
  GtkWidget *button;
298
  void *ptr;
299
 
300
  gdk_threads_enter ();
301
 
302
  ptr = gtkpeer_get_widget (env, obj);
303
 
304
  button = gtk_bin_get_child (GTK_BIN (ptr));
305
  gtk_widget_activate (GTK_WIDGET (button));
306
 
307
  gdk_threads_leave ();
308
}
309
 
310
JNIEXPORT void JNICALL
311
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetRequestFocus
312
  (JNIEnv *env, jobject obj)
313
{
314
  void *ptr;
315
  GtkWidget *button;
316
 
317
  gdk_threads_enter ();
318
 
319
  ptr = gtkpeer_get_widget (env, obj);
320
 
321
  button = gtk_bin_get_child (GTK_BIN (ptr));
322
  gtk_widget_grab_focus (button);
323
 
324
  gdk_threads_leave ();
325
}
326
 
327
JNIEXPORT void JNICALL
328
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_setNativeBounds
329
  (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
330
{
331
  GtkWidget *widget, *child;
332
  void *ptr;
333
 
334
  gdk_threads_enter ();
335
 
336
  ptr = gtkpeer_get_widget (env, obj);
337
 
338
  widget = GTK_WIDGET (ptr);
339
 
340
  /* We assume that -1 is a width or height and not a request for the
341
     widget's natural size. */
342
  width = width < 0 ? 0 : width;
343
  height = height < 0 ? 0 : height;
344
  child = gtk_bin_get_child (GTK_BIN (widget));
345
 
346
  if (!(width == 0 && height == 0))
347
    {
348
      /* Set the event box's size request... */
349
      gtk_widget_set_size_request (widget, width, height);
350
      /* ...and the button's size request... */
351
      gtk_widget_set_size_request (child, width, height);
352
      /* ...and the label's size request. */
353
      gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (child)), width,
354
                                                      height);
355
      if (widget->parent != NULL && GTK_IS_FIXED (widget->parent))
356
        gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
357
    }
358
 
359
  gdk_threads_leave ();
360
}
361
 
362
static void
363
clicked_cb (GtkButton* button __attribute__((unused)),
364
            jobject peer)
365
{
366
  GdkEventButton* event;
367
 
368
  event = (GdkEventButton*) gtk_get_current_event ();
369
  g_assert (event);
370
 
371
  (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
372
                                       postActionEventID,
373
                                       cp_gtk_state_to_awt_mods (event->state));
374
 
375
  gdk_event_free ((GdkEvent*) event);
376
}

powered by: WebSVN 2.1.0

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