2342
|
1 /* Must define frame->faces, frame->n_faces,
|
|
2 FRAME_NORMAL_FACE, FRAME_MODELINE_FACE. */
|
|
3
|
2336
|
4 /* "Face" primitives
|
2342
|
5 Copyright (C) 1992, 1993 Free Software Foundation.
|
|
6
|
2336
|
7 This file is part of GNU Emacs.
|
|
8
|
|
9 GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 it under the terms of the GNU General Public License as published by
|
2342
|
11 the Free Software Foundation; either version 2, or (at your option)
|
2336
|
12 any later version.
|
|
13
|
|
14 GNU Emacs is distributed in the hope that it will be useful,
|
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 GNU General Public License for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with GNU Emacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
22
|
2342
|
23 struct face
|
|
24 {
|
|
25 unsigned char underline;
|
|
26 unsigned char hilited;
|
|
27 unsigned char modif;
|
|
28 GC facegc;
|
|
29 XFontStruct * font;
|
|
30 unsigned long foreground;
|
|
31 unsigned long background;
|
|
32 Pixmap back_pixmap;
|
|
33 unsigned int pixmap_w, pixmap_h /* , pixmap_depth */;
|
|
34 };
|
|
35
|
2336
|
36 #include <sys/types.h>
|
|
37 #include <sys/stat.h>
|
|
38
|
|
39 #include "config.h"
|
|
40 #include "lisp.h"
|
|
41
|
|
42 #include "xterm.h"
|
|
43 #include "buffer.h"
|
2342
|
44 #include "frame.h"
|
2336
|
45 #include "window.h"
|
|
46 #include "indent.h"
|
|
47
|
|
48 /* Display Context for the icons */
|
|
49 #include <X11/Intrinsic.h>
|
|
50 #include <X11/StringDefs.h>
|
|
51 #include <X11/Xmu/Drawing.h>
|
|
52 #include <X11/Xos.h>
|
|
53
|
2342
|
54 /* We use face structures in two ways:
|
|
55 At the frame level, each frame has a vector of faces. (f->faces).
|
|
56 Face number 0 is the normal face (for normal text).
|
|
57 Face number 1 is the mode line face.
|
|
58 Higher face numbers have no built-in meaning.
|
|
59 The faces in these vectors are called "frame faces".
|
|
60
|
|
61 Faces number 0 and 1 have graphics contexts.
|
|
62 They can be user in the redisplay code directly.
|
|
63 Higher numbered frame faces do not have graphics contexts.
|
|
64
|
|
65 There are also "cached faces". They have graphics contexts.
|
|
66 They are kept in a C vector called face_vector.
|
|
67
|
|
68 A "display face" is a face with a graphics context.
|
|
69 It is either a frame face number 0 or 1,
|
|
70 or a cached face. */
|
|
71
|
2336
|
72 /* A table of display faces. */
|
|
73 struct face **face_vector;
|
|
74 /* The length in use of the table. */
|
|
75 int nfaces;
|
|
76 /* The allocated length of the table. */
|
|
77 int nfaces_allocated;
|
|
78
|
|
79 /* The number of face-id's in use (same for all frames). */
|
|
80 int next_face_id;
|
|
81
|
2342
|
82 #define FACE_DEFAULT (~0)
|
|
83
|
2336
|
84 static struct face *allocate_face ();
|
|
85 static void build_face ();
|
|
86
|
|
87 /* Make a new face that's a copy of an existing one. */
|
|
88
|
|
89 static struct face *
|
|
90 copy_face (face)
|
|
91 struct face *face;
|
|
92 {
|
|
93 struct face *result = allocate_face ();
|
|
94
|
|
95 result->font = face->font;
|
|
96 result->foreground = face->foreground;
|
|
97 result->background = face->background;
|
|
98 result->back_pixmap = face->back_pixmap;
|
|
99 result->underline = face->underline;
|
|
100
|
|
101 return result;
|
|
102 }
|
|
103
|
|
104 static int
|
|
105 face_eql (face1, face2)
|
|
106 struct face *face1, *face2;
|
|
107 {
|
|
108 return (face1->font == face2->font
|
|
109 && face1->foreground == face2->foreground
|
|
110 && face1->background == face2->background
|
|
111 && face1->back_pixmap == face2->back_pixmap
|
|
112 && face1->underline == face2->underline);
|
|
113 }
|
|
114
|
|
115 /* Return the unique display face corresponding to the user-level face FACE.
|
|
116
|
|
117 If there isn't one, make one, and find a slot in the face_vector to
|
|
118 put it in. */
|
|
119
|
|
120 static struct face *
|
2342
|
121 get_cached_face (f, face)
|
2336
|
122 struct frame *f;
|
|
123 struct face *face;
|
|
124 {
|
|
125 int i, empty = -1;
|
|
126
|
|
127 /* Look for an existing display face that does the job.
|
|
128 Also find an empty slot if any. */
|
|
129 for (i = 0; i < nfaces; i++)
|
|
130 {
|
|
131 if (face_eql (face_vector[i], face))
|
|
132 return face_vector[i];
|
|
133 if (face_vector[i] == 0)
|
|
134 empty = i;
|
|
135 }
|
|
136
|
|
137 /* If no empty slots, make one. */
|
|
138 if (empty < 0 && nfaces == nfaces_allocated)
|
|
139 {
|
|
140 int newsize = nfaces + 20;
|
|
141 face_vector
|
|
142 = (struct face **) xrealloc (face_vector,
|
|
143 newsize * sizeof (struct face *));
|
|
144 nfaces_allocated = newsize;
|
|
145 }
|
|
146
|
|
147 if (empty < 0)
|
|
148 empty = nfaces++;
|
|
149
|
|
150 /* Put a new display face in the empty slot. */
|
|
151 result = copy_face (face);
|
|
152 face_vector[empty] = result;
|
|
153
|
|
154 /* Make a graphics context for it. */
|
|
155 build_face (f, result);
|
|
156
|
|
157 return result;
|
|
158 }
|
|
159
|
|
160 /* Clear out face_vector and start anew.
|
|
161 This should be done from time to time just to avoid
|
|
162 keeping too many graphics contexts in face_vector
|
|
163 that are no longer needed. */
|
|
164
|
|
165 void
|
|
166 clear_face_vector ()
|
|
167 {
|
|
168 Lisp_Object rest;
|
|
169 Display *dpy = x_current_display;
|
|
170
|
|
171 BLOCK_INPUT;
|
|
172 /* Free the display faces in the face_vector. */
|
|
173 for (i = 0; i < nfaces; i++)
|
|
174 {
|
|
175 struct face *face = face_vector[i];
|
|
176 if (face->facegc)
|
|
177 XFreeGC (dpy, face->facegc);
|
|
178 xfree (face);
|
|
179 }
|
|
180 nfaces = 0;
|
|
181
|
|
182 UNBLOCK_INPUT;
|
|
183 }
|
|
184
|
|
185 /* Make a graphics context for face FACE, which is on frame F. */
|
|
186
|
|
187 static void
|
|
188 build_face (f, face)
|
|
189 struct frame* f;
|
|
190 struct face* face;
|
|
191 {
|
|
192 GC gc;
|
|
193 XGCValues xgcv;
|
|
194 unsigned long mask;
|
|
195
|
|
196 xgcv.foreground = face->foreground;
|
|
197 xgcv.background = face->background;
|
|
198 xgcv.font = face->font->fid;
|
|
199 xgcv.graphics_exposures = 0;
|
|
200 mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
|
|
201 gc = XCreateGC (x_current_display, FRAME_X_WINDOW (f),
|
|
202 mask, &xgcv);
|
|
203 #if 0
|
|
204 if (face->back_pixmap && face->back_pixmap != FACE_DEFAULT)
|
|
205 XSetStipple (XtDisplay (f->display.x->widget), gc, face->back_pixmap);
|
|
206 #endif
|
|
207 face->facegc = gc;
|
|
208 }
|
|
209
|
2342
|
210 /* Modify face TO by copying from FROM all properties which have
|
|
211 nondefault settings. */
|
|
212
|
|
213 static void
|
|
214 merge_faces (from, to)
|
|
215 struct face *from, *to;
|
|
216 {
|
|
217 if (from->font != (XFontStruct *)FACE_DEFAULT)
|
|
218 {
|
|
219 to->font = from->font;
|
|
220 }
|
|
221 if (from->foreground != FACE_DEFAULT)
|
|
222 to->foreground = from->foreground;
|
|
223 if (from->background != FACE_DEFAULT)
|
|
224 to->background = from->background;
|
|
225 if (from->back_pixmap != FACE_DEFAULT)
|
|
226 to->back_pixmap = from->back_pixmap;
|
|
227 if (from->underline)
|
|
228 to->underline = from->underline;
|
|
229 }
|
|
230
|
|
231 /* Return the display face associated with a buffer position POS.
|
|
232 Store into *ENDPTR the position at which a different face is needed.
|
|
233 This does not take account of glyphs that specify their own face codes.
|
|
234 F is the frame in use for display. */
|
|
235
|
|
236 struct face *
|
|
237 compute_char_face (f, pos, endptr)
|
|
238 struct frame *f;
|
|
239 int pos;
|
|
240 int *endptr;
|
|
241 {
|
|
242 struct face face;
|
|
243 Lisp_Object prop, position, length;
|
|
244 Lisp_Object overlay, start, end;
|
|
245 int i, j, noverlays;
|
|
246 int facecode;
|
|
247 int endpos;
|
|
248 Lisp_Object *overlay_vec;
|
|
249 int len;
|
|
250
|
|
251 XFASTINT (position) = pos;
|
|
252 prop = Fget_text_property (position, Qface);
|
|
253
|
|
254 len = 10;
|
|
255 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
|
|
256 noverlays = overlays_at (pos, &overlay_vec, &len, &endpos);
|
|
257
|
|
258 /* Optimize the default case. */
|
|
259 if (noverlays == 0 && NILP (prop))
|
|
260 return FRAME_NORMAL_FACE (f);
|
|
261
|
|
262 bcopy (FRAME_NORMAL_FACE (f), &face, sizeof (struct face));
|
|
263
|
|
264 if (!NILP (prop))
|
|
265 {
|
|
266 facecode = Fface_name_id_number (prop);
|
|
267 if (facecode >= 0 && facecode < f->n_faces && f->faces[facecode] != 0)
|
|
268 merge_faces (f->faces[facecode], &face);
|
|
269 }
|
|
270
|
|
271 /* Discard invalid overlays from the vector. */
|
|
272 for (i = 0, j = 0; i < noverlays; i++)
|
|
273 {
|
|
274 overlay = overlay_vec[i];
|
|
275
|
|
276 if (OVERLAY_VALID (overlay)
|
|
277 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
|
|
278 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
|
|
279 overlay_vec[j++] = overlay;
|
|
280 }
|
|
281 noverlays = j;
|
|
282
|
|
283 /* Sort the overlays into the proper order. */
|
|
284
|
|
285 /* Now merge the overlay data in that order. */
|
|
286
|
|
287 for (i = 0; i < noverlays; i++)
|
|
288 {
|
|
289 prop = Foverlay_get (overlay_vec[i], Qface);
|
|
290 if (!NILP (prop))
|
|
291 {
|
|
292 Lisp_Object oend;
|
|
293 int oendpos;
|
|
294
|
|
295 facecode = Fface_name_id_number (prop);
|
|
296 if (facecode >= 0 && facecode < f->n_faces
|
|
297 && f->faces[facecode] != 0)
|
|
298 merge_faces (f->faces[facecode], &face);
|
|
299
|
|
300 oend = OVERLAY_END (overlay_vec[i]);
|
|
301 oendpos = OVERLAY_POSITION (oend);
|
|
302 if (oendpos > endpos)
|
|
303 endpos = oendpos;
|
|
304 }
|
|
305 }
|
|
306
|
|
307 xfree (overlay_vec);
|
|
308
|
|
309 *endptr = endpos;
|
|
310
|
|
311 return get_display_face (f, &face);
|
|
312 }
|
|
313
|
|
314 /* Return the display face to use to display a special glyph
|
|
315 which selects FACE_CODE as the face ID,
|
|
316 assuming that ordinarily the face would be BASIC_FACE.
|
|
317 F is the frame. */
|
|
318
|
|
319 struct face *
|
|
320 compute_glyph_face (f, basic_face, face_code)
|
|
321 struct frame *f;
|
|
322 struct face *basic_face;
|
|
323 int face_code;
|
|
324 {
|
|
325 struct face face;
|
|
326
|
|
327 bcopy (basic_face, &face, sizeof (struct face));
|
|
328
|
|
329 if (face_code >= 0 && face_code < f->n_faces && f->faces[face_code] != 0)
|
|
330 merge_faces (f->faces[face_code], &face);
|
|
331
|
|
332 return get_display_face (f, &face);
|
|
333 }
|
|
334
|
2336
|
335 /* Given a frame face, return an equivalent display face
|
|
336 (one which has a graphics context). */
|
|
337
|
|
338 static struct face *
|
|
339 get_display_face (f, face)
|
|
340 struct frame *f;
|
|
341 struct face *face;
|
|
342 {
|
|
343 struct face *result;
|
|
344
|
|
345 /* Does the face have a GC already? */
|
|
346 if (face->facegc)
|
|
347 return face;
|
|
348
|
|
349 /* If it's equivalent to the normal face, use that. */
|
|
350 if (face->font == FRAME_NORMAL_FACE (f)->font
|
|
351 && face->foreground == FRAME_NORMAL_FACE (f)->foreground
|
|
352 && face->background == FRAME_NORMAL_FACE (f)->background
|
|
353 && face->back_pixmap == FRAME_NORMAL_FACE (f)->back_pixmap
|
|
354 && face->underline == FRAME_NORMAL_FACE (f)->underline)
|
|
355 {
|
|
356 if (!FRAME_NORMAL_FACE (f)->framegc)
|
|
357 build_frame (f, FRAME_NORMAL_FACE (f));
|
|
358 return FRAME_NORMAL_FACE (f);
|
|
359 }
|
|
360
|
|
361 /* If it's equivalent to the mode line face, use that. */
|
|
362 if (face->font == FRAME_MODELINE_FACE (f)->font
|
|
363 && face->foreground == FRAME_MODELINE_FACE (f)->foreground
|
|
364 && face->background == FRAME_MODELINE_FACE (f)->background
|
|
365 && face->back_pixmap == FRAME_MODELINE_FACE (f)->back_pixmap
|
|
366 && face->underline == FRAME_MODELINE_FACE (f)->underline)
|
|
367 {
|
|
368 if (!FRAME_MODELINE_FACE (f)->framegc)
|
|
369 build_frame (f, FRAME_MODELINE_FACE (f));
|
|
370 return FRAME_MODELINE_FACE (f);
|
|
371 }
|
|
372
|
|
373 /* Get a specialized display face. */
|
|
374 return get_cached_face (f, face);
|
|
375 }
|
|
376
|
|
377
|
|
378 /* Allocate a new face */
|
|
379 static struct face *
|
|
380 allocate_face ()
|
|
381 {
|
|
382 struct face *result = (struct face *) xmalloc (sizeof (struct face));
|
|
383 bzero (result, sizeof (struct face));
|
2342
|
384 result->font = (XFontStruct *) FACE_DEFAULT;
|
|
385 result->foreground = FACE_DEFAULT;
|
|
386 result->background = FACE_DEFAULT;
|
|
387 result->back_pixmap = FACE_DEFAULT;
|
2336
|
388 return result;
|
|
389 }
|
|
390
|
|
391 /* Make face id ID valid on frame F. */
|
|
392
|
|
393 void
|
|
394 ensure_face_ready (f, id)
|
|
395 struct frame *f;
|
|
396 int id;
|
|
397 {
|
|
398 if (f->n_faces <= id)
|
|
399 {
|
|
400 int n = id + 10;
|
|
401 int i;
|
|
402 if (!f->n_faces)
|
|
403 f->faces = (struct face **) xmalloc (sizeof (struct face *) * n);
|
|
404 else
|
|
405 f->faces
|
|
406 = (struct face **) xrealloc (f->faces, sizeof (struct face *) * n);
|
|
407
|
|
408 f->n_faces = n;
|
|
409 }
|
|
410
|
|
411 f->faces[id] = allocate_face ();
|
|
412 }
|
|
413
|
|
414 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. */
|
|
415
|
|
416 #ifdef HAVE_X_WINDOWS
|
|
417
|
|
418 static XFontStruct *
|
|
419 load_font (f, name)
|
|
420 struct frame *f;
|
|
421 Lisp_Object name;
|
|
422 {
|
|
423 XFontStruct *font;
|
|
424
|
2342
|
425 if (NILP (name))
|
|
426 return (XFontStruct *) FACE_DEFAULT;
|
|
427
|
2336
|
428 CHECK_STRING (name, 0);
|
|
429 BLOCK_INPUT;
|
|
430 font = XLoadQueryFont (x_current_display, (char *) XSTRING (name)->data);
|
|
431 UNBLOCK_INPUT;
|
|
432
|
|
433 if (! font)
|
|
434 Fsignal (Qerror, Fcons (build_string ("undefined font"),
|
|
435 Fcons (name, Qnil)));
|
|
436 return font;
|
|
437 }
|
|
438
|
|
439 static void
|
|
440 unload_font (f, font)
|
|
441 struct frame *f;
|
|
442 XFontStruct *font;
|
|
443 {
|
|
444 if (!font || font == ((XFontStruct *) FACE_DEFAULT))
|
|
445 return;
|
|
446 XFreeFont (x_current_display, font);
|
|
447 }
|
|
448
|
|
449 static unsigned long
|
|
450 load_color (f, name)
|
|
451 struct frame *f;
|
|
452 Lisp_Object name;
|
|
453 {
|
|
454 Display *dpy = x_current_display;
|
|
455 Colormap cmap;
|
|
456 XColor color;
|
|
457 int result;
|
|
458
|
2342
|
459 if (NILP (name))
|
|
460 return FACE_DEFAULT;
|
|
461
|
2336
|
462 cmap = DefaultColormapOfScreen (x_screen);
|
|
463
|
|
464 CHECK_STRING (name, 0);
|
|
465 BLOCK_INPUT;
|
|
466 result = XParseColor (dpy, cmap, (char *) XSTRING (name)->data, &color);
|
|
467 UNBLOCK_INPUT;
|
|
468 if (! result)
|
|
469 Fsignal (Qerror, Fcons (build_string ("undefined color"),
|
|
470 Fcons (name, Qnil)));
|
|
471 BLOCK_INPUT;
|
|
472 result = XAllocColor (dpy, cmap, &color);
|
|
473 UNBLOCK_INPUT;
|
|
474 if (! result)
|
|
475 Fsignal (Qerror, Fcons (build_string ("X server cannot allocate color"),
|
|
476 Fcons (name, Qnil)));
|
|
477 return (unsigned long) color.pixel;
|
|
478 }
|
|
479
|
|
480 static void
|
|
481 unload_color (f, pixel)
|
|
482 struct frame *f;
|
|
483 Pixel pixel;
|
|
484 {
|
|
485 Colormap cmap;
|
|
486 Display *dpy = x_current_display;
|
|
487 if (pixel == FACE_DEFAULT)
|
|
488 return;
|
|
489 cmap = DefaultColormapOfScreen (x_screen);
|
|
490 BLOCK_INPUT;
|
|
491 XFreeColors (dpy, cmap, &pixel, 1, 0);
|
|
492 UNBLOCK_INPUT;
|
|
493 }
|
|
494
|
|
495 #endif /* HAVE_X_WINDOWS */
|
|
496
|
|
497
|
|
498 /* frames */
|
|
499
|
|
500 void
|
|
501 init_frame_faces (f)
|
|
502 struct frame f;
|
|
503 {
|
|
504 struct frame *other_frame = 0;
|
|
505 Lisp_Object rest;
|
|
506
|
|
507 for (rest = Vframe_list; !NILP (rest); rest = Fcdr (rest))
|
|
508 {
|
|
509 struct frame *f2 = XFRAME (Fcar (rest));
|
|
510 if (f2 != f && FRAME_IS_X (f2))
|
|
511 {
|
|
512 other_frame = f2;
|
|
513 break;
|
|
514 }
|
|
515 }
|
|
516
|
|
517 if (other_frame)
|
|
518 {
|
|
519 /* Make sure this frame's face vector is as big as the others. */
|
|
520 f->n_faces = other_frame->n_faces;
|
|
521 f->faces = (struct face **) xmalloc (f->n_faces * sizeof (struct face *));
|
|
522
|
|
523 /* Make sure the frame has the two basic faces. */
|
|
524 FRAME_NORMAL_FACE (f)
|
|
525 = copy_face (FRAME_NORMAL_FACE (other_frame));
|
|
526 FRAME_MODELINE_FACE (f)
|
|
527 = copy_face (FRAME_MODELINE_FACE (other_frame));
|
|
528 }
|
|
529 }
|
|
530
|
|
531
|
|
532 /* Called from Fdelete_frame? */
|
|
533
|
|
534 void
|
|
535 free_screen_faces (f)
|
|
536 struct frame *f;
|
|
537 {
|
|
538 Display *dpy = x_current_display;
|
|
539 int i;
|
|
540
|
|
541 for (i = 0; i < f->n_faces; i++)
|
|
542 {
|
|
543 struct face *face = f->faces [i];
|
|
544 if (! face)
|
|
545 continue;
|
|
546 if (face->facegc)
|
|
547 XFreeGC (dpy, face->facegc);
|
|
548 unload_font (f, face->font);
|
|
549 unload_color (f, face->foreground);
|
|
550 unload_color (f, face->background);
|
|
551 unload_pixmap (f, face->back_pixmap);
|
|
552 xfree (face);
|
|
553 }
|
|
554 xfree (f->faces);
|
|
555 f->faces = 0;
|
|
556 f->n_faces = 0;
|
|
557 }
|
|
558
|
|
559
|
|
560 /* Lisp interface */
|
|
561
|
|
562 DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, 1, 1, 0,
|
|
563 "")
|
|
564 (frame)
|
|
565 Lisp_Object frame;
|
|
566 {
|
|
567 CHECK_FRAME (frame, 0);
|
|
568 return XFRAME (frame)->face_alist;
|
|
569 }
|
|
570
|
|
571 DEFUN ("set-frame-face-alist", Fset_frame_face_alist, Sset_frame_face_alist,
|
|
572 2, 2, 0, "")
|
|
573 (frame, value)
|
|
574 Lisp_Object frame, value;
|
|
575 {
|
|
576 CHECK_FRAME (frame, 0);
|
|
577 XFRAME (frame)->face_alist = value;
|
|
578 return value;
|
|
579 }
|
|
580
|
|
581
|
|
582 DEFUN ("make-face-internal", Fmake_face_internal, Smake_face_internal, 1, 1, 0,
|
|
583 "Create face number FACE-ID on all frames.")
|
|
584 (face_id)
|
|
585 Lisp_Object face_id;
|
|
586 {
|
|
587 Lisp_Object rest;
|
|
588 int id = XINT (face_id);
|
|
589
|
|
590 CHECK_FIXNUM (face_id, 0);
|
|
591 if (id < 0)
|
|
592 error ("Face id must be nonnegative");
|
|
593
|
|
594 for (rest = Vframe_list; !NILP (rest); rest = XCONS (rest)->cdr)
|
|
595 {
|
|
596 struct frame *f = XFRAME (XCONS (rest)->car);
|
|
597 ensure_face_ready (f, id);
|
|
598 }
|
|
599 return Qnil;
|
|
600 }
|
|
601
|
|
602
|
|
603 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal,
|
|
604 Sset_face_attribute_internal, 4, 4, 0, "")
|
|
605 (face_id, attr_name, attr_value, frame)
|
|
606 Lisp_Object face_id, attr_name, attr_value, frame;
|
|
607 {
|
|
608 struct face *face;
|
|
609 struct frame *f;
|
|
610 int magic_p;
|
|
611 int id;
|
|
612
|
|
613 CHECK_FRAME (frame, 0);
|
|
614 CHECK_FIXNUM (face_id, 0);
|
|
615 CHECK_SYMBOL (attr_name, 0);
|
|
616
|
|
617 f = XFRAME (frame);
|
|
618 id = XINT (face_id);
|
|
619 if (id < 0)
|
|
620 Fsignal (Qerror, Fcons (build_string ("invalid face id"),
|
|
621 Fcons (face_id, Fcons (frame, Qnil))));
|
|
622
|
|
623 ensure_face_ready (f, id);
|
|
624 face = f->faces [XFASTINT (face_id)];
|
|
625 if (! face) abort ();
|
|
626
|
|
627 magic_p = (NILP (attr_value) && XFASTINT (face_id) <= 1);
|
|
628
|
|
629 if (EQ (attr_name, intern ("font")))
|
|
630 {
|
|
631 #ifdef HAVE_X_WINDOWS
|
|
632 XFontStruct *font;
|
|
633 if (magic_p)
|
|
634 error ("font of the `normal' or `modeline' face may not be nil");
|
|
635 font = load_font (f, attr_value);
|
|
636 unload_font (f, face->font);
|
|
637 face->font = font;
|
|
638 #endif /* HAVE_X_WINDOWS */
|
|
639 }
|
|
640 else if (EQ (attr_name, intern ("foreground")))
|
|
641 {
|
|
642 #ifdef HAVE_X_WINDOWS
|
|
643 unsigned long new_color;
|
|
644 if (magic_p)
|
|
645 error ("forground color of the `normal' or `modeline' face may not be nil");
|
|
646 new_color = load_color (f, attr_value);
|
|
647 unload_color (f, face->foreground);
|
|
648 face->foreground = new_color;
|
|
649 #endif /* HAVE_X_WINDOWS */
|
|
650 }
|
|
651 else if (EQ (attr_name, intern ("background")))
|
|
652 {
|
|
653 #ifdef HAVE_X_WINDOWS
|
|
654 unsigned long new_color;
|
|
655 if (magic_p)
|
|
656 error ("background color of the `normal' or `modeline' face may not be nil");
|
|
657 new_color = load_color (f, attr_value);
|
|
658 unload_color (f, face->background);
|
|
659 face->background = new_color;
|
|
660 #endif /* HAVE_X_WINDOWS */
|
|
661 }
|
|
662 #if 0
|
|
663 else if (EQ (attr_name, intern ("background-pixmap")))
|
|
664 {
|
|
665 #ifdef HAVE_X_WINDOWS
|
|
666 unsigned int w, h, d;
|
|
667 unsigned long new_pixmap = load_pixmap (f, attr_value, &w, &h, &d, 0);
|
|
668 unload_pixmap (f, face->back_pixmap);
|
|
669 if (magic_p) new_pixmap = 0;
|
|
670 face->back_pixmap = new_pixmap;
|
|
671 face->pixmap_w = w;
|
|
672 face->pixmap_h = h;
|
|
673 /* face->pixmap_depth = d; */
|
|
674 #endif /* HAVE_X_WINDOWS */
|
|
675 }
|
|
676 #endif /* 0 */
|
|
677 else if (EQ (attr_name, intern ("underline")))
|
|
678 {
|
|
679 int new = !NILP (attr_value);
|
|
680 face->underline = new;
|
|
681 }
|
|
682 else
|
|
683 error ("unknown face attribute");
|
|
684
|
|
685 if (id == 0)
|
|
686 {
|
|
687 BLOCK_INPUT;
|
|
688 XFreeGC (dpy, FRAME_NORMAL_FACE (f)->facegc);
|
|
689 build_face (f, FRAME_NORMAL_FACE (f));
|
|
690 UNBLOCK_INPUT;
|
|
691 }
|
|
692
|
|
693 if (id == 1)
|
|
694 {
|
|
695 BLOCK_INPUT;
|
|
696 XFreeGC (dpy, FRAME_NORMAL_FACE (f)->facegc);
|
|
697 build_face (f, FRAME_NORMAL_FACE (f));
|
|
698 UNBLOCK_INPUT;
|
|
699 }
|
|
700
|
|
701 return Qnil;
|
|
702 }
|
|
703
|
|
704 DEFUN ("internal-next-face-id", Finternal_next_face_id, Sinternal_next_face_id,
|
|
705 0, 0, 0, "")
|
|
706 ()
|
|
707 {
|
|
708 return make_number (next_face_id++);
|
|
709 }
|
|
710
|
|
711 void
|
|
712 syms_of_faces ()
|
|
713 {
|
|
714 defsubr (&Sframe_face_alist);
|
|
715 defsubr (&Sset_frame_face_alist);
|
|
716 defsubr (&Smake_face_internal);
|
|
717 defsubr (&Sset_face_attribute_internal);
|
|
718 defsubr (&Sinternal_next_face_id);
|
|
719 }
|