gdk3 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Rakefile +53 -0
  2. data/ext/gdk3/depend +11 -0
  3. data/ext/gdk3/extconf.rb +127 -0
  4. data/ext/gdk3/gdk3.def +12 -0
  5. data/ext/gdk3/init.c +35 -0
  6. data/ext/gdk3/rbgdk.c +540 -0
  7. data/ext/gdk3/rbgdk3.h +71 -0
  8. data/ext/gdk3/rbgdk3conversions.h +118 -0
  9. data/ext/gdk3/rbgdk3private.h +93 -0
  10. data/ext/gdk3/rbgdkatom.c +122 -0
  11. data/ext/gdk3/rbgdkcairo.c +95 -0
  12. data/ext/gdk3/rbgdkcolor.c +137 -0
  13. data/ext/gdk3/rbgdkconst.c +33 -0
  14. data/ext/gdk3/rbgdkcursor.c +99 -0
  15. data/ext/gdk3/rbgdkdevice.c +197 -0
  16. data/ext/gdk3/rbgdkdisplay.c +482 -0
  17. data/ext/gdk3/rbgdkdisplaymanager.c +55 -0
  18. data/ext/gdk3/rbgdkdragcontext.c +191 -0
  19. data/ext/gdk3/rbgdkdraw.c +520 -0
  20. data/ext/gdk3/rbgdkevent.c +926 -0
  21. data/ext/gdk3/rbgdkgeometry.c +252 -0
  22. data/ext/gdk3/rbgdkkeymap.c +151 -0
  23. data/ext/gdk3/rbgdkkeyval.c +108 -0
  24. data/ext/gdk3/rbgdkpango.c +197 -0
  25. data/ext/gdk3/rbgdkpangorenderer.c +144 -0
  26. data/ext/gdk3/rbgdkpixbuf.c +176 -0
  27. data/ext/gdk3/rbgdkproperty.c +305 -0
  28. data/ext/gdk3/rbgdkrectangle.c +140 -0
  29. data/ext/gdk3/rbgdkrgb.c +199 -0
  30. data/ext/gdk3/rbgdkrgba.c +142 -0
  31. data/ext/gdk3/rbgdkscreen.c +443 -0
  32. data/ext/gdk3/rbgdkselection.c +146 -0
  33. data/ext/gdk3/rbgdkthreads.c +77 -0
  34. data/ext/gdk3/rbgdktimecoord.c +133 -0
  35. data/ext/gdk3/rbgdkvisual.c +251 -0
  36. data/ext/gdk3/rbgdkwindow.c +1044 -0
  37. data/ext/gdk3/rbgdkwindowattr.c +191 -0
  38. data/ext/gdk3/rbgdkx11.c +102 -0
  39. data/ext/gdk3/rbgdkx11x11window.c +66 -0
  40. data/extconf.rb +49 -0
  41. data/lib/gdk3.rb +3 -0
  42. data/lib/gdk3/base.rb +50 -0
  43. data/lib/gdk3/deprecated.rb +152 -0
  44. metadata +156 -0
@@ -0,0 +1,926 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
+ * Copyright (C) 2002-2004 Ruby-GNOME2 Project Team
5
+ * Copyright (C) 1998-2000 Yukihiro Matsumoto,
6
+ * Daisuke Kanda,
7
+ * Hiroshi Igarashi
8
+ *
9
+ * This library is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 2.1 of the License, or (at your option) any later version.
13
+ *
14
+ * This library is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with this library; if not, write to the Free Software
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
+ * MA 02110-1301 USA
23
+ */
24
+
25
+ #include "rbgdk3private.h"
26
+
27
+ static VALUE gdkevents[36];
28
+
29
+ /***********************************************/
30
+
31
+ VALUE
32
+ make_gdkevent(GdkEvent *ev)
33
+ {
34
+ VALUE obj;
35
+ if (ev == NULL) return Qnil;
36
+
37
+ obj = GDKEVENT2RVAL(ev);
38
+ RBASIC(obj)->klass = gdkevents[ev->type]; /* hack */
39
+ return obj;
40
+ }
41
+
42
+ GdkEvent*
43
+ get_gdkevent(VALUE event)
44
+ {
45
+ return NIL_P(event) ? NULL : RVAL2GDKEVENT(event);
46
+ }
47
+
48
+ /***********************************************/
49
+ #define ATTR_STR(type, name)\
50
+ static VALUE \
51
+ gdkevent ## type ## _ ## name (VALUE self)\
52
+ {\
53
+ return CSTR2RVAL(get_gdkevent(self)->type.name);\
54
+ }\
55
+ static VALUE \
56
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
57
+ {\
58
+ get_gdkevent(self)->type.name = (gchar *)RVAL2CSTR(val);\
59
+ return self;\
60
+ }
61
+
62
+ #define ATTR_INT(type, name)\
63
+ static VALUE \
64
+ gdkevent ## type ## _ ## name (VALUE self)\
65
+ {\
66
+ return INT2NUM(get_gdkevent(self)->type.name);\
67
+ }\
68
+ static VALUE \
69
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
70
+ {\
71
+ get_gdkevent(self)->type.name = NUM2INT(val);\
72
+ return self;\
73
+ }
74
+
75
+ #define ATTR_UINT(type, name)\
76
+ static VALUE \
77
+ gdkevent ## type ## _ ## name (VALUE self)\
78
+ {\
79
+ return UINT2NUM(get_gdkevent(self)->type.name);\
80
+ }\
81
+ static VALUE \
82
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
83
+ {\
84
+ get_gdkevent(self)->type.name = NUM2UINT(val);\
85
+ return self;\
86
+ }
87
+
88
+ #define ATTR_GDKWINDOW(type, name)\
89
+ static VALUE \
90
+ gdkevent ## type ## _ ## name (VALUE self)\
91
+ {\
92
+ return GOBJ2RVAL(get_gdkevent(self)->type.name);\
93
+ }\
94
+ static VALUE \
95
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
96
+ {\
97
+ get_gdkevent(self)->type.name = RVAL2GDKWINDOW(val);\
98
+ return self;\
99
+ }
100
+
101
+ #define ATTR_FLOAT(type, name)\
102
+ static VALUE \
103
+ gdkevent ## type ## _ ## name (VALUE self)\
104
+ {\
105
+ return rb_float_new(get_gdkevent(self)->type.name);\
106
+ }\
107
+ static VALUE \
108
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
109
+ {\
110
+ get_gdkevent(self)->type.name = NUM2DBL(val);\
111
+ return self;\
112
+ }
113
+
114
+ #define ATTR_GOBJ(type, name)\
115
+ static VALUE \
116
+ gdkevent ## type ## _ ## name (VALUE self)\
117
+ {\
118
+ return GOBJ2RVAL(get_gdkevent(self)->type.name);\
119
+ }\
120
+ static VALUE \
121
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
122
+ {\
123
+ GdkEvent *event;\
124
+ event = get_gdkevent(self);\
125
+ if (event->type.name)\
126
+ g_object_unref(event->type.name);\
127
+ event->type.name = RVAL2GOBJ(val);\
128
+ if (event->type.name)\
129
+ g_object_ref(event->type.name);\
130
+ return self;\
131
+ }
132
+
133
+ #define ATTR_BOOL(type, name)\
134
+ static VALUE \
135
+ gdkevent ## type ## _ ## name (VALUE self)\
136
+ {\
137
+ return CBOOL2RVAL(get_gdkevent(self)->type.name);\
138
+ }\
139
+ static VALUE \
140
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
141
+ {\
142
+ get_gdkevent(self)->type.name = RVAL2CBOOL(val);\
143
+ return self;\
144
+ }
145
+
146
+ #define ATTR_ATOM(type, name)\
147
+ static VALUE \
148
+ gdkevent ## type ## _ ## name (VALUE self)\
149
+ {\
150
+ GdkAtom atom = get_gdkevent(self)->type.name;\
151
+ return GDKATOM2RVAL(atom);\
152
+ }\
153
+ static VALUE \
154
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
155
+ {\
156
+ get_gdkevent(self)->type.name = RVAL2ATOM(val);\
157
+ return self;\
158
+ }
159
+
160
+ #define ATTR_FLAGS(type, name, gtype)\
161
+ static VALUE \
162
+ gdkevent ## type ## _ ## name (VALUE self)\
163
+ {\
164
+ return GFLAGS2RVAL(get_gdkevent(self)->type.name, gtype);\
165
+ }\
166
+ static VALUE \
167
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
168
+ {\
169
+ get_gdkevent(self)->type.name = RVAL2GFLAGS(val, gtype);\
170
+ return self;\
171
+ }
172
+
173
+ #define ATTR_ENUM(type, name, gtype)\
174
+ static VALUE \
175
+ gdkevent ## type ## _ ## name (VALUE self)\
176
+ {\
177
+ return GENUM2RVAL(get_gdkevent(self)->type.name, gtype);\
178
+ }\
179
+ static VALUE \
180
+ gdkevent ## type ## _set_ ## name (VALUE self, VALUE val)\
181
+ {\
182
+ get_gdkevent(self)->type.name = RVAL2GENUM(val, gtype);\
183
+ return self;\
184
+ }
185
+
186
+ #define ATTR_AXES(type, gdkklass) \
187
+ static VALUE \
188
+ gdkevent ##type ## _axes(VALUE self)\
189
+ {\
190
+ gdkklass type = get_gdkevent(self)->type;\
191
+ return type.axes ? rb_ary_new3(2, \
192
+ rb_float_new(type.axes[0]),\
193
+ rb_float_new(type.axes[1])) : Qnil;\
194
+ } \
195
+ static VALUE \
196
+ gdkevent ## type ## _set_axes(VALUE self, VALUE x, VALUE y)\
197
+ {\
198
+ gdkklass val = get_gdkevent(self)->type;\
199
+ val.axes[0] = NUM2DBL(x);\
200
+ val.axes[1] = NUM2DBL(y);\
201
+ return self;\
202
+ }
203
+
204
+ #define DEFINE_ACCESSOR(event, type, name) \
205
+ rbg_define_method(event, G_STRINGIFY(name), gdkevent ## type ## _## name, 0);\
206
+ rbg_define_method(event, G_STRINGIFY(set_ ## name), gdkevent ## type ## _set_## name, 1);
207
+
208
+
209
+ /* initialize */
210
+ #define GDKEVENT_INIT(type, default_gtype) \
211
+ static VALUE \
212
+ gdkevent ## type ## _initialize(int argc, VALUE *argv, VALUE self)\
213
+ {\
214
+ VALUE type;\
215
+ GdkEventType gtype;\
216
+ \
217
+ rb_scan_args(argc, argv, "01", &type);\
218
+ if (NIL_P(type)){\
219
+ gtype = default_gtype;\
220
+ } else {\
221
+ gtype = RVAL2GDKEVENTTYPE(type);\
222
+ }\
223
+ \
224
+ G_INITIALIZE(self, gdk_event_new(gtype));\
225
+ return Qnil;\
226
+ }
227
+
228
+ #define DEFINE_INIT(event, type) \
229
+ rbg_define_method(event, "initialize", gdkevent ## type ## _initialize, -1);
230
+
231
+ /***********************************************/
232
+
233
+ /* GdkEvent Singleton Methods */
234
+ static VALUE
235
+ gdkevent_s_events_pending(G_GNUC_UNUSED VALUE self)
236
+ {
237
+ return CBOOL2RVAL(gdk_events_pending());
238
+ }
239
+
240
+ static VALUE
241
+ gdkevent_s_peek(G_GNUC_UNUSED VALUE self)
242
+ {
243
+ return make_gdkevent(gdk_event_peek());
244
+ }
245
+
246
+ static VALUE
247
+ gdkevent_s_get(G_GNUC_UNUSED VALUE self)
248
+ {
249
+ return make_gdkevent(gdk_event_get());
250
+ }
251
+
252
+ /* deprecated
253
+ static VALUE
254
+ gdkevent_s_get_graphics_expose(G_GNUC_UNUSED VALUE self, VALUE window)
255
+ {
256
+ return make_gdkevent(gdk_event_get_graphics_expose(RVAL2GDKWINDOW(window)));
257
+ }
258
+ */
259
+
260
+ /* GdkEvent */
261
+ static VALUE
262
+ gdkevent_initialize(VALUE self, VALUE type)
263
+ {
264
+ GdkEventType gtype = RVAL2GDKEVENTTYPE(type);
265
+ if (RBASIC(self)->klass != gdkevents[gtype])
266
+ rb_raise(rb_eArgError, "Wrong event type for this class.");
267
+
268
+ G_INITIALIZE(self, gdk_event_new(gtype));
269
+ return Qnil;
270
+ }
271
+
272
+ static VALUE
273
+ gdkevent_type(VALUE self)
274
+ {
275
+ return GDKEVENTTYPE2RVAL(get_gdkevent(self)->type);
276
+ }
277
+
278
+ static VALUE
279
+ gdkevent_put(VALUE self)
280
+ {
281
+ gdk_event_put(get_gdkevent(self));
282
+ return self;
283
+ }
284
+
285
+ /* We don't need this.
286
+ gdk_event_get_time();
287
+ gboolean gdk_event_get_state (GdkEvent *event,
288
+ GdkModifierType *state);
289
+ */
290
+
291
+ static VALUE
292
+ gdkevent_get_axis(VALUE self, VALUE axis_use)
293
+ {
294
+ gdouble value;
295
+ gboolean ret = gdk_event_get_axis(get_gdkevent(self),
296
+ RVAL2GDKAXISUSE(axis_use), &value);
297
+ return ret ? rb_float_new(value) : Qnil;
298
+ }
299
+
300
+ static VALUE
301
+ gdkevent_get_coords(VALUE self)
302
+ {
303
+ gdouble x_win, y_win;
304
+ gboolean ret = gdk_event_get_coords(get_gdkevent(self), &x_win, &y_win);
305
+
306
+ return ret ? rb_ary_new3(2, rb_float_new(x_win), rb_float_new(y_win)) : Qnil;
307
+ }
308
+
309
+ static VALUE
310
+ gdkevent_get_root_coords(VALUE self)
311
+ {
312
+ gdouble x_root, y_root;
313
+ gboolean ret = gdk_event_get_root_coords(get_gdkevent(self), &x_root, &y_root);
314
+
315
+ return ret ? rb_ary_new3(2, rb_float_new(x_root), rb_float_new(y_root)) : Qnil;
316
+ }
317
+
318
+ static void
319
+ handler_func(GdkEvent *event, gpointer func)
320
+ {
321
+ rb_funcall((VALUE)func, id_call, 1, make_gdkevent(event));
322
+ }
323
+
324
+ static VALUE
325
+ gdkevent_s_handler_set(VALUE self)
326
+ {
327
+ volatile VALUE func = rb_block_proc();
328
+ G_RELATIVE(self, func);
329
+
330
+ gdk_event_handler_set((GdkEventFunc)handler_func, (gpointer)func, NULL);
331
+ return self;
332
+ }
333
+
334
+ static VALUE
335
+ gdkevent_s_get_show_events(G_GNUC_UNUSED VALUE self)
336
+ {
337
+ return CBOOL2RVAL(gdk_get_show_events());
338
+ }
339
+
340
+ static VALUE
341
+ gdkevent_s_set_show_events(VALUE self, VALUE show_events)
342
+ {
343
+ gdk_set_show_events(RVAL2CBOOL(show_events));
344
+ return self;
345
+ }
346
+
347
+ static VALUE
348
+ gdkevent_set_screen(VALUE self, VALUE screen)
349
+ {
350
+ gdk_event_set_screen(get_gdkevent(self), RVAL2GDKSCREEN(screen));
351
+ return self;
352
+ }
353
+
354
+ static VALUE
355
+ gdkevent_screen(VALUE self)
356
+ {
357
+ return GOBJ2RVAL(gdk_event_get_screen(get_gdkevent(self)));
358
+ }
359
+
360
+ /*
361
+ type: String, Integer, Gdk::Color.
362
+ */
363
+ static VALUE
364
+ gdkevent_s_setting_get(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
365
+ {
366
+ VALUE name, type;
367
+ GType gtype;
368
+ GValue val = G_VALUE_INIT;
369
+ gboolean ret;
370
+ VALUE value;
371
+
372
+ rb_scan_args(argc, argv, "11", &name, &type);
373
+ if NIL_P(type)
374
+ gtype = G_TYPE_STRING;
375
+ else
376
+ gtype = CLASS2GTYPE(type);
377
+
378
+ g_value_init(&val, gtype);
379
+ ret = gdk_setting_get(RVAL2CSTR(name), &val);
380
+
381
+ value = ret ? GVAL2RVAL(&val) : Qnil;
382
+ g_value_unset(&val);
383
+ return value;
384
+ }
385
+
386
+ /* GdkEventAny */
387
+ ATTR_GOBJ(any, window);
388
+ ATTR_BOOL(any, send_event);
389
+
390
+ /* GdkEventKey */
391
+ ATTR_UINT(key, time);
392
+ ATTR_FLAGS(key, state, GDK_TYPE_MODIFIER_TYPE);
393
+ ATTR_INT(key, keyval);
394
+ ATTR_UINT(key, hardware_keycode);
395
+ ATTR_UINT(key, group);
396
+
397
+ /* GdkEventButton */
398
+ ATTR_UINT(button, time);
399
+ ATTR_FLOAT(button, x);
400
+ ATTR_FLOAT(button, y);
401
+ ATTR_AXES(button, GdkEventButton);
402
+ ATTR_INT(button, button);
403
+ ATTR_FLAGS(button, state, GDK_TYPE_MODIFIER_TYPE);
404
+ ATTR_GOBJ(button, device);
405
+ ATTR_FLOAT(button, x_root);
406
+ ATTR_FLOAT(button, y_root);
407
+
408
+ /* GdkEventScroll */
409
+ ATTR_UINT(scroll, time);
410
+ ATTR_FLOAT(scroll, x);
411
+ ATTR_FLOAT(scroll, y);
412
+ ATTR_FLAGS(scroll, state, GDK_TYPE_MODIFIER_TYPE);
413
+ ATTR_ENUM(scroll, direction, GDK_TYPE_SCROLL_DIRECTION);
414
+ ATTR_GOBJ(scroll, device);
415
+ ATTR_FLOAT(scroll, x_root);
416
+ ATTR_FLOAT(scroll, y_root);
417
+ GDKEVENT_INIT(scroll, GDK_SCROLL);
418
+
419
+ /* GdkEventMotion */
420
+ ATTR_UINT(motion, time);
421
+ ATTR_FLOAT(motion, x);
422
+ ATTR_FLOAT(motion, y);
423
+ ATTR_AXES(motion, GdkEventMotion);
424
+ ATTR_FLOAT(motion, x_root);
425
+ ATTR_FLOAT(motion, y_root);
426
+ ATTR_FLAGS(motion, state, GDK_TYPE_MODIFIER_TYPE);
427
+ ATTR_BOOL(motion, is_hint);
428
+ ATTR_GOBJ(motion, device);
429
+ GDKEVENT_INIT(motion, GDK_MOTION_NOTIFY);
430
+
431
+ static VALUE
432
+ gdkeventmotion_request_motions(VALUE self)
433
+ {
434
+ gdk_event_request_motions(&(get_gdkevent(self)->motion));
435
+ return self;
436
+ }
437
+
438
+ /* GdkEventExpose */
439
+ /* deprecated
440
+ static VALUE
441
+ gdkeventexpose_area(VALUE self)
442
+ {
443
+ return GDKRECTANGLE2RVAL(&get_gdkevent(self)->expose.area);
444
+ }
445
+
446
+ static VALUE
447
+ gdkeventexpose_set_area(VALUE self, VALUE rect)
448
+ {
449
+ GdkRectangle* grect = RVAL2GDKRECTANGLE(rect);
450
+ GdkEventExpose event = get_gdkevent(self)->expose;
451
+ event.area.x = grect->x;
452
+ event.area.y = grect->y;
453
+ event.area.width = grect->width;
454
+ event.area.height = grect->height;
455
+ return self;
456
+ }
457
+
458
+ static VALUE
459
+ gdkeventexpose_region(VALUE self)
460
+ {
461
+ return GDKREGION2RVAL(get_gdkevent(self)->expose.region);
462
+ }
463
+ static VALUE
464
+ gdkeventexpose_set_region(VALUE self, VALUE region)
465
+ {
466
+ get_gdkevent(self)->expose.region = RVAL2GDKREGION(region);
467
+ return self;
468
+ }
469
+
470
+ ATTR_INT(expose, count);
471
+ GDKEVENT_INIT(expose, GDK_EXPOSE);
472
+ */
473
+
474
+ /* GdkEventVisibility */
475
+ ATTR_ENUM(visibility, state, GDK_TYPE_VISIBILITY_STATE);
476
+ GDKEVENT_INIT(visibility, GDK_VISIBILITY_NOTIFY);
477
+
478
+ /* GdkEventCrossing */
479
+ ATTR_GOBJ(crossing, subwindow);
480
+ ATTR_UINT(crossing, time);
481
+ ATTR_INT(crossing, x);
482
+ ATTR_INT(crossing, y);
483
+ ATTR_FLOAT(crossing, x_root);
484
+ ATTR_FLOAT(crossing, y_root);
485
+ ATTR_ENUM(crossing, mode, GDK_TYPE_CROSSING_MODE);
486
+ ATTR_ENUM(crossing, detail, GDK_TYPE_NOTIFY_TYPE);
487
+ ATTR_BOOL(crossing, focus);
488
+ ATTR_FLAGS(crossing, state, GDK_TYPE_MODIFIER_TYPE);
489
+
490
+ /* GdkEventFocus */
491
+ ATTR_BOOL(focus_change, in);
492
+ GDKEVENT_INIT(focus_change, GDK_FOCUS_CHANGE);
493
+
494
+ /* GdkEventConfigure */
495
+ ATTR_INT(configure, x);
496
+ ATTR_INT(configure, y);
497
+ ATTR_INT(configure, width);
498
+ ATTR_INT(configure, height);
499
+ GDKEVENT_INIT(configure, GDK_CONFIGURE);
500
+
501
+ /* GdkEventProperty */
502
+ ATTR_ATOM(property, atom);
503
+ ATTR_UINT(property, time);
504
+ ATTR_ENUM(property, state, GDK_TYPE_PROPERTY_STATE);
505
+ GDKEVENT_INIT(property, GDK_PROPERTY_NOTIFY);
506
+
507
+ /* GdkEventSelection */
508
+ ATTR_ATOM(selection, selection);
509
+ ATTR_ATOM(selection, target);
510
+ ATTR_ATOM(selection, property);
511
+ ATTR_GDKWINDOW(selection, requestor);
512
+ ATTR_INT(selection, time);
513
+
514
+ /* GdkEventDND */
515
+ ATTR_GOBJ(dnd, context);
516
+ ATTR_UINT(dnd, time);
517
+ ATTR_INT(dnd, x_root);
518
+ ATTR_INT(dnd, y_root);
519
+
520
+ /* GdkEventProximity */
521
+ ATTR_UINT(proximity, time);
522
+ ATTR_GOBJ(proximity, device);
523
+
524
+ /* GdkEventClient */
525
+ /* deprecated
526
+ ATTR_ATOM(client, message_type);
527
+ GDKEVENT_INIT(client, GDK_CLIENT_EVENT);
528
+
529
+ static VALUE
530
+ gdkeventclient_data_format(VALUE self)
531
+ {
532
+ return INT2NUM(get_gdkevent(self)->client.data_format);
533
+ }
534
+
535
+ static VALUE
536
+ gdkeventclient_data(VALUE self)
537
+ {
538
+ int i;
539
+ VALUE ary = Qnil;
540
+ gushort format = get_gdkevent(self)->client.data_format;
541
+
542
+ if (format == 8) {
543
+ ary = rb_ary_new2(20);
544
+ for (i = 0; i < 20; i++)
545
+ rb_ary_push(ary, INT2FIX(get_gdkevent(self)->client.data.b[i]));
546
+ } else if (format == 16) {
547
+ ary = rb_ary_new2(10);
548
+ for (i = 0; i<10; i++)
549
+ rb_ary_push(ary, INT2FIX(get_gdkevent(self)->client.data.s[i]));
550
+ } else if (format == 32){
551
+ ary = rb_ary_new2(5);
552
+ for (i = 0; i < 5; i++)
553
+ rb_ary_push(ary, INT2NUM(get_gdkevent(self)->client.data.l[i]));
554
+ } else {
555
+ rb_warn("The format is not supported.");
556
+ }
557
+ return ary;
558
+ }
559
+
560
+ static VALUE
561
+ gdkeventclient_send_client_message(int argc, VALUE *argv, VALUE self)
562
+ {
563
+ VALUE xid, display;
564
+ rb_scan_args(argc, argv, "11", &xid, &display);
565
+ if (NIL_P(display)){
566
+ return CBOOL2RVAL(gdk_event_send_client_message(
567
+ get_gdkevent(self), RVAL2GDKNATIVEWINDOW(xid)));
568
+ } else {
569
+ return CBOOL2RVAL(gdk_event_send_client_message_for_display(
570
+ RVAL2GDKDISPLAYOBJECT(display),
571
+ get_gdkevent(self),
572
+ RVAL2GDKNATIVEWINDOW(xid)));
573
+ }
574
+ }
575
+
576
+ static VALUE
577
+ gdkeventclient_send_clientmessage_toall(VALUE self)
578
+ {
579
+ gdk_event_send_clientmessage_toall(get_gdkevent(self));
580
+ return self;
581
+ }
582
+
583
+ static GdkFilterReturn
584
+ filter_func(GdkXEvent *xevent, GdkEvent *event, gpointer func)
585
+ {
586
+ VALUE ret = rb_funcall((VALUE)func, id_call, 2, LONG2NUM((glong)xevent), make_gdkevent(event));
587
+ return RVAL2GDKFILTERRETURN(ret);
588
+ }
589
+
590
+ static VALUE
591
+ gdkevent_s_add_client_message_filter(VALUE self, VALUE message_type)
592
+ {
593
+ volatile VALUE func = rb_block_proc();
594
+ G_RELATIVE(self, func);
595
+ gdk_add_client_message_filter(RVAL2ATOM(message_type),
596
+ (GdkFilterFunc)filter_func, (gpointer)func);
597
+ return self;
598
+ }
599
+ */
600
+
601
+ /* GdkEventNoExpose */
602
+ /* deprecated
603
+ GDKEVENT_INIT(noexpose, GDK_NO_EXPOSE);
604
+ */
605
+
606
+ /* GdkEventWindowState */
607
+ ATTR_FLAGS(window_state, changed_mask, GDK_TYPE_WINDOW_STATE);
608
+ ATTR_FLAGS(window_state, new_window_state, GDK_TYPE_WINDOW_STATE);
609
+ GDKEVENT_INIT(window_state, GDK_WINDOW_STATE);
610
+
611
+ /* GdkEventSetting */
612
+ ATTR_ENUM(setting, action, GDK_TYPE_SETTING_ACTION);
613
+ ATTR_STR(setting, name);
614
+ GDKEVENT_INIT(setting, GDK_SETTING);
615
+
616
+ /* GdkEventOwnerChange */
617
+ ATTR_GDKWINDOW(owner_change, owner);
618
+ ATTR_ENUM(owner_change, reason, GDK_TYPE_OWNER_CHANGE);
619
+ ATTR_ATOM(owner_change, selection);
620
+ ATTR_UINT(owner_change, time);
621
+ ATTR_UINT(owner_change, selection_time);
622
+ GDKEVENT_INIT(owner_change, GDK_OWNER_CHANGE);
623
+
624
+ /* GdkEventGrabBroken */
625
+ ATTR_BOOL(grab_broken, keyboard);
626
+ ATTR_BOOL(grab_broken, implicit);
627
+ ATTR_GOBJ(grab_broken, grab_window);
628
+ GDKEVENT_INIT(grab_broken, GDK_GRAB_BROKEN);
629
+
630
+ /* MISC */
631
+ static VALUE
632
+ gdkevent_g2r(const GValue *values)
633
+ {
634
+ return make_gdkevent(g_value_get_boxed(&values[0]));
635
+ }
636
+
637
+ void
638
+ Init_gdk_event(VALUE mGdk)
639
+ {
640
+ VALUE ev;
641
+ VALUE gdkEvent;
642
+ VALUE gdkEventAny;
643
+
644
+ gdkEvent = G_DEF_CLASS(GDK_TYPE_EVENT, "Event", mGdk);
645
+ gdkEventAny = rb_define_class_under(mGdk, "EventAny", gdkEvent);
646
+
647
+ gdkevents[GDK_DELETE] = gdkEventAny;
648
+ gdkevents[GDK_DESTROY] = gdkEventAny;
649
+ /* deprecated
650
+ gdkevents[GDK_EXPOSE] = rb_define_class_under(mGdk, "EventExpose", gdkEventAny);
651
+ */
652
+ gdkevents[GDK_MOTION_NOTIFY] = rb_define_class_under(mGdk, "EventMotion", gdkEventAny);
653
+ gdkevents[GDK_BUTTON_PRESS] = rb_define_class_under(mGdk, "EventButton", gdkEventAny);
654
+ gdkevents[GDK_2BUTTON_PRESS] = gdkevents[GDK_BUTTON_PRESS];
655
+ gdkevents[GDK_3BUTTON_PRESS] = gdkevents[GDK_BUTTON_PRESS];
656
+ gdkevents[GDK_BUTTON_RELEASE]= gdkevents[GDK_BUTTON_PRESS];
657
+ gdkevents[GDK_KEY_PRESS] = rb_define_class_under(mGdk, "EventKey", gdkEventAny);
658
+ gdkevents[GDK_KEY_RELEASE] = gdkevents[GDK_KEY_PRESS];
659
+ gdkevents[GDK_ENTER_NOTIFY] = rb_define_class_under(mGdk, "EventCrossing", gdkEventAny);
660
+ gdkevents[GDK_LEAVE_NOTIFY] = gdkevents[GDK_ENTER_NOTIFY];
661
+ gdkevents[GDK_FOCUS_CHANGE] = rb_define_class_under(mGdk, "EventFocus", gdkEventAny);
662
+ gdkevents[GDK_CONFIGURE] = rb_define_class_under(mGdk, "EventConfigure", gdkEventAny);
663
+ gdkevents[GDK_MAP] = gdkEventAny;
664
+ gdkevents[GDK_UNMAP] = gdkEventAny;
665
+ gdkevents[GDK_PROPERTY_NOTIFY]= rb_define_class_under(mGdk, "EventProperty", gdkEventAny);
666
+ gdkevents[GDK_SELECTION_CLEAR]= rb_define_class_under(mGdk, "EventSelection", gdkEventAny);
667
+ gdkevents[GDK_SELECTION_REQUEST]= gdkevents[GDK_SELECTION_CLEAR];
668
+ gdkevents[GDK_SELECTION_NOTIFY] = gdkevents[GDK_SELECTION_CLEAR];
669
+ gdkevents[GDK_PROXIMITY_IN] = rb_define_class_under(mGdk, "EventProximity", gdkEventAny);
670
+ gdkevents[GDK_PROXIMITY_OUT] = gdkevents[GDK_PROXIMITY_IN];
671
+ gdkevents[GDK_DRAG_ENTER] = rb_define_class_under(mGdk, "EventDND", gdkEventAny);
672
+ gdkevents[GDK_DRAG_LEAVE] = gdkevents[GDK_DRAG_ENTER];
673
+ gdkevents[GDK_DRAG_MOTION] = gdkevents[GDK_DRAG_ENTER];
674
+ gdkevents[GDK_DRAG_STATUS] = gdkevents[GDK_DRAG_ENTER];
675
+ gdkevents[GDK_DROP_START] = gdkevents[GDK_DRAG_ENTER];
676
+ gdkevents[GDK_DROP_FINISHED] = gdkevents[GDK_DRAG_ENTER];
677
+ gdkevents[GDK_CLIENT_EVENT] = rb_define_class_under(mGdk, "EventClient", gdkEventAny);
678
+ gdkevents[GDK_VISIBILITY_NOTIFY] = rb_define_class_under(mGdk, "EventVisibility", gdkEventAny);
679
+ /* deprecated
680
+ gdkevents[GDK_NO_EXPOSE] = rb_define_class_under(mGdk, "EventNoExpose", gdkEventAny);
681
+ */
682
+ gdkevents[GDK_SCROLL] = rb_define_class_under(mGdk, "EventScroll", gdkEventAny);
683
+ gdkevents[GDK_WINDOW_STATE] = rb_define_class_under(mGdk, "EventWindowState", gdkEventAny);
684
+ gdkevents[GDK_SETTING] = rb_define_class_under(mGdk, "EventSetting", gdkEventAny);
685
+ gdkevents[GDK_OWNER_CHANGE] = rb_define_class_under(mGdk, "EventOwnerChange", gdkEventAny);
686
+ gdkevents[GDK_GRAB_BROKEN] = rb_define_class_under(mGdk, "EventGrabBroken", gdkEventAny);
687
+
688
+ /* GdkEvent */
689
+ rbg_define_method(gdkEvent, "initialize", gdkevent_initialize, 1);
690
+ rbg_define_method(gdkEvent, "event_type", gdkevent_type, 0);
691
+
692
+ rbg_define_singleton_method(gdkEvent, "events_pending?", gdkevent_s_events_pending, 0);
693
+ rbg_define_singleton_method(gdkEvent, "peek", gdkevent_s_peek, 0);
694
+ rbg_define_singleton_method(gdkEvent, "get", gdkevent_s_get, 0);
695
+ rbg_define_method(gdkEvent, "put", gdkevent_put, 0);
696
+ rbg_define_method(gdkEvent, "get_axis", gdkevent_get_axis, 1);
697
+ rbg_define_method(gdkEvent, "coords", gdkevent_get_coords, 0);
698
+ rbg_define_method(gdkEvent, "root_coords", gdkevent_get_root_coords, 0);
699
+
700
+ rbg_define_singleton_method(gdkEvent, "handler_set", gdkevent_s_handler_set, 0);
701
+ rbg_define_singleton_method(gdkEvent, "show_events?", gdkevent_s_get_show_events, 0);
702
+ rbg_define_singleton_method(gdkEvent, "set_show_events", gdkevent_s_set_show_events, 1);
703
+ rbg_define_singleton_method(gdkEvent, "setting_get", gdkevent_s_setting_get, -1);
704
+ /* deprecated
705
+ rbg_define_singleton_method(gdkEvent, "add_client_message_filter", gdkevent_s_add_client_message_filter, 1);
706
+ */
707
+ rbg_define_method(gdkEvent, "screen", gdkevent_screen, 0);
708
+ rbg_define_method(gdkEvent, "set_screen", gdkevent_set_screen, 1);
709
+
710
+ /* GdkEventAny */
711
+ DEFINE_ACCESSOR(gdkEventAny, any, window);
712
+ rbg_define_method(gdkEventAny, "send_event?", gdkeventany_send_event, 0);
713
+ rbg_define_method(gdkEventAny, "set_send_event", gdkeventany_set_send_event, 1);
714
+
715
+ /* GdkEventKey */
716
+ ev = gdkevents[GDK_KEY_PRESS];
717
+ DEFINE_ACCESSOR(ev, key, time);
718
+ DEFINE_ACCESSOR(ev, key, state);
719
+ DEFINE_ACCESSOR(ev, key, keyval);
720
+ DEFINE_ACCESSOR(ev, key, hardware_keycode);
721
+ DEFINE_ACCESSOR(ev, key, group);
722
+
723
+ /* GdkEventButton */
724
+ ev = gdkevents[GDK_BUTTON_PRESS];
725
+ DEFINE_ACCESSOR(ev, button, time);
726
+ DEFINE_ACCESSOR(ev, button, x);
727
+ DEFINE_ACCESSOR(ev, button, y);
728
+ rbg_define_method(ev, "axes", gdkeventbutton_axes, 0);
729
+ rbg_define_method(ev, "set_axes", gdkeventbutton_set_axes, 2);
730
+ DEFINE_ACCESSOR(ev, button, state);
731
+ DEFINE_ACCESSOR(ev, button, button);
732
+ DEFINE_ACCESSOR(ev, button, device);
733
+ DEFINE_ACCESSOR(ev, button, x_root);
734
+ DEFINE_ACCESSOR(ev, button, y_root);
735
+
736
+ /* GdkEventScroll */
737
+ ev = gdkevents[GDK_SCROLL];
738
+ DEFINE_ACCESSOR(ev, scroll, time);
739
+ DEFINE_ACCESSOR(ev, scroll, x);
740
+ DEFINE_ACCESSOR(ev, scroll, y);
741
+ DEFINE_ACCESSOR(ev, scroll, state);
742
+ DEFINE_ACCESSOR(ev, scroll, direction);
743
+ DEFINE_ACCESSOR(ev, scroll, device);
744
+ DEFINE_ACCESSOR(ev, scroll, x_root);
745
+ DEFINE_ACCESSOR(ev, scroll, y_root);
746
+ DEFINE_INIT(ev, scroll);
747
+
748
+ /* GdkScrollDirection */
749
+ G_DEF_CLASS(GDK_TYPE_SCROLL_DIRECTION, "Direction", ev);
750
+
751
+ /* GdkEventMotion */
752
+ ev = gdkevents[GDK_MOTION_NOTIFY];
753
+ DEFINE_ACCESSOR(ev, motion, time);
754
+ DEFINE_ACCESSOR(ev, motion, x);
755
+ DEFINE_ACCESSOR(ev, motion, y);
756
+ rbg_define_method(ev, "axes", gdkeventmotion_axes, 0);
757
+ rbg_define_method(ev, "set_axes", gdkeventmotion_set_axes, 1);
758
+ DEFINE_ACCESSOR(ev, motion, state);
759
+ rbg_define_method(ev, "hint?", gdkeventmotion_is_hint, 0);
760
+ rbg_define_method(ev, "set_hint", gdkeventmotion_set_is_hint, 1);
761
+ DEFINE_ACCESSOR(ev, motion, device);
762
+ DEFINE_ACCESSOR(ev, motion, x_root);
763
+ DEFINE_ACCESSOR(ev, motion, y_root);
764
+ DEFINE_INIT(ev, motion);
765
+ rbg_define_method(ev, "request", gdkeventmotion_request_motions, 0);
766
+
767
+ /* GdkEventExpose */
768
+ /* deprecated
769
+ ev = gdkevents[GDK_EXPOSE];
770
+ DEFINE_ACCESSOR(ev, expose, area);
771
+ DEFINE_ACCESSOR(ev, expose, region);
772
+ DEFINE_ACCESSOR(ev, expose, count);
773
+ DEFINE_INIT(ev, expose);
774
+ rbg_define_singleton_method(ev, "get_graphics_expose",
775
+ gdkevent_s_get_graphics_expose, 1);
776
+ */
777
+
778
+ /* GdkEventVisibility */
779
+ ev = gdkevents[GDK_VISIBILITY_NOTIFY];
780
+ DEFINE_ACCESSOR(ev, visibility, state);
781
+ DEFINE_INIT(ev, visibility);
782
+
783
+ /* GdkVisibilityState */
784
+ G_DEF_CLASS(GDK_TYPE_VISIBILITY_STATE, "State", ev);
785
+
786
+ /* GdkEventCrossing */
787
+ ev = gdkevents[GDK_ENTER_NOTIFY];
788
+ DEFINE_ACCESSOR(ev, crossing, subwindow);
789
+ DEFINE_ACCESSOR(ev, crossing, time);
790
+ DEFINE_ACCESSOR(ev, crossing, x);
791
+ DEFINE_ACCESSOR(ev, crossing, y);
792
+ DEFINE_ACCESSOR(ev, crossing, x_root);
793
+ DEFINE_ACCESSOR(ev, crossing, y_root);
794
+ DEFINE_ACCESSOR(ev, crossing, mode);
795
+ DEFINE_ACCESSOR(ev, crossing, detail);
796
+ rbg_define_method(ev, "focus?", gdkeventcrossing_focus, 0);
797
+ rbg_define_method(ev, "set_focus", gdkeventcrossing_set_focus, 1);
798
+ DEFINE_ACCESSOR(ev, crossing, state);
799
+
800
+ /* GdkCrossingMode */
801
+ G_DEF_CLASS(GDK_TYPE_CROSSING_MODE, "Mode", ev);
802
+ /* GdkNotifyType */
803
+ G_DEF_CLASS(GDK_TYPE_NOTIFY_TYPE, "NotifyType", ev);
804
+
805
+ /* GdkEventFocus */
806
+ ev = gdkevents[GDK_FOCUS_CHANGE];
807
+ rbg_define_method(ev, "in?", gdkeventfocus_change_in, 0);
808
+ rbg_define_method(ev, "set_in", gdkeventfocus_change_set_in, 1);
809
+ DEFINE_INIT(ev, focus_change);
810
+
811
+ /* GdkEventConfigure */
812
+ ev = gdkevents[GDK_CONFIGURE];
813
+ DEFINE_ACCESSOR(ev, configure, x);
814
+ DEFINE_ACCESSOR(ev, configure, y);
815
+ DEFINE_ACCESSOR(ev, configure, width);
816
+ DEFINE_ACCESSOR(ev, configure, height);
817
+ DEFINE_INIT(ev, configure);
818
+
819
+ /* GdkEventProperty */
820
+ ev = gdkevents[GDK_PROPERTY_NOTIFY];
821
+ DEFINE_ACCESSOR(ev, property, atom);
822
+ DEFINE_ACCESSOR(ev, property, time);
823
+ DEFINE_ACCESSOR(ev, property, state);
824
+ DEFINE_INIT(ev, property);
825
+
826
+ /* GdkPropertyState */
827
+ G_DEF_CLASS(GDK_TYPE_PROPERTY_STATE, "State", ev);
828
+
829
+ /* GdkEventSelection */
830
+ ev = gdkevents[GDK_SELECTION_CLEAR];
831
+ DEFINE_ACCESSOR(ev, selection, selection);
832
+ DEFINE_ACCESSOR(ev, selection, target);
833
+ DEFINE_ACCESSOR(ev, selection, property);
834
+ DEFINE_ACCESSOR(ev, selection, requestor);
835
+ DEFINE_ACCESSOR(ev, selection, time);
836
+
837
+ /* GdkEventDND */
838
+ ev = gdkevents[GDK_DRAG_ENTER];
839
+ DEFINE_ACCESSOR(ev, dnd, context);
840
+ DEFINE_ACCESSOR(ev, dnd, time);
841
+ DEFINE_ACCESSOR(ev, dnd, x_root);
842
+ DEFINE_ACCESSOR(ev, dnd, y_root);
843
+
844
+ /* GdkEventProximity */
845
+ ev = gdkevents[GDK_PROXIMITY_IN];
846
+ DEFINE_ACCESSOR(ev, proximity, time);
847
+ DEFINE_ACCESSOR(ev, proximity, device);
848
+
849
+ /* GdkEventClient */
850
+ /* deprecated
851
+ ev = gdkevents[GDK_CLIENT_EVENT];
852
+ DEFINE_ACCESSOR(ev, client, message_type);
853
+ rbg_define_method(ev, "data_format", gdkeventclient_data_format, 0);
854
+ rbg_define_method(ev, "data", gdkeventclient_data, 0);
855
+ rbg_define_method(ev, "send_client_message",
856
+ gdkeventclient_send_client_message, -1);
857
+ rbg_define_method(ev, "send_clientmessage_toall",
858
+ gdkeventclient_send_clientmessage_toall, 0);
859
+ DEFINE_INIT(ev, client);
860
+ */
861
+
862
+ /* GdkEventNoExpose */
863
+ /* deprecated
864
+ ev = gdkevents[GDK_NO_EXPOSE];
865
+ DEFINE_INIT(ev, noexpose);
866
+ */
867
+
868
+ /* GdkEventWindowState */
869
+ ev = gdkevents[GDK_WINDOW_STATE];
870
+ DEFINE_ACCESSOR(ev, window_state, changed_mask);
871
+ DEFINE_ACCESSOR(ev, window_state, new_window_state);
872
+ DEFINE_INIT(ev, window_state);
873
+
874
+ /* GdkWindowState */
875
+ G_DEF_CLASS(GDK_TYPE_WINDOW_STATE, "WindowState", ev);
876
+
877
+ /* GdkEventSetting */
878
+ ev = gdkevents[GDK_SETTING];
879
+ DEFINE_ACCESSOR(ev, setting, action);
880
+ DEFINE_ACCESSOR(ev, setting, name);
881
+ DEFINE_INIT(ev, setting);
882
+
883
+ /* GdkSettingAction */
884
+ G_DEF_CLASS(GDK_TYPE_SETTING_ACTION, "Action", ev);
885
+
886
+ /* GdkEventOwnerChange */
887
+ ev = gdkevents[GDK_OWNER_CHANGE];
888
+ DEFINE_ACCESSOR(ev, owner_change, owner);
889
+ DEFINE_ACCESSOR(ev, owner_change, reason);
890
+ DEFINE_ACCESSOR(ev, owner_change, selection);
891
+ DEFINE_ACCESSOR(ev, owner_change, time);
892
+ DEFINE_ACCESSOR(ev, owner_change, selection_time);
893
+ DEFINE_INIT(ev, owner_change);
894
+
895
+ /* GdkOwnerChange */
896
+ G_DEF_CLASS(GDK_TYPE_OWNER_CHANGE, "OwnerChange", ev);
897
+
898
+ /* GdkEventGrabBroken */
899
+ ev = gdkevents[GDK_GRAB_BROKEN];
900
+ rbg_define_method(ev, "keyboard?", gdkeventgrab_broken_keyboard, 0);
901
+ rbg_define_method(ev, "set_keyboard", gdkeventgrab_broken_set_keyboard, 1);
902
+ rbg_define_method(ev, "implicit?", gdkeventgrab_broken_implicit, 0);
903
+ rbg_define_method(ev, "set_implicit", gdkeventgrab_broken_set_implicit, 1);
904
+ DEFINE_ACCESSOR(ev, grab_broken, grab_window);
905
+ DEFINE_INIT(ev, grab_broken);
906
+
907
+ rbgobj_register_g2r_func(GDK_TYPE_EVENT, &gdkevent_g2r);
908
+
909
+ /*
910
+ * GdkEvent's Constants
911
+ */
912
+ rb_define_const(gdkEvent, "CURRENT_TIME", INT2FIX(GDK_CURRENT_TIME));
913
+ rb_define_const(gdkEvent, "PRIORITY_EVENTS", INT2FIX(GDK_PRIORITY_EVENTS));
914
+ rb_define_const(gdkEvent, "PRIORITY_REDRAW", INT2FIX(GDK_PRIORITY_REDRAW));
915
+
916
+ /* GdkEventType */
917
+ /* XXX */
918
+ G_RENAME_CONSTANT("2BUTTON_PRESS","BUTTON2_PRESS");
919
+ G_RENAME_CONSTANT("3BUTTON_PRESS","BUTTON3_PRESS");
920
+ G_DEF_CLASS(GDK_TYPE_EVENT_TYPE, "Type", gdkEvent);
921
+ G_RENAME_CONSTANT("2BUTTON_PRESS","BUTTON2_PRESS");
922
+ G_RENAME_CONSTANT("3BUTTON_PRESS","BUTTON3_PRESS");
923
+
924
+ /* GdkEventMask */
925
+ G_DEF_CLASS(GDK_TYPE_EVENT_MASK, "Mask", gdkEvent);
926
+ }