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