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