1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gtksignal.h"
#include "gtkargcollector.c"
#include "gtkmarshal.c"
/* the real parameter limit is of course given by GSignal, bu we need
* an upper limit for the implementations. so this should be adjusted
* with any future changes on the GSignal side of things.
*/
#define SIGNAL_MAX_PARAMS 12
/* --- functions --- */
guint
gtk_signal_newv (const gchar *name,
GtkSignalRunType signal_flags,
GtkType object_type,
guint function_offset,
GtkSignalMarshaller marshaller,
GtkType return_val,
guint n_params,
GtkType *params)
{
GClosure *closure;
g_return_val_if_fail (n_params < SIGNAL_MAX_PARAMS, 0);
closure = g_signal_type_cclosure_new (object_type, function_offset);
return g_signal_newv (name, object_type, signal_flags, closure, NULL, NULL, marshaller, return_val, n_params, params);
}
guint
gtk_signal_new (const gchar *name,
GtkSignalRunType signal_flags,
GtkType object_type,
guint function_offset,
GtkSignalMarshaller marshaller,
GtkType return_val,
guint n_params,
...)
{
GtkType *params;
guint signal_id;
if (n_params)
{
va_list args;
guint i;
params = g_new (GtkType, n_params);
va_start (args, n_params);
for (i = 0; i < n_params; i++)
params[i] = va_arg (args, GtkType);
va_end (args);
}
else
params = NULL;
signal_id = gtk_signal_newv (name,
signal_flags,
object_type,
function_offset,
marshaller,
return_val,
n_params,
params);
g_free (params);
return signal_id;
}
void
gtk_signal_emit_stop_by_name (GtkObject *object,
const gchar *name)
{
g_return_if_fail (GTK_IS_OBJECT (object));
g_signal_stop_emission (object, g_signal_lookup (name, G_OBJECT_TYPE (object)), 0);
}
void
gtk_signal_connect_object_while_alive (GtkObject *object,
const gchar *signal,
GtkSignalFunc func,
GtkObject *alive_object)
{
g_return_if_fail (GTK_IS_OBJECT (object));
g_signal_connect_closure_by_id (object,
g_signal_lookup (signal, G_OBJECT_TYPE (object)), 0,
g_cclosure_new_object_swap (func, alive_object),
FALSE);
}
void
gtk_signal_connect_while_alive (GtkObject *object,
const gchar *signal,
GtkSignalFunc func,
gpointer func_data,
GtkObject *alive_object)
{
GClosure *closure;
g_return_if_fail (GTK_IS_OBJECT (object));
closure = g_cclosure_new (func, func_data, NULL);
g_object_watch_closure (G_OBJECT (alive_object), closure);
g_signal_connect_closure_by_id (object,
g_signal_lookup (signal, G_OBJECT_TYPE (object)), 0,
closure,
FALSE);
}
guint
gtk_signal_connect_full (GtkObject *object,
const gchar *name,
GtkSignalFunc func,
GtkCallbackMarshal unsupported,
gpointer data,
GtkDestroyNotify destroy_func,
gint object_signal,
gint after)
{
g_return_val_if_fail (GTK_IS_OBJECT (object), 0);
g_return_val_if_fail (unsupported == NULL, 0);
return g_signal_connect_closure_by_id (object,
g_signal_lookup (name, G_OBJECT_TYPE (object)), 0,
(object_signal
? g_cclosure_new_swap
: g_cclosure_new) (func,
data,
(GClosureNotify) destroy_func),
after);
}
void
gtk_signal_compat_matched (GtkObject *object,
GtkSignalFunc func,
gpointer data,
GSignalMatchType match,
guint action)
{
guint n_handlers;
g_return_if_fail (GTK_IS_OBJECT (object));
switch (action)
{
case 0: n_handlers = g_signal_handlers_disconnect_matched (object, match, 0, 0, NULL, func, data); break;
case 1: n_handlers = g_signal_handlers_block_matched (object, match, 0, 0, NULL, func, data); break;
case 2: n_handlers = g_signal_handlers_unblock_matched (object, match, 0, 0, NULL, func, data); break;
default: n_handlers = 0; break;
}
if (!n_handlers)
g_warning ("unable to find signal handler for object(%s:%p) with func(%p) and data(%p)",
G_OBJECT_TYPE_NAME (object), object, func, data);
}
static inline gboolean
gtk_arg_to_value (GtkArg *arg,
GValue *value)
{
switch (G_TYPE_FUNDAMENTAL (arg->type))
{
case G_TYPE_CHAR: g_value_set_char (value, GTK_VALUE_CHAR (*arg)); break;
case G_TYPE_UCHAR: g_value_set_uchar (value, GTK_VALUE_UCHAR (*arg)); break;
case G_TYPE_BOOLEAN: g_value_set_boolean (value, GTK_VALUE_BOOL (*arg)); break;
case G_TYPE_INT: g_value_set_int (value, GTK_VALUE_INT (*arg)); break;
case G_TYPE_UINT: g_value_set_uint (value, GTK_VALUE_UINT (*arg)); break;
case G_TYPE_LONG: g_value_set_long (value, GTK_VALUE_LONG (*arg)); break;
case G_TYPE_ULONG: g_value_set_ulong (value, GTK_VALUE_ULONG (*arg)); break;
case G_TYPE_ENUM: g_value_set_enum (value, GTK_VALUE_ENUM (*arg)); break;
case G_TYPE_FLAGS: g_value_set_flags (value, GTK_VALUE_FLAGS (*arg)); break;
case G_TYPE_FLOAT: g_value_set_float (value, GTK_VALUE_FLOAT (*arg)); break;
case G_TYPE_DOUBLE: g_value_set_double (value, GTK_VALUE_DOUBLE (*arg)); break;
case G_TYPE_STRING: g_value_set_string (value, GTK_VALUE_STRING (*arg)); break;
case G_TYPE_BOXED: g_value_set_boxed (value, GTK_VALUE_BOXED (*arg)); break;
case G_TYPE_POINTER: g_value_set_pointer (value, GTK_VALUE_POINTER (*arg)); break;
case G_TYPE_OBJECT: g_value_set_object (value, GTK_VALUE_POINTER (*arg)); break;
default:
return FALSE;
}
return TRUE;
}
static inline gboolean
gtk_arg_static_to_value (GtkArg *arg,
GValue *value)
{
switch (G_TYPE_FUNDAMENTAL (arg->type))
{
case G_TYPE_CHAR: g_value_set_char (value, GTK_VALUE_CHAR (*arg)); break;
case G_TYPE_UCHAR: g_value_set_uchar (value, GTK_VALUE_UCHAR (*arg)); break;
case G_TYPE_BOOLEAN: g_value_set_boolean (value, GTK_VALUE_BOOL (*arg)); break;
case G_TYPE_INT: g_value_set_int (value, GTK_VALUE_INT (*arg)); break;
case G_TYPE_UINT: g_value_set_uint (value, GTK_VALUE_UINT (*arg)); break;
case G_TYPE_LONG: g_value_set_long (value, GTK_VALUE_LONG (*arg)); break;
case G_TYPE_ULONG: g_value_set_ulong (value, GTK_VALUE_ULONG (*arg)); break;
case G_TYPE_ENUM: g_value_set_enum (value, GTK_VALUE_ENUM (*arg)); break;
case G_TYPE_FLAGS: g_value_set_flags (value, GTK_VALUE_FLAGS (*arg)); break;
case G_TYPE_FLOAT: g_value_set_float (value, GTK_VALUE_FLOAT (*arg)); break;
case G_TYPE_DOUBLE: g_value_set_double (value, GTK_VALUE_DOUBLE (*arg)); break;
case G_TYPE_STRING: g_value_set_static_string (value, GTK_VALUE_STRING (*arg)); break;
case G_TYPE_BOXED: g_value_set_static_boxed (value, GTK_VALUE_BOXED (*arg)); break;
case G_TYPE_POINTER: g_value_set_pointer (value, GTK_VALUE_POINTER (*arg)); break;
case G_TYPE_OBJECT: g_value_set_object (value, GTK_VALUE_POINTER (*arg)); break;
default:
return FALSE;
}
return TRUE;
}
static inline gboolean
gtk_arg_set_from_value (GtkArg *arg,
GValue *value,
gboolean copy_string)
{
switch (G_TYPE_FUNDAMENTAL (arg->type))
{
case G_TYPE_CHAR: GTK_VALUE_CHAR (*arg) = g_value_get_char (value); break;
case G_TYPE_UCHAR: GTK_VALUE_UCHAR (*arg) = g_value_get_uchar (value); break;
case G_TYPE_BOOLEAN: GTK_VALUE_BOOL (*arg) = g_value_get_boolean (value); break;
case G_TYPE_INT: GTK_VALUE_INT (*arg) = g_value_get_int (value); break;
case G_TYPE_UINT: GTK_VALUE_UINT (*arg) = g_value_get_uint (value); break;
case G_TYPE_LONG: GTK_VALUE_LONG (*arg) = g_value_get_long (value); break;
case G_TYPE_ULONG: GTK_VALUE_ULONG (*arg) = g_value_get_ulong (value); break;
case G_TYPE_ENUM: GTK_VALUE_ENUM (*arg) = g_value_get_enum (value); break;
case G_TYPE_FLAGS: GTK_VALUE_FLAGS (*arg) = g_value_get_flags (value); break;
case G_TYPE_FLOAT: GTK_VALUE_FLOAT (*arg) = g_value_get_float (value); break;
case G_TYPE_DOUBLE: GTK_VALUE_DOUBLE (*arg) = g_value_get_double (value); break;
case G_TYPE_BOXED: GTK_VALUE_BOXED (*arg) = g_value_get_boxed (value); break;
case G_TYPE_POINTER: GTK_VALUE_POINTER (*arg) = g_value_get_pointer (value); break;
case G_TYPE_OBJECT: GTK_VALUE_POINTER (*arg) = g_value_get_object (value); break;
case G_TYPE_STRING: if (copy_string)
GTK_VALUE_STRING (*arg) = g_value_dup_string (value);
else
GTK_VALUE_STRING (*arg) = g_value_get_string (value);
break;
default:
return FALSE;
}
return TRUE;
}
static inline gboolean
gtk_argloc_set_from_value (GtkArg *arg,
GValue *value,
gboolean copy_string)
{
switch (G_TYPE_FUNDAMENTAL (arg->type))
{
case G_TYPE_CHAR: *GTK_RETLOC_CHAR (*arg) = g_value_get_char (value); break;
case G_TYPE_UCHAR: *GTK_RETLOC_UCHAR (*arg) = g_value_get_uchar (value); break;
case G_TYPE_BOOLEAN: *GTK_RETLOC_BOOL (*arg) = g_value_get_boolean (value); break;
case G_TYPE_INT: *GTK_RETLOC_INT (*arg) = g_value_get_int (value); break;
case G_TYPE_UINT: *GTK_RETLOC_UINT (*arg) = g_value_get_uint (value); break;
case G_TYPE_LONG: *GTK_RETLOC_LONG (*arg) = g_value_get_long (value); break;
case G_TYPE_ULONG: *GTK_RETLOC_ULONG (*arg) = g_value_get_ulong (value); break;
case G_TYPE_ENUM: *GTK_RETLOC_ENUM (*arg) = g_value_get_enum (value); break;
case G_TYPE_FLAGS: *GTK_RETLOC_FLAGS (*arg) = g_value_get_flags (value); break;
case G_TYPE_FLOAT: *GTK_RETLOC_FLOAT (*arg) = g_value_get_float (value); break;
case G_TYPE_DOUBLE: *GTK_RETLOC_DOUBLE (*arg) = g_value_get_double (value); break;
case G_TYPE_BOXED: *GTK_RETLOC_BOXED (*arg) = g_value_get_boxed (value); break;
case G_TYPE_POINTER: *GTK_RETLOC_POINTER (*arg) = g_value_get_pointer (value); break;
case G_TYPE_OBJECT: *GTK_RETLOC_POINTER (*arg) = g_value_get_object (value); break;
case G_TYPE_STRING: if (copy_string)
*GTK_RETLOC_STRING (*arg) = g_value_dup_string (value);
else
*GTK_RETLOC_STRING (*arg) = g_value_get_string (value);
break;
default:
return FALSE;
}
return TRUE;
}
void
gtk_signal_emitv (GtkObject *object,
guint signal_id,
GtkArg *args)
{
GSignalQuery query;
GValue params[SIGNAL_MAX_PARAMS + 1] = { { 0, }, };
GValue rvalue = { 0, };
guint i;
g_return_if_fail (GTK_IS_OBJECT (object));
g_signal_query (signal_id, &query);
g_return_if_fail (query.signal_id != 0);
g_return_if_fail (g_type_is_a (GTK_OBJECT_TYPE (object), query.itype));
g_return_if_fail (query.n_params < SIGNAL_MAX_PARAMS);
if (query.n_params > 0)
g_return_if_fail (args != NULL);
g_value_init (params + 0, GTK_OBJECT_TYPE (object));
g_value_set_object (params + 0, G_OBJECT (object));
for (i = 0; i < query.n_params; i++)
{
GValue *value = params + 1 + i;
GtkArg *arg = args + i;
g_value_init (value, arg->type);
if (!gtk_arg_static_to_value (arg, value))
{
g_warning ("%s: failed to convert arg type `%s' to value type `%s'",
G_STRLOC, g_type_name (arg->type), g_type_name (G_VALUE_TYPE (value)));
return;
}
}
if (query.return_type != G_TYPE_NONE)
g_value_init (&rvalue, query.return_type);
g_signal_emitv (params, signal_id, 0, &rvalue);
if (query.return_type != G_TYPE_NONE)
{
gtk_argloc_set_from_value (args + query.n_params, &rvalue, TRUE);
g_value_unset (&rvalue);
}
for (i = 0; i < query.n_params; i++)
g_value_unset (params + 1 + i);
g_value_unset (params + 0);
}
static gboolean
gtk_signal_collect_args (GtkArg *args,
guint n_args,
const GtkType *arg_types,
GtkType return_type,
va_list var_args)
{
register GtkArg *last_arg;
register gboolean failed = FALSE;
for (last_arg = args + n_args; args < last_arg; args++)
{
register gchar *error;
args->name = NULL;
args->type = *(arg_types++);
GTK_ARG_COLLECT_VALUE (args,
var_args,
error);
if (error)
{
failed = TRUE;
g_warning ("gtk_signal_collect_args(): %s", error);
g_free (error);
}
}
args->type = return_type;
args->name = NULL;
return_type = GTK_FUNDAMENTAL_TYPE (return_type);
if (return_type != G_TYPE_NONE)
{
if (return_type != 0) /* FIXME: check for IS_ARG */
{
GTK_VALUE_POINTER (*args) = va_arg (var_args, gpointer);
if (GTK_VALUE_POINTER (*args) == NULL)
{
failed = TRUE;
g_warning ("gtk_signal_collect_args(): invalid NULL pointer for return argument type `%s'",
gtk_type_name (args->type));
}
}
else
{
failed = TRUE;
g_warning ("gtk_signal_collect_args(): unsupported return argument type `%s'",
gtk_type_name (args->type));
}
}
else
GTK_VALUE_POINTER (*args) = NULL;
return failed;
}
#if 0
void
gtk_signal_emit (GtkObject *object,
guint signal_id,
...)
{
GtkArg args[SIGNAL_MAX_PARAMS + 1];
GSignalQuery query;
gboolean abort;
va_list var_args;
g_return_if_fail (GTK_IS_OBJECT (object));
g_signal_query (signal_id, &query);
g_return_if_fail (query.signal_id != 0);
g_return_if_fail (query.n_params < SIGNAL_MAX_PARAMS);
va_start (var_args, signal_id);
abort = gtk_signal_collect_args (args,
query.n_params,
query.param_types,
query.return_type,
var_args);
va_end (var_args);
if (!abort)
gtk_signal_emitv (object, signal_id, args);
}
#endif
void
gtk_signal_emit (GtkObject *object,
guint signal_id,
...)
{
va_list var_args;
g_return_if_fail (GTK_IS_OBJECT (object));
va_start (var_args, signal_id);
g_signal_emit_valist (G_OBJECT (object), signal_id, 0, var_args);
va_end (var_args);
}
void
gtk_signal_emit_by_name (GtkObject *object,
const gchar *name,
...)
{
GtkArg args[SIGNAL_MAX_PARAMS + 1];
GSignalQuery query;
gboolean abort;
va_list var_args;
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (name != NULL);
g_signal_query (g_signal_lookup (name, GTK_OBJECT_TYPE (object)), &query);
g_return_if_fail (query.signal_id != 0);
g_return_if_fail (query.n_params < SIGNAL_MAX_PARAMS);
va_start (var_args, name);
abort = gtk_signal_collect_args (args,
query.n_params,
query.param_types,
query.return_type,
var_args);
va_end (var_args);
if (!abort)
gtk_signal_emitv (object, query.signal_id, args);
}
void
gtk_signal_emitv_by_name (GtkObject *object,
const gchar *name,
GtkArg *args)
{
g_return_if_fail (GTK_IS_OBJECT (object));
gtk_signal_emitv (object, g_signal_lookup (name, GTK_OBJECT_TYPE (object)), args);
}
|