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