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