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 Each computed face belongs to a particular frame.
111 Computed faces have graphics contexts some of the time.
112 intern_face builds a GC for a specified computed face
113 if it doesn't have one already.
114 clear_face_cache clears out the GCs of all computed faces.
115 This is done from time to time so that we don't hold on to
116 lots of GCs that are no longer needed.
120 Symbols naming faces must have associations on all frames; for any
121 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist
122 FRAME)) is non-nil, it must be non-nil for all frames.
124 Analogously, indices into param_faces must be valid on all frames;
125 if param_faces[i] is a non-zero face pointer on one frame, then it
126 must be filled in on all frames. Code assumes that face ID's can
127 be used on any frame.
131 Why do we keep param_faces and computed_faces separate?
132 computed_faces contains an element for every combination of facial
133 parameters we have ever displayed. indices into param_faces have
134 to be valid on all frames. If they were the same array, then that
135 array would grow very large on all frames, because any facial
136 combination displayed on any frame would need to be a valid entry
139 /* Definitions and declarations. */
141 /* The number of face-id's in use (same for all frames). */
144 /* The number of the face to use to indicate the region. */
147 /* This is what appears in a slot in a face to signify that the face
148 does not specify that display aspect. */
149 #define FACE_DEFAULT (~0)
151 Lisp_Object Qface
, Qmouse_face
;
152 Lisp_Object Qpixmap_spec_p
;
154 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ );
156 struct face
*intern_face ( /* FRAME_PTR, struct face * */ );
157 static int new_computed_face ( /* FRAME_PTR, struct face * */ );
158 static int intern_computed_face ( /* FRAME_PTR, struct face * */ );
159 static void ensure_face_ready ( /* FRAME_PTR, int id */ );
160 void recompute_basic_faces ( /* FRAME_PTR f */ );
162 /* Allocating, copying, and comparing struct faces. */
164 /* Allocate a new face */
168 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
169 bzero (result
, sizeof (struct face
));
170 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
171 result
->foreground
= FACE_DEFAULT
;
172 result
->background
= FACE_DEFAULT
;
173 result
->stipple
= FACE_DEFAULT
;
177 /* Make a new face that's a copy of an existing one. */
182 struct face
*result
= allocate_face ();
184 result
->font
= face
->font
;
185 result
->foreground
= face
->foreground
;
186 result
->background
= face
->background
;
187 result
->stipple
= face
->stipple
;
188 result
->underline
= face
->underline
;
189 result
->pixmap_h
= face
->pixmap_h
;
190 result
->pixmap_w
= face
->pixmap_w
;
196 face_eql (face1
, face2
)
197 struct face
*face1
, *face2
;
199 return ( face1
->font
== face2
->font
200 && face1
->foreground
== face2
->foreground
201 && face1
->background
== face2
->background
202 && face1
->stipple
== face2
->stipple
203 && face1
->underline
== face2
->underline
);
206 /* Managing graphics contexts of faces. */
208 /* Given a computed face, construct its graphics context if necessary. */
211 intern_face (f
, face
)
224 if (face
->foreground
!= FACE_DEFAULT
)
225 xgcv
.foreground
= face
->foreground
;
227 xgcv
.foreground
= f
->display
.x
->foreground_pixel
;
229 if (face
->background
!= FACE_DEFAULT
)
230 xgcv
.background
= face
->background
;
232 xgcv
.background
= f
->display
.x
->background_pixel
;
234 if (face
->font
&& (int) face
->font
!= FACE_DEFAULT
)
235 xgcv
.font
= face
->font
->fid
;
237 xgcv
.font
= f
->display
.x
->font
->fid
;
239 xgcv
.graphics_exposures
= 0;
241 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
242 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
244 xgcv
.fill_style
= FillStippled
;
245 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
246 mask
|= GCFillStyle
| GCStipple
;
249 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
259 /* Clear out all graphics contexts for all computed faces
260 except for the default and mode line faces.
261 This should be done from time to time just to avoid
262 keeping too many graphics contexts that are no longer needed. */
267 Lisp_Object tail
, frame
;
270 FOR_EACH_FRAME (tail
, frame
)
272 FRAME_PTR f
= XFRAME (frame
);
276 Display
*dpy
= FRAME_X_DISPLAY (f
);
278 for (i
= 2; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
280 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
282 XFreeGC (dpy
, face
->gc
);
291 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps.
293 These functions operate on param faces only.
294 Computed faces get their fonts, colors and pixmaps
295 by merging param faces. */
305 return (XFontStruct
*) FACE_DEFAULT
;
307 CHECK_STRING (name
, 0);
309 font
= XLoadQueryFont (FRAME_X_DISPLAY (f
), (char *) XSTRING (name
)->data
);
313 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
314 Fcons (name
, Qnil
)));
319 unload_font (f
, font
)
323 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
327 XFreeFont (FRAME_X_DISPLAY (f
), font
);
336 Display
*dpy
= FRAME_X_DISPLAY (f
);
344 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy
));
346 CHECK_STRING (name
, 0);
348 result
= XParseColor (dpy
, cmap
, (char *) XSTRING (name
)->data
, &color
);
351 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
352 Fcons (name
, Qnil
)));
354 result
= XAllocColor (dpy
, cmap
, &color
);
357 Fsignal (Qerror
, Fcons (build_string ("X server cannot allocate color"),
358 Fcons (name
, Qnil
)));
359 return (unsigned long) color
.pixel
;
363 unload_color (f
, pixel
)
368 Display
*dpy
= FRAME_X_DISPLAY (f
);
369 if (pixel
== FACE_DEFAULT
370 || pixel
== BLACK_PIX_DEFAULT
371 || pixel
== WHITE_PIX_DEFAULT
)
373 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy
));
375 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
379 DEFUN ("pixmap-spec-p", Fpixmap_spec_p
, Spixmap_spec_p
, 1, 1, 0,
380 "Return t if ARG is a valid pixmap specification.")
384 Lisp_Object height
, width
;
386 return ((STRINGP (arg
)
388 && CONSP (Fcdr (arg
))
389 && CONSP (Fcdr (Fcdr (arg
)))
390 && NILP (Fcdr (Fcdr (Fcdr (arg
))))
391 && INTEGERP (width
= Fcar (arg
))
392 && INTEGERP (height
= Fcar (Fcdr (arg
)))
393 && STRINGP (Fcar (Fcdr (Fcdr (arg
))))
396 /* The string must have enough bits for width * height. */
397 && (XINT (width
) * XINT (height
)
398 <= (XSTRING (Fcar (Fcdr (Fcdr (arg
))))->size
399 * (INTBITS
/ sizeof (int))))))
403 /* Load a bitmap according to NAME (which is either a file name
404 or a pixmap spec). Return the bitmap_id (see xfns.c)
405 or get an error if NAME is invalid.
407 Store the bitmap width in *W_PTR and height in *H_PTR. */
410 load_pixmap (f
, name
, w_ptr
, h_ptr
)
413 unsigned int *w_ptr
, *h_ptr
;
421 tem
= Fpixmap_spec_p (name
);
423 wrong_type_argument (Qpixmap_spec_p
, name
);
429 /* Decode a bitmap spec into a bitmap. */
434 w
= XINT (Fcar (name
));
435 h
= XINT (Fcar (Fcdr (name
)));
436 bits
= Fcar (Fcdr (Fcdr (name
)));
438 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
443 /* It must be a string -- a file name. */
444 bitmap_id
= x_create_bitmap_from_file (f
, name
);
449 Fsignal (Qerror
, Fcons (build_string ("undefined bitmap"),
450 Fcons (name
, Qnil
)));
452 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
453 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
458 /* Managing parameter face arrays for frames. */
464 ensure_face_ready (f
, 0);
465 ensure_face_ready (f
, 1);
467 FRAME_N_COMPUTED_FACES (f
) = 0;
468 FRAME_SIZE_COMPUTED_FACES (f
) = 0;
470 new_computed_face (f
, FRAME_PARAM_FACES (f
)[0]);
471 new_computed_face (f
, FRAME_PARAM_FACES (f
)[1]);
472 recompute_basic_faces (f
);
474 /* Find another X frame. */
476 Lisp_Object tail
, frame
, result
;
479 FOR_EACH_FRAME (tail
, frame
)
480 if (FRAME_X_P (XFRAME (frame
))
481 && XFRAME (frame
) != f
)
487 /* If we didn't find any X frames other than f, then we don't need
488 any faces other than 0 and 1, so we're okay. Otherwise, make
489 sure that all faces valid on the selected frame are also valid
490 on this new frame. */
494 int n_faces
= FRAME_N_PARAM_FACES (XFRAME (result
));
495 struct face
**faces
= FRAME_PARAM_FACES (XFRAME (result
));
497 for (i
= 2; i
< n_faces
; i
++)
499 ensure_face_ready (f
, i
);
505 /* Called from Fdelete_frame. */
511 Display
*dpy
= FRAME_X_DISPLAY (f
);
516 for (i
= 0; i
< FRAME_N_PARAM_FACES (f
); i
++)
518 struct face
*face
= FRAME_PARAM_FACES (f
) [i
];
521 unload_font (f
, face
->font
);
522 unload_color (f
, face
->foreground
);
523 unload_color (f
, face
->background
);
524 x_destroy_bitmap (f
, face
->stipple
);
528 xfree (FRAME_PARAM_FACES (f
));
529 FRAME_PARAM_FACES (f
) = 0;
530 FRAME_N_PARAM_FACES (f
) = 0;
532 /* All faces in FRAME_COMPUTED_FACES use resources copied from
533 FRAME_PARAM_FACES; we can free them without fuss.
534 But we do free the GCs and the face objects themselves. */
535 for (i
= 0; i
< FRAME_N_COMPUTED_FACES (f
); i
++)
537 struct face
*face
= FRAME_COMPUTED_FACES (f
) [i
];
541 XFreeGC (dpy
, face
->gc
);
545 xfree (FRAME_COMPUTED_FACES (f
));
546 FRAME_COMPUTED_FACES (f
) = 0;
547 FRAME_N_COMPUTED_FACES (f
) = 0;
552 /* Interning faces in a frame's face array. */
555 new_computed_face (f
, new_face
)
557 struct face
*new_face
;
559 int i
= FRAME_N_COMPUTED_FACES (f
);
561 if (i
>= FRAME_SIZE_COMPUTED_FACES (f
))
563 int new_size
= i
+ 32;
565 FRAME_COMPUTED_FACES (f
)
566 = (struct face
**) (FRAME_SIZE_COMPUTED_FACES (f
) == 0
567 ? xmalloc (new_size
* sizeof (struct face
*))
568 : xrealloc (FRAME_COMPUTED_FACES (f
),
569 new_size
* sizeof (struct face
*)));
570 FRAME_SIZE_COMPUTED_FACES (f
) = new_size
;
573 i
= FRAME_N_COMPUTED_FACES (f
)++;
574 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
579 /* Find a match for NEW_FACE in a FRAME's computed face array, and add
580 it if we don't find one. */
582 intern_computed_face (f
, new_face
)
584 struct face
*new_face
;
586 int len
= FRAME_N_COMPUTED_FACES (f
);
589 /* Search for a computed face already on F equivalent to FACE. */
590 for (i
= 0; i
< len
; i
++)
592 if (! FRAME_COMPUTED_FACES (f
)[i
])
594 if (face_eql (new_face
, FRAME_COMPUTED_FACES (f
)[i
]))
598 /* We didn't find one; add a new one. */
599 return new_computed_face (f
, new_face
);
602 /* Make parameter face id ID valid on frame F. */
605 ensure_face_ready (f
, id
)
609 if (FRAME_N_PARAM_FACES (f
) <= id
)
613 if (!FRAME_N_PARAM_FACES (f
))
614 FRAME_PARAM_FACES (f
)
615 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
617 FRAME_PARAM_FACES (f
)
618 = (struct face
**) xrealloc (FRAME_PARAM_FACES (f
),
619 sizeof (struct face
*) * n
);
621 bzero (FRAME_PARAM_FACES (f
) + FRAME_N_PARAM_FACES (f
),
622 (n
- FRAME_N_PARAM_FACES (f
)) * sizeof (struct face
*));
623 FRAME_N_PARAM_FACES (f
) = n
;
626 if (FRAME_PARAM_FACES (f
) [id
] == 0)
627 FRAME_PARAM_FACES (f
) [id
] = allocate_face ();
630 /* Return non-zero if FONT1 and FONT2 have the same width.
631 We do not check the height, because we can now deal with
633 We assume that they're both character-cell fonts. */
636 same_size_fonts (font1
, font2
)
637 XFontStruct
*font1
, *font2
;
639 XCharStruct
*bounds1
= &font1
->min_bounds
;
640 XCharStruct
*bounds2
= &font2
->min_bounds
;
642 return (bounds1
->width
== bounds2
->width
);
645 /* Update the line_height of frame F according to the biggest font in
646 any face. Return nonzero if if line_height changes. */
649 frame_update_line_height (f
)
653 int biggest
= FONT_HEIGHT (f
->display
.x
->font
);
655 for (i
= 0; i
< f
->display
.x
->n_param_faces
; i
++)
656 if (f
->display
.x
->param_faces
[i
] != 0
657 && f
->display
.x
->param_faces
[i
]->font
!= (XFontStruct
*) FACE_DEFAULT
)
659 int height
= FONT_HEIGHT (f
->display
.x
->param_faces
[i
]->font
);
660 if (height
> biggest
)
664 if (biggest
== f
->display
.x
->line_height
)
667 f
->display
.x
->line_height
= biggest
;
671 /* Modify face TO by copying from FROM all properties which have
672 nondefault settings. */
675 merge_faces (from
, to
)
676 struct face
*from
, *to
;
678 /* Only merge the font if it's the same width as the base font.
679 Otherwise ignore it, since we can't handle it properly. */
680 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
681 && same_size_fonts (from
->font
, to
->font
))
682 to
->font
= from
->font
;
683 if (from
->foreground
!= FACE_DEFAULT
)
684 to
->foreground
= from
->foreground
;
685 if (from
->background
!= FACE_DEFAULT
)
686 to
->background
= from
->background
;
687 if (from
->stipple
!= FACE_DEFAULT
)
689 to
->stipple
= from
->stipple
;
690 to
->pixmap_h
= from
->pixmap_h
;
691 to
->pixmap_w
= from
->pixmap_w
;
694 to
->underline
= from
->underline
;
697 /* Set up the basic set of facial parameters, based on the frame's
698 data; all faces are deltas applied to this. */
701 compute_base_face (f
, face
)
706 face
->foreground
= FRAME_FOREGROUND_PIXEL (f
);
707 face
->background
= FRAME_BACKGROUND_PIXEL (f
);
708 face
->font
= FRAME_FONT (f
);
713 /* Return the face ID to use to display a special glyph which selects
714 FACE_CODE as the face ID, assuming that ordinarily the face would
715 be CURRENT_FACE. F is the frame. */
718 compute_glyph_face (f
, face_code
, current_face
)
720 int face_code
, current_face
;
724 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
726 if (face_code
>= 0 && face_code
< FRAME_N_PARAM_FACES (f
)
727 && FRAME_PARAM_FACES (f
) [face_code
] != 0)
728 merge_faces (FRAME_PARAM_FACES (f
) [face_code
], &face
);
730 return intern_computed_face (f
, &face
);
733 /* Return the face ID to use to display a special glyph which selects
734 FACE_CODE as the face ID, assuming that ordinarily the face would
735 be CURRENT_FACE. F is the frame. */
738 compute_glyph_face_1 (f
, face_name
, current_face
)
740 Lisp_Object face_name
;
745 face
= *FRAME_COMPUTED_FACES (f
)[current_face
];
747 if (!NILP (face_name
))
749 int facecode
= face_name_id_number (f
, face_name
);
750 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
751 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
752 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
755 return intern_computed_face (f
, &face
);
758 /* Return the face ID associated with a buffer position POS.
759 Store into *ENDPTR the position at which a different face is needed.
760 This does not take account of glyphs that specify their own face codes.
761 F is the frame in use for display, and W is a window displaying
764 REGION_BEG, REGION_END delimit the region, so it can be highlighted.
766 LIMIT is a position not to scan beyond. That is to limit
767 the time this function can take.
769 If MOUSE is nonzero, use the character's mouse-face, not its face. */
772 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
, limit
, mouse
)
776 int region_beg
, region_end
;
782 Lisp_Object prop
, position
;
785 Lisp_Object
*overlay_vec
;
788 Lisp_Object propname
;
790 /* W must display the current buffer. We could write this function
791 to use the frame and buffer of W, but right now it doesn't. */
792 if (XBUFFER (w
->buffer
) != current_buffer
)
795 XSETFRAME (frame
, f
);
798 if (pos
< region_beg
&& region_beg
< endpos
)
801 XSETFASTINT (position
, pos
);
804 propname
= Qmouse_face
;
808 prop
= Fget_text_property (position
, propname
, w
->buffer
);
811 Lisp_Object limit1
, end
;
813 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
814 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
823 /* First try with room for 40 overlays. */
825 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
827 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
, NULL
);
829 /* If there are more than 40,
830 make enough space for all, and try again. */
834 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
835 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
836 &next_overlay
, NULL
);
839 if (next_overlay
< endpos
)
840 endpos
= next_overlay
;
845 /* Optimize the default case. */
846 if (noverlays
== 0 && NILP (prop
)
847 && !(pos
>= region_beg
&& pos
< region_end
))
850 compute_base_face (f
, &face
);
854 /* We have a list of faces, merge them in reverse order */
855 Lisp_Object length
= Flength (prop
);
856 int len
= XINT (length
);
859 /* Put them into an array */
860 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
861 for (j
= 0; j
< len
; j
++)
863 faces
[j
] = Fcar (prop
);
866 /* So that we can merge them in the reverse order */
867 for (j
= len
- 1; j
>= 0; j
--)
869 facecode
= face_name_id_number (f
, faces
[j
]);
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 else if (!NILP (prop
))
877 facecode
= face_name_id_number (f
, prop
);
878 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
879 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
880 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
883 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
885 /* Now merge the overlay data in that order. */
886 for (i
= 0; i
< noverlays
; i
++)
888 prop
= Foverlay_get (overlay_vec
[i
], propname
);
891 /* We have a list of faces, merge them in reverse order */
892 Lisp_Object length
= Flength (prop
);
893 int len
= XINT (length
);
897 /* Put them into an array */
898 faces
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
899 for (j
= 0; j
< len
; j
++)
901 faces
[j
] = Fcar (prop
);
904 /* So that we can merge them in the reverse order */
905 for (j
= len
- 1; j
>= 0; j
--)
907 facecode
= face_name_id_number (f
, faces
[j
]);
908 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
909 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
910 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
913 else if (!NILP (prop
))
918 facecode
= face_name_id_number (f
, prop
);
919 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
920 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
921 merge_faces (FRAME_PARAM_FACES (f
)[facecode
], &face
);
923 oend
= OVERLAY_END (overlay_vec
[i
]);
924 oendpos
= OVERLAY_POSITION (oend
);
925 if (oendpos
< endpos
)
930 if (pos
>= region_beg
&& pos
< region_end
)
932 if (region_end
< endpos
)
934 if (region_face
>= 0 && region_face
< next_face_id
)
935 merge_faces (FRAME_PARAM_FACES (f
)[region_face
], &face
);
940 return intern_computed_face (f
, &face
);
943 /* Recompute the GC's for the default and modeline faces.
944 We call this after changing frame parameters on which those GC's
948 recompute_basic_faces (f
)
951 /* If the frame's faces haven't been initialized yet, don't worry about
953 if (FRAME_N_PARAM_FACES (f
) < 2)
958 if (FRAME_DEFAULT_FACE (f
)->gc
)
959 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_DEFAULT_FACE (f
)->gc
);
960 if (FRAME_MODE_LINE_FACE (f
)->gc
)
961 XFreeGC (FRAME_X_DISPLAY (f
), FRAME_MODE_LINE_FACE (f
)->gc
);
963 compute_base_face (f
, FRAME_DEFAULT_FACE (f
));
964 compute_base_face (f
, FRAME_MODE_LINE_FACE (f
));
966 merge_faces (FRAME_DEFAULT_PARAM_FACE (f
), FRAME_DEFAULT_FACE (f
));
967 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f
), FRAME_MODE_LINE_FACE (f
));
969 intern_face (f
, FRAME_DEFAULT_FACE (f
));
970 intern_face (f
, FRAME_MODE_LINE_FACE (f
));
977 /* Lisp interface. */
979 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
984 CHECK_FRAME (frame
, 0);
985 return XFRAME (frame
)->face_alist
;
988 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
991 Lisp_Object frame
, value
;
993 CHECK_FRAME (frame
, 0);
994 XFRAME (frame
)->face_alist
= value
;
999 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
1000 "Create face number FACE-ID on all frames.")
1002 Lisp_Object face_id
;
1005 int id
= XINT (face_id
);
1007 CHECK_NUMBER (face_id
, 0);
1008 if (id
< 0 || id
>= next_face_id
)
1009 error ("Face id out of range");
1011 for (rest
= Vframe_list
; !NILP (rest
); rest
= XCONS (rest
)->cdr
)
1013 struct frame
*f
= XFRAME (XCONS (rest
)->car
);
1015 ensure_face_ready (f
, id
);
1021 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
1022 Sset_face_attribute_internal
, 4, 4, 0, "")
1023 (face_id
, attr_name
, attr_value
, frame
)
1024 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
1032 CHECK_FRAME (frame
, 0);
1033 CHECK_NUMBER (face_id
, 0);
1034 CHECK_SYMBOL (attr_name
, 0);
1037 id
= XINT (face_id
);
1038 if (id
< 0 || id
>= next_face_id
)
1039 error ("Face id out of range");
1041 if (! FRAME_X_P (f
))
1044 ensure_face_ready (f
, id
);
1045 face
= FRAME_PARAM_FACES (f
) [XFASTINT (face_id
)];
1047 if (EQ (attr_name
, intern ("font")))
1049 XFontStruct
*font
= load_font (f
, attr_value
);
1050 if (face
->font
!= f
->display
.x
->font
)
1051 unload_font (f
, face
->font
);
1053 if (frame_update_line_height (f
))
1054 x_set_window_size (f
, 0, f
->width
, f
->height
);
1055 /* Must clear cache, since it might contain the font
1056 we just got rid of. */
1059 else if (EQ (attr_name
, intern ("foreground")))
1061 unsigned long new_color
= load_color (f
, attr_value
);
1062 unload_color (f
, face
->foreground
);
1063 face
->foreground
= new_color
;
1066 else if (EQ (attr_name
, intern ("background")))
1068 unsigned long new_color
= load_color (f
, attr_value
);
1069 unload_color (f
, face
->background
);
1070 face
->background
= new_color
;
1073 else if (EQ (attr_name
, intern ("background-pixmap")))
1076 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
);
1077 x_destroy_bitmap (f
, face
->stipple
);
1078 face
->stipple
= new_pixmap
;
1083 else if (EQ (attr_name
, intern ("underline")))
1085 int new = !NILP (attr_value
);
1086 face
->underline
= new;
1089 error ("unknown face attribute");
1091 if (id
== 0 || id
== 1)
1092 recompute_basic_faces (f
);
1094 /* We must redraw the frame whenever any face font or color changes,
1095 because it's possible that a merged (display) face
1096 contains the font or color we just replaced.
1097 And we must inhibit any Expose events until the redraw is done,
1098 since they would try to use the invalid display faces. */
1100 SET_FRAME_GARBAGED (f
);
1105 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1109 return make_number (next_face_id
++);
1112 /* Return the face id for name NAME on frame FRAME.
1113 (It should be the same for all frames,
1114 but it's as easy to use the "right" frame to look it up
1115 as to use any other one.) */
1118 face_name_id_number (f
, name
)
1124 tem
= Fcdr (assq_no_quit (name
, f
->face_alist
));
1127 CHECK_VECTOR (tem
, 0);
1128 tem
= XVECTOR (tem
)->contents
[2];
1129 CHECK_NUMBER (tem
, 0);
1133 /* Emacs initialization. */
1138 Qface
= intern ("face");
1140 Qmouse_face
= intern ("mouse-face");
1141 staticpro (&Qmouse_face
);
1142 Qpixmap_spec_p
= intern ("pixmap-spec-p");
1143 staticpro (&Qpixmap_spec_p
);
1145 DEFVAR_INT ("region-face", ®ion_face
,
1146 "Face number to use to highlight the region\n\
1147 The region is highlighted with this face\n\
1148 when Transient Mark mode is enabled and the mark is active.");
1150 defsubr (&Spixmap_spec_p
);
1151 defsubr (&Sframe_face_alist
);
1152 defsubr (&Sset_frame_face_alist
);
1153 defsubr (&Smake_face_internal
);
1154 defsubr (&Sset_face_attribute_internal
);
1155 defsubr (&Sinternal_next_face_id
);
1158 #endif /* HAVE_X_WINDOWS */