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