glib2 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3023 -0
- data/README +28 -0
- data/Rakefile +87 -0
- data/extconf.rb +61 -0
- data/sample/bookmarkfile.rb +66 -0
- data/sample/completion.rb +45 -0
- data/sample/idle.rb +41 -0
- data/sample/iochannel.rb +44 -0
- data/sample/keyfile.rb +62 -0
- data/sample/shell.rb +36 -0
- data/sample/spawn.rb +25 -0
- data/sample/timeout.rb +28 -0
- data/sample/timeout2.rb +35 -0
- data/sample/timer.rb +40 -0
- data/sample/type-register.rb +103 -0
- data/sample/type-register2.rb +104 -0
- data/sample/utils.rb +54 -0
- data/src/glib-enum-types.c +1032 -0
- data/src/glib-enum-types.h +140 -0
- data/src/lib/glib-mkenums.rb +199 -0
- data/src/lib/glib2.rb +220 -0
- data/src/lib/mkmf-gnome2.rb +390 -0
- data/src/lib/pkg-config.rb +137 -0
- data/src/rbgcompat.h +30 -0
- data/src/rbglib.c +320 -0
- data/src/rbglib.h +96 -0
- data/src/rbglib_bookmarkfile.c +595 -0
- data/src/rbglib_completion.c +192 -0
- data/src/rbglib_convert.c +195 -0
- data/src/rbglib_error.c +95 -0
- data/src/rbglib_fileutils.c +83 -0
- data/src/rbglib_i18n.c +44 -0
- data/src/rbglib_int64.c +157 -0
- data/src/rbglib_iochannel.c +883 -0
- data/src/rbglib_keyfile.c +846 -0
- data/src/rbglib_maincontext.c +917 -0
- data/src/rbglib_mainloop.c +87 -0
- data/src/rbglib_messages.c +150 -0
- data/src/rbglib_pollfd.c +111 -0
- data/src/rbglib_shell.c +68 -0
- data/src/rbglib_source.c +190 -0
- data/src/rbglib_spawn.c +345 -0
- data/src/rbglib_threads.c +51 -0
- data/src/rbglib_timer.c +127 -0
- data/src/rbglib_unicode.c +611 -0
- data/src/rbglib_utils.c +386 -0
- data/src/rbglib_win32.c +136 -0
- data/src/rbgobj_boxed.c +251 -0
- data/src/rbgobj_closure.c +337 -0
- data/src/rbgobj_convert.c +167 -0
- data/src/rbgobj_enums.c +961 -0
- data/src/rbgobj_fundamental.c +30 -0
- data/src/rbgobj_object.c +892 -0
- data/src/rbgobj_param.c +390 -0
- data/src/rbgobj_paramspecs.c +305 -0
- data/src/rbgobj_signal.c +963 -0
- data/src/rbgobj_strv.c +61 -0
- data/src/rbgobj_type.c +851 -0
- data/src/rbgobj_typeinstance.c +121 -0
- data/src/rbgobj_typeinterface.c +148 -0
- data/src/rbgobj_typemodule.c +66 -0
- data/src/rbgobj_typeplugin.c +49 -0
- data/src/rbgobj_value.c +313 -0
- data/src/rbgobj_valuearray.c +59 -0
- data/src/rbgobj_valuetypes.c +298 -0
- data/src/rbgobject.c +406 -0
- data/src/rbgobject.h +265 -0
- data/src/rbgprivate.h +88 -0
- data/src/rbgutil.c +222 -0
- data/src/rbgutil.h +82 -0
- data/src/rbgutil_callback.c +231 -0
- data/test/glib-test-init.rb +6 -0
- data/test/glib-test-utils.rb +12 -0
- data/test/run-test.rb +25 -0
- data/test/test_enum.rb +99 -0
- data/test/test_file_utils.rb +15 -0
- data/test/test_glib2.rb +120 -0
- data/test/test_iochannel.rb +275 -0
- data/test/test_key_file.rb +38 -0
- data/test/test_mkenums.rb +25 -0
- data/test/test_signal.rb +20 -0
- data/test/test_timeout.rb +28 -0
- data/test/test_unicode.rb +369 -0
- data/test/test_utils.rb +37 -0
- data/test/test_win32.rb +13 -0
- metadata +165 -0
data/src/rbgobj_param.c
ADDED
@@ -0,0 +1,390 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_param.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 16:07:28 $
|
8
|
+
created at: Sun Jun 9 20:31:47 JST 2002
|
9
|
+
|
10
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
11
|
+
|
12
|
+
**********************************************************************/
|
13
|
+
|
14
|
+
#include "rbgprivate.h"
|
15
|
+
|
16
|
+
VALUE rbgobj_cParam;
|
17
|
+
static GQuark qparamspec;
|
18
|
+
|
19
|
+
static VALUE pspec_s_allocate(VALUE klass);
|
20
|
+
|
21
|
+
typedef struct {
|
22
|
+
GParamSpec* instance;
|
23
|
+
const RGObjClassInfo* cinfo;
|
24
|
+
} pspec_holder;
|
25
|
+
|
26
|
+
static void
|
27
|
+
pspec_mark(holder)
|
28
|
+
pspec_holder* holder;
|
29
|
+
{
|
30
|
+
if (holder->instance)
|
31
|
+
rbgobj_instance_call_cinfo_mark(holder->instance);
|
32
|
+
}
|
33
|
+
|
34
|
+
static void
|
35
|
+
pspec_free(holder)
|
36
|
+
pspec_holder* holder;
|
37
|
+
{
|
38
|
+
if (holder->instance){
|
39
|
+
rbgobj_instance_call_cinfo_free(holder->instance);
|
40
|
+
g_param_spec_set_qdata(holder->instance, qparamspec, NULL);
|
41
|
+
g_param_spec_unref(holder->instance);
|
42
|
+
}
|
43
|
+
free(holder);
|
44
|
+
}
|
45
|
+
|
46
|
+
GParamSpec*
|
47
|
+
rbgobj_get_param_spec(VALUE obj)
|
48
|
+
{
|
49
|
+
pspec_holder* holder;
|
50
|
+
Data_Get_Struct(obj, pspec_holder, holder);
|
51
|
+
return G_PARAM_SPEC(holder->instance);
|
52
|
+
}
|
53
|
+
|
54
|
+
void
|
55
|
+
rbgobj_param_spec_initialize(self, pspec)
|
56
|
+
VALUE self;
|
57
|
+
GParamSpec* pspec;
|
58
|
+
{
|
59
|
+
pspec_holder* holder;
|
60
|
+
Data_Get_Struct(self, pspec_holder, holder);
|
61
|
+
|
62
|
+
pspec = g_param_spec_ref(pspec);
|
63
|
+
g_param_spec_sink(pspec);
|
64
|
+
|
65
|
+
holder->instance = pspec;
|
66
|
+
holder->cinfo = GTYPE2CINFO(G_PARAM_SPEC_TYPE(pspec));
|
67
|
+
g_param_spec_set_qdata(pspec, qparamspec, (gpointer)self);
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE
|
71
|
+
rbgobj_get_ruby_object_from_param_spec(GParamSpec* pspec, gboolean alloc)
|
72
|
+
{
|
73
|
+
gpointer data = g_param_spec_get_qdata(pspec, qparamspec);
|
74
|
+
if (data)
|
75
|
+
return (VALUE)data;
|
76
|
+
else if (alloc) {
|
77
|
+
VALUE result = pspec_s_allocate(GTYPE2CLASS(G_PARAM_SPEC_TYPE(pspec)));
|
78
|
+
rbgobj_param_spec_initialize(result, pspec);
|
79
|
+
return result;
|
80
|
+
} else
|
81
|
+
return Qnil;
|
82
|
+
}
|
83
|
+
|
84
|
+
/**********************************************************************/
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
pspec_s_allocate(VALUE klass)
|
88
|
+
{
|
89
|
+
const RGObjClassInfo* cinfo = rbgobj_lookup_class(klass);
|
90
|
+
if (G_TYPE_IS_ABSTRACT(cinfo->gtype))
|
91
|
+
rb_raise(rb_eTypeError, "abstract class");
|
92
|
+
|
93
|
+
{
|
94
|
+
pspec_holder* holder;
|
95
|
+
VALUE result;
|
96
|
+
|
97
|
+
result = Data_Make_Struct(klass, pspec_holder, pspec_mark, pspec_free,
|
98
|
+
holder);
|
99
|
+
holder->instance = NULL;
|
100
|
+
holder->cinfo = NULL;
|
101
|
+
|
102
|
+
return result;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE
|
107
|
+
inspect(VALUE self)
|
108
|
+
{
|
109
|
+
GParamSpec* pspec = rbgobj_get_param_spec(self);
|
110
|
+
VALUE v = rb_inspect(GTYPE2CLASS(pspec->owner_type));
|
111
|
+
gchar* str = g_strdup_printf("#<%s: %s#%s>",
|
112
|
+
rb_class2name(CLASS_OF(self)),
|
113
|
+
StringValuePtr(v),
|
114
|
+
g_param_spec_get_name(pspec));
|
115
|
+
VALUE result = rb_str_new2(str);
|
116
|
+
g_free(str);
|
117
|
+
return result;
|
118
|
+
}
|
119
|
+
|
120
|
+
static VALUE
|
121
|
+
get_name(VALUE self)
|
122
|
+
{
|
123
|
+
return rb_str_new2(g_param_spec_get_name(rbgobj_get_param_spec(self)));
|
124
|
+
}
|
125
|
+
|
126
|
+
static VALUE
|
127
|
+
get_nick(VALUE self)
|
128
|
+
{
|
129
|
+
const gchar* str = g_param_spec_get_nick(rbgobj_get_param_spec(self));
|
130
|
+
return str ? rb_str_new2(str) : Qnil;
|
131
|
+
}
|
132
|
+
|
133
|
+
static VALUE
|
134
|
+
get_blurb(VALUE self)
|
135
|
+
{
|
136
|
+
const gchar* str = g_param_spec_get_blurb(rbgobj_get_param_spec(self));
|
137
|
+
return str ? rb_str_new2(str) : Qnil;
|
138
|
+
}
|
139
|
+
|
140
|
+
static VALUE
|
141
|
+
get_flags(VALUE self)
|
142
|
+
{
|
143
|
+
return INT2NUM(rbgobj_get_param_spec(self)->flags);
|
144
|
+
}
|
145
|
+
|
146
|
+
static VALUE
|
147
|
+
get_value_type(VALUE self)
|
148
|
+
{
|
149
|
+
return rbgobj_gtype_new(G_PARAM_SPEC_VALUE_TYPE(rbgobj_get_param_spec(self)));
|
150
|
+
}
|
151
|
+
|
152
|
+
static VALUE
|
153
|
+
get_owner_type(VALUE self)
|
154
|
+
{
|
155
|
+
return rbgobj_gtype_new(rbgobj_get_param_spec(self)->owner_type);
|
156
|
+
}
|
157
|
+
|
158
|
+
static VALUE
|
159
|
+
get_owner(VALUE self)
|
160
|
+
{
|
161
|
+
return GTYPE2CLASS(rbgobj_get_param_spec(self)->owner_type);
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE
|
165
|
+
value_default(VALUE self)
|
166
|
+
{
|
167
|
+
GValue tmp = {0,};
|
168
|
+
VALUE result;
|
169
|
+
|
170
|
+
g_value_init(&tmp,
|
171
|
+
G_PARAM_SPEC_VALUE_TYPE(rbgobj_get_param_spec(self)));
|
172
|
+
g_param_value_set_default(rbgobj_get_param_spec(self), &tmp);
|
173
|
+
result = rbgobj_gvalue_to_rvalue(&tmp);
|
174
|
+
g_value_unset(&tmp);
|
175
|
+
|
176
|
+
return result;
|
177
|
+
}
|
178
|
+
|
179
|
+
#if 0
|
180
|
+
static VALUE
|
181
|
+
value_defaults(VALUE self, VALUE val)
|
182
|
+
{
|
183
|
+
GValue tmp = {0,};
|
184
|
+
gboolean result;
|
185
|
+
|
186
|
+
/* FIXME: use rb_ensure to ensure following g_value_unset() call*/
|
187
|
+
g_value_init(&tmp,
|
188
|
+
G_PARAM_SPEC_VALUE_TYPE(rbgobj_get_param_spec(self)));
|
189
|
+
rbgobj_rvalue_to_gvalue(val, &tmp);
|
190
|
+
result = g_param_value_defaults(rbgobj_get_param_spec(self), &tmp);
|
191
|
+
g_value_unset(&tmp);
|
192
|
+
|
193
|
+
return CBOOL2RVAL(result);
|
194
|
+
}
|
195
|
+
#endif
|
196
|
+
|
197
|
+
|
198
|
+
struct validate_arg{
|
199
|
+
GParamSpec* pspec;
|
200
|
+
GValue* value;
|
201
|
+
VALUE obj;
|
202
|
+
};
|
203
|
+
|
204
|
+
static VALUE
|
205
|
+
value_validate_body(struct validate_arg* arg)
|
206
|
+
{
|
207
|
+
VALUE ret;
|
208
|
+
gboolean b;
|
209
|
+
|
210
|
+
rbgobj_rvalue_to_gvalue(arg->obj, arg->value);
|
211
|
+
b = g_param_value_validate(arg->pspec, arg->value);
|
212
|
+
ret = rbgobj_gvalue_to_rvalue(arg->value);
|
213
|
+
return rb_ary_new3(2, CBOOL2RVAL(b), ret);
|
214
|
+
}
|
215
|
+
|
216
|
+
static VALUE
|
217
|
+
value_validate_ensure(struct validate_arg* arg)
|
218
|
+
{
|
219
|
+
g_value_unset(arg->value);
|
220
|
+
return Qnil;
|
221
|
+
}
|
222
|
+
|
223
|
+
static VALUE
|
224
|
+
value_validate(self, obj)
|
225
|
+
VALUE self, obj;
|
226
|
+
{
|
227
|
+
struct validate_arg arg;
|
228
|
+
GValue value = {0,};
|
229
|
+
|
230
|
+
arg.pspec = rbgobj_get_param_spec(self);
|
231
|
+
arg.value = &value;
|
232
|
+
arg.obj = obj;
|
233
|
+
|
234
|
+
g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(arg.pspec));
|
235
|
+
|
236
|
+
return rb_ensure(value_validate_body, (VALUE)&arg,
|
237
|
+
value_validate_ensure, (VALUE)&arg);
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
static VALUE
|
242
|
+
value_convert(int argc, VALUE* argv, VALUE self)
|
243
|
+
{
|
244
|
+
GParamSpec* pspec = rbgobj_get_param_spec(self);
|
245
|
+
VALUE src, strict_validation;
|
246
|
+
VALUE src_type;
|
247
|
+
VALUE result = Qnil;
|
248
|
+
GValue src_value = {0,};
|
249
|
+
GValue dest_value = {0,};
|
250
|
+
gboolean b;
|
251
|
+
|
252
|
+
rb_scan_args(argc, argv, "21", &src, &src_type, &strict_validation);
|
253
|
+
|
254
|
+
/* FIXME: use rb_ensure to ensure following g_value_unset() call*/
|
255
|
+
g_value_init(&src_value, rbgobj_gtype_get(src_type));
|
256
|
+
g_value_init(&dest_value, G_PARAM_SPEC_VALUE_TYPE(pspec));
|
257
|
+
|
258
|
+
rbgobj_rvalue_to_gvalue(src, &src_value);
|
259
|
+
|
260
|
+
b = g_param_value_convert(rbgobj_get_param_spec(self),
|
261
|
+
&src_value, &dest_value,
|
262
|
+
RVAL2CBOOL(strict_validation));
|
263
|
+
|
264
|
+
if (b)
|
265
|
+
result = rbgobj_gvalue_to_rvalue(&dest_value);
|
266
|
+
|
267
|
+
g_value_unset(&src_value);
|
268
|
+
g_value_unset(&dest_value);
|
269
|
+
|
270
|
+
if (b)
|
271
|
+
return result;
|
272
|
+
else
|
273
|
+
rb_raise(rb_eTypeError, "can't convert");
|
274
|
+
}
|
275
|
+
|
276
|
+
static VALUE
|
277
|
+
values_compare(self, a, b)
|
278
|
+
VALUE self, a, b;
|
279
|
+
{
|
280
|
+
GParamSpec* pspec = rbgobj_get_param_spec(self);
|
281
|
+
GType type = G_PARAM_SPEC_VALUE_TYPE(pspec);
|
282
|
+
GValue v1 = {0,};
|
283
|
+
GValue v2 = {0,};
|
284
|
+
gint result;
|
285
|
+
|
286
|
+
g_value_init(&v1, type);
|
287
|
+
g_value_init(&v2, type);
|
288
|
+
|
289
|
+
/* FIXME: use rb_ensure to ensure following g_value_unset() call*/
|
290
|
+
rbgobj_rvalue_to_gvalue(a, &v1);
|
291
|
+
rbgobj_rvalue_to_gvalue(b, &v2);
|
292
|
+
|
293
|
+
result = g_param_values_cmp(pspec, &v1, &v2);
|
294
|
+
|
295
|
+
g_value_unset(&v1);
|
296
|
+
g_value_unset(&v2);
|
297
|
+
|
298
|
+
return INT2NUM(result);
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
static VALUE
|
303
|
+
get_ref_count(self)
|
304
|
+
VALUE self;
|
305
|
+
{
|
306
|
+
return INT2NUM(G_PARAM_SPEC(rbgobj_get_param_spec(self))->ref_count);
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
#define param_is_flag(flag) \
|
311
|
+
static VALUE \
|
312
|
+
param_is_##flag(self) \
|
313
|
+
VALUE self; \
|
314
|
+
{ \
|
315
|
+
GParamSpec* pspec = G_PARAM_SPEC(rbgobj_get_param_spec(self)); \
|
316
|
+
return CBOOL2RVAL(pspec->flags & flag); \
|
317
|
+
}
|
318
|
+
|
319
|
+
param_is_flag(G_PARAM_READABLE)
|
320
|
+
param_is_flag(G_PARAM_WRITABLE)
|
321
|
+
param_is_flag(G_PARAM_CONSTRUCT)
|
322
|
+
param_is_flag(G_PARAM_CONSTRUCT_ONLY)
|
323
|
+
param_is_flag(G_PARAM_LAX_VALIDATION)
|
324
|
+
param_is_flag(G_PARAM_PRIVATE)
|
325
|
+
param_is_flag(G_PARAM_READWRITE)
|
326
|
+
|
327
|
+
/**********************************************************************/
|
328
|
+
|
329
|
+
static void
|
330
|
+
Init_gobject_gparam_spec()
|
331
|
+
{
|
332
|
+
VALUE cParamSpec;
|
333
|
+
|
334
|
+
qparamspec = g_quark_from_static_string("__ruby_gobject_param_spec__");
|
335
|
+
rbgobj_cParam = G_DEF_CLASS(G_TYPE_PARAM, "Param", mGLib);
|
336
|
+
cParamSpec = rbgobj_cParam;
|
337
|
+
|
338
|
+
/* GParamFlags */
|
339
|
+
rb_define_const(cParamSpec, "READABLE", INT2FIX(G_PARAM_READABLE));
|
340
|
+
rb_define_const(cParamSpec, "WRITABLE", INT2FIX(G_PARAM_WRITABLE));
|
341
|
+
rb_define_const(cParamSpec, "CONSTRUCT", INT2FIX(G_PARAM_CONSTRUCT));
|
342
|
+
rb_define_const(cParamSpec, "CONSTRUCT_ONLY", INT2FIX(G_PARAM_CONSTRUCT_ONLY));
|
343
|
+
rb_define_const(cParamSpec, "LAX_VALIDATION", INT2FIX(G_PARAM_LAX_VALIDATION));
|
344
|
+
rb_define_const(cParamSpec, "PRIVATE", INT2FIX(G_PARAM_PRIVATE));
|
345
|
+
rb_define_const(cParamSpec, "READWRITE", INT2FIX(G_PARAM_READWRITE));
|
346
|
+
rb_define_const(cParamSpec, "MASK", INT2FIX(G_PARAM_MASK));
|
347
|
+
rb_define_const(cParamSpec, "USER_SHIFT", INT2FIX(G_PARAM_USER_SHIFT));
|
348
|
+
|
349
|
+
rb_define_alloc_func(cParamSpec, pspec_s_allocate);
|
350
|
+
|
351
|
+
rb_define_method(cParamSpec, "inspect", inspect, 0);
|
352
|
+
|
353
|
+
rb_define_method(cParamSpec, "name", get_name, 0);
|
354
|
+
rb_define_method(cParamSpec, "nick", get_nick, 0);
|
355
|
+
rb_define_method(cParamSpec, "blurb", get_blurb, 0);
|
356
|
+
|
357
|
+
rb_define_method(cParamSpec, "flags", get_flags, 0);
|
358
|
+
rb_define_method(cParamSpec, "value_type", get_value_type, 0);
|
359
|
+
rb_define_method(cParamSpec, "owner_type", get_owner_type, 0);
|
360
|
+
rb_define_method(cParamSpec, "owner", get_owner, 0);
|
361
|
+
|
362
|
+
rb_define_method(cParamSpec, "value_default", value_default, 0);
|
363
|
+
rb_define_alias(cParamSpec, "default", "value_default");
|
364
|
+
|
365
|
+
// FIXME: better name
|
366
|
+
#if 0
|
367
|
+
rb_define_method(cParamSpec, "value_defaults?", value_defaults, 1);
|
368
|
+
#endif
|
369
|
+
rb_define_method(cParamSpec, "value_validate", value_validate, 1);
|
370
|
+
rb_define_method(cParamSpec, "value_convert", value_convert, -1);
|
371
|
+
rb_define_method(cParamSpec, "value_compare", values_compare, 2);
|
372
|
+
|
373
|
+
/* for debugging */
|
374
|
+
rb_define_method(cParamSpec, "ref_count", get_ref_count, 0);
|
375
|
+
|
376
|
+
rb_define_method(cParamSpec, "readable?", param_is_G_PARAM_READABLE, 0);
|
377
|
+
rb_define_method(cParamSpec, "writable?", param_is_G_PARAM_WRITABLE, 0);
|
378
|
+
rb_define_method(cParamSpec, "construct?", param_is_G_PARAM_CONSTRUCT, 0);
|
379
|
+
rb_define_method(cParamSpec, "construct_only?", param_is_G_PARAM_CONSTRUCT_ONLY, 0);
|
380
|
+
rb_define_method(cParamSpec, "lax_validation?", param_is_G_PARAM_LAX_VALIDATION, 0);
|
381
|
+
rb_define_method(cParamSpec, "private?", param_is_G_PARAM_PRIVATE, 0);
|
382
|
+
rb_define_method(cParamSpec, "readwrite?", param_is_G_PARAM_READWRITE, 0);
|
383
|
+
}
|
384
|
+
|
385
|
+
/**********************************************************************/
|
386
|
+
|
387
|
+
void Init_gobject_gparam()
|
388
|
+
{
|
389
|
+
Init_gobject_gparam_spec();
|
390
|
+
}
|
@@ -0,0 +1,305 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbgobj_paramspecs.c -
|
5
|
+
|
6
|
+
$Author: ggc $
|
7
|
+
$Date: 2007/07/13 16:07:28 $
|
8
|
+
created at: Sun Jul 26 14:31:33 JST 2002
|
9
|
+
|
10
|
+
Copyright (C) 2004 Ruby-GNOME2 Project Team
|
11
|
+
Copyright (C) 2002,2003 Masahiro Sakai
|
12
|
+
|
13
|
+
**********************************************************************/
|
14
|
+
|
15
|
+
#include "rbgprivate.h"
|
16
|
+
|
17
|
+
#define DEF_NUMERIC_PSPEC_METHODS_FUNC(pspec_type, typename, from_ruby, to_ruby, pspec_cast) \
|
18
|
+
static VALUE \
|
19
|
+
typename##_initialize(self, name, nick, blurb, minimum, maximum, default_value, flags) \
|
20
|
+
VALUE self, name, nick, blurb, minimum, maximum, default_value, flags; \
|
21
|
+
{ \
|
22
|
+
GParamSpec* pspec; \
|
23
|
+
pspec = g_param_spec_##typename(StringValuePtr(name), \
|
24
|
+
StringValuePtr(nick), \
|
25
|
+
StringValuePtr(blurb), \
|
26
|
+
from_ruby(minimum), \
|
27
|
+
from_ruby(maximum), \
|
28
|
+
from_ruby(default_value), \
|
29
|
+
NUM2UINT(flags)); \
|
30
|
+
rbgobj_param_spec_initialize(self, pspec); \
|
31
|
+
return Qnil; \
|
32
|
+
} \
|
33
|
+
\
|
34
|
+
static \
|
35
|
+
VALUE typename##_minimum(self) \
|
36
|
+
{ \
|
37
|
+
return to_ruby(pspec_cast(RVAL2GOBJ(self))->minimum); \
|
38
|
+
} \
|
39
|
+
\
|
40
|
+
static \
|
41
|
+
VALUE typename##_maximum(self) \
|
42
|
+
{ \
|
43
|
+
return to_ruby(pspec_cast(RVAL2GOBJ(self))->maximum); \
|
44
|
+
} \
|
45
|
+
\
|
46
|
+
static \
|
47
|
+
VALUE typename##_range(self) \
|
48
|
+
{ \
|
49
|
+
pspec_type* pspec = pspec_cast(RVAL2GOBJ(self)); \
|
50
|
+
return rb_range_new(pspec->minimum, pspec->maximum, 0); \
|
51
|
+
}
|
52
|
+
|
53
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecChar, char, NUM2INT, INT2FIX, G_PARAM_SPEC_CHAR)
|
54
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecUChar, uchar, NUM2UINT, INT2FIX, G_PARAM_SPEC_UCHAR)
|
55
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecInt, int, NUM2INT, INT2NUM, G_PARAM_SPEC_INT)
|
56
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecUInt, uint, NUM2UINT, UINT2NUM, G_PARAM_SPEC_UINT)
|
57
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecLong, long, NUM2LONG, INT2NUM, G_PARAM_SPEC_LONG)
|
58
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecULong, ulong, NUM2ULONG, UINT2NUM, G_PARAM_SPEC_ULONG)
|
59
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecInt64, int64, rbglib_num_to_int64, rbglib_int64_to_num, G_PARAM_SPEC_INT64)
|
60
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecUInt64, uint64, rbglib_num_to_uint64, rbglib_uint64_to_num, G_PARAM_SPEC_UINT64)
|
61
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecFloat, float, NUM2DBL, rb_float_new, G_PARAM_SPEC_FLOAT)
|
62
|
+
DEF_NUMERIC_PSPEC_METHODS_FUNC(GParamSpecDouble, double, NUM2DBL, rb_float_new, G_PARAM_SPEC_DOUBLE)
|
63
|
+
|
64
|
+
static VALUE
|
65
|
+
float_epsilon(self)
|
66
|
+
VALUE self;
|
67
|
+
{
|
68
|
+
return rb_float_new(G_PARAM_SPEC_FLOAT(RVAL2GOBJ(self))->epsilon);
|
69
|
+
}
|
70
|
+
|
71
|
+
static VALUE
|
72
|
+
double_epsilon(self)
|
73
|
+
VALUE self;
|
74
|
+
{
|
75
|
+
return rb_float_new(G_PARAM_SPEC_DOUBLE(RVAL2GOBJ(self))->epsilon);
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
static VALUE
|
80
|
+
boolean_initialize(self, name, nick, blurb, default_value, flags)
|
81
|
+
VALUE self, name, nick, blurb, default_value, flags;
|
82
|
+
{
|
83
|
+
GParamSpec* pspec;
|
84
|
+
pspec = g_param_spec_boolean(StringValuePtr(name),
|
85
|
+
StringValuePtr(nick),
|
86
|
+
StringValuePtr(blurb),
|
87
|
+
RVAL2CBOOL(default_value),
|
88
|
+
NUM2UINT(flags));
|
89
|
+
rbgobj_param_spec_initialize(self, pspec);
|
90
|
+
return Qnil;
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE
|
94
|
+
unichar_initialize(self, name, nick, blurb, default_value, flags)
|
95
|
+
VALUE self, name, nick, blurb, default_value, flags;
|
96
|
+
{
|
97
|
+
GParamSpec* pspec;
|
98
|
+
pspec = g_param_spec_unichar(StringValuePtr(name),
|
99
|
+
StringValuePtr(nick),
|
100
|
+
StringValuePtr(blurb),
|
101
|
+
NUM2UINT(default_value),
|
102
|
+
NUM2UINT(flags));
|
103
|
+
rbgobj_param_spec_initialize(self, pspec);
|
104
|
+
return Qnil;
|
105
|
+
}
|
106
|
+
|
107
|
+
static VALUE
|
108
|
+
enum_initialize(self, name, nick, blurb, enum_type, default_value, flags)
|
109
|
+
VALUE self, name, nick, blurb, enum_type, default_value, flags;
|
110
|
+
{
|
111
|
+
GParamSpec* pspec;
|
112
|
+
GType gtype = rbgobj_gtype_get(enum_type);
|
113
|
+
|
114
|
+
pspec = g_param_spec_enum(StringValuePtr(name),
|
115
|
+
StringValuePtr(nick),
|
116
|
+
StringValuePtr(blurb),
|
117
|
+
gtype,
|
118
|
+
RVAL2GENUM(default_value, gtype),
|
119
|
+
NUM2UINT(flags));
|
120
|
+
rbgobj_param_spec_initialize(self, pspec);
|
121
|
+
return Qnil;
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE
|
125
|
+
flags_initialize(self, name, nick, blurb, flags_type, default_value, flags)
|
126
|
+
VALUE self, name, nick, blurb, flags_type, default_value, flags;
|
127
|
+
{
|
128
|
+
GParamSpec* pspec;
|
129
|
+
GType gtype = rbgobj_gtype_get(flags_type);
|
130
|
+
|
131
|
+
pspec = g_param_spec_flags(StringValuePtr(name),
|
132
|
+
StringValuePtr(nick),
|
133
|
+
StringValuePtr(blurb),
|
134
|
+
gtype,
|
135
|
+
RVAL2GFLAGS(default_value, gtype),
|
136
|
+
NUM2UINT(flags));
|
137
|
+
rbgobj_param_spec_initialize(self, pspec);
|
138
|
+
return Qnil;
|
139
|
+
}
|
140
|
+
|
141
|
+
static VALUE
|
142
|
+
string_initialize(self, name, nick, blurb, default_value, flags)
|
143
|
+
VALUE self, name, nick, blurb, default_value, flags;
|
144
|
+
{
|
145
|
+
GParamSpec* pspec;
|
146
|
+
pspec = g_param_spec_string(StringValuePtr(name),
|
147
|
+
StringValuePtr(nick),
|
148
|
+
StringValuePtr(blurb),
|
149
|
+
NIL_P(default_value) ? NULL : StringValuePtr(default_value),
|
150
|
+
NUM2UINT(flags));
|
151
|
+
rbgobj_param_spec_initialize(self, pspec);
|
152
|
+
return Qnil;
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE
|
156
|
+
param_initialize(self, name, nick, blurb, param_type, flags)
|
157
|
+
VALUE self, name, nick, blurb, param_type, flags;
|
158
|
+
{
|
159
|
+
GParamSpec* pspec;
|
160
|
+
pspec = g_param_spec_param(StringValuePtr(name),
|
161
|
+
StringValuePtr(nick),
|
162
|
+
StringValuePtr(blurb),
|
163
|
+
rbgobj_gtype_get(param_type),
|
164
|
+
NUM2UINT(flags));
|
165
|
+
rbgobj_param_spec_initialize(self, pspec);
|
166
|
+
return Qnil;
|
167
|
+
}
|
168
|
+
|
169
|
+
static VALUE
|
170
|
+
boxed_initialize(self, name, nick, blurb, boxed_type, flags)
|
171
|
+
VALUE self, name, nick, blurb, boxed_type, flags;
|
172
|
+
{
|
173
|
+
GParamSpec* pspec;
|
174
|
+
pspec = g_param_spec_boxed(StringValuePtr(name),
|
175
|
+
StringValuePtr(nick),
|
176
|
+
StringValuePtr(blurb),
|
177
|
+
rbgobj_gtype_get(boxed_type),
|
178
|
+
NUM2UINT(flags));
|
179
|
+
rbgobj_param_spec_initialize(self, pspec);
|
180
|
+
return Qnil;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
pointer_initialize(self, name, nick, blurb, flags)
|
185
|
+
VALUE self, name, nick, blurb, flags;
|
186
|
+
{
|
187
|
+
GParamSpec* pspec;
|
188
|
+
pspec = g_param_spec_pointer(StringValuePtr(name),
|
189
|
+
StringValuePtr(nick),
|
190
|
+
StringValuePtr(blurb),
|
191
|
+
NUM2UINT(flags));
|
192
|
+
rbgobj_param_spec_initialize(self, pspec);
|
193
|
+
return Qnil;
|
194
|
+
}
|
195
|
+
|
196
|
+
static VALUE
|
197
|
+
value_array_initialize(self, name, nick, blurb, element_spec, flags)
|
198
|
+
VALUE self, name, nick, blurb, element_spec, flags;
|
199
|
+
{
|
200
|
+
GParamSpec* pspec;
|
201
|
+
pspec = g_param_spec_value_array(StringValuePtr(name),
|
202
|
+
StringValuePtr(nick),
|
203
|
+
StringValuePtr(blurb),
|
204
|
+
RVAL2GOBJ(element_spec),
|
205
|
+
NUM2UINT(flags));
|
206
|
+
rbgobj_param_spec_initialize(self, pspec);
|
207
|
+
return Qnil;
|
208
|
+
}
|
209
|
+
|
210
|
+
static VALUE
|
211
|
+
object_initialize(self, name, nick, blurb, object_type, flags)
|
212
|
+
VALUE self, name, nick, blurb, object_type, flags;
|
213
|
+
{
|
214
|
+
GParamSpec* pspec;
|
215
|
+
pspec = g_param_spec_object(StringValuePtr(name),
|
216
|
+
StringValuePtr(nick),
|
217
|
+
StringValuePtr(blurb),
|
218
|
+
rbgobj_gtype_get(object_type),
|
219
|
+
NUM2UINT(flags));
|
220
|
+
rbgobj_param_spec_initialize(self, pspec);
|
221
|
+
return Qnil;
|
222
|
+
}
|
223
|
+
|
224
|
+
void
|
225
|
+
Init_gobject_gparamspecs()
|
226
|
+
{
|
227
|
+
VALUE cParamSpec = GTYPE2CLASS(G_TYPE_PARAM);
|
228
|
+
VALUE c;
|
229
|
+
|
230
|
+
#define DEF_NUMERIC_PSPEC_METHODS(c, typename) \
|
231
|
+
G_STMT_START {\
|
232
|
+
rb_define_method(c, "initialize", typename##_initialize, 7); \
|
233
|
+
rb_define_method(c, "minimum", typename##_minimum, 0); \
|
234
|
+
rb_define_method(c, "maximum", typename##_maximum, 0); \
|
235
|
+
rb_define_method(c, "range", typename##_range, 0); \
|
236
|
+
} G_STMT_END
|
237
|
+
|
238
|
+
#if 0
|
239
|
+
rb_define_method(c, "default_value", typename##_default_value, 0); \
|
240
|
+
rb_define_alias(c, "default", "default_value"); \
|
241
|
+
|
242
|
+
#endif
|
243
|
+
|
244
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_CHAR, "Char", cParamSpec);
|
245
|
+
DEF_NUMERIC_PSPEC_METHODS(c, char);
|
246
|
+
|
247
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_UCHAR, "UChar", cParamSpec);
|
248
|
+
DEF_NUMERIC_PSPEC_METHODS(c, uchar);
|
249
|
+
|
250
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_INT, "Int", cParamSpec);
|
251
|
+
DEF_NUMERIC_PSPEC_METHODS(c, int);
|
252
|
+
|
253
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_UINT, "UInt", cParamSpec);
|
254
|
+
DEF_NUMERIC_PSPEC_METHODS(c, uint);
|
255
|
+
|
256
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_LONG, "Long", cParamSpec);
|
257
|
+
DEF_NUMERIC_PSPEC_METHODS(c, long);
|
258
|
+
|
259
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_ULONG, "ULong", cParamSpec);
|
260
|
+
DEF_NUMERIC_PSPEC_METHODS(c, ulong);
|
261
|
+
|
262
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_INT64, "Int64", cParamSpec);
|
263
|
+
DEF_NUMERIC_PSPEC_METHODS(c, int64);
|
264
|
+
|
265
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_UINT64, "UInt64", cParamSpec);
|
266
|
+
DEF_NUMERIC_PSPEC_METHODS(c, uint64);
|
267
|
+
|
268
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_FLOAT, "Float", cParamSpec);
|
269
|
+
DEF_NUMERIC_PSPEC_METHODS(c, float);
|
270
|
+
rb_define_method(c, "epsilon", float_epsilon, 0);
|
271
|
+
|
272
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_DOUBLE, "Double", cParamSpec);
|
273
|
+
DEF_NUMERIC_PSPEC_METHODS(c, double);
|
274
|
+
rb_define_method(c, "epsilon", double_epsilon, 0);
|
275
|
+
|
276
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_BOOLEAN, "Boolean", cParamSpec);
|
277
|
+
rb_define_method(c, "initialize", boolean_initialize, 5);
|
278
|
+
|
279
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_UNICHAR, "UniChar", cParamSpec);
|
280
|
+
rb_define_method(c, "initialize", unichar_initialize, 5);
|
281
|
+
|
282
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_ENUM, "Enum", cParamSpec);
|
283
|
+
rb_define_method(c, "initialize", enum_initialize, 6);
|
284
|
+
|
285
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_FLAGS, "Flags", cParamSpec);
|
286
|
+
rb_define_method(c, "initialize", flags_initialize, 6);
|
287
|
+
|
288
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_STRING, "String", cParamSpec);
|
289
|
+
rb_define_method(c, "initialize", string_initialize, 5);
|
290
|
+
|
291
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_PARAM, "Param", cParamSpec);
|
292
|
+
rb_define_method(c, "initialize", param_initialize, 5);
|
293
|
+
|
294
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_BOXED, "Boxed", cParamSpec);
|
295
|
+
rb_define_method(c, "initialize", boxed_initialize, 5);
|
296
|
+
|
297
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_POINTER, "Pointer", cParamSpec);
|
298
|
+
rb_define_method(c, "initialize", pointer_initialize, 4);
|
299
|
+
|
300
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_VALUE_ARRAY, "ValueArray", cParamSpec);
|
301
|
+
rb_define_method(c, "initialize", value_array_initialize, 5);
|
302
|
+
|
303
|
+
c = G_DEF_CLASS(G_TYPE_PARAM_OBJECT, "Object", cParamSpec);
|
304
|
+
rb_define_method(c, "initialize", object_initialize, 5);
|
305
|
+
}
|