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