462
|
1 /* ui-gtk.c
|
|
2 **
|
|
3 ** Description: Creating 'real' UIs from lisp.
|
|
4 **
|
|
5 ** Created by: William M. Perry <wmperry@gnu.org>
|
|
6 ** Copyright (c) 2000 William M. Perry <wmperry@gnu.org>
|
|
7 **
|
|
8 */
|
|
9
|
|
10 #include <config.h>
|
|
11 #include "lisp.h"
|
1346
|
12
|
462
|
13 #include "buffer.h"
|
2168
|
14 #include "console-gtk-impl.h"
|
462
|
15 #include "device.h"
|
|
16 #include "elhash.h"
|
778
|
17 #include "event-gtk.h"
|
1346
|
18 #include "events.h"
|
|
19 #include "faces.h"
|
|
20 #include "glyphs-gtk.h"
|
|
21 #include "hash.h"
|
|
22 #include "objects-gtk.h"
|
|
23 #include "sysdll.h"
|
|
24 #include "ui-gtk.h"
|
|
25 #include "window.h"
|
462
|
26
|
|
27 /* XEmacs specific GTK types */
|
|
28 #include "gtk-glue.c"
|
|
29
|
2054
|
30 /* Is the fundamental type of 't' the xemacs defined fundamental type 'type'? */
|
|
31 #define IS_XEMACS_GTK_FUNDAMENTAL_TYPE(t,type) (((GtkType) GTK_FUNDAMENTAL_TYPE(t)) == (type))
|
|
32
|
462
|
33 Lisp_Object Qemacs_ffip;
|
|
34 Lisp_Object Qemacs_gtk_objectp;
|
|
35 Lisp_Object Qemacs_gtk_boxedp;
|
|
36 Lisp_Object Qvoid;
|
|
37 Lisp_Object Venumeration_info;
|
|
38
|
|
39 static GHashTable *dll_cache;
|
|
40
|
|
41 Lisp_Object gtk_type_to_lisp (GtkArg *arg);
|
|
42 int lisp_to_gtk_type (Lisp_Object obj, GtkArg *arg);
|
1883
|
43 int lisp_to_gtk_ret_type (Lisp_Object obj, GtkArg *arg);
|
778
|
44 #if 0
|
462
|
45 void describe_gtk_arg (GtkArg *arg);
|
778
|
46 #endif
|
462
|
47 guint symbol_to_enum (Lisp_Object obj, GtkType t);
|
|
48 static guint lisp_to_flag (Lisp_Object obj, GtkType t);
|
|
49 static Lisp_Object flags_to_list (guint value, GtkType t);
|
|
50 static Lisp_Object enum_to_symbol (guint value, GtkType t);
|
|
51
|
|
52 #define NIL_OR_VOID_P(x) (NILP (x) || EQ (x, Qvoid))
|
|
53
|
|
54 static void
|
|
55 initialize_dll_cache (void)
|
|
56 {
|
|
57 if (!dll_cache)
|
|
58 {
|
2054
|
59 static char text[] = "---XEmacs Internal Handle---";
|
|
60
|
462
|
61 dll_cache = g_hash_table_new (g_str_hash, g_str_equal);
|
|
62
|
2054
|
63 g_hash_table_insert (dll_cache, text, dll_open (Qnil));
|
462
|
64 }
|
|
65 }
|
|
66
|
|
67 DEFUN ("dll-load", Fdll_load, 1, 1, 0, /*
|
|
68 Load a shared library DLL into XEmacs. No initialization routines are required.
|
|
69 This is for loading dependency DLLs into XEmacs.
|
|
70 */
|
|
71 (dll))
|
|
72 {
|
|
73 dll_handle h;
|
|
74
|
|
75 CHECK_STRING (dll);
|
|
76
|
|
77 initialize_dll_cache ();
|
|
78
|
|
79 /* If the dll name has a directory component in it, then we should
|
|
80 expand it. */
|
|
81 if (!NILP (Fstring_match (build_string ("/"), dll, Qnil, Qnil)))
|
|
82 dll = Fexpand_file_name (dll, Qnil);
|
|
83
|
|
84 /* Check if we have already opened it first */
|
|
85 h = g_hash_table_lookup (dll_cache, XSTRING_DATA (dll));
|
|
86
|
|
87 if (!h)
|
|
88 {
|
1811
|
89 h = dll_open (dll);
|
462
|
90
|
|
91 if (h)
|
|
92 {
|
2054
|
93 g_hash_table_insert (dll_cache, qxestrdup (XSTRING_DATA (dll)), h);
|
462
|
94 }
|
|
95 else
|
|
96 {
|
2054
|
97 signal_error (Qfile_error, "dll_open error", dll_error());
|
462
|
98 }
|
|
99 }
|
|
100 return (h ? Qt : Qnil);
|
|
101 }
|
|
102
|
|
103
|
|
104 /* Gtk object importing */
|
|
105 EXFUN (Fgtk_import_type, 1);
|
|
106
|
|
107 static struct hash_table *internal_type_hash;
|
|
108
|
|
109 static int
|
|
110 type_already_imported_p (GtkType t)
|
|
111 {
|
|
112 void *retval = NULL;
|
|
113
|
|
114 /* These are cases that we don't need to import */
|
|
115 switch (GTK_FUNDAMENTAL_TYPE (t))
|
|
116 {
|
|
117 case GTK_TYPE_CHAR:
|
|
118 case GTK_TYPE_UCHAR:
|
|
119 case GTK_TYPE_BOOL:
|
|
120 case GTK_TYPE_INT:
|
|
121 case GTK_TYPE_UINT:
|
|
122 case GTK_TYPE_LONG:
|
|
123 case GTK_TYPE_ULONG:
|
|
124 case GTK_TYPE_FLOAT:
|
|
125 case GTK_TYPE_DOUBLE:
|
|
126 case GTK_TYPE_STRING:
|
|
127 case GTK_TYPE_BOXED:
|
|
128 case GTK_TYPE_POINTER:
|
|
129 case GTK_TYPE_SIGNAL:
|
|
130 case GTK_TYPE_ARGS:
|
|
131 case GTK_TYPE_CALLBACK:
|
|
132 case GTK_TYPE_C_CALLBACK:
|
|
133 case GTK_TYPE_FOREIGN:
|
|
134 return (1);
|
|
135 }
|
|
136
|
|
137 if (!internal_type_hash)
|
|
138 {
|
2515
|
139 internal_type_hash = make_hash_table (163);
|
462
|
140 return (0);
|
|
141 }
|
|
142
|
|
143 if (gethash ((void *)t, internal_type_hash, (const void **)&retval))
|
|
144 {
|
|
145 return (1);
|
|
146 }
|
|
147 return (0);
|
|
148 }
|
|
149
|
|
150 static void
|
|
151 mark_type_as_imported (GtkType t)
|
|
152 {
|
|
153 if (type_already_imported_p (t))
|
|
154 return;
|
|
155
|
|
156 puthash ((void *) t, (void *) 1, internal_type_hash);
|
|
157 }
|
|
158
|
|
159 static void import_gtk_type (GtkType t);
|
|
160
|
|
161 static void
|
|
162 import_gtk_object_internal (GtkType the_type)
|
|
163 {
|
|
164 GtkType original_type = the_type;
|
|
165 int first_time = 1;
|
|
166
|
|
167 do
|
|
168 {
|
|
169 GtkArg *args;
|
|
170 guint32 *flags;
|
|
171 guint n_args;
|
|
172 guint i;
|
|
173 #if 0
|
|
174 GtkObjectClass *klass;
|
|
175 GtkSignalQuery *query;
|
|
176 guint32 *signals;
|
|
177 guint n_signals;
|
|
178 #endif
|
|
179
|
|
180 /* Register the type before we do anything else with it... */
|
|
181 if (!first_time)
|
|
182 {
|
|
183 if (!type_already_imported_p (the_type))
|
|
184 {
|
|
185 import_gtk_type (the_type);
|
|
186 }
|
|
187 }
|
|
188 else
|
|
189 {
|
|
190 /* We need to mark the object type as imported here or we
|
|
191 run the risk of SERIOUS recursion when we do automatic
|
|
192 argument type importing. mark_type_as_imported() is
|
|
193 smart enough to be a noop if we attempt to register
|
|
194 things twice. */
|
|
195 first_time = 0;
|
|
196 mark_type_as_imported (the_type);
|
|
197 }
|
|
198
|
|
199 args = gtk_object_query_args(the_type,&flags,&n_args);
|
|
200
|
|
201 /* First get the arguments the object can accept */
|
|
202 for (i = 0; i < n_args; i++)
|
|
203 {
|
|
204 if ((args[i].type != original_type) && !type_already_imported_p (args[i].type))
|
|
205 {
|
|
206 import_gtk_type (args[i].type);
|
|
207 }
|
|
208 }
|
|
209
|
|
210 g_free(args);
|
|
211 g_free(flags);
|
|
212
|
|
213 #if 0
|
|
214 /* Now lets publish the signals */
|
|
215 klass = (GtkObjectClass *) gtk_type_class (the_type);
|
|
216 signals = klass->signals;
|
|
217 n_signals = klass->nsignals;
|
|
218
|
|
219 for (i = 0; i < n_signals; i++)
|
|
220 {
|
|
221 query = gtk_signal_query (signals[i]);
|
|
222 /* What do we want to do here? */
|
|
223 g_free (query);
|
|
224 }
|
|
225 #endif
|
|
226
|
|
227 the_type = gtk_type_parent(the_type);
|
|
228 } while (the_type != GTK_TYPE_INVALID);
|
|
229 }
|
|
230
|
|
231 static void
|
|
232 import_gtk_enumeration_internal (GtkType the_type)
|
|
233 {
|
|
234 GtkEnumValue *vals = gtk_type_enum_get_values (the_type);
|
|
235 Lisp_Object assoc = Qnil;
|
|
236
|
|
237 if (NILP (Venumeration_info))
|
|
238 {
|
|
239 Venumeration_info = call2 (intern ("make-hashtable"), make_int (100), Qequal);
|
|
240 }
|
|
241
|
|
242 while (vals && vals->value_name)
|
|
243 {
|
|
244 assoc = Fcons (Fcons (intern (vals->value_nick), make_int (vals->value)), assoc);
|
|
245 assoc = Fcons (Fcons (intern (vals->value_name), make_int (vals->value)), assoc);
|
|
246 vals++;
|
|
247 }
|
|
248
|
|
249 assoc = Fnreverse (assoc);
|
|
250
|
|
251 Fputhash (make_int (the_type), assoc, Venumeration_info);
|
|
252 }
|
|
253
|
|
254 static void
|
|
255 import_gtk_type (GtkType t)
|
|
256 {
|
|
257 if (type_already_imported_p (t))
|
|
258 {
|
|
259 return;
|
|
260 }
|
|
261
|
|
262 switch (GTK_FUNDAMENTAL_TYPE (t))
|
|
263 {
|
|
264 case GTK_TYPE_ENUM:
|
|
265 case GTK_TYPE_FLAGS:
|
|
266 import_gtk_enumeration_internal (t);
|
|
267 break;
|
|
268 case GTK_TYPE_OBJECT:
|
|
269 import_gtk_object_internal (t);
|
|
270 break;
|
|
271 default:
|
|
272 break;
|
|
273 }
|
|
274
|
|
275 mark_type_as_imported (t);
|
|
276 }
|
|
277
|
|
278
|
|
279 /* Foreign function calls */
|
|
280 static emacs_ffi_data *
|
|
281 allocate_ffi_data (void)
|
|
282 {
|
2720
|
283 #ifdef MC_ALLOC
|
|
284 emacs_ffi_data *data = alloc_lrecord_type (emacs_ffi_data, &lrecord_emacs_ffi);
|
|
285 #else /* not MC_ALLOC */
|
462
|
286 emacs_ffi_data *data = alloc_lcrecord_type (emacs_ffi_data, &lrecord_emacs_ffi);
|
2720
|
287 #endif /* not MC_ALLOC */
|
462
|
288
|
|
289 data->return_type = GTK_TYPE_NONE;
|
|
290 data->n_args = 0;
|
|
291 data->function_name = Qnil;
|
|
292 data->function_ptr = 0;
|
|
293 data->marshal = 0;
|
|
294
|
|
295 return (data);
|
|
296 }
|
|
297
|
1204
|
298 static const struct memory_description ffi_data_description [] = {
|
|
299 { XD_LISP_OBJECT, offsetof (emacs_ffi_data, function_name) },
|
934
|
300 { XD_END }
|
|
301 };
|
|
302
|
462
|
303 static Lisp_Object
|
|
304 mark_ffi_data (Lisp_Object obj)
|
|
305 {
|
|
306 emacs_ffi_data *data = (emacs_ffi_data *) XFFI (obj);
|
|
307
|
|
308 mark_object (data->function_name);
|
|
309 return (Qnil);
|
|
310 }
|
|
311
|
|
312 static void
|
2286
|
313 ffi_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
314 int UNUSED (escapeflag))
|
462
|
315 {
|
|
316 if (print_readably)
|
563
|
317 printing_unreadable_object ("#<ffi %p>", XFFI (obj)->function_ptr);
|
462
|
318
|
800
|
319 write_fmt_string_lisp (printcharfun, "#<ffi %S", 1, XFFI (obj)->function_name);
|
462
|
320 if (XFFI (obj)->n_args)
|
800
|
321 write_fmt_string (printcharfun, " %d arguments", XFFI (obj)->n_args);
|
|
322 write_fmt_string (printcharfun, " %p>", (void *)XFFI (obj)->function_ptr);
|
462
|
323 }
|
|
324
|
934
|
325 DEFINE_LRECORD_IMPLEMENTATION ("ffi", emacs_ffi,
|
960
|
326 0, /*dumpable-flag*/
|
934
|
327 mark_ffi_data, ffi_object_printer,
|
|
328 0, 0, 0,
|
|
329 ffi_data_description, emacs_ffi_data);
|
462
|
330
|
2054
|
331 #if defined (__cplusplus)
|
|
332 #define MANY_ARGS ...
|
|
333 #else
|
|
334 #define MANY_ARGS
|
|
335 #endif
|
|
336
|
|
337 typedef void (*pfv)();
|
|
338 typedef GtkObject * (*__OBJECT_fn) (MANY_ARGS);
|
|
339 typedef gint (*__INT_fn) (MANY_ARGS);
|
|
340 typedef void (*__NONE_fn) (MANY_ARGS);
|
|
341 typedef gchar * (*__STRING_fn) (MANY_ARGS);
|
|
342 typedef gboolean (*__BOOL_fn) (MANY_ARGS);
|
|
343 typedef gfloat (*__FLOAT_fn) (MANY_ARGS);
|
|
344 typedef void * (*__POINTER_fn) (MANY_ARGS);
|
|
345 typedef GList * (*__LIST_fn) (MANY_ARGS);
|
462
|
346
|
|
347 /* An auto-generated file of marshalling functions. */
|
|
348 #include "emacs-marshals.c"
|
2054
|
349 #undef MANY_ARGS
|
462
|
350
|
|
351 #define CONVERT_SINGLE_TYPE(var,nam,tp) case GTK_TYPE_##nam: GTK_VALUE_##nam (var) = * (tp *) v; break;
|
|
352 #define CONVERT_RETVAL(a,freep) \
|
|
353 do { \
|
|
354 void *v = GTK_VALUE_POINTER(a); \
|
|
355 switch (GTK_FUNDAMENTAL_TYPE (a.type)) \
|
1726
|
356 { \
|
462
|
357 CONVERT_SINGLE_TYPE(a,CHAR,gchar); \
|
|
358 CONVERT_SINGLE_TYPE(a,UCHAR,guchar); \
|
|
359 CONVERT_SINGLE_TYPE(a,BOOL,gboolean); \
|
|
360 CONVERT_SINGLE_TYPE(a,INT,gint); \
|
|
361 CONVERT_SINGLE_TYPE(a,UINT,guint); \
|
|
362 CONVERT_SINGLE_TYPE(a,LONG,glong); \
|
|
363 CONVERT_SINGLE_TYPE(a,ULONG,gulong); \
|
|
364 CONVERT_SINGLE_TYPE(a,FLOAT,gfloat); \
|
|
365 CONVERT_SINGLE_TYPE(a,DOUBLE,gdouble); \
|
|
366 CONVERT_SINGLE_TYPE(a,STRING,gchar *); \
|
|
367 CONVERT_SINGLE_TYPE(a,ENUM,gint); \
|
|
368 CONVERT_SINGLE_TYPE(a,FLAGS,guint); \
|
|
369 CONVERT_SINGLE_TYPE(a,BOXED,void *); \
|
|
370 CONVERT_SINGLE_TYPE(a,POINTER,void *); \
|
|
371 CONVERT_SINGLE_TYPE(a,OBJECT,GtkObject *); \
|
1726
|
372 default: \
|
|
373 GTK_VALUE_POINTER (a) = * (void **) v; \
|
462
|
374 break; \
|
1726
|
375 } \
|
|
376 if (freep) xfree(v, void *); \
|
462
|
377 } while (0)
|
|
378
|
778
|
379 static gpointer __allocate_object_storage (GtkType t)
|
462
|
380 {
|
|
381 size_t s = 0;
|
|
382 void *rval = NULL;
|
|
383
|
|
384 switch (GTK_FUNDAMENTAL_TYPE (t))
|
|
385 {
|
|
386 /* flag types */
|
|
387 case GTK_TYPE_CHAR:
|
|
388 s = (sizeof (gchar));
|
|
389 break;
|
|
390 case GTK_TYPE_UCHAR:
|
|
391 s = (sizeof (guchar));
|
|
392 break;
|
|
393 case GTK_TYPE_BOOL:
|
|
394 s = (sizeof (gboolean));
|
|
395 break;
|
|
396 case GTK_TYPE_INT:
|
|
397 s = (sizeof (gint));
|
|
398 break;
|
|
399 case GTK_TYPE_UINT:
|
|
400 s = (sizeof (guint));
|
|
401 break;
|
|
402 case GTK_TYPE_LONG:
|
|
403 s = (sizeof (glong));
|
|
404 break;
|
|
405 case GTK_TYPE_ULONG:
|
|
406 s = (sizeof (gulong));
|
|
407 break;
|
|
408 case GTK_TYPE_FLOAT:
|
|
409 s = (sizeof (gfloat));
|
|
410 break;
|
|
411 case GTK_TYPE_DOUBLE:
|
|
412 s = (sizeof (gdouble));
|
|
413 break;
|
|
414 case GTK_TYPE_STRING:
|
|
415 s = (sizeof (gchar *));
|
|
416 break;
|
|
417 case GTK_TYPE_ENUM:
|
|
418 case GTK_TYPE_FLAGS:
|
|
419 s = (sizeof (guint));
|
|
420 break;
|
|
421 case GTK_TYPE_BOXED:
|
|
422 case GTK_TYPE_POINTER:
|
|
423 s = (sizeof (void *));
|
|
424 break;
|
|
425
|
|
426 /* base type of the object system */
|
|
427 case GTK_TYPE_OBJECT:
|
|
428 s = (sizeof (GtkObject *));
|
|
429 break;
|
|
430
|
|
431 default:
|
2054
|
432 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(t, GTK_TYPE_LISTOF))
|
462
|
433 {
|
|
434 s = (sizeof (void *));
|
|
435 }
|
|
436 rval = NULL;
|
|
437 break;
|
|
438 }
|
|
439
|
|
440 if (s)
|
|
441 {
|
|
442 rval = xmalloc (s);
|
|
443 memset (rval, '\0', s);
|
|
444 }
|
|
445
|
|
446 return (rval);
|
|
447 }
|
|
448
|
778
|
449 static Lisp_Object type_to_marshaller_type (GtkType t)
|
462
|
450 {
|
|
451 switch (GTK_FUNDAMENTAL_TYPE (t))
|
|
452 {
|
|
453 case GTK_TYPE_NONE:
|
|
454 return (build_string ("NONE"));
|
|
455 /* flag types */
|
|
456 case GTK_TYPE_CHAR:
|
|
457 case GTK_TYPE_UCHAR:
|
|
458 return (build_string ("CHAR"));
|
|
459 case GTK_TYPE_BOOL:
|
|
460 return (build_string ("BOOL"));
|
|
461 case GTK_TYPE_ENUM:
|
|
462 case GTK_TYPE_FLAGS:
|
|
463 case GTK_TYPE_INT:
|
|
464 case GTK_TYPE_UINT:
|
|
465 return (build_string ("INT"));
|
|
466 case GTK_TYPE_LONG:
|
|
467 case GTK_TYPE_ULONG:
|
|
468 return (build_string ("LONG"));
|
|
469 case GTK_TYPE_FLOAT:
|
|
470 case GTK_TYPE_DOUBLE:
|
|
471 return (build_string ("FLOAT"));
|
|
472 case GTK_TYPE_STRING:
|
|
473 return (build_string ("STRING"));
|
|
474 case GTK_TYPE_BOXED:
|
|
475 case GTK_TYPE_POINTER:
|
|
476 return (build_string ("POINTER"));
|
|
477 case GTK_TYPE_OBJECT:
|
|
478 return (build_string ("OBJECT"));
|
|
479 case GTK_TYPE_CALLBACK:
|
|
480 return (build_string ("CALLBACK"));
|
|
481 default:
|
|
482 /* I can't put this in the main switch statement because it is a
|
|
483 new fundamental type that is not fixed at compile time.
|
|
484 *sigh*
|
|
485 */
|
2054
|
486 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(t, GTK_TYPE_ARRAY))
|
462
|
487 return (build_string ("ARRAY"));
|
|
488
|
2054
|
489 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(t, GTK_TYPE_LISTOF))
|
462
|
490 return (build_string ("LIST"));
|
|
491 return (Qnil);
|
|
492 }
|
|
493 }
|
|
494
|
|
495 struct __dll_mapper_closure {
|
2054
|
496 void * (*func) (dll_handle, const CIbyte *);
|
|
497 Ibyte *obj_name;
|
462
|
498 void **storage;
|
|
499 };
|
|
500
|
2286
|
501 static void __dll_mapper (gpointer UNUSED (key), gpointer value,
|
|
502 gpointer user_data)
|
462
|
503 {
|
|
504 struct __dll_mapper_closure *closure = (struct __dll_mapper_closure *) user_data;
|
|
505
|
|
506 if (*(closure->storage) == NULL)
|
|
507 {
|
|
508 /* Need to see if it is in this one */
|
2054
|
509 *(closure->storage) = closure->func ((dll_handle) value, (CIbyte*) closure->obj_name);
|
462
|
510 }
|
|
511 }
|
|
512
|
|
513 DEFUN ("gtk-import-variable-internal", Fgtk_import_variable_internal, 2, 2, 0, /*
|
|
514 Import a variable into the XEmacs namespace.
|
|
515 */
|
|
516 (type, name))
|
|
517 {
|
|
518 void *var = NULL;
|
|
519 GtkArg arg;
|
|
520
|
|
521 if (SYMBOLP (type)) type = Fsymbol_name (type);
|
|
522
|
|
523 CHECK_STRING (type);
|
|
524 CHECK_STRING (name);
|
|
525
|
|
526 initialize_dll_cache ();
|
|
527 xemacs_init_gtk_classes ();
|
|
528
|
|
529 arg.type = gtk_type_from_name ((char *) XSTRING_DATA (type));
|
|
530
|
|
531 if (arg.type == GTK_TYPE_INVALID)
|
|
532 {
|
563
|
533 sferror ("Unknown type", type);
|
462
|
534 }
|
|
535
|
|
536 /* Need to look thru the already-loaded dlls */
|
|
537 {
|
|
538 struct __dll_mapper_closure closure;
|
|
539
|
|
540 closure.func = dll_variable;
|
|
541 closure.obj_name = XSTRING_DATA (name);
|
|
542 closure.storage = &var;
|
|
543
|
|
544 g_hash_table_foreach (dll_cache, __dll_mapper, &closure);
|
|
545 }
|
|
546
|
|
547 if (!var)
|
|
548 {
|
563
|
549 gui_error ("Could not locate variable", name);
|
462
|
550 }
|
|
551
|
|
552 GTK_VALUE_POINTER(arg) = var;
|
|
553 CONVERT_RETVAL (arg, 0);
|
|
554 return (gtk_type_to_lisp (&arg));
|
|
555 }
|
|
556
|
|
557 DEFUN ("gtk-import-function-internal", Fgtk_import_function_internal, 2, 3, 0, /*
|
|
558 Import a function into the XEmacs namespace.
|
|
559 */
|
|
560 (rettype, name, args))
|
|
561 {
|
|
562 Lisp_Object rval = Qnil;
|
|
563 Lisp_Object marshaller = Qnil;
|
|
564 emacs_ffi_data *data = NULL;
|
|
565 gint n_args = 0;
|
|
566 #if 0
|
|
567 dll_handle h = NULL;
|
|
568 #endif
|
|
569 ffi_marshalling_function marshaller_func = NULL;
|
|
570 ffi_actual_function name_func = NULL;
|
|
571
|
|
572 CHECK_SYMBOL (rettype);
|
|
573 CHECK_STRING (name);
|
|
574 CHECK_LIST (args);
|
|
575
|
|
576 initialize_dll_cache ();
|
|
577 xemacs_init_gtk_classes ();
|
|
578
|
|
579 /* Need to look thru the already-loaded dlls */
|
|
580 {
|
|
581 struct __dll_mapper_closure closure;
|
|
582
|
|
583 closure.func = dll_function;
|
|
584 closure.obj_name = XSTRING_DATA (name);
|
|
585 closure.storage = (void **) &name_func;
|
|
586
|
|
587 g_hash_table_foreach (dll_cache, __dll_mapper, &closure);
|
|
588 }
|
|
589
|
|
590 if (!name_func)
|
|
591 {
|
563
|
592 gui_error ("Could not locate function", name);
|
462
|
593 }
|
|
594
|
|
595 data = allocate_ffi_data ();
|
|
596
|
|
597 if (NILP (rettype))
|
|
598 {
|
|
599 rettype = Qvoid;
|
|
600 }
|
|
601
|
|
602 if (!NILP (args))
|
|
603 {
|
|
604 Lisp_Object value = args;
|
|
605 Lisp_Object type = Qnil;
|
|
606
|
2367
|
607 EXTERNAL_LIST_LOOP_2 (elt, value)
|
462
|
608 {
|
|
609 GtkType the_type;
|
|
610 Lisp_Object marshaller_type = Qnil;
|
|
611
|
2367
|
612 CHECK_SYMBOL (elt);
|
462
|
613
|
2367
|
614 type = Fsymbol_name (elt);
|
462
|
615
|
|
616 the_type = gtk_type_from_name ((char *) XSTRING_DATA (type));
|
|
617
|
|
618 if (the_type == GTK_TYPE_INVALID)
|
|
619 {
|
563
|
620 invalid_argument ("Unknown argument type", type);
|
462
|
621 }
|
|
622
|
|
623 /* All things must be reduced to their basest form... */
|
|
624 import_gtk_type (the_type);
|
|
625 data->args[n_args] = the_type; /* GTK_FUNDAMENTAL_TYPE (the_type); */
|
|
626
|
|
627 /* Now lets build up another chunk of our marshaller function name */
|
|
628 marshaller_type = type_to_marshaller_type (data->args[n_args]);
|
|
629
|
|
630 if (NILP (marshaller_type))
|
|
631 {
|
563
|
632 invalid_argument ("Do not know how to marshal", type);
|
462
|
633 }
|
|
634 marshaller = concat3 (marshaller, build_string ("_"), marshaller_type);
|
|
635 n_args++;
|
|
636 }
|
|
637 }
|
|
638 else
|
|
639 {
|
|
640 marshaller = concat3 (marshaller, build_string ("_"), type_to_marshaller_type (GTK_TYPE_NONE));
|
|
641 }
|
|
642
|
|
643 rettype = Fsymbol_name (rettype);
|
|
644 data->return_type = gtk_type_from_name ((char *) XSTRING_DATA (rettype));
|
|
645
|
|
646 if (data->return_type == GTK_TYPE_INVALID)
|
|
647 {
|
563
|
648 invalid_argument ("Unknown return type", rettype);
|
462
|
649 }
|
|
650
|
|
651 import_gtk_type (data->return_type);
|
|
652
|
|
653 marshaller = concat3 (type_to_marshaller_type (data->return_type), build_string ("_"), marshaller);
|
|
654 marshaller = concat2 (build_string ("emacs_gtk_marshal_"), marshaller);
|
|
655
|
|
656 marshaller_func = (ffi_marshalling_function) find_marshaller ((char *) XSTRING_DATA (marshaller));
|
|
657
|
|
658 if (!marshaller_func)
|
|
659 {
|
563
|
660 gui_error ("Could not locate marshaller function", marshaller);
|
462
|
661 }
|
|
662
|
|
663 data->n_args = n_args;
|
|
664 data->function_name = name;
|
2054
|
665 data->function_ptr = (dll_func) name_func;
|
462
|
666 data->marshal = marshaller_func;
|
|
667
|
797
|
668 rval = wrap_emacs_ffi (data);
|
462
|
669 return (rval);
|
|
670 }
|
|
671
|
|
672 DEFUN ("gtk-call-function", Fgtk_call_function, 1, 2, 0, /*
|
|
673 Call an external function.
|
|
674 */
|
|
675 (func, args))
|
|
676 {
|
|
677 GtkArg the_args[MAX_GTK_ARGS];
|
|
678 gint n_args = 0;
|
|
679 Lisp_Object retval = Qnil;
|
|
680
|
|
681 CHECK_FFI (func);
|
|
682 CHECK_LIST (args);
|
|
683
|
|
684 n_args = XINT (Flength (args));
|
|
685
|
|
686 #ifdef XEMACS_IS_SMARTER_THAN_THE_PROGRAMMER
|
|
687 /* #### I think this is too dangerous to enable by default.
|
|
688 ** #### Genuine program bugs would probably be allowed to
|
|
689 ** #### slip by, and not be very easy to find.
|
|
690 ** #### Bill Perry July 9, 2000
|
|
691 */
|
|
692 if (n_args != XFFI(func)->n_args)
|
|
693 {
|
|
694 Lisp_Object for_append[3];
|
|
695
|
|
696 /* Signal an error if they pass in too many arguments */
|
|
697 if (n_args > XFFI(func)->n_args)
|
|
698 {
|
|
699 return Fsignal (Qwrong_number_of_arguments,
|
|
700 list2 (func, make_int (n_args)));
|
|
701 }
|
|
702
|
|
703 /* If they did not provide enough arguments, be nice and assume
|
|
704 ** they wanted `nil' in there.
|
|
705 */
|
|
706 for_append[0] = args;
|
|
707 for_append[1] = Fmake_list (make_int (XFFI(func)->n_args - n_args), Qnil);
|
|
708
|
|
709 args = Fappend (2, for_append);
|
|
710 }
|
|
711 #else
|
|
712 if (n_args != XFFI(func)->n_args)
|
|
713 {
|
|
714 /* Signal an error if they do not pass in the correct # of arguments */
|
|
715 return Fsignal (Qwrong_number_of_arguments,
|
|
716 list2 (func, make_int (n_args)));
|
|
717 }
|
|
718 #endif
|
|
719
|
|
720 if (!NILP (args))
|
|
721 {
|
|
722 Lisp_Object value = args;
|
|
723
|
|
724 CHECK_LIST (args);
|
|
725 n_args = 0;
|
|
726
|
|
727 /* First we convert all of the arguments from Lisp to GtkArgs */
|
2367
|
728 {
|
|
729 EXTERNAL_LIST_LOOP_2 (elt, value)
|
|
730 {
|
|
731 the_args[n_args].type = XFFI (func)->args[n_args];
|
462
|
732
|
2367
|
733 if (lisp_to_gtk_type (elt, &the_args[n_args]))
|
|
734 {
|
|
735 /* There was some sort of an error */
|
|
736 gui_error ("Error converting arguments", args);
|
|
737 }
|
|
738 n_args++;
|
|
739 }
|
|
740 }
|
462
|
741 }
|
|
742
|
|
743 /* Now we need to tack on space for a return value, if they have
|
|
744 asked for one */
|
|
745 if (XFFI (func)->return_type != GTK_TYPE_NONE)
|
|
746 {
|
|
747 the_args[n_args].type = XFFI (func)->return_type;
|
|
748 GTK_VALUE_POINTER (the_args[n_args]) = __allocate_object_storage (the_args[n_args].type);
|
|
749 n_args++;
|
|
750 }
|
|
751
|
|
752 XFFI (func)->marshal ((ffi_actual_function) (XFFI (func)->function_ptr), the_args);
|
|
753
|
|
754 if (XFFI (func)->return_type != GTK_TYPE_NONE)
|
|
755 {
|
|
756 CONVERT_RETVAL (the_args[n_args - 1], 1);
|
|
757 retval = gtk_type_to_lisp (&the_args[n_args - 1]);
|
|
758 }
|
|
759
|
|
760 /* Need to free any array or list pointers */
|
|
761 {
|
|
762 int i;
|
|
763 for (i = 0; i < n_args; i++)
|
|
764 {
|
2054
|
765 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(the_args[i].type, GTK_TYPE_ARRAY))
|
462
|
766 {
|
|
767 g_free (GTK_VALUE_POINTER (the_args[i]));
|
|
768 }
|
2054
|
769 else if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(the_args[i].type, GTK_TYPE_LISTOF))
|
462
|
770 {
|
|
771 /* g_list_free (GTK_VALUE_POINTER (the_args[i])); */
|
|
772 }
|
|
773 }
|
|
774 }
|
|
775
|
|
776 return (retval);
|
|
777 }
|
|
778
|
|
779
|
|
780
|
|
781 /* GtkObject wrapping for Lisp */
|
|
782 static void
|
2286
|
783 emacs_gtk_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
784 int UNUSED (escapeflag))
|
462
|
785 {
|
|
786 if (print_readably)
|
563
|
787 printing_unreadable_object ("#<GtkObject %p>", XGTK_OBJECT (obj)->object);
|
462
|
788
|
826
|
789 write_c_string (printcharfun, "#<GtkObject (");
|
462
|
790 if (XGTK_OBJECT (obj)->alive_p)
|
826
|
791 write_c_string (printcharfun, gtk_type_name (GTK_OBJECT_TYPE (XGTK_OBJECT (obj)->object)));
|
462
|
792 else
|
826
|
793 write_c_string (printcharfun, "dead");
|
800
|
794 write_fmt_string (printcharfun, ") %p>", (void *) XGTK_OBJECT (obj)->object);
|
462
|
795 }
|
|
796
|
|
797 static Lisp_Object
|
|
798 object_getprop (Lisp_Object obj, Lisp_Object prop)
|
|
799 {
|
|
800 Lisp_Object rval = Qnil;
|
|
801 Lisp_Object prop_name = Qnil;
|
|
802 GtkArgInfo *info = NULL;
|
|
803 char *err;
|
|
804 GtkArg args[2];
|
|
805
|
|
806 CHECK_SYMBOL (prop); /* Shouldn't need to ever do this, but I'm paranoid */
|
|
807
|
|
808 prop_name = Fsymbol_name (prop);
|
|
809
|
|
810 args[0].name = (char *) XSTRING_DATA (prop_name);
|
|
811
|
|
812 err = gtk_object_arg_get_info (GTK_OBJECT_TYPE (XGTK_OBJECT (obj)->object),
|
|
813 args[0].name,
|
|
814 &info);
|
|
815
|
|
816 if (err)
|
|
817 {
|
|
818 /* Not a magic symbol, fall back to just looking in our real plist */
|
|
819 g_free (err);
|
|
820
|
|
821 return (Fplist_get (XGTK_OBJECT (obj)->plist, prop, Qunbound));
|
|
822 }
|
|
823
|
|
824 if (!(info->arg_flags & GTK_ARG_READABLE))
|
|
825 {
|
563
|
826 invalid_operation ("Attempt to get write-only property", prop);
|
462
|
827 }
|
|
828
|
|
829 gtk_object_getv (XGTK_OBJECT (obj)->object, 1, args);
|
|
830
|
|
831 if (args[0].type == GTK_TYPE_INVALID)
|
|
832 {
|
|
833 /* If we can't get the attribute, then let the code in Fget know
|
|
834 so it can use the default value supplied by the caller */
|
|
835 return (Qunbound);
|
|
836 }
|
|
837
|
|
838 rval = gtk_type_to_lisp (&args[0]);
|
|
839
|
|
840 /* Free up any memory. According to the documentation and Havoc's
|
|
841 book, if the fundamental type of the returned value is
|
|
842 GTK_TYPE_STRING, GTK_TYPE_BOXED, or GTK_TYPE_ARGS, you are
|
|
843 responsible for freeing it. */
|
|
844 switch (GTK_FUNDAMENTAL_TYPE (args[0].type))
|
|
845 {
|
|
846 case GTK_TYPE_STRING:
|
|
847 g_free (GTK_VALUE_STRING (args[0]));
|
|
848 break;
|
|
849 case GTK_TYPE_BOXED:
|
|
850 g_free (GTK_VALUE_BOXED (args[0]));
|
|
851 break;
|
|
852 case GTK_TYPE_ARGS:
|
|
853 g_free (GTK_VALUE_ARGS (args[0]).args);
|
|
854 default:
|
|
855 break;
|
|
856 }
|
|
857
|
|
858 return (rval);
|
|
859 }
|
|
860
|
|
861 static int
|
|
862 object_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
|
|
863 {
|
|
864 GtkArgInfo *info = NULL;
|
|
865 Lisp_Object prop_name = Qnil;
|
|
866 GtkArg args[2];
|
|
867 char *err = NULL;
|
|
868
|
|
869 prop_name = Fsymbol_name (prop);
|
|
870
|
|
871 args[0].name = (char *) XSTRING_DATA (prop_name);
|
|
872
|
|
873 err = gtk_object_arg_get_info (GTK_OBJECT_TYPE (XGTK_OBJECT (obj)->object),
|
|
874 args[0].name,
|
|
875 &info);
|
|
876
|
|
877 if (err)
|
|
878 {
|
|
879 /* Not a magic symbol, fall back to just storing in our real plist */
|
|
880 g_free (err);
|
|
881
|
|
882 XGTK_OBJECT (obj)->plist = Fplist_put (XGTK_OBJECT (obj)->plist, prop, value);
|
|
883 return (1);
|
|
884 }
|
|
885
|
|
886 args[0].type = info->type;
|
|
887
|
|
888 if (lisp_to_gtk_type (value, &args[0]))
|
|
889 {
|
563
|
890 gui_error ("Error converting to GtkType", value);
|
462
|
891 }
|
|
892
|
|
893 if (!(info->arg_flags & GTK_ARG_WRITABLE))
|
|
894 {
|
563
|
895 invalid_operation ("Attempt to set read-only argument", prop);
|
462
|
896 }
|
|
897
|
|
898 gtk_object_setv (XGTK_OBJECT (obj)->object, 1, args);
|
|
899
|
|
900 return (1);
|
|
901 }
|
|
902
|
1204
|
903 static const struct memory_description gtk_object_data_description [] = {
|
|
904 { XD_LISP_OBJECT, offsetof (emacs_gtk_object_data, plist) },
|
934
|
905 { XD_END }
|
|
906 };
|
|
907
|
462
|
908 static Lisp_Object
|
|
909 mark_gtk_object_data (Lisp_Object obj)
|
|
910 {
|
|
911 return (XGTK_OBJECT (obj)->plist);
|
|
912 }
|
|
913
|
|
914 static void
|
|
915 emacs_gtk_object_finalizer (void *header, int for_disksave)
|
|
916 {
|
|
917 emacs_gtk_object_data *data = (emacs_gtk_object_data *) header;
|
|
918
|
|
919 if (for_disksave)
|
|
920 {
|
797
|
921 Lisp_Object obj = wrap_emacs_gtk_object (data);
|
793
|
922
|
462
|
923
|
563
|
924 invalid_operation
|
462
|
925 ("Can't dump an emacs containing GtkObject objects", obj);
|
|
926 }
|
|
927
|
|
928 if (data->alive_p)
|
|
929 {
|
|
930 gtk_object_unref (data->object);
|
|
931 }
|
|
932 }
|
|
933
|
934
|
934 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("GtkObject", emacs_gtk_object,
|
960
|
935 0, /*dumpable-flag*/
|
1204
|
936 mark_gtk_object_data,
|
|
937 emacs_gtk_object_printer,
|
|
938 emacs_gtk_object_finalizer,
|
934
|
939 0, /* equality */
|
|
940 0, /* hash */
|
1204
|
941 gtk_object_data_description,
|
|
942 object_getprop,
|
|
943 object_putprop,
|
934
|
944 0, /* rem prop */
|
|
945 0, /* plist */
|
|
946 emacs_gtk_object_data);
|
462
|
947
|
|
948 static emacs_gtk_object_data *
|
|
949 allocate_emacs_gtk_object_data (void)
|
|
950 {
|
2720
|
951 #ifdef MC_ALLOC
|
|
952 emacs_gtk_object_data *data = alloc_lrecord_type (emacs_gtk_object_data,
|
|
953 &lrecord_emacs_gtk_object);
|
|
954 #else /* not MC_ALLOC */
|
462
|
955 emacs_gtk_object_data *data = alloc_lcrecord_type (emacs_gtk_object_data,
|
|
956 &lrecord_emacs_gtk_object);
|
2720
|
957 #endif /* not MC_ALLOC */
|
462
|
958
|
|
959 data->object = NULL;
|
|
960 data->alive_p = FALSE;
|
|
961 data->plist = Qnil;
|
|
962
|
|
963 return (data);
|
|
964 }
|
|
965
|
|
966 /* We need to keep track of when the object is destroyed so that we
|
|
967 can mark it as dead, otherwise even our print routine (which calls
|
|
968 GTK_OBJECT_TYPE) will crap out and die. This is also used in the
|
|
969 lisp_to_gtk_type() routine to defend against passing dead objects
|
|
970 to GTK routines. */
|
|
971 static void
|
2286
|
972 __notice_object_destruction (GtkObject *UNUSED (obj), gpointer user_data)
|
462
|
973 {
|
|
974 ungcpro_popup_callbacks ((GUI_ID) user_data);
|
|
975 }
|
|
976
|
|
977 Lisp_Object build_gtk_object (GtkObject *obj)
|
|
978 {
|
|
979 Lisp_Object retval = Qnil;
|
|
980 emacs_gtk_object_data *data = NULL;
|
|
981 GUI_ID id = 0;
|
|
982
|
2168
|
983 id = (GUI_ID) gtk_object_get_data (obj, GTK_DATA_GUI_IDENTIFIER);
|
462
|
984
|
|
985 if (id)
|
|
986 {
|
|
987 retval = get_gcpro_popup_callbacks (id);
|
|
988 }
|
|
989
|
|
990 if (NILP (retval))
|
|
991 {
|
|
992 data = allocate_emacs_gtk_object_data ();
|
|
993
|
|
994 data->object = obj;
|
|
995 data->alive_p = TRUE;
|
797
|
996 retval = wrap_emacs_gtk_object (data);
|
462
|
997
|
|
998 id = new_gui_id ();
|
2168
|
999 gtk_object_set_data (obj, GTK_DATA_GUI_IDENTIFIER, (gpointer) id);
|
462
|
1000 gcpro_popup_callbacks (id, retval);
|
|
1001 gtk_object_ref (obj);
|
|
1002 gtk_signal_connect (obj, "destroy", GTK_SIGNAL_FUNC (__notice_object_destruction), (gpointer)id);
|
|
1003 }
|
|
1004
|
|
1005 return (retval);
|
|
1006 }
|
|
1007
|
|
1008 static void
|
|
1009 __internal_callback_destroy (gpointer data)
|
|
1010 {
|
|
1011 Lisp_Object lisp_data;
|
|
1012
|
826
|
1013 lisp_data = VOID_TO_LISP (data);
|
462
|
1014
|
|
1015 ungcpro_popup_callbacks (XINT (XCAR (lisp_data)));
|
|
1016 }
|
|
1017
|
|
1018 static void
|
|
1019 __internal_callback_marshal (GtkObject *obj, gpointer data, guint n_args, GtkArg *args)
|
|
1020 {
|
|
1021 Lisp_Object arg_list = Qnil;
|
|
1022 Lisp_Object callback_fn = Qnil;
|
|
1023 Lisp_Object callback_data = Qnil;
|
|
1024 Lisp_Object newargs[3];
|
|
1025 Lisp_Object rval = Qnil;
|
|
1026 struct gcpro gcpro1;
|
|
1027 int i;
|
|
1028
|
826
|
1029 callback_fn = VOID_TO_LISP (data);
|
462
|
1030
|
|
1031 /* Nuke the GUI_ID off the front */
|
|
1032 callback_fn = XCDR (callback_fn);
|
|
1033
|
|
1034 callback_data = XCAR (callback_fn);
|
|
1035 callback_fn = XCDR (callback_fn);
|
|
1036
|
|
1037 /* The callback data goes at the very end of the argument list */
|
|
1038 arg_list = Fcons (callback_data, Qnil);
|
|
1039
|
|
1040 /* Build up the argument list, lisp style */
|
|
1041 for (i = n_args - 1; i >= 0; i--)
|
|
1042 {
|
|
1043 arg_list = Fcons (gtk_type_to_lisp (&args[i]), arg_list);
|
|
1044 }
|
|
1045
|
|
1046 /* We always pass the widget as the first parameter at the very least */
|
|
1047 arg_list = Fcons (build_gtk_object (obj), arg_list);
|
|
1048
|
|
1049 GCPRO1 ((arg_list));
|
|
1050
|
|
1051 newargs[0] = callback_fn;
|
|
1052 newargs[1] = arg_list;
|
|
1053
|
|
1054 rval = Fapply (2, newargs);
|
|
1055 signal_fake_event ();
|
|
1056
|
|
1057 if (args[n_args].type != GTK_TYPE_NONE)
|
1883
|
1058 lisp_to_gtk_ret_type (rval, &args[n_args]);
|
462
|
1059
|
|
1060 UNGCPRO;
|
|
1061 }
|
|
1062
|
|
1063 DEFUN ("gtk-signal-connect", Fgtk_signal_connect, 3, 6, 0, /*
|
|
1064 */
|
|
1065 (obj, name, func, cb_data, object_signal, after_p))
|
|
1066 {
|
|
1067 int c_after;
|
|
1068 int c_object_signal;
|
|
1069 GUI_ID id = 0;
|
|
1070
|
|
1071 CHECK_GTK_OBJECT (obj);
|
|
1072
|
|
1073 if (SYMBOLP (name))
|
|
1074 name = Fsymbol_name (name);
|
|
1075
|
|
1076 CHECK_STRING (name);
|
|
1077
|
|
1078 if (NILP (object_signal))
|
|
1079 c_object_signal = 0;
|
|
1080 else
|
|
1081 c_object_signal = 1;
|
|
1082
|
|
1083 if (NILP (after_p))
|
|
1084 c_after = 0;
|
|
1085 else
|
|
1086 c_after = 1;
|
|
1087
|
|
1088 id = new_gui_id ();
|
|
1089 func = Fcons (cb_data, func);
|
|
1090 func = Fcons (make_int (id), func);
|
|
1091
|
|
1092 gcpro_popup_callbacks (id, func);
|
|
1093
|
|
1094 gtk_signal_connect_full (XGTK_OBJECT (obj)->object, (char *) XSTRING_DATA (name),
|
|
1095 NULL, __internal_callback_marshal, LISP_TO_VOID (func),
|
|
1096 __internal_callback_destroy, c_object_signal, c_after);
|
|
1097 return (Qt);
|
|
1098 }
|
|
1099
|
|
1100
|
|
1101 /* GTK_TYPE_BOXED wrapper for Emacs lisp */
|
1204
|
1102 static const struct memory_description emacs_gtk_boxed_description [] = {
|
960
|
1103 { XD_END }
|
|
1104 };
|
|
1105
|
462
|
1106 static void
|
2286
|
1107 emacs_gtk_boxed_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1108 int UNUSED (escapeflag))
|
462
|
1109 {
|
|
1110 if (print_readably)
|
563
|
1111 printing_unreadable_object ("#<GtkBoxed %p>", XGTK_BOXED (obj)->object);
|
462
|
1112
|
826
|
1113 write_c_string (printcharfun, "#<GtkBoxed (");
|
|
1114 write_c_string (printcharfun, gtk_type_name (XGTK_BOXED (obj)->object_type));
|
800
|
1115 write_fmt_string (printcharfun, ") %p>", (void *) XGTK_BOXED (obj)->object);
|
462
|
1116 }
|
|
1117
|
|
1118 static int
|
2286
|
1119 emacs_gtk_boxed_equality (Lisp_Object o1, Lisp_Object o2, int UNUSED (depth))
|
462
|
1120 {
|
|
1121 emacs_gtk_boxed_data *data1 = XGTK_BOXED(o1);
|
|
1122 emacs_gtk_boxed_data *data2 = XGTK_BOXED(o2);
|
|
1123
|
|
1124 return ((data1->object == data2->object) &&
|
|
1125 (data1->object_type == data2->object_type));
|
|
1126 }
|
|
1127
|
2515
|
1128 static Hashcode
|
2286
|
1129 emacs_gtk_boxed_hash (Lisp_Object obj, int UNUSED (depth))
|
462
|
1130 {
|
|
1131 emacs_gtk_boxed_data *data = XGTK_BOXED(obj);
|
2515
|
1132 return (HASH2 ((Hashcode) data->object, data->object_type));
|
462
|
1133 }
|
|
1134
|
960
|
1135 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("GtkBoxed", emacs_gtk_boxed,
|
|
1136 0, /*dumpable-flag*/
|
|
1137 0, /* marker function */
|
1204
|
1138 emacs_gtk_boxed_printer,
|
960
|
1139 0, /* nuker */
|
1204
|
1140 emacs_gtk_boxed_equality,
|
|
1141 emacs_gtk_boxed_hash,
|
|
1142 emacs_gtk_boxed_description,
|
960
|
1143 0, /* get prop */
|
|
1144 0, /* put prop */
|
|
1145 0, /* rem prop */
|
|
1146 0, /* plist */
|
|
1147 emacs_gtk_boxed_data);
|
462
|
1148 /* Currently defined GTK_TYPE_BOXED structures are:
|
|
1149
|
|
1150 GtkAccelGroup -
|
|
1151 GtkSelectionData -
|
|
1152 GtkStyle -
|
|
1153 GtkCTreeNode -
|
|
1154 GdkColormap -
|
|
1155 GdkVisual -
|
|
1156 GdkFont -
|
|
1157 GdkWindow -
|
|
1158 GdkDragContext -
|
|
1159 GdkEvent -
|
|
1160 GdkColor -
|
|
1161 */
|
|
1162 static emacs_gtk_boxed_data *
|
|
1163 allocate_emacs_gtk_boxed_data (void)
|
|
1164 {
|
2720
|
1165 #ifdef MC_ALLOC
|
|
1166 emacs_gtk_boxed_data *data = alloc_lrecord_type (emacs_gtk_boxed_data,
|
|
1167 &lrecord_emacs_gtk_boxed);
|
|
1168 #else /* not MC_ALLOC */
|
462
|
1169 emacs_gtk_boxed_data *data = alloc_lcrecord_type (emacs_gtk_boxed_data,
|
|
1170 &lrecord_emacs_gtk_boxed);
|
2720
|
1171 #endif /* not MC_ALLOC */
|
462
|
1172
|
|
1173 data->object = NULL;
|
|
1174 data->object_type = GTK_TYPE_INVALID;
|
|
1175
|
|
1176 return (data);
|
|
1177 }
|
|
1178
|
|
1179 Lisp_Object build_gtk_boxed (void *obj, GtkType t)
|
|
1180 {
|
|
1181 Lisp_Object retval = Qnil;
|
|
1182 emacs_gtk_boxed_data *data = NULL;
|
|
1183
|
|
1184 if (GTK_FUNDAMENTAL_TYPE (t) != GTK_TYPE_BOXED)
|
2500
|
1185 ABORT();
|
462
|
1186
|
|
1187 data = allocate_emacs_gtk_boxed_data ();
|
|
1188 data->object = obj;
|
|
1189 data->object_type = t;
|
|
1190
|
797
|
1191 retval = wrap_emacs_gtk_boxed (data);
|
462
|
1192
|
|
1193 return (retval);
|
|
1194 }
|
|
1195
|
|
1196
|
|
1197 /* The automatically generated structure access routines */
|
|
1198 #include "emacs-widget-accessors.c"
|
|
1199
|
|
1200 /* The hand generated funky functions that we can't just import using the FFI */
|
|
1201 #include "ui-byhand.c"
|
|
1202
|
|
1203 /* The glade support */
|
|
1204 #include "glade.c"
|
|
1205
|
|
1206
|
|
1207 /* Type manipulation */
|
|
1208 DEFUN ("gtk-fundamental-type", Fgtk_fundamental_type, 1, 1, 0, /*
|
|
1209 Load a shared library DLL into XEmacs. No initialization routines are required.
|
|
1210 This is for loading dependency DLLs into XEmacs.
|
|
1211 */
|
|
1212 (type))
|
|
1213 {
|
|
1214 GtkType t;
|
|
1215
|
|
1216 if (SYMBOLP (type))
|
|
1217 type = Fsymbol_name (type);
|
|
1218
|
|
1219 CHECK_STRING (type);
|
|
1220
|
|
1221 t = gtk_type_from_name ((char *) XSTRING_DATA (type));
|
|
1222
|
|
1223 if (t == GTK_TYPE_INVALID)
|
|
1224 {
|
563
|
1225 invalid_argument ("Not a GTK type", type);
|
462
|
1226 }
|
|
1227 return (make_int (GTK_FUNDAMENTAL_TYPE (t)));
|
|
1228 }
|
|
1229
|
|
1230 DEFUN ("gtk-object-type", Fgtk_object_type, 1, 1, 0, /*
|
|
1231 Return the GtkType of OBJECT.
|
|
1232 */
|
|
1233 (object))
|
|
1234 {
|
|
1235 CHECK_GTK_OBJECT (object);
|
|
1236 return (make_int (GTK_OBJECT_TYPE (XGTK_OBJECT (object)->object)));
|
|
1237 }
|
|
1238
|
|
1239 DEFUN ("gtk-describe-type", Fgtk_describe_type, 1, 1, 0, /*
|
|
1240 Returns a cons of two lists describing the Gtk object TYPE.
|
|
1241 The car is a list of all the signals that it will emit.
|
|
1242 The cdr is a list of all the magic properties it has.
|
|
1243 */
|
|
1244 (type))
|
|
1245 {
|
|
1246 Lisp_Object rval, signals, props;
|
|
1247 GtkType t;
|
|
1248
|
|
1249 props = signals = rval = Qnil;
|
|
1250
|
|
1251 if (SYMBOLP (type))
|
|
1252 {
|
|
1253 type = Fsymbol_name (type);
|
|
1254 }
|
|
1255
|
|
1256 if (STRINGP (type))
|
|
1257 {
|
2054
|
1258 t = gtk_type_from_name ((gchar*) XSTRING_DATA (type));
|
462
|
1259 if (t == GTK_TYPE_INVALID)
|
|
1260 {
|
563
|
1261 invalid_argument ("Not a GTK type", type);
|
462
|
1262 }
|
|
1263 }
|
|
1264 else
|
|
1265 {
|
|
1266 CHECK_INT (type);
|
|
1267 t = XINT (type);
|
|
1268 }
|
|
1269
|
|
1270 if (GTK_FUNDAMENTAL_TYPE (t) != GTK_TYPE_OBJECT)
|
|
1271 {
|
563
|
1272 invalid_argument ("Not a GtkObject", type);
|
462
|
1273 }
|
|
1274
|
|
1275 /* Need to do stupid shit like this to get the args
|
|
1276 ** registered... damn GTK and its lazy loading
|
|
1277 */
|
|
1278 {
|
|
1279 GtkArg args[3];
|
|
1280 GtkObject *obj = gtk_object_newv (t, 0, args);
|
|
1281
|
|
1282 gtk_object_destroy(obj);
|
|
1283 }
|
|
1284
|
|
1285 do
|
|
1286 {
|
|
1287 guint i;
|
|
1288
|
|
1289 /* Do the magic arguments first */
|
|
1290 {
|
|
1291 GtkArg *args;
|
|
1292 guint32 *flags;
|
|
1293 guint n_args;
|
|
1294
|
|
1295 args = gtk_object_query_args(t,&flags,&n_args);
|
|
1296
|
|
1297 for (i = 0; i < n_args; i++)
|
|
1298 {
|
|
1299 props = Fcons (Fcons (intern (gtk_type_name(args[i].type)),
|
|
1300 intern (args[i].name)), props);
|
|
1301 }
|
|
1302
|
|
1303 g_free (args);
|
|
1304 g_free (flags);
|
|
1305 }
|
|
1306
|
|
1307 /* Now the signals */
|
|
1308 {
|
|
1309 GtkObjectClass *klass;
|
|
1310 GtkSignalQuery *query;
|
|
1311 guint32 *gtk_signals;
|
|
1312 guint n_signals;
|
|
1313
|
|
1314 klass = (GtkObjectClass *) gtk_type_class (t);
|
|
1315 gtk_signals = klass->signals;
|
|
1316 n_signals = klass->nsignals;
|
|
1317
|
|
1318 for (i = 0; i < n_signals; i++)
|
|
1319 {
|
|
1320 Lisp_Object params = Qnil;
|
|
1321
|
|
1322 query = gtk_signal_query (gtk_signals[i]);
|
|
1323
|
|
1324 if (query)
|
|
1325 {
|
|
1326 if (query->nparams)
|
|
1327 {
|
|
1328 int j;
|
|
1329
|
|
1330 for (j = query->nparams - 1; j >= 0; j--)
|
|
1331 {
|
|
1332 params = Fcons (intern (gtk_type_name (query->params[j])), params);
|
|
1333 }
|
|
1334 }
|
|
1335
|
|
1336 signals = Fcons (Fcons (intern (gtk_type_name (query->return_val)),
|
|
1337 Fcons (intern (query->signal_name),
|
|
1338 params)),
|
|
1339 signals);
|
|
1340
|
|
1341 g_free (query);
|
|
1342 }
|
|
1343 }
|
|
1344 }
|
|
1345 t = gtk_type_parent(t);
|
|
1346 } while (t != GTK_TYPE_INVALID);
|
|
1347
|
|
1348 rval = Fcons (signals, props);
|
|
1349
|
|
1350 return (rval);
|
|
1351 }
|
|
1352
|
|
1353
|
|
1354 void
|
|
1355 syms_of_ui_gtk (void)
|
|
1356 {
|
|
1357 INIT_LRECORD_IMPLEMENTATION (emacs_ffi);
|
|
1358 INIT_LRECORD_IMPLEMENTATION (emacs_gtk_object);
|
|
1359 INIT_LRECORD_IMPLEMENTATION (emacs_gtk_boxed);
|
563
|
1360 DEFSYMBOL_MULTIWORD_PREDICATE (Qemacs_ffip);
|
|
1361 DEFSYMBOL_MULTIWORD_PREDICATE (Qemacs_gtk_objectp);
|
|
1362 DEFSYMBOL_MULTIWORD_PREDICATE (Qemacs_gtk_boxedp);
|
|
1363 DEFSYMBOL (Qvoid);
|
462
|
1364 DEFSUBR (Fdll_load);
|
|
1365 DEFSUBR (Fgtk_import_function_internal);
|
|
1366 DEFSUBR (Fgtk_import_variable_internal);
|
|
1367 DEFSUBR (Fgtk_signal_connect);
|
|
1368 DEFSUBR (Fgtk_call_function);
|
|
1369 DEFSUBR (Fgtk_fundamental_type);
|
|
1370 DEFSUBR (Fgtk_object_type);
|
|
1371 DEFSUBR (Fgtk_describe_type);
|
|
1372 syms_of_widget_accessors ();
|
|
1373 syms_of_ui_byhand ();
|
|
1374 syms_of_glade ();
|
|
1375 }
|
|
1376
|
|
1377 void
|
|
1378 vars_of_ui_gtk (void)
|
|
1379 {
|
|
1380 Fprovide (intern ("gtk-ui"));
|
|
1381 DEFVAR_LISP ("gtk-enumeration-info", &Venumeration_info /*
|
|
1382 A hashtable holding type information about GTK enumerations and flags.
|
|
1383 Do NOT modify unless you really understand ui-gtk.c.
|
|
1384 */);
|
|
1385
|
|
1386 Venumeration_info = Qnil;
|
|
1387 vars_of_glade ();
|
|
1388 }
|
|
1389
|
|
1390
|
|
1391 /* Various utility functions */
|
778
|
1392 #if 0
|
462
|
1393 void describe_gtk_arg (GtkArg *arg)
|
|
1394 {
|
|
1395 GtkArg a = *arg;
|
|
1396
|
|
1397 switch (GTK_FUNDAMENTAL_TYPE (a.type))
|
|
1398 {
|
|
1399 /* flag types */
|
|
1400 case GTK_TYPE_CHAR:
|
|
1401 stderr_out ("char: %c\n", GTK_VALUE_CHAR (a));
|
|
1402 break;
|
|
1403 case GTK_TYPE_UCHAR:
|
|
1404 stderr_out ("uchar: %c\n", GTK_VALUE_CHAR (a));
|
|
1405 break;
|
|
1406 case GTK_TYPE_BOOL:
|
|
1407 stderr_out ("uchar: %s\n", GTK_VALUE_BOOL (a) ? "true" : "false");
|
|
1408 break;
|
|
1409 case GTK_TYPE_INT:
|
|
1410 stderr_out ("int: %d\n", GTK_VALUE_INT (a));
|
|
1411 break;
|
|
1412 case GTK_TYPE_UINT:
|
|
1413 stderr_out ("uint: %du\n", GTK_VALUE_UINT (a));
|
|
1414 break;
|
|
1415 case GTK_TYPE_LONG:
|
|
1416 stderr_out ("long: %ld\n", GTK_VALUE_LONG (a));
|
|
1417 break;
|
|
1418 case GTK_TYPE_ULONG:
|
|
1419 stderr_out ("ulong: %lu\n", GTK_VALUE_ULONG (a));
|
|
1420 break;
|
|
1421 case GTK_TYPE_FLOAT:
|
|
1422 stderr_out ("float: %g\n", GTK_VALUE_FLOAT (a));
|
|
1423 break;
|
|
1424 case GTK_TYPE_DOUBLE:
|
|
1425 stderr_out ("double: %f\n", GTK_VALUE_DOUBLE (a));
|
|
1426 break;
|
|
1427 case GTK_TYPE_STRING:
|
|
1428 stderr_out ("string: %s\n", GTK_VALUE_STRING (a));
|
|
1429 break;
|
|
1430 case GTK_TYPE_ENUM:
|
|
1431 case GTK_TYPE_FLAGS:
|
|
1432 stderr_out ("%s: ", (a.type == GTK_TYPE_ENUM) ? "enum" : "flag");
|
|
1433 {
|
|
1434 GtkEnumValue *vals = gtk_type_enum_get_values (a.type);
|
|
1435
|
|
1436 while (vals && vals->value_name && (vals->value != GTK_VALUE_ENUM(a))) vals++;
|
|
1437
|
|
1438 stderr_out ("%s\n", vals ? vals->value_name : "!!! UNKNOWN ENUM VALUE !!!");
|
|
1439 }
|
|
1440 break;
|
|
1441 case GTK_TYPE_BOXED:
|
|
1442 stderr_out ("boxed: %p\n", GTK_VALUE_BOXED (a));
|
|
1443 break;
|
|
1444 case GTK_TYPE_POINTER:
|
|
1445 stderr_out ("pointer: %p\n", GTK_VALUE_BOXED (a));
|
|
1446 break;
|
|
1447
|
|
1448 /* structured types */
|
|
1449 case GTK_TYPE_SIGNAL:
|
|
1450 case GTK_TYPE_ARGS: /* This we can do as a list of values */
|
2500
|
1451 ABORT();
|
462
|
1452 case GTK_TYPE_CALLBACK:
|
|
1453 stderr_out ("callback fn: ...\n");
|
|
1454 break;
|
|
1455 case GTK_TYPE_C_CALLBACK:
|
|
1456 case GTK_TYPE_FOREIGN:
|
2500
|
1457 ABORT();
|
462
|
1458
|
|
1459 /* base type of the object system */
|
|
1460 case GTK_TYPE_OBJECT:
|
|
1461 if (GTK_VALUE_OBJECT (a))
|
|
1462 stderr_out ("object: %s\n", gtk_type_name (GTK_OBJECT_TYPE (GTK_VALUE_OBJECT (a))));
|
|
1463 else
|
|
1464 stderr_out ("object: NULL\n");
|
|
1465 break;
|
|
1466
|
|
1467 default:
|
2500
|
1468 ABORT();
|
462
|
1469 }
|
|
1470 }
|
778
|
1471 #endif
|
462
|
1472
|
|
1473 Lisp_Object gtk_type_to_lisp (GtkArg *arg)
|
|
1474 {
|
|
1475 switch (GTK_FUNDAMENTAL_TYPE (arg->type))
|
|
1476 {
|
|
1477 case GTK_TYPE_NONE:
|
|
1478 return (Qnil);
|
|
1479 case GTK_TYPE_CHAR:
|
|
1480 return (make_char (GTK_VALUE_CHAR (*arg)));
|
|
1481 case GTK_TYPE_UCHAR:
|
|
1482 return (make_char (GTK_VALUE_UCHAR (*arg)));
|
|
1483 case GTK_TYPE_BOOL:
|
|
1484 return (GTK_VALUE_BOOL (*arg) ? Qt : Qnil);
|
|
1485 case GTK_TYPE_INT:
|
|
1486 return (make_int (GTK_VALUE_INT (*arg)));
|
|
1487 case GTK_TYPE_UINT:
|
|
1488 return (make_int (GTK_VALUE_INT (*arg)));
|
|
1489 case GTK_TYPE_LONG: /* I think these are wrong! */
|
|
1490 return (make_int (GTK_VALUE_INT (*arg)));
|
|
1491 case GTK_TYPE_ULONG: /* I think these are wrong! */
|
|
1492 return (make_int (GTK_VALUE_INT (*arg)));
|
|
1493 case GTK_TYPE_FLOAT:
|
|
1494 return (make_float (GTK_VALUE_FLOAT (*arg)));
|
|
1495 case GTK_TYPE_DOUBLE:
|
|
1496 return (make_float (GTK_VALUE_DOUBLE (*arg)));
|
|
1497 case GTK_TYPE_STRING:
|
|
1498 return (build_string (GTK_VALUE_STRING (*arg)));
|
|
1499 case GTK_TYPE_FLAGS:
|
|
1500 return (flags_to_list (GTK_VALUE_FLAGS (*arg), arg->type));
|
|
1501 case GTK_TYPE_ENUM:
|
|
1502 return (enum_to_symbol (GTK_VALUE_ENUM (*arg), arg->type));
|
|
1503 case GTK_TYPE_BOXED:
|
|
1504 if (arg->type == GTK_TYPE_GDK_EVENT)
|
|
1505 {
|
|
1506 return (gdk_event_to_emacs_event((GdkEvent *) GTK_VALUE_BOXED (*arg)));
|
|
1507 }
|
|
1508
|
|
1509 if (GTK_VALUE_BOXED (*arg))
|
|
1510 return (build_gtk_boxed (GTK_VALUE_BOXED (*arg), arg->type));
|
|
1511 else
|
|
1512 return (Qnil);
|
|
1513 case GTK_TYPE_POINTER:
|
|
1514 if (GTK_VALUE_POINTER (*arg))
|
|
1515 {
|
|
1516 Lisp_Object rval;
|
|
1517
|
826
|
1518 rval = VOID_TO_LISP (GTK_VALUE_POINTER (*arg));
|
462
|
1519 return (rval);
|
|
1520 }
|
|
1521 else
|
|
1522 return (Qnil);
|
|
1523 case GTK_TYPE_OBJECT:
|
|
1524 if (GTK_VALUE_OBJECT (*arg))
|
|
1525 return (build_gtk_object (GTK_VALUE_OBJECT (*arg)));
|
|
1526 else
|
|
1527 return (Qnil);
|
|
1528
|
|
1529 case GTK_TYPE_CALLBACK:
|
|
1530 {
|
|
1531 Lisp_Object rval;
|
|
1532
|
826
|
1533 rval = VOID_TO_LISP (GTK_VALUE_CALLBACK (*arg).data);
|
462
|
1534
|
|
1535 return (rval);
|
|
1536 }
|
|
1537
|
|
1538 default:
|
2054
|
1539 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(arg->type, GTK_TYPE_LISTOF))
|
462
|
1540 {
|
|
1541 if (!GTK_VALUE_POINTER (*arg))
|
|
1542 return (Qnil);
|
|
1543 else
|
|
1544 {
|
|
1545 return (xemacs_gtklist_to_list (arg));
|
|
1546 }
|
|
1547 }
|
|
1548 stderr_out ("Do not know how to convert `%s' to lisp!\n", gtk_type_name (arg->type));
|
2500
|
1549 ABORT ();
|
462
|
1550 }
|
|
1551 /* This is chuck reminding GCC to... SHUT UP! */
|
|
1552 return (Qnil);
|
|
1553 }
|
|
1554
|
|
1555 int lisp_to_gtk_type (Lisp_Object obj, GtkArg *arg)
|
|
1556 {
|
|
1557 switch (GTK_FUNDAMENTAL_TYPE (arg->type))
|
|
1558 {
|
|
1559 /* flag types */
|
|
1560 case GTK_TYPE_NONE:
|
|
1561 return (0);
|
|
1562 case GTK_TYPE_CHAR:
|
|
1563 {
|
867
|
1564 Ichar c;
|
462
|
1565
|
|
1566 CHECK_CHAR_COERCE_INT (obj);
|
|
1567 c = XCHAR (obj);
|
|
1568 GTK_VALUE_CHAR (*arg) = c;
|
|
1569 }
|
|
1570 break;
|
|
1571 case GTK_TYPE_UCHAR:
|
|
1572 {
|
867
|
1573 Ichar c;
|
462
|
1574
|
|
1575 CHECK_CHAR_COERCE_INT (obj);
|
|
1576 c = XCHAR (obj);
|
|
1577 GTK_VALUE_CHAR (*arg) = c;
|
|
1578 }
|
|
1579 break;
|
|
1580 case GTK_TYPE_BOOL:
|
|
1581 GTK_VALUE_BOOL (*arg) = NILP (obj) ? FALSE : TRUE;
|
|
1582 break;
|
|
1583 case GTK_TYPE_INT:
|
|
1584 case GTK_TYPE_UINT:
|
|
1585 if (NILP (obj) || EQ (Qt, obj))
|
|
1586 {
|
|
1587 /* For we are a kind mistress and allow sending t/nil for
|
|
1588 1/0 to stupid GTK functions that say they take guint or
|
|
1589 gint in the header files, but actually treat it like a
|
|
1590 bool. *sigh*
|
|
1591 */
|
|
1592 GTK_VALUE_INT(*arg) = NILP (obj) ? 0 : 1;
|
|
1593 }
|
|
1594 else
|
|
1595 {
|
|
1596 CHECK_INT (obj);
|
|
1597 GTK_VALUE_INT(*arg) = XINT (obj);
|
|
1598 }
|
|
1599 break;
|
|
1600 case GTK_TYPE_LONG:
|
|
1601 case GTK_TYPE_ULONG:
|
2500
|
1602 ABORT();
|
462
|
1603 case GTK_TYPE_FLOAT:
|
|
1604 CHECK_INT_OR_FLOAT (obj);
|
|
1605 GTK_VALUE_FLOAT(*arg) = extract_float (obj);
|
|
1606 break;
|
|
1607 case GTK_TYPE_DOUBLE:
|
|
1608 CHECK_INT_OR_FLOAT (obj);
|
|
1609 GTK_VALUE_DOUBLE(*arg) = extract_float (obj);
|
|
1610 break;
|
|
1611 case GTK_TYPE_STRING:
|
|
1612 if (NILP (obj))
|
|
1613 GTK_VALUE_STRING (*arg) = NULL;
|
|
1614 else
|
|
1615 {
|
|
1616 CHECK_STRING (obj);
|
|
1617 GTK_VALUE_STRING (*arg) = (char *) XSTRING_DATA (obj);
|
|
1618 }
|
|
1619 break;
|
|
1620 case GTK_TYPE_ENUM:
|
|
1621 case GTK_TYPE_FLAGS:
|
|
1622 /* Convert a lisp symbol to a GTK enum */
|
|
1623 GTK_VALUE_ENUM(*arg) = lisp_to_flag (obj, arg->type);
|
|
1624 break;
|
|
1625 case GTK_TYPE_BOXED:
|
|
1626 if (NILP (obj))
|
|
1627 {
|
|
1628 GTK_VALUE_BOXED(*arg) = NULL;
|
|
1629 }
|
|
1630 else if (GTK_BOXEDP (obj))
|
|
1631 {
|
|
1632 GTK_VALUE_BOXED(*arg) = XGTK_BOXED (obj)->object;
|
|
1633 }
|
|
1634 else if (arg->type == GTK_TYPE_STYLE)
|
|
1635 {
|
|
1636 obj = Ffind_face (obj);
|
|
1637 CHECK_FACE (obj);
|
|
1638 GTK_VALUE_BOXED(*arg) = face_to_style (obj);
|
|
1639 }
|
|
1640 else if (arg->type == GTK_TYPE_GDK_GC)
|
|
1641 {
|
|
1642 obj = Ffind_face (obj);
|
|
1643 CHECK_FACE (obj);
|
|
1644 GTK_VALUE_BOXED(*arg) = face_to_gc (obj);
|
|
1645 }
|
|
1646 else if (arg->type == GTK_TYPE_GDK_WINDOW)
|
|
1647 {
|
|
1648 if (GLYPHP (obj))
|
|
1649 {
|
|
1650 Lisp_Object window = Fselected_window (Qnil);
|
793
|
1651 Lisp_Object instance =
|
|
1652 glyph_image_instance (obj, window, ERROR_ME_DEBUG_WARN, 1);
|
462
|
1653 struct Lisp_Image_Instance *p = XIMAGE_INSTANCE (instance);
|
|
1654
|
|
1655 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
1656 {
|
|
1657 case IMAGE_TEXT:
|
|
1658 case IMAGE_POINTER:
|
|
1659 case IMAGE_SUBWINDOW:
|
|
1660 case IMAGE_NOTHING:
|
|
1661 GTK_VALUE_BOXED(*arg) = NULL;
|
|
1662 break;
|
|
1663
|
|
1664 case IMAGE_MONO_PIXMAP:
|
|
1665 case IMAGE_COLOR_PIXMAP:
|
|
1666 GTK_VALUE_BOXED(*arg) = IMAGE_INSTANCE_GTK_PIXMAP (p);
|
|
1667 break;
|
|
1668 }
|
|
1669 }
|
|
1670 else if (GTK_OBJECTP (obj) && GTK_IS_WIDGET (XGTK_OBJECT (obj)->object))
|
|
1671 {
|
|
1672 GTK_VALUE_BOXED(*arg) = GTK_WIDGET (XGTK_OBJECT (obj))->window;
|
|
1673 }
|
|
1674 else
|
|
1675 {
|
563
|
1676 invalid_argument ("Don't know how to convert object to GDK_WINDOW", obj);
|
462
|
1677 }
|
|
1678 break;
|
|
1679 }
|
|
1680 else if (arg->type == GTK_TYPE_GDK_COLOR)
|
|
1681 {
|
|
1682 if (COLOR_SPECIFIERP (obj))
|
|
1683 {
|
|
1684 /* If it is a specifier, we just convert it to an
|
|
1685 instance, and let the ifs below handle it.
|
|
1686 */
|
|
1687 obj = Fspecifier_instance (obj, Qnil, Qnil, Qnil);
|
|
1688 }
|
|
1689
|
|
1690 if (COLOR_INSTANCEP (obj))
|
|
1691 {
|
|
1692 /* Easiest one */
|
|
1693 GTK_VALUE_BOXED(*arg) = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (obj));
|
|
1694 }
|
|
1695 else if (STRINGP (obj))
|
|
1696 {
|
563
|
1697 invalid_argument ("Please use a color specifier or instance, not a string", obj);
|
462
|
1698 }
|
|
1699 else
|
|
1700 {
|
563
|
1701 invalid_argument ("Don't know how to convert to GdkColor", obj);
|
462
|
1702 }
|
|
1703 }
|
|
1704 else if (arg->type == GTK_TYPE_GDK_FONT)
|
|
1705 {
|
|
1706 if (SYMBOLP (obj))
|
|
1707 {
|
|
1708 /* If it is a symbol, we treat that as a face name */
|
|
1709 obj = Ffind_face (obj);
|
|
1710 }
|
|
1711
|
|
1712 if (FACEP (obj))
|
|
1713 {
|
|
1714 /* If it is a face, we just grab the font specifier, and
|
|
1715 cascade down until we finally reach a FONT_INSTANCE
|
|
1716 */
|
|
1717 obj = Fget (obj, Qfont, Qnil);
|
|
1718 }
|
|
1719
|
|
1720 if (FONT_SPECIFIERP (obj))
|
|
1721 {
|
|
1722 /* If it is a specifier, we just convert it to an
|
|
1723 instance, and let the ifs below handle it
|
|
1724 */
|
|
1725 obj = Fspecifier_instance (obj, Qnil, Qnil, Qnil);
|
|
1726 }
|
|
1727
|
|
1728 if (FONT_INSTANCEP (obj))
|
|
1729 {
|
|
1730 /* Easiest one */
|
|
1731 GTK_VALUE_BOXED(*arg) = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (obj));
|
|
1732 }
|
|
1733 else if (STRINGP (obj))
|
|
1734 {
|
563
|
1735 invalid_argument ("Please use a font specifier or instance, not a string", obj);
|
462
|
1736 }
|
|
1737 else
|
|
1738 {
|
563
|
1739 invalid_argument ("Don't know how to convert to GdkColor", obj);
|
462
|
1740 }
|
|
1741 }
|
|
1742 else
|
|
1743 {
|
|
1744 /* Unknown type to convert to boxed */
|
|
1745 stderr_out ("Don't know how to convert to boxed!\n");
|
|
1746 GTK_VALUE_BOXED(*arg) = NULL;
|
|
1747 }
|
|
1748 break;
|
|
1749
|
|
1750 case GTK_TYPE_POINTER:
|
|
1751 if (NILP (obj))
|
|
1752 GTK_VALUE_POINTER(*arg) = NULL;
|
|
1753 else
|
|
1754 GTK_VALUE_POINTER(*arg) = LISP_TO_VOID (obj);
|
|
1755 break;
|
|
1756
|
|
1757 /* structured types */
|
|
1758 case GTK_TYPE_SIGNAL:
|
|
1759 case GTK_TYPE_ARGS: /* This we can do as a list of values */
|
|
1760 case GTK_TYPE_C_CALLBACK:
|
|
1761 case GTK_TYPE_FOREIGN:
|
|
1762 stderr_out ("Do not know how to convert `%s' from lisp!\n", gtk_type_name (arg->type));
|
|
1763 return (-1);
|
|
1764
|
|
1765 #if 0
|
|
1766 /* #### BILL! */
|
|
1767 /* This is not used, and does not work with union type */
|
|
1768 case GTK_TYPE_CALLBACK:
|
|
1769 {
|
|
1770 GUI_ID id;
|
|
1771
|
|
1772 id = new_gui_id ();
|
|
1773 obj = Fcons (Qnil, obj); /* Empty data */
|
|
1774 obj = Fcons (make_int (id), obj);
|
|
1775
|
|
1776 gcpro_popup_callbacks (id, obj);
|
|
1777
|
|
1778 GTK_VALUE_CALLBACK(*arg).marshal = __internal_callback_marshal;
|
|
1779 GTK_VALUE_CALLBACK(*arg).data = (gpointer) obj;
|
|
1780 GTK_VALUE_CALLBACK(*arg).notify = __internal_callback_destroy;
|
|
1781 }
|
|
1782 break;
|
|
1783 #endif
|
|
1784
|
|
1785 /* base type of the object system */
|
|
1786 case GTK_TYPE_OBJECT:
|
|
1787 if (NILP (obj))
|
|
1788 GTK_VALUE_OBJECT (*arg) = NULL;
|
|
1789 else
|
|
1790 {
|
|
1791 CHECK_GTK_OBJECT (obj);
|
|
1792 if (XGTK_OBJECT (obj)->alive_p)
|
|
1793 GTK_VALUE_OBJECT (*arg) = XGTK_OBJECT (obj)->object;
|
|
1794 else
|
563
|
1795 invalid_argument ("Attempting to pass dead object to GTK function", obj);
|
462
|
1796 }
|
|
1797 break;
|
|
1798
|
|
1799 default:
|
2054
|
1800 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(arg->type, GTK_TYPE_ARRAY))
|
462
|
1801 {
|
|
1802 if (NILP (obj))
|
|
1803 GTK_VALUE_POINTER(*arg) = NULL;
|
|
1804 else
|
|
1805 {
|
|
1806 xemacs_list_to_array (obj, arg);
|
|
1807 }
|
|
1808 }
|
2054
|
1809 else if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(arg->type, GTK_TYPE_LISTOF))
|
462
|
1810 {
|
|
1811 if (NILP (obj))
|
|
1812 GTK_VALUE_POINTER(*arg) = NULL;
|
|
1813 else
|
|
1814 {
|
|
1815 xemacs_list_to_gtklist (obj, arg);
|
|
1816 }
|
|
1817 }
|
|
1818 else
|
|
1819 {
|
|
1820 stderr_out ("Do not know how to convert `%s' from lisp!\n", gtk_type_name (arg->type));
|
2500
|
1821 ABORT();
|
462
|
1822 }
|
|
1823 break;
|
|
1824 }
|
|
1825
|
|
1826 return (0);
|
|
1827 }
|
|
1828
|
1883
|
1829 /* Convert lisp types to GTK return types. This is identical to
|
|
1830 lisp_to_gtk_type() except that the macro used to set the value is
|
|
1831 different.
|
|
1832
|
|
1833 ### There should be some way of combining these two functions.
|
|
1834 */
|
|
1835 int lisp_to_gtk_ret_type (Lisp_Object obj, GtkArg *arg)
|
|
1836 {
|
|
1837 switch (GTK_FUNDAMENTAL_TYPE (arg->type))
|
|
1838 {
|
|
1839 /* flag types */
|
|
1840 case GTK_TYPE_NONE:
|
|
1841 return (0);
|
|
1842 case GTK_TYPE_CHAR:
|
|
1843 {
|
|
1844 Ichar c;
|
|
1845
|
|
1846 CHECK_CHAR_COERCE_INT (obj);
|
|
1847 c = XCHAR (obj);
|
|
1848 *(GTK_RETLOC_CHAR (*arg)) = c;
|
|
1849 }
|
|
1850 break;
|
|
1851 case GTK_TYPE_UCHAR:
|
|
1852 {
|
|
1853 Ichar c;
|
|
1854
|
|
1855 CHECK_CHAR_COERCE_INT (obj);
|
|
1856 c = XCHAR (obj);
|
|
1857 *(GTK_RETLOC_CHAR (*arg)) = c;
|
|
1858 }
|
|
1859 break;
|
|
1860 case GTK_TYPE_BOOL:
|
|
1861 *(GTK_RETLOC_BOOL (*arg)) = NILP (obj) ? FALSE : TRUE;
|
|
1862 break;
|
|
1863 case GTK_TYPE_INT:
|
|
1864 case GTK_TYPE_UINT:
|
|
1865 if (NILP (obj) || EQ (Qt, obj))
|
|
1866 {
|
|
1867 /* For we are a kind mistress and allow sending t/nil for
|
|
1868 1/0 to stupid GTK functions that say they take guint or
|
|
1869 gint in the header files, but actually treat it like a
|
|
1870 bool. *sigh*
|
|
1871 */
|
|
1872 *(GTK_RETLOC_INT(*arg)) = NILP (obj) ? 0 : 1;
|
|
1873 }
|
|
1874 else
|
|
1875 {
|
|
1876 CHECK_INT (obj);
|
|
1877 *(GTK_RETLOC_INT(*arg)) = XINT (obj);
|
|
1878 }
|
|
1879 break;
|
|
1880 case GTK_TYPE_LONG:
|
|
1881 case GTK_TYPE_ULONG:
|
2500
|
1882 ABORT();
|
1883
|
1883 case GTK_TYPE_FLOAT:
|
|
1884 CHECK_INT_OR_FLOAT (obj);
|
|
1885 *(GTK_RETLOC_FLOAT(*arg)) = extract_float (obj);
|
|
1886 break;
|
|
1887 case GTK_TYPE_DOUBLE:
|
|
1888 CHECK_INT_OR_FLOAT (obj);
|
|
1889 *(GTK_RETLOC_DOUBLE(*arg)) = extract_float (obj);
|
|
1890 break;
|
|
1891 case GTK_TYPE_STRING:
|
|
1892 if (NILP (obj))
|
|
1893 *(GTK_RETLOC_STRING (*arg)) = NULL;
|
|
1894 else
|
|
1895 {
|
|
1896 CHECK_STRING (obj);
|
|
1897 *(GTK_RETLOC_STRING (*arg)) = (char *) XSTRING_DATA (obj);
|
|
1898 }
|
|
1899 break;
|
|
1900 case GTK_TYPE_ENUM:
|
|
1901 case GTK_TYPE_FLAGS:
|
|
1902 /* Convert a lisp symbol to a GTK enum */
|
|
1903 *(GTK_RETLOC_ENUM(*arg)) = lisp_to_flag (obj, arg->type);
|
|
1904 break;
|
|
1905 case GTK_TYPE_BOXED:
|
|
1906 if (NILP (obj))
|
|
1907 {
|
|
1908 *(GTK_RETLOC_BOXED(*arg)) = NULL;
|
|
1909 }
|
|
1910 else if (GTK_BOXEDP (obj))
|
|
1911 {
|
|
1912 *(GTK_RETLOC_BOXED(*arg)) = XGTK_BOXED (obj)->object;
|
|
1913 }
|
|
1914 else if (arg->type == GTK_TYPE_STYLE)
|
|
1915 {
|
|
1916 obj = Ffind_face (obj);
|
|
1917 CHECK_FACE (obj);
|
|
1918 *(GTK_RETLOC_BOXED(*arg)) = face_to_style (obj);
|
|
1919 }
|
|
1920 else if (arg->type == GTK_TYPE_GDK_GC)
|
|
1921 {
|
|
1922 obj = Ffind_face (obj);
|
|
1923 CHECK_FACE (obj);
|
|
1924 *(GTK_RETLOC_BOXED(*arg)) = face_to_gc (obj);
|
|
1925 }
|
|
1926 else if (arg->type == GTK_TYPE_GDK_WINDOW)
|
|
1927 {
|
|
1928 if (GLYPHP (obj))
|
|
1929 {
|
|
1930 Lisp_Object window = Fselected_window (Qnil);
|
|
1931 Lisp_Object instance =
|
|
1932 glyph_image_instance (obj, window, ERROR_ME_DEBUG_WARN, 1);
|
|
1933 struct Lisp_Image_Instance *p = XIMAGE_INSTANCE (instance);
|
|
1934
|
|
1935 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
1936 {
|
|
1937 case IMAGE_TEXT:
|
|
1938 case IMAGE_POINTER:
|
|
1939 case IMAGE_SUBWINDOW:
|
|
1940 case IMAGE_NOTHING:
|
|
1941 *(GTK_RETLOC_BOXED(*arg)) = NULL;
|
|
1942 break;
|
|
1943
|
|
1944 case IMAGE_MONO_PIXMAP:
|
|
1945 case IMAGE_COLOR_PIXMAP:
|
|
1946 *(GTK_RETLOC_BOXED(*arg)) = IMAGE_INSTANCE_GTK_PIXMAP (p);
|
|
1947 break;
|
|
1948 }
|
|
1949 }
|
|
1950 else if (GTK_OBJECTP (obj) && GTK_IS_WIDGET (XGTK_OBJECT (obj)->object))
|
|
1951 {
|
|
1952 *(GTK_RETLOC_BOXED(*arg)) = GTK_WIDGET (XGTK_OBJECT (obj))->window;
|
|
1953 }
|
|
1954 else
|
|
1955 {
|
|
1956 invalid_argument ("Don't know how to convert object to GDK_WINDOW", obj);
|
|
1957 }
|
|
1958 break;
|
|
1959 }
|
|
1960 else if (arg->type == GTK_TYPE_GDK_COLOR)
|
|
1961 {
|
|
1962 if (COLOR_SPECIFIERP (obj))
|
|
1963 {
|
|
1964 /* If it is a specifier, we just convert it to an
|
|
1965 instance, and let the ifs below handle it.
|
|
1966 */
|
|
1967 obj = Fspecifier_instance (obj, Qnil, Qnil, Qnil);
|
|
1968 }
|
|
1969
|
|
1970 if (COLOR_INSTANCEP (obj))
|
|
1971 {
|
|
1972 /* Easiest one */
|
|
1973 *(GTK_RETLOC_BOXED(*arg)) = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (obj));
|
|
1974 }
|
|
1975 else if (STRINGP (obj))
|
|
1976 {
|
|
1977 invalid_argument ("Please use a color specifier or instance, not a string", obj);
|
|
1978 }
|
|
1979 else
|
|
1980 {
|
|
1981 invalid_argument ("Don't know how to convert to GdkColor", obj);
|
|
1982 }
|
|
1983 }
|
|
1984 else if (arg->type == GTK_TYPE_GDK_FONT)
|
|
1985 {
|
|
1986 if (SYMBOLP (obj))
|
|
1987 {
|
|
1988 /* If it is a symbol, we treat that as a face name */
|
|
1989 obj = Ffind_face (obj);
|
|
1990 }
|
|
1991
|
|
1992 if (FACEP (obj))
|
|
1993 {
|
|
1994 /* If it is a face, we just grab the font specifier, and
|
|
1995 cascade down until we finally reach a FONT_INSTANCE
|
|
1996 */
|
|
1997 obj = Fget (obj, Qfont, Qnil);
|
|
1998 }
|
|
1999
|
|
2000 if (FONT_SPECIFIERP (obj))
|
|
2001 {
|
|
2002 /* If it is a specifier, we just convert it to an
|
|
2003 instance, and let the ifs below handle it
|
|
2004 */
|
|
2005 obj = Fspecifier_instance (obj, Qnil, Qnil, Qnil);
|
|
2006 }
|
|
2007
|
|
2008 if (FONT_INSTANCEP (obj))
|
|
2009 {
|
|
2010 /* Easiest one */
|
|
2011 *(GTK_RETLOC_BOXED(*arg)) = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (obj));
|
|
2012 }
|
|
2013 else if (STRINGP (obj))
|
|
2014 {
|
|
2015 invalid_argument ("Please use a font specifier or instance, not a string", obj);
|
|
2016 }
|
|
2017 else
|
|
2018 {
|
|
2019 invalid_argument ("Don't know how to convert to GdkColor", obj);
|
|
2020 }
|
|
2021 }
|
|
2022 else
|
|
2023 {
|
|
2024 /* Unknown type to convert to boxed */
|
|
2025 stderr_out ("Don't know how to convert to boxed!\n");
|
|
2026 *(GTK_RETLOC_BOXED(*arg)) = NULL;
|
|
2027 }
|
|
2028 break;
|
|
2029
|
|
2030 case GTK_TYPE_POINTER:
|
|
2031 if (NILP (obj))
|
|
2032 *(GTK_RETLOC_POINTER(*arg)) = NULL;
|
|
2033 else
|
|
2034 *(GTK_RETLOC_POINTER(*arg)) = LISP_TO_VOID (obj);
|
|
2035 break;
|
|
2036
|
|
2037 /* structured types */
|
|
2038 case GTK_TYPE_SIGNAL:
|
|
2039 case GTK_TYPE_ARGS: /* This we can do as a list of values */
|
|
2040 case GTK_TYPE_C_CALLBACK:
|
|
2041 case GTK_TYPE_FOREIGN:
|
|
2042 stderr_out ("Do not know how to convert `%s' from lisp!\n", gtk_type_name (arg->type));
|
|
2043 return (-1);
|
|
2044
|
|
2045 #if 0
|
|
2046 /* #### BILL! */
|
|
2047 /* This is not used, and does not work with union type */
|
|
2048 case GTK_TYPE_CALLBACK:
|
|
2049 {
|
|
2050 GUI_ID id;
|
|
2051
|
|
2052 id = new_gui_id ();
|
|
2053 obj = Fcons (Qnil, obj); /* Empty data */
|
|
2054 obj = Fcons (make_int (id), obj);
|
|
2055
|
|
2056 gcpro_popup_callbacks (id, obj);
|
|
2057
|
|
2058 *(GTK_RETLOC_CALLBACK(*arg)).marshal = __internal_callback_marshal;
|
|
2059 *(GTK_RETLOC_CALLBACK(*arg)).data = (gpointer) obj;
|
|
2060 *(GTK_RETLOC_CALLBACK(*arg)).notify = __internal_callback_destroy;
|
|
2061 }
|
|
2062 break;
|
|
2063 #endif
|
|
2064
|
|
2065 /* base type of the object system */
|
|
2066 case GTK_TYPE_OBJECT:
|
|
2067 if (NILP (obj))
|
|
2068 *(GTK_RETLOC_OBJECT (*arg)) = NULL;
|
|
2069 else
|
|
2070 {
|
|
2071 CHECK_GTK_OBJECT (obj);
|
|
2072 if (XGTK_OBJECT (obj)->alive_p)
|
|
2073 *(GTK_RETLOC_OBJECT (*arg)) = XGTK_OBJECT (obj)->object;
|
|
2074 else
|
|
2075 invalid_argument ("Attempting to pass dead object to GTK function", obj);
|
|
2076 }
|
|
2077 break;
|
|
2078
|
|
2079 default:
|
2054
|
2080 if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(arg->type, GTK_TYPE_ARRAY))
|
1883
|
2081 {
|
|
2082 if (NILP (obj))
|
|
2083 *(GTK_RETLOC_POINTER(*arg)) = NULL;
|
|
2084 else
|
|
2085 {
|
|
2086 xemacs_list_to_array (obj, arg);
|
|
2087 }
|
|
2088 }
|
2054
|
2089 else if (IS_XEMACS_GTK_FUNDAMENTAL_TYPE(arg->type, GTK_TYPE_LISTOF))
|
1883
|
2090 {
|
|
2091 if (NILP (obj))
|
|
2092 *(GTK_RETLOC_POINTER(*arg)) = NULL;
|
|
2093 else
|
|
2094 {
|
|
2095 xemacs_list_to_gtklist (obj, arg);
|
|
2096 }
|
|
2097 }
|
|
2098 else
|
|
2099 {
|
|
2100 stderr_out ("Do not know how to convert `%s' from lisp!\n", gtk_type_name (arg->type));
|
2500
|
2101 ABORT();
|
1883
|
2102 }
|
|
2103 break;
|
|
2104 }
|
|
2105
|
|
2106 return (0);
|
|
2107 }
|
|
2108
|
462
|
2109 /* This is used in glyphs-gtk.c as well */
|
|
2110 static Lisp_Object
|
|
2111 get_enumeration (GtkType t)
|
|
2112 {
|
|
2113 Lisp_Object alist;
|
|
2114
|
|
2115 if (NILP (Venumeration_info))
|
|
2116 {
|
|
2117 Venumeration_info = call2 (intern ("make-hashtable"), make_int (100), Qequal);
|
|
2118 }
|
|
2119
|
|
2120 alist = Fgethash (make_int (t), Venumeration_info, Qnil);
|
|
2121
|
|
2122 if (NILP (alist))
|
|
2123 {
|
|
2124 import_gtk_enumeration_internal (t);
|
|
2125 alist = Fgethash (make_int (t), Venumeration_info, Qnil);
|
|
2126 }
|
|
2127 return (alist);
|
|
2128 }
|
|
2129
|
|
2130 guint
|
|
2131 symbol_to_enum (Lisp_Object obj, GtkType t)
|
|
2132 {
|
|
2133 Lisp_Object alist = get_enumeration (t);
|
|
2134 Lisp_Object value = Qnil;
|
|
2135
|
|
2136 if (NILP (alist))
|
|
2137 {
|
563
|
2138 invalid_argument ("Unknown enumeration", build_string (gtk_type_name (t)));
|
462
|
2139 }
|
|
2140
|
|
2141 value = Fassq (obj, alist);
|
|
2142
|
|
2143 if (NILP (value))
|
|
2144 {
|
563
|
2145 invalid_argument ("Unknown value", obj);
|
462
|
2146 }
|
|
2147
|
|
2148 CHECK_INT (XCDR (value));
|
|
2149
|
|
2150 return (XINT (XCDR (value)));
|
|
2151 }
|
|
2152
|
|
2153 static guint
|
|
2154 lisp_to_flag (Lisp_Object obj, GtkType t)
|
|
2155 {
|
|
2156 guint val = 0;
|
|
2157
|
|
2158 if (NILP (obj))
|
|
2159 {
|
|
2160 /* Do nothing */
|
|
2161 }
|
|
2162 else if (SYMBOLP (obj))
|
|
2163 {
|
|
2164 val = symbol_to_enum (obj, t);
|
|
2165 }
|
|
2166 else if (LISTP (obj))
|
|
2167 {
|
|
2168 while (!NILP (obj))
|
|
2169 {
|
|
2170 val |= symbol_to_enum (XCAR (obj), t);
|
|
2171 obj = XCDR (obj);
|
|
2172 }
|
|
2173 }
|
|
2174 else
|
|
2175 {
|
2500
|
2176 /* ABORT ()? */
|
462
|
2177 }
|
|
2178 return (val);
|
|
2179 }
|
|
2180
|
|
2181 static Lisp_Object
|
|
2182 flags_to_list (guint value, GtkType t)
|
|
2183 {
|
|
2184 Lisp_Object rval = Qnil;
|
|
2185 Lisp_Object alist = get_enumeration (t);
|
|
2186
|
|
2187 while (!NILP (alist))
|
|
2188 {
|
|
2189 if (value & XINT (XCDR (XCAR (alist))))
|
|
2190 {
|
|
2191 rval = Fcons (XCAR (XCAR (alist)), rval);
|
|
2192 value &= ~(XINT (XCDR (XCAR (alist))));
|
|
2193 }
|
|
2194 alist = XCDR (alist);
|
|
2195 }
|
|
2196 return (rval);
|
|
2197 }
|
|
2198
|
|
2199 static Lisp_Object
|
|
2200 enum_to_symbol (guint value, GtkType t)
|
|
2201 {
|
|
2202 Lisp_Object alist = get_enumeration (t);
|
|
2203 Lisp_Object cell = Qnil;
|
|
2204
|
|
2205 if (NILP (alist))
|
|
2206 {
|
563
|
2207 invalid_argument ("Unknown enumeration", build_string (gtk_type_name (t)));
|
462
|
2208 }
|
|
2209
|
|
2210 cell = Frassq (make_int (value), alist);
|
|
2211
|
|
2212 return (NILP (cell) ? Qnil : XCAR (cell));
|
|
2213 }
|