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