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