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