Mercurial > emacs
annotate src/w32faces.c @ 23554:e06e84c477fa
(Fsubst_char_in_region): Correctly handle the case
that byte combining before happens.
(Ftranslate_region): Likewise.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 27 Oct 1998 03:54:13 +0000 |
parents | 1050835fbcef |
children | f6c3cc94ae4f |
rev | line source |
---|---|
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16588
diff
changeset
|
1 /* "Face" primitives on the Microsoft W32 API. |
13434 | 2 Copyright (C) 1993, 1994, 1995 Free Software Foundation. |
3 | |
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 | |
8 the Free Software Foundation; either version 2, or (at your option) | |
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 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
13434 | 20 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16051
diff
changeset
|
21 /* Ported xfaces.c for w32 - Kevin Gallo */ |
13434 | 22 |
23 #include <sys/types.h> | |
24 #include <sys/stat.h> | |
25 | |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 | |
29 #include "w32term.h" | |
30 #include "buffer.h" | |
31 #include "dispextern.h" | |
32 #include "frame.h" | |
33 #include "blockinput.h" | |
34 #include "window.h" | |
35 #include "intervals.h" | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
36 #include "charset.h" |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
37 #include "fontset.h" |
13434 | 38 |
39 | |
40 /* An explanation of the face data structures. */ | |
41 | |
42 /* ========================= Face Data Structures ========================= | |
43 | |
44 Let FACE-NAME be a symbol naming a face. | |
45 | |
46 Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME)) | |
47 FACE-VECTOR is either nil, or a vector of the form | |
48 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P] | |
49 where | |
50 face is the symbol `face', | |
51 NAME is the symbol with which this vector is associated (a backpointer), | |
52 ID is the face ID, an integer used internally by the C code to identify | |
53 the face, | |
54 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
55 to use with the face, FONT may name fontsets, |
13434 | 56 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't |
57 use right now, and | |
58 UNDERLINE-P is non-nil if the face should be underlined. | |
59 If any of these elements are nil, that parameter is considered | |
60 unspecified; parameters from faces specified by lower-priority | |
61 overlays or text properties, or the parameters of the frame itself, | |
62 can show through. (lisp/faces.el maintains these lists.) | |
63 | |
64 (assq FACE-NAME global-face-data) returns a vector describing the | |
65 global parameters for that face. | |
66 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
67 Let PARAM-FACE be FRAME->output_data.w32->param_faces[Faref(FACE-VECTOR,2)]. |
13434 | 68 PARAM_FACE is a struct face whose members are the Xlib analogues of |
69 the parameters in FACE-VECTOR. If an element of FACE-VECTOR is | |
70 nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT. | |
71 These faces are called "parameter faces", because they're the ones | |
72 lisp manipulates to control what gets displayed. Elements 0 and 1 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
73 of FRAME->output_data.w32->param_faces are special - they describe the |
13434 | 74 default and mode line faces. None of the faces in param_faces have |
14036 | 75 GC's. (See src/dispextern.h for the definition of struct face. |
13434 | 76 lisp/faces.el maintains the isomorphism between face_alist and |
77 param_faces.) | |
78 | |
79 The functions compute_char_face and compute_glyph_face find and | |
80 combine the parameter faces associated with overlays and text | |
81 properties. The resulting faces are called "computed faces"; none | |
82 of their members are FACE_DEFAULT; they are completely specified. | |
83 They then call intern_compute_face to search | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
84 FRAME->output_data.x->computed_faces for a matching face, add one if |
13434 | 85 none is found, and return the index into |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
86 FRAME->output_data.x->computed_faces. FRAME's glyph matrices use these |
13434 | 87 indices to record the faces of the matrix characters, and the X |
88 display hooks consult compute_faces to decide how to display these | |
89 characters. Elements 0 and 1 of computed_faces always describe the | |
90 default and mode-line faces. | |
91 | |
92 Each computed face belongs to a particular frame. | |
93 | |
94 Computed faces have graphics contexts some of the time. | |
95 intern_face builds a GC for a specified computed face | |
96 if it doesn't have one already. | |
97 clear_face_cache clears out the GCs of all computed faces. | |
98 This is done from time to time so that we don't hold on to | |
99 lots of GCs that are no longer needed. | |
100 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
101 If a computed face has 0 as its font, |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
102 it is unused, and can be reused by new_computed_face. |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
103 |
13434 | 104 Constraints: |
105 | |
106 Symbols naming faces must have associations on all frames; for any | |
107 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist | |
108 FRAME)) is non-nil, it must be non-nil for all frames. | |
109 | |
110 Analogously, indices into param_faces must be valid on all frames; | |
111 if param_faces[i] is a non-zero face pointer on one frame, then it | |
112 must be filled in on all frames. Code assumes that face ID's can | |
113 be used on any frame. | |
114 | |
115 Some subtleties: | |
116 | |
117 Why do we keep param_faces and computed_faces separate? | |
118 computed_faces contains an element for every combination of facial | |
119 parameters we have ever displayed. indices into param_faces have | |
120 to be valid on all frames. If they were the same array, then that | |
121 array would grow very large on all frames, because any facial | |
122 combination displayed on any frame would need to be a valid entry | |
123 on all frames. */ | |
124 | |
125 /* Definitions and declarations. */ | |
126 | |
127 /* The number of face-id's in use (same for all frames). */ | |
128 static int next_face_id; | |
129 | |
130 /* The number of the face to use to indicate the region. */ | |
131 static int region_face; | |
132 | |
133 /* This is what appears in a slot in a face to signify that the face | |
134 does not specify that display aspect. */ | |
135 #define FACE_DEFAULT (~0) | |
136 | |
137 Lisp_Object Qface, Qmouse_face; | |
138 Lisp_Object Qpixmap_spec_p; | |
139 | |
140 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ ); | |
141 | |
142 struct face *intern_face ( /* FRAME_PTR, struct face * */ ); | |
143 static int new_computed_face ( /* FRAME_PTR, struct face * */ ); | |
144 static int intern_computed_face ( /* FRAME_PTR, struct face * */ ); | |
145 static void ensure_face_ready ( /* FRAME_PTR, int id */ ); | |
146 void recompute_basic_faces ( /* FRAME_PTR f */ ); | |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
147 static void merge_face_list ( /* FRAME_PTR, struct face *, Lisp_Object */ ); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
148 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
149 extern Lisp_Object Qforeground_color, Qbackground_color; |
13434 | 150 |
151 /* Allocating, copying, and comparing struct faces. */ | |
152 | |
153 /* Allocate a new face */ | |
154 static struct face * | |
155 allocate_face () | |
156 { | |
157 struct face *result = (struct face *) xmalloc (sizeof (struct face)); | |
158 bzero (result, sizeof (struct face)); | |
159 result->font = (XFontStruct *) FACE_DEFAULT; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
160 result->fontset = -1; |
13434 | 161 result->foreground = FACE_DEFAULT; |
162 result->background = FACE_DEFAULT; | |
163 result->stipple = FACE_DEFAULT; | |
164 return result; | |
165 } | |
166 | |
167 /* Make a new face that's a copy of an existing one. */ | |
168 static struct face * | |
169 copy_face (face) | |
170 struct face *face; | |
171 { | |
172 struct face *result = allocate_face (); | |
173 | |
174 result->font = face->font; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
175 result->fontset = face->fontset; |
13434 | 176 result->foreground = face->foreground; |
177 result->background = face->background; | |
178 result->stipple = face->stipple; | |
179 result->underline = face->underline; | |
180 result->pixmap_h = face->pixmap_h; | |
181 result->pixmap_w = face->pixmap_w; | |
182 | |
183 return result; | |
184 } | |
185 | |
186 static int | |
187 face_eql (face1, face2) | |
188 struct face *face1, *face2; | |
189 { | |
190 return ( face1->font == face2->font | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
191 && face1->fontset == face2->fontset |
13434 | 192 && face1->foreground == face2->foreground |
193 && face1->background == face2->background | |
194 && face1->stipple == face2->stipple | |
195 && face1->underline == face2->underline); | |
196 } | |
197 | |
198 /* Managing graphics contexts of faces. */ | |
199 | |
200 /* Given a computed face, construct its graphics context if necessary. */ | |
201 | |
202 struct face * | |
203 intern_face (f, face) | |
204 struct frame *f; | |
205 struct face *face; | |
206 { | |
207 face->gc = NULL; | |
208 | |
209 return face; | |
210 } | |
211 | |
212 /* Clear out all graphics contexts for all computed faces | |
213 except for the default and mode line faces. | |
214 This should be done from time to time just to avoid | |
215 keeping too many graphics contexts that are no longer needed. */ | |
216 | |
217 void | |
218 clear_face_cache () | |
219 { | |
220 /* Nothing extra */ | |
221 } | |
222 | |
223 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. | |
224 | |
225 These functions operate on param faces only. | |
226 Computed faces get their fonts, colors and pixmaps | |
227 by merging param faces. */ | |
228 | |
229 static XFontStruct * | |
230 load_font (f, name) | |
231 struct frame *f; | |
232 Lisp_Object name; | |
233 { | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
234 struct font_info *fontinf; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
235 XFontStruct *font = NULL; |
13434 | 236 |
237 if (NILP (name)) | |
238 return (XFontStruct *) FACE_DEFAULT; | |
239 | |
240 CHECK_STRING (name, 0); | |
241 BLOCK_INPUT; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
242 fontinf = w32_load_font (f, (char *) XSTRING (name)->data, 0); |
13434 | 243 UNBLOCK_INPUT; |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
244 if (fontinf) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
245 font = (XFontStruct *)fontinf->font; |
13434 | 246 |
247 if (! font) | |
248 Fsignal (Qerror, Fcons (build_string ("undefined font"), | |
249 Fcons (name, Qnil))); | |
250 return font; | |
251 } | |
252 | |
253 static void | |
254 unload_font (f, font) | |
255 struct frame *f; | |
256 XFontStruct *font; | |
257 { | |
258 if (!font || font == ((XFontStruct *) FACE_DEFAULT)) | |
259 return; | |
260 | |
261 BLOCK_INPUT; | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16051
diff
changeset
|
262 w32_unload_font (FRAME_W32_DISPLAY_INFO (f), font); |
13434 | 263 UNBLOCK_INPUT; |
264 } | |
265 | |
266 static unsigned long | |
267 load_color (f, name) | |
268 struct frame *f; | |
269 Lisp_Object name; | |
270 { | |
271 COLORREF color; | |
272 int result; | |
273 | |
274 if (NILP (name)) | |
275 return FACE_DEFAULT; | |
276 | |
277 CHECK_STRING (name, 0); | |
278 /* if the colormap is full, defined_color will return a best match | |
279 to the values in an an existing cell. */ | |
280 result = defined_color(f, (char *) XSTRING (name)->data, &color, 1); | |
281 if (! result) | |
282 Fsignal (Qerror, Fcons (build_string ("undefined color"), | |
283 Fcons (name, Qnil))); | |
284 return (unsigned long) color; | |
285 } | |
286 | |
287 static void | |
288 unload_color (f, pixel) | |
289 struct frame *f; | |
290 unsigned long pixel; | |
291 { | |
292 } | |
293 | |
294 DEFUN ("pixmap-spec-p", Fpixmap_spec_p, Spixmap_spec_p, 1, 1, 0, | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
295 "Return t if OBJECT is a valid pixmap specification.") |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
296 (object) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
297 Lisp_Object object; |
13434 | 298 { |
299 Lisp_Object height, width; | |
300 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
301 return ((STRINGP (object) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
302 || (CONSP (object) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
303 && CONSP (XCONS (object)->cdr) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
304 && CONSP (XCONS (XCONS (object)->cdr)->cdr) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
305 && NILP (XCONS (XCONS (XCONS (object)->cdr)->cdr)->cdr) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
306 && (width = XCONS (object)->car, INTEGERP (width)) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
307 && (height = XCONS (XCONS (object)->cdr)->car, INTEGERP (height)) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
308 && STRINGP (XCONS (XCONS (XCONS (object)->cdr)->cdr)->car) |
13434 | 309 && XINT (width) > 0 |
310 && XINT (height) > 0 | |
311 /* The string must have enough bits for width * height. */ | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
312 && ((XSTRING (XCONS (XCONS (XCONS (object)->cdr)->cdr)->car)->size |
13434 | 313 * (BITS_PER_INT / sizeof (int))) |
314 >= XFASTINT (width) * XFASTINT (height)))) | |
315 ? Qt : Qnil); | |
316 } | |
317 | |
318 /* Load a bitmap according to NAME (which is either a file name | |
319 or a pixmap spec). Return the bitmap_id (see xfns.c) | |
320 or get an error if NAME is invalid. | |
321 | |
322 Store the bitmap width in *W_PTR and height in *H_PTR. */ | |
323 | |
324 static long | |
325 load_pixmap (f, name, w_ptr, h_ptr) | |
326 FRAME_PTR f; | |
327 Lisp_Object name; | |
328 unsigned int *w_ptr, *h_ptr; | |
329 { | |
330 int bitmap_id; | |
331 Lisp_Object tem; | |
332 | |
333 if (NILP (name)) | |
334 return FACE_DEFAULT; | |
335 | |
336 tem = Fpixmap_spec_p (name); | |
337 if (NILP (tem)) | |
338 wrong_type_argument (Qpixmap_spec_p, name); | |
339 | |
340 BLOCK_INPUT; | |
341 | |
342 if (CONSP (name)) | |
343 { | |
344 /* Decode a bitmap spec into a bitmap. */ | |
345 | |
346 int h, w; | |
347 Lisp_Object bits; | |
348 | |
349 w = XINT (Fcar (name)); | |
350 h = XINT (Fcar (Fcdr (name))); | |
351 bits = Fcar (Fcdr (Fcdr (name))); | |
352 | |
353 bitmap_id = x_create_bitmap_from_data (f, XSTRING (bits)->data, | |
354 w, h); | |
355 } | |
356 else | |
357 { | |
358 /* It must be a string -- a file name. */ | |
359 bitmap_id = x_create_bitmap_from_file (f, name); | |
360 } | |
361 UNBLOCK_INPUT; | |
362 | |
363 if (bitmap_id < 0) | |
364 Fsignal (Qerror, Fcons (build_string ("invalid or undefined bitmap"), | |
365 Fcons (name, Qnil))); | |
366 | |
367 *w_ptr = x_bitmap_width (f, bitmap_id); | |
368 *h_ptr = x_bitmap_height (f, bitmap_id); | |
369 | |
370 return bitmap_id; | |
371 } | |
372 | |
373 | |
374 /* Managing parameter face arrays for frames. */ | |
375 | |
376 void | |
377 init_frame_faces (f) | |
378 FRAME_PTR f; | |
379 { | |
380 ensure_face_ready (f, 0); | |
381 ensure_face_ready (f, 1); | |
382 | |
383 FRAME_N_COMPUTED_FACES (f) = 0; | |
384 FRAME_SIZE_COMPUTED_FACES (f) = 0; | |
385 | |
386 new_computed_face (f, FRAME_PARAM_FACES (f)[0]); | |
387 new_computed_face (f, FRAME_PARAM_FACES (f)[1]); | |
388 recompute_basic_faces (f); | |
389 | |
390 /* Find another frame. */ | |
391 { | |
392 Lisp_Object tail, frame, result; | |
393 | |
394 result = Qnil; | |
395 FOR_EACH_FRAME (tail, frame) | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16051
diff
changeset
|
396 if (FRAME_W32_P (XFRAME (frame)) |
13434 | 397 && XFRAME (frame) != f) |
398 { | |
399 result = frame; | |
400 break; | |
401 } | |
402 | |
403 /* If we didn't find any X frames other than f, then we don't need | |
404 any faces other than 0 and 1, so we're okay. Otherwise, make | |
405 sure that all faces valid on the selected frame are also valid | |
406 on this new frame. */ | |
407 if (FRAMEP (result)) | |
408 { | |
409 int i; | |
410 int n_faces = FRAME_N_PARAM_FACES (XFRAME (result)); | |
411 struct face **faces = FRAME_PARAM_FACES (XFRAME (result)); | |
412 | |
413 for (i = 2; i < n_faces; i++) | |
414 if (faces[i]) | |
415 ensure_face_ready (f, i); | |
416 } | |
417 } | |
418 } | |
419 | |
420 | |
421 /* Called from Fdelete_frame. */ | |
422 | |
423 void | |
424 free_frame_faces (f) | |
425 struct frame *f; | |
426 { | |
427 int i; | |
428 | |
429 BLOCK_INPUT; | |
430 | |
431 for (i = 0; i < FRAME_N_PARAM_FACES (f); i++) | |
432 { | |
433 struct face *face = FRAME_PARAM_FACES (f) [i]; | |
434 if (face) | |
435 { | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
436 if (face->fontset < 0) |
13434 | 437 unload_font (f, face->font); |
438 unload_color (f, face->foreground); | |
439 unload_color (f, face->background); | |
440 x_destroy_bitmap (f, face->stipple); | |
441 xfree (face); | |
442 } | |
443 } | |
444 xfree (FRAME_PARAM_FACES (f)); | |
445 FRAME_PARAM_FACES (f) = 0; | |
446 FRAME_N_PARAM_FACES (f) = 0; | |
447 | |
448 /* All faces in FRAME_COMPUTED_FACES use resources copied from | |
449 FRAME_PARAM_FACES; we can free them without fuss. | |
450 But we do free the GCs and the face objects themselves. */ | |
451 for (i = 0; i < FRAME_N_COMPUTED_FACES (f); i++) | |
452 { | |
453 struct face *face = FRAME_COMPUTED_FACES (f) [i]; | |
454 if (face) | |
455 { | |
456 xfree (face); | |
457 } | |
458 } | |
459 xfree (FRAME_COMPUTED_FACES (f)); | |
460 FRAME_COMPUTED_FACES (f) = 0; | |
461 FRAME_N_COMPUTED_FACES (f) = 0; | |
462 | |
463 UNBLOCK_INPUT; | |
464 } | |
465 | |
466 /* Interning faces in a frame's face array. */ | |
467 | |
468 static int | |
469 new_computed_face (f, new_face) | |
470 struct frame *f; | |
471 struct face *new_face; | |
472 { | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
473 int len = FRAME_N_COMPUTED_FACES (f); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
474 int i; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
475 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
476 /* Search for an unused computed face in the middle of the table. */ |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
477 for (i = 0; i < len; i++) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
478 { |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
479 struct face *face = FRAME_COMPUTED_FACES (f)[i]; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
480 if (face->font == 0) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
481 { |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
482 FRAME_COMPUTED_FACES (f)[i] = copy_face (new_face); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
483 return i; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
484 } |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
485 } |
13434 | 486 |
487 if (i >= FRAME_SIZE_COMPUTED_FACES (f)) | |
488 { | |
489 int new_size = i + 32; | |
490 | |
491 FRAME_COMPUTED_FACES (f) | |
492 = (struct face **) (FRAME_SIZE_COMPUTED_FACES (f) == 0 | |
493 ? xmalloc (new_size * sizeof (struct face *)) | |
494 : xrealloc (FRAME_COMPUTED_FACES (f), | |
495 new_size * sizeof (struct face *))); | |
496 FRAME_SIZE_COMPUTED_FACES (f) = new_size; | |
497 } | |
498 | |
499 i = FRAME_N_COMPUTED_FACES (f)++; | |
500 FRAME_COMPUTED_FACES (f)[i] = copy_face (new_face); | |
501 return i; | |
502 } | |
503 | |
504 | |
505 /* Find a match for NEW_FACE in a FRAME's computed face array, and add | |
506 it if we don't find one. */ | |
507 static int | |
508 intern_computed_face (f, new_face) | |
509 struct frame *f; | |
510 struct face *new_face; | |
511 { | |
512 int len = FRAME_N_COMPUTED_FACES (f); | |
513 int i; | |
514 | |
515 /* Search for a computed face already on F equivalent to FACE. */ | |
516 for (i = 0; i < len; i++) | |
517 { | |
518 if (! FRAME_COMPUTED_FACES (f)[i]) | |
519 abort (); | |
520 if (face_eql (new_face, FRAME_COMPUTED_FACES (f)[i])) | |
521 return i; | |
522 } | |
523 | |
524 /* We didn't find one; add a new one. */ | |
525 return new_computed_face (f, new_face); | |
526 } | |
527 | |
528 /* Make parameter face id ID valid on frame F. */ | |
529 | |
530 static void | |
531 ensure_face_ready (f, id) | |
532 struct frame *f; | |
533 int id; | |
534 { | |
535 if (FRAME_N_PARAM_FACES (f) <= id) | |
536 { | |
537 int n = id + 10; | |
538 int i; | |
539 if (!FRAME_N_PARAM_FACES (f)) | |
540 FRAME_PARAM_FACES (f) | |
541 = (struct face **) xmalloc (sizeof (struct face *) * n); | |
542 else | |
543 FRAME_PARAM_FACES (f) | |
544 = (struct face **) xrealloc (FRAME_PARAM_FACES (f), | |
545 sizeof (struct face *) * n); | |
546 | |
547 bzero (FRAME_PARAM_FACES (f) + FRAME_N_PARAM_FACES (f), | |
548 (n - FRAME_N_PARAM_FACES (f)) * sizeof (struct face *)); | |
549 FRAME_N_PARAM_FACES (f) = n; | |
550 } | |
551 | |
552 if (FRAME_PARAM_FACES (f) [id] == 0) | |
553 FRAME_PARAM_FACES (f) [id] = allocate_face (); | |
554 } | |
555 | |
556 /* Return non-zero if FONT1 and FONT2 have the same width. | |
557 We do not check the height, because we can now deal with | |
558 different heights. | |
559 We assume that they're both character-cell fonts. */ | |
560 | |
561 int | |
562 same_size_fonts (font1, font2) | |
563 XFontStruct *font1, *font2; | |
564 { | |
565 return (FONT_WIDTH(font1) == FONT_WIDTH(font2)); | |
566 } | |
567 | |
568 /* Update the line_height of frame F according to the biggest font in | |
569 any face. Return nonzero if if line_height changes. */ | |
570 | |
571 int | |
572 frame_update_line_height (f) | |
573 FRAME_PTR f; | |
574 { | |
575 int i; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
576 int fontset = FRAME_FONTSET (f); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
577 int biggest = (fontset > 0 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
578 ? FRAME_FONTSET_DATA (f)->fontset_table[fontset]->height |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
579 : FONT_HEIGHT (FRAME_FONT (f))); |
13434 | 580 |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
581 for (i = 0; i < FRAME_N_PARAM_FACES (f); i++) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
582 if (FRAME_PARAM_FACES (f)[i] != 0 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
583 && FRAME_PARAM_FACES (f)[i]->font != (XFontStruct *) FACE_DEFAULT) |
13434 | 584 { |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
585 int height = ((fontset = |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
586 FRAME_PARAM_FACES (f)[i]->fontset) > 0 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
587 ? FRAME_FONTSET_DATA (f)->fontset_table[fontset]->height |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
588 : FONT_HEIGHT |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
589 (FRAME_PARAM_FACES (f)[i]->font)); |
13434 | 590 if (height > biggest) |
591 biggest = height; | |
592 } | |
593 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
594 if (biggest == FRAME_LINE_HEIGHT (f)) |
13434 | 595 return 0; |
596 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
597 FRAME_LINE_HEIGHT (f) = biggest; |
13434 | 598 return 1; |
599 } | |
600 | |
601 /* Modify face TO by copying from FROM all properties which have | |
602 nondefault settings. */ | |
603 | |
604 static void | |
605 merge_faces (from, to) | |
606 struct face *from, *to; | |
607 { | |
608 /* Only merge the font if it's the same width as the base font. | |
609 Otherwise ignore it, since we can't handle it properly. */ | |
610 if (from->font != (XFontStruct *) FACE_DEFAULT | |
611 && same_size_fonts (from->font, to->font)) | |
612 to->font = from->font; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
613 if (from->fontset != -1) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
614 to->fontset = from->fontset; |
13434 | 615 if (from->foreground != FACE_DEFAULT) |
616 to->foreground = from->foreground; | |
617 if (from->background != FACE_DEFAULT) | |
618 to->background = from->background; | |
619 if (from->stipple != FACE_DEFAULT) | |
620 { | |
621 to->stipple = from->stipple; | |
622 to->pixmap_h = from->pixmap_h; | |
623 to->pixmap_w = from->pixmap_w; | |
624 } | |
625 if (from->underline) | |
626 to->underline = from->underline; | |
627 } | |
628 | |
629 /* Set up the basic set of facial parameters, based on the frame's | |
630 data; all faces are deltas applied to this. */ | |
631 | |
632 static void | |
633 compute_base_face (f, face) | |
634 FRAME_PTR f; | |
635 struct face *face; | |
636 { | |
637 face->gc = 0; | |
638 face->foreground = FRAME_FOREGROUND_PIXEL (f); | |
639 face->background = FRAME_BACKGROUND_PIXEL (f); | |
640 face->font = FRAME_FONT (f); | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
641 face->fontset = -1; |
13434 | 642 face->stipple = 0; |
643 face->underline = 0; | |
644 } | |
645 | |
646 /* Return the face ID to use to display a special glyph which selects | |
647 FACE_CODE as the face ID, assuming that ordinarily the face would | |
648 be CURRENT_FACE. F is the frame. */ | |
649 | |
650 int | |
651 compute_glyph_face (f, face_code, current_face) | |
652 struct frame *f; | |
653 int face_code, current_face; | |
654 { | |
655 struct face face; | |
656 | |
657 face = *FRAME_COMPUTED_FACES (f)[current_face]; | |
658 | |
659 if (face_code >= 0 && face_code < FRAME_N_PARAM_FACES (f) | |
660 && FRAME_PARAM_FACES (f) [face_code] != 0) | |
661 merge_faces (FRAME_PARAM_FACES (f) [face_code], &face); | |
662 | |
663 return intern_computed_face (f, &face); | |
664 } | |
665 | |
666 /* Return the face ID to use to display a special glyph which selects | |
667 FACE_CODE as the face ID, assuming that ordinarily the face would | |
668 be CURRENT_FACE. F is the frame. */ | |
669 | |
670 int | |
671 compute_glyph_face_1 (f, face_name, current_face) | |
672 struct frame *f; | |
673 Lisp_Object face_name; | |
674 int current_face; | |
675 { | |
676 struct face face; | |
677 | |
678 face = *FRAME_COMPUTED_FACES (f)[current_face]; | |
679 | |
680 if (!NILP (face_name)) | |
681 { | |
682 int facecode = face_name_id_number (f, face_name); | |
683 if (facecode >= 0 && facecode < FRAME_N_PARAM_FACES (f) | |
684 && FRAME_PARAM_FACES (f) [facecode] != 0) | |
685 merge_faces (FRAME_PARAM_FACES (f) [facecode], &face); | |
686 } | |
687 | |
688 return intern_computed_face (f, &face); | |
689 } | |
690 | |
691 /* Return the face ID associated with a buffer position POS. | |
692 Store into *ENDPTR the position at which a different face is needed. | |
693 This does not take account of glyphs that specify their own face codes. | |
694 F is the frame in use for display, and W is a window displaying | |
695 the current buffer. | |
696 | |
697 REGION_BEG, REGION_END delimit the region, so it can be highlighted. | |
698 | |
699 LIMIT is a position not to scan beyond. That is to limit | |
700 the time this function can take. | |
701 | |
702 If MOUSE is nonzero, use the character's mouse-face, not its face. */ | |
703 int | |
704 compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse) | |
705 struct frame *f; | |
706 struct window *w; | |
707 int pos; | |
708 int region_beg, region_end; | |
709 int *endptr; | |
710 int limit; | |
711 int mouse; | |
712 { | |
713 struct face face; | |
714 Lisp_Object prop, position; | |
715 int i, j, noverlays; | |
716 int facecode; | |
717 Lisp_Object *overlay_vec; | |
718 Lisp_Object frame; | |
719 int endpos; | |
720 Lisp_Object propname; | |
721 | |
722 /* W must display the current buffer. We could write this function | |
723 to use the frame and buffer of W, but right now it doesn't. */ | |
724 if (XBUFFER (w->buffer) != current_buffer) | |
725 abort (); | |
726 | |
727 XSETFRAME (frame, f); | |
728 | |
729 endpos = ZV; | |
730 if (pos < region_beg && region_beg < endpos) | |
731 endpos = region_beg; | |
732 | |
733 XSETFASTINT (position, pos); | |
734 | |
735 if (mouse) | |
736 propname = Qmouse_face; | |
737 else | |
738 propname = Qface; | |
739 | |
740 prop = Fget_text_property (position, propname, w->buffer); | |
741 | |
742 { | |
743 Lisp_Object limit1, end; | |
744 | |
745 XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); | |
746 end = Fnext_single_property_change (position, propname, w->buffer, limit1); | |
747 if (INTEGERP (end)) | |
748 endpos = XINT (end); | |
749 } | |
750 | |
751 { | |
752 int next_overlay; | |
753 int len; | |
754 | |
755 /* First try with room for 40 overlays. */ | |
756 len = 40; | |
757 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
758 | |
759 noverlays = overlays_at (pos, 0, &overlay_vec, &len, | |
760 &next_overlay, (int *) 0); | |
761 | |
762 /* If there are more than 40, | |
763 make enough space for all, and try again. */ | |
764 if (noverlays > len) | |
765 { | |
766 len = noverlays; | |
767 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
768 noverlays = overlays_at (pos, 0, &overlay_vec, &len, | |
769 &next_overlay, (int *) 0); | |
770 } | |
771 | |
772 if (next_overlay < endpos) | |
773 endpos = next_overlay; | |
774 } | |
775 | |
776 *endptr = endpos; | |
777 | |
778 /* Optimize the default case. */ | |
779 if (noverlays == 0 && NILP (prop) | |
780 && !(pos >= region_beg && pos < region_end)) | |
781 return 0; | |
782 | |
783 compute_base_face (f, &face); | |
784 | |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
785 merge_face_list (f, &face, prop); |
13434 | 786 |
787 noverlays = sort_overlays (overlay_vec, noverlays, w); | |
788 | |
789 /* Now merge the overlay data in that order. */ | |
790 for (i = 0; i < noverlays; i++) | |
791 { | |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
792 Lisp_Object oend; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
793 int oendpos; |
13434 | 794 |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
795 prop = Foverlay_get (overlay_vec[i], propname); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
796 merge_face_list (f, &face, prop); |
13434 | 797 |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
798 oend = OVERLAY_END (overlay_vec[i]); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
799 oendpos = OVERLAY_POSITION (oend); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
800 if (oendpos < endpos) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
801 endpos = oendpos; |
13434 | 802 } |
803 | |
804 if (pos >= region_beg && pos < region_end) | |
805 { | |
806 if (region_end < endpos) | |
807 endpos = region_end; | |
808 if (region_face >= 0 && region_face < next_face_id) | |
809 merge_faces (FRAME_PARAM_FACES (f)[region_face], &face); | |
810 } | |
811 | |
812 *endptr = endpos; | |
813 | |
814 return intern_computed_face (f, &face); | |
815 } | |
21607
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
816 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
817 static void |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
818 merge_face_list (f, face, prop) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
819 FRAME_PTR f; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
820 struct face *face; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
821 Lisp_Object prop; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
822 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
823 Lisp_Object length; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
824 int len; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
825 Lisp_Object *faces; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
826 int j; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
827 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
828 if (CONSP (prop) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
829 && ! STRINGP (XCONS (prop)->cdr)) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
830 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
831 /* We have a list of faces, merge them in reverse order. */ |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
832 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
833 length = Fsafe_length (prop); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
834 len = XFASTINT (length); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
835 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
836 /* Put them into an array. */ |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
837 faces = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
838 for (j = 0; j < len; j++) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
839 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
840 faces[j] = Fcar (prop); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
841 prop = Fcdr (prop); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
842 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
843 /* So that we can merge them in the reverse order. */ |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
844 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
845 else |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
846 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
847 faces = (Lisp_Object *) alloca (sizeof (Lisp_Object)); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
848 faces[0] = prop; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
849 len = 1; |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
850 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
851 |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
852 for (j = len - 1; j >= 0; j--) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
853 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
854 if (CONSP (faces[j])) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
855 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
856 if (EQ (XCONS (faces[j])->car, Qbackground_color)) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
857 face->background = load_color (f, XCONS (faces[j])->cdr); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
858 if (EQ (XCONS (faces[j])->car, Qforeground_color)) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
859 face->foreground = load_color (f, XCONS (faces[j])->cdr); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
860 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
861 else |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
862 { |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
863 int facecode = face_name_id_number (f, faces[j]); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
864 if (facecode >= 0 && facecode < FRAME_N_PARAM_FACES (f) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
865 && FRAME_PARAM_FACES (f) [facecode] != 0) |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
866 merge_faces (FRAME_PARAM_FACES (f) [facecode], face); |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
867 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
868 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
869 } |
59159a81b101
(Qforeground_color, Qbackground_color): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
870 |
13434 | 871 |
872 /* Recompute the GC's for the default and modeline faces. | |
873 We call this after changing frame parameters on which those GC's | |
874 depend. */ | |
875 | |
876 void | |
877 recompute_basic_faces (f) | |
878 FRAME_PTR f; | |
879 { | |
880 /* If the frame's faces haven't been initialized yet, don't worry about | |
881 this stuff. */ | |
882 if (FRAME_N_PARAM_FACES (f) < 2) | |
883 return; | |
884 | |
885 BLOCK_INPUT; | |
886 | |
887 compute_base_face (f, FRAME_DEFAULT_FACE (f)); | |
888 compute_base_face (f, FRAME_MODE_LINE_FACE (f)); | |
889 | |
890 merge_faces (FRAME_DEFAULT_PARAM_FACE (f), FRAME_DEFAULT_FACE (f)); | |
891 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f), FRAME_MODE_LINE_FACE (f)); | |
892 | |
893 intern_face (f, FRAME_DEFAULT_FACE (f)); | |
894 intern_face (f, FRAME_MODE_LINE_FACE (f)); | |
895 | |
896 UNBLOCK_INPUT; | |
897 } | |
898 | |
899 | |
900 | |
901 /* Lisp interface. */ | |
902 | |
903 DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, 1, 1, 0, | |
904 "") | |
905 (frame) | |
906 Lisp_Object frame; | |
907 { | |
908 CHECK_FRAME (frame, 0); | |
909 return XFRAME (frame)->face_alist; | |
910 } | |
911 | |
912 DEFUN ("set-frame-face-alist", Fset_frame_face_alist, Sset_frame_face_alist, | |
913 2, 2, 0, "") | |
914 (frame, value) | |
915 Lisp_Object frame, value; | |
916 { | |
917 CHECK_FRAME (frame, 0); | |
918 XFRAME (frame)->face_alist = value; | |
919 return value; | |
920 } | |
921 | |
922 | |
923 DEFUN ("make-face-internal", Fmake_face_internal, Smake_face_internal, 1, 1, 0, | |
924 "Create face number FACE-ID on all frames.") | |
925 (face_id) | |
926 Lisp_Object face_id; | |
927 { | |
928 Lisp_Object rest, frame; | |
929 int id = XINT (face_id); | |
930 | |
931 CHECK_NUMBER (face_id, 0); | |
932 if (id < 0 || id >= next_face_id) | |
933 error ("Face id out of range"); | |
934 | |
935 FOR_EACH_FRAME (rest, frame) | |
936 { | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16051
diff
changeset
|
937 if (FRAME_W32_P (XFRAME (frame))) |
13434 | 938 ensure_face_ready (XFRAME (frame), id); |
939 } | |
940 return Qnil; | |
941 } | |
942 | |
943 | |
944 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal, | |
945 Sset_face_attribute_internal, 4, 4, 0, "") | |
946 (face_id, attr_name, attr_value, frame) | |
947 Lisp_Object face_id, attr_name, attr_value, frame; | |
948 { | |
949 struct face *face; | |
950 struct frame *f; | |
951 int magic_p; | |
952 int id; | |
953 int garbaged = 0; | |
954 | |
955 CHECK_FRAME (frame, 0); | |
956 CHECK_NUMBER (face_id, 0); | |
957 CHECK_SYMBOL (attr_name, 0); | |
958 | |
959 f = XFRAME (frame); | |
960 id = XINT (face_id); | |
961 if (id < 0 || id >= next_face_id) | |
962 error ("Face id out of range"); | |
963 | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
964 if (! FRAME_WINDOW_P (f)) |
13434 | 965 return Qnil; |
966 | |
967 ensure_face_ready (f, id); | |
968 face = FRAME_PARAM_FACES (f) [XFASTINT (face_id)]; | |
969 | |
970 if (EQ (attr_name, intern ("font"))) | |
971 { | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
972 XFontStruct *font = NULL; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
973 int fontset; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
974 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
975 if (NILP (attr_value)) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
976 { |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
977 font = (XFontStruct *) FACE_DEFAULT; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
978 fontset = -1; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
979 } |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
980 else |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
981 { |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
982 CHECK_STRING (attr_value, 0); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
983 fontset = fs_query_fontset (f, XSTRING (attr_value)->data); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
984 if (fontset >= 0) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
985 { |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
986 struct font_info *fontp; |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
987 |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
988 if (!(fontp = FS_LOAD_FONT (f, FRAME_W32_FONT_TABLE (f), |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
989 CHARSET_ASCII, NULL, fontset))) |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
990 Fsignal (Qerror, |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
991 Fcons (build_string ("ASCII font can't be loaded"), |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
992 Fcons (attr_value, Qnil))); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
993 font = (XFontStruct *) (fontp->font); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
994 } |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
995 else |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
996 font = load_font (f, attr_value); |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
997 } |
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
998 if (face->fontset == -1 && face->font != f->output_data.w32->font) |
13434 | 999 unload_font (f, face->font); |
1000 face->font = font; | |
23505
1050835fbcef
Update comments referring to obsolete structs.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21607
diff
changeset
|
1001 face->fontset = fontset; |
13434 | 1002 if (frame_update_line_height (f)) |
1003 x_set_window_size (f, 0, f->width, f->height); | |
1004 /* Must clear cache, since it might contain the font | |
1005 we just got rid of. */ | |
1006 garbaged = 1; | |
1007 } | |
1008 else if (EQ (attr_name, intern ("foreground"))) | |
1009 { | |
1010 unsigned long new_color = load_color (f, attr_value); | |
1011 unload_color (f, face->foreground); | |
1012 face->foreground = new_color; | |
1013 garbaged = 1; | |
1014 } | |
1015 else if (EQ (attr_name, intern ("background"))) | |
1016 { | |
1017 unsigned long new_color = load_color (f, attr_value); | |
1018 unload_color (f, face->background); | |
1019 face->background = new_color; | |
1020 garbaged = 1; | |
1021 } | |
1022 else if (EQ (attr_name, intern ("background-pixmap"))) | |
1023 { | |
1024 unsigned int w, h; | |
1025 unsigned long new_pixmap = load_pixmap (f, attr_value, &w, &h); | |
1026 x_destroy_bitmap (f, face->stipple); | |
1027 face->stipple = (Pixmap) new_pixmap; | |
1028 face->pixmap_w = w; | |
1029 face->pixmap_h = h; | |
1030 garbaged = 1; | |
1031 } | |
1032 else if (EQ (attr_name, intern ("underline"))) | |
1033 { | |
1034 int new = !NILP (attr_value); | |
1035 face->underline = new; | |
1036 } | |
1037 else | |
1038 error ("unknown face attribute"); | |
1039 | |
1040 if (id == 0 || id == 1) | |
1041 recompute_basic_faces (f); | |
1042 | |
1043 /* We must redraw the frame whenever any face font or color changes, | |
1044 because it's possible that a merged (display) face | |
1045 contains the font or color we just replaced. | |
1046 And we must inhibit any Expose events until the redraw is done, | |
1047 since they would try to use the invalid display faces. */ | |
1048 if (garbaged) | |
1049 SET_FRAME_GARBAGED (f); | |
1050 | |
1051 return Qnil; | |
1052 } | |
1053 | |
1054 DEFUN ("internal-next-face-id", Finternal_next_face_id, Sinternal_next_face_id, | |
1055 0, 0, 0, "") | |
1056 () | |
1057 { | |
1058 return make_number (next_face_id++); | |
1059 } | |
1060 | |
1061 /* Return the face id for name NAME on frame FRAME. | |
1062 (It should be the same for all frames, | |
1063 but it's as easy to use the "right" frame to look it up | |
1064 as to use any other one.) */ | |
1065 | |
1066 int | |
1067 face_name_id_number (f, name) | |
1068 FRAME_PTR f; | |
1069 Lisp_Object name; | |
1070 { | |
1071 Lisp_Object tem; | |
1072 | |
1073 tem = Fcdr (assq_no_quit (name, f->face_alist)); | |
1074 if (NILP (tem)) | |
1075 return 0; | |
1076 CHECK_VECTOR (tem, 0); | |
1077 tem = XVECTOR (tem)->contents[2]; | |
1078 CHECK_NUMBER (tem, 0); | |
1079 return XINT (tem); | |
1080 } | |
1081 | |
1082 /* Emacs initialization. */ | |
1083 | |
1084 void | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16051
diff
changeset
|
1085 syms_of_w32faces () |
13434 | 1086 { |
1087 Qface = intern ("face"); | |
1088 staticpro (&Qface); | |
1089 Qmouse_face = intern ("mouse-face"); | |
1090 staticpro (&Qmouse_face); | |
1091 Qpixmap_spec_p = intern ("pixmap-spec-p"); | |
1092 staticpro (&Qpixmap_spec_p); | |
1093 | |
1094 DEFVAR_INT ("region-face", ®ion_face, | |
1095 "Face number to use to highlight the region\n\ | |
1096 The region is highlighted with this face\n\ | |
1097 when Transient Mark mode is enabled and the mark is active."); | |
1098 | |
1099 defsubr (&Spixmap_spec_p); | |
1100 defsubr (&Sframe_face_alist); | |
1101 defsubr (&Sset_frame_face_alist); | |
1102 defsubr (&Smake_face_internal); | |
1103 defsubr (&Sset_face_attribute_internal); | |
1104 defsubr (&Sinternal_next_face_id); | |
1105 } |