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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gdkrobotpeer.c
2
   Copyright (C) 2004 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
#include "gtkpeer.h"
39
#include "gnu_java_awt_peer_gtk_GdkRobotPeer.h"
40
 
41
#ifdef HAVE_XTEST
42
#include <gdk/gdkx.h>
43
#include <X11/extensions/XTest.h>
44
#endif
45
 
46
#ifdef HAVE_XTEST
47
 
48
static int
49
awt_button_mask_to_num (int buttons)
50
{
51
  switch (buttons)
52
    {
53
    case AWT_BUTTON1_MASK:
54
      return 1;
55
    case AWT_BUTTON2_MASK:
56
      return 2;
57
    case AWT_BUTTON3_MASK:
58
      return 3;
59
    }
60
 
61
  return 0;
62
}
63
 
64
#endif
65
 
66
JNIEXPORT jboolean JNICALL
67
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_initXTest
68
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
69
{
70
 
71
#ifdef HAVE_XTEST
72
 
73
  GdkDisplay *display;
74
  Display *xdisplay;
75
  int event_basep;
76
  int error_basep;
77
  int majorp;
78
  int minorp;
79
  jboolean result;
80
 
81
  gdk_threads_enter ();
82
 
83
  display = gdk_display_get_default ();
84
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
85
 
86
  result = XTestQueryExtension (xdisplay,
87
                                &event_basep,
88
                                &error_basep,
89
                                &majorp,
90
                                &minorp);
91
 
92
  gdk_threads_leave ();
93
 
94
  return result;
95
 
96
#else
97
 
98
  return JNI_FALSE;
99
 
100
#endif
101
 
102
}
103
 
104
JNIEXPORT void JNICALL
105
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseMove
106
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint x, jint y)
107
{
108
 
109
#ifdef HAVE_XTEST
110
 
111
  GdkDisplay *display;
112
  Display *xdisplay;
113
  int result;
114
 
115
  gdk_threads_enter ();
116
 
117
  display = gdk_display_get_default ();
118
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
119
 
120
  result = XTestFakeMotionEvent (xdisplay,
121
                                 -1,
122
                                 x, y, CurrentTime);
123
 
124
  XFlush (xdisplay);
125
 
126
  gdk_threads_leave ();
127
 
128
#else
129
 
130
  (void) x; // Unused.
131
  (void) y; // Unused.
132
 
133
#endif
134
 
135
}
136
 
137
JNIEXPORT void JNICALL
138
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mousePress
139
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons)
140
{
141
 
142
#ifdef HAVE_XTEST
143
 
144
  GdkDisplay *display;
145
  Display *xdisplay;
146
  int result;
147
 
148
  gdk_threads_enter ();
149
 
150
  display = gdk_display_get_default ();
151
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
152
 
153
  result = XTestFakeButtonEvent (xdisplay,
154
                                 awt_button_mask_to_num (buttons),
155
                                 True, CurrentTime);
156
 
157
  XFlush (xdisplay);
158
 
159
  gdk_threads_leave ();
160
 
161
#else
162
 
163
  (void) buttons; // Unused.
164
 
165
#endif
166
 
167
}
168
 
169
JNIEXPORT void JNICALL
170
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseRelease
171
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint buttons)
172
{
173
 
174
#ifdef HAVE_XTEST
175
 
176
  GdkDisplay *display;
177
  Display *xdisplay;
178
  int result;
179
 
180
  gdk_threads_enter ();
181
 
182
  display = gdk_display_get_default ();
183
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
184
 
185
  result = XTestFakeButtonEvent (xdisplay,
186
                                 awt_button_mask_to_num (buttons),
187
                                 False, CurrentTime);
188
 
189
  XFlush (xdisplay);
190
 
191
  gdk_threads_leave ();
192
 
193
#else
194
 
195
  (void) buttons; // Unused.
196
 
197
#endif
198
 
199
}
200
 
201
JNIEXPORT void JNICALL
202
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_mouseWheel
203
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint wheelAmt)
204
{
205
 
206
#ifdef HAVE_XTEST
207
 
208
  GdkDisplay *display;
209
  Display *xdisplay;
210
  int i = 0;
211
 
212
  gdk_threads_enter ();
213
 
214
  display = gdk_display_get_default ();
215
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
216
 
217
  if (wheelAmt < 0)
218
    for (i = 0; i < -wheelAmt; i++)
219
      {
220
        XTestFakeButtonEvent (xdisplay,
221
                              4,
222
                              True, CurrentTime);
223
        XTestFakeButtonEvent (xdisplay,
224
                              4,
225
                              False, CurrentTime);
226
      }
227
  else
228
    for (i = 0; i < wheelAmt; i++)
229
      {
230
        XTestFakeButtonEvent (xdisplay,
231
                              5,
232
                              True, CurrentTime);
233
        XTestFakeButtonEvent (xdisplay,
234
                              5,
235
                              False, CurrentTime);
236
      }
237
 
238
  XFlush (xdisplay);
239
 
240
  gdk_threads_leave ();
241
 
242
#else
243
 
244
  (void) wheelAmt; // Unused.
245
 
246
#endif
247
 
248
}
249
 
250
JNIEXPORT void JNICALL
251
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyPress
252
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode)
253
{
254
 
255
#ifdef HAVE_XTEST
256
 
257
  GdkDisplay *display;
258
  Display *xdisplay;
259
  GdkKeymapKey *keymap_keys = NULL;
260
  gint n_keys = 0;
261
  guint lookup_keyval = 0;
262
  int result;
263
 
264
  gdk_threads_enter ();
265
 
266
  display = gdk_display_get_default ();
267
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
268
 
269
  lookup_keyval = cp_gtk_awt_keycode_to_keysym (keycode,
270
                                                       AWT_KEY_LOCATION_LEFT);
271
 
272
  if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
273
                                          lookup_keyval,
274
                                          &keymap_keys,
275
                                          &n_keys))
276
    {
277
      /* No matching keymap entry was found. */
278
      g_printerr ("No matching keymap entries were found\n");
279
      gdk_threads_leave ();
280
      return;
281
    }
282
 
283
  /* If n_keys > 1 then there are multiple hardware keycodes that
284
     translate to lookup_keyval.  We arbitrarily choose the first
285
     hardware keycode from the list returned by
286
     gdk_keymap_get_entries_for_keyval. */
287
  result = XTestFakeKeyEvent (xdisplay,
288
                              keymap_keys[0].keycode,
289
                              True, CurrentTime);
290
 
291
  g_free (keymap_keys);
292
 
293
  XFlush (xdisplay);
294
 
295
  gdk_threads_leave ();
296
 
297
#else
298
 
299
  (void) keycode; // Unused.
300
 
301
#endif
302
 
303
}
304
 
305
JNIEXPORT void JNICALL
306
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_keyRelease
307
  (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)), jint keycode)
308
{
309
 
310
#ifdef HAVE_XTEST
311
 
312
  GdkDisplay *display;
313
  Display *xdisplay;
314
  GdkKeymapKey *keymap_keys = NULL;
315
  gint n_keys = 0;
316
  guint lookup_keyval = 0;
317
  int result;
318
 
319
  gdk_threads_enter ();
320
 
321
  display = gdk_display_get_default ();
322
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
323
 
324
  lookup_keyval = cp_gtk_awt_keycode_to_keysym (keycode,
325
                                                       AWT_KEY_LOCATION_LEFT);
326
 
327
  if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
328
                                          lookup_keyval,
329
                                          &keymap_keys,
330
                                          &n_keys))
331
    {
332
      /* No matching keymap entry was found. */
333
      g_printerr ("No matching keymap entries were found\n");
334
      gdk_threads_leave ();
335
      return;
336
    }
337
 
338
  /* If n_keys > 1 then there are multiple hardware keycodes that
339
     translate to lookup_keyval.  We arbitrarily choose the first
340
     hardware keycode from the list returned by
341
     gdk_keymap_get_entries_for_keyval. */
342
  result = XTestFakeKeyEvent (xdisplay,
343
                              keymap_keys[0].keycode,
344
                              False, CurrentTime);
345
 
346
  g_free (keymap_keys);
347
 
348
  XFlush (xdisplay);
349
 
350
  gdk_threads_leave ();
351
 
352
#else
353
 
354
  (void) keycode; // Unused.
355
 
356
#endif
357
 
358
}
359
 
360
JNIEXPORT jintArray JNICALL
361
Java_gnu_java_awt_peer_gtk_GdkRobotPeer_nativeGetRGBPixels
362
  (JNIEnv *env, jobject obj __attribute__((unused)), jint x, jint y,
363
   jint width, jint height)
364
{
365
 
366
#ifdef HAVE_XTEST
367
 
368
  jint stride_bytes, stride_pixels, n_channels, n_pixels;
369
  jintArray jpixels;
370
  jint *java_pixels;
371
  guchar *gdk_pixels;
372
  GdkPixbuf *pixbuf_no_alpha = NULL;
373
  GdkPixbuf *pixbuf = NULL;
374
 
375
#ifndef WORDS_BIGENDIAN
376
  int i;
377
#endif
378
 
379
  gdk_threads_enter ();
380
 
381
  pixbuf_no_alpha = gdk_pixbuf_get_from_drawable (NULL,
382
                                                  gdk_get_default_root_window (),
383
                                                  NULL, x, y, 0, 0,
384
                                                  width, height);
385
 
386
  pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0);
387
  g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
388
 
389
  stride_bytes = gdk_pixbuf_get_rowstride (pixbuf);
390
  n_channels = gdk_pixbuf_get_n_channels (pixbuf);
391
  stride_pixels =  stride_bytes / n_channels;
392
  n_pixels = height * stride_pixels;
393
  gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
394
 
395
  jpixels = (*env)->NewIntArray (env, n_pixels);
396
 
397
  java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL);
398
 
399
  memcpy (java_pixels,
400
          gdk_pixels,
401
          (height * stride_bytes));
402
 
403
#ifndef WORDS_BIGENDIAN
404
  /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */
405
  for (i = 0; i < n_pixels; ++i)
406
    {
407
      java_pixels[i] = SWAPU32 ((unsigned)java_pixels[i]);
408
    }
409
#endif
410
 
411
  g_object_unref (pixbuf);
412
 
413
  (*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0);
414
 
415
  gdk_threads_leave ();
416
 
417
  return jpixels;
418
 
419
#else
420
 
421
  (void) env;
422
  (void) x;
423
  (void) y;
424
  (void) width;
425
  (void) height;
426
  return NULL;
427
 
428
#endif
429
 
430
}

powered by: WebSVN 2.1.0

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