0
|
1 /* Generic glyph/image implementation + display tables
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995 Tinker Systems
|
|
4 Copyright (C) 1995, 1996 Ben Wing
|
|
5 Copyright (C) 1995 Sun Microsystems
|
173
|
6
|
0
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Written by Ben Wing and Chuck Thompson */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "device.h"
|
|
33 #include "elhash.h"
|
|
34 #include "faces.h"
|
|
35 #include "frame.h"
|
276
|
36 #include "insdel.h"
|
0
|
37 #include "glyphs.h"
|
|
38 #include "objects.h"
|
|
39 #include "redisplay.h"
|
|
40 #include "window.h"
|
|
41
|
276
|
42 #ifdef HAVE_XPM
|
|
43 #include <X11/xpm.h>
|
|
44 #endif
|
|
45
|
269
|
46 Lisp_Object Qimage_conversion_error;
|
|
47
|
0
|
48 Lisp_Object Qglyphp, Qcontrib_p, Qbaseline;
|
|
49 Lisp_Object Qbuffer_glyph_p, Qpointer_glyph_p, Qicon_glyph_p;
|
|
50 Lisp_Object Qnothing_image_instance_p, Qtext_image_instance_p;
|
|
51 Lisp_Object Qmono_pixmap_image_instance_p;
|
|
52 Lisp_Object Qcolor_pixmap_image_instance_p;
|
|
53 Lisp_Object Qpointer_image_instance_p;
|
|
54 Lisp_Object Qsubwindow_image_instance_p;
|
|
55 Lisp_Object Qconst_glyph_variable;
|
|
56 Lisp_Object Qmono_pixmap, Qcolor_pixmap, Qsubwindow;
|
272
|
57 Lisp_Object Q_file, Q_data, Q_face;
|
|
58 Lisp_Object Qicon;
|
|
59 Lisp_Object Qformatted_string;
|
0
|
60
|
|
61 Lisp_Object Vcurrent_display_table;
|
|
62 Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
|
|
63 Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
|
|
64 Lisp_Object Vxemacs_logo;
|
|
65 Lisp_Object Vthe_nothing_vector;
|
272
|
66 Lisp_Object Vimage_instantiator_format_list;
|
|
67 Lisp_Object Vimage_instance_type_list;
|
|
68 Lisp_Object Vglyph_type_list;
|
|
69
|
0
|
70 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing);
|
|
71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit);
|
|
72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string);
|
|
73 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
|
|
74
|
278
|
75 Lisp_Object x_locate_pixmap_file (Lisp_Object name);
|
|
76 Lisp_Object mswindows_locate_pixmap_file (Lisp_Object name);
|
|
77
|
276
|
78 #ifdef HAVE_XPM
|
|
79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
|
|
80 Lisp_Object Qxpm;
|
|
81 Lisp_Object Q_color_symbols;
|
|
82 #endif
|
|
83
|
185
|
84 typedef struct image_instantiator_format_entry image_instantiator_format_entry;
|
0
|
85 struct image_instantiator_format_entry
|
|
86 {
|
|
87 Lisp_Object symbol;
|
|
88 struct image_instantiator_methods *meths;
|
|
89 };
|
|
90
|
185
|
91 typedef struct
|
0
|
92 {
|
|
93 Dynarr_declare (struct image_instantiator_format_entry);
|
|
94 } image_instantiator_format_entry_dynarr;
|
|
95
|
|
96 image_instantiator_format_entry_dynarr *
|
|
97 the_image_instantiator_format_entry_dynarr;
|
|
98
|
|
99 static Lisp_Object allocate_image_instance (Lisp_Object device);
|
|
100 static void image_validate (Lisp_Object instantiator);
|
|
101 static void glyph_property_was_changed (Lisp_Object glyph,
|
|
102 Lisp_Object property,
|
|
103 Lisp_Object locale);
|
272
|
104 EXFUN (Fimage_instance_type, 1);
|
|
105 EXFUN (Fglyph_type, 1);
|
0
|
106
|
|
107
|
|
108 /****************************************************************************
|
|
109 * Image Instantiators *
|
|
110 ****************************************************************************/
|
|
111
|
|
112 static struct image_instantiator_methods *
|
|
113 decode_image_instantiator_format (Lisp_Object format, Error_behavior errb)
|
|
114 {
|
|
115 int i;
|
|
116
|
|
117 if (!SYMBOLP (format))
|
|
118 {
|
|
119 if (ERRB_EQ (errb, ERROR_ME))
|
|
120 CHECK_SYMBOL (format);
|
|
121 return 0;
|
|
122 }
|
|
123
|
|
124 for (i = 0; i < Dynarr_length (the_image_instantiator_format_entry_dynarr);
|
|
125 i++)
|
|
126 {
|
|
127 if (EQ (format,
|
|
128 Dynarr_at (the_image_instantiator_format_entry_dynarr, i).
|
|
129 symbol))
|
|
130 return Dynarr_at (the_image_instantiator_format_entry_dynarr, i).meths;
|
|
131 }
|
|
132
|
|
133 maybe_signal_simple_error ("Invalid image-instantiator format", format,
|
|
134 Qimage, errb);
|
|
135
|
|
136 return 0;
|
|
137 }
|
|
138
|
|
139 static int
|
|
140 valid_image_instantiator_format_p (Lisp_Object format)
|
|
141 {
|
272
|
142 return (decode_image_instantiator_format (format, ERROR_ME_NOT) != 0);
|
0
|
143 }
|
|
144
|
284
|
145 DEFUN ("valid-image-instantiator-format-p", Fvalid_image_instantiator_format_p,
|
|
146 1, 1, 0, /*
|
0
|
147 Given an IMAGE-INSTANTIATOR-FORMAT, return non-nil if it is valid.
|
120
|
148 Valid formats are some subset of 'nothing, 'string, 'formatted-string,
|
|
149 'xpm, 'xbm, 'xface, 'gif, 'jpeg, 'png, 'tiff, 'cursor-font, 'font,
|
272
|
150 'autodetect, and 'subwindow, depending on how XEmacs was compiled.
|
20
|
151 */
|
|
152 (image_instantiator_format))
|
0
|
153 {
|
272
|
154 return valid_image_instantiator_format_p (image_instantiator_format) ?
|
|
155 Qt : Qnil;
|
0
|
156 }
|
|
157
|
284
|
158 DEFUN ("image-instantiator-format-list", Fimage_instantiator_format_list,
|
|
159 0, 0, 0, /*
|
0
|
160 Return a list of valid image-instantiator formats.
|
20
|
161 */
|
|
162 ())
|
0
|
163 {
|
|
164 return Fcopy_sequence (Vimage_instantiator_format_list);
|
|
165 }
|
|
166
|
|
167 void
|
|
168 add_entry_to_image_instantiator_format_list (Lisp_Object symbol,
|
|
169 struct
|
|
170 image_instantiator_methods *meths)
|
|
171 {
|
|
172 struct image_instantiator_format_entry entry;
|
|
173
|
|
174 entry.symbol = symbol;
|
|
175 entry.meths = meths;
|
|
176 Dynarr_add (the_image_instantiator_format_entry_dynarr, entry);
|
|
177 Vimage_instantiator_format_list =
|
|
178 Fcons (symbol, Vimage_instantiator_format_list);
|
|
179 }
|
|
180
|
|
181 static Lisp_Object *
|
|
182 get_image_conversion_list (Lisp_Object console_type)
|
|
183 {
|
|
184 return &decode_console_type (console_type, ERROR_ME)->image_conversion_list;
|
|
185 }
|
|
186
|
284
|
187 DEFUN ("set-console-type-image-conversion-list", Fset_console_type_image_conversion_list,
|
|
188 2, 2, 0, /*
|
0
|
189 Set the image-conversion-list for consoles of the given TYPE.
|
|
190 The image-conversion-list specifies how image instantiators that
|
|
191 are strings should be interpreted. Each element of the list should be
|
|
192 a list of two elements (a regular expression string and a vector) or
|
|
193 a list of three elements (the preceding two plus an integer index into
|
|
194 the vector). The string is converted to the vector associated with the
|
|
195 first matching regular expression. If a vector index is specified, the
|
|
196 string itself is substituted into that position in the vector.
|
|
197
|
|
198 Note: The conversion above is applied when the image instantiator is
|
|
199 added to an image specifier, not when the specifier is actually
|
|
200 instantiated. Therefore, changing the image-conversion-list only affects
|
|
201 newly-added instantiators. Existing instantiators in glyphs and image
|
|
202 specifiers will not be affected.
|
20
|
203 */
|
|
204 (console_type, list))
|
0
|
205 {
|
|
206 Lisp_Object tail;
|
|
207 Lisp_Object *imlist = get_image_conversion_list (console_type);
|
|
208
|
|
209 /* Check the list to make sure that it only has valid entries. */
|
|
210
|
|
211 EXTERNAL_LIST_LOOP (tail, list)
|
|
212 {
|
|
213 Lisp_Object mapping = XCAR (tail);
|
|
214
|
|
215 /* Mapping form should be (STRING VECTOR) or (STRING VECTOR INTEGER) */
|
|
216 if (!CONSP (mapping) ||
|
|
217 !CONSP (XCDR (mapping)) ||
|
|
218 (!NILP (XCDR (XCDR (mapping))) &&
|
|
219 (!CONSP (XCDR (XCDR (mapping))) ||
|
|
220 !NILP (XCDR (XCDR (XCDR (mapping)))))))
|
|
221 signal_simple_error ("Invalid mapping form", mapping);
|
|
222 else
|
|
223 {
|
|
224 Lisp_Object exp = XCAR (mapping);
|
|
225 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
226 Lisp_Object pos = Qnil;
|
|
227 Lisp_Object newvec;
|
|
228 struct gcpro gcpro1;
|
|
229
|
|
230 CHECK_STRING (exp);
|
|
231 CHECK_VECTOR (typevec);
|
|
232 if (!NILP (XCDR (XCDR (mapping))))
|
|
233 {
|
|
234 pos = XCAR (XCDR (XCDR (mapping)));
|
|
235 CHECK_INT (pos);
|
|
236 if (XINT (pos) < 0 ||
|
173
|
237 XINT (pos) >= XVECTOR_LENGTH (typevec))
|
0
|
238 args_out_of_range_3
|
173
|
239 (pos, Qzero, make_int (XVECTOR_LENGTH (typevec) - 1));
|
0
|
240 }
|
173
|
241
|
0
|
242 newvec = Fcopy_sequence (typevec);
|
|
243 if (INTP (pos))
|
173
|
244 XVECTOR_DATA (newvec)[XINT (pos)] = exp;
|
0
|
245 GCPRO1 (newvec);
|
|
246 image_validate (newvec);
|
|
247 UNGCPRO;
|
|
248 }
|
|
249 }
|
|
250
|
|
251 *imlist = Fcopy_tree (list, Qt);
|
|
252 return list;
|
|
253 }
|
|
254
|
284
|
255 DEFUN ("console-type-image-conversion-list", Fconsole_type_image_conversion_list,
|
|
256 1, 1, 0, /*
|
0
|
257 Return the image-conversion-list for devices of the given TYPE.
|
|
258 The image-conversion-list specifies how to interpret image string
|
|
259 instantiators for the specified console type. See
|
|
260 `set-console-type-image-conversion-list' for a description of its syntax.
|
20
|
261 */
|
|
262 (console_type))
|
0
|
263 {
|
|
264 return Fcopy_tree (*get_image_conversion_list (console_type), Qt);
|
|
265 }
|
|
266
|
185
|
267 /* Process a string instantiator according to the image-conversion-list for
|
0
|
268 CONSOLE_TYPE. Returns a vector. */
|
|
269
|
|
270 static Lisp_Object
|
|
271 process_image_string_instantiator (Lisp_Object data,
|
|
272 Lisp_Object console_type,
|
|
273 int dest_mask)
|
|
274 {
|
|
275 Lisp_Object tail;
|
|
276
|
|
277 LIST_LOOP (tail, *get_image_conversion_list (console_type))
|
|
278 {
|
|
279 Lisp_Object mapping = XCAR (tail);
|
|
280 Lisp_Object exp = XCAR (mapping);
|
|
281 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
282
|
|
283 /* if the result is of a type that can't be instantiated
|
|
284 (e.g. a string when we're dealing with a pointer glyph),
|
|
285 skip it. */
|
|
286 if (!(dest_mask &
|
|
287 IIFORMAT_METH (decode_image_instantiator_format
|
173
|
288 (XVECTOR_DATA (typevec)[0], ERROR_ME),
|
0
|
289 possible_dest_types, ())))
|
|
290 continue;
|
|
291 if (fast_string_match (exp, 0, data, 0, -1, 0, ERROR_ME, 0) >= 0)
|
|
292 {
|
|
293 if (!NILP (XCDR (XCDR (mapping))))
|
|
294 {
|
|
295 int pos = XINT (XCAR (XCDR (XCDR (mapping))));
|
|
296 Lisp_Object newvec = Fcopy_sequence (typevec);
|
173
|
297 XVECTOR_DATA (newvec)[pos] = data;
|
0
|
298 return newvec;
|
|
299 }
|
|
300 else
|
|
301 return typevec;
|
|
302 }
|
|
303 }
|
|
304
|
|
305 /* Oh well. */
|
|
306 signal_simple_error ("Unable to interpret glyph instantiator",
|
|
307 data);
|
173
|
308
|
0
|
309 return Qnil;
|
|
310 }
|
|
311
|
|
312 Lisp_Object
|
|
313 find_keyword_in_vector_or_given (Lisp_Object vector, Lisp_Object keyword,
|
173
|
314 Lisp_Object default_)
|
0
|
315 {
|
|
316 Lisp_Object *elt;
|
|
317 int instantiator_len;
|
|
318
|
173
|
319 elt = XVECTOR_DATA (vector);
|
|
320 instantiator_len = XVECTOR_LENGTH (vector);
|
0
|
321
|
|
322 elt++;
|
|
323 instantiator_len--;
|
|
324
|
|
325 while (instantiator_len > 0)
|
|
326 {
|
|
327 if (EQ (elt[0], keyword))
|
|
328 return elt[1];
|
|
329 elt += 2;
|
|
330 instantiator_len -= 2;
|
|
331 }
|
|
332
|
173
|
333 return default_;
|
0
|
334 }
|
|
335
|
|
336 Lisp_Object
|
|
337 find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword)
|
|
338 {
|
|
339 return find_keyword_in_vector_or_given (vector, keyword, Qnil);
|
|
340 }
|
|
341
|
|
342 void
|
|
343 check_valid_string (Lisp_Object data)
|
|
344 {
|
|
345 CHECK_STRING (data);
|
|
346 }
|
|
347
|
|
348 static void
|
|
349 check_valid_face (Lisp_Object data)
|
|
350 {
|
|
351 Fget_face (data);
|
|
352 }
|
|
353
|
|
354 void
|
|
355 check_valid_int (Lisp_Object data)
|
|
356 {
|
|
357 CHECK_INT (data);
|
|
358 }
|
|
359
|
|
360 void
|
|
361 file_or_data_must_be_present (Lisp_Object instantiator)
|
|
362 {
|
|
363 if (NILP (find_keyword_in_vector (instantiator, Q_file)) &&
|
|
364 NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
365 signal_simple_error ("Must supply either :file or :data",
|
|
366 instantiator);
|
|
367 }
|
|
368
|
|
369 void
|
|
370 data_must_be_present (Lisp_Object instantiator)
|
|
371 {
|
|
372 if (NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
373 signal_simple_error ("Must supply :data", instantiator);
|
|
374 }
|
|
375
|
|
376 static void
|
|
377 face_must_be_present (Lisp_Object instantiator)
|
|
378 {
|
|
379 if (NILP (find_keyword_in_vector (instantiator, Q_face)))
|
|
380 signal_simple_error ("Must supply :face", instantiator);
|
|
381 }
|
|
382
|
|
383 /* utility function useful in retrieving data from a file. */
|
|
384
|
|
385 Lisp_Object
|
|
386 make_string_from_file (Lisp_Object file)
|
|
387 {
|
116
|
388 /* This function can call lisp */
|
0
|
389 int count = specpdl_depth ();
|
|
390 Lisp_Object temp_buffer;
|
|
391 struct gcpro gcpro1;
|
|
392 Lisp_Object data;
|
173
|
393
|
0
|
394 specbind (Qinhibit_quit, Qt);
|
|
395 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
396 temp_buffer = Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
397 GCPRO1 (temp_buffer);
|
|
398 set_buffer_internal (XBUFFER (temp_buffer));
|
223
|
399 Ferase_buffer (Qnil);
|
169
|
400 specbind (intern ("format-alist"), Qnil);
|
70
|
401 Finsert_file_contents_internal (file, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
|
223
|
402 data = Fbuffer_substring (Qnil, Qnil, Qnil);
|
0
|
403 unbind_to (count, Qnil);
|
|
404 UNGCPRO;
|
|
405 return data;
|
|
406 }
|
|
407
|
|
408 /* The following two functions are provided to make it easier for
|
|
409 the normalize methods to work with keyword-value vectors.
|
|
410 Hash tables are kind of heavyweight for this purpose.
|
|
411 (If vectors were resizable, we could avoid this problem;
|
|
412 but they're not.) An alternative approach that might be
|
|
413 more efficient but require more work is to use a type of
|
|
414 assoc-Dynarr and provide primitives for deleting elements out
|
|
415 of it. (However, you'd also have to add an unwind-protect
|
|
416 to make sure the Dynarr got freed in case of an error in
|
|
417 the normalization process.) */
|
|
418
|
|
419 Lisp_Object
|
|
420 tagged_vector_to_alist (Lisp_Object vector)
|
|
421 {
|
173
|
422 Lisp_Object *elt = XVECTOR_DATA (vector);
|
|
423 int len = XVECTOR_LENGTH (vector);
|
0
|
424 Lisp_Object result = Qnil;
|
|
425
|
|
426 assert (len & 1);
|
|
427 for (len -= 2; len >= 1; len -= 2)
|
|
428 result = Fcons (Fcons (elt[len], elt[len+1]), result);
|
|
429
|
|
430 return result;
|
|
431 }
|
|
432
|
|
433 Lisp_Object
|
|
434 alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist)
|
|
435 {
|
|
436 int len = 1 + 2 * XINT (Flength (alist));
|
185
|
437 Lisp_Object *elt = alloca_array (Lisp_Object, len);
|
0
|
438 int i;
|
|
439 Lisp_Object rest;
|
|
440
|
|
441 i = 0;
|
|
442 elt[i++] = tag;
|
|
443 LIST_LOOP (rest, alist)
|
|
444 {
|
|
445 Lisp_Object pair = XCAR (rest);
|
|
446 elt[i] = XCAR (pair);
|
|
447 elt[i+1] = XCDR (pair);
|
|
448 i += 2;
|
|
449 }
|
|
450
|
|
451 return Fvector (len, elt);
|
|
452 }
|
|
453
|
|
454 static Lisp_Object
|
|
455 normalize_image_instantiator (Lisp_Object instantiator,
|
|
456 Lisp_Object contype,
|
|
457 Lisp_Object dest_mask)
|
|
458 {
|
|
459 if (IMAGE_INSTANCEP (instantiator))
|
|
460 return instantiator;
|
|
461
|
|
462 if (STRINGP (instantiator))
|
|
463 instantiator = process_image_string_instantiator (instantiator, contype,
|
|
464 XINT (dest_mask));
|
|
465
|
|
466 assert (VECTORP (instantiator));
|
|
467 /* We have to always store the actual pixmap data and not the
|
|
468 filename even though this is a potential memory pig. We have to
|
|
469 do this because it is quite possible that we will need to
|
|
470 instantiate a new instance of the pixmap and the file will no
|
|
471 longer exist (e.g. w3 pixmaps are almost always from temporary
|
|
472 files). */
|
272
|
473 {
|
|
474 struct image_instantiator_methods * meths =
|
|
475 decode_image_instantiator_format (XVECTOR_DATA (instantiator)[0],
|
|
476 ERROR_ME);
|
|
477 return IIFORMAT_METH_OR_GIVEN (meths, normalize,
|
|
478 (instantiator, contype),
|
|
479 instantiator);
|
|
480 }
|
0
|
481 }
|
|
482
|
|
483 static Lisp_Object
|
124
|
484 instantiate_image_instantiator (Lisp_Object device, Lisp_Object domain,
|
|
485 Lisp_Object instantiator,
|
0
|
486 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
487 int dest_mask)
|
|
488 {
|
272
|
489 Lisp_Object ii = allocate_image_instance (device);
|
|
490 struct image_instantiator_methods *meths;
|
0
|
491 struct gcpro gcpro1;
|
|
492
|
|
493 GCPRO1 (ii);
|
272
|
494 meths = decode_image_instantiator_format (XVECTOR_DATA (instantiator)[0],
|
|
495 ERROR_ME);
|
|
496 if (!HAS_IIFORMAT_METH_P (meths, instantiate))
|
|
497 signal_simple_error
|
|
498 ("Don't know how to instantiate this image instantiator?",
|
|
499 instantiator);
|
|
500 IIFORMAT_METH (meths, instantiate, (ii, instantiator, pointer_fg,
|
|
501 pointer_bg, dest_mask, domain));
|
0
|
502 UNGCPRO;
|
|
503
|
|
504 return ii;
|
|
505 }
|
|
506
|
|
507
|
|
508 /****************************************************************************
|
|
509 * Image-Instance Object *
|
|
510 ****************************************************************************/
|
|
511
|
|
512 Lisp_Object Qimage_instancep;
|
272
|
513
|
0
|
514 static Lisp_Object
|
|
515 mark_image_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
516 {
|
|
517 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
518
|
|
519 (markobj) (i->name);
|
|
520 switch (IMAGE_INSTANCE_TYPE (i))
|
|
521 {
|
|
522 case IMAGE_TEXT:
|
|
523 (markobj) (IMAGE_INSTANCE_TEXT_STRING (i));
|
|
524 break;
|
|
525 case IMAGE_MONO_PIXMAP:
|
|
526 case IMAGE_COLOR_PIXMAP:
|
|
527 (markobj) (IMAGE_INSTANCE_PIXMAP_FILENAME (i));
|
|
528 (markobj) (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i));
|
|
529 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i));
|
|
530 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i));
|
|
531 (markobj) (IMAGE_INSTANCE_PIXMAP_FG (i));
|
|
532 (markobj) (IMAGE_INSTANCE_PIXMAP_BG (i));
|
|
533 break;
|
|
534 case IMAGE_SUBWINDOW:
|
|
535 /* #### implement me */
|
|
536 break;
|
|
537 default:
|
|
538 break;
|
|
539 }
|
|
540
|
|
541 MAYBE_DEVMETH (XDEVICE (i->device), mark_image_instance, (i, markobj));
|
|
542
|
173
|
543 return i->device;
|
0
|
544 }
|
|
545
|
|
546 static void
|
|
547 print_image_instance (Lisp_Object obj, Lisp_Object printcharfun,
|
|
548 int escapeflag)
|
|
549 {
|
|
550 char buf[100];
|
|
551 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (obj);
|
|
552
|
|
553 if (print_readably)
|
|
554 error ("printing unreadable object #<image-instance 0x%x>",
|
|
555 ii->header.uid);
|
|
556 write_c_string ("#<image-instance (", printcharfun);
|
|
557 print_internal (Fimage_instance_type (obj), printcharfun, 0);
|
|
558 write_c_string (") ", printcharfun);
|
|
559 if (!NILP (ii->name))
|
|
560 {
|
|
561 print_internal (ii->name, printcharfun, 1);
|
|
562 write_c_string (" ", printcharfun);
|
|
563 }
|
|
564 write_c_string ("on ", printcharfun);
|
|
565 print_internal (ii->device, printcharfun, 0);
|
|
566 write_c_string (" ", printcharfun);
|
|
567 switch (IMAGE_INSTANCE_TYPE (ii))
|
|
568 {
|
|
569 case IMAGE_NOTHING:
|
|
570 break;
|
|
571
|
|
572 case IMAGE_TEXT:
|
|
573 print_internal (IMAGE_INSTANCE_TEXT_STRING (ii), printcharfun, 1);
|
|
574 break;
|
|
575
|
|
576 case IMAGE_MONO_PIXMAP:
|
|
577 case IMAGE_COLOR_PIXMAP:
|
|
578 case IMAGE_POINTER:
|
|
579 if (STRINGP (IMAGE_INSTANCE_PIXMAP_FILENAME (ii)))
|
|
580 {
|
|
581 char *s;
|
|
582 Lisp_Object filename = IMAGE_INSTANCE_PIXMAP_FILENAME (ii);
|
14
|
583 s = strrchr ((char *) XSTRING_DATA (filename), '/');
|
0
|
584 if (s)
|
|
585 print_internal (build_string (s + 1), printcharfun, 1);
|
|
586 else
|
|
587 print_internal (filename, printcharfun, 1);
|
|
588 }
|
|
589 if (IMAGE_INSTANCE_PIXMAP_DEPTH (ii) > 1)
|
|
590 sprintf (buf, " %dx%dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
591 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
592 IMAGE_INSTANCE_PIXMAP_DEPTH (ii));
|
|
593 else
|
|
594 sprintf (buf, " %dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
595 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii));
|
|
596 write_c_string (buf, printcharfun);
|
|
597 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ||
|
|
598 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
599 {
|
|
600 write_c_string (" @", printcharfun);
|
|
601 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
|
|
602 {
|
276
|
603 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
|
0
|
604 write_c_string (buf, printcharfun);
|
|
605 }
|
|
606 else
|
|
607 write_c_string ("??", printcharfun);
|
|
608 write_c_string (",", printcharfun);
|
|
609 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
610 {
|
276
|
611 long_to_string (buf, XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
|
0
|
612 write_c_string (buf, printcharfun);
|
|
613 }
|
|
614 else
|
|
615 write_c_string ("??", printcharfun);
|
|
616 }
|
|
617 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)) ||
|
|
618 !NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
619 {
|
|
620 write_c_string (" (", printcharfun);
|
|
621 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)))
|
|
622 {
|
|
623 print_internal
|
|
624 (XCOLOR_INSTANCE
|
|
625 (IMAGE_INSTANCE_PIXMAP_FG (ii))->name, printcharfun, 0);
|
|
626 }
|
|
627 write_c_string ("/", printcharfun);
|
|
628 if (!NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
629 {
|
|
630 print_internal
|
|
631 (XCOLOR_INSTANCE
|
|
632 (IMAGE_INSTANCE_PIXMAP_BG (ii))->name, printcharfun, 0);
|
|
633 }
|
|
634 write_c_string (")", printcharfun);
|
|
635 }
|
|
636 break;
|
|
637
|
|
638 case IMAGE_SUBWINDOW:
|
|
639 /* #### implement me */
|
|
640 break;
|
|
641
|
|
642 default:
|
|
643 abort ();
|
|
644 }
|
|
645
|
|
646 MAYBE_DEVMETH (XDEVICE (ii->device), print_image_instance,
|
|
647 (ii, printcharfun, escapeflag));
|
|
648 sprintf (buf, " 0x%x>", ii->header.uid);
|
|
649 write_c_string (buf, printcharfun);
|
|
650 }
|
|
651
|
|
652 static void
|
|
653 finalize_image_instance (void *header, int for_disksave)
|
|
654 {
|
|
655 struct Lisp_Image_Instance *i = (struct Lisp_Image_Instance *) header;
|
|
656
|
|
657 if (IMAGE_INSTANCE_TYPE (i) == IMAGE_NOTHING)
|
|
658 /* objects like this exist at dump time, so don't bomb out. */
|
|
659 return;
|
|
660 if (for_disksave) finalose (i);
|
|
661
|
|
662 MAYBE_DEVMETH (XDEVICE (i->device), finalize_image_instance, (i));
|
|
663 }
|
|
664
|
|
665 static int
|
|
666 image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
667 {
|
|
668 struct Lisp_Image_Instance *i1 = XIMAGE_INSTANCE (o1);
|
|
669 struct Lisp_Image_Instance *i2 = XIMAGE_INSTANCE (o2);
|
|
670 struct device *d1 = XDEVICE (i1->device);
|
|
671 struct device *d2 = XDEVICE (i2->device);
|
|
672
|
|
673 if (d1 != d2)
|
|
674 return 0;
|
|
675 if (IMAGE_INSTANCE_TYPE (i1) != IMAGE_INSTANCE_TYPE (i2))
|
|
676 return 0;
|
|
677 if (!internal_equal (IMAGE_INSTANCE_NAME (i1), IMAGE_INSTANCE_NAME (i2),
|
|
678 depth + 1))
|
|
679 return 0;
|
|
680
|
|
681 switch (IMAGE_INSTANCE_TYPE (i1))
|
|
682 {
|
|
683 case IMAGE_NOTHING:
|
|
684 break;
|
|
685
|
|
686 case IMAGE_TEXT:
|
|
687 if (!internal_equal (IMAGE_INSTANCE_TEXT_STRING (i1),
|
|
688 IMAGE_INSTANCE_TEXT_STRING (i2),
|
|
689 depth + 1))
|
|
690 return 0;
|
|
691 break;
|
|
692
|
|
693 case IMAGE_MONO_PIXMAP:
|
|
694 case IMAGE_COLOR_PIXMAP:
|
|
695 case IMAGE_POINTER:
|
|
696 if (!(IMAGE_INSTANCE_PIXMAP_WIDTH (i1) ==
|
|
697 IMAGE_INSTANCE_PIXMAP_WIDTH (i2) &&
|
|
698 IMAGE_INSTANCE_PIXMAP_HEIGHT (i1) ==
|
|
699 IMAGE_INSTANCE_PIXMAP_HEIGHT (i2) &&
|
|
700 IMAGE_INSTANCE_PIXMAP_DEPTH (i1) ==
|
|
701 IMAGE_INSTANCE_PIXMAP_DEPTH (i2) &&
|
|
702 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i1),
|
|
703 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i2)) &&
|
|
704 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i1),
|
|
705 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i2)) &&
|
|
706 internal_equal (IMAGE_INSTANCE_PIXMAP_FILENAME (i1),
|
|
707 IMAGE_INSTANCE_PIXMAP_FILENAME (i2),
|
|
708 depth + 1) &&
|
|
709 internal_equal (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i1),
|
|
710 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i2),
|
|
711 depth + 1)))
|
|
712 return 0;
|
|
713 break;
|
|
714
|
|
715 case IMAGE_SUBWINDOW:
|
|
716 /* #### implement me */
|
|
717 break;
|
|
718
|
|
719 default:
|
|
720 abort ();
|
|
721 }
|
|
722
|
|
723 return DEVMETH_OR_GIVEN (d1, image_instance_equal, (i1, i2, depth), 1);
|
|
724 }
|
|
725
|
|
726 static unsigned long
|
|
727 image_instance_hash (Lisp_Object obj, int depth)
|
|
728 {
|
|
729 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
730 struct device *d = XDEVICE (i->device);
|
|
731 unsigned long hash = (unsigned long) d;
|
|
732
|
|
733 switch (IMAGE_INSTANCE_TYPE (i))
|
|
734 {
|
|
735 case IMAGE_NOTHING:
|
|
736 break;
|
|
737
|
|
738 case IMAGE_TEXT:
|
|
739 hash = HASH2 (hash, internal_hash (IMAGE_INSTANCE_TEXT_STRING (i),
|
|
740 depth + 1));
|
|
741 break;
|
|
742
|
|
743 case IMAGE_MONO_PIXMAP:
|
|
744 case IMAGE_COLOR_PIXMAP:
|
|
745 case IMAGE_POINTER:
|
|
746 hash = HASH5 (hash, IMAGE_INSTANCE_PIXMAP_WIDTH (i),
|
|
747 IMAGE_INSTANCE_PIXMAP_HEIGHT (i),
|
|
748 IMAGE_INSTANCE_PIXMAP_DEPTH (i),
|
|
749 internal_hash (IMAGE_INSTANCE_PIXMAP_FILENAME (i),
|
|
750 depth + 1));
|
|
751 break;
|
|
752
|
|
753 case IMAGE_SUBWINDOW:
|
|
754 /* #### implement me */
|
|
755 break;
|
|
756
|
|
757 default:
|
|
758 abort ();
|
|
759 }
|
|
760
|
|
761 return HASH2 (hash, DEVMETH_OR_GIVEN (d, image_instance_hash, (i, depth),
|
|
762 0));
|
|
763 }
|
|
764
|
272
|
765 DEFINE_LRECORD_IMPLEMENTATION ("image-instance", image_instance,
|
|
766 mark_image_instance, print_image_instance,
|
|
767 finalize_image_instance, image_instance_equal,
|
|
768 image_instance_hash,
|
|
769 struct Lisp_Image_Instance);
|
|
770
|
0
|
771 static Lisp_Object
|
|
772 allocate_image_instance (Lisp_Object device)
|
|
773 {
|
|
774 struct Lisp_Image_Instance *lp =
|
185
|
775 alloc_lcrecord_type (struct Lisp_Image_Instance, lrecord_image_instance);
|
272
|
776 Lisp_Object val;
|
0
|
777
|
|
778 zero_lcrecord (lp);
|
|
779 lp->device = device;
|
|
780 lp->type = IMAGE_NOTHING;
|
|
781 lp->name = Qnil;
|
|
782 XSETIMAGE_INSTANCE (val, lp);
|
|
783 return val;
|
|
784 }
|
|
785
|
|
786 static enum image_instance_type
|
|
787 decode_image_instance_type (Lisp_Object type, Error_behavior errb)
|
|
788 {
|
|
789 if (ERRB_EQ (errb, ERROR_ME))
|
|
790 CHECK_SYMBOL (type);
|
|
791
|
185
|
792 if (EQ (type, Qnothing)) return IMAGE_NOTHING;
|
|
793 if (EQ (type, Qtext)) return IMAGE_TEXT;
|
|
794 if (EQ (type, Qmono_pixmap)) return IMAGE_MONO_PIXMAP;
|
|
795 if (EQ (type, Qcolor_pixmap)) return IMAGE_COLOR_PIXMAP;
|
|
796 if (EQ (type, Qpointer)) return IMAGE_POINTER;
|
|
797 if (EQ (type, Qsubwindow)) return IMAGE_SUBWINDOW;
|
0
|
798
|
|
799 maybe_signal_simple_error ("Invalid image-instance type", type,
|
|
800 Qimage, errb);
|
185
|
801
|
|
802 return IMAGE_UNKNOWN; /* not reached */
|
0
|
803 }
|
|
804
|
|
805 static Lisp_Object
|
|
806 encode_image_instance_type (enum image_instance_type type)
|
|
807 {
|
|
808 switch (type)
|
|
809 {
|
185
|
810 case IMAGE_NOTHING: return Qnothing;
|
|
811 case IMAGE_TEXT: return Qtext;
|
|
812 case IMAGE_MONO_PIXMAP: return Qmono_pixmap;
|
|
813 case IMAGE_COLOR_PIXMAP: return Qcolor_pixmap;
|
|
814 case IMAGE_POINTER: return Qpointer;
|
|
815 case IMAGE_SUBWINDOW: return Qsubwindow;
|
0
|
816 default:
|
|
817 abort ();
|
|
818 }
|
|
819
|
|
820 return Qnil; /* not reached */
|
|
821 }
|
|
822
|
|
823 static int
|
|
824 image_instance_type_to_mask (enum image_instance_type type)
|
|
825 {
|
|
826 /* This depends on the fact that enums are assigned consecutive
|
|
827 integers starting at 0. (Remember that IMAGE_UNKNOWN is the
|
|
828 first enum.) I'm fairly sure this behavior in ANSI-mandated,
|
|
829 so there should be no portability problems here. */
|
|
830 return (1 << ((int) (type) - 1));
|
|
831 }
|
|
832
|
|
833 static int
|
|
834 decode_image_instance_type_list (Lisp_Object list)
|
|
835 {
|
|
836 Lisp_Object rest;
|
|
837 int mask = 0;
|
|
838
|
|
839 if (NILP (list))
|
|
840 return ~0;
|
|
841
|
|
842 if (!CONSP (list))
|
|
843 {
|
|
844 enum image_instance_type type =
|
|
845 decode_image_instance_type (list, ERROR_ME);
|
|
846 return image_instance_type_to_mask (type);
|
|
847 }
|
|
848
|
|
849 EXTERNAL_LIST_LOOP (rest, list)
|
|
850 {
|
|
851 enum image_instance_type type =
|
|
852 decode_image_instance_type (XCAR (rest), ERROR_ME);
|
|
853 mask |= image_instance_type_to_mask (type);
|
|
854 }
|
|
855
|
|
856 return mask;
|
|
857 }
|
|
858
|
|
859 static Lisp_Object
|
|
860 encode_image_instance_type_list (int mask)
|
|
861 {
|
|
862 int count = 0;
|
|
863 Lisp_Object result = Qnil;
|
|
864
|
|
865 while (mask)
|
|
866 {
|
|
867 count++;
|
|
868 if (mask & 1)
|
|
869 result = Fcons (encode_image_instance_type
|
|
870 ((enum image_instance_type) count), result);
|
|
871 mask >>= 1;
|
|
872 }
|
|
873
|
|
874 return Fnreverse (result);
|
|
875 }
|
|
876
|
|
877 DOESNT_RETURN
|
|
878 incompatible_image_types (Lisp_Object instantiator, int given_dest_mask,
|
|
879 int desired_dest_mask)
|
|
880 {
|
|
881 signal_error
|
|
882 (Qerror,
|
|
883 list2
|
|
884 (emacs_doprnt_string_lisp_2
|
|
885 ((CONST Bufbyte *)
|
|
886 "No compatible image-instance types given: wanted one of %s, got %s",
|
|
887 Qnil, -1, 2,
|
|
888 encode_image_instance_type_list (desired_dest_mask),
|
|
889 encode_image_instance_type_list (given_dest_mask)),
|
|
890 instantiator));
|
|
891 }
|
|
892
|
|
893 static int
|
|
894 valid_image_instance_type_p (Lisp_Object type)
|
|
895 {
|
185
|
896 return !NILP (memq_no_quit (type, Vimage_instance_type_list));
|
0
|
897 }
|
|
898
|
20
|
899 DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p, 1, 1, 0, /*
|
0
|
900 Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid.
|
|
901 Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap,
|
|
902 'pointer, and 'subwindow, depending on how XEmacs was compiled.
|
20
|
903 */
|
|
904 (image_instance_type))
|
0
|
905 {
|
185
|
906 return valid_image_instance_type_p (image_instance_type) ? Qt : Qnil;
|
0
|
907 }
|
|
908
|
20
|
909 DEFUN ("image-instance-type-list", Fimage_instance_type_list, 0, 0, 0, /*
|
0
|
910 Return a list of valid image-instance types.
|
20
|
911 */
|
|
912 ())
|
0
|
913 {
|
|
914 return Fcopy_sequence (Vimage_instance_type_list);
|
|
915 }
|
|
916
|
|
917 Error_behavior
|
|
918 decode_error_behavior_flag (Lisp_Object no_error)
|
|
919 {
|
185
|
920 if (NILP (no_error)) return ERROR_ME;
|
|
921 else if (EQ (no_error, Qt)) return ERROR_ME_NOT;
|
|
922 else return ERROR_ME_WARN;
|
0
|
923 }
|
|
924
|
|
925 Lisp_Object
|
|
926 encode_error_behavior_flag (Error_behavior errb)
|
|
927 {
|
|
928 if (ERRB_EQ (errb, ERROR_ME))
|
|
929 return Qnil;
|
|
930 else if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
931 return Qt;
|
|
932 else
|
|
933 {
|
|
934 assert (ERRB_EQ (errb, ERROR_ME_WARN));
|
|
935 return Qwarning;
|
|
936 }
|
|
937 }
|
|
938
|
|
939 static Lisp_Object
|
|
940 make_image_instance_1 (Lisp_Object data, Lisp_Object device,
|
|
941 Lisp_Object dest_types)
|
|
942 {
|
|
943 Lisp_Object ii;
|
|
944 struct gcpro gcpro1;
|
|
945 int dest_mask;
|
|
946
|
|
947 XSETDEVICE (device, decode_device (device));
|
|
948 /* instantiate_image_instantiator() will abort if given an
|
|
949 image instance ... */
|
|
950 if (IMAGE_INSTANCEP (data))
|
|
951 signal_simple_error ("image instances not allowed here", data);
|
|
952 image_validate (data);
|
|
953 dest_mask = decode_image_instance_type_list (dest_types);
|
|
954 data = normalize_image_instantiator (data, DEVICE_TYPE (XDEVICE (device)),
|
|
955 make_int (dest_mask));
|
|
956 GCPRO1 (data);
|
173
|
957 if (VECTORP (data) && EQ (XVECTOR_DATA (data)[0], Qinherit))
|
0
|
958 signal_simple_error ("inheritance not allowed here", data);
|
124
|
959 ii = instantiate_image_instantiator (device, device, data,
|
|
960 Qnil, Qnil, dest_mask);
|
0
|
961 RETURN_UNGCPRO (ii);
|
|
962 }
|
|
963
|
20
|
964 DEFUN ("make-image-instance", Fmake_image_instance, 1, 4, 0, /*
|
272
|
965 Return a new `image-instance' object.
|
0
|
966
|
|
967 Image-instance objects encapsulate the way a particular image (pixmap,
|
|
968 etc.) is displayed on a particular device. In most circumstances, you
|
|
969 do not need to directly create image instances; use a glyph instead.
|
|
970 However, it may occasionally be useful to explicitly create image
|
|
971 instances, if you want more control over the instantiation process.
|
|
972
|
|
973 DATA is an image instantiator, which describes the image; see
|
|
974 `image-specifier-p' for a description of the allowed values.
|
|
975
|
|
976 DEST-TYPES should be a list of allowed image instance types that can
|
|
977 be generated. The recognized image instance types are
|
|
978
|
|
979 'nothing
|
|
980 Nothing is displayed.
|
|
981 'text
|
|
982 Displayed as text. The foreground and background colors and the
|
|
983 font of the text are specified independent of the pixmap. Typically
|
|
984 these attributes will come from the face of the surrounding text,
|
|
985 unless a face is specified for the glyph in which the image appears.
|
|
986 'mono-pixmap
|
|
987 Displayed as a mono pixmap (a pixmap with only two colors where the
|
|
988 foreground and background can be specified independent of the pixmap;
|
|
989 typically the pixmap assumes the foreground and background colors of
|
|
990 the text around it, unless a face is specified for the glyph in which
|
|
991 the image appears).
|
|
992 'color-pixmap
|
|
993 Displayed as a color pixmap.
|
|
994 'pointer
|
|
995 Used as the mouse pointer for a window.
|
|
996 'subwindow
|
|
997 A child window that is treated as an image. This allows (e.g.)
|
|
998 another program to be responsible for drawing into the window.
|
|
999 Not currently implemented.
|
|
1000
|
|
1001 The DEST-TYPES list is unordered. If multiple destination types
|
185
|
1002 are possible for a given instantiator, the "most natural" type
|
0
|
1003 for the instantiator's format is chosen. (For XBM, the most natural
|
|
1004 types are `mono-pixmap', followed by `color-pixmap', followed by
|
|
1005 `pointer'. For the other normal image formats, the most natural
|
|
1006 types are `color-pixmap', followed by `mono-pixmap', followed by
|
|
1007 `pointer'. For the string and formatted-string formats, the most
|
|
1008 natural types are `text', followed by `mono-pixmap' (not currently
|
|
1009 implemented), followed by `color-pixmap' (not currently implemented).
|
|
1010 The other formats can only be instantiated as one type. (If you
|
|
1011 want to control more specifically the order of the types into which
|
|
1012 an image is instantiated, just call `make-image-instance' repeatedly
|
|
1013 until it succeeds, passing less and less preferred destination types
|
|
1014 each time.
|
|
1015
|
|
1016 If DEST-TYPES is omitted, all possible types are allowed.
|
|
1017
|
|
1018 NO-ERROR controls what happens when the image cannot be generated.
|
|
1019 If nil, an error message is generated. If t, no messages are
|
|
1020 generated and this function returns nil. If anything else, a warning
|
|
1021 message is generated and this function returns nil.
|
20
|
1022 */
|
|
1023 (data, device, dest_types, no_error))
|
0
|
1024 {
|
|
1025 Error_behavior errb = decode_error_behavior_flag (no_error);
|
|
1026
|
74
|
1027 return call_with_suspended_errors ((lisp_fn_t) make_image_instance_1,
|
0
|
1028 Qnil, Qimage, errb,
|
|
1029 3, data, device, dest_types);
|
|
1030 }
|
|
1031
|
20
|
1032 DEFUN ("image-instance-p", Fimage_instance_p, 1, 1, 0, /*
|
0
|
1033 Return non-nil if OBJECT is an image instance.
|
20
|
1034 */
|
|
1035 (object))
|
0
|
1036 {
|
173
|
1037 return IMAGE_INSTANCEP (object) ? Qt : Qnil;
|
0
|
1038 }
|
|
1039
|
20
|
1040 DEFUN ("image-instance-type", Fimage_instance_type, 1, 1, 0, /*
|
0
|
1041 Return the type of the given image instance.
|
|
1042 The return value will be one of 'nothing, 'text, 'mono-pixmap,
|
|
1043 'color-pixmap, 'pointer, or 'subwindow.
|
20
|
1044 */
|
|
1045 (image_instance))
|
0
|
1046 {
|
|
1047 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1048 return encode_image_instance_type (XIMAGE_INSTANCE_TYPE (image_instance));
|
|
1049 }
|
|
1050
|
20
|
1051 DEFUN ("image-instance-name", Fimage_instance_name, 1, 1, 0, /*
|
0
|
1052 Return the name of the given image instance.
|
20
|
1053 */
|
|
1054 (image_instance))
|
0
|
1055 {
|
|
1056 CHECK_IMAGE_INSTANCE (image_instance);
|
173
|
1057 return XIMAGE_INSTANCE_NAME (image_instance);
|
0
|
1058 }
|
|
1059
|
20
|
1060 DEFUN ("image-instance-string", Fimage_instance_string, 1, 1, 0, /*
|
0
|
1061 Return the string of the given image instance.
|
|
1062 This will only be non-nil for text image instances.
|
20
|
1063 */
|
|
1064 (image_instance))
|
0
|
1065 {
|
|
1066 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1067 if (XIMAGE_INSTANCE_TYPE (image_instance) == IMAGE_TEXT)
|
173
|
1068 return XIMAGE_INSTANCE_TEXT_STRING (image_instance);
|
0
|
1069 else
|
|
1070 return Qnil;
|
|
1071 }
|
|
1072
|
20
|
1073 DEFUN ("image-instance-file-name", Fimage_instance_file_name, 1, 1, 0, /*
|
0
|
1074 Return the file name from which IMAGE-INSTANCE was read, if known.
|
20
|
1075 */
|
|
1076 (image_instance))
|
0
|
1077 {
|
|
1078 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1079
|
|
1080 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1081 {
|
|
1082 case IMAGE_MONO_PIXMAP:
|
|
1083 case IMAGE_COLOR_PIXMAP:
|
|
1084 case IMAGE_POINTER:
|
|
1085 return XIMAGE_INSTANCE_PIXMAP_FILENAME (image_instance);
|
|
1086
|
|
1087 default:
|
|
1088 return Qnil;
|
|
1089 }
|
|
1090 }
|
|
1091
|
20
|
1092 DEFUN ("image-instance-mask-file-name", Fimage_instance_mask_file_name, 1, 1, 0, /*
|
0
|
1093 Return the file name from which IMAGE-INSTANCE's mask was read, if known.
|
20
|
1094 */
|
|
1095 (image_instance))
|
0
|
1096 {
|
|
1097 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1098
|
|
1099 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1100 {
|
|
1101 case IMAGE_MONO_PIXMAP:
|
|
1102 case IMAGE_COLOR_PIXMAP:
|
|
1103 case IMAGE_POINTER:
|
|
1104 return XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME (image_instance);
|
|
1105
|
|
1106 default:
|
|
1107 return Qnil;
|
|
1108 }
|
|
1109 }
|
|
1110
|
20
|
1111 DEFUN ("image-instance-depth", Fimage_instance_depth, 1, 1, 0, /*
|
0
|
1112 Return the depth of the image instance.
|
|
1113 This is 0 for a bitmap, or a positive integer for a pixmap.
|
20
|
1114 */
|
|
1115 (image_instance))
|
0
|
1116 {
|
|
1117 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1118
|
|
1119 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1120 {
|
|
1121 case IMAGE_MONO_PIXMAP:
|
|
1122 case IMAGE_COLOR_PIXMAP:
|
|
1123 case IMAGE_POINTER:
|
173
|
1124 return make_int (XIMAGE_INSTANCE_PIXMAP_DEPTH (image_instance));
|
0
|
1125
|
|
1126 default:
|
|
1127 return Qnil;
|
|
1128 }
|
|
1129 }
|
|
1130
|
20
|
1131 DEFUN ("image-instance-height", Fimage_instance_height, 1, 1, 0, /*
|
0
|
1132 Return the height of the image instance, in pixels.
|
20
|
1133 */
|
|
1134 (image_instance))
|
0
|
1135 {
|
|
1136 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1137
|
|
1138 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1139 {
|
|
1140 case IMAGE_MONO_PIXMAP:
|
|
1141 case IMAGE_COLOR_PIXMAP:
|
|
1142 case IMAGE_POINTER:
|
173
|
1143 return make_int (XIMAGE_INSTANCE_PIXMAP_HEIGHT (image_instance));
|
0
|
1144
|
|
1145 default:
|
|
1146 return Qnil;
|
|
1147 }
|
|
1148 }
|
|
1149
|
20
|
1150 DEFUN ("image-instance-width", Fimage_instance_width, 1, 1, 0, /*
|
0
|
1151 Return the width of the image instance, in pixels.
|
20
|
1152 */
|
|
1153 (image_instance))
|
0
|
1154 {
|
|
1155 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1156
|
|
1157 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1158 {
|
|
1159 case IMAGE_MONO_PIXMAP:
|
|
1160 case IMAGE_COLOR_PIXMAP:
|
|
1161 case IMAGE_POINTER:
|
173
|
1162 return make_int (XIMAGE_INSTANCE_PIXMAP_WIDTH (image_instance));
|
0
|
1163
|
|
1164 default:
|
|
1165 return Qnil;
|
|
1166 }
|
|
1167 }
|
|
1168
|
20
|
1169 DEFUN ("image-instance-hotspot-x", Fimage_instance_hotspot_x, 1, 1, 0, /*
|
0
|
1170 Return the X coordinate of the image instance's hotspot, if known.
|
|
1171 This is a point relative to the origin of the pixmap. When an image is
|
|
1172 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1173 over the location that the pointer points to. This is, for example, the
|
|
1174 tip of the arrow or the center of the crosshairs.
|
|
1175 This will always be nil for a non-pointer image instance.
|
20
|
1176 */
|
|
1177 (image_instance))
|
0
|
1178 {
|
|
1179 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1180
|
|
1181 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1182 {
|
|
1183 case IMAGE_MONO_PIXMAP:
|
|
1184 case IMAGE_COLOR_PIXMAP:
|
|
1185 case IMAGE_POINTER:
|
|
1186 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image_instance);
|
|
1187
|
|
1188 default:
|
|
1189 return Qnil;
|
|
1190 }
|
|
1191 }
|
|
1192
|
20
|
1193 DEFUN ("image-instance-hotspot-y", Fimage_instance_hotspot_y, 1, 1, 0, /*
|
0
|
1194 Return the Y coordinate of the image instance's hotspot, if known.
|
|
1195 This is a point relative to the origin of the pixmap. When an image is
|
|
1196 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1197 over the location that the pointer points to. This is, for example, the
|
|
1198 tip of the arrow or the center of the crosshairs.
|
|
1199 This will always be nil for a non-pointer image instance.
|
20
|
1200 */
|
|
1201 (image_instance))
|
0
|
1202 {
|
|
1203 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1204
|
|
1205 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1206 {
|
|
1207 case IMAGE_MONO_PIXMAP:
|
|
1208 case IMAGE_COLOR_PIXMAP:
|
|
1209 case IMAGE_POINTER:
|
|
1210 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image_instance);
|
|
1211
|
|
1212 default:
|
|
1213 return Qnil;
|
|
1214 }
|
|
1215 }
|
|
1216
|
20
|
1217 DEFUN ("image-instance-foreground", Fimage_instance_foreground, 1, 1, 0, /*
|
0
|
1218 Return the foreground color of IMAGE-INSTANCE, if applicable.
|
|
1219 This will be a color instance or nil. (It will only be non-nil for
|
|
1220 colorized mono pixmaps and for pointers.)
|
20
|
1221 */
|
|
1222 (image_instance))
|
0
|
1223 {
|
|
1224 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1225
|
|
1226 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1227 {
|
|
1228 case IMAGE_MONO_PIXMAP:
|
|
1229 case IMAGE_COLOR_PIXMAP:
|
|
1230 case IMAGE_POINTER:
|
|
1231 return XIMAGE_INSTANCE_PIXMAP_FG (image_instance);
|
|
1232
|
|
1233 default:
|
|
1234 return Qnil;
|
|
1235 }
|
|
1236 }
|
|
1237
|
20
|
1238 DEFUN ("image-instance-background", Fimage_instance_background, 1, 1, 0, /*
|
0
|
1239 Return the background color of IMAGE-INSTANCE, if applicable.
|
|
1240 This will be a color instance or nil. (It will only be non-nil for
|
|
1241 colorized mono pixmaps and for pointers.)
|
20
|
1242 */
|
|
1243 (image_instance))
|
0
|
1244 {
|
|
1245 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1246
|
|
1247 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1248 {
|
|
1249 case IMAGE_MONO_PIXMAP:
|
|
1250 case IMAGE_COLOR_PIXMAP:
|
|
1251 case IMAGE_POINTER:
|
|
1252 return XIMAGE_INSTANCE_PIXMAP_BG (image_instance);
|
|
1253
|
|
1254 default:
|
|
1255 return Qnil;
|
|
1256 }
|
|
1257 }
|
|
1258
|
|
1259
|
20
|
1260 DEFUN ("colorize-image-instance", Fcolorize_image_instance, 3, 3, 0, /*
|
0
|
1261 Make the image instance be displayed in the given colors.
|
|
1262 This function returns a new image instance that is exactly like the
|
|
1263 specified one except that (if possible) the foreground and background
|
|
1264 colors and as specified. Currently, this only does anything if the image
|
|
1265 instance is a mono pixmap; otherwise, the same image instance is returned.
|
20
|
1266 */
|
|
1267 (image_instance, foreground, background))
|
0
|
1268 {
|
|
1269 Lisp_Object new;
|
|
1270 Lisp_Object device;
|
|
1271
|
|
1272 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1273 CHECK_COLOR_INSTANCE (foreground);
|
|
1274 CHECK_COLOR_INSTANCE (background);
|
|
1275
|
|
1276 device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
1277 if (!HAS_DEVMETH_P (XDEVICE (device), colorize_image_instance))
|
|
1278 return image_instance;
|
|
1279
|
|
1280 new = allocate_image_instance (device);
|
|
1281 copy_lcrecord (XIMAGE_INSTANCE (new), XIMAGE_INSTANCE (image_instance));
|
|
1282 /* note that if this method returns non-zero, this method MUST
|
|
1283 copy any window-system resources, so that when one image instance is
|
|
1284 freed, the other one is not hosed. */
|
|
1285 if (!DEVMETH (XDEVICE (device), colorize_image_instance, (new, foreground,
|
|
1286 background)))
|
|
1287 return image_instance;
|
|
1288 return new;
|
|
1289 }
|
|
1290
|
|
1291
|
276
|
1292 /************************************************************************/
|
|
1293 /* error helpers */
|
|
1294 /************************************************************************/
|
|
1295 DOESNT_RETURN
|
|
1296 signal_image_error (CONST char *reason, Lisp_Object frob)
|
|
1297 {
|
|
1298 signal_error (Qimage_conversion_error,
|
|
1299 list2 (build_translated_string (reason), frob));
|
|
1300 }
|
|
1301
|
|
1302 DOESNT_RETURN
|
|
1303 signal_image_error_2 (CONST char *reason, Lisp_Object frob0, Lisp_Object frob1)
|
|
1304 {
|
|
1305 signal_error (Qimage_conversion_error,
|
|
1306 list3 (build_translated_string (reason), frob0, frob1));
|
|
1307 }
|
|
1308
|
0
|
1309 /****************************************************************************
|
|
1310 * nothing *
|
|
1311 ****************************************************************************/
|
|
1312
|
|
1313 static int
|
74
|
1314 nothing_possible_dest_types (void)
|
0
|
1315 {
|
|
1316 return IMAGE_NOTHING_MASK;
|
|
1317 }
|
|
1318
|
|
1319 static void
|
|
1320 nothing_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1321 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1322 int dest_mask, Lisp_Object domain)
|
0
|
1323 {
|
|
1324 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1325
|
|
1326 if (dest_mask & IMAGE_NOTHING_MASK)
|
|
1327 IMAGE_INSTANCE_TYPE (ii) = IMAGE_NOTHING;
|
|
1328 else
|
|
1329 incompatible_image_types (instantiator, dest_mask, IMAGE_NOTHING_MASK);
|
|
1330 }
|
|
1331
|
|
1332
|
|
1333 /****************************************************************************
|
|
1334 * inherit *
|
|
1335 ****************************************************************************/
|
|
1336
|
|
1337 static void
|
|
1338 inherit_validate (Lisp_Object instantiator)
|
|
1339 {
|
|
1340 face_must_be_present (instantiator);
|
|
1341 }
|
|
1342
|
|
1343 static Lisp_Object
|
|
1344 inherit_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1345 {
|
|
1346 Lisp_Object face;
|
|
1347
|
173
|
1348 assert (XVECTOR_LENGTH (inst) == 3);
|
|
1349 face = XVECTOR_DATA (inst)[2];
|
0
|
1350 if (!FACEP (face))
|
|
1351 inst = vector3 (Qinherit, Q_face, Fget_face (face));
|
|
1352 return inst;
|
|
1353 }
|
|
1354
|
|
1355 static int
|
74
|
1356 inherit_possible_dest_types (void)
|
0
|
1357 {
|
|
1358 return IMAGE_MONO_PIXMAP_MASK;
|
|
1359 }
|
|
1360
|
|
1361 static void
|
|
1362 inherit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1363 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1364 int dest_mask, Lisp_Object domain)
|
0
|
1365 {
|
|
1366 /* handled specially in image_instantiate */
|
|
1367 abort ();
|
|
1368 }
|
|
1369
|
|
1370
|
|
1371 /****************************************************************************
|
|
1372 * string *
|
|
1373 ****************************************************************************/
|
|
1374
|
|
1375 static void
|
|
1376 string_validate (Lisp_Object instantiator)
|
|
1377 {
|
|
1378 data_must_be_present (instantiator);
|
|
1379 }
|
|
1380
|
|
1381 static int
|
74
|
1382 string_possible_dest_types (void)
|
0
|
1383 {
|
|
1384 return IMAGE_TEXT_MASK;
|
|
1385 }
|
|
1386
|
|
1387 /* called from autodetect_instantiate() */
|
|
1388 void
|
|
1389 string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1390 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1391 int dest_mask, Lisp_Object domain)
|
0
|
1392 {
|
|
1393 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1394 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1395
|
|
1396 assert (!NILP (data));
|
|
1397 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1398 {
|
|
1399 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1400 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1401 }
|
|
1402 else
|
|
1403 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1404 }
|
|
1405
|
|
1406
|
|
1407 /****************************************************************************
|
|
1408 * formatted-string *
|
|
1409 ****************************************************************************/
|
|
1410
|
|
1411 static void
|
|
1412 formatted_string_validate (Lisp_Object instantiator)
|
|
1413 {
|
|
1414 data_must_be_present (instantiator);
|
|
1415 }
|
|
1416
|
|
1417 static int
|
74
|
1418 formatted_string_possible_dest_types (void)
|
0
|
1419 {
|
|
1420 return IMAGE_TEXT_MASK;
|
|
1421 }
|
|
1422
|
|
1423 static void
|
|
1424 formatted_string_instantiate (Lisp_Object image_instance,
|
|
1425 Lisp_Object instantiator,
|
|
1426 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1427 int dest_mask, Lisp_Object domain)
|
0
|
1428 {
|
|
1429 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1430 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1431
|
|
1432 assert (!NILP (data));
|
|
1433 /* #### implement this */
|
|
1434 warn_when_safe (Qunimplemented, Qnotice,
|
|
1435 "`formatted-string' not yet implemented; assuming `string'");
|
|
1436 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1437 {
|
|
1438 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1439 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1440 }
|
|
1441 else
|
|
1442 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1443 }
|
|
1444
|
|
1445
|
278
|
1446 /************************************************************************/
|
|
1447 /* pixmap file functions */
|
|
1448 /************************************************************************/
|
|
1449
|
|
1450 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
1451 If INSTANTIATOR refers to data in a file, return the full filename
|
|
1452 if it exists; otherwise, return a cons of (filename).
|
|
1453
|
|
1454 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
1455 keywords used to look up the file and inline data,
|
|
1456 respectively, in the instantiator. Normally these would
|
|
1457 be Q_file and Q_data, but might be different for mask data. */
|
|
1458
|
|
1459 Lisp_Object
|
|
1460 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
1461 Lisp_Object file_keyword,
|
|
1462 Lisp_Object data_keyword,
|
|
1463 Lisp_Object console_type)
|
|
1464 {
|
|
1465 Lisp_Object file;
|
|
1466 Lisp_Object data;
|
|
1467
|
|
1468 assert (VECTORP (instantiator));
|
|
1469
|
|
1470 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
1471 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
1472
|
|
1473 if (!NILP (file) && NILP (data))
|
|
1474 {
|
|
1475 Lisp_Object retval = MAYBE_LISP_CONTYPE_METH
|
|
1476 (decode_console_type(console_type, ERROR_ME),
|
|
1477 locate_pixmap_file, (file));
|
|
1478
|
|
1479 if (!NILP (retval))
|
|
1480 return retval;
|
|
1481 else
|
|
1482 return Fcons (file, Qnil); /* should have been file */
|
|
1483 }
|
|
1484
|
|
1485 return Qnil;
|
|
1486 }
|
|
1487
|
|
1488 Lisp_Object
|
|
1489 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
1490 Lisp_Object image_type_tag)
|
|
1491 {
|
|
1492 /* This function can call lisp */
|
|
1493 Lisp_Object file = Qnil;
|
|
1494 struct gcpro gcpro1, gcpro2;
|
|
1495 Lisp_Object alist = Qnil;
|
|
1496
|
|
1497 GCPRO2 (file, alist);
|
|
1498
|
|
1499 /* Now, convert any file data into inline data. At the end of this,
|
|
1500 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
1501 will contain the name this data was derived from (if known) or
|
|
1502 Qnil.
|
|
1503
|
|
1504 Note that if we cannot generate any regular inline data, we
|
|
1505 skip out. */
|
|
1506
|
|
1507 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1508 console_type);
|
|
1509
|
|
1510 if (CONSP (file)) /* failure locating filename */
|
|
1511 signal_double_file_error ("Opening pixmap file",
|
|
1512 "no such file or directory",
|
|
1513 Fcar (file));
|
|
1514
|
|
1515 if (NILP (file)) /* no conversion necessary */
|
|
1516 RETURN_UNGCPRO (inst);
|
|
1517
|
|
1518 alist = tagged_vector_to_alist (inst);
|
|
1519
|
|
1520 {
|
|
1521 Lisp_Object data = make_string_from_file (file);
|
|
1522 alist = remassq_no_quit (Q_file, alist);
|
|
1523 /* there can't be a :data at this point. */
|
|
1524 alist = Fcons (Fcons (Q_file, file),
|
|
1525 Fcons (Fcons (Q_data, data), alist));
|
|
1526 }
|
|
1527
|
|
1528 {
|
|
1529 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
1530 free_alist (alist);
|
|
1531 RETURN_UNGCPRO (result);
|
|
1532 }
|
|
1533 }
|
|
1534
|
|
1535
|
276
|
1536 #ifdef HAVE_XPM
|
|
1537
|
|
1538 /**********************************************************************
|
|
1539 * XPM *
|
|
1540 **********************************************************************/
|
|
1541
|
280
|
1542 Lisp_Object
|
|
1543 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid)
|
|
1544 {
|
|
1545 char **data;
|
|
1546 int result;
|
|
1547
|
|
1548 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data);
|
|
1549
|
|
1550 if (result == XpmSuccess)
|
|
1551 {
|
|
1552 Lisp_Object retval = Qnil;
|
|
1553 struct buffer *old_buffer = current_buffer;
|
|
1554 Lisp_Object temp_buffer =
|
|
1555 Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
1556 int elt;
|
|
1557 int height, width, ncolors;
|
|
1558 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1559 int speccount = specpdl_depth ();
|
|
1560
|
|
1561 GCPRO3 (name, retval, temp_buffer);
|
|
1562
|
|
1563 specbind (Qinhibit_quit, Qt);
|
|
1564 set_buffer_internal (XBUFFER (temp_buffer));
|
|
1565 Ferase_buffer (Qnil);
|
|
1566
|
|
1567 buffer_insert_c_string (current_buffer, "/* XPM */\r");
|
|
1568 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r");
|
|
1569
|
|
1570 sscanf (data[0], "%d %d %d", &height, &width, &ncolors);
|
|
1571 for (elt = 0; elt <= width + ncolors; elt++)
|
|
1572 {
|
|
1573 buffer_insert_c_string (current_buffer, "\"");
|
|
1574 buffer_insert_c_string (current_buffer, data[elt]);
|
|
1575
|
|
1576 if (elt < width + ncolors)
|
|
1577 buffer_insert_c_string (current_buffer, "\",\r");
|
|
1578 else
|
|
1579 buffer_insert_c_string (current_buffer, "\"};\r");
|
|
1580 }
|
|
1581
|
|
1582 retval = Fbuffer_substring (Qnil, Qnil, Qnil);
|
|
1583 XpmFree (data);
|
|
1584
|
|
1585 set_buffer_internal (old_buffer);
|
|
1586 unbind_to (speccount, Qnil);
|
|
1587
|
|
1588 RETURN_UNGCPRO (retval);
|
|
1589 }
|
|
1590
|
|
1591 switch (result)
|
|
1592 {
|
|
1593 case XpmFileInvalid:
|
|
1594 {
|
|
1595 if (ok_if_data_invalid)
|
|
1596 return Qt;
|
|
1597 signal_image_error ("invalid XPM data in file", name);
|
|
1598 }
|
|
1599 case XpmNoMemory:
|
|
1600 {
|
|
1601 signal_double_file_error ("Reading pixmap file",
|
|
1602 "out of memory", name);
|
|
1603 }
|
|
1604 case XpmOpenFailed:
|
|
1605 {
|
|
1606 /* should never happen? */
|
|
1607 signal_double_file_error ("Opening pixmap file",
|
|
1608 "no such file or directory", name);
|
|
1609 }
|
|
1610 default:
|
|
1611 {
|
|
1612 signal_double_file_error_2 ("Parsing pixmap file",
|
|
1613 "unknown error code",
|
|
1614 make_int (result), name);
|
|
1615 break;
|
|
1616 }
|
|
1617 }
|
|
1618
|
|
1619 return Qnil; /* not reached */
|
|
1620 }
|
|
1621
|
276
|
1622 static void
|
|
1623 check_valid_xpm_color_symbols (Lisp_Object data)
|
|
1624 {
|
|
1625 Lisp_Object rest;
|
|
1626
|
|
1627 for (rest = data; !NILP (rest); rest = XCDR (rest))
|
|
1628 {
|
|
1629 if (!CONSP (rest) ||
|
|
1630 !CONSP (XCAR (rest)) ||
|
|
1631 !STRINGP (XCAR (XCAR (rest))) ||
|
|
1632 (!STRINGP (XCDR (XCAR (rest))) &&
|
|
1633 !COLOR_SPECIFIERP (XCDR (XCAR (rest)))))
|
|
1634 signal_simple_error ("Invalid color symbol alist", data);
|
|
1635 }
|
|
1636 }
|
|
1637
|
|
1638 static void
|
|
1639 xpm_validate (Lisp_Object instantiator)
|
|
1640 {
|
|
1641 file_or_data_must_be_present (instantiator);
|
|
1642 }
|
|
1643
|
|
1644 Lisp_Object Vxpm_color_symbols;
|
|
1645
|
|
1646 Lisp_Object
|
|
1647 evaluate_xpm_color_symbols (void)
|
|
1648 {
|
|
1649 Lisp_Object rest, results = Qnil;
|
|
1650 struct gcpro gcpro1, gcpro2;
|
|
1651
|
|
1652 GCPRO2 (rest, results);
|
|
1653 for (rest = Vxpm_color_symbols; !NILP (rest); rest = XCDR (rest))
|
|
1654 {
|
|
1655 Lisp_Object name, value, cons;
|
|
1656
|
|
1657 CHECK_CONS (rest);
|
|
1658 cons = XCAR (rest);
|
|
1659 CHECK_CONS (cons);
|
|
1660 name = XCAR (cons);
|
|
1661 CHECK_STRING (name);
|
|
1662 value = XCDR (cons);
|
|
1663 CHECK_CONS (value);
|
|
1664 value = XCAR (value);
|
|
1665 value = Feval (value);
|
|
1666 if (NILP (value))
|
|
1667 continue;
|
|
1668 if (!STRINGP (value) && !COLOR_SPECIFIERP (value))
|
|
1669 signal_simple_error
|
|
1670 ("Result from xpm-color-symbols eval must be nil, string, or color",
|
|
1671 value);
|
|
1672 results = Fcons (Fcons (name, value), results);
|
|
1673 }
|
|
1674 UNGCPRO; /* no more evaluation */
|
|
1675 return results;
|
|
1676 }
|
|
1677
|
|
1678 static Lisp_Object
|
|
1679 xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1680 {
|
280
|
1681 Lisp_Object file = Qnil;
|
|
1682 Lisp_Object color_symbols;
|
|
1683 struct gcpro gcpro1, gcpro2;
|
|
1684 Lisp_Object alist = Qnil;
|
|
1685
|
|
1686 GCPRO2 (file, alist);
|
|
1687
|
|
1688 /* Now, convert any file data into inline data. At the end of this,
|
|
1689 `data' will contain the inline data (if any) or Qnil, and
|
|
1690 `file' will contain the name this data was derived from (if
|
|
1691 known) or Qnil.
|
|
1692
|
|
1693 Note that if we cannot generate any regular inline data, we
|
|
1694 skip out. */
|
|
1695
|
|
1696 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1697 console_type);
|
|
1698
|
|
1699 if (CONSP (file)) /* failure locating filename */
|
|
1700 signal_double_file_error ("Opening pixmap file",
|
|
1701 "no such file or directory",
|
|
1702 Fcar (file));
|
|
1703
|
|
1704 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols,
|
|
1705 Qunbound);
|
|
1706
|
|
1707 if (NILP (file) && !UNBOUNDP (color_symbols))
|
|
1708 /* no conversion necessary */
|
|
1709 RETURN_UNGCPRO (inst);
|
|
1710
|
|
1711 alist = tagged_vector_to_alist (inst);
|
|
1712
|
|
1713 if (!NILP (file))
|
|
1714 {
|
|
1715 Lisp_Object data = pixmap_to_lisp_data (file, 0);
|
|
1716 alist = remassq_no_quit (Q_file, alist);
|
|
1717 /* there can't be a :data at this point. */
|
|
1718 alist = Fcons (Fcons (Q_file, file),
|
|
1719 Fcons (Fcons (Q_data, data), alist));
|
|
1720 }
|
|
1721
|
|
1722 if (UNBOUNDP (color_symbols))
|
|
1723 {
|
|
1724 color_symbols = evaluate_xpm_color_symbols ();
|
|
1725 alist = Fcons (Fcons (Q_color_symbols, color_symbols),
|
|
1726 alist);
|
|
1727 }
|
|
1728
|
|
1729 {
|
|
1730 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1731 free_alist (alist);
|
|
1732 RETURN_UNGCPRO (result);
|
|
1733 }
|
276
|
1734 }
|
|
1735
|
|
1736 static int
|
|
1737 xpm_possible_dest_types (void)
|
|
1738 {
|
|
1739 return
|
|
1740 IMAGE_MONO_PIXMAP_MASK |
|
|
1741 IMAGE_COLOR_PIXMAP_MASK |
|
|
1742 IMAGE_POINTER_MASK;
|
|
1743 }
|
|
1744
|
|
1745 static void
|
|
1746 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1747 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1748 int dest_mask, Lisp_Object domain)
|
|
1749 {
|
|
1750 Lisp_Object device= IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (image_instance));
|
280
|
1751
|
|
1752 MAYBE_DEVMETH (XDEVICE (device),
|
|
1753 xpm_instantiate,
|
|
1754 (image_instance, instantiator, pointer_fg,
|
|
1755 pointer_bg, dest_mask, domain));
|
276
|
1756 }
|
|
1757
|
|
1758 #endif /* HAVE_XPM */
|
|
1759
|
|
1760
|
0
|
1761 /****************************************************************************
|
|
1762 * Image Specifier Object *
|
|
1763 ****************************************************************************/
|
|
1764
|
|
1765 DEFINE_SPECIFIER_TYPE (image);
|
|
1766
|
|
1767 static void
|
|
1768 image_create (Lisp_Object obj)
|
|
1769 {
|
|
1770 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
1771
|
|
1772 IMAGE_SPECIFIER_ALLOWED (image) = ~0; /* all are allowed */
|
|
1773 IMAGE_SPECIFIER_ATTACHEE (image) = Qnil;
|
|
1774 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image) = Qnil;
|
|
1775 }
|
|
1776
|
|
1777 static void
|
|
1778 image_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
1779 {
|
|
1780 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
1781
|
|
1782 ((markobj) (IMAGE_SPECIFIER_ATTACHEE (image)));
|
|
1783 ((markobj) (IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image)));
|
|
1784 }
|
|
1785
|
|
1786 static Lisp_Object
|
|
1787 image_instantiate_cache_result (Lisp_Object locative)
|
|
1788 {
|
272
|
1789 /* locative = (instance instantiator . subtable) */
|
|
1790 Fputhash (XCAR (XCDR (locative)), XCAR (locative), XCDR (XCDR (locative)));
|
0
|
1791 free_cons (XCONS (XCDR (locative)));
|
|
1792 free_cons (XCONS (locative));
|
|
1793 return Qnil;
|
|
1794 }
|
|
1795
|
|
1796 /* Given a specification for an image, return an instance of
|
|
1797 the image which matches the given instantiator and which can be
|
|
1798 displayed in the given domain. */
|
|
1799
|
|
1800 static Lisp_Object
|
|
1801 image_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
|
|
1802 Lisp_Object domain, Lisp_Object instantiator,
|
|
1803 Lisp_Object depth)
|
|
1804 {
|
|
1805 Lisp_Object device = DFW_DEVICE (domain);
|
|
1806 struct device *d = XDEVICE (device);
|
|
1807 int dest_mask = XIMAGE_SPECIFIER_ALLOWED (specifier);
|
|
1808 int pointerp = dest_mask & image_instance_type_to_mask (IMAGE_POINTER);
|
|
1809
|
|
1810 if (IMAGE_INSTANCEP (instantiator))
|
|
1811 {
|
|
1812 /* make sure that the image instance's device and type are
|
|
1813 matching. */
|
|
1814
|
|
1815 if (EQ (device, XIMAGE_INSTANCE_DEVICE (instantiator)))
|
|
1816 {
|
|
1817 int mask =
|
|
1818 image_instance_type_to_mask (XIMAGE_INSTANCE_TYPE (instantiator));
|
|
1819 if (mask & dest_mask)
|
|
1820 return instantiator;
|
|
1821 else
|
|
1822 signal_simple_error ("Type of image instance not allowed here",
|
|
1823 instantiator);
|
|
1824 }
|
|
1825 else
|
|
1826 signal_simple_error_2 ("Wrong device for image instance",
|
|
1827 instantiator, device);
|
|
1828 }
|
|
1829 else if (VECTORP (instantiator)
|
173
|
1830 && EQ (XVECTOR_DATA (instantiator)[0], Qinherit))
|
0
|
1831 {
|
173
|
1832 assert (XVECTOR_LENGTH (instantiator) == 3);
|
0
|
1833 return (FACE_PROPERTY_INSTANCE
|
173
|
1834 (Fget_face (XVECTOR_DATA (instantiator)[2]),
|
0
|
1835 Qbackground_pixmap, domain, 0, depth));
|
|
1836 }
|
|
1837 else
|
|
1838 {
|
|
1839 Lisp_Object instance;
|
|
1840 Lisp_Object subtable;
|
|
1841 Lisp_Object ls3 = Qnil;
|
|
1842 Lisp_Object pointer_fg = Qnil;
|
|
1843 Lisp_Object pointer_bg = Qnil;
|
|
1844
|
|
1845 if (pointerp)
|
|
1846 {
|
|
1847 pointer_fg = FACE_FOREGROUND (Vpointer_face, domain);
|
|
1848 pointer_bg = FACE_BACKGROUND (Vpointer_face, domain);
|
|
1849 ls3 = list3 (instantiator, pointer_fg, pointer_bg);
|
|
1850 }
|
|
1851
|
|
1852 /* First look in the hash table. */
|
|
1853 subtable = Fgethash (make_int (dest_mask), d->image_instance_cache,
|
|
1854 Qunbound);
|
|
1855 if (UNBOUNDP (subtable))
|
|
1856 {
|
|
1857 /* For the image instance cache, we do comparisons with EQ rather
|
|
1858 than with EQUAL, as we do for color and font names.
|
|
1859 The reasons are:
|
|
1860
|
|
1861 1) pixmap data can be very long, and thus the hashing and
|
|
1862 comparing will take awhile.
|
|
1863 2) It's not so likely that we'll run into things that are EQUAL
|
|
1864 but not EQ (that can happen a lot with faces, because their
|
|
1865 specifiers are copied around); but pixmaps tend not to be
|
|
1866 in faces.
|
|
1867
|
|
1868 However, if the image-instance could be a pointer, we have to
|
|
1869 use EQUAL because we massaged the instantiator into a cons3
|
|
1870 also containing the foreground and background of the
|
|
1871 pointer face.
|
|
1872 */
|
|
1873
|
|
1874 subtable = make_lisp_hashtable (20,
|
|
1875 pointerp ? HASHTABLE_KEY_CAR_WEAK
|
|
1876 : HASHTABLE_KEY_WEAK,
|
|
1877 pointerp ? HASHTABLE_EQUAL
|
|
1878 : HASHTABLE_EQ);
|
|
1879 Fputhash (make_int (dest_mask), subtable,
|
|
1880 d->image_instance_cache);
|
|
1881 instance = Qunbound;
|
|
1882 }
|
|
1883 else
|
|
1884 instance = Fgethash (pointerp ? ls3 : instantiator,
|
|
1885 subtable, Qunbound);
|
|
1886
|
|
1887 if (UNBOUNDP (instance))
|
|
1888 {
|
|
1889 Lisp_Object locative =
|
|
1890 noseeum_cons (Qnil,
|
|
1891 noseeum_cons (pointerp ? ls3 : instantiator,
|
|
1892 subtable));
|
|
1893 int speccount = specpdl_depth ();
|
|
1894
|
|
1895 /* make sure we cache the failures, too.
|
|
1896 Use an unwind-protect to catch such errors.
|
|
1897 If we fail, the unwind-protect records nil in
|
|
1898 the hash table. If we succeed, we change the
|
|
1899 car of the locative to the resulting instance,
|
|
1900 which gets recorded instead. */
|
|
1901 record_unwind_protect (image_instantiate_cache_result,
|
|
1902 locative);
|
|
1903 instance = instantiate_image_instantiator (device,
|
124
|
1904 domain,
|
0
|
1905 instantiator,
|
|
1906 pointer_fg, pointer_bg,
|
|
1907 dest_mask);
|
|
1908 Fsetcar (locative, instance);
|
|
1909 unbind_to (speccount, Qnil);
|
|
1910 }
|
|
1911 else
|
|
1912 free_list (ls3);
|
|
1913
|
|
1914 if (NILP (instance))
|
|
1915 signal_simple_error ("Can't instantiate image (probably cached)",
|
|
1916 instantiator);
|
|
1917 return instance;
|
|
1918 }
|
|
1919
|
|
1920 abort ();
|
|
1921 return Qnil; /* not reached */
|
|
1922 }
|
|
1923
|
|
1924 /* Validate an image instantiator. */
|
|
1925
|
|
1926 static void
|
|
1927 image_validate (Lisp_Object instantiator)
|
|
1928 {
|
|
1929 if (IMAGE_INSTANCEP (instantiator) || STRINGP (instantiator))
|
|
1930 return;
|
|
1931 else if (VECTORP (instantiator))
|
|
1932 {
|
173
|
1933 Lisp_Object *elt = XVECTOR_DATA (instantiator);
|
|
1934 int instantiator_len = XVECTOR_LENGTH (instantiator);
|
0
|
1935 struct image_instantiator_methods *meths;
|
|
1936 Lisp_Object already_seen = Qnil;
|
|
1937 struct gcpro gcpro1;
|
|
1938 int i;
|
|
1939
|
|
1940 if (instantiator_len < 1)
|
|
1941 signal_simple_error ("Vector length must be at least 1",
|
|
1942 instantiator);
|
|
1943
|
|
1944 meths = decode_image_instantiator_format (elt[0], ERROR_ME);
|
|
1945 if (!(instantiator_len & 1))
|
|
1946 signal_simple_error
|
|
1947 ("Must have alternating keyword/value pairs", instantiator);
|
|
1948
|
|
1949 GCPRO1 (already_seen);
|
|
1950
|
|
1951 for (i = 1; i < instantiator_len; i += 2)
|
|
1952 {
|
|
1953 Lisp_Object keyword = elt[i];
|
|
1954 Lisp_Object value = elt[i+1];
|
|
1955 int j;
|
|
1956
|
|
1957 CHECK_SYMBOL (keyword);
|
|
1958 if (!SYMBOL_IS_KEYWORD (keyword))
|
|
1959 signal_simple_error ("Symbol must begin with a colon", keyword);
|
|
1960
|
|
1961 for (j = 0; j < Dynarr_length (meths->keywords); j++)
|
|
1962 if (EQ (keyword, Dynarr_at (meths->keywords, j).keyword))
|
|
1963 break;
|
|
1964
|
|
1965 if (j == Dynarr_length (meths->keywords))
|
|
1966 signal_simple_error ("Unrecognized keyword", keyword);
|
|
1967
|
|
1968 if (!Dynarr_at (meths->keywords, j).multiple_p)
|
|
1969 {
|
|
1970 if (!NILP (memq_no_quit (keyword, already_seen)))
|
|
1971 signal_simple_error
|
|
1972 ("Keyword may not appear more than once", keyword);
|
|
1973 already_seen = Fcons (keyword, already_seen);
|
|
1974 }
|
|
1975
|
|
1976 (Dynarr_at (meths->keywords, j).validate) (value);
|
|
1977 }
|
|
1978
|
|
1979 UNGCPRO;
|
|
1980
|
|
1981 MAYBE_IIFORMAT_METH (meths, validate, (instantiator));
|
|
1982 }
|
|
1983 else
|
|
1984 signal_simple_error ("Must be string or vector", instantiator);
|
|
1985 }
|
|
1986
|
|
1987 static void
|
|
1988 image_after_change (Lisp_Object specifier, Lisp_Object locale)
|
|
1989 {
|
|
1990 Lisp_Object attachee =
|
|
1991 IMAGE_SPECIFIER_ATTACHEE (XIMAGE_SPECIFIER (specifier));
|
|
1992 Lisp_Object property =
|
|
1993 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (XIMAGE_SPECIFIER (specifier));
|
|
1994 if (FACEP (attachee))
|
|
1995 face_property_was_changed (attachee, property, locale);
|
|
1996 else if (GLYPHP (attachee))
|
|
1997 glyph_property_was_changed (attachee, property, locale);
|
|
1998 }
|
|
1999
|
|
2000 void
|
|
2001 set_image_attached_to (Lisp_Object obj, Lisp_Object face_or_glyph,
|
|
2002 Lisp_Object property)
|
|
2003 {
|
|
2004 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
2005
|
|
2006 IMAGE_SPECIFIER_ATTACHEE (image) = face_or_glyph;
|
|
2007 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image) = property;
|
|
2008 }
|
|
2009
|
|
2010 static Lisp_Object
|
|
2011 image_going_to_add (Lisp_Object specifier, Lisp_Object locale,
|
|
2012 Lisp_Object tag_set, Lisp_Object instantiator)
|
|
2013 {
|
|
2014 Lisp_Object possible_console_types = Qnil;
|
|
2015 Lisp_Object rest;
|
|
2016 Lisp_Object retlist = Qnil;
|
|
2017 struct gcpro gcpro1, gcpro2;
|
|
2018
|
|
2019 LIST_LOOP (rest, Vconsole_type_list)
|
|
2020 {
|
|
2021 Lisp_Object contype = XCAR (rest);
|
|
2022 if (!NILP (memq_no_quit (contype, tag_set)))
|
|
2023 possible_console_types = Fcons (contype, possible_console_types);
|
|
2024 }
|
|
2025
|
|
2026 if (XINT (Flength (possible_console_types)) > 1)
|
|
2027 /* two conflicting console types specified */
|
|
2028 return Qnil;
|
|
2029
|
|
2030 if (NILP (possible_console_types))
|
|
2031 possible_console_types = Vconsole_type_list;
|
|
2032
|
|
2033 GCPRO2 (retlist, possible_console_types);
|
|
2034
|
|
2035 LIST_LOOP (rest, possible_console_types)
|
|
2036 {
|
|
2037 Lisp_Object contype = XCAR (rest);
|
272
|
2038 Lisp_Object newinst = call_with_suspended_errors
|
74
|
2039 ((lisp_fn_t) normalize_image_instantiator,
|
|
2040 Qnil, Qimage, ERROR_ME_NOT, 3, instantiator, contype,
|
|
2041 make_int (XIMAGE_SPECIFIER_ALLOWED (specifier)));
|
84
|
2042
|
0
|
2043 if (!NILP (newinst))
|
|
2044 {
|
|
2045 Lisp_Object newtag;
|
|
2046 if (NILP (memq_no_quit (contype, tag_set)))
|
|
2047 newtag = Fcons (contype, tag_set);
|
|
2048 else
|
|
2049 newtag = tag_set;
|
|
2050 retlist = Fcons (Fcons (newtag, newinst), retlist);
|
|
2051 }
|
|
2052 }
|
|
2053
|
|
2054 UNGCPRO;
|
|
2055
|
|
2056 return retlist;
|
|
2057 }
|
|
2058
|
20
|
2059 DEFUN ("image-specifier-p", Fimage_specifier_p, 1, 1, 0, /*
|
0
|
2060 Return non-nil if OBJECT is an image specifier.
|
|
2061
|
|
2062 An image specifier is used for images (pixmaps and the like). It is used
|
|
2063 to describe the actual image in a glyph. It is instanced as an image-
|
|
2064 instance.
|
|
2065
|
|
2066 Image instantiators come in many formats: `xbm', `xpm', `gif', `jpeg',
|
|
2067 etc. This describes the format of the data describing the image. The
|
|
2068 resulting image instances also come in many types -- `mono-pixmap',
|
|
2069 `color-pixmap', `text', `pointer', etc. This refers to the behavior of
|
|
2070 the image and the sorts of places it can appear. (For example, a
|
|
2071 color-pixmap image has fixed colors specified for it, while a
|
185
|
2072 mono-pixmap image comes in two unspecified shades "foreground" and
|
|
2073 "background" that are determined from the face of the glyph or
|
0
|
2074 surrounding text; a text image appears as a string of text and has an
|
|
2075 unspecified foreground, background, and font; a pointer image behaves
|
|
2076 like a mono-pixmap image but can only be used as a mouse pointer
|
|
2077 \[mono-pixmap images cannot be used as mouse pointers]; etc.) It is
|
|
2078 important to keep the distinction between image instantiator format and
|
|
2079 image instance type in mind. Typically, a given image instantiator
|
|
2080 format can result in many different image instance types (for example,
|
|
2081 `xpm' can be instanced as `color-pixmap', `mono-pixmap', or `pointer';
|
|
2082 whereas `cursor-font' can be instanced only as `pointer'), and a
|
|
2083 particular image instance type can be generated by many different
|
|
2084 image instantiator formats (e.g. `color-pixmap' can be generated by `xpm',
|
|
2085 `gif', `jpeg', etc.).
|
|
2086
|
|
2087 See `make-image-instance' for a more detailed discussion of image
|
|
2088 instance types.
|
|
2089
|
|
2090 An image instantiator should be a string or a vector of the form
|
|
2091
|
|
2092 [FORMAT :KEYWORD VALUE ...]
|
|
2093
|
|
2094 i.e. a format symbol followed by zero or more alternating keyword-value
|
|
2095 pairs. FORMAT should be one of
|
|
2096
|
|
2097 'nothing
|
|
2098 (Don't display anything; no keywords are valid for this.
|
|
2099 Can only be instanced as `nothing'.)
|
|
2100 'string
|
|
2101 (Display this image as a text string. Can only be instanced
|
|
2102 as `text', although support for instancing as `mono-pixmap'
|
|
2103 should be added.)
|
|
2104 'formatted-string
|
|
2105 (Display this image as a text string, with replaceable fields;
|
|
2106 not currently implemented.)
|
|
2107 'xbm
|
|
2108 (An X bitmap; only if X support was compiled into this XEmacs.
|
|
2109 Can be instanced as `mono-pixmap', `color-pixmap', or `pointer'.)
|
|
2110 'xpm
|
|
2111 (An XPM pixmap; only if XPM support was compiled into this XEmacs.
|
|
2112 Can be instanced as `color-pixmap', `mono-pixmap', or `pointer'.)
|
|
2113 'xface
|
|
2114 (An X-Face bitmap, used to encode people's faces in e-mail messages;
|
|
2115 only if X-Face support was compiled into this XEmacs. Can be
|
|
2116 instanced as `mono-pixmap', `color-pixmap', or `pointer'.)
|
|
2117 'gif
|
|
2118 (A GIF87 or GIF89 image; only if GIF support was compiled into this
|
|
2119 XEmacs. Can be instanced as `color-pixmap'.)
|
|
2120 'jpeg
|
|
2121 (A JPEG image; only if JPEG support was compiled into this XEmacs.
|
|
2122 Can be instanced as `color-pixmap'.)
|
|
2123 'png
|
|
2124 (A PNG/GIF24 image; only if PNG support was compiled into this XEmacs.
|
|
2125 Can be instanced as `color-pixmap'.)
|
|
2126 'tiff
|
|
2127 (A TIFF image; not currently implemented.)
|
|
2128 'cursor-font
|
185
|
2129 (One of the standard cursor-font names, such as "watch" or
|
|
2130 "right_ptr" under X. Under X, this is, more specifically, any
|
0
|
2131 of the standard cursor names from appendix B of the Xlib manual
|
|
2132 [also known as the file <X11/cursorfont.h>] minus the XC_ prefix.
|
|
2133 On other window systems, the valid names will be specific to the
|
|
2134 type of window system. Can only be instanced as `pointer'.)
|
|
2135 'font
|
|
2136 (A glyph from a font; i.e. the name of a font, and glyph index into it
|
185
|
2137 of the form "FONT fontname index [[mask-font] mask-index]".
|
0
|
2138 Currently can only be instanced as `pointer', although this should
|
|
2139 probably be fixed.)
|
|
2140 'subwindow
|
|
2141 (An embedded X window; not currently implemented.)
|
122
|
2142 'autodetect
|
0
|
2143 (XEmacs tries to guess what format the data is in. If X support
|
|
2144 exists, the data string will be checked to see if it names a filename.
|
|
2145 If so, and this filename contains XBM or XPM data, the appropriate
|
|
2146 sort of pixmap or pointer will be created. [This includes picking up
|
|
2147 any specified hotspot or associated mask file.] Otherwise, if `pointer'
|
|
2148 is one of the allowable image-instance types and the string names a
|
|
2149 valid cursor-font name, the image will be created as a pointer.
|
|
2150 Otherwise, the image will be displayed as text. If no X support
|
|
2151 exists, the image will always be displayed as text.)
|
|
2152 'inherit
|
|
2153 Inherit from the background-pixmap property of a face.
|
|
2154
|
|
2155 The valid keywords are:
|
|
2156
|
|
2157 :data
|
|
2158 (Inline data. For most formats above, this should be a string. For
|
|
2159 XBM images, this should be a list of three elements: width, height, and
|
|
2160 a string of bit data. This keyword is not valid for instantiator
|
|
2161 formats `nothing' and `inherit'.)
|
|
2162 :file
|
|
2163 (Data is contained in a file. The value is the name of this file.
|
|
2164 If both :data and :file are specified, the image is created from
|
|
2165 what is specified in :data and the string in :file becomes the
|
|
2166 value of the `image-instance-file-name' function when applied to
|
|
2167 the resulting image-instance. This keyword is not valid for
|
|
2168 instantiator formats `nothing', `string', `formatted-string',
|
122
|
2169 `cursor-font', `font', `autodetect', and `inherit'.)
|
0
|
2170 :foreground
|
|
2171 :background
|
|
2172 (For `xbm', `xface', `cursor-font', and `font'. These keywords
|
|
2173 allow you to explicitly specify foreground and background colors.
|
|
2174 The argument should be anything acceptable to `make-color-instance'.
|
|
2175 This will cause what would be a `mono-pixmap' to instead be colorized
|
|
2176 as a two-color color-pixmap, and specifies the foreground and/or
|
|
2177 background colors for a pointer instead of black and white.)
|
|
2178 :mask-data
|
|
2179 (For `xbm' and `xface'. This specifies a mask to be used with the
|
|
2180 bitmap. The format is a list of width, height, and bits, like for
|
|
2181 :data.)
|
|
2182 :mask-file
|
|
2183 (For `xbm' and `xface'. This specifies a file containing the mask data.
|
|
2184 If neither a mask file nor inline mask data is given for an XBM image,
|
|
2185 and the XBM image comes from a file, XEmacs will look for a mask file
|
185
|
2186 with the same name as the image file but with "Mask" or "msk"
|
|
2187 appended. For example, if you specify the XBM file "left_ptr"
|
|
2188 [usually located in "/usr/include/X11/bitmaps"], the associated
|
|
2189 mask file "left_ptrmsk" will automatically be picked up.)
|
0
|
2190 :hotspot-x
|
|
2191 :hotspot-y
|
|
2192 (For `xbm' and `xface'. These keywords specify a hotspot if the image
|
|
2193 is instantiated as a `pointer'. Note that if the XBM image file
|
|
2194 specifies a hotspot, it will automatically be picked up if no
|
|
2195 explicit hotspot is given.)
|
|
2196 :color-symbols
|
|
2197 (Only for `xpm'. This specifies an alist that maps strings
|
|
2198 that specify symbolic color names to the actual color to be used
|
|
2199 for that symbolic color (in the form of a string or a color-specifier
|
|
2200 object). If this is not specified, the contents of `xpm-color-symbols'
|
|
2201 are used to generate the alist.)
|
|
2202 :face
|
|
2203 (Only for `inherit'. This specifies the face to inherit from.)
|
|
2204
|
|
2205 If instead of a vector, the instantiator is a string, it will be
|
|
2206 converted into a vector by looking it up according to the specs in the
|
|
2207 `console-type-image-conversion-list' (q.v.) for the console type of
|
|
2208 the domain (usually a window; sometimes a frame or device) over which
|
|
2209 the image is being instantiated.
|
|
2210
|
|
2211 If the instantiator specifies data from a file, the data will be read
|
|
2212 in at the time that the instantiator is added to the image (which may
|
|
2213 be well before when the image is actually displayed), and the
|
|
2214 instantiator will be converted into one of the inline-data forms, with
|
|
2215 the filename retained using a :file keyword. This implies that the
|
|
2216 file must exist when the instantiator is added to the image, but does
|
|
2217 not need to exist at any other time (e.g. it may safely be a temporary
|
|
2218 file).
|
20
|
2219 */
|
|
2220 (object))
|
0
|
2221 {
|
173
|
2222 return IMAGE_SPECIFIERP (object) ? Qt : Qnil;
|
0
|
2223 }
|
|
2224
|
|
2225
|
|
2226 /****************************************************************************
|
|
2227 * Glyph Object *
|
|
2228 ****************************************************************************/
|
|
2229
|
|
2230 static Lisp_Object
|
|
2231 mark_glyph (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2232 {
|
272
|
2233 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
0
|
2234
|
|
2235 ((markobj) (glyph->image));
|
|
2236 ((markobj) (glyph->contrib_p));
|
|
2237 ((markobj) (glyph->baseline));
|
|
2238 ((markobj) (glyph->face));
|
|
2239
|
173
|
2240 return glyph->plist;
|
0
|
2241 }
|
|
2242
|
|
2243 static void
|
|
2244 print_glyph (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
2245 {
|
|
2246 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
|
2247 char buf[20];
|
|
2248
|
|
2249 if (print_readably)
|
|
2250 error ("printing unreadable object #<glyph 0x%x>", glyph->header.uid);
|
|
2251
|
|
2252 write_c_string ("#<glyph (", printcharfun);
|
|
2253 print_internal (Fglyph_type (obj), printcharfun, 0);
|
|
2254 write_c_string (") ", printcharfun);
|
|
2255 print_internal (glyph->image, printcharfun, 1);
|
|
2256 sprintf (buf, "0x%x>", glyph->header.uid);
|
|
2257 write_c_string (buf, printcharfun);
|
|
2258 }
|
|
2259
|
|
2260 /* Glyphs are equal if all of their display attributes are equal. We
|
|
2261 don't compare names or doc-strings, because that would make equal
|
|
2262 be eq.
|
|
2263
|
|
2264 This isn't concerned with "unspecified" attributes, that's what
|
|
2265 #'glyph-differs-from-default-p is for. */
|
|
2266 static int
|
|
2267 glyph_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2268 {
|
|
2269 struct Lisp_Glyph *g1 = XGLYPH (o1);
|
|
2270 struct Lisp_Glyph *g2 = XGLYPH (o2);
|
|
2271
|
|
2272 depth++;
|
|
2273
|
185
|
2274 return (internal_equal (g1->image, g2->image, depth) &&
|
|
2275 internal_equal (g1->contrib_p, g2->contrib_p, depth) &&
|
|
2276 internal_equal (g1->baseline, g2->baseline, depth) &&
|
|
2277 internal_equal (g1->face, g2->face, depth) &&
|
|
2278 !plists_differ (g1->plist, g2->plist, 0, 0, depth + 1));
|
0
|
2279 }
|
|
2280
|
|
2281 static unsigned long
|
|
2282 glyph_hash (Lisp_Object obj, int depth)
|
|
2283 {
|
|
2284 depth++;
|
|
2285
|
|
2286 /* No need to hash all of the elements; that would take too long.
|
|
2287 Just hash the most common ones. */
|
185
|
2288 return HASH2 (internal_hash (XGLYPH (obj)->image, depth),
|
|
2289 internal_hash (XGLYPH (obj)->face, depth));
|
0
|
2290 }
|
|
2291
|
|
2292 static Lisp_Object
|
|
2293 glyph_getprop (Lisp_Object obj, Lisp_Object prop)
|
|
2294 {
|
|
2295 struct Lisp_Glyph *g = XGLYPH (obj);
|
272
|
2296
|
185
|
2297 if (EQ (prop, Qimage)) return g->image;
|
|
2298 if (EQ (prop, Qcontrib_p)) return g->contrib_p;
|
|
2299 if (EQ (prop, Qbaseline)) return g->baseline;
|
|
2300 if (EQ (prop, Qface)) return g->face;
|
0
|
2301
|
|
2302 return external_plist_get (&g->plist, prop, 0, ERROR_ME);
|
|
2303 }
|
|
2304
|
|
2305 static int
|
|
2306 glyph_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
|
|
2307 {
|
185
|
2308 if ((EQ (prop, Qimage)) ||
|
|
2309 (EQ (prop, Qcontrib_p)) ||
|
|
2310 (EQ (prop, Qbaseline)))
|
|
2311 return 0;
|
0
|
2312
|
|
2313 if (EQ (prop, Qface))
|
|
2314 {
|
185
|
2315 XGLYPH (obj)->face = Fget_face (value);
|
0
|
2316 return 1;
|
|
2317 }
|
|
2318
|
185
|
2319 external_plist_put (&XGLYPH (obj)->plist, prop, value, 0, ERROR_ME);
|
0
|
2320 return 1;
|
|
2321 }
|
|
2322
|
|
2323 static int
|
|
2324 glyph_remprop (Lisp_Object obj, Lisp_Object prop)
|
|
2325 {
|
185
|
2326 if ((EQ (prop, Qimage)) ||
|
|
2327 (EQ (prop, Qcontrib_p)) ||
|
|
2328 (EQ (prop, Qbaseline)))
|
|
2329 return -1;
|
0
|
2330
|
|
2331 if (EQ (prop, Qface))
|
|
2332 {
|
185
|
2333 XGLYPH (obj)->face = Qnil;
|
0
|
2334 return 1;
|
|
2335 }
|
|
2336
|
185
|
2337 return external_remprop (&XGLYPH (obj)->plist, prop, 0, ERROR_ME);
|
0
|
2338 }
|
|
2339
|
|
2340 static Lisp_Object
|
|
2341 glyph_plist (Lisp_Object obj)
|
|
2342 {
|
272
|
2343 struct Lisp_Glyph *glyph = XGLYPH (obj);
|
|
2344 Lisp_Object result = glyph->plist;
|
|
2345
|
|
2346 result = cons3 (Qface, glyph->face, result);
|
|
2347 result = cons3 (Qbaseline, glyph->baseline, result);
|
|
2348 result = cons3 (Qcontrib_p, glyph->contrib_p, result);
|
|
2349 result = cons3 (Qimage, glyph->image, result);
|
|
2350
|
|
2351 return result;
|
0
|
2352 }
|
|
2353
|
272
|
2354 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("glyph", glyph,
|
|
2355 mark_glyph, print_glyph, 0,
|
|
2356 glyph_equal, glyph_hash,
|
|
2357 glyph_getprop, glyph_putprop,
|
|
2358 glyph_remprop, glyph_plist,
|
|
2359 struct Lisp_Glyph);
|
|
2360
|
0
|
2361 Lisp_Object
|
|
2362 allocate_glyph (enum glyph_type type,
|
|
2363 void (*after_change) (Lisp_Object glyph, Lisp_Object property,
|
|
2364 Lisp_Object locale))
|
|
2365 {
|
249
|
2366 /* This function can GC */
|
0
|
2367 Lisp_Object obj = Qnil;
|
|
2368 struct Lisp_Glyph *g =
|
185
|
2369 alloc_lcrecord_type (struct Lisp_Glyph, lrecord_glyph);
|
173
|
2370
|
0
|
2371 g->type = type;
|
249
|
2372 g->image = Fmake_specifier (Qimage); /* This function can GC */
|
0
|
2373 switch (g->type)
|
|
2374 {
|
|
2375 case GLYPH_BUFFER:
|
|
2376 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2377 IMAGE_NOTHING_MASK | IMAGE_TEXT_MASK | IMAGE_MONO_PIXMAP_MASK |
|
|
2378 IMAGE_COLOR_PIXMAP_MASK | IMAGE_SUBWINDOW_MASK;
|
|
2379 break;
|
|
2380 case GLYPH_POINTER:
|
|
2381 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2382 IMAGE_NOTHING_MASK | IMAGE_POINTER_MASK;
|
|
2383 break;
|
|
2384 case GLYPH_ICON:
|
|
2385 XIMAGE_SPECIFIER_ALLOWED (g->image) =
|
|
2386 IMAGE_NOTHING_MASK | IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
2387 break;
|
|
2388 default:
|
|
2389 abort ();
|
|
2390 }
|
|
2391
|
249
|
2392 /* I think Fmake_specifier can GC. I think set_specifier_fallback can GC. */
|
|
2393 /* We're getting enough reports of odd behavior in this area it seems */
|
|
2394 /* best to GCPRO everything. */
|
|
2395 {
|
|
2396 Lisp_Object tem1 = list1 (Fcons (Qnil, Vthe_nothing_vector));
|
|
2397 Lisp_Object tem2 = list1 (Fcons (Qnil, Qt));
|
|
2398 Lisp_Object tem3 = list1 (Fcons (Qnil, Qnil));
|
|
2399 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2400
|
|
2401 GCPRO4 (obj, tem1, tem2, tem3);
|
|
2402
|
|
2403 set_specifier_fallback (g->image, tem1);
|
|
2404 g->contrib_p = Fmake_specifier (Qboolean);
|
|
2405 set_specifier_fallback (g->contrib_p, tem2);
|
|
2406 /* #### should have a specifier for the following */
|
|
2407 g->baseline = Fmake_specifier (Qgeneric);
|
|
2408 set_specifier_fallback (g->baseline, tem3);
|
|
2409 g->face = Qnil;
|
|
2410 g->plist = Qnil;
|
|
2411 g->after_change = after_change;
|
|
2412 XSETGLYPH (obj, g);
|
|
2413
|
|
2414 set_image_attached_to (g->image, obj, Qimage);
|
|
2415 UNGCPRO;
|
|
2416 }
|
0
|
2417
|
|
2418 return obj;
|
|
2419 }
|
|
2420
|
|
2421 static enum glyph_type
|
|
2422 decode_glyph_type (Lisp_Object type, Error_behavior errb)
|
|
2423 {
|
|
2424 if (NILP (type))
|
|
2425 return GLYPH_BUFFER;
|
|
2426
|
|
2427 if (ERRB_EQ (errb, ERROR_ME))
|
|
2428 CHECK_SYMBOL (type);
|
|
2429
|
185
|
2430 if (EQ (type, Qbuffer)) return GLYPH_BUFFER;
|
|
2431 if (EQ (type, Qpointer)) return GLYPH_POINTER;
|
|
2432 if (EQ (type, Qicon)) return GLYPH_ICON;
|
0
|
2433
|
|
2434 maybe_signal_simple_error ("Invalid glyph type", type, Qimage, errb);
|
185
|
2435
|
0
|
2436 return GLYPH_UNKNOWN;
|
|
2437 }
|
|
2438
|
|
2439 static int
|
|
2440 valid_glyph_type_p (Lisp_Object type)
|
|
2441 {
|
185
|
2442 return !NILP (memq_no_quit (type, Vglyph_type_list));
|
0
|
2443 }
|
|
2444
|
20
|
2445 DEFUN ("valid-glyph-type-p", Fvalid_glyph_type_p, 1, 1, 0, /*
|
0
|
2446 Given a GLYPH-TYPE, return non-nil if it is valid.
|
|
2447 Valid types are `buffer', `pointer', and `icon'.
|
20
|
2448 */
|
|
2449 (glyph_type))
|
0
|
2450 {
|
185
|
2451 return valid_glyph_type_p (glyph_type) ? Qt : Qnil;
|
0
|
2452 }
|
|
2453
|
20
|
2454 DEFUN ("glyph-type-list", Fglyph_type_list, 0, 0, 0, /*
|
0
|
2455 Return a list of valid glyph types.
|
20
|
2456 */
|
|
2457 ())
|
0
|
2458 {
|
|
2459 return Fcopy_sequence (Vglyph_type_list);
|
|
2460 }
|
|
2461
|
20
|
2462 DEFUN ("make-glyph-internal", Fmake_glyph_internal, 0, 1, 0, /*
|
272
|
2463 Create and return a new uninitialized glyph or type TYPE.
|
0
|
2464
|
|
2465 TYPE specifies the type of the glyph; this should be one of `buffer',
|
|
2466 `pointer', or `icon', and defaults to `buffer'. The type of the glyph
|
|
2467 specifies in which contexts the glyph can be used, and controls the
|
|
2468 allowable image types into which the glyph's image can be
|
|
2469 instantiated.
|
|
2470
|
|
2471 `buffer' glyphs can be used as the begin-glyph or end-glyph of an
|
|
2472 extent, in the modeline, and in the toolbar. Their image can be
|
|
2473 instantiated as `nothing', `mono-pixmap', `color-pixmap', `text',
|
|
2474 and `subwindow'.
|
|
2475
|
|
2476 `pointer' glyphs can be used to specify the mouse pointer. Their
|
|
2477 image can be instantiated as `pointer'.
|
|
2478
|
|
2479 `icon' glyphs can be used to specify the icon used when a frame is
|
|
2480 iconified. Their image can be instantiated as `mono-pixmap' and
|
|
2481 `color-pixmap'.
|
20
|
2482 */
|
|
2483 (type))
|
0
|
2484 {
|
|
2485 enum glyph_type typeval = decode_glyph_type (type, ERROR_ME);
|
|
2486 return allocate_glyph (typeval, 0);
|
|
2487 }
|
|
2488
|
20
|
2489 DEFUN ("glyphp", Fglyphp, 1, 1, 0, /*
|
0
|
2490 Return non-nil if OBJECT is a glyph.
|
|
2491
|
|
2492 A glyph is an object used for pixmaps and the like. It is used
|
|
2493 in begin-glyphs and end-glyphs attached to extents, in marginal and textual
|
|
2494 annotations, in overlay arrows (overlay-arrow-* variables), in toolbar
|
|
2495 buttons, and the like. Its image is described using an image specifier --
|
|
2496 see `image-specifier-p'.
|
20
|
2497 */
|
|
2498 (object))
|
0
|
2499 {
|
|
2500 return GLYPHP (object) ? Qt : Qnil;
|
|
2501 }
|
|
2502
|
20
|
2503 DEFUN ("glyph-type", Fglyph_type, 1, 1, 0, /*
|
0
|
2504 Return the type of the given glyph.
|
|
2505 The return value will be one of 'buffer, 'pointer, or 'icon.
|
20
|
2506 */
|
|
2507 (glyph))
|
0
|
2508 {
|
|
2509 CHECK_GLYPH (glyph);
|
|
2510 switch (XGLYPH_TYPE (glyph))
|
|
2511 {
|
185
|
2512 case GLYPH_BUFFER: return Qbuffer;
|
|
2513 case GLYPH_POINTER: return Qpointer;
|
|
2514 case GLYPH_ICON: return Qicon;
|
0
|
2515 default:
|
|
2516 abort ();
|
185
|
2517 return Qnil; /* not reached */
|
0
|
2518 }
|
|
2519 }
|
|
2520
|
|
2521 /*****************************************************************************
|
|
2522 glyph_width
|
|
2523
|
|
2524 Return the width of the given GLYPH on the given WINDOW. If the
|
|
2525 instance is a string then the width is calculated using the font of
|
|
2526 the given FACE, unless a face is defined by the glyph itself.
|
|
2527 ****************************************************************************/
|
|
2528 unsigned short
|
|
2529 glyph_width (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2530 face_index window_findex, Lisp_Object window)
|
|
2531 {
|
|
2532 Lisp_Object instance;
|
|
2533 Lisp_Object frame = XWINDOW (window)->frame;
|
|
2534
|
|
2535 /* #### We somehow need to distinguish between the user causing this
|
|
2536 error condition and a bug causing it. */
|
|
2537 if (!GLYPHP (glyph))
|
|
2538 return 0;
|
|
2539 else
|
|
2540 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
|
|
2541
|
|
2542 if (!IMAGE_INSTANCEP (instance))
|
|
2543 return 0;
|
|
2544
|
|
2545 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
2546 {
|
|
2547 case IMAGE_TEXT:
|
|
2548 {
|
|
2549 Lisp_Object str = XIMAGE_INSTANCE_TEXT_STRING (instance);
|
|
2550 Lisp_Object private_face = XGLYPH_FACE(glyph);
|
|
2551
|
|
2552 if (!NILP (private_face))
|
173
|
2553 return redisplay_frame_text_width_string (XFRAME (frame),
|
|
2554 private_face,
|
|
2555 0, str, 0, -1);
|
0
|
2556 else
|
|
2557 if (!NILP (frame_face))
|
173
|
2558 return redisplay_frame_text_width_string (XFRAME (frame),
|
|
2559 frame_face,
|
|
2560 0, str, 0, -1);
|
0
|
2561 else
|
173
|
2562 return redisplay_text_width_string (XWINDOW (window),
|
|
2563 window_findex,
|
|
2564 0, str, 0, -1);
|
0
|
2565 }
|
|
2566
|
|
2567 case IMAGE_MONO_PIXMAP:
|
|
2568 case IMAGE_COLOR_PIXMAP:
|
|
2569 case IMAGE_POINTER:
|
|
2570 return XIMAGE_INSTANCE_PIXMAP_WIDTH (instance);
|
|
2571
|
|
2572 case IMAGE_NOTHING:
|
|
2573 return 0;
|
|
2574
|
|
2575 case IMAGE_SUBWINDOW:
|
|
2576 /* #### implement me */
|
|
2577 return 0;
|
|
2578
|
|
2579 default:
|
|
2580 abort ();
|
|
2581 return 0;
|
|
2582 }
|
|
2583 }
|
|
2584
|
20
|
2585 DEFUN ("glyph-width", Fglyph_width, 1, 2, 0, /*
|
0
|
2586 Return the width of GLYPH on WINDOW.
|
|
2587 This may not be exact as it does not take into account all of the context
|
|
2588 that redisplay will.
|
20
|
2589 */
|
|
2590 (glyph, window))
|
0
|
2591 {
|
|
2592 XSETWINDOW (window, decode_window (window));
|
|
2593 CHECK_GLYPH (glyph);
|
|
2594
|
173
|
2595 return make_int (glyph_width (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2596 }
|
|
2597
|
|
2598 #define RETURN_ASCENT 0
|
|
2599 #define RETURN_DESCENT 1
|
|
2600 #define RETURN_HEIGHT 2
|
|
2601
|
|
2602 Lisp_Object
|
|
2603 glyph_image_instance (Lisp_Object glyph, Lisp_Object domain,
|
|
2604 Error_behavior errb, int no_quit)
|
|
2605 {
|
|
2606 Lisp_Object specifier = GLYPH_IMAGE (XGLYPH (glyph));
|
|
2607
|
|
2608 /* This can never return Qunbound. All glyphs have 'nothing as
|
|
2609 a fallback. */
|
|
2610 return specifier_instance (specifier, Qunbound, domain, errb, no_quit, 0,
|
|
2611 Qzero);
|
|
2612 }
|
|
2613
|
|
2614 static unsigned short
|
|
2615 glyph_height_internal (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2616 face_index window_findex, Lisp_Object window,
|
|
2617 int function)
|
|
2618 {
|
|
2619 Lisp_Object instance;
|
|
2620 Lisp_Object frame = XWINDOW (window)->frame;
|
|
2621
|
|
2622 if (!GLYPHP (glyph))
|
|
2623 return 0;
|
|
2624 else
|
|
2625 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
|
|
2626
|
|
2627 if (!IMAGE_INSTANCEP (instance))
|
|
2628 return 0;
|
|
2629
|
|
2630 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
2631 {
|
|
2632 case IMAGE_TEXT:
|
|
2633 {
|
|
2634 struct font_metric_info fm;
|
|
2635 Lisp_Object string = XIMAGE_INSTANCE_TEXT_STRING (instance);
|
|
2636 unsigned char charsets[NUM_LEADING_BYTES];
|
|
2637 struct face_cachel frame_cachel;
|
|
2638 struct face_cachel *cachel;
|
|
2639
|
|
2640 find_charsets_in_bufbyte_string (charsets,
|
82
|
2641 XSTRING_DATA (string),
|
14
|
2642 XSTRING_LENGTH (string));
|
0
|
2643
|
|
2644 if (!NILP (frame_face))
|
|
2645 {
|
|
2646 reset_face_cachel (&frame_cachel);
|
|
2647 update_face_cachel_data (&frame_cachel, frame, frame_face);
|
|
2648 cachel = &frame_cachel;
|
|
2649 }
|
|
2650 else
|
|
2651 cachel = WINDOW_FACE_CACHEL (XWINDOW (window), window_findex);
|
|
2652 ensure_face_cachel_complete (cachel, window, charsets);
|
|
2653
|
|
2654 face_cachel_charset_font_metric_info (cachel, charsets, &fm);
|
173
|
2655
|
185
|
2656 switch (function)
|
|
2657 {
|
|
2658 case RETURN_ASCENT: return fm.ascent;
|
|
2659 case RETURN_DESCENT: return fm.descent;
|
|
2660 case RETURN_HEIGHT: return fm.ascent + fm.descent;
|
|
2661 default:
|
|
2662 abort ();
|
|
2663 return 0; /* not reached */
|
|
2664 }
|
0
|
2665 }
|
|
2666
|
|
2667 case IMAGE_MONO_PIXMAP:
|
|
2668 case IMAGE_COLOR_PIXMAP:
|
|
2669 case IMAGE_POINTER:
|
|
2670 /* #### Ugh ugh ugh -- temporary crap */
|
|
2671 if (function == RETURN_ASCENT || function == RETURN_HEIGHT)
|
|
2672 return XIMAGE_INSTANCE_PIXMAP_HEIGHT (instance);
|
|
2673 else
|
|
2674 return 0;
|
|
2675
|
|
2676 case IMAGE_NOTHING:
|
|
2677 return 0;
|
|
2678
|
|
2679 case IMAGE_SUBWINDOW:
|
|
2680 /* #### implement me */
|
|
2681 return 0;
|
|
2682
|
|
2683 default:
|
|
2684 abort ();
|
|
2685 return 0;
|
|
2686 }
|
|
2687 }
|
|
2688
|
|
2689 unsigned short
|
|
2690 glyph_ascent (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2691 face_index window_findex, Lisp_Object window)
|
|
2692 {
|
|
2693 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2694 RETURN_ASCENT);
|
|
2695 }
|
|
2696
|
|
2697 unsigned short
|
|
2698 glyph_descent (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2699 face_index window_findex, Lisp_Object window)
|
|
2700 {
|
|
2701 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2702 RETURN_DESCENT);
|
|
2703 }
|
|
2704
|
|
2705 /* strictly a convenience function. */
|
|
2706 unsigned short
|
|
2707 glyph_height (Lisp_Object glyph, Lisp_Object frame_face,
|
|
2708 face_index window_findex, Lisp_Object window)
|
|
2709 {
|
|
2710 return glyph_height_internal (glyph, frame_face, window_findex, window,
|
|
2711 RETURN_HEIGHT);
|
|
2712 }
|
|
2713
|
20
|
2714 DEFUN ("glyph-ascent", Fglyph_ascent, 1, 2, 0, /*
|
0
|
2715 Return the ascent value of GLYPH on WINDOW.
|
|
2716 This may not be exact as it does not take into account all of the context
|
|
2717 that redisplay will.
|
20
|
2718 */
|
|
2719 (glyph, window))
|
0
|
2720 {
|
|
2721 XSETWINDOW (window, decode_window (window));
|
|
2722 CHECK_GLYPH (glyph);
|
|
2723
|
173
|
2724 return make_int (glyph_ascent (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2725 }
|
|
2726
|
20
|
2727 DEFUN ("glyph-descent", Fglyph_descent, 1, 2, 0, /*
|
0
|
2728 Return the descent value of GLYPH on WINDOW.
|
|
2729 This may not be exact as it does not take into account all of the context
|
|
2730 that redisplay will.
|
20
|
2731 */
|
|
2732 (glyph, window))
|
0
|
2733 {
|
|
2734 XSETWINDOW (window, decode_window (window));
|
|
2735 CHECK_GLYPH (glyph);
|
|
2736
|
173
|
2737 return make_int (glyph_descent (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2738 }
|
|
2739
|
|
2740 /* This is redundant but I bet a lot of people expect it to exist. */
|
20
|
2741 DEFUN ("glyph-height", Fglyph_height, 1, 2, 0, /*
|
0
|
2742 Return the height of GLYPH on WINDOW.
|
|
2743 This may not be exact as it does not take into account all of the context
|
|
2744 that redisplay will.
|
20
|
2745 */
|
|
2746 (glyph, window))
|
0
|
2747 {
|
|
2748 XSETWINDOW (window, decode_window (window));
|
|
2749 CHECK_GLYPH (glyph);
|
|
2750
|
173
|
2751 return make_int (glyph_height (glyph, Qnil, DEFAULT_INDEX, window));
|
0
|
2752 }
|
|
2753
|
|
2754 #undef RETURN_ASCENT
|
|
2755 #undef RETURN_DESCENT
|
|
2756 #undef RETURN_HEIGHT
|
|
2757
|
|
2758 /* #### do we need to cache this info to speed things up? */
|
|
2759
|
|
2760 Lisp_Object
|
|
2761 glyph_baseline (Lisp_Object glyph, Lisp_Object domain)
|
|
2762 {
|
|
2763 if (!GLYPHP (glyph))
|
|
2764 return Qnil;
|
|
2765 else
|
|
2766 {
|
|
2767 Lisp_Object retval =
|
|
2768 specifier_instance_no_quit (GLYPH_BASELINE (XGLYPH (glyph)),
|
|
2769 /* #### look into ERROR_ME_NOT */
|
|
2770 Qunbound, domain, ERROR_ME_NOT,
|
|
2771 0, Qzero);
|
|
2772 if (!NILP (retval) && !INTP (retval))
|
|
2773 retval = Qnil;
|
|
2774 else if (INTP (retval))
|
|
2775 {
|
|
2776 if (XINT (retval) < 0)
|
|
2777 retval = Qzero;
|
|
2778 if (XINT (retval) > 100)
|
|
2779 retval = make_int (100);
|
|
2780 }
|
|
2781 return retval;
|
|
2782 }
|
|
2783 }
|
|
2784
|
|
2785 Lisp_Object
|
|
2786 glyph_face (Lisp_Object glyph, Lisp_Object domain)
|
|
2787 {
|
|
2788 /* #### Domain parameter not currently used but it will be */
|
185
|
2789 return GLYPHP (glyph) ? GLYPH_FACE (XGLYPH (glyph)) : Qnil;
|
0
|
2790 }
|
|
2791
|
|
2792 int
|
|
2793 glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain)
|
|
2794 {
|
|
2795 if (!GLYPHP (glyph))
|
|
2796 return 0;
|
|
2797 else
|
173
|
2798 return !NILP (specifier_instance_no_quit
|
|
2799 (GLYPH_CONTRIB_P (XGLYPH (glyph)), Qunbound, domain,
|
|
2800 /* #### look into ERROR_ME_NOT */
|
|
2801 ERROR_ME_NOT, 0, Qzero));
|
0
|
2802 }
|
|
2803
|
|
2804 static void
|
|
2805 glyph_property_was_changed (Lisp_Object glyph, Lisp_Object property,
|
|
2806 Lisp_Object locale)
|
|
2807 {
|
|
2808 if (XGLYPH (glyph)->after_change)
|
|
2809 (XGLYPH (glyph)->after_change) (glyph, property, locale);
|
|
2810 }
|
|
2811
|
|
2812
|
|
2813 /*****************************************************************************
|
|
2814 * glyph cachel functions *
|
|
2815 *****************************************************************************/
|
|
2816
|
|
2817 /*
|
|
2818 #### All of this is 95% copied from face cachels.
|
|
2819 Consider consolidating.
|
|
2820 #### We need to add a dirty flag to the glyphs.
|
|
2821 */
|
|
2822
|
|
2823 void
|
|
2824 mark_glyph_cachels (glyph_cachel_dynarr *elements,
|
|
2825 void (*markobj) (Lisp_Object))
|
|
2826 {
|
|
2827 int elt;
|
|
2828
|
|
2829 if (!elements)
|
|
2830 return;
|
|
2831
|
|
2832 for (elt = 0; elt < Dynarr_length (elements); elt++)
|
|
2833 {
|
|
2834 struct glyph_cachel *cachel = Dynarr_atp (elements, elt);
|
|
2835 ((markobj) (cachel->glyph));
|
|
2836 }
|
|
2837 }
|
|
2838
|
|
2839 static void
|
|
2840 update_glyph_cachel_data (struct window *w, Lisp_Object glyph,
|
|
2841 struct glyph_cachel *cachel)
|
|
2842 {
|
|
2843 /* #### This should be || !cachel->updated */
|
|
2844 if (NILP (cachel->glyph) || !EQ (cachel->glyph, glyph))
|
|
2845 {
|
272
|
2846 Lisp_Object window;
|
0
|
2847
|
|
2848 XSETWINDOW (window, w);
|
|
2849
|
|
2850 /* #### This could be sped up if we redid things to grab the glyph
|
|
2851 instantiation and passed it to the size functions. */
|
185
|
2852 cachel->glyph = glyph;
|
|
2853 cachel->width = glyph_width (glyph, Qnil, DEFAULT_INDEX, window);
|
|
2854 cachel->ascent = glyph_ascent (glyph, Qnil, DEFAULT_INDEX, window);
|
|
2855 cachel->descent = glyph_descent (glyph, Qnil, DEFAULT_INDEX, window);
|
0
|
2856 }
|
|
2857
|
|
2858 cachel->updated = 1;
|
|
2859 }
|
|
2860
|
|
2861 static void
|
|
2862 add_glyph_cachel (struct window *w, Lisp_Object glyph)
|
|
2863 {
|
|
2864 struct glyph_cachel new_cachel;
|
|
2865
|
272
|
2866 xzero (new_cachel);
|
0
|
2867 new_cachel.glyph = Qnil;
|
|
2868
|
|
2869 update_glyph_cachel_data (w, glyph, &new_cachel);
|
|
2870 Dynarr_add (w->glyph_cachels, new_cachel);
|
|
2871 }
|
|
2872
|
|
2873 static glyph_index
|
|
2874 get_glyph_cachel_index (struct window *w, Lisp_Object glyph)
|
|
2875 {
|
|
2876 int elt;
|
|
2877
|
|
2878 if (noninteractive)
|
|
2879 return 0;
|
|
2880
|
|
2881 for (elt = 0; elt < Dynarr_length (w->glyph_cachels); elt++)
|
|
2882 {
|
|
2883 struct glyph_cachel *cachel =
|
|
2884 Dynarr_atp (w->glyph_cachels, elt);
|
|
2885
|
|
2886 if (EQ (cachel->glyph, glyph) && !NILP (glyph))
|
|
2887 {
|
|
2888 if (!cachel->updated)
|
|
2889 update_glyph_cachel_data (w, glyph, cachel);
|
|
2890 return elt;
|
|
2891 }
|
|
2892 }
|
|
2893
|
|
2894 /* If we didn't find the glyph, add it and then return its index. */
|
|
2895 add_glyph_cachel (w, glyph);
|
|
2896 return elt;
|
|
2897 }
|
|
2898
|
|
2899 void
|
|
2900 reset_glyph_cachels (struct window *w)
|
|
2901 {
|
|
2902 Dynarr_reset (w->glyph_cachels);
|
|
2903 get_glyph_cachel_index (w, Vcontinuation_glyph);
|
|
2904 get_glyph_cachel_index (w, Vtruncation_glyph);
|
|
2905 get_glyph_cachel_index (w, Vhscroll_glyph);
|
|
2906 get_glyph_cachel_index (w, Vcontrol_arrow_glyph);
|
|
2907 get_glyph_cachel_index (w, Voctal_escape_glyph);
|
|
2908 get_glyph_cachel_index (w, Vinvisible_text_glyph);
|
|
2909 }
|
|
2910
|
|
2911 void
|
|
2912 mark_glyph_cachels_as_not_updated (struct window *w)
|
|
2913 {
|
|
2914 int elt;
|
|
2915
|
|
2916 /* We need to have a dirty flag to tell if the glyph has changed.
|
|
2917 We can check to see if each glyph variable is actually a
|
|
2918 completely different glyph, though. */
|
|
2919 #define FROB(glyph_obj, gindex) \
|
|
2920 update_glyph_cachel_data (w, glyph_obj, \
|
|
2921 Dynarr_atp (w->glyph_cachels, gindex))
|
|
2922
|
|
2923 FROB (Vcontinuation_glyph, CONT_GLYPH_INDEX);
|
|
2924 FROB (Vtruncation_glyph, TRUN_GLYPH_INDEX);
|
|
2925 FROB (Vhscroll_glyph, HSCROLL_GLYPH_INDEX);
|
|
2926 FROB (Vcontrol_arrow_glyph, CONTROL_GLYPH_INDEX);
|
|
2927 FROB (Voctal_escape_glyph, OCT_ESC_GLYPH_INDEX);
|
|
2928 FROB (Vinvisible_text_glyph, INVIS_GLYPH_INDEX);
|
|
2929 #undef FROB
|
|
2930
|
|
2931 for (elt = 0; elt < Dynarr_length (w->glyph_cachels); elt++)
|
|
2932 Dynarr_atp (w->glyph_cachels, elt)->updated = 0;
|
|
2933 }
|
|
2934
|
|
2935 #ifdef MEMORY_USAGE_STATS
|
|
2936
|
|
2937 int
|
|
2938 compute_glyph_cachel_usage (glyph_cachel_dynarr *glyph_cachels,
|
|
2939 struct overhead_stats *ovstats)
|
|
2940 {
|
|
2941 int total = 0;
|
|
2942
|
|
2943 if (glyph_cachels)
|
|
2944 total += Dynarr_memory_usage (glyph_cachels, ovstats);
|
|
2945
|
|
2946 return total;
|
|
2947 }
|
|
2948
|
|
2949 #endif /* MEMORY_USAGE_STATS */
|
|
2950
|
|
2951
|
|
2952 /*****************************************************************************
|
|
2953 * display tables *
|
|
2954 *****************************************************************************/
|
|
2955
|
|
2956 /* Get the display table for use currently on window W with face FACE.
|
|
2957 Precedence:
|
|
2958
|
|
2959 -- FACE's display table
|
|
2960 -- W's display table (comes from specifier `current-display-table')
|
|
2961
|
|
2962 Ignore the specified tables if they are not valid;
|
|
2963 if no valid table is specified, return 0. */
|
|
2964
|
|
2965 struct Lisp_Vector *
|
|
2966 get_display_table (struct window *w, face_index findex)
|
|
2967 {
|
272
|
2968 Lisp_Object tem;
|
0
|
2969
|
|
2970 tem = WINDOW_FACE_CACHEL_DISPLAY_TABLE (w, findex);
|
173
|
2971 if (VECTORP (tem) && XVECTOR_LENGTH (tem) == DISP_TABLE_SIZE)
|
0
|
2972 return XVECTOR (tem);
|
|
2973
|
|
2974 tem = w->display_table;
|
173
|
2975 if (VECTORP (tem) && XVECTOR_LENGTH (tem) == DISP_TABLE_SIZE)
|
0
|
2976 return XVECTOR (tem);
|
|
2977
|
|
2978 return 0;
|
|
2979 }
|
|
2980
|
|
2981
|
|
2982 /*****************************************************************************
|
|
2983 * initialization *
|
|
2984 *****************************************************************************/
|
|
2985
|
|
2986 void
|
|
2987 syms_of_glyphs (void)
|
|
2988 {
|
|
2989 /* image instantiators */
|
|
2990
|
20
|
2991 DEFSUBR (Fimage_instantiator_format_list);
|
|
2992 DEFSUBR (Fvalid_image_instantiator_format_p);
|
|
2993 DEFSUBR (Fset_console_type_image_conversion_list);
|
|
2994 DEFSUBR (Fconsole_type_image_conversion_list);
|
0
|
2995
|
|
2996 defkeyword (&Q_file, ":file");
|
|
2997 defkeyword (&Q_data, ":data");
|
|
2998 defkeyword (&Q_face, ":face");
|
|
2999
|
276
|
3000 #ifdef HAVE_XPM
|
|
3001 defkeyword (&Q_color_symbols, ":color-symbols");
|
|
3002 #endif
|
|
3003
|
0
|
3004 /* image specifiers */
|
|
3005
|
20
|
3006 DEFSUBR (Fimage_specifier_p);
|
0
|
3007 /* Qimage in general.c */
|
|
3008
|
|
3009 /* image instances */
|
|
3010
|
|
3011 defsymbol (&Qimage_instancep, "image-instance-p");
|
|
3012
|
|
3013 defsymbol (&Qnothing_image_instance_p, "nothing-image-instance-p");
|
|
3014 defsymbol (&Qtext_image_instance_p, "text-image-instance-p");
|
|
3015 defsymbol (&Qmono_pixmap_image_instance_p, "mono-pixmap-image-instance-p");
|
|
3016 defsymbol (&Qcolor_pixmap_image_instance_p, "color-pixmap-image-instance-p");
|
|
3017 defsymbol (&Qpointer_image_instance_p, "pointer-image-instance-p");
|
|
3018 defsymbol (&Qsubwindow_image_instance_p, "subwindow-image-instance-p");
|
|
3019
|
20
|
3020 DEFSUBR (Fmake_image_instance);
|
|
3021 DEFSUBR (Fimage_instance_p);
|
|
3022 DEFSUBR (Fimage_instance_type);
|
|
3023 DEFSUBR (Fvalid_image_instance_type_p);
|
|
3024 DEFSUBR (Fimage_instance_type_list);
|
|
3025 DEFSUBR (Fimage_instance_name);
|
|
3026 DEFSUBR (Fimage_instance_string);
|
|
3027 DEFSUBR (Fimage_instance_file_name);
|
|
3028 DEFSUBR (Fimage_instance_mask_file_name);
|
|
3029 DEFSUBR (Fimage_instance_depth);
|
|
3030 DEFSUBR (Fimage_instance_height);
|
|
3031 DEFSUBR (Fimage_instance_width);
|
|
3032 DEFSUBR (Fimage_instance_hotspot_x);
|
|
3033 DEFSUBR (Fimage_instance_hotspot_y);
|
|
3034 DEFSUBR (Fimage_instance_foreground);
|
|
3035 DEFSUBR (Fimage_instance_background);
|
|
3036 DEFSUBR (Fcolorize_image_instance);
|
0
|
3037
|
|
3038 /* Qnothing defined as part of the "nothing" image-instantiator
|
|
3039 type. */
|
|
3040 /* Qtext defined in general.c */
|
|
3041 defsymbol (&Qmono_pixmap, "mono-pixmap");
|
|
3042 defsymbol (&Qcolor_pixmap, "color-pixmap");
|
|
3043 /* Qpointer defined in general.c */
|
|
3044 defsymbol (&Qsubwindow, "subwindow");
|
|
3045
|
|
3046 /* glyphs */
|
|
3047
|
|
3048 defsymbol (&Qglyphp, "glyphp");
|
|
3049 defsymbol (&Qcontrib_p, "contrib-p");
|
|
3050 defsymbol (&Qbaseline, "baseline");
|
|
3051
|
|
3052 defsymbol (&Qbuffer_glyph_p, "buffer-glyph-p");
|
|
3053 defsymbol (&Qpointer_glyph_p, "pointer-glyph-p");
|
|
3054 defsymbol (&Qicon_glyph_p, "icon-glyph-p");
|
|
3055
|
|
3056 defsymbol (&Qconst_glyph_variable, "const-glyph-variable");
|
|
3057
|
20
|
3058 DEFSUBR (Fglyph_type);
|
|
3059 DEFSUBR (Fvalid_glyph_type_p);
|
|
3060 DEFSUBR (Fglyph_type_list);
|
|
3061 DEFSUBR (Fglyphp);
|
|
3062 DEFSUBR (Fmake_glyph_internal);
|
|
3063 DEFSUBR (Fglyph_width);
|
|
3064 DEFSUBR (Fglyph_ascent);
|
|
3065 DEFSUBR (Fglyph_descent);
|
|
3066 DEFSUBR (Fglyph_height);
|
0
|
3067
|
|
3068 /* Qbuffer defined in general.c. */
|
|
3069 /* Qpointer defined above */
|
|
3070 defsymbol (&Qicon, "icon");
|
269
|
3071
|
|
3072 /* Errors */
|
|
3073 deferror (&Qimage_conversion_error,
|
|
3074 "image-conversion-error",
|
|
3075 "image-conversion error", Qio_error);
|
|
3076
|
0
|
3077 }
|
|
3078
|
|
3079 void
|
|
3080 specifier_type_create_image (void)
|
|
3081 {
|
|
3082 /* image specifiers */
|
|
3083
|
|
3084 INITIALIZE_SPECIFIER_TYPE_WITH_DATA (image, "image", "imagep");
|
|
3085
|
|
3086 SPECIFIER_HAS_METHOD (image, create);
|
|
3087 SPECIFIER_HAS_METHOD (image, mark);
|
|
3088 SPECIFIER_HAS_METHOD (image, instantiate);
|
|
3089 SPECIFIER_HAS_METHOD (image, validate);
|
|
3090 SPECIFIER_HAS_METHOD (image, after_change);
|
|
3091 SPECIFIER_HAS_METHOD (image, going_to_add);
|
|
3092 }
|
|
3093
|
|
3094 void
|
|
3095 image_instantiator_format_create (void)
|
|
3096 {
|
|
3097 /* image instantiators */
|
|
3098
|
|
3099 the_image_instantiator_format_entry_dynarr =
|
185
|
3100 Dynarr_new (image_instantiator_format_entry);
|
0
|
3101
|
|
3102 Vimage_instantiator_format_list = Qnil;
|
|
3103 staticpro (&Vimage_instantiator_format_list);
|
|
3104
|
|
3105 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (nothing, "nothing");
|
|
3106
|
|
3107 IIFORMAT_HAS_METHOD (nothing, possible_dest_types);
|
|
3108 IIFORMAT_HAS_METHOD (nothing, instantiate);
|
|
3109
|
|
3110 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (inherit, "inherit");
|
|
3111
|
|
3112 IIFORMAT_HAS_METHOD (inherit, validate);
|
|
3113 IIFORMAT_HAS_METHOD (inherit, normalize);
|
|
3114 IIFORMAT_HAS_METHOD (inherit, possible_dest_types);
|
|
3115 IIFORMAT_HAS_METHOD (inherit, instantiate);
|
|
3116
|
|
3117 IIFORMAT_VALID_KEYWORD (inherit, Q_face, check_valid_face);
|
|
3118
|
|
3119 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (string, "string");
|
|
3120
|
|
3121 IIFORMAT_HAS_METHOD (string, validate);
|
|
3122 IIFORMAT_HAS_METHOD (string, possible_dest_types);
|
|
3123 IIFORMAT_HAS_METHOD (string, instantiate);
|
|
3124
|
|
3125 IIFORMAT_VALID_KEYWORD (string, Q_data, check_valid_string);
|
|
3126
|
|
3127 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (formatted_string, "formatted-string");
|
|
3128
|
|
3129 IIFORMAT_HAS_METHOD (formatted_string, validate);
|
|
3130 IIFORMAT_HAS_METHOD (formatted_string, possible_dest_types);
|
|
3131 IIFORMAT_HAS_METHOD (formatted_string, instantiate);
|
|
3132
|
|
3133 IIFORMAT_VALID_KEYWORD (formatted_string, Q_data, check_valid_string);
|
276
|
3134
|
|
3135 #ifdef HAVE_XPM
|
|
3136 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
|
|
3137
|
|
3138 IIFORMAT_HAS_METHOD (xpm, validate);
|
|
3139 IIFORMAT_HAS_METHOD (xpm, normalize);
|
|
3140 IIFORMAT_HAS_METHOD (xpm, possible_dest_types);
|
|
3141 IIFORMAT_HAS_METHOD (xpm, instantiate);
|
|
3142
|
|
3143 IIFORMAT_VALID_KEYWORD (xpm, Q_data, check_valid_string);
|
|
3144 IIFORMAT_VALID_KEYWORD (xpm, Q_file, check_valid_string);
|
|
3145 IIFORMAT_VALID_KEYWORD (xpm, Q_color_symbols, check_valid_xpm_color_symbols);
|
284
|
3146 #endif /* HAVE_XPM */
|
0
|
3147 }
|
|
3148
|
|
3149 void
|
|
3150 vars_of_glyphs (void)
|
|
3151 {
|
|
3152 Vthe_nothing_vector = vector1 (Qnothing);
|
|
3153 staticpro (&Vthe_nothing_vector);
|
|
3154
|
|
3155 /* image instances */
|
|
3156
|
|
3157 Vimage_instance_type_list = list6 (Qnothing, Qtext, Qmono_pixmap,
|
|
3158 Qcolor_pixmap, Qpointer, Qsubwindow);
|
|
3159 staticpro (&Vimage_instance_type_list);
|
|
3160
|
|
3161 /* glyphs */
|
|
3162
|
|
3163 Vglyph_type_list = list3 (Qbuffer, Qpointer, Qicon);
|
|
3164 staticpro (&Vglyph_type_list);
|
|
3165
|
|
3166 /* The octal-escape glyph, control-arrow-glyph and
|
|
3167 invisible-text-glyph are completely initialized in glyphs.el */
|
|
3168
|
|
3169 DEFVAR_LISP ("octal-escape-glyph", &Voctal_escape_glyph /*
|
|
3170 What to prefix character codes displayed in octal with.
|
|
3171 */);
|
|
3172 Voctal_escape_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3173
|
|
3174 DEFVAR_LISP ("control-arrow-glyph", &Vcontrol_arrow_glyph /*
|
|
3175 What to use as an arrow for control characters.
|
|
3176 */);
|
|
3177 Vcontrol_arrow_glyph = allocate_glyph (GLYPH_BUFFER,
|
|
3178 redisplay_glyph_changed);
|
|
3179
|
|
3180 DEFVAR_LISP ("invisible-text-glyph", &Vinvisible_text_glyph /*
|
|
3181 What to use to indicate the presence of invisible text.
|
|
3182 This is the glyph that is displayed when an ellipsis is called for
|
|
3183 \(see `selective-display-ellipses' and `buffer-invisibility-spec').
|
185
|
3184 Normally this is three dots ("...").
|
0
|
3185 */);
|
|
3186 Vinvisible_text_glyph = allocate_glyph (GLYPH_BUFFER,
|
|
3187 redisplay_glyph_changed);
|
|
3188
|
|
3189 /* Partially initialized in glyphs.el */
|
|
3190 DEFVAR_LISP ("hscroll-glyph", &Vhscroll_glyph /*
|
|
3191 What to display at the beginning of horizontally scrolled lines.
|
|
3192 */);
|
|
3193 Vhscroll_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
276
|
3194
|
|
3195 #ifdef HAVE_XPM
|
|
3196 Fprovide (Qxpm);
|
|
3197
|
|
3198 DEFVAR_LISP ("xpm-color-symbols", &Vxpm_color_symbols /*
|
|
3199 Definitions of logical color-names used when reading XPM files.
|
|
3200 Elements of this list should be of the form (COLOR-NAME FORM-TO-EVALUATE).
|
|
3201 The COLOR-NAME should be a string, which is the name of the color to define;
|
|
3202 the FORM should evaluate to a `color' specifier object, or a string to be
|
|
3203 passed to `make-color-instance'. If a loaded XPM file references a symbolic
|
|
3204 color called COLOR-NAME, it will display as the computed color instead.
|
|
3205
|
|
3206 The default value of this variable defines the logical color names
|
|
3207 \"foreground\" and \"background\" to be the colors of the `default' face.
|
|
3208 */ );
|
|
3209 Vxpm_color_symbols = Qnil; /* initialized in x-faces.el */
|
284
|
3210 #endif /* HAVE_XPM */
|
0
|
3211 }
|
|
3212
|
|
3213 void
|
|
3214 specifier_vars_of_glyphs (void)
|
|
3215 {
|
249
|
3216 /* #### Can we GC here? The set_specifier_* calls definitely need */
|
|
3217 /* protection. */
|
0
|
3218 /* display tables */
|
|
3219
|
|
3220 DEFVAR_SPECIFIER ("current-display-table", &Vcurrent_display_table /*
|
|
3221 *The display table currently in use.
|
|
3222 This is a specifier; use `set-specifier' to change it.
|
|
3223 The display table is a vector created with `make-display-table'.
|
|
3224 The 256 elements control how to display each possible text character.
|
|
3225 Each value should be a string, a glyph, a vector or nil.
|
|
3226 If a value is a vector it must be composed only of strings and glyphs.
|
|
3227 nil means display the character in the default fashion.
|
|
3228 Faces can have their own, overriding display table.
|
|
3229 */ );
|
116
|
3230 Vcurrent_display_table = Fmake_specifier (Qdisplay_table);
|
0
|
3231 set_specifier_fallback (Vcurrent_display_table,
|
|
3232 list1 (Fcons (Qnil, Qnil)));
|
|
3233 set_specifier_caching (Vcurrent_display_table,
|
|
3234 slot_offset (struct window,
|
|
3235 display_table),
|
|
3236 some_window_value_changed,
|
|
3237 0, 0);
|
|
3238 }
|
|
3239
|
|
3240 void
|
|
3241 complex_vars_of_glyphs (void)
|
|
3242 {
|
|
3243 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3244 DEFVAR_LISP ("truncation-glyph", &Vtruncation_glyph /*
|
|
3245 What to display at the end of truncated lines.
|
|
3246 */ );
|
|
3247 Vtruncation_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3248
|
|
3249 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3250 DEFVAR_LISP ("continuation-glyph", &Vcontinuation_glyph /*
|
|
3251 What to display at the end of wrapped lines.
|
|
3252 */ );
|
|
3253 Vcontinuation_glyph = allocate_glyph (GLYPH_BUFFER, redisplay_glyph_changed);
|
|
3254
|
|
3255 /* Partially initialized in glyphs-x.c, glyphs.el */
|
|
3256 DEFVAR_LISP ("xemacs-logo", &Vxemacs_logo /*
|
|
3257 The glyph used to display the XEmacs logo at startup.
|
|
3258 */ );
|
|
3259 Vxemacs_logo = allocate_glyph (GLYPH_BUFFER, 0);
|
|
3260 }
|