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