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