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>
32 #include "dispextern.h"
34 #include "blockinput.h"
36 #include "intervals.h"
38 /* Compensate for bug in Xos.h on some systems, on which it requires
39 time.h. On some such systems, Xos.h tries to redefine struct
40 timeval and struct timezone if USG is #defined while it is
42 #ifdef XOS_NEEDS_TIME_H
57 /* An explanation of the face data structures. */
59 /* ========================= Face Data Structures =========================
61 Let FACE-NAME be a symbol naming a face.
63 Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME))
64 FACE-VECTOR is either nil, or a vector of the form
65 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P]
67 face is the symbol `face',
68 NAME is the symbol with which this vector is associated (a backpointer),
69 ID is the face ID, an integer used internally by the C code to identify
71 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors
73 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't
75 UNDERLINE-P is non-nil if the face should be underlined.
76 If any of these elements are nil, that parameter is considered
77 unspecified; parameters from faces specified by lower-priority
78 overlays or text properties, or the parameters of the frame itself,
79 can show through. (lisp/faces.el maintains these lists.)
81 (assq FACE-NAME global-face-data) returns a vector describing the
82 global parameters for that face.
84 Let PARAM-FACE be FRAME->display.x->param_faces[Faref (FACE-VECTOR, 2)].
85 PARAM_FACE is a struct face whose members are the Xlib analogues of
86 the parameters in FACE-VECTOR. If an element of FACE-VECTOR is
87 nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT.
88 These faces are called "parameter faces", because they're the ones
89 lisp manipulates to control what gets displayed. Elements 0 and 1
90 of FRAME->display.x->param_faces are special - they describe the
91 default and mode line faces. None of the faces in param_faces have
92 GC's. (See src/dispextern.h for the definiton of struct face.
93 lisp/faces.el maintains the isomorphism between face_alist and
96 The functions compute_char_face and compute_glyph_face find and
97 combine the parameter faces associated with overlays and text
98 properties. The resulting faces are called "computed faces"; none
99 of their members are FACE_DEFAULT; they are completely specified.
100 They then call intern_compute_face to search
101 FRAME->display.x->computed_faces for a matching face, add one if
102 none is found, and return the index into
103 FRAME->display.x->computed_faces. FRAME's glyph matrices use these
104 indices to record the faces of the matrix characters, and the X
105 display hooks consult compute_faces to decide how to display these
106 characters. Elements 0 and 1 of computed_faces always describe the
107 default and mode-line faces.
109 Elements 0 and 1 of computed_faces have GC's; all the other faces
110 in computed_faces do not. The global array face_vector contains
111 faces with their GC's set. Given a computed_face, the function
112 intern_face finds (or adds) an element of face_vector with
113 equivalent parameters, and returns a pointer to that face, whose GC
114 can then be used for display.
118 Symbols naming faces must have associations on all frames; for any
119 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist
120 FRAME)) is non-nil, it must be non-nil for all frames.
122 Analogously, indices into param_faces must be valid on all frames;
123 if param_faces[i] is a non-zero face pointer on one frame, then it
124 must be filled in on all frames. Code assumes that face ID's can
125 be used on any frame.
129 Why do we keep param_faces and computed_faces separate?
130 computed_faces contains an element for every combination of facial
131 parameters we have ever displayed. indices into param_faces have
132 to be valid on all frames. If they were the same array, then that
133 array would grow very large on all frames, because any facial
134 combination displayed on any frame would need to be a valid entry
137 Since face_vector is just a cache --- there are no pointers into it
138 from the rest of the code, and everyone accesses it through
139 intern_face --- we could just free its GC's and throw the whole
140 thing away without breaking anything. This gives us a simple way
141 to garbage-collect old GC's nobody's using any more - we can just
142 purge face_vector, and then let subsequent calls to intern_face
143 refill it as needed. The function clear_face_vector performs this
146 We're often applying intern_face to faces in computed_faces -
147 for example, we do this while sending GLYPHs from a struct
148 frame_glyphs to X during redisplay. It would be nice to avoid
149 searching all of face_vector every time we intern a frame's face.
150 So, when intern_face finds a match for FACE in face_vector, it
151 stores the index of the match in FACE's cached_index member, and
152 checks there first next time. */
155 /* Definitions and declarations. */
157 /* A table of display faces. */
158 static struct face
**face_vector
;
159 /* The length in use of the table. */
161 /* The allocated length of the table. */
162 static int nfaces_allocated
;
164 /* The number of face-id's in use (same for all frames). */
167 /* The number of the face to use to indicate the region. */
170 /* This is what appears in a slot in a face to signify that the face
171 does not specify that display aspect. */
172 #define FACE_DEFAULT (~0)
174 Lisp_Object Qface
, Qmouse_face
;
176 static void build_face ( /* FRAME_PTR, struct face * */ );
177 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ );
179 struct face
*intern_face ( /* FRAME_PTR, struct face * */ );
180 static int new_computed_face ( /* FRAME_PTR, struct face * */ );
181 static int intern_computed_face ( /* FRAME_PTR, struct face * */ );
182 static void ensure_face_ready ( /* FRAME_PTR, int id */ );
183 void recompute_basic_faces ( /* FRAME_PTR f */ );
185 /* Allocating, copying, and comparing struct faces. */
187 /* Allocate a new face */
191 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
192 bzero (result
, sizeof (struct face
));
193 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
194 result
->foreground
= FACE_DEFAULT
;
195 result
->background
= FACE_DEFAULT
;
196 result
->stipple
= FACE_DEFAULT
;
200 /* Make a new face that's a copy of an existing one. */
205 struct face
*result
= allocate_face ();
207 result
->font
= face
->font
;
208 result
->foreground
= face
->foreground
;
209 result
->background
= face
->background
;
210 result
->stipple
= face
->stipple
;
211 result
->underline
= face
->underline
;
217 face_eql (face1
, face2
)
218 struct face
*face1
, *face2
;
220 return ( face1
->font
== face2
->font
221 && face1
->foreground
== face2
->foreground
222 && face1
->background
== face2
->background
223 && face1
->stipple
== face2
->stipple
224 && face1
->underline
== face2
->underline
);
227 /* Interning faces in the `face_vector' cache, and clearing that cache. */
229 /* Return the unique display face corresponding to the user-level face FACE.
230 If there isn't one, make one, and find a slot in the face_vector to
233 get_cached_face (f
, face
)
240 /* Perhaps FACE->cached_index is valid; this could happen if FACE is
241 in a frame's face list. */
242 if (face
->cached_index
>= 0
243 && face
->cached_index
< nfaces
244 && face_eql (face_vector
[face
->cached_index
], face
))
245 return face_vector
[face
->cached_index
];
247 /* Look for an existing display face that does the job.
248 Also find an empty slot if any. */
249 for (i
= 0; i
< nfaces
; i
++)
251 if (face_eql (face_vector
[i
], face
))
253 face
->cached_index
= i
;
254 return face_vector
[i
];
256 if (face_vector
[i
] == 0)
260 /* If no empty slots, make one. */
261 if (empty
< 0 && nfaces
== nfaces_allocated
)
263 int newsize
= nfaces
+ 20;
265 = (struct face
**) xrealloc (face_vector
,
266 newsize
* sizeof (struct face
*));
267 nfaces_allocated
= newsize
;
273 /* Put a new display face in the empty slot. */
274 result
= copy_face (face
);
275 face_vector
[empty
] = result
;
277 /* Make a graphics context for it. */
278 build_face (f
, result
);
280 face
->cached_index
= empty
;
284 /* Given a computed face, return an equivalent display face
285 (one which has a graphics context). */
288 intern_face (f
, face
)
292 /* If it's equivalent to the default face, use that. */
293 if (face_eql (face
, FRAME_DEFAULT_FACE (f
)))
295 if (!FRAME_DEFAULT_FACE (f
)->gc
)
296 build_face (f
, FRAME_DEFAULT_FACE (f
));
297 return FRAME_DEFAULT_FACE (f
);
300 /* If it's equivalent to the mode line face, use that. */
301 if (face_eql (face
, FRAME_MODE_LINE_FACE (f
)))
303 if (!FRAME_MODE_LINE_FACE (f
)->gc
)
304 build_face (f
, FRAME_MODE_LINE_FACE (f
));
305 return FRAME_MODE_LINE_FACE (f
);
308 /* If it's not one of the frame's default faces, it shouldn't have a GC. */
312 /* Get a specialized display face. */
313 return get_cached_face (f
, face
);
316 /* Clear out face_vector and start anew.
317 This should be done from time to time just to avoid
318 keeping too many graphics contexts in face_vector
319 that are no longer needed. */
325 Display
*dpy
= x_current_display
;
329 /* Free the display faces in the face_vector. */
330 for (i
= 0; i
< nfaces
; i
++)
332 struct face
*face
= face_vector
[i
];
334 XFreeGC (dpy
, face
->gc
);
342 /* Allocating and freeing X resources for display faces. */
344 /* Make a graphics context for face FACE, which is on frame F,
345 if that can be done. */
357 if (face
->foreground
!= FACE_DEFAULT
)
358 xgcv
.foreground
= face
->foreground
;
360 xgcv
.foreground
= f
->display
.x
->foreground_pixel
;
362 if (face
->background
!= FACE_DEFAULT
)
363 xgcv
.background
= face
->background
;
365 xgcv
.background
= f
->display
.x
->background_pixel
;
367 if (face
->font
&& (int) face
->font
!= FACE_DEFAULT
)
368 xgcv
.font
= face
->font
->fid
;
370 xgcv
.font
= f
->display
.x
->font
->fid
;
372 xgcv
.graphics_exposures
= 0;
374 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
375 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
379 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
380 XSetStipple (x_current_display
, gc
, face
->stipple
);
388 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. */
398 return (XFontStruct
*) FACE_DEFAULT
;
400 CHECK_STRING (name
, 0);
402 font
= XLoadQueryFont (x_current_display
, (char *) XSTRING (name
)->data
);
406 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
407 Fcons (name
, Qnil
)));
412 unload_font (f
, font
)
416 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
420 XFreeFont (x_current_display
, font
);
429 Display
*dpy
= x_current_display
;
437 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
439 CHECK_STRING (name
, 0);
441 result
= XParseColor (dpy
, cmap
, (char *) XSTRING (name
)->data
, &color
);
444 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
445 Fcons (name
, Qnil
)));
447 result
= XAllocColor (dpy
, cmap
, &color
);
450 Fsignal (Qerror
, Fcons (build_string ("X server cannot allocate color"),
451 Fcons (name
, Qnil
)));
452 return (unsigned long) color
.pixel
;
456 unload_color (f
, pixel
)
460 /* Since faces get built by copying parameters from other faces, the
461 allocation counts for the colors get all screwed up. I don't see
462 any solution that will take less than 10 minutes, and it's better
463 to have a color leak than a crash, so I'm just dyking this out.
464 This isn't really a color leak, anyway - if we ask for it again,
465 we'll get the same pixel. */
468 Display
*dpy
= x_current_display
;
469 if (pixel
== FACE_DEFAULT
470 || pixel
== BLACK_PIX_DEFAULT
471 || pixel
== WHITE_PIX_DEFAULT
)
473 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
475 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
480 /* Managing parameter face arrays for frames. */
486 ensure_face_ready (f
, 0);
487 ensure_face_ready (f
, 1);
489 FRAME_N_COMPUTED_FACES (f
) = 0;
490 FRAME_SIZE_COMPUTED_FACES (f
) = 0;
492 new_computed_face (f
, FRAME_PARAM_FACES (f
)[0]);
493 new_computed_face (f
, FRAME_PARAM_FACES (f
)[1]);
494 recompute_basic_faces (f
);
496 /* Find another X frame. */
498 Lisp_Object tail
, frame
, result
;
501 FOR_EACH_FRAME (tail
, frame
)
502 if (FRAME_X_P (XFRAME (frame
))
503 && XFRAME (frame
) != f
)
509 /* If we didn't find any X frames other than f, then we don't need
510 any faces other than 0 and 1, so we're okay. Otherwise, make
511 sure that all faces valid on the selected frame are also valid
512 on this new frame. */
516 int n_faces
= FRAME_N_PARAM_FACES (XFRAME (result
));
517 struct face
**faces
= FRAME_PARAM_FACES (XFRAME (result
));
519 for (i
= 2; i
< n_faces
; i
++)
521 ensure_face_ready (f
, i
);
527 /* Called from Fdelete_frame. */
532 Display
*dpy
= x_current_display
;
537 for (i
= 0; i
< FRAME_N_PARAM_FACES (f
); i
++)
539 struct face
*face
= FRAME_PARAM_FACES (f
) [i
];
543 XFreeGC (dpy
, face
->gc
);
544 unload_font (f
, face
->font
);
545 unload_color (f
, face
->foreground
);
546 unload_color (f
, face
->background
);
548 unload_pixmap (f
, face
->stipple
);
553 xfree (FRAME_PARAM_FACES (f
));
554 FRAME_PARAM_FACES (f
) = 0;
555 FRAME_N_PARAM_FACES (f
) = 0;
557 /* All faces in FRAME_COMPUTED_FACES use resources copied from
558 FRAME_PARAM_FACES; we can free them without fuss. */
559 xfree (FRAME_COMPUTED_FACES (f
));
560 FRAME_COMPUTED_FACES (f
) = 0;
561 FRAME_N_COMPUTED_FACES (f
) = 0;
566 /* Interning faces in a frame's face array. */
569 new_computed_face (f
, new_face
)
571 struct face
*new_face
;
573 int i
= FRAME_N_COMPUTED_FACES (f
);
575 if (i
>= FRAME_SIZE_COMPUTED_FACES (f
))
577 int new_size
= i
+ 32;
579 FRAME_COMPUTED_FACES (f
)
580 = (struct face
**) (FRAME_SIZE_COMPUTED_FACES (f
) == 0
581 ? xmalloc (new_size
* sizeof (struct face
*))
582 : xrealloc (FRAME_COMPUTED_FACES (f
),
583 new_size
* sizeof (struct face
*)));
584 FRAME_SIZE_COMPUTED_FACES (f
) = new_size
;
587 i
= FRAME_N_COMPUTED_FACES (f
)++;
588 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
593 /* Find a match for NEW_FACE in a FRAME's computed face array, and add
594 it if we don't find one. */
596 intern_computed_face (f
, new_face
)
598 struct face
*new_face
;
600 int len
= FRAME_N_COMPUTED_FACES (f
);
603 /* Search for a computed face already on F equivalent to FACE. */
604 for (i
= 0; i
< len
; i
++)
606 if (! FRAME_COMPUTED_FACES (f
)[i
])
608 if (face_eql (new_face
, FRAME_COMPUTED_FACES (f
)[i
]))
612 /* We didn't find one; add a new one. */
613 return new_computed_face (f
, new_face
);
616 /* Make parameter face id ID valid on frame F. */
619 ensure_face_ready (f
, id
)
623 if (FRAME_N_PARAM_FACES (f
) <= id
)
627 if (!FRAME_N_PARAM_FACES (f
))
628 FRAME_PARAM_FACES (f
)
629 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
631 FRAME_PARAM_FACES (f
)
632 = (struct face
**) xrealloc (FRAME_PARAM_FACES (f
),
633 sizeof (struct face
*) * n
);
635 bzero (FRAME_PARAM_FACES (f
) + FRAME_N_PARAM_FACES (f
),
636 (n
- FRAME_N_PARAM_FACES (f
)) * sizeof (struct face
*));
637 FRAME_N_PARAM_FACES (f
) = n
;
640 if (FRAME_PARAM_FACES (f
) [id
] == 0)
641 FRAME_PARAM_FACES (f
) [id
] = allocate_face ();
644 /* Return non-zero if FONT1 and FONT2 have the same width.
645 We do not check the height, because we can now deal with
647 We assume that they're both character-cell fonts. */
650 same_size_fonts (font1
, font2
)
651 XFontStruct
*font1
, *font2
;
653 XCharStruct
*bounds1
= &font1
->min_bounds
;
654 XCharStruct
*bounds2
= &font2
->min_bounds
;
656 return (bounds1
->width
== bounds2
->width
);
659 /* Update the line_height of frame F according to the biggest font in
660 any face. Return nonzero if if line_height changes. */
663 frame_update_line_height (f
)
667 int biggest
= FONT_HEIGHT (f
->display
.x
->font
);
669 for (i
= 0; i
< f
->display
.x
->n_param_faces
; i
++)
670 if (f
->display
.x
->param_faces
[i
] != 0
671 && f
->display
.x
->param_faces
[i
]->font
!= (XFontStruct
*) FACE_DEFAULT
)
673 int height
= FONT_HEIGHT (f
->display
.x
->param_faces
[i
]->font
);
674 if (height
> biggest
)
678 if (biggest
== f
->display
.x
->line_height
)
681 f
->display
.x
->line_height
= biggest
;
685 /* Modify face TO by copying from FROM all properties which have
686 nondefault settings. */
689 merge_faces (from
, to
)
690 struct face
*from
, *to
;
692 /* Only merge the font if it's the same width as the base font.
693 Otherwise ignore it, since we can't handle it properly. */
694 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
695 && same_size_fonts (from
->font
, to
->font
))
696 to
->font
= from
->font
;
697 if (from
->foreground
!= FACE_DEFAULT
)
698 to
->foreground
= from
->foreground
;
699 if (from
->background
!= FACE_DEFAULT
)
700 to
->background
= from
->background
;
701 if (from
->stipple
!= FACE_DEFAULT
)
702 to
->stipple
= from
->stipple
;
704 to
->underline
= from
->underline
;
707 /* Set up the basic set of facial parameters, based on the frame's
708 data; all faces are deltas applied to this. */
711 compute_base_face (f
, face
)
715 struct x_display
*d
= f
->display
.x
;
718 face
->foreground
= d
->foreground_pixel
;
719 face
->background
= d
->background_pixel
;
720 face
->font
= d
->font
;
724 /* Avoid a face comparison by making this invalid. */
725 face
->cached_index
= -1;
728 /* Return the face ID to use to display a special glyph which selects
729 FACE_CODE as the face ID, assuming that ordinarily the face would
730 be CURRENT_FACE. F is the frame. */
733 compute_glyph_face (f
, face_code
, current_face
)
735 int face_code
, current_face
;
739 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
741 if (face_code
>= 0 && face_code
< FRAME_N_PARAM_FACES (f
)
742 && FRAME_PARAM_FACES (f
) [face_code
] != 0)
743 merge_faces (FRAME_PARAM_FACES (f
) [face_code
], &face
);
745 return intern_computed_face (f
, &face
);
748 /* Return the face ID to use to display a special glyph which selects
749 FACE_CODE as the face ID, assuming that ordinarily the face would
750 be CURRENT_FACE. F is the frame. */
753 compute_glyph_face_1 (f
, face_name
, current_face
)
755 Lisp_Object face_name
;
760 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
762 if (!NILP (face_name
))
764 int facecode
= face_name_id_number (f
, face_name
);
765 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
766 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
767 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
770 return intern_computed_face (f
, &face
);
773 /* Return the face ID associated with a buffer position POS.
774 Store into *ENDPTR the position at which a different face is needed.
775 This does not take account of glyphs that specify their own face codes.
776 F is the frame in use for display, and W is a window displaying
779 REGION_BEG, REGION_END delimit the region, so it can be highlighted.
781 LIMIT is a position not to scan beyond. That is to limit
782 the time this function can take.
784 If MOUSE is nonzero, use the character's mouse-face, not its face. */
787 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
, limit
, mouse
)
791 int region_beg
, region_end
;
797 Lisp_Object prop
, position
;
800 Lisp_Object
*overlay_vec
;
803 Lisp_Object propname
;
805 /* W must display the current buffer. We could write this function
806 to use the frame and buffer of W, but right now it doesn't. */
807 if (XBUFFER (w
->buffer
) != current_buffer
)
810 XSET (frame
, Lisp_Frame
, f
);
813 if (pos
< region_beg
&& region_beg
< endpos
)
816 XFASTINT (position
) = pos
;
819 propname
= Qmouse_face
;
823 prop
= Fget_text_property (position
, propname
, w
->buffer
);
826 Lisp_Object limit1
, end
;
828 XFASTINT (limit1
) = (limit
< endpos
? limit
: endpos
);
829 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
838 /* First try with room for 40 overlays. */
840 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
842 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
, NULL
);
844 /* If there are more than 40,
845 make enough space for all, and try again. */
849 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
850 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
851 &next_overlay
, NULL
);
854 if (next_overlay
< endpos
)
855 endpos
= next_overlay
;
860 /* Optimize the default case. */
861 if (noverlays
== 0 && NILP (prop
)
862 && !(pos
>= region_beg
&& pos
< region_end
))
865 compute_base_face (f
, &face
);
869 facecode
= face_name_id_number (f
, prop
);
870 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
871 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
872 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
875 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
877 /* Now merge the overlay data in that order. */
878 for (i
= 0; i
< noverlays
; i
++)
880 prop
= Foverlay_get (overlay_vec
[i
], propname
);
886 facecode
= face_name_id_number (f
, prop
);
887 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
888 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
889 merge_faces (FRAME_PARAM_FACES (f
)[facecode
], &face
);
891 oend
= OVERLAY_END (overlay_vec
[i
]);
892 oendpos
= OVERLAY_POSITION (oend
);
893 if (oendpos
< endpos
)
898 if (pos
>= region_beg
&& pos
< region_end
)
900 if (region_end
< endpos
)
902 if (region_face
>= 0 && region_face
< next_face_id
)
903 merge_faces (FRAME_PARAM_FACES (f
)[region_face
], &face
);
908 return intern_computed_face (f
, &face
);
911 /* Recompute the GC's for the default and modeline faces.
912 We call this after changing frame parameters on which those GC's
916 recompute_basic_faces (f
)
919 /* If the frame's faces haven't been initialized yet, don't worry about
921 if (FRAME_N_PARAM_FACES (f
) < 2)
926 if (FRAME_DEFAULT_FACE (f
)->gc
)
927 XFreeGC (x_current_display
, FRAME_DEFAULT_FACE (f
)->gc
);
928 if (FRAME_MODE_LINE_FACE (f
)->gc
)
929 XFreeGC (x_current_display
, FRAME_MODE_LINE_FACE (f
)->gc
);
931 compute_base_face (f
, FRAME_DEFAULT_FACE (f
));
932 compute_base_face (f
, FRAME_MODE_LINE_FACE (f
));
934 merge_faces (FRAME_DEFAULT_PARAM_FACE (f
), FRAME_DEFAULT_FACE (f
));
935 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f
), FRAME_MODE_LINE_FACE (f
));
937 build_face (f
, FRAME_DEFAULT_FACE (f
));
938 build_face (f
, FRAME_MODE_LINE_FACE (f
));
945 /* Lisp interface. */
947 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
952 CHECK_FRAME (frame
, 0);
953 return XFRAME (frame
)->face_alist
;
956 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
959 Lisp_Object frame
, value
;
961 CHECK_FRAME (frame
, 0);
962 XFRAME (frame
)->face_alist
= value
;
967 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
968 "Create face number FACE-ID on all frames.")
973 int id
= XINT (face_id
);
975 CHECK_NUMBER (face_id
, 0);
976 if (id
< 0 || id
>= next_face_id
)
977 error ("Face id out of range");
979 for (rest
= Vframe_list
; !NILP (rest
); rest
= XCONS (rest
)->cdr
)
981 struct frame
*f
= XFRAME (XCONS (rest
)->car
);
983 ensure_face_ready (f
, id
);
989 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
990 Sset_face_attribute_internal
, 4, 4, 0, "")
991 (face_id
, attr_name
, attr_value
, frame
)
992 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
1000 CHECK_FRAME (frame
, 0);
1001 CHECK_NUMBER (face_id
, 0);
1002 CHECK_SYMBOL (attr_name
, 0);
1005 id
= XINT (face_id
);
1006 if (id
< 0 || id
>= next_face_id
)
1007 error ("Face id out of range");
1009 if (! FRAME_X_P (f
))
1012 ensure_face_ready (f
, id
);
1013 face
= FRAME_PARAM_FACES (f
) [XFASTINT (face_id
)];
1015 if (EQ (attr_name
, intern ("font")))
1017 XFontStruct
*font
= load_font (f
, attr_value
);
1018 if (face
->font
!= f
->display
.x
->font
)
1019 unload_font (f
, face
->font
);
1021 if (frame_update_line_height (f
))
1022 x_set_window_size (f
, 0, f
->width
, f
->height
);
1023 /* Must clear cache, since it might contain the font
1024 we just got rid of. */
1027 else if (EQ (attr_name
, intern ("foreground")))
1029 unsigned long new_color
= load_color (f
, attr_value
);
1030 unload_color (f
, face
->foreground
);
1031 face
->foreground
= new_color
;
1034 else if (EQ (attr_name
, intern ("background")))
1036 unsigned long new_color
= load_color (f
, attr_value
);
1037 unload_color (f
, face
->background
);
1038 face
->background
= new_color
;
1042 else if (EQ (attr_name
, intern ("background-pixmap")))
1044 unsigned int w
, h
, d
;
1045 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
, &d
, 0);
1046 unload_pixmap (f
, face
->stipple
);
1047 if (NILP (attr_value
))
1049 face
->stipple
= new_pixmap
;
1052 /* face->pixmap_depth = d; */
1055 else if (EQ (attr_name
, intern ("underline")))
1057 int new = !NILP (attr_value
);
1058 face
->underline
= new;
1061 error ("unknown face attribute");
1063 if (id
== 0 || id
== 1)
1064 recompute_basic_faces (f
);
1066 /* We must redraw the frame whenever any face font or color changes,
1067 because it's possible that a merged (display) face
1068 contains the font or color we just replaced.
1069 And we must inhibit any Expose events until the redraw is done,
1070 since they would try to use the invalid display faces. */
1072 SET_FRAME_GARBAGED (f
);
1077 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1081 return make_number (next_face_id
++);
1084 /* Return the face id for name NAME on frame FRAME.
1085 (It should be the same for all frames,
1086 but it's as easy to use the "right" frame to look it up
1087 as to use any other one.) */
1090 face_name_id_number (f
, name
)
1096 tem
= Fcdr (assq_no_quit (name
, f
->face_alist
));
1099 CHECK_VECTOR (tem
, 0);
1100 tem
= XVECTOR (tem
)->contents
[2];
1101 CHECK_NUMBER (tem
, 0);
1105 /* Emacs initialization. */
1110 Qface
= intern ("face");
1112 Qmouse_face
= intern ("mouse-face");
1113 staticpro (&Qmouse_face
);
1115 DEFVAR_INT ("region-face", ®ion_face
,
1116 "Face number to use to highlight the region\n\
1117 The region is highlighted with this face\n\
1118 when Transient Mark mode is enabled and the mark is active.");
1120 defsubr (&Sframe_face_alist
);
1121 defsubr (&Sset_frame_face_alist
);
1122 defsubr (&Smake_face_internal
);
1123 defsubr (&Sset_face_attribute_internal
);
1124 defsubr (&Sinternal_next_face_id
);
1127 #endif /* HAVE_X_WINDOWS */