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