2 Copyright (C) 1993, 1994 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This is derived from work by Lucid (some parts very loosely so). */
22 #include <sys/types.h>
37 #include "dispextern.h"
39 #include "blockinput.h"
41 #include "intervals.h"
44 /* Compensate for bug in Xos.h on some systems, on which it requires
45 time.h. On some such systems, Xos.h tries to redefine struct
46 timeval and struct timezone if USG is #defined while it is
48 #ifdef XOS_NEEDS_TIME_H
61 #endif /* HAVE_X_WINDOWS */
63 /* An explanation of the face data structures. */
65 /* ========================= Face Data Structures =========================
67 Let FACE-NAME be a symbol naming a face.
69 Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME))
70 FACE-VECTOR is either nil, or a vector of the form
71 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P]
73 face is the symbol `face',
74 NAME is the symbol with which this vector is associated (a backpointer),
75 ID is the face ID, an integer used internally by the C code to identify
77 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors
79 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't
81 UNDERLINE-P is non-nil if the face should be underlined.
82 If any of these elements are nil, that parameter is considered
83 unspecified; parameters from faces specified by lower-priority
84 overlays or text properties, or the parameters of the frame itself,
85 can show through. (lisp/faces.el maintains these lists.)
87 (assq FACE-NAME global-face-data) returns a vector describing the
88 global parameters for that face.
90 Let PARAM-FACE be FRAME->output_data.x->param_faces[Faref (FACE-VECTOR, 2)].
91 PARAM_FACE is a struct face whose members are the Xlib analogues of
92 the parameters in FACE-VECTOR. If an element of FACE-VECTOR is
93 nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT.
94 These faces are called "parameter faces", because they're the ones
95 lisp manipulates to control what gets displayed. Elements 0 and 1
96 of FRAME->output_data.x->param_faces are special - they describe the
97 default and mode line faces. None of the faces in param_faces have
98 GC's. (See src/dispextern.h for the definiton of struct face.
99 lisp/faces.el maintains the isomorphism between face_alist and
102 The functions compute_char_face and compute_glyph_face find and
103 combine the parameter faces associated with overlays and text
104 properties. The resulting faces are called "computed faces"; none
105 of their members are FACE_DEFAULT; they are completely specified.
106 They then call intern_compute_face to search
107 FRAME->output_data.x->computed_faces for a matching face, add one if
108 none is found, and return the index into
109 FRAME->output_data.x->computed_faces. FRAME's glyph matrices use these
110 indices to record the faces of the matrix characters, and the X
111 display hooks consult compute_faces to decide how to display these
112 characters. Elements 0 and 1 of computed_faces always describe the
113 default and mode-line faces.
115 Each computed face belongs to a particular frame.
117 Computed faces have graphics contexts some of the time.
118 intern_face builds a GC for a specified computed face
119 if it doesn't have one already.
120 clear_face_cache clears out the GCs of all computed faces.
121 This is done from time to time so that we don't hold on to
122 lots of GCs that are no longer needed.
124 If a computed face has 0 as its font,
125 it is unused, and can be reused by new_computed_face.
129 Symbols naming faces must have associations on all frames; for any
130 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist
131 FRAME)) is non-nil, it must be non-nil for all frames.
133 Analogously, indices into param_faces must be valid on all frames;
134 if param_faces[i] is a non-zero face pointer on one frame, then it
135 must be filled in on all frames. Code assumes that face ID's can
136 be used on any frame.
140 Why do we keep param_faces and computed_faces separate?
141 computed_faces contains an element for every combination of facial
142 parameters we have ever displayed. indices into param_faces have
143 to be valid on all frames. If they were the same array, then that
144 array would grow very large on all frames, because any facial
145 combination displayed on any frame would need to be a valid entry
148 /* Definitions and declarations. */
150 /* The number of face-id's in use (same for all frames). */
151 static int next_face_id
;
153 /* The number of the face to use to indicate the region. */
154 static int region_face
;
156 /* This is what appears in a slot in a face to signify that the face
157 does not specify that display aspect. */
158 #define FACE_DEFAULT (~0)
160 Lisp_Object Qface
, Qmouse_face
;
161 Lisp_Object Qpixmap_spec_p
;
163 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ );
165 struct face
*intern_face ( /* FRAME_PTR, struct face * */ );
166 static int new_computed_face ( /* FRAME_PTR, struct face * */ );
167 static int intern_computed_face ( /* FRAME_PTR, struct face * */ );
168 static void ensure_face_ready ( /* FRAME_PTR, int id */ );
169 void recompute_basic_faces ( /* FRAME_PTR f */ );
171 /* Allocating, copying, and comparing struct faces. */
173 /* Allocate a new face */
177 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
178 bzero (result
, sizeof (struct face
));
179 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
180 result
->foreground
= FACE_DEFAULT
;
181 result
->background
= FACE_DEFAULT
;
182 result
->stipple
= FACE_DEFAULT
;
186 /* Make a new face that's a copy of an existing one. */
191 struct face
*result
= allocate_face ();
193 result
->font
= face
->font
;
194 result
->foreground
= face
->foreground
;
195 result
->background
= face
->background
;
196 result
->stipple
= face
->stipple
;
197 result
->underline
= face
->underline
;
198 result
->pixmap_h
= face
->pixmap_h
;
199 result
->pixmap_w
= face
->pixmap_w
;
205 face_eql (face1
, face2
)
206 struct face
*face1
, *face2
;
208 return ( face1
->font
== face2
->font
209 && face1
->foreground
== face2
->foreground
210 && face1
->background
== face2
->background
211 && face1
->stipple
== face2
->stipple
212 && face1
->underline
== face2
->underline
);
215 /* Managing graphics contexts of faces. */
217 #ifdef HAVE_X_WINDOWS
218 /* Given a computed face, construct its graphics context if necessary. */
221 intern_face (f
, face
)
234 if (face
->foreground
!= FACE_DEFAULT
)
235 xgcv
.foreground
= face
->foreground
;
237 xgcv
.foreground
= f
->output_data
.x
->foreground_pixel
;
239 if (face
->background
!= FACE_DEFAULT
)
240 xgcv
.background
= face
->background
;
242 xgcv
.background
= f
->output_data
.x
->background_pixel
;
244 if (face
->font
&& face
->font
!= (XFontStruct
*) FACE_DEFAULT
)
245 xgcv
.font
= face
->font
->fid
;
247 xgcv
.font
= f
->output_data
.x
->font
->fid
;
249 xgcv
.graphics_exposures
= 0;
251 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
252 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
254 xgcv
.fill_style
= FillStippled
;
255 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
256 mask
|= GCFillStyle
| GCStipple
;
259 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
269 /* Clear out all graphics contexts for all computed faces
270 except for the default and mode line faces.
271 This should be done from time to time just to avoid
272 keeping too many graphics contexts that are no longer needed. */
277 Lisp_Object tail
, frame
;
280 FOR_EACH_FRAME (tail
, frame
)
282 FRAME_PTR f
= XFRAME (frame
);
286 Display
*dpy
= FRAME_X_DISPLAY (f
);
288 for (i
= 2; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
290 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
292 XFreeGC (dpy
, face
->gc
);
301 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps.
303 These functions operate on param faces only.
304 Computed faces get their fonts, colors and pixmaps
305 by merging param faces. */
315 return (XFontStruct
*) FACE_DEFAULT
;
317 CHECK_STRING (name
, 0);
319 font
= XLoadQueryFont (FRAME_X_DISPLAY (f
), (char *) XSTRING (name
)->data
);
323 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
324 Fcons (name
, Qnil
)));
329 unload_font (f
, font
)
333 int len
= FRAME_N_COMPUTED_FACES (f
);
336 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
340 /* Invalidate any computed faces which use this font,
341 and free their GC's if they have any. */
342 for (i
= 0; i
< len
; i
++)
344 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
345 if (face
->font
== font
)
347 Display
*dpy
= FRAME_X_DISPLAY (f
);
349 XFreeGC (dpy
, face
->gc
);
355 XFreeFont (FRAME_X_DISPLAY (f
), font
);
370 CHECK_STRING (name
, 0);
371 /* if the colormap is full, defined_color will return a best match
372 to the values in an an existing cell. */
373 result
= defined_color(f
, (char *) XSTRING (name
)->data
, &color
, 1);
375 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
376 Fcons (name
, Qnil
)));
377 return (unsigned long) color
.pixel
;
381 unload_color (f
, pixel
)
386 Display
*dpy
= FRAME_X_DISPLAY (f
);
387 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
389 if (pixel
== FACE_DEFAULT
390 || pixel
== BLACK_PIX_DEFAULT (f
)
391 || pixel
== WHITE_PIX_DEFAULT (f
))
393 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy
));
395 /* If display has an immutable color map, freeing colors is not
396 necessary and some servers don't allow it. So don't do it. */
397 if (! (class == StaticColor
|| class == StaticGray
|| class == TrueColor
))
399 int len
= FRAME_N_COMPUTED_FACES (f
);
403 /* Invalidate any computed faces which use this color,
404 and free their GC's if they have any. */
405 for (i
= 0; i
< len
; i
++)
407 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
408 if (face
->foreground
== pixel
409 || face
->background
== pixel
)
411 Display
*dpy
= FRAME_X_DISPLAY (f
);
413 XFreeGC (dpy
, face
->gc
);
419 XFreeColors (dpy
, cmap
, &pixel
, 1, (unsigned long)0);
424 DEFUN ("pixmap-spec-p", Fpixmap_spec_p
, Spixmap_spec_p
, 1, 1, 0,
425 "Return t if ARG is a valid pixmap specification.")
429 Lisp_Object height
, width
;
431 return ((STRINGP (arg
)
433 && CONSP (XCONS (arg
)->cdr
)
434 && CONSP (XCONS (XCONS (arg
)->cdr
)->cdr
)
435 && NILP (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->cdr
)
436 && (width
= XCONS (arg
)->car
, INTEGERP (width
))
437 && (height
= XCONS (XCONS (arg
)->cdr
)->car
, INTEGERP (height
))
438 && STRINGP (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->car
)
441 /* The string must have enough bits for width * height. */
442 && ((XSTRING (XCONS (XCONS (XCONS (arg
)->cdr
)->cdr
)->car
)->size
443 * (BITS_PER_INT
/ sizeof (int)))
444 >= XFASTINT (width
) * XFASTINT (height
))))
448 /* Load a bitmap according to NAME (which is either a file name
449 or a pixmap spec). Return the bitmap_id (see xfns.c)
450 or get an error if NAME is invalid.
452 Store the bitmap width in *W_PTR and height in *H_PTR. */
455 load_pixmap (f
, name
, w_ptr
, h_ptr
)
458 unsigned int *w_ptr
, *h_ptr
;
466 tem
= Fpixmap_spec_p (name
);
468 wrong_type_argument (Qpixmap_spec_p
, name
);
474 /* Decode a bitmap spec into a bitmap. */
479 w
= XINT (Fcar (name
));
480 h
= XINT (Fcar (Fcdr (name
)));
481 bits
= Fcar (Fcdr (Fcdr (name
)));
483 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
488 /* It must be a string -- a file name. */
489 bitmap_id
= x_create_bitmap_from_file (f
, name
);
494 Fsignal (Qerror
, Fcons (build_string ("invalid or undefined bitmap"),
495 Fcons (name
, Qnil
)));
497 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
498 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
503 #else /* !HAVE_X_WINDOWS */
505 /* Stubs for MSDOS when not under X. */
508 intern_face (f
, face
)
532 CHECK_STRING (name
, 0);
533 result
= call1 (Qmsdos_color_translate
, name
);
534 if (INTEGERP (result
))
535 return XINT (result
);
537 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
538 Fcons (name
, Qnil
)));
541 #endif /* !HAVE_X_WINDOWS */
544 /* Managing parameter face arrays for frames. */
550 ensure_face_ready (f
, 0);
551 ensure_face_ready (f
, 1);
553 FRAME_N_COMPUTED_FACES (f
) = 0;
554 FRAME_SIZE_COMPUTED_FACES (f
) = 0;
556 new_computed_face (f
, FRAME_PARAM_FACES (f
)[0]);
557 new_computed_face (f
, FRAME_PARAM_FACES (f
)[1]);
558 recompute_basic_faces (f
);
561 /* Find another X frame. */
563 Lisp_Object tail
, frame
, result
;
566 FOR_EACH_FRAME (tail
, frame
)
567 if (FRAME_X_P (XFRAME (frame
))
568 && XFRAME (frame
) != f
)
574 /* If we didn't find any X frames other than f, then we don't need
575 any faces other than 0 and 1, so we're okay. Otherwise, make
576 sure that all faces valid on the selected frame are also valid
577 on this new frame. */
581 int n_faces
= FRAME_N_PARAM_FACES (XFRAME (result
));
582 struct face
**faces
= FRAME_PARAM_FACES (XFRAME (result
));
584 for (i
= 2; i
< n_faces
; i
++)
586 ensure_face_ready (f
, i
);
589 #endif /* MULTI_FRAME */
593 /* Called from Fdelete_frame. */
599 Display
*dpy
= FRAME_X_DISPLAY (f
);
604 for (i
= 0; i
< FRAME_N_PARAM_FACES (f
); i
++)
606 struct face
*face
= FRAME_PARAM_FACES (f
) [i
];
609 unload_font (f
, face
->font
);
610 unload_color (f
, face
->foreground
);
611 unload_color (f
, face
->background
);
612 x_destroy_bitmap (f
, face
->stipple
);
616 xfree (FRAME_PARAM_FACES (f
));
617 FRAME_PARAM_FACES (f
) = 0;
618 FRAME_N_PARAM_FACES (f
) = 0;
620 /* All faces in FRAME_COMPUTED_FACES use resources copied from
621 FRAME_PARAM_FACES; we can free them without fuss.
622 But we do free the GCs and the face objects themselves. */
623 for (i
= 0; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
625 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
629 XFreeGC (dpy
, face
->gc
);
633 xfree (FRAME_COMPUTED_FACES (f
));
634 FRAME_COMPUTED_FACES (f
) = 0;
635 FRAME_N_COMPUTED_FACES (f
) = 0;
640 /* Interning faces in a frame's face array. */
643 new_computed_face (f
, new_face
)
645 struct face
*new_face
;
647 int len
= FRAME_N_COMPUTED_FACES (f
);
650 /* Search for an unused computed face in the middle of the table. */
651 for (i
= 0; i
< len
; i
++)
653 struct face
*face
= FRAME_COMPUTED_FACES (f
)[i
];
656 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
661 if (i
>= FRAME_SIZE_COMPUTED_FACES (f
))
663 int new_size
= i
+ 32;
665 FRAME_COMPUTED_FACES (f
)
666 = (struct face
**) (FRAME_SIZE_COMPUTED_FACES (f
) == 0
667 ? xmalloc (new_size
* sizeof (struct face
*))
668 : xrealloc (FRAME_COMPUTED_FACES (f
),
669 new_size
* sizeof (struct face
*)));
670 FRAME_SIZE_COMPUTED_FACES (f
) = new_size
;
673 i
= FRAME_N_COMPUTED_FACES (f
)++;
674 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
679 /* Find a match for NEW_FACE in a FRAME's computed face array, and add
680 it if we don't find one. */
682 intern_computed_face (f
, new_face
)
684 struct face
*new_face
;
686 int len
= FRAME_N_COMPUTED_FACES (f
);
689 /* Search for a computed face already on F equivalent to FACE. */
690 for (i
= 0; i
< len
; i
++)
692 if (! FRAME_COMPUTED_FACES (f
)[i
])
694 if (face_eql (new_face
, FRAME_COMPUTED_FACES (f
)[i
]))
698 /* We didn't find one; add a new one. */
699 return new_computed_face (f
, new_face
);
702 /* Make parameter face id ID valid on frame F. */
705 ensure_face_ready (f
, id
)
709 if (FRAME_N_PARAM_FACES (f
) <= id
)
713 if (!FRAME_N_PARAM_FACES (f
))
714 FRAME_PARAM_FACES (f
)
715 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
717 FRAME_PARAM_FACES (f
)
718 = (struct face
**) xrealloc (FRAME_PARAM_FACES (f
),
719 sizeof (struct face
*) * n
);
721 bzero (FRAME_PARAM_FACES (f
) + FRAME_N_PARAM_FACES (f
),
722 (n
- FRAME_N_PARAM_FACES (f
)) * sizeof (struct face
*));
723 FRAME_N_PARAM_FACES (f
) = n
;
726 if (FRAME_PARAM_FACES (f
) [id
] == 0)
727 FRAME_PARAM_FACES (f
) [id
] = allocate_face ();
730 #ifdef HAVE_X_WINDOWS
731 /* Return non-zero if FONT1 and FONT2 have the same width.
732 We do not check the height, because we can now deal with
734 We assume that they're both character-cell fonts. */
737 same_size_fonts (font1
, font2
)
738 XFontStruct
*font1
, *font2
;
740 XCharStruct
*bounds1
= &font1
->min_bounds
;
741 XCharStruct
*bounds2
= &font2
->min_bounds
;
743 return (bounds1
->width
== bounds2
->width
);
746 /* Update the line_height of frame F according to the biggest font in
747 any face. Return nonzero if if line_height changes. */
750 frame_update_line_height (f
)
754 int biggest
= FONT_HEIGHT (f
->output_data
.x
->font
);
756 for (i
= 0; i
< f
->output_data
.x
->n_param_faces
; i
++)
757 if (f
->output_data
.x
->param_faces
[i
] != 0
758 && f
->output_data
.x
->param_faces
[i
]->font
!= (XFontStruct
*) FACE_DEFAULT
)
760 int height
= FONT_HEIGHT (f
->output_data
.x
->param_faces
[i
]->font
);
761 if (height
> biggest
)
765 if (biggest
== f
->output_data
.x
->line_height
)
768 f
->output_data
.x
->line_height
= biggest
;
771 #endif /* not HAVE_X_WINDOWS */
773 /* Modify face TO by copying from FROM all properties which have
774 nondefault settings. */
777 merge_faces (from
, to
)
778 struct face
*from
, *to
;
780 /* Only merge the font if it's the same width as the base font.
781 Otherwise ignore it, since we can't handle it properly. */
782 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
783 && same_size_fonts (from
->font
, to
->font
))
784 to
->font
= from
->font
;
785 if (from
->foreground
!= FACE_DEFAULT
)
786 to
->foreground
= from
->foreground
;
787 if (from
->background
!= FACE_DEFAULT
)
788 to
->background
= from
->background
;
789 if (from
->stipple
!= FACE_DEFAULT
)
791 to
->stipple
= from
->stipple
;
792 to
->pixmap_h
= from
->pixmap_h
;
793 to
->pixmap_w
= from
->pixmap_w
;
796 to
->underline
= from
->underline
;
799 /* Set up the basic set of facial parameters, based on the frame's
800 data; all faces are deltas applied to this. */
803 compute_base_face (f
, face
)
808 face
->foreground
= FRAME_FOREGROUND_PIXEL (f
);
809 face
->background
= FRAME_BACKGROUND_PIXEL (f
);
810 face
->font
= FRAME_FONT (f
);
815 /* Return the face ID to use to display a special glyph which selects
816 FACE_CODE as the face ID, assuming that ordinarily the face would
817 be CURRENT_FACE. F is the frame. */
820 compute_glyph_face (f
, face_code
, current_face
)
822 int face_code
, current_face
;
826 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
828 if (face_code
>= 0 && face_code
< FRAME_N_PARAM_FACES (f
)
829 && FRAME_PARAM_FACES (f
) [face_code
] != 0)
830 merge_faces (FRAME_PARAM_FACES (f
) [face_code
], &face
);
832 return intern_computed_face (f
, &face
);
835 /* Return the face ID to use to display a special glyph which selects
836 FACE_CODE as the face ID, assuming that ordinarily the face would
837 be CURRENT_FACE. F is the frame. */
840 compute_glyph_face_1 (f
, face_name
, current_face
)
842 Lisp_Object face_name
;
847 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
849 if (!NILP (face_name
))
851 int facecode
= face_name_id_number (f
, face_name
);
852 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
853 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
854 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
857 return intern_computed_face (f
, &face
);
860 /* Return the face ID associated with a buffer position POS.
861 Store into *ENDPTR the position at which a different face is needed.
862 This does not take account of glyphs that specify their own face codes.
863 F is the frame in use for display, and W is a window displaying
866 REGION_BEG, REGION_END delimit the region, so it can be highlighted.
868 LIMIT is a position not to scan beyond. That is to limit
869 the time this function can take.
871 If MOUSE is nonzero, use the character's mouse-face, not its face. */
874 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
, limit
, mouse
)
878 int region_beg
, region_end
;
884 Lisp_Object prop
, position
;
887 Lisp_Object
*overlay_vec
;
890 Lisp_Object propname
;
892 /* W must display the current buffer. We could write this function
893 to use the frame and buffer of W, but right now it doesn't. */
894 if (XBUFFER (w
->buffer
) != current_buffer
)
897 XSETFRAME (frame
, f
);
900 if (pos
< region_beg
&& region_beg
< endpos
)
903 XSETFASTINT (position
, pos
);
906 propname
= Qmouse_face
;
910 prop
= Fget_text_property (position
, propname
, w
->buffer
);
913 Lisp_Object limit1
, end
;
915 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
916 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
925 /* First try with room for 40 overlays. */
927 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
929 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
930 &next_overlay
, (int *) 0);
932 /* If there are more than 40,
933 make enough space for all, and try again. */
937 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
938 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
939 &next_overlay
, (int *) 0);
942 if (next_overlay
< endpos
)
943 endpos
= next_overlay
;
948 /* Optimize the default case. */
949 if (noverlays
== 0 && NILP (prop
)
950 && !(pos
>= region_beg
&& pos
< region_end
))
953 compute_base_face (f
, &face
);
957 /* We have a list of faces, merge them in reverse order */
962 length
= Fsafe_length (prop
);
963 len
= XFASTINT (length
);
965 /* Put them into an array */
966 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
967 for (j
= 0; j
< len
; j
++)
969 faces
[j
] = Fcar (prop
);
972 /* So that we can merge them in the reverse order */
973 for (j
= len
- 1; j
>= 0; j
--)
975 facecode
= face_name_id_number (f
, faces
[j
]);
976 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
977 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
978 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
981 else if (!NILP (prop
))
983 facecode
= face_name_id_number (f
, prop
);
984 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
985 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
986 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
989 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
991 /* Now merge the overlay data in that order. */
992 for (i
= 0; i
< noverlays
; i
++)
994 prop
= Foverlay_get (overlay_vec
[i
], propname
);
997 /* We have a list of faces, merge them in reverse order */
1002 length
= Fsafe_length (prop
);
1003 len
= XFASTINT (length
);
1005 /* Put them into an array */
1006 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1007 for (j
= 0; j
< len
; j
++)
1009 faces
[j
] = Fcar (prop
);
1012 /* So that we can merge them in the reverse order */
1013 for (j
= len
- 1; j
>= 0; j
--)
1015 facecode
= face_name_id_number (f
, faces
[j
]);
1016 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
1017 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
1018 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
1021 else if (!NILP (prop
))
1026 facecode
= face_name_id_number (f
, prop
);
1027 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
1028 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
1029 merge_faces (FRAME_PARAM_FACES (f
)[facecode
], &face
);
1031 oend
= OVERLAY_END (overlay_vec
[i
]);
1032 oendpos
= OVERLAY_POSITION (oend
);
1033 if (oendpos
< endpos
)
1038 if (pos
>= region_beg
&& pos
< region_end
)
1040 if (region_end
< endpos
)
1041 endpos
= region_end
;
1042 if (region_face
>= 0 && region_face
< next_face_id
)
1043 merge_faces (FRAME_PARAM_FACES (f
)[region_face
], &face
);
1048 return intern_computed_face (f
, &face
);
1051 /* Recompute the GC's for the default and modeline faces.
1052 We call this after changing frame parameters on which those GC's
1056 recompute_basic_faces (f
)
1059 /* If the frame's faces haven't been initialized yet, don't worry about
1061 if (FRAME_N_PARAM_FACES (f
) < 2)
1066 if (FRAME_DEFAULT_FACE (f
)->gc
)
1067 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_DEFAULT_FACE (f
)->gc
);
1068 if (FRAME_MODE_LINE_FACE (f
)->gc
)
1069 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_MODE_LINE_FACE (f
)->gc
);
1071 compute_base_face (f
, FRAME_DEFAULT_FACE (f
));
1072 compute_base_face (f
, FRAME_MODE_LINE_FACE (f
));
1074 merge_faces (FRAME_DEFAULT_PARAM_FACE (f
), FRAME_DEFAULT_FACE (f
));
1075 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f
), FRAME_MODE_LINE_FACE (f
));
1077 intern_face (f
, FRAME_DEFAULT_FACE (f
));
1078 intern_face (f
, FRAME_MODE_LINE_FACE (f
));
1085 /* Lisp interface. */
1087 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
1092 CHECK_FRAME (frame
, 0);
1093 return XFRAME (frame
)->face_alist
;
1096 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
1099 Lisp_Object frame
, value
;
1101 CHECK_FRAME (frame
, 0);
1102 XFRAME (frame
)->face_alist
= value
;
1107 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
1108 "Create face number FACE-ID on all frames.")
1110 Lisp_Object face_id
;
1112 Lisp_Object rest
, frame
;
1113 int id
= XINT (face_id
);
1115 CHECK_NUMBER (face_id
, 0);
1116 if (id
< 0 || id
>= next_face_id
)
1117 error ("Face id out of range");
1119 FOR_EACH_FRAME (rest
, frame
)
1121 if (FRAME_X_P (XFRAME (frame
)))
1122 ensure_face_ready (XFRAME (frame
), id
);
1128 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
1129 Sset_face_attribute_internal
, 4, 4, 0, "")
1130 (face_id
, attr_name
, attr_value
, frame
)
1131 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
1139 CHECK_FRAME (frame
, 0);
1140 CHECK_NUMBER (face_id
, 0);
1141 CHECK_SYMBOL (attr_name
, 0);
1144 id
= XINT (face_id
);
1145 if (id
< 0 || id
>= next_face_id
)
1146 error ("Face id out of range");
1148 if (! FRAME_X_P (f
))
1151 ensure_face_ready (f
, id
);
1152 face
= FRAME_PARAM_FACES (f
) [XFASTINT (face_id
)];
1154 if (EQ (attr_name
, intern ("font")))
1156 #if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
1157 face
->font
= 0; /* The one and only font. */
1159 XFontStruct
*font
= load_font (f
, attr_value
);
1160 if (face
->font
!= f
->output_data
.x
->font
)
1161 unload_font (f
, face
->font
);
1163 if (frame_update_line_height (f
))
1164 x_set_window_size (f
, 0, f
->width
, f
->height
);
1165 /* Must clear cache, since it might contain the font
1166 we just got rid of. */
1170 else if (EQ (attr_name
, intern ("foreground")))
1172 unsigned long new_color
= load_color (f
, attr_value
);
1173 unload_color (f
, face
->foreground
);
1174 face
->foreground
= new_color
;
1177 else if (EQ (attr_name
, intern ("background")))
1179 unsigned long new_color
= load_color (f
, attr_value
);
1180 unload_color (f
, face
->background
);
1181 #if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
1182 new_color
&= ~8; /* Bright would give blinking characters. */
1184 face
->background
= new_color
;
1187 else if (EQ (attr_name
, intern ("background-pixmap")))
1190 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
);
1191 x_destroy_bitmap (f
, face
->stipple
);
1192 face
->stipple
= new_pixmap
;
1197 else if (EQ (attr_name
, intern ("underline")))
1199 int new = !NILP (attr_value
);
1200 face
->underline
= new;
1203 error ("unknown face attribute");
1205 if (id
== 0 || id
== 1)
1206 recompute_basic_faces (f
);
1208 /* We must redraw the frame whenever any face font or color changes,
1209 because it's possible that a merged (display) face
1210 contains the font or color we just replaced.
1211 And we must inhibit any Expose events until the redraw is done,
1212 since they would try to use the invalid display faces. */
1214 SET_FRAME_GARBAGED (f
);
1219 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1223 return make_number (next_face_id
++);
1226 /* Return the face id for name NAME on frame FRAME.
1227 (It should be the same for all frames,
1228 but it's as easy to use the "right" frame to look it up
1229 as to use any other one.) */
1232 face_name_id_number (f
, name
)
1238 tem
= Fcdr (assq_no_quit (name
, f
->face_alist
));
1241 CHECK_VECTOR (tem
, 0);
1242 tem
= XVECTOR (tem
)->contents
[2];
1243 CHECK_NUMBER (tem
, 0);
1247 /* Emacs initialization. */
1252 Qface
= intern ("face");
1254 Qmouse_face
= intern ("mouse-face");
1255 staticpro (&Qmouse_face
);
1256 Qpixmap_spec_p
= intern ("pixmap-spec-p");
1257 staticpro (&Qpixmap_spec_p
);
1259 DEFVAR_INT ("region-face", ®ion_face
,
1260 "Face number to use to highlight the region\n\
1261 The region is highlighted with this face\n\
1262 when Transient Mark mode is enabled and the mark is active.");
1264 #ifdef HAVE_X_WINDOWS
1265 defsubr (&Spixmap_spec_p
);
1267 defsubr (&Sframe_face_alist
);
1268 defsubr (&Sset_frame_face_alist
);
1269 defsubr (&Smake_face_internal
);
1270 defsubr (&Sset_face_attribute_internal
);
1271 defsubr (&Sinternal_next_face_id
);
1274 #endif /* HAVE_FACES */