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