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