Commit | Line | Data |
---|---|---|
cb637678 | 1 | /* "Face" primitives. |
3a22ee35 | 2 | Copyright (C) 1993, 1994 Free Software Foundation. |
7b7739b1 | 3 | |
c115973b JB |
4 | This file is part of GNU Emacs. |
5 | ||
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 | |
7b7739b1 | 8 | the Free Software Foundation; either version 2, or (at your option) |
c115973b JB |
9 | any later version. |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
357f32fc | 20 | /* This is derived from work by Lucid (some parts very loosely so). */ |
7b7739b1 | 21 | |
c115973b JB |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
24 | ||
18160b98 | 25 | #include <config.h> |
c115973b JB |
26 | #include "lisp.h" |
27 | ||
cb637678 JB |
28 | #ifdef HAVE_X_WINDOWS |
29 | ||
c115973b JB |
30 | #include "xterm.h" |
31 | #include "buffer.h" | |
f211082d | 32 | #include "dispextern.h" |
7b7739b1 | 33 | #include "frame.h" |
357f32fc | 34 | #include "blockinput.h" |
b6d40e46 | 35 | #include "window.h" |
bde7c500 | 36 | #include "intervals.h" |
c115973b | 37 | |
657070ac JB |
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 | |
41 | #included. */ | |
6233db35 | 42 | #ifdef XOS_NEEDS_TIME_H |
657070ac | 43 | |
e11d186d | 44 | #include <time.h> |
657070ac JB |
45 | #undef USG |
46 | #include <X11/Xos.h> | |
47 | #define USG | |
e11d186d | 48 | #define __TIMEVAL__ |
e11d186d | 49 | |
657070ac | 50 | #else |
7a4d2269 | 51 | |
c115973b JB |
52 | #include <X11/Xos.h> |
53 | ||
657070ac JB |
54 | #endif |
55 | ||
cb637678 JB |
56 | \f |
57 | /* An explanation of the face data structures. */ | |
58 | ||
59 | /* ========================= Face Data Structures ========================= | |
60 | ||
7b00de84 | 61 | Let FACE-NAME be a symbol naming a face. |
cb637678 | 62 | |
7b00de84 JB |
63 | Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME)) |
64 | FACE-VECTOR is either nil, or a vector of the form | |
cb637678 JB |
65 | [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P] |
66 | where | |
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 | |
70 | the face, | |
71 | FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors | |
72 | to use with the face, | |
73 | BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't | |
74 | use right now, and | |
75 | UNDERLINE-P is non-nil if the face should be underlined. | |
7b00de84 JB |
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.) | |
80 | ||
81 | (assq FACE-NAME global-face-data) returns a vector describing the | |
82 | global parameters for that face. | |
83 | ||
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 | |
94 | param_faces.) | |
95 | ||
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. | |
108 | ||
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. | |
115 | ||
116 | Constraints: | |
117 | ||
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. | |
121 | ||
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. | |
cb637678 JB |
126 | |
127 | Some subtleties: | |
7b7739b1 | 128 | |
7b00de84 JB |
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 | |
135 | on all frames. | |
136 | ||
cb637678 JB |
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 | |
144 | purge. | |
145 | ||
7b00de84 | 146 | We're often applying intern_face to faces in computed_faces - |
cb637678 JB |
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. */ | |
153 | ||
154 | \f | |
155 | /* Definitions and declarations. */ | |
156 | ||
c115973b | 157 | /* A table of display faces. */ |
7b00de84 | 158 | static struct face **face_vector; |
c115973b | 159 | /* The length in use of the table. */ |
7b00de84 | 160 | static int nfaces; |
c115973b | 161 | /* The allocated length of the table. */ |
7b00de84 | 162 | static int nfaces_allocated; |
c115973b JB |
163 | |
164 | /* The number of face-id's in use (same for all frames). */ | |
165 | int next_face_id; | |
166 | ||
bc0db68d RS |
167 | /* The number of the face to use to indicate the region. */ |
168 | int region_face; | |
169 | ||
9516fe94 RS |
170 | /* This is what appears in a slot in a face to signify that the face |
171 | does not specify that display aspect. */ | |
7b7739b1 JB |
172 | #define FACE_DEFAULT (~0) |
173 | ||
6f134486 | 174 | Lisp_Object Qface, Qmouse_face; |
f211082d | 175 | |
415445e2 JB |
176 | static void build_face ( /* FRAME_PTR, struct face * */ ); |
177 | int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ ); | |
cb637678 | 178 | |
415445e2 | 179 | struct face *intern_face ( /* FRAME_PTR, struct face * */ ); |
7b00de84 JB |
180 | static int new_computed_face ( /* FRAME_PTR, struct face * */ ); |
181 | static int intern_computed_face ( /* FRAME_PTR, struct face * */ ); | |
415445e2 | 182 | static void ensure_face_ready ( /* FRAME_PTR, int id */ ); |
254a1b66 | 183 | void recompute_basic_faces ( /* FRAME_PTR f */ ); |
c115973b | 184 | \f |
cb637678 JB |
185 | /* Allocating, copying, and comparing struct faces. */ |
186 | ||
187 | /* Allocate a new face */ | |
188 | static struct face * | |
189 | allocate_face () | |
190 | { | |
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; | |
197 | return result; | |
198 | } | |
c115973b | 199 | |
cb637678 | 200 | /* Make a new face that's a copy of an existing one. */ |
c115973b JB |
201 | static struct face * |
202 | copy_face (face) | |
203 | struct face *face; | |
204 | { | |
205 | struct face *result = allocate_face (); | |
206 | ||
207 | result->font = face->font; | |
208 | result->foreground = face->foreground; | |
209 | result->background = face->background; | |
f211082d | 210 | result->stipple = face->stipple; |
c115973b JB |
211 | result->underline = face->underline; |
212 | ||
213 | return result; | |
214 | } | |
215 | ||
216 | static int | |
217 | face_eql (face1, face2) | |
218 | struct face *face1, *face2; | |
219 | { | |
cb637678 | 220 | return ( face1->font == face2->font |
c115973b JB |
221 | && face1->foreground == face2->foreground |
222 | && face1->background == face2->background | |
cb637678 JB |
223 | && face1->stipple == face2->stipple |
224 | && face1->underline == face2->underline); | |
c115973b | 225 | } |
cb637678 JB |
226 | \f |
227 | /* Interning faces in the `face_vector' cache, and clearing that cache. */ | |
c115973b JB |
228 | |
229 | /* Return the unique display face corresponding to the user-level face FACE. | |
c115973b JB |
230 | If there isn't one, make one, and find a slot in the face_vector to |
231 | put it in. */ | |
c115973b | 232 | static struct face * |
7b7739b1 | 233 | get_cached_face (f, face) |
c115973b JB |
234 | struct frame *f; |
235 | struct face *face; | |
236 | { | |
237 | int i, empty = -1; | |
f211082d | 238 | struct face *result; |
c115973b | 239 | |
cb637678 JB |
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]; | |
246 | ||
c115973b JB |
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++) | |
250 | { | |
251 | if (face_eql (face_vector[i], face)) | |
90e6242c RS |
252 | { |
253 | face->cached_index = i; | |
254 | return face_vector[i]; | |
255 | } | |
c115973b JB |
256 | if (face_vector[i] == 0) |
257 | empty = i; | |
258 | } | |
259 | ||
260 | /* If no empty slots, make one. */ | |
261 | if (empty < 0 && nfaces == nfaces_allocated) | |
262 | { | |
263 | int newsize = nfaces + 20; | |
264 | face_vector | |
265 | = (struct face **) xrealloc (face_vector, | |
266 | newsize * sizeof (struct face *)); | |
267 | nfaces_allocated = newsize; | |
268 | } | |
269 | ||
270 | if (empty < 0) | |
271 | empty = nfaces++; | |
272 | ||
273 | /* Put a new display face in the empty slot. */ | |
274 | result = copy_face (face); | |
275 | face_vector[empty] = result; | |
276 | ||
277 | /* Make a graphics context for it. */ | |
278 | build_face (f, result); | |
279 | ||
90e6242c | 280 | face->cached_index = empty; |
c115973b JB |
281 | return result; |
282 | } | |
283 | ||
7b00de84 | 284 | /* Given a computed face, return an equivalent display face |
cb637678 JB |
285 | (one which has a graphics context). */ |
286 | ||
287 | struct face * | |
288 | intern_face (f, face) | |
289 | struct frame *f; | |
290 | struct face *face; | |
291 | { | |
cb637678 JB |
292 | /* If it's equivalent to the default face, use that. */ |
293 | if (face_eql (face, FRAME_DEFAULT_FACE (f))) | |
294 | { | |
295 | if (!FRAME_DEFAULT_FACE (f)->gc) | |
296 | build_face (f, FRAME_DEFAULT_FACE (f)); | |
297 | return FRAME_DEFAULT_FACE (f); | |
298 | } | |
299 | ||
300 | /* If it's equivalent to the mode line face, use that. */ | |
301 | if (face_eql (face, FRAME_MODE_LINE_FACE (f))) | |
302 | { | |
303 | if (!FRAME_MODE_LINE_FACE (f)->gc) | |
304 | build_face (f, FRAME_MODE_LINE_FACE (f)); | |
305 | return FRAME_MODE_LINE_FACE (f); | |
306 | } | |
307 | ||
f6b98e0b JB |
308 | /* If it's not one of the frame's default faces, it shouldn't have a GC. */ |
309 | if (face->gc) | |
310 | abort (); | |
311 | ||
cb637678 JB |
312 | /* Get a specialized display face. */ |
313 | return get_cached_face (f, face); | |
314 | } | |
315 | ||
c115973b JB |
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. */ | |
320 | ||
321 | void | |
322 | clear_face_vector () | |
323 | { | |
324 | Lisp_Object rest; | |
325 | Display *dpy = x_current_display; | |
f211082d | 326 | int i; |
c115973b JB |
327 | |
328 | BLOCK_INPUT; | |
329 | /* Free the display faces in the face_vector. */ | |
330 | for (i = 0; i < nfaces; i++) | |
331 | { | |
332 | struct face *face = face_vector[i]; | |
f211082d JB |
333 | if (face->gc) |
334 | XFreeGC (dpy, face->gc); | |
c115973b JB |
335 | xfree (face); |
336 | } | |
337 | nfaces = 0; | |
338 | ||
339 | UNBLOCK_INPUT; | |
340 | } | |
341 | \f | |
cb637678 JB |
342 | /* Allocating and freeing X resources for display faces. */ |
343 | ||
f211082d JB |
344 | /* Make a graphics context for face FACE, which is on frame F, |
345 | if that can be done. */ | |
c115973b JB |
346 | static void |
347 | build_face (f, face) | |
cb637678 JB |
348 | struct frame *f; |
349 | struct face *face; | |
c115973b JB |
350 | { |
351 | GC gc; | |
352 | XGCValues xgcv; | |
353 | unsigned long mask; | |
354 | ||
660ed669 JB |
355 | BLOCK_INPUT; |
356 | ||
f211082d JB |
357 | if (face->foreground != FACE_DEFAULT) |
358 | xgcv.foreground = face->foreground; | |
359 | else | |
660ed669 JB |
360 | xgcv.foreground = f->display.x->foreground_pixel; |
361 | ||
f211082d JB |
362 | if (face->background != FACE_DEFAULT) |
363 | xgcv.background = face->background; | |
364 | else | |
660ed669 JB |
365 | xgcv.background = f->display.x->background_pixel; |
366 | ||
f211082d JB |
367 | if (face->font && (int) face->font != FACE_DEFAULT) |
368 | xgcv.font = face->font->fid; | |
369 | else | |
370 | xgcv.font = f->display.x->font->fid; | |
660ed669 | 371 | |
c115973b | 372 | xgcv.graphics_exposures = 0; |
660ed669 | 373 | |
c115973b JB |
374 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; |
375 | gc = XCreateGC (x_current_display, FRAME_X_WINDOW (f), | |
376 | mask, &xgcv); | |
660ed669 | 377 | |
c115973b | 378 | #if 0 |
f211082d JB |
379 | if (face->stipple && face->stipple != FACE_DEFAULT) |
380 | XSetStipple (x_current_display, gc, face->stipple); | |
c115973b | 381 | #endif |
660ed669 | 382 | |
f211082d | 383 | face->gc = gc; |
660ed669 JB |
384 | |
385 | UNBLOCK_INPUT; | |
c115973b | 386 | } |
cb637678 JB |
387 | |
388 | /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. */ | |
389 | ||
390 | static XFontStruct * | |
391 | load_font (f, name) | |
392 | struct frame *f; | |
393 | Lisp_Object name; | |
394 | { | |
395 | XFontStruct *font; | |
396 | ||
397 | if (NILP (name)) | |
398 | return (XFontStruct *) FACE_DEFAULT; | |
399 | ||
400 | CHECK_STRING (name, 0); | |
401 | BLOCK_INPUT; | |
402 | font = XLoadQueryFont (x_current_display, (char *) XSTRING (name)->data); | |
403 | UNBLOCK_INPUT; | |
404 | ||
405 | if (! font) | |
406 | Fsignal (Qerror, Fcons (build_string ("undefined font"), | |
407 | Fcons (name, Qnil))); | |
408 | return font; | |
409 | } | |
410 | ||
411 | static void | |
412 | unload_font (f, font) | |
413 | struct frame *f; | |
414 | XFontStruct *font; | |
415 | { | |
416 | if (!font || font == ((XFontStruct *) FACE_DEFAULT)) | |
417 | return; | |
660ed669 JB |
418 | |
419 | BLOCK_INPUT; | |
cb637678 | 420 | XFreeFont (x_current_display, font); |
660ed669 | 421 | UNBLOCK_INPUT; |
cb637678 JB |
422 | } |
423 | ||
424 | static unsigned long | |
425 | load_color (f, name) | |
426 | struct frame *f; | |
427 | Lisp_Object name; | |
428 | { | |
429 | Display *dpy = x_current_display; | |
430 | Colormap cmap; | |
431 | XColor color; | |
432 | int result; | |
433 | ||
434 | if (NILP (name)) | |
435 | return FACE_DEFAULT; | |
436 | ||
437 | cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display)); | |
438 | ||
439 | CHECK_STRING (name, 0); | |
440 | BLOCK_INPUT; | |
441 | result = XParseColor (dpy, cmap, (char *) XSTRING (name)->data, &color); | |
442 | UNBLOCK_INPUT; | |
443 | if (! result) | |
444 | Fsignal (Qerror, Fcons (build_string ("undefined color"), | |
445 | Fcons (name, Qnil))); | |
446 | BLOCK_INPUT; | |
447 | result = XAllocColor (dpy, cmap, &color); | |
448 | UNBLOCK_INPUT; | |
449 | if (! result) | |
450 | Fsignal (Qerror, Fcons (build_string ("X server cannot allocate color"), | |
451 | Fcons (name, Qnil))); | |
452 | return (unsigned long) color.pixel; | |
453 | } | |
454 | ||
455 | static void | |
456 | unload_color (f, pixel) | |
457 | struct frame *f; | |
7a4d2269 | 458 | unsigned long pixel; |
cb637678 | 459 | { |
1d9fd7fe JB |
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. */ | |
466 | #if 0 | |
cb637678 JB |
467 | Colormap cmap; |
468 | Display *dpy = x_current_display; | |
32dc0866 JB |
469 | if (pixel == FACE_DEFAULT |
470 | || pixel == BLACK_PIX_DEFAULT | |
471 | || pixel == WHITE_PIX_DEFAULT) | |
cb637678 JB |
472 | return; |
473 | cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display)); | |
474 | BLOCK_INPUT; | |
475 | XFreeColors (dpy, cmap, &pixel, 1, 0); | |
476 | UNBLOCK_INPUT; | |
1d9fd7fe | 477 | #endif |
cb637678 JB |
478 | } |
479 | \f | |
7b00de84 | 480 | /* Managing parameter face arrays for frames. */ |
cb637678 | 481 | |
cb637678 JB |
482 | void |
483 | init_frame_faces (f) | |
660ed669 | 484 | FRAME_PTR f; |
cb637678 JB |
485 | { |
486 | ensure_face_ready (f, 0); | |
cb637678 | 487 | ensure_face_ready (f, 1); |
660ed669 | 488 | |
fffc2367 RS |
489 | FRAME_N_COMPUTED_FACES (f) = 0; |
490 | FRAME_SIZE_COMPUTED_FACES (f) = 0; | |
491 | ||
7b00de84 JB |
492 | new_computed_face (f, FRAME_PARAM_FACES (f)[0]); |
493 | new_computed_face (f, FRAME_PARAM_FACES (f)[1]); | |
660ed669 | 494 | recompute_basic_faces (f); |
7b37f67b | 495 | |
1120eb5e JB |
496 | /* Find another X frame. */ |
497 | { | |
498 | Lisp_Object tail, frame, result; | |
499 | ||
500 | result = Qnil; | |
501 | FOR_EACH_FRAME (tail, frame) | |
502 | if (FRAME_X_P (XFRAME (frame)) | |
503 | && XFRAME (frame) != f) | |
504 | { | |
505 | result = frame; | |
506 | break; | |
507 | } | |
508 | ||
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. */ | |
513 | if (FRAMEP (result)) | |
514 | { | |
515 | int i; | |
7b00de84 JB |
516 | int n_faces = FRAME_N_PARAM_FACES (XFRAME (result)); |
517 | struct face **faces = FRAME_PARAM_FACES (XFRAME (result)); | |
1120eb5e JB |
518 | |
519 | for (i = 2; i < n_faces; i++) | |
520 | if (faces[i]) | |
521 | ensure_face_ready (f, i); | |
522 | } | |
523 | } | |
cb637678 JB |
524 | } |
525 | ||
660ed669 | 526 | |
cb637678 JB |
527 | /* Called from Fdelete_frame. */ |
528 | void | |
529 | free_frame_faces (f) | |
530 | struct frame *f; | |
531 | { | |
532 | Display *dpy = x_current_display; | |
533 | int i; | |
534 | ||
660ed669 JB |
535 | BLOCK_INPUT; |
536 | ||
7b00de84 | 537 | for (i = 0; i < FRAME_N_PARAM_FACES (f); i++) |
cb637678 | 538 | { |
7b00de84 | 539 | struct face *face = FRAME_PARAM_FACES (f) [i]; |
660ed669 JB |
540 | if (face) |
541 | { | |
542 | if (face->gc) | |
543 | XFreeGC (dpy, face->gc); | |
7b00de84 JB |
544 | unload_font (f, face->font); |
545 | unload_color (f, face->foreground); | |
546 | unload_color (f, face->background); | |
cb637678 | 547 | #if 0 |
7b00de84 | 548 | unload_pixmap (f, face->stipple); |
cb637678 | 549 | #endif |
660ed669 JB |
550 | xfree (face); |
551 | } | |
cb637678 | 552 | } |
7b00de84 JB |
553 | xfree (FRAME_PARAM_FACES (f)); |
554 | FRAME_PARAM_FACES (f) = 0; | |
555 | FRAME_N_PARAM_FACES (f) = 0; | |
556 | ||
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; | |
660ed669 JB |
562 | |
563 | UNBLOCK_INPUT; | |
cb637678 | 564 | } |
c115973b | 565 | \f |
cb637678 JB |
566 | /* Interning faces in a frame's face array. */ |
567 | ||
660ed669 | 568 | static int |
7b00de84 JB |
569 | new_computed_face (f, new_face) |
570 | struct frame *f; | |
571 | struct face *new_face; | |
572 | { | |
573 | int i = FRAME_N_COMPUTED_FACES (f); | |
574 | ||
575 | if (i >= FRAME_SIZE_COMPUTED_FACES (f)) | |
576 | { | |
577 | int new_size = i + 32; | |
578 | ||
579 | FRAME_COMPUTED_FACES (f) | |
fffc2367 RS |
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 *))); | |
7b00de84 JB |
584 | FRAME_SIZE_COMPUTED_FACES (f) = new_size; |
585 | } | |
586 | ||
587 | i = FRAME_N_COMPUTED_FACES (f)++; | |
588 | FRAME_COMPUTED_FACES (f)[i] = copy_face (new_face); | |
589 | return i; | |
590 | } | |
591 | ||
592 | ||
593 | /* Find a match for NEW_FACE in a FRAME's computed face array, and add | |
594 | it if we don't find one. */ | |
595 | static int | |
596 | intern_computed_face (f, new_face) | |
597 | struct frame *f; | |
b6d40e46 | 598 | struct face *new_face; |
cb637678 | 599 | { |
7b00de84 | 600 | int len = FRAME_N_COMPUTED_FACES (f); |
cb637678 JB |
601 | int i; |
602 | ||
7b00de84 | 603 | /* Search for a computed face already on F equivalent to FACE. */ |
cb637678 JB |
604 | for (i = 0; i < len; i++) |
605 | { | |
7b00de84 JB |
606 | if (! FRAME_COMPUTED_FACES (f)[i]) |
607 | abort (); | |
608 | if (face_eql (new_face, FRAME_COMPUTED_FACES (f)[i])) | |
cb637678 JB |
609 | return i; |
610 | } | |
611 | ||
612 | /* We didn't find one; add a new one. */ | |
7b00de84 | 613 | return new_computed_face (f, new_face); |
cb637678 JB |
614 | } |
615 | ||
7b00de84 | 616 | /* Make parameter face id ID valid on frame F. */ |
cb637678 JB |
617 | |
618 | static void | |
619 | ensure_face_ready (f, id) | |
620 | struct frame *f; | |
621 | int id; | |
622 | { | |
7b00de84 | 623 | if (FRAME_N_PARAM_FACES (f) <= id) |
cb637678 JB |
624 | { |
625 | int n = id + 10; | |
626 | int i; | |
7b00de84 JB |
627 | if (!FRAME_N_PARAM_FACES (f)) |
628 | FRAME_PARAM_FACES (f) | |
cb637678 JB |
629 | = (struct face **) xmalloc (sizeof (struct face *) * n); |
630 | else | |
7b00de84 JB |
631 | FRAME_PARAM_FACES (f) |
632 | = (struct face **) xrealloc (FRAME_PARAM_FACES (f), | |
cb637678 JB |
633 | sizeof (struct face *) * n); |
634 | ||
7b00de84 JB |
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; | |
cb637678 JB |
638 | } |
639 | ||
7b00de84 JB |
640 | if (FRAME_PARAM_FACES (f) [id] == 0) |
641 | FRAME_PARAM_FACES (f) [id] = allocate_face (); | |
cb637678 JB |
642 | } |
643 | \f | |
867dd159 RS |
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 | |
646 | different heights. | |
660ed669 | 647 | We assume that they're both character-cell fonts. */ |
867dd159 | 648 | |
660ed669 JB |
649 | int |
650 | same_size_fonts (font1, font2) | |
651 | XFontStruct *font1, *font2; | |
652 | { | |
653 | XCharStruct *bounds1 = &font1->min_bounds; | |
654 | XCharStruct *bounds2 = &font2->min_bounds; | |
655 | ||
46407861 | 656 | return (bounds1->width == bounds2->width); |
660ed669 JB |
657 | } |
658 | ||
729425b1 | 659 | /* Update the line_height of frame F according to the biggest font in |
6717f691 | 660 | any face. Return nonzero if if line_height changes. */ |
729425b1 | 661 | |
6717f691 | 662 | int |
729425b1 RS |
663 | frame_update_line_height (f) |
664 | FRAME_PTR f; | |
665 | { | |
666 | int i; | |
667 | int biggest = FONT_HEIGHT (f->display.x->font); | |
668 | ||
669 | for (i = 0; i < f->display.x->n_param_faces; i++) | |
867dd159 RS |
670 | if (f->display.x->param_faces[i] != 0 |
671 | && f->display.x->param_faces[i]->font != (XFontStruct *) FACE_DEFAULT) | |
729425b1 RS |
672 | { |
673 | int height = FONT_HEIGHT (f->display.x->param_faces[i]->font); | |
674 | if (height > biggest) | |
675 | biggest = height; | |
676 | } | |
677 | ||
678 | if (biggest == f->display.x->line_height) | |
6717f691 | 679 | return 0; |
729425b1 RS |
680 | |
681 | f->display.x->line_height = biggest; | |
6717f691 | 682 | return 1; |
729425b1 | 683 | } |
867dd159 | 684 | \f |
7b7739b1 JB |
685 | /* Modify face TO by copying from FROM all properties which have |
686 | nondefault settings. */ | |
867dd159 | 687 | |
7b7739b1 JB |
688 | static void |
689 | merge_faces (from, to) | |
690 | struct face *from, *to; | |
691 | { | |
867dd159 RS |
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. */ | |
68a97335 | 694 | if (from->font != (XFontStruct *) FACE_DEFAULT |
68a97335 JB |
695 | && same_size_fonts (from->font, to->font)) |
696 | to->font = from->font; | |
7b7739b1 JB |
697 | if (from->foreground != FACE_DEFAULT) |
698 | to->foreground = from->foreground; | |
699 | if (from->background != FACE_DEFAULT) | |
700 | to->background = from->background; | |
f211082d JB |
701 | if (from->stipple != FACE_DEFAULT) |
702 | to->stipple = from->stipple; | |
7b7739b1 JB |
703 | if (from->underline) |
704 | to->underline = from->underline; | |
705 | } | |
706 | ||
660ed669 JB |
707 | /* Set up the basic set of facial parameters, based on the frame's |
708 | data; all faces are deltas applied to this. */ | |
867dd159 | 709 | |
660ed669 JB |
710 | static void |
711 | compute_base_face (f, face) | |
712 | FRAME_PTR f; | |
713 | struct face *face; | |
714 | { | |
715 | struct x_display *d = f->display.x; | |
716 | ||
717 | face->gc = 0; | |
718 | face->foreground = d->foreground_pixel; | |
719 | face->background = d->background_pixel; | |
720 | face->font = d->font; | |
582080c1 | 721 | face->stipple = 0; |
660ed669 | 722 | face->underline = 0; |
582080c1 JB |
723 | |
724 | /* Avoid a face comparison by making this invalid. */ | |
725 | face->cached_index = -1; | |
660ed669 JB |
726 | } |
727 | ||
867dd159 RS |
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. */ | |
731 | ||
732 | int | |
733 | compute_glyph_face (f, face_code, current_face) | |
734 | struct frame *f; | |
735 | int face_code, current_face; | |
736 | { | |
737 | struct face face; | |
738 | ||
739 | face = *FRAME_COMPUTED_FACES (f)[current_face]; | |
740 | ||
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); | |
660ed669 | 744 | |
867dd159 RS |
745 | return intern_computed_face (f, &face); |
746 | } | |
2e16580f RS |
747 | |
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. */ | |
751 | ||
752 | int | |
753 | compute_glyph_face_1 (f, face_name, current_face) | |
754 | struct frame *f; | |
755 | Lisp_Object face_name; | |
756 | int current_face; | |
757 | { | |
758 | struct face face; | |
759 | ||
760 | face = *FRAME_COMPUTED_FACES (f)[current_face]; | |
761 | ||
762 | if (!NILP (face_name)) | |
763 | { | |
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); | |
768 | } | |
769 | ||
770 | return intern_computed_face (f, &face); | |
771 | } | |
867dd159 | 772 | \f |
cb637678 | 773 | /* Return the face ID associated with a buffer position POS. |
7b7739b1 JB |
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. | |
f6b98e0b | 776 | F is the frame in use for display, and W is a window displaying |
bc0db68d RS |
777 | the current buffer. |
778 | ||
b349f4fb RS |
779 | REGION_BEG, REGION_END delimit the region, so it can be highlighted. |
780 | ||
781 | LIMIT is a position not to scan beyond. That is to limit | |
6f134486 RS |
782 | the time this function can take. |
783 | ||
784 | If MOUSE is nonzero, use the character's mouse-face, not its face. */ | |
bc0db68d | 785 | |
cb637678 | 786 | int |
6f134486 | 787 | compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse) |
7b7739b1 | 788 | struct frame *f; |
f211082d | 789 | struct window *w; |
7b7739b1 | 790 | int pos; |
bc0db68d | 791 | int region_beg, region_end; |
7b7739b1 | 792 | int *endptr; |
b349f4fb | 793 | int limit; |
6f134486 | 794 | int mouse; |
7b7739b1 JB |
795 | { |
796 | struct face face; | |
b6d40e46 | 797 | Lisp_Object prop, position; |
7b7739b1 JB |
798 | int i, j, noverlays; |
799 | int facecode; | |
7b7739b1 | 800 | Lisp_Object *overlay_vec; |
f211082d | 801 | Lisp_Object frame; |
f6b98e0b | 802 | int endpos; |
6f134486 | 803 | Lisp_Object propname; |
f6b98e0b JB |
804 | |
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) | |
808 | abort (); | |
f211082d JB |
809 | |
810 | XSET (frame, Lisp_Frame, f); | |
7b7739b1 | 811 | |
f6b98e0b | 812 | endpos = ZV; |
bc0db68d RS |
813 | if (pos < region_beg && region_beg < endpos) |
814 | endpos = region_beg; | |
f6b98e0b | 815 | |
7b7739b1 | 816 | XFASTINT (position) = pos; |
6f134486 RS |
817 | |
818 | if (mouse) | |
819 | propname = Qmouse_face; | |
820 | else | |
821 | propname = Qface; | |
822 | ||
823 | prop = Fget_text_property (position, propname, w->buffer); | |
824 | ||
b6d40e46 | 825 | { |
b349f4fb | 826 | Lisp_Object limit1, end; |
7b7739b1 | 827 | |
b349f4fb | 828 | XFASTINT (limit1) = (limit < endpos ? limit : endpos); |
6f134486 | 829 | end = Fnext_single_property_change (position, propname, w->buffer, limit1); |
b6d40e46 JB |
830 | if (INTEGERP (end)) |
831 | endpos = XINT (end); | |
832 | } | |
833 | ||
834 | { | |
f6b98e0b | 835 | int next_overlay; |
9516fe94 RS |
836 | int len; |
837 | ||
838 | /* First try with room for 40 overlays. */ | |
839 | len = 40; | |
840 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
841 | ||
82277c2f | 842 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, &next_overlay, NULL); |
9516fe94 RS |
843 | |
844 | /* If there are more than 40, | |
845 | make enough space for all, and try again. */ | |
846 | if (noverlays > len) | |
847 | { | |
848 | len = noverlays; | |
849 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
82277c2f RS |
850 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, |
851 | &next_overlay, NULL); | |
9516fe94 | 852 | } |
b6d40e46 | 853 | |
f6b98e0b JB |
854 | if (next_overlay < endpos) |
855 | endpos = next_overlay; | |
b6d40e46 JB |
856 | } |
857 | ||
858 | *endptr = endpos; | |
7b7739b1 JB |
859 | |
860 | /* Optimize the default case. */ | |
bc0db68d RS |
861 | if (noverlays == 0 && NILP (prop) |
862 | && !(pos >= region_beg && pos < region_end)) | |
cb637678 | 863 | return 0; |
7b7739b1 | 864 | |
660ed669 | 865 | compute_base_face (f, &face); |
7b7739b1 JB |
866 | |
867 | if (!NILP (prop)) | |
868 | { | |
1d9fd7fe | 869 | facecode = face_name_id_number (f, prop); |
7b00de84 JB |
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); | |
7b7739b1 JB |
873 | } |
874 | ||
4d6ebff8 | 875 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
7b7739b1 JB |
876 | |
877 | /* Now merge the overlay data in that order. */ | |
7b7739b1 JB |
878 | for (i = 0; i < noverlays; i++) |
879 | { | |
6f134486 | 880 | prop = Foverlay_get (overlay_vec[i], propname); |
7b7739b1 JB |
881 | if (!NILP (prop)) |
882 | { | |
883 | Lisp_Object oend; | |
884 | int oendpos; | |
885 | ||
1d9fd7fe | 886 | facecode = face_name_id_number (f, prop); |
7b00de84 JB |
887 | if (facecode >= 0 && facecode < FRAME_N_PARAM_FACES (f) |
888 | && FRAME_PARAM_FACES (f) [facecode] != 0) | |
6f134486 | 889 | merge_faces (FRAME_PARAM_FACES (f)[facecode], &face); |
7b7739b1 | 890 | |
4d6ebff8 | 891 | oend = OVERLAY_END (overlay_vec[i]); |
7b7739b1 | 892 | oendpos = OVERLAY_POSITION (oend); |
f6b98e0b | 893 | if (oendpos < endpos) |
7b7739b1 JB |
894 | endpos = oendpos; |
895 | } | |
896 | } | |
897 | ||
bc0db68d RS |
898 | if (pos >= region_beg && pos < region_end) |
899 | { | |
900 | if (region_end < endpos) | |
901 | endpos = region_end; | |
902 | if (region_face >= 0 && region_face < next_face_id) | |
6f134486 | 903 | merge_faces (FRAME_PARAM_FACES (f)[region_face], &face); |
bc0db68d RS |
904 | } |
905 | ||
7b7739b1 JB |
906 | *endptr = endpos; |
907 | ||
7b00de84 | 908 | return intern_computed_face (f, &face); |
f211082d | 909 | } |
867dd159 | 910 | \f |
660ed669 JB |
911 | /* Recompute the GC's for the default and modeline faces. |
912 | We call this after changing frame parameters on which those GC's | |
913 | depend. */ | |
fffc2367 | 914 | |
660ed669 JB |
915 | void |
916 | recompute_basic_faces (f) | |
917 | FRAME_PTR f; | |
918 | { | |
919 | /* If the frame's faces haven't been initialized yet, don't worry about | |
920 | this stuff. */ | |
7b00de84 | 921 | if (FRAME_N_PARAM_FACES (f) < 2) |
660ed669 JB |
922 | return; |
923 | ||
924 | BLOCK_INPUT; | |
925 | ||
926 | if (FRAME_DEFAULT_FACE (f)->gc) | |
927 | XFreeGC (x_current_display, FRAME_DEFAULT_FACE (f)->gc); | |
660ed669 JB |
928 | if (FRAME_MODE_LINE_FACE (f)->gc) |
929 | XFreeGC (x_current_display, FRAME_MODE_LINE_FACE (f)->gc); | |
7b00de84 JB |
930 | |
931 | compute_base_face (f, FRAME_DEFAULT_FACE (f)); | |
932 | compute_base_face (f, FRAME_MODE_LINE_FACE (f)); | |
933 | ||
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)); | |
936 | ||
937 | build_face (f, FRAME_DEFAULT_FACE (f)); | |
660ed669 JB |
938 | build_face (f, FRAME_MODE_LINE_FACE (f)); |
939 | ||
940 | UNBLOCK_INPUT; | |
941 | } | |
942 | ||
943 | ||
c115973b | 944 | \f |
cb637678 | 945 | /* Lisp interface. */ |
c115973b JB |
946 | |
947 | DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, 1, 1, 0, | |
948 | "") | |
949 | (frame) | |
950 | Lisp_Object frame; | |
951 | { | |
952 | CHECK_FRAME (frame, 0); | |
953 | return XFRAME (frame)->face_alist; | |
954 | } | |
955 | ||
956 | DEFUN ("set-frame-face-alist", Fset_frame_face_alist, Sset_frame_face_alist, | |
957 | 2, 2, 0, "") | |
958 | (frame, value) | |
959 | Lisp_Object frame, value; | |
960 | { | |
961 | CHECK_FRAME (frame, 0); | |
962 | XFRAME (frame)->face_alist = value; | |
963 | return value; | |
964 | } | |
965 | ||
966 | ||
967 | DEFUN ("make-face-internal", Fmake_face_internal, Smake_face_internal, 1, 1, 0, | |
968 | "Create face number FACE-ID on all frames.") | |
969 | (face_id) | |
970 | Lisp_Object face_id; | |
971 | { | |
972 | Lisp_Object rest; | |
973 | int id = XINT (face_id); | |
974 | ||
f211082d JB |
975 | CHECK_NUMBER (face_id, 0); |
976 | if (id < 0 || id >= next_face_id) | |
977 | error ("Face id out of range"); | |
c115973b JB |
978 | |
979 | for (rest = Vframe_list; !NILP (rest); rest = XCONS (rest)->cdr) | |
980 | { | |
981 | struct frame *f = XFRAME (XCONS (rest)->car); | |
cb637678 JB |
982 | if (FRAME_X_P (f)) |
983 | ensure_face_ready (f, id); | |
c115973b JB |
984 | } |
985 | return Qnil; | |
986 | } | |
987 | ||
988 | ||
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; | |
993 | { | |
994 | struct face *face; | |
995 | struct frame *f; | |
996 | int magic_p; | |
997 | int id; | |
998 | ||
999 | CHECK_FRAME (frame, 0); | |
f211082d | 1000 | CHECK_NUMBER (face_id, 0); |
c115973b JB |
1001 | CHECK_SYMBOL (attr_name, 0); |
1002 | ||
1003 | f = XFRAME (frame); | |
1004 | id = XINT (face_id); | |
f211082d JB |
1005 | if (id < 0 || id >= next_face_id) |
1006 | error ("Face id out of range"); | |
c115973b | 1007 | |
b6d40e46 | 1008 | if (! FRAME_X_P (f)) |
b839cea0 | 1009 | return Qnil; |
b6d40e46 | 1010 | |
c115973b | 1011 | ensure_face_ready (f, id); |
7b00de84 | 1012 | face = FRAME_PARAM_FACES (f) [XFASTINT (face_id)]; |
c115973b JB |
1013 | |
1014 | if (EQ (attr_name, intern ("font"))) | |
1015 | { | |
f211082d | 1016 | XFontStruct *font = load_font (f, attr_value); |
ebc64af3 RS |
1017 | if (face->font != f->display.x->font) |
1018 | unload_font (f, face->font); | |
c115973b | 1019 | face->font = font; |
6717f691 RS |
1020 | if (frame_update_line_height (f)) |
1021 | x_set_window_size (f, 0, f->width, f->height); | |
c115973b JB |
1022 | } |
1023 | else if (EQ (attr_name, intern ("foreground"))) | |
1024 | { | |
f211082d | 1025 | unsigned long new_color = load_color (f, attr_value); |
c115973b JB |
1026 | unload_color (f, face->foreground); |
1027 | face->foreground = new_color; | |
c115973b JB |
1028 | } |
1029 | else if (EQ (attr_name, intern ("background"))) | |
1030 | { | |
f211082d | 1031 | unsigned long new_color = load_color (f, attr_value); |
c115973b JB |
1032 | unload_color (f, face->background); |
1033 | face->background = new_color; | |
c115973b JB |
1034 | } |
1035 | #if 0 | |
1036 | else if (EQ (attr_name, intern ("background-pixmap"))) | |
1037 | { | |
c115973b JB |
1038 | unsigned int w, h, d; |
1039 | unsigned long new_pixmap = load_pixmap (f, attr_value, &w, &h, &d, 0); | |
f211082d JB |
1040 | unload_pixmap (f, face->stipple); |
1041 | if (NILP (attr_value)) | |
1042 | new_pixmap = 0; | |
1043 | face->stipple = new_pixmap; | |
c115973b JB |
1044 | face->pixmap_w = w; |
1045 | face->pixmap_h = h; | |
1046 | /* face->pixmap_depth = d; */ | |
c115973b JB |
1047 | } |
1048 | #endif /* 0 */ | |
1049 | else if (EQ (attr_name, intern ("underline"))) | |
1050 | { | |
1051 | int new = !NILP (attr_value); | |
1052 | face->underline = new; | |
1053 | } | |
1054 | else | |
1055 | error ("unknown face attribute"); | |
1056 | ||
7b00de84 JB |
1057 | if (id == 0 || id == 1) |
1058 | recompute_basic_faces (f); | |
c115973b | 1059 | |
584d0634 JB |
1060 | /* If we're modifying either of the frame's display faces, that |
1061 | means that we're changing the parameters of a fixed face code; | |
1062 | since the color/font/whatever is changed but the face ID hasn't, | |
1063 | redisplay won't know to redraw the affected sections. Give it a | |
1064 | kick. */ | |
1065 | if (id == 0 || id == 1) | |
1066 | SET_FRAME_GARBAGED (f); | |
1067 | else | |
1068 | /* Otherwise, it's enough to tell it to redisplay the text. */ | |
1069 | windows_or_buffers_changed = 1; | |
1070 | ||
c115973b JB |
1071 | return Qnil; |
1072 | } | |
1073 | ||
1074 | DEFUN ("internal-next-face-id", Finternal_next_face_id, Sinternal_next_face_id, | |
1075 | 0, 0, 0, "") | |
1076 | () | |
1077 | { | |
1078 | return make_number (next_face_id++); | |
1079 | } | |
f211082d JB |
1080 | |
1081 | /* Return the face id for name NAME on frame FRAME. | |
1082 | (It should be the same for all frames, | |
1083 | but it's as easy to use the "right" frame to look it up | |
1084 | as to use any other one.) */ | |
1085 | ||
1d9fd7fe JB |
1086 | int |
1087 | face_name_id_number (f, name) | |
1088 | FRAME_PTR f; | |
1089 | Lisp_Object name; | |
f211082d JB |
1090 | { |
1091 | Lisp_Object tem; | |
1092 | ||
82411f65 | 1093 | tem = Fcdr (assq_no_quit (name, f->face_alist)); |
b6d40e46 JB |
1094 | if (NILP (tem)) |
1095 | return 0; | |
f211082d JB |
1096 | CHECK_VECTOR (tem, 0); |
1097 | tem = XVECTOR (tem)->contents[2]; | |
1098 | CHECK_NUMBER (tem, 0); | |
1099 | return XINT (tem); | |
1100 | } | |
c115973b | 1101 | \f |
cb637678 JB |
1102 | /* Emacs initialization. */ |
1103 | ||
c115973b | 1104 | void |
f211082d | 1105 | syms_of_xfaces () |
c115973b | 1106 | { |
f211082d JB |
1107 | Qface = intern ("face"); |
1108 | staticpro (&Qface); | |
6f134486 RS |
1109 | Qmouse_face = intern ("mouse-face"); |
1110 | staticpro (&Qmouse_face); | |
f211082d | 1111 | |
bc0db68d RS |
1112 | DEFVAR_INT ("region-face", ®ion_face, |
1113 | "Face number to use to highlight the region\n\ | |
1114 | The region is highlighted with this face\n\ | |
1115 | when Transient Mark mode is enabled and the mark is active."); | |
1116 | ||
c115973b JB |
1117 | defsubr (&Sframe_face_alist); |
1118 | defsubr (&Sset_frame_face_alist); | |
1119 | defsubr (&Smake_face_internal); | |
1120 | defsubr (&Sset_face_attribute_internal); | |
1121 | defsubr (&Sinternal_next_face_id); | |
1122 | } | |
cb637678 JB |
1123 | |
1124 | #endif /* HAVE_X_WINDOWS */ | |
1125 |