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