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;
|
122
|
57 /* Declared in faces.c */
|
|
58 extern Lisp_Object Qdisplay_table;
|
0
|
59
|
|
60 Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
|
|
61 Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
|
|
62 Lisp_Object Vxemacs_logo;
|
|
63
|
|
64 Lisp_Object Vthe_nothing_vector;
|
|
65
|
|
66 Lisp_Object Q_file, Q_data, Q_face;
|
|
67
|
|
68 Lisp_Object Qicon;
|
|
69
|
|
70 /* Qnothing, Qstring, Qinherit in general.c */
|
|
71 DEFINE_IMAGE_INSTANTIATOR_FORMAT (nothing);
|
|
72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (inherit);
|
|
73 DEFINE_IMAGE_INSTANTIATOR_FORMAT (string);
|
|
74 DEFINE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
|
|
75 Lisp_Object Qformatted_string;
|
|
76
|
|
77 MAC_DEFINE (struct image_instantiator_methods *, MTiiformat_meth_or_given)
|
|
78
|
|
79 struct image_instantiator_format_entry
|
|
80 {
|
|
81 Lisp_Object symbol;
|
|
82 struct image_instantiator_methods *meths;
|
|
83 };
|
|
84
|
|
85 typedef struct image_instantiator_format_entry_dynarr_type
|
|
86 {
|
|
87 Dynarr_declare (struct image_instantiator_format_entry);
|
|
88 } image_instantiator_format_entry_dynarr;
|
|
89
|
|
90 image_instantiator_format_entry_dynarr *
|
|
91 the_image_instantiator_format_entry_dynarr;
|
|
92
|
|
93 Lisp_Object Vimage_instantiator_format_list;
|
|
94
|
|
95 Lisp_Object Vimage_instance_type_list;
|
|
96
|
|
97 Lisp_Object Vglyph_type_list;
|
|
98
|
|
99 static Lisp_Object allocate_image_instance (Lisp_Object device);
|
|
100 static void image_validate (Lisp_Object instantiator);
|
|
101 static void glyph_property_was_changed (Lisp_Object glyph,
|
|
102 Lisp_Object property,
|
|
103 Lisp_Object locale);
|
|
104
|
|
105
|
|
106 /****************************************************************************
|
|
107 * Image Instantiators *
|
|
108 ****************************************************************************/
|
|
109
|
|
110 static struct image_instantiator_methods *
|
|
111 decode_image_instantiator_format (Lisp_Object format, Error_behavior errb)
|
|
112 {
|
|
113 int i;
|
|
114
|
|
115 if (!SYMBOLP (format))
|
|
116 {
|
|
117 if (ERRB_EQ (errb, ERROR_ME))
|
|
118 CHECK_SYMBOL (format);
|
|
119 return 0;
|
|
120 }
|
|
121
|
|
122 for (i = 0; i < Dynarr_length (the_image_instantiator_format_entry_dynarr);
|
|
123 i++)
|
|
124 {
|
|
125 if (EQ (format,
|
|
126 Dynarr_at (the_image_instantiator_format_entry_dynarr, i).
|
|
127 symbol))
|
|
128 return Dynarr_at (the_image_instantiator_format_entry_dynarr, i).meths;
|
|
129 }
|
|
130
|
|
131 maybe_signal_simple_error ("Invalid image-instantiator format", format,
|
|
132 Qimage, errb);
|
|
133
|
|
134 return 0;
|
|
135 }
|
|
136
|
|
137 static int
|
|
138 valid_image_instantiator_format_p (Lisp_Object format)
|
|
139 {
|
|
140 if (decode_image_instantiator_format (format, ERROR_ME_NOT))
|
|
141 return 1;
|
|
142 return 0;
|
|
143 }
|
|
144
|
20
|
145 DEFUN ("valid-image-instantiator-format-p",
|
|
146 Fvalid_image_instantiator_format_p, 1, 1, 0, /*
|
0
|
147 Given an IMAGE-INSTANTIATOR-FORMAT, return non-nil if it is valid.
|
120
|
148 Valid formats are some subset of 'nothing, 'string, 'formatted-string,
|
|
149 'xpm, 'xbm, 'xface, 'gif, 'jpeg, 'png, 'tiff, 'cursor-font, 'font,
|
122
|
150 'autodetect, and 'subwindow, depending on how XEmacs was
|
120
|
151 compiled.
|
20
|
152 */
|
|
153 (image_instantiator_format))
|
0
|
154 {
|
|
155 if (valid_image_instantiator_format_p (image_instantiator_format))
|
|
156 return Qt;
|
|
157 else
|
|
158 return Qnil;
|
|
159 }
|
|
160
|
20
|
161 DEFUN ("image-instantiator-format-list",
|
|
162 Fimage_instantiator_format_list, 0, 0, 0, /*
|
0
|
163 Return a list of valid image-instantiator formats.
|
20
|
164 */
|
|
165 ())
|
0
|
166 {
|
|
167 return Fcopy_sequence (Vimage_instantiator_format_list);
|
|
168 }
|
|
169
|
|
170 void
|
|
171 add_entry_to_image_instantiator_format_list (Lisp_Object symbol,
|
|
172 struct
|
|
173 image_instantiator_methods *meths)
|
|
174 {
|
|
175 struct image_instantiator_format_entry entry;
|
|
176
|
|
177 entry.symbol = symbol;
|
|
178 entry.meths = meths;
|
|
179 Dynarr_add (the_image_instantiator_format_entry_dynarr, entry);
|
|
180 Vimage_instantiator_format_list =
|
|
181 Fcons (symbol, Vimage_instantiator_format_list);
|
|
182 }
|
|
183
|
|
184 static Lisp_Object *
|
|
185 get_image_conversion_list (Lisp_Object console_type)
|
|
186 {
|
|
187 return &decode_console_type (console_type, ERROR_ME)->image_conversion_list;
|
|
188 }
|
|
189
|
|
190 DEFUN ("set-console-type-image-conversion-list",
|
20
|
191 Fset_console_type_image_conversion_list, 2, 2, 0, /*
|
0
|
192 Set the image-conversion-list for consoles of the given TYPE.
|
|
193 The image-conversion-list specifies how image instantiators that
|
|
194 are strings should be interpreted. Each element of the list should be
|
|
195 a list of two elements (a regular expression string and a vector) or
|
|
196 a list of three elements (the preceding two plus an integer index into
|
|
197 the vector). The string is converted to the vector associated with the
|
|
198 first matching regular expression. If a vector index is specified, the
|
|
199 string itself is substituted into that position in the vector.
|
|
200
|
|
201 Note: The conversion above is applied when the image instantiator is
|
|
202 added to an image specifier, not when the specifier is actually
|
|
203 instantiated. Therefore, changing the image-conversion-list only affects
|
|
204 newly-added instantiators. Existing instantiators in glyphs and image
|
|
205 specifiers will not be affected.
|
20
|
206 */
|
|
207 (console_type, list))
|
0
|
208 {
|
|
209 Lisp_Object tail;
|
|
210 Lisp_Object *imlist = get_image_conversion_list (console_type);
|
|
211
|
|
212 /* Check the list to make sure that it only has valid entries. */
|
|
213
|
|
214 EXTERNAL_LIST_LOOP (tail, list)
|
|
215 {
|
|
216 Lisp_Object mapping = XCAR (tail);
|
|
217
|
|
218 /* Mapping form should be (STRING VECTOR) or (STRING VECTOR INTEGER) */
|
|
219 if (!CONSP (mapping) ||
|
|
220 !CONSP (XCDR (mapping)) ||
|
|
221 (!NILP (XCDR (XCDR (mapping))) &&
|
|
222 (!CONSP (XCDR (XCDR (mapping))) ||
|
|
223 !NILP (XCDR (XCDR (XCDR (mapping)))))))
|
|
224 signal_simple_error ("Invalid mapping form", mapping);
|
|
225 else
|
|
226 {
|
|
227 Lisp_Object exp = XCAR (mapping);
|
|
228 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
229 Lisp_Object pos = Qnil;
|
|
230 Lisp_Object newvec;
|
|
231 struct gcpro gcpro1;
|
|
232
|
|
233 CHECK_STRING (exp);
|
|
234 CHECK_VECTOR (typevec);
|
|
235 if (!NILP (XCDR (XCDR (mapping))))
|
|
236 {
|
|
237 pos = XCAR (XCDR (XCDR (mapping)));
|
|
238 CHECK_INT (pos);
|
|
239 if (XINT (pos) < 0 ||
|
|
240 XINT (pos) >= vector_length (XVECTOR (typevec)))
|
|
241 args_out_of_range_3
|
|
242 (pos, Qzero, make_int
|
|
243 (vector_length (XVECTOR (typevec)) - 1));
|
|
244 }
|
|
245
|
|
246 newvec = Fcopy_sequence (typevec);
|
|
247 if (INTP (pos))
|
|
248 vector_data (XVECTOR (newvec))[XINT (pos)] = exp;
|
|
249 GCPRO1 (newvec);
|
|
250 image_validate (newvec);
|
|
251 UNGCPRO;
|
|
252 }
|
|
253 }
|
|
254
|
|
255 *imlist = Fcopy_tree (list, Qt);
|
|
256 return list;
|
|
257 }
|
|
258
|
|
259 DEFUN ("console-type-image-conversion-list",
|
20
|
260 Fconsole_type_image_conversion_list, 1, 1, 0, /*
|
0
|
261 Return the image-conversion-list for devices of the given TYPE.
|
|
262 The image-conversion-list specifies how to interpret image string
|
|
263 instantiators for the specified console type. See
|
|
264 `set-console-type-image-conversion-list' for a description of its syntax.
|
20
|
265 */
|
|
266 (console_type))
|
0
|
267 {
|
|
268 return Fcopy_tree (*get_image_conversion_list (console_type), Qt);
|
|
269 }
|
|
270
|
|
271 /* Process an string instantiator according to the image-conversion-list for
|
|
272 CONSOLE_TYPE. Returns a vector. */
|
|
273
|
|
274 static Lisp_Object
|
|
275 process_image_string_instantiator (Lisp_Object data,
|
|
276 Lisp_Object console_type,
|
|
277 int dest_mask)
|
|
278 {
|
|
279 Lisp_Object tail;
|
|
280
|
|
281 LIST_LOOP (tail, *get_image_conversion_list (console_type))
|
|
282 {
|
|
283 Lisp_Object mapping = XCAR (tail);
|
|
284 Lisp_Object exp = XCAR (mapping);
|
|
285 Lisp_Object typevec = XCAR (XCDR (mapping));
|
|
286
|
|
287 /* if the result is of a type that can't be instantiated
|
|
288 (e.g. a string when we're dealing with a pointer glyph),
|
|
289 skip it. */
|
|
290 if (!(dest_mask &
|
|
291 IIFORMAT_METH (decode_image_instantiator_format
|
|
292 (vector_data (XVECTOR (typevec))[0], ERROR_ME),
|
|
293 possible_dest_types, ())))
|
|
294 continue;
|
|
295 if (fast_string_match (exp, 0, data, 0, -1, 0, ERROR_ME, 0) >= 0)
|
|
296 {
|
|
297 if (!NILP (XCDR (XCDR (mapping))))
|
|
298 {
|
|
299 int pos = XINT (XCAR (XCDR (XCDR (mapping))));
|
|
300 Lisp_Object newvec = Fcopy_sequence (typevec);
|
|
301 vector_data (XVECTOR (newvec))[pos] = data;
|
|
302 return newvec;
|
|
303 }
|
|
304 else
|
|
305 return typevec;
|
|
306 }
|
|
307 }
|
|
308
|
|
309 /* Oh well. */
|
|
310 signal_simple_error ("Unable to interpret glyph instantiator",
|
|
311 data);
|
|
312
|
|
313 return Qnil;
|
|
314 }
|
|
315
|
|
316 Lisp_Object
|
|
317 find_keyword_in_vector_or_given (Lisp_Object vector, Lisp_Object keyword,
|
|
318 Lisp_Object defalt)
|
|
319 {
|
|
320 Lisp_Object *elt;
|
|
321 int instantiator_len;
|
|
322
|
|
323 elt = vector_data (XVECTOR (vector));
|
|
324 instantiator_len = vector_length (XVECTOR (vector));
|
|
325
|
|
326 elt++;
|
|
327 instantiator_len--;
|
|
328
|
|
329 while (instantiator_len > 0)
|
|
330 {
|
|
331 if (EQ (elt[0], keyword))
|
|
332 return elt[1];
|
|
333 elt += 2;
|
|
334 instantiator_len -= 2;
|
|
335 }
|
|
336
|
|
337 return defalt;
|
|
338 }
|
|
339
|
|
340 Lisp_Object
|
|
341 find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword)
|
|
342 {
|
|
343 return find_keyword_in_vector_or_given (vector, keyword, Qnil);
|
|
344 }
|
|
345
|
|
346 void
|
|
347 check_valid_string (Lisp_Object data)
|
|
348 {
|
|
349 CHECK_STRING (data);
|
|
350 }
|
|
351
|
|
352 static void
|
|
353 check_valid_face (Lisp_Object data)
|
|
354 {
|
|
355 Fget_face (data);
|
|
356 }
|
|
357
|
|
358 void
|
|
359 check_valid_int (Lisp_Object data)
|
|
360 {
|
|
361 CHECK_INT (data);
|
|
362 }
|
|
363
|
|
364 void
|
|
365 file_or_data_must_be_present (Lisp_Object instantiator)
|
|
366 {
|
|
367 if (NILP (find_keyword_in_vector (instantiator, Q_file)) &&
|
|
368 NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
369 signal_simple_error ("Must supply either :file or :data",
|
|
370 instantiator);
|
|
371 }
|
|
372
|
|
373 void
|
|
374 data_must_be_present (Lisp_Object instantiator)
|
|
375 {
|
|
376 if (NILP (find_keyword_in_vector (instantiator, Q_data)))
|
|
377 signal_simple_error ("Must supply :data", instantiator);
|
|
378 }
|
|
379
|
|
380 static void
|
|
381 face_must_be_present (Lisp_Object instantiator)
|
|
382 {
|
|
383 if (NILP (find_keyword_in_vector (instantiator, Q_face)))
|
|
384 signal_simple_error ("Must supply :face", instantiator);
|
|
385 }
|
|
386
|
|
387 /* utility function useful in retrieving data from a file. */
|
|
388
|
|
389 Lisp_Object
|
|
390 make_string_from_file (Lisp_Object file)
|
|
391 {
|
116
|
392 /* This function can call lisp */
|
0
|
393 int count = specpdl_depth ();
|
|
394 Lisp_Object temp_buffer;
|
|
395 struct gcpro gcpro1;
|
|
396 Lisp_Object data;
|
|
397
|
|
398 specbind (Qinhibit_quit, Qt);
|
|
399 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
400 temp_buffer = Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
401 GCPRO1 (temp_buffer);
|
|
402 set_buffer_internal (XBUFFER (temp_buffer));
|
|
403 Ferase_buffer (Fcurrent_buffer ());
|
70
|
404 Finsert_file_contents_internal (file, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
|
0
|
405 data = Fbuffer_substring (Qnil, Qnil, Fcurrent_buffer ());
|
|
406 unbind_to (count, Qnil);
|
|
407 UNGCPRO;
|
|
408 return data;
|
|
409 }
|
|
410
|
|
411 /* The following two functions are provided to make it easier for
|
|
412 the normalize methods to work with keyword-value vectors.
|
|
413 Hash tables are kind of heavyweight for this purpose.
|
|
414 (If vectors were resizable, we could avoid this problem;
|
|
415 but they're not.) An alternative approach that might be
|
|
416 more efficient but require more work is to use a type of
|
|
417 assoc-Dynarr and provide primitives for deleting elements out
|
|
418 of it. (However, you'd also have to add an unwind-protect
|
|
419 to make sure the Dynarr got freed in case of an error in
|
|
420 the normalization process.) */
|
|
421
|
|
422 Lisp_Object
|
|
423 tagged_vector_to_alist (Lisp_Object vector)
|
|
424 {
|
|
425 Lisp_Object *elt = vector_data (XVECTOR (vector));
|
|
426 int len = vector_length (XVECTOR (vector));
|
|
427 Lisp_Object result = Qnil;
|
|
428
|
|
429 assert (len & 1);
|
|
430 for (len -= 2; len >= 1; len -= 2)
|
|
431 result = Fcons (Fcons (elt[len], elt[len+1]), result);
|
|
432
|
|
433 return result;
|
|
434 }
|
|
435
|
|
436 Lisp_Object
|
|
437 alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist)
|
|
438 {
|
|
439 int len = 1 + 2 * XINT (Flength (alist));
|
|
440 Lisp_Object *elt = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
|
|
441 int i;
|
|
442 Lisp_Object rest;
|
|
443
|
|
444 i = 0;
|
|
445 elt[i++] = tag;
|
|
446 LIST_LOOP (rest, alist)
|
|
447 {
|
|
448 Lisp_Object pair = XCAR (rest);
|
|
449 elt[i] = XCAR (pair);
|
|
450 elt[i+1] = XCDR (pair);
|
|
451 i += 2;
|
|
452 }
|
|
453
|
|
454 return Fvector (len, elt);
|
|
455 }
|
|
456
|
|
457 static Lisp_Object
|
|
458 normalize_image_instantiator (Lisp_Object instantiator,
|
|
459 Lisp_Object contype,
|
|
460 Lisp_Object dest_mask)
|
|
461 {
|
|
462 if (IMAGE_INSTANCEP (instantiator))
|
|
463 return instantiator;
|
|
464
|
|
465 if (STRINGP (instantiator))
|
|
466 instantiator = process_image_string_instantiator (instantiator, contype,
|
|
467 XINT (dest_mask));
|
|
468
|
|
469 assert (VECTORP (instantiator));
|
|
470 /* We have to always store the actual pixmap data and not the
|
|
471 filename even though this is a potential memory pig. We have to
|
|
472 do this because it is quite possible that we will need to
|
|
473 instantiate a new instance of the pixmap and the file will no
|
|
474 longer exist (e.g. w3 pixmaps are almost always from temporary
|
|
475 files). */
|
|
476 instantiator = IIFORMAT_METH_OR_GIVEN
|
|
477 (decode_image_instantiator_format
|
|
478 (vector_data (XVECTOR (instantiator))[0], ERROR_ME),
|
|
479 normalize, (instantiator, contype), instantiator);
|
|
480
|
|
481 return instantiator;
|
|
482 }
|
|
483
|
|
484 static Lisp_Object
|
70
|
485 instantiate_image_instantiator (Lisp_Object device, Lisp_Object instantiator,
|
0
|
486 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
487 int dest_mask)
|
|
488 {
|
|
489 Lisp_Object ii;
|
|
490 struct gcpro gcpro1;
|
|
491
|
|
492 ii = allocate_image_instance (device);
|
|
493
|
|
494 GCPRO1 (ii);
|
|
495 {
|
|
496 struct image_instantiator_methods *meths =
|
|
497 decode_image_instantiator_format
|
|
498 (vector_data (XVECTOR (instantiator))[0], ERROR_ME);
|
|
499
|
|
500 if (!HAS_IIFORMAT_METH_P (meths, instantiate))
|
|
501 signal_simple_error
|
|
502 ("Don't know how to instantiate this image instantiator?",
|
|
503 instantiator);
|
|
504 IIFORMAT_METH (meths, instantiate, (ii, instantiator, pointer_fg,
|
70
|
505 pointer_bg, dest_mask));
|
0
|
506 }
|
|
507 UNGCPRO;
|
|
508
|
|
509 return ii;
|
|
510 }
|
|
511
|
|
512
|
|
513 /****************************************************************************
|
|
514 * Image-Instance Object *
|
|
515 ****************************************************************************/
|
|
516
|
|
517 Lisp_Object Qimage_instancep;
|
|
518 static Lisp_Object mark_image_instance (Lisp_Object, void (*) (Lisp_Object));
|
|
519 static void print_image_instance (Lisp_Object, Lisp_Object, int);
|
|
520 static void finalize_image_instance (void *, int);
|
|
521 static int image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth);
|
|
522 static unsigned long image_instance_hash (Lisp_Object obj, int depth);
|
|
523 DEFINE_LRECORD_IMPLEMENTATION ("image-instance", image_instance,
|
|
524 mark_image_instance, print_image_instance,
|
|
525 finalize_image_instance, image_instance_equal,
|
|
526 image_instance_hash,
|
|
527 struct Lisp_Image_Instance);
|
|
528 static Lisp_Object
|
|
529 mark_image_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
530 {
|
|
531 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
532
|
|
533 (markobj) (i->name);
|
|
534 switch (IMAGE_INSTANCE_TYPE (i))
|
|
535 {
|
|
536 case IMAGE_TEXT:
|
|
537 (markobj) (IMAGE_INSTANCE_TEXT_STRING (i));
|
|
538 break;
|
|
539 case IMAGE_MONO_PIXMAP:
|
|
540 case IMAGE_COLOR_PIXMAP:
|
|
541 (markobj) (IMAGE_INSTANCE_PIXMAP_FILENAME (i));
|
|
542 (markobj) (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i));
|
|
543 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i));
|
|
544 (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i));
|
|
545 (markobj) (IMAGE_INSTANCE_PIXMAP_FG (i));
|
|
546 (markobj) (IMAGE_INSTANCE_PIXMAP_BG (i));
|
|
547 break;
|
|
548 case IMAGE_SUBWINDOW:
|
|
549 /* #### implement me */
|
|
550 break;
|
|
551 default:
|
|
552 break;
|
|
553 }
|
|
554
|
|
555 MAYBE_DEVMETH (XDEVICE (i->device), mark_image_instance, (i, markobj));
|
|
556
|
|
557 return (i->device);
|
|
558 }
|
|
559
|
|
560 static void
|
|
561 print_image_instance (Lisp_Object obj, Lisp_Object printcharfun,
|
|
562 int escapeflag)
|
|
563 {
|
|
564 char buf[100];
|
|
565 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (obj);
|
|
566
|
|
567 if (print_readably)
|
|
568 error ("printing unreadable object #<image-instance 0x%x>",
|
|
569 ii->header.uid);
|
|
570 write_c_string ("#<image-instance (", printcharfun);
|
|
571 print_internal (Fimage_instance_type (obj), printcharfun, 0);
|
|
572 write_c_string (") ", printcharfun);
|
|
573 if (!NILP (ii->name))
|
|
574 {
|
|
575 print_internal (ii->name, printcharfun, 1);
|
|
576 write_c_string (" ", printcharfun);
|
|
577 }
|
|
578 write_c_string ("on ", printcharfun);
|
|
579 print_internal (ii->device, printcharfun, 0);
|
|
580 write_c_string (" ", printcharfun);
|
|
581 switch (IMAGE_INSTANCE_TYPE (ii))
|
|
582 {
|
|
583 case IMAGE_NOTHING:
|
|
584 break;
|
|
585
|
|
586 case IMAGE_TEXT:
|
|
587 print_internal (IMAGE_INSTANCE_TEXT_STRING (ii), printcharfun, 1);
|
|
588 break;
|
|
589
|
|
590 case IMAGE_MONO_PIXMAP:
|
|
591 case IMAGE_COLOR_PIXMAP:
|
|
592 case IMAGE_POINTER:
|
|
593 if (STRINGP (IMAGE_INSTANCE_PIXMAP_FILENAME (ii)))
|
|
594 {
|
|
595 char *s;
|
|
596 Lisp_Object filename = IMAGE_INSTANCE_PIXMAP_FILENAME (ii);
|
14
|
597 s = strrchr ((char *) XSTRING_DATA (filename), '/');
|
0
|
598 if (s)
|
|
599 print_internal (build_string (s + 1), printcharfun, 1);
|
|
600 else
|
|
601 print_internal (filename, printcharfun, 1);
|
|
602 }
|
|
603 if (IMAGE_INSTANCE_PIXMAP_DEPTH (ii) > 1)
|
|
604 sprintf (buf, " %dx%dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
605 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
|
|
606 IMAGE_INSTANCE_PIXMAP_DEPTH (ii));
|
|
607 else
|
|
608 sprintf (buf, " %dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
|
|
609 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii));
|
|
610 write_c_string (buf, printcharfun);
|
|
611 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ||
|
|
612 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
613 {
|
|
614 write_c_string (" @", printcharfun);
|
|
615 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
|
|
616 {
|
|
617 sprintf (buf, "%d", XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
|
|
618 write_c_string (buf, printcharfun);
|
|
619 }
|
|
620 else
|
|
621 write_c_string ("??", printcharfun);
|
|
622 write_c_string (",", printcharfun);
|
|
623 if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
|
|
624 {
|
|
625 sprintf (buf, "%d", XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
|
|
626 write_c_string (buf, printcharfun);
|
|
627 }
|
|
628 else
|
|
629 write_c_string ("??", printcharfun);
|
|
630 }
|
|
631 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)) ||
|
|
632 !NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
633 {
|
|
634 write_c_string (" (", printcharfun);
|
|
635 if (!NILP (IMAGE_INSTANCE_PIXMAP_FG (ii)))
|
|
636 {
|
|
637 print_internal
|
|
638 (XCOLOR_INSTANCE
|
|
639 (IMAGE_INSTANCE_PIXMAP_FG (ii))->name, printcharfun, 0);
|
|
640 }
|
|
641 write_c_string ("/", printcharfun);
|
|
642 if (!NILP (IMAGE_INSTANCE_PIXMAP_BG (ii)))
|
|
643 {
|
|
644 print_internal
|
|
645 (XCOLOR_INSTANCE
|
|
646 (IMAGE_INSTANCE_PIXMAP_BG (ii))->name, printcharfun, 0);
|
|
647 }
|
|
648 write_c_string (")", printcharfun);
|
|
649 }
|
|
650 break;
|
|
651
|
|
652 case IMAGE_SUBWINDOW:
|
|
653 /* #### implement me */
|
|
654 break;
|
|
655
|
|
656 default:
|
|
657 abort ();
|
|
658 }
|
|
659
|
|
660 MAYBE_DEVMETH (XDEVICE (ii->device), print_image_instance,
|
|
661 (ii, printcharfun, escapeflag));
|
|
662 sprintf (buf, " 0x%x>", ii->header.uid);
|
|
663 write_c_string (buf, printcharfun);
|
|
664 }
|
|
665
|
|
666 static void
|
|
667 finalize_image_instance (void *header, int for_disksave)
|
|
668 {
|
|
669 struct Lisp_Image_Instance *i = (struct Lisp_Image_Instance *) header;
|
|
670
|
|
671 if (IMAGE_INSTANCE_TYPE (i) == IMAGE_NOTHING)
|
|
672 /* objects like this exist at dump time, so don't bomb out. */
|
|
673 return;
|
|
674 if (for_disksave) finalose (i);
|
|
675
|
|
676 MAYBE_DEVMETH (XDEVICE (i->device), finalize_image_instance, (i));
|
|
677 }
|
|
678
|
|
679 static int
|
|
680 image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
681 {
|
|
682 struct Lisp_Image_Instance *i1 = XIMAGE_INSTANCE (o1);
|
|
683 struct Lisp_Image_Instance *i2 = XIMAGE_INSTANCE (o2);
|
|
684 struct device *d1 = XDEVICE (i1->device);
|
|
685 struct device *d2 = XDEVICE (i2->device);
|
|
686
|
|
687 if (d1 != d2)
|
|
688 return 0;
|
|
689 if (IMAGE_INSTANCE_TYPE (i1) != IMAGE_INSTANCE_TYPE (i2))
|
|
690 return 0;
|
|
691 if (!internal_equal (IMAGE_INSTANCE_NAME (i1), IMAGE_INSTANCE_NAME (i2),
|
|
692 depth + 1))
|
|
693 return 0;
|
|
694
|
|
695 switch (IMAGE_INSTANCE_TYPE (i1))
|
|
696 {
|
|
697 case IMAGE_NOTHING:
|
|
698 break;
|
|
699
|
|
700 case IMAGE_TEXT:
|
|
701 if (!internal_equal (IMAGE_INSTANCE_TEXT_STRING (i1),
|
|
702 IMAGE_INSTANCE_TEXT_STRING (i2),
|
|
703 depth + 1))
|
|
704 return 0;
|
|
705 break;
|
|
706
|
|
707 case IMAGE_MONO_PIXMAP:
|
|
708 case IMAGE_COLOR_PIXMAP:
|
|
709 case IMAGE_POINTER:
|
|
710 if (!(IMAGE_INSTANCE_PIXMAP_WIDTH (i1) ==
|
|
711 IMAGE_INSTANCE_PIXMAP_WIDTH (i2) &&
|
|
712 IMAGE_INSTANCE_PIXMAP_HEIGHT (i1) ==
|
|
713 IMAGE_INSTANCE_PIXMAP_HEIGHT (i2) &&
|
|
714 IMAGE_INSTANCE_PIXMAP_DEPTH (i1) ==
|
|
715 IMAGE_INSTANCE_PIXMAP_DEPTH (i2) &&
|
|
716 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i1),
|
|
717 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i2)) &&
|
|
718 EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i1),
|
|
719 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i2)) &&
|
|
720 internal_equal (IMAGE_INSTANCE_PIXMAP_FILENAME (i1),
|
|
721 IMAGE_INSTANCE_PIXMAP_FILENAME (i2),
|
|
722 depth + 1) &&
|
|
723 internal_equal (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i1),
|
|
724 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i2),
|
|
725 depth + 1)))
|
|
726 return 0;
|
|
727 break;
|
|
728
|
|
729 case IMAGE_SUBWINDOW:
|
|
730 /* #### implement me */
|
|
731 break;
|
|
732
|
|
733 default:
|
|
734 abort ();
|
|
735 }
|
|
736
|
|
737 return DEVMETH_OR_GIVEN (d1, image_instance_equal, (i1, i2, depth), 1);
|
|
738 }
|
|
739
|
|
740 static unsigned long
|
|
741 image_instance_hash (Lisp_Object obj, int depth)
|
|
742 {
|
|
743 struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
|
|
744 struct device *d = XDEVICE (i->device);
|
|
745 unsigned long hash = (unsigned long) d;
|
|
746
|
|
747 switch (IMAGE_INSTANCE_TYPE (i))
|
|
748 {
|
|
749 case IMAGE_NOTHING:
|
|
750 break;
|
|
751
|
|
752 case IMAGE_TEXT:
|
|
753 hash = HASH2 (hash, internal_hash (IMAGE_INSTANCE_TEXT_STRING (i),
|
|
754 depth + 1));
|
|
755 break;
|
|
756
|
|
757 case IMAGE_MONO_PIXMAP:
|
|
758 case IMAGE_COLOR_PIXMAP:
|
|
759 case IMAGE_POINTER:
|
|
760 hash = HASH5 (hash, IMAGE_INSTANCE_PIXMAP_WIDTH (i),
|
|
761 IMAGE_INSTANCE_PIXMAP_HEIGHT (i),
|
|
762 IMAGE_INSTANCE_PIXMAP_DEPTH (i),
|
|
763 internal_hash (IMAGE_INSTANCE_PIXMAP_FILENAME (i),
|
|
764 depth + 1));
|
|
765 break;
|
|
766
|
|
767 case IMAGE_SUBWINDOW:
|
|
768 /* #### implement me */
|
|
769 break;
|
|
770
|
|
771 default:
|
|
772 abort ();
|
|
773 }
|
|
774
|
|
775 return HASH2 (hash, DEVMETH_OR_GIVEN (d, image_instance_hash, (i, depth),
|
|
776 0));
|
|
777 }
|
|
778
|
|
779 static Lisp_Object
|
|
780 allocate_image_instance (Lisp_Object device)
|
|
781 {
|
|
782 struct Lisp_Image_Instance *lp =
|
|
783 alloc_lcrecord (sizeof (struct Lisp_Image_Instance),
|
|
784 lrecord_image_instance);
|
|
785 Lisp_Object val = Qnil;
|
|
786
|
|
787 zero_lcrecord (lp);
|
|
788 lp->device = device;
|
|
789 lp->type = IMAGE_NOTHING;
|
|
790 lp->name = Qnil;
|
|
791 XSETIMAGE_INSTANCE (val, lp);
|
|
792 return val;
|
|
793 }
|
|
794
|
|
795 static enum image_instance_type
|
|
796 decode_image_instance_type (Lisp_Object type, Error_behavior errb)
|
|
797 {
|
|
798 if (ERRB_EQ (errb, ERROR_ME))
|
|
799 CHECK_SYMBOL (type);
|
|
800
|
|
801 if (EQ (type, Qnothing))
|
|
802 return IMAGE_NOTHING;
|
|
803 if (EQ (type, Qtext))
|
|
804 return IMAGE_TEXT;
|
|
805 if (EQ (type, Qmono_pixmap))
|
|
806 return IMAGE_MONO_PIXMAP;
|
|
807 if (EQ (type, Qcolor_pixmap))
|
|
808 return IMAGE_COLOR_PIXMAP;
|
|
809 if (EQ (type, Qpointer))
|
|
810 return IMAGE_POINTER;
|
|
811 if (EQ (type, Qsubwindow))
|
|
812 return IMAGE_SUBWINDOW;
|
|
813
|
|
814 maybe_signal_simple_error ("Invalid image-instance type", type,
|
|
815 Qimage, errb);
|
|
816 return IMAGE_UNKNOWN;
|
|
817 }
|
|
818
|
|
819 static Lisp_Object
|
|
820 encode_image_instance_type (enum image_instance_type type)
|
|
821 {
|
|
822 switch (type)
|
|
823 {
|
|
824 case IMAGE_NOTHING:
|
|
825 return Qnothing;
|
|
826 case IMAGE_TEXT:
|
|
827 return Qtext;
|
|
828 case IMAGE_MONO_PIXMAP:
|
|
829 return Qmono_pixmap;
|
|
830 case IMAGE_COLOR_PIXMAP:
|
|
831 return Qcolor_pixmap;
|
|
832 case IMAGE_POINTER:
|
|
833 return Qpointer;
|
|
834 case IMAGE_SUBWINDOW:
|
|
835 return Qsubwindow;
|
|
836 default:
|
|
837 abort ();
|
|
838 }
|
|
839
|
|
840 return Qnil; /* not reached */
|
|
841 }
|
|
842
|
|
843 static int
|
|
844 image_instance_type_to_mask (enum image_instance_type type)
|
|
845 {
|
|
846 /* This depends on the fact that enums are assigned consecutive
|
|
847 integers starting at 0. (Remember that IMAGE_UNKNOWN is the
|
|
848 first enum.) I'm fairly sure this behavior in ANSI-mandated,
|
|
849 so there should be no portability problems here. */
|
|
850 return (1 << ((int) (type) - 1));
|
|
851 }
|
|
852
|
|
853 static int
|
|
854 decode_image_instance_type_list (Lisp_Object list)
|
|
855 {
|
|
856 Lisp_Object rest;
|
|
857 int mask = 0;
|
|
858
|
|
859 if (NILP (list))
|
|
860 return ~0;
|
|
861
|
|
862 if (!CONSP (list))
|
|
863 {
|
|
864 enum image_instance_type type =
|
|
865 decode_image_instance_type (list, ERROR_ME);
|
|
866 return image_instance_type_to_mask (type);
|
|
867 }
|
|
868
|
|
869 EXTERNAL_LIST_LOOP (rest, list)
|
|
870 {
|
|
871 enum image_instance_type type =
|
|
872 decode_image_instance_type (XCAR (rest), ERROR_ME);
|
|
873 mask |= image_instance_type_to_mask (type);
|
|
874 }
|
|
875
|
|
876 return mask;
|
|
877 }
|
|
878
|
|
879 static Lisp_Object
|
|
880 encode_image_instance_type_list (int mask)
|
|
881 {
|
|
882 int count = 0;
|
|
883 Lisp_Object result = Qnil;
|
|
884
|
|
885 while (mask)
|
|
886 {
|
|
887 count++;
|
|
888 if (mask & 1)
|
|
889 result = Fcons (encode_image_instance_type
|
|
890 ((enum image_instance_type) count), result);
|
|
891 mask >>= 1;
|
|
892 }
|
|
893
|
|
894 return Fnreverse (result);
|
|
895 }
|
|
896
|
|
897 DOESNT_RETURN
|
|
898 incompatible_image_types (Lisp_Object instantiator, int given_dest_mask,
|
|
899 int desired_dest_mask)
|
|
900 {
|
|
901 signal_error
|
|
902 (Qerror,
|
|
903 list2
|
|
904 (emacs_doprnt_string_lisp_2
|
|
905 ((CONST Bufbyte *)
|
|
906 "No compatible image-instance types given: wanted one of %s, got %s",
|
|
907 Qnil, -1, 2,
|
|
908 encode_image_instance_type_list (desired_dest_mask),
|
|
909 encode_image_instance_type_list (given_dest_mask)),
|
|
910 instantiator));
|
|
911 }
|
|
912
|
|
913 static int
|
|
914 valid_image_instance_type_p (Lisp_Object type)
|
|
915 {
|
|
916 if (!NILP (memq_no_quit (type, Vimage_instance_type_list)))
|
|
917 return 1;
|
|
918 return 0;
|
|
919 }
|
|
920
|
20
|
921 DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p, 1, 1, 0, /*
|
0
|
922 Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid.
|
|
923 Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap,
|
|
924 'pointer, and 'subwindow, depending on how XEmacs was compiled.
|
20
|
925 */
|
|
926 (image_instance_type))
|
0
|
927 {
|
|
928 if (valid_image_instance_type_p (image_instance_type))
|
|
929 return Qt;
|
|
930 else
|
|
931 return Qnil;
|
|
932 }
|
|
933
|
20
|
934 DEFUN ("image-instance-type-list", Fimage_instance_type_list, 0, 0, 0, /*
|
0
|
935 Return a list of valid image-instance types.
|
20
|
936 */
|
|
937 ())
|
0
|
938 {
|
|
939 return Fcopy_sequence (Vimage_instance_type_list);
|
|
940 }
|
|
941
|
|
942 Error_behavior
|
|
943 decode_error_behavior_flag (Lisp_Object no_error)
|
|
944 {
|
|
945 if (NILP (no_error))
|
|
946 return ERROR_ME;
|
|
947 else if (EQ (no_error, Qt))
|
|
948 return ERROR_ME_NOT;
|
|
949 else
|
|
950 return ERROR_ME_WARN;
|
|
951 }
|
|
952
|
|
953 Lisp_Object
|
|
954 encode_error_behavior_flag (Error_behavior errb)
|
|
955 {
|
|
956 if (ERRB_EQ (errb, ERROR_ME))
|
|
957 return Qnil;
|
|
958 else if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
959 return Qt;
|
|
960 else
|
|
961 {
|
|
962 assert (ERRB_EQ (errb, ERROR_ME_WARN));
|
|
963 return Qwarning;
|
|
964 }
|
|
965 }
|
|
966
|
|
967 static Lisp_Object
|
|
968 make_image_instance_1 (Lisp_Object data, Lisp_Object device,
|
|
969 Lisp_Object dest_types)
|
|
970 {
|
|
971 Lisp_Object ii;
|
|
972 struct gcpro gcpro1;
|
|
973 int dest_mask;
|
|
974
|
|
975 XSETDEVICE (device, decode_device (device));
|
|
976 /* instantiate_image_instantiator() will abort if given an
|
|
977 image instance ... */
|
|
978 if (IMAGE_INSTANCEP (data))
|
|
979 signal_simple_error ("image instances not allowed here", data);
|
|
980 image_validate (data);
|
|
981 dest_mask = decode_image_instance_type_list (dest_types);
|
|
982 data = normalize_image_instantiator (data, DEVICE_TYPE (XDEVICE (device)),
|
|
983 make_int (dest_mask));
|
|
984 GCPRO1 (data);
|
|
985 if (VECTORP (data)
|
|
986 && EQ (vector_data (XVECTOR (data))[0], Qinherit))
|
|
987 signal_simple_error ("inheritance not allowed here", data);
|
70
|
988 ii = instantiate_image_instantiator (device, data, Qnil, Qnil, dest_mask);
|
0
|
989 RETURN_UNGCPRO (ii);
|
|
990 }
|
|
991
|
20
|
992 DEFUN ("make-image-instance", Fmake_image_instance, 1, 4, 0, /*
|
0
|
993 Create a new `image-instance' object.
|
|
994
|
|
995 Image-instance objects encapsulate the way a particular image (pixmap,
|
|
996 etc.) is displayed on a particular device. In most circumstances, you
|
|
997 do not need to directly create image instances; use a glyph instead.
|
|
998 However, it may occasionally be useful to explicitly create image
|
|
999 instances, if you want more control over the instantiation process.
|
|
1000
|
|
1001 DATA is an image instantiator, which describes the image; see
|
|
1002 `image-specifier-p' for a description of the allowed values.
|
|
1003
|
|
1004 DEST-TYPES should be a list of allowed image instance types that can
|
|
1005 be generated. The recognized image instance types are
|
|
1006
|
|
1007 'nothing
|
|
1008 Nothing is displayed.
|
|
1009 'text
|
|
1010 Displayed as text. The foreground and background colors and the
|
|
1011 font of the text are specified independent of the pixmap. Typically
|
|
1012 these attributes will come from the face of the surrounding text,
|
|
1013 unless a face is specified for the glyph in which the image appears.
|
|
1014 'mono-pixmap
|
|
1015 Displayed as a mono pixmap (a pixmap with only two colors where the
|
|
1016 foreground and background can be specified independent of the pixmap;
|
|
1017 typically the pixmap assumes the foreground and background colors of
|
|
1018 the text around it, unless a face is specified for the glyph in which
|
|
1019 the image appears).
|
|
1020 'color-pixmap
|
|
1021 Displayed as a color pixmap.
|
|
1022 'pointer
|
|
1023 Used as the mouse pointer for a window.
|
|
1024 'subwindow
|
|
1025 A child window that is treated as an image. This allows (e.g.)
|
|
1026 another program to be responsible for drawing into the window.
|
|
1027 Not currently implemented.
|
|
1028
|
|
1029 The DEST-TYPES list is unordered. If multiple destination types
|
|
1030 are possible for a given instantiator, the \"most natural\" type
|
|
1031 for the instantiator's format is chosen. (For XBM, the most natural
|
|
1032 types are `mono-pixmap', followed by `color-pixmap', followed by
|
|
1033 `pointer'. For the other normal image formats, the most natural
|
|
1034 types are `color-pixmap', followed by `mono-pixmap', followed by
|
|
1035 `pointer'. For the string and formatted-string formats, the most
|
|
1036 natural types are `text', followed by `mono-pixmap' (not currently
|
|
1037 implemented), followed by `color-pixmap' (not currently implemented).
|
|
1038 The other formats can only be instantiated as one type. (If you
|
|
1039 want to control more specifically the order of the types into which
|
|
1040 an image is instantiated, just call `make-image-instance' repeatedly
|
|
1041 until it succeeds, passing less and less preferred destination types
|
|
1042 each time.
|
|
1043
|
|
1044 If DEST-TYPES is omitted, all possible types are allowed.
|
|
1045
|
|
1046 NO-ERROR controls what happens when the image cannot be generated.
|
|
1047 If nil, an error message is generated. If t, no messages are
|
|
1048 generated and this function returns nil. If anything else, a warning
|
|
1049 message is generated and this function returns nil.
|
20
|
1050 */
|
|
1051 (data, device, dest_types, no_error))
|
0
|
1052 {
|
|
1053 Error_behavior errb = decode_error_behavior_flag (no_error);
|
|
1054
|
74
|
1055 return call_with_suspended_errors ((lisp_fn_t) make_image_instance_1,
|
0
|
1056 Qnil, Qimage, errb,
|
|
1057 3, data, device, dest_types);
|
|
1058 }
|
|
1059
|
20
|
1060 DEFUN ("image-instance-p", Fimage_instance_p, 1, 1, 0, /*
|
0
|
1061 Return non-nil if OBJECT is an image instance.
|
20
|
1062 */
|
|
1063 (object))
|
0
|
1064 {
|
|
1065 return (IMAGE_INSTANCEP (object) ? Qt : Qnil);
|
|
1066 }
|
|
1067
|
20
|
1068 DEFUN ("image-instance-type", Fimage_instance_type, 1, 1, 0, /*
|
0
|
1069 Return the type of the given image instance.
|
|
1070 The return value will be one of 'nothing, 'text, 'mono-pixmap,
|
|
1071 'color-pixmap, 'pointer, or 'subwindow.
|
20
|
1072 */
|
|
1073 (image_instance))
|
0
|
1074 {
|
|
1075 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1076 return encode_image_instance_type (XIMAGE_INSTANCE_TYPE (image_instance));
|
|
1077 }
|
|
1078
|
20
|
1079 DEFUN ("image-instance-name", Fimage_instance_name, 1, 1, 0, /*
|
0
|
1080 Return the name of the given image instance.
|
20
|
1081 */
|
|
1082 (image_instance))
|
0
|
1083 {
|
|
1084 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1085 return (XIMAGE_INSTANCE_NAME (image_instance));
|
|
1086 }
|
|
1087
|
20
|
1088 DEFUN ("image-instance-string", Fimage_instance_string, 1, 1, 0, /*
|
0
|
1089 Return the string of the given image instance.
|
|
1090 This will only be non-nil for text image instances.
|
20
|
1091 */
|
|
1092 (image_instance))
|
0
|
1093 {
|
|
1094 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1095 if (XIMAGE_INSTANCE_TYPE (image_instance) == IMAGE_TEXT)
|
|
1096 return (XIMAGE_INSTANCE_TEXT_STRING (image_instance));
|
|
1097 else
|
|
1098 return Qnil;
|
|
1099 }
|
|
1100
|
20
|
1101 DEFUN ("image-instance-file-name", Fimage_instance_file_name, 1, 1, 0, /*
|
0
|
1102 Return the file name from which IMAGE-INSTANCE was read, if known.
|
20
|
1103 */
|
|
1104 (image_instance))
|
0
|
1105 {
|
|
1106 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1107
|
|
1108 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1109 {
|
|
1110 case IMAGE_MONO_PIXMAP:
|
|
1111 case IMAGE_COLOR_PIXMAP:
|
|
1112 case IMAGE_POINTER:
|
|
1113 return XIMAGE_INSTANCE_PIXMAP_FILENAME (image_instance);
|
|
1114
|
|
1115 default:
|
|
1116 return Qnil;
|
|
1117 }
|
|
1118 }
|
|
1119
|
20
|
1120 DEFUN ("image-instance-mask-file-name", Fimage_instance_mask_file_name, 1, 1, 0, /*
|
0
|
1121 Return the file name from which IMAGE-INSTANCE's mask was read, if known.
|
20
|
1122 */
|
|
1123 (image_instance))
|
0
|
1124 {
|
|
1125 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1126
|
|
1127 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1128 {
|
|
1129 case IMAGE_MONO_PIXMAP:
|
|
1130 case IMAGE_COLOR_PIXMAP:
|
|
1131 case IMAGE_POINTER:
|
|
1132 return XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME (image_instance);
|
|
1133
|
|
1134 default:
|
|
1135 return Qnil;
|
|
1136 }
|
|
1137 }
|
|
1138
|
20
|
1139 DEFUN ("image-instance-depth", Fimage_instance_depth, 1, 1, 0, /*
|
0
|
1140 Return the depth of the image instance.
|
|
1141 This is 0 for a bitmap, or a positive integer for a pixmap.
|
20
|
1142 */
|
|
1143 (image_instance))
|
0
|
1144 {
|
|
1145 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1146
|
|
1147 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1148 {
|
|
1149 case IMAGE_MONO_PIXMAP:
|
|
1150 case IMAGE_COLOR_PIXMAP:
|
|
1151 case IMAGE_POINTER:
|
|
1152 return (make_int (XIMAGE_INSTANCE_PIXMAP_DEPTH (image_instance)));
|
|
1153
|
|
1154 default:
|
|
1155 return Qnil;
|
|
1156 }
|
|
1157 }
|
|
1158
|
20
|
1159 DEFUN ("image-instance-height", Fimage_instance_height, 1, 1, 0, /*
|
0
|
1160 Return the height of the image instance, in pixels.
|
20
|
1161 */
|
|
1162 (image_instance))
|
0
|
1163 {
|
|
1164 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1165
|
|
1166 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1167 {
|
|
1168 case IMAGE_MONO_PIXMAP:
|
|
1169 case IMAGE_COLOR_PIXMAP:
|
|
1170 case IMAGE_POINTER:
|
|
1171 return (make_int (XIMAGE_INSTANCE_PIXMAP_HEIGHT (image_instance)));
|
|
1172
|
|
1173 default:
|
|
1174 return Qnil;
|
|
1175 }
|
|
1176 }
|
|
1177
|
20
|
1178 DEFUN ("image-instance-width", Fimage_instance_width, 1, 1, 0, /*
|
0
|
1179 Return the width of the image instance, in pixels.
|
20
|
1180 */
|
|
1181 (image_instance))
|
0
|
1182 {
|
|
1183 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1184
|
|
1185 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1186 {
|
|
1187 case IMAGE_MONO_PIXMAP:
|
|
1188 case IMAGE_COLOR_PIXMAP:
|
|
1189 case IMAGE_POINTER:
|
|
1190 return (make_int (XIMAGE_INSTANCE_PIXMAP_WIDTH (image_instance)));
|
|
1191
|
|
1192 default:
|
|
1193 return Qnil;
|
|
1194 }
|
|
1195 }
|
|
1196
|
20
|
1197 DEFUN ("image-instance-hotspot-x", Fimage_instance_hotspot_x, 1, 1, 0, /*
|
0
|
1198 Return the X coordinate of the image instance's hotspot, if known.
|
|
1199 This is a point relative to the origin of the pixmap. When an image is
|
|
1200 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1201 over the location that the pointer points to. This is, for example, the
|
|
1202 tip of the arrow or the center of the crosshairs.
|
|
1203 This will always be nil for a non-pointer image instance.
|
20
|
1204 */
|
|
1205 (image_instance))
|
0
|
1206 {
|
|
1207 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1208
|
|
1209 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1210 {
|
|
1211 case IMAGE_MONO_PIXMAP:
|
|
1212 case IMAGE_COLOR_PIXMAP:
|
|
1213 case IMAGE_POINTER:
|
|
1214 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image_instance);
|
|
1215
|
|
1216 default:
|
|
1217 return Qnil;
|
|
1218 }
|
|
1219 }
|
|
1220
|
20
|
1221 DEFUN ("image-instance-hotspot-y", Fimage_instance_hotspot_y, 1, 1, 0, /*
|
0
|
1222 Return the Y coordinate of the image instance's hotspot, if known.
|
|
1223 This is a point relative to the origin of the pixmap. When an image is
|
|
1224 used as a mouse pointer, the hotspot is the point on the image that sits
|
|
1225 over the location that the pointer points to. This is, for example, the
|
|
1226 tip of the arrow or the center of the crosshairs.
|
|
1227 This will always be nil for a non-pointer image instance.
|
20
|
1228 */
|
|
1229 (image_instance))
|
0
|
1230 {
|
|
1231 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1232
|
|
1233 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1234 {
|
|
1235 case IMAGE_MONO_PIXMAP:
|
|
1236 case IMAGE_COLOR_PIXMAP:
|
|
1237 case IMAGE_POINTER:
|
|
1238 return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image_instance);
|
|
1239
|
|
1240 default:
|
|
1241 return Qnil;
|
|
1242 }
|
|
1243 }
|
|
1244
|
20
|
1245 DEFUN ("image-instance-foreground", Fimage_instance_foreground, 1, 1, 0, /*
|
0
|
1246 Return the foreground color of IMAGE-INSTANCE, if applicable.
|
|
1247 This will be a color instance or nil. (It will only be non-nil for
|
|
1248 colorized mono pixmaps and for pointers.)
|
20
|
1249 */
|
|
1250 (image_instance))
|
0
|
1251 {
|
|
1252 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1253
|
|
1254 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1255 {
|
|
1256 case IMAGE_MONO_PIXMAP:
|
|
1257 case IMAGE_COLOR_PIXMAP:
|
|
1258 case IMAGE_POINTER:
|
|
1259 return XIMAGE_INSTANCE_PIXMAP_FG (image_instance);
|
|
1260
|
|
1261 default:
|
|
1262 return Qnil;
|
|
1263 }
|
|
1264 }
|
|
1265
|
20
|
1266 DEFUN ("image-instance-background", Fimage_instance_background, 1, 1, 0, /*
|
0
|
1267 Return the background color of IMAGE-INSTANCE, if applicable.
|
|
1268 This will be a color instance or nil. (It will only be non-nil for
|
|
1269 colorized mono pixmaps and for pointers.)
|
20
|
1270 */
|
|
1271 (image_instance))
|
0
|
1272 {
|
|
1273 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1274
|
|
1275 switch (XIMAGE_INSTANCE_TYPE (image_instance))
|
|
1276 {
|
|
1277 case IMAGE_MONO_PIXMAP:
|
|
1278 case IMAGE_COLOR_PIXMAP:
|
|
1279 case IMAGE_POINTER:
|
|
1280 return XIMAGE_INSTANCE_PIXMAP_BG (image_instance);
|
|
1281
|
|
1282 default:
|
|
1283 return Qnil;
|
|
1284 }
|
|
1285 }
|
|
1286
|
|
1287
|
20
|
1288 DEFUN ("colorize-image-instance", Fcolorize_image_instance, 3, 3, 0, /*
|
0
|
1289 Make the image instance be displayed in the given colors.
|
|
1290 This function returns a new image instance that is exactly like the
|
|
1291 specified one except that (if possible) the foreground and background
|
|
1292 colors and as specified. Currently, this only does anything if the image
|
|
1293 instance is a mono pixmap; otherwise, the same image instance is returned.
|
20
|
1294 */
|
|
1295 (image_instance, foreground, background))
|
0
|
1296 {
|
|
1297 Lisp_Object new;
|
|
1298 Lisp_Object device;
|
|
1299
|
|
1300 CHECK_IMAGE_INSTANCE (image_instance);
|
|
1301 CHECK_COLOR_INSTANCE (foreground);
|
|
1302 CHECK_COLOR_INSTANCE (background);
|
|
1303
|
|
1304 device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
1305 if (!HAS_DEVMETH_P (XDEVICE (device), colorize_image_instance))
|
|
1306 return image_instance;
|
|
1307
|
|
1308 new = allocate_image_instance (device);
|
|
1309 copy_lcrecord (XIMAGE_INSTANCE (new), XIMAGE_INSTANCE (image_instance));
|
|
1310 /* note that if this method returns non-zero, this method MUST
|
|
1311 copy any window-system resources, so that when one image instance is
|
|
1312 freed, the other one is not hosed. */
|
|
1313 if (!DEVMETH (XDEVICE (device), colorize_image_instance, (new, foreground,
|
|
1314 background)))
|
|
1315 return image_instance;
|
|
1316 return new;
|
|
1317 }
|
|
1318
|
|
1319
|
|
1320 /****************************************************************************
|
|
1321 * nothing *
|
|
1322 ****************************************************************************/
|
|
1323
|
|
1324 static int
|
74
|
1325 nothing_possible_dest_types (void)
|
0
|
1326 {
|
|
1327 return IMAGE_NOTHING_MASK;
|
|
1328 }
|
|
1329
|
|
1330 static void
|
|
1331 nothing_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1332 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
70
|
1333 int dest_mask)
|
0
|
1334 {
|
|
1335 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1336
|
|
1337 if (dest_mask & IMAGE_NOTHING_MASK)
|
|
1338 IMAGE_INSTANCE_TYPE (ii) = IMAGE_NOTHING;
|
|
1339 else
|
|
1340 incompatible_image_types (instantiator, dest_mask, IMAGE_NOTHING_MASK);
|
|
1341 }
|
|
1342
|
|
1343
|
|
1344 /****************************************************************************
|
|
1345 * inherit *
|
|
1346 ****************************************************************************/
|
|
1347
|
|
1348 static void
|
|
1349 inherit_validate (Lisp_Object instantiator)
|
|
1350 {
|
|
1351 face_must_be_present (instantiator);
|
|
1352 }
|
|
1353
|
|
1354 static Lisp_Object
|
|
1355 inherit_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1356 {
|
|
1357 Lisp_Object face;
|
|
1358
|
|
1359 assert (XVECTOR (inst)->size == 3);
|
|
1360 face = vector_data (XVECTOR (inst))[2];
|
|
1361 if (!FACEP (face))
|
|
1362 inst = vector3 (Qinherit, Q_face, Fget_face (face));
|
|
1363 return inst;
|
|
1364 }
|
|
1365
|
|
1366 static int
|
74
|
1367 inherit_possible_dest_types (void)
|
0
|
1368 {
|
|
1369 return IMAGE_MONO_PIXMAP_MASK;
|
|
1370 }
|
|
1371
|
|
1372 static void
|
|
1373 inherit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1374 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
70
|
1375 int dest_mask)
|
0
|
1376 {
|
|
1377 /* handled specially in image_instantiate */
|
|
1378 abort ();
|
|
1379 }
|
|
1380
|
|
1381
|
|
1382 /****************************************************************************
|
|
1383 * string *
|
|
1384 ****************************************************************************/
|
|
1385
|
|
1386 static void
|
|
1387 string_validate (Lisp_Object instantiator)
|
|
1388 {
|
|
1389 data_must_be_present (instantiator);
|
|
1390 }
|
|
1391
|
|
1392 static int
|
74
|
1393 string_possible_dest_types (void)
|
0
|
1394 {
|
|
1395 return IMAGE_TEXT_MASK;
|
|
1396 }
|
|
1397
|
|
1398 /* called from autodetect_instantiate() */
|
|
1399 void
|
|
1400 string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1401 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
70
|
1402 int dest_mask)
|
0
|
1403 {
|
|
1404 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1405 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1406
|
|
1407 assert (!NILP (data));
|
|
1408 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1409 {
|
|
1410 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1411 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1412 }
|
|
1413 else
|
|
1414 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1415 }
|
|
1416
|
|
1417
|
|
1418 /****************************************************************************
|
|
1419 * formatted-string *
|
|
1420 ****************************************************************************/
|
|
1421
|
|
1422 static void
|
|
1423 formatted_string_validate (Lisp_Object instantiator)
|
|
1424 {
|
|
1425 data_must_be_present (instantiator);
|
|
1426 }
|
|
1427
|
|
1428 static int
|
74
|
1429 formatted_string_possible_dest_types (void)
|
0
|
1430 {
|
|
1431 return IMAGE_TEXT_MASK;
|
|
1432 }
|
|
1433
|
|
1434 static void
|
|
1435 formatted_string_instantiate (Lisp_Object image_instance,
|
|
1436 Lisp_Object instantiator,
|
|
1437 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
70
|
1438 int dest_mask)
|
0
|
1439 {
|
|
1440 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1441 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1442
|
|
1443 assert (!NILP (data));
|
|
1444 /* #### implement this */
|
|
1445 warn_when_safe (Qunimplemented, Qnotice,
|
|
1446 "`formatted-string' not yet implemented; assuming `string'");
|
|
1447 if (dest_mask & IMAGE_TEXT_MASK)
|
|
1448 {
|
|
1449 IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
|
|
1450 IMAGE_INSTANCE_TEXT_STRING (ii) = data;
|
|
1451 }
|
|
1452 else
|
|
1453 incompatible_image_types (instantiator, dest_mask, IMAGE_TEXT_MASK);
|
|
1454 }
|
|
1455
|
|
1456
|
|
1457 /****************************************************************************
|
|
1458 * Image Specifier Object *
|
|
1459 ****************************************************************************/
|
|
1460
|
|
1461 DEFINE_SPECIFIER_TYPE (image);
|
|
1462
|
|
1463 static void
|
|
1464 image_create (Lisp_Object obj)
|
|
1465 {
|
|
1466 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
1467
|
|
1468 IMAGE_SPECIFIER_ALLOWED (image) = ~0; /* all are allowed */
|
|
1469 IMAGE_SPECIFIER_ATTACHEE (image) = Qnil;
|
|
1470 IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image) = Qnil;
|
|
1471 }
|
|
1472
|
|
1473 static void
|
|
1474 image_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
1475 {
|
|
1476 struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
|
|
1477
|
|
1478 ((markobj) (IMAGE_SPECIFIER_ATTACHEE (image)));
|
|
1479 ((markobj) (IMAGE_SPECIFIER_ATTACHEE_PROPERTY (image)));
|
|
1480 }
|
|
1481
|
|
1482 static Lisp_Object
|
|
1483 image_instantiate_cache_result (Lisp_Object locative)
|
|
1484 {
|
|
1485 Lisp_Object instance = Fcar (locative);
|
|
1486 Lisp_Object instantiator = Fcar (Fcdr (locative));
|
|
1487 Lisp_Object subtable = Fcdr (Fcdr (locative));
|
|
1488 Fputhash (instantiator, instance, subtable);
|
|
1489 free_cons (XCONS (XCDR (locative)));
|
|
1490 free_cons (XCONS (locative));
|
|
1491 return Qnil;
|
|
1492 }
|
|
1493
|
|
1494 /* Given a specification for an image, return an instance of
|
|
1495 the image which matches the given instantiator and which can be
|
|
1496 displayed in the given domain. */
|
|
1497
|
|
1498 static Lisp_Object
|
|
1499 image_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
|
|
1500 Lisp_Object domain, Lisp_Object instantiator,
|
|
1501 Lisp_Object depth)
|
|
1502 {
|
|
1503 Lisp_Object device = DFW_DEVICE (domain);
|
|
1504 struct device *d = XDEVICE (device);
|
|
1505 int dest_mask = XIMAGE_SPECIFIER_ALLOWED (specifier);
|
|
1506 int pointerp = dest_mask & image_instance_type_to_mask (IMAGE_POINTER);
|
|
1507
|
|
1508 if (IMAGE_INSTANCEP (instantiator))
|
|
1509 {
|
|
1510 /* make sure that the image instance's device and type are
|
|
1511 matching. */
|
|
1512
|
|
1513 if (EQ (device, XIMAGE_INSTANCE_DEVICE (instantiator)))
|
|
1514 {
|
|
1515 int mask =
|
|
1516 image_instance_type_to_mask (XIMAGE_INSTANCE_TYPE (instantiator));
|
|
1517 if (mask & dest_mask)
|
|
1518 return instantiator;
|
|
1519 else
|
|
1520 signal_simple_error ("Type of image instance not allowed here",
|
|
1521 instantiator);
|
|
1522 }
|
|
1523 else
|
|
1524 signal_simple_error_2 ("Wrong device for image instance",
|
|
1525 instantiator, device);
|
|
1526 }
|
|
1527 else if (VECTORP (instantiator)
|
|
1528 && EQ (vector_data (XVECTOR (instantiator))[0], Qinherit))
|
|
1529 {
|
|
1530 assert (XVECTOR (instantiator)->size == 3);
|
|
1531 return (FACE_PROPERTY_INSTANCE
|
|
1532 (Fget_face (vector_data (XVECTOR (instantiator))[2]),
|
|
1533 Qbackground_pixmap, domain, 0, depth));
|
|
1534 }
|
|
1535 else
|
|
1536 {
|
|
1537 Lisp_Object instance;
|
|
1538 Lisp_Object subtable;
|
|
1539 Lisp_Object ls3 = Qnil;
|
|
1540 Lisp_Object pointer_fg = Qnil;
|
|
1541 Lisp_Object pointer_bg = Qnil;
|
|
1542
|
|
1543 if (pointerp)
|
|
1544 {
|
|
1545 pointer_fg = FACE_FOREGROUND (Vpointer_face, domain);
|
|
1546 pointer_bg = FACE_BACKGROUND (Vpointer_face, domain);
|
|
1547 ls3 = list3 (instantiator, pointer_fg, pointer_bg);
|
|
1548 }
|
|
1549
|
|
1550 /* First look in the hash table. */
|
|
1551 subtable = Fgethash (make_int (dest_mask), d->image_instance_cache,
|
|
1552 Qunbound);
|
|
1553 if (UNBOUNDP (subtable))
|
|
1554 {
|
|
1555 /* For the image instance cache, we do comparisons with EQ rather
|
|
1556 than with EQUAL, as we do for color and font names.
|
|
1557 The reasons are:
|
|
1558
|
|
1559 1) pixmap data can be very long, and thus the hashing and
|
|
1560 comparing will take awhile.
|
|
1561 2) It's not so likely that we'll run into things that are EQUAL
|
|
1562 but not EQ (that can happen a lot with faces, because their
|
|
1563 specifiers are copied around); but pixmaps tend not to be
|
|
1564 in faces.
|
|
1565
|
|
1566 However, if the image-instance could be a pointer, we have to
|
|
1567 use EQUAL because we massaged the instantiator into a cons3
|
|
1568 also containing the foreground and background of the
|
|
1569 pointer face.
|
|
1570 */
|
|
1571
|
|
1572 subtable = make_lisp_hashtable (20,
|
|
1573 pointerp ? HASHTABLE_KEY_CAR_WEAK
|
|
1574 : HASHTABLE_KEY_WEAK,
|
|
1575 pointerp ? HASHTABLE_EQUAL
|
|
1576 : HASHTABLE_EQ);
|
|
1577 Fputhash (make_int (dest_mask), subtable,
|
|
1578 d->image_instance_cache);
|
|
1579 instance = Qunbound;
|
|
1580 }
|
|
1581 else
|
|
1582 instance = Fgethash (pointerp ? ls3 : instantiator,
|
|
1583 subtable, Qunbound);
|
|
1584
|
|
1585 if (UNBOUNDP (instance))
|
|
1586 {
|
|
1587 Lisp_Object locative =
|
|
1588 noseeum_cons (Qnil,
|
|
1589 noseeum_cons (pointerp ? ls3 : instantiator,
|
|
1590 subtable));
|
|
1591 int speccount = specpdl_depth ();
|
|
1592
|
|
1593 /* make sure we cache the failures, too.
|
|
1594 Use an unwind-protect to catch such errors.
|
|
1595 If we fail, the unwind-protect records nil in
|
|
1596 the hash table. If we succeed, we change the
|
|
1597 car of the locative to the resulting instance,
|
|
1598 which gets recorded instead. */
|
|
1599 record_unwind_protect (image_instantiate_cache_result,
|
|
1600 locative);
|
|
1601 instance = instantiate_image_instantiator (device,
|
|
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
|
74
|
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)));
|
84
|
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.)
|
122
|
1841 'autodetect
|
0
|
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',
|
122
|
1868 `cursor-font', `font', `autodetect', and `inherit'.)
|
0
|
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,
|
82
|
2386 XSTRING_DATA (string),
|
14
|
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 */ );
|
116
|
2946 Vcurrent_display_table = Fmake_specifier (Qdisplay_table);
|
0
|
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 }
|