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