428
|
1 /* X output and frame manipulation routines.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994 Lucid, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
1318
|
5 Copyright (C) 2002, 2003 Ben Wing.
|
428
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Author: Chuck Thompson */
|
|
27
|
|
28 /* Lots of work done by Ben Wing for Mule */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "buffer.h"
|
|
34 #include "debug.h"
|
872
|
35 #include "device-impl.h"
|
428
|
36 #include "faces.h"
|
800
|
37 #include "file-coding.h"
|
872
|
38 #include "frame-impl.h"
|
428
|
39 #include "gutter.h"
|
|
40 #include "redisplay.h"
|
|
41 #include "sysdep.h"
|
|
42 #include "window.h"
|
800
|
43
|
|
44 #include "mule-ccl.h"
|
3659
|
45 #include "charset.h"
|
800
|
46
|
872
|
47 #include "console-x-impl.h"
|
800
|
48 #include "glyphs-x.h"
|
872
|
49 #include "objects-x-impl.h"
|
800
|
50 #include "xgccache.h"
|
|
51
|
|
52 #include "EmacsFrame.h"
|
|
53 #include "EmacsFrameP.h"
|
428
|
54
|
|
55 #include "sysproc.h" /* for select() */
|
|
56
|
800
|
57 #include <X11/bitmaps/gray>
|
428
|
58
|
|
59 /* Number of pixels below each line. */
|
3094
|
60 int x_interline_space; /* #### this needs to be implemented, but per-font */
|
428
|
61
|
|
62 #define EOL_CURSOR_WIDTH 5
|
|
63
|
|
64 static void x_output_vertical_divider (struct window *w, int clear);
|
|
65 static void x_output_blank (struct window *w, struct display_line *dl,
|
|
66 struct rune *rb, int start_pixpos,
|
|
67 int cursor_start, int cursor_width);
|
|
68 static void x_output_hline (struct window *w, struct display_line *dl,
|
|
69 struct rune *rb);
|
|
70 static void x_output_eol_cursor (struct window *w, struct display_line *dl,
|
|
71 int xpos, face_index findex);
|
|
72 static void x_clear_frame (struct frame *f);
|
|
73 static void x_clear_frame_windows (Lisp_Object window);
|
|
74
|
3094
|
75 #ifdef USE_XFT
|
|
76 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
77 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
78 #endif /* USE_XFT */
|
|
79
|
428
|
80
|
3896
|
81 /* Note: We do not use the Xmb*() functions and XFontSets, nor the
|
|
82 Motif XFontLists and CompoundStrings.
|
|
83 Those functions are generally losing for a number of reasons.
|
|
84 Most important, they only support one locale (e.g. you could
|
|
85 display Japanese and ASCII text, but not mixed Japanese/Chinese
|
|
86 text). You could maybe call setlocale() frequently to try to deal
|
|
87 with this, but that would generally fail because an XFontSet is
|
|
88 tied to one locale and won't have the other character sets in it.
|
3094
|
89
|
3896
|
90 fontconfig (the font database for Xft) has some specifier-like
|
|
91 properties, but it's not sufficient (witness the existence of
|
|
92 Pango). Pango might do the trick, but it's not a cross-platform
|
|
93 solution; it would need significant advantages to be worth the
|
|
94 effort.
|
|
95 */
|
428
|
96
|
3094
|
97 /* #### Break me out into a separate header */
|
428
|
98 struct textual_run
|
|
99 {
|
|
100 Lisp_Object charset;
|
|
101 unsigned char *ptr;
|
|
102 int len;
|
|
103 int dimension;
|
|
104 };
|
|
105
|
|
106 /* Separate out the text in DYN into a series of textual runs of a
|
|
107 particular charset. Also convert the characters as necessary into
|
|
108 the format needed by XDrawImageString(), XDrawImageString16(), et
|
3896
|
109 al. This means converting to one or two byte format, possibly
|
|
110 tweaking the high bits, and possibly running a CCL program. You
|
428
|
111 must pre-allocate the space used and pass it in. (This is done so
|
3896
|
112 you can ALLOCA () the space.) (sizeof(bufchar) * len) bytes must be
|
|
113 allocated for TEXT_STORAGE and (len * sizeof (struct textual_run))
|
|
114 bytes of RUN_STORAGE, where LEN is the length of the dynarr.
|
|
115
|
|
116 bufchar might not be fixed width (in the case of UTF-8).
|
428
|
117
|
|
118 Returns the number of runs actually used. */
|
|
119
|
3094
|
120 /* Notes on Xft implementation
|
|
121
|
|
122 - With Unicode, we're no longer going to have repertoires reified as
|
|
123 charsets. (Not that we ever really did, what with corporate variants,
|
|
124 and so on.) So we really should be querying the face for the desired
|
|
125 font, rather than the character for the charset, and that's what would
|
|
126 determine the separation into runs.
|
|
127 - The widechar versions of fontconfig (and therefore Xft) functions
|
|
128 seem to be just bigendian Unicode. So there's actually no need to use
|
|
129 the 8-bit versions in computing runs and runes, it would seem.
|
|
130 */
|
|
131
|
3895
|
132 #if !defined(USE_XFT) && !defined(MULE)
|
428
|
133 static int
|
3895
|
134 separate_textual_runs_nomule (unsigned char *text_storage,
|
|
135 struct textual_run *run_storage,
|
|
136 const Ichar *str, Charcount len,
|
|
137 struct face_cachel *UNUSED(cachel))
|
|
138 {
|
|
139 if (!len)
|
|
140 return 0;
|
|
141
|
|
142 run_storage[0].ptr = text_storage;
|
|
143 run_storage[0].len = len;
|
|
144 run_storage[0].dimension = 1;
|
|
145 run_storage[0].charset = Qnil;
|
|
146
|
3909
|
147 while (len--)
|
|
148 *text_storage++ = *str++;
|
3895
|
149 return 1;
|
|
150 }
|
|
151 #endif
|
|
152
|
|
153 #if defined(USE_XFT) && !defined(MULE)
|
3896
|
154 /*
|
|
155 Note that in this configuration the "Croatian hack" of using an 8-bit,
|
|
156 non-Latin-1 font to get localized display without Mule simply isn't
|
|
157 available. That's by design -- Unicode does not aid or abet that kind
|
|
158 of punning.
|
|
159 This means that the cast to XftChar16 gives the correct "conversion" to
|
|
160 UCS-2.
|
|
161 #### Is there an alignment issue with text_storage?
|
|
162 */
|
3895
|
163 static int
|
|
164 separate_textual_runs_xft_nomule (unsigned char *text_storage,
|
|
165 struct textual_run *run_storage,
|
|
166 const Ichar *str, Charcount len,
|
|
167 struct face_cachel *UNUSED(cachel))
|
|
168 {
|
|
169 int i;
|
|
170 if (!len)
|
|
171 return 0;
|
|
172
|
|
173 run_storage[0].ptr = text_storage;
|
|
174 run_storage[0].len = len;
|
|
175 run_storage[0].dimension = 2;
|
|
176 run_storage[0].charset = Qnil;
|
|
177
|
|
178 for (i = 0; i < len; i++)
|
|
179 {
|
|
180 *(XftChar16 *)text_storage = str[i];
|
|
181 text_storage += sizeof(XftChar16);
|
|
182 }
|
|
183 return 1;
|
|
184 }
|
|
185 #endif
|
|
186
|
|
187 #if defined(USE_XFT) && defined(MULE)
|
|
188 static int
|
|
189 separate_textual_runs_xft_mule (unsigned char *text_storage,
|
|
190 struct textual_run *run_storage,
|
|
191 const Ichar *str, Charcount len,
|
|
192 struct face_cachel *UNUSED(cachel))
|
|
193 {
|
3896
|
194 Lisp_Object prev_charset = Qunbound;
|
3895
|
195 int runs_so_far = 0, i;
|
|
196
|
|
197 run_storage[0].ptr = text_storage;
|
|
198 run_storage[0].len = len;
|
|
199 run_storage[0].dimension = 2;
|
|
200 run_storage[0].charset = Qnil;
|
|
201
|
|
202 for (i = 0; i < len; i++)
|
|
203 {
|
3896
|
204 Ichar ch = str[i];
|
3895
|
205 Lisp_Object charset = ichar_charset(ch);
|
|
206 int ucs = ichar_to_unicode(ch);
|
|
207
|
|
208 /* If UCS is less than zero or greater than 0xFFFF, set ucs2 to
|
|
209 REPLACMENT CHARACTER. */
|
|
210 /* That means we can't handle characters outside of the BMP for now */
|
|
211 ucs = (ucs & ~0xFFFF) ? 0xFFFD : ucs;
|
|
212
|
|
213 if (!EQ (charset, prev_charset))
|
|
214 {
|
|
215 if (runs_so_far)
|
|
216 run_storage[runs_so_far-1].len = (text_storage - run_storage[runs_so_far-1].ptr) >> 1;
|
|
217 run_storage[runs_so_far].ptr = text_storage;
|
|
218 run_storage[runs_so_far].dimension = 2;
|
|
219 run_storage[runs_so_far].charset = charset;
|
|
220 prev_charset = charset;
|
|
221 runs_so_far++;
|
|
222 }
|
|
223
|
|
224 *(XftChar16 *)text_storage = ucs;
|
|
225 text_storage += sizeof(XftChar16);
|
|
226 }
|
|
227
|
|
228 if (runs_so_far)
|
|
229 run_storage[runs_so_far-1].len = (text_storage - run_storage[runs_so_far-1].ptr) >> 1;
|
|
230 return runs_so_far;
|
|
231 }
|
|
232 #endif
|
|
233
|
|
234 #if !defined(USE_XFT) && defined(MULE)
|
3896
|
235 /*
|
|
236 This is the most complex function of this group, due to the various
|
|
237 indexing schemes used by different fonts. For our purposes, they
|
|
238 fall into three classes. Some fonts are indexed compatibly with ISO
|
|
239 2022; those fonts just use the Mule internal representation directly
|
|
240 (typically the high bit must be reset; this is determined by the `graphic'
|
|
241 flag). Some fonts are indexed by Unicode, specifically by UCS-2. These
|
|
242 are all translated using `ichar_to_unicode'. Finally some fonts have
|
|
243 irregular indexes, and must be translated ad hoc. In XEmacs ad hoc
|
|
244 translations are accomplished with CCL programs. */
|
3895
|
245 static int
|
|
246 separate_textual_runs_mule (unsigned char *text_storage,
|
|
247 struct textual_run *run_storage,
|
|
248 const Ichar *str, Charcount len,
|
|
249 struct face_cachel *cachel)
|
428
|
250 {
|
3896
|
251 Lisp_Object prev_charset = Qunbound;
|
3659
|
252 int runs_so_far = 0, i;
|
|
253 Ibyte charset_leading_byte = LEADING_BYTE_ASCII;
|
|
254 int dimension = 1, graphic = 0, need_ccl_conversion = 0;
|
|
255 Lisp_Object ccl_prog;
|
428
|
256 struct ccl_program char_converter;
|
3659
|
257
|
|
258 int translate_to_ucs_2 = 0;
|
428
|
259
|
|
260 for (i = 0; i < len; i++)
|
|
261 {
|
867
|
262 Ichar ch = str[i];
|
428
|
263 Lisp_Object charset;
|
3896
|
264 int byte1, byte2; /* BREAKUP_ICHAR dereferences the addresses
|
|
265 of its arguments as pointer to int. */
|
867
|
266 BREAKUP_ICHAR (ch, charset, byte1, byte2);
|
428
|
267
|
|
268 if (!EQ (charset, prev_charset))
|
|
269 {
|
3896
|
270 /* At this point, dimension' and `prev_charset' refer to just-
|
|
271 completed run. `runs_so_far' and `text_storage' refer to the
|
|
272 run about to start. */
|
428
|
273 if (runs_so_far)
|
|
274 {
|
3896
|
275 /* Update metadata for previous run. */
|
428
|
276 run_storage[runs_so_far - 1].len =
|
|
277 text_storage - run_storage[runs_so_far - 1].ptr;
|
3659
|
278 if (2 == dimension) run_storage[runs_so_far - 1].len >>= 1;
|
428
|
279 }
|
3659
|
280
|
3896
|
281 /* Compute metadata for current run.
|
|
282 First, classify font.
|
|
283 If the font is indexed by UCS-2, set `translate_to_ucs_2'.
|
|
284 Else if the charset has a CCL program, set `need_ccl_conversion'.
|
|
285 Else if the font is indexed by an ISO 2022 "graphic register",
|
|
286 set `graphic'.
|
|
287 These flags are almost mutually exclusive, but we're sloppy
|
|
288 about resetting "shadowed" flags. So the flags must be checked
|
|
289 in the proper order in computing byte1 and byte2, below. */
|
3659
|
290 charset_leading_byte = XCHARSET_LEADING_BYTE(charset);
|
3895
|
291 translate_to_ucs_2 =
|
3896
|
292 bit_vector_bit (FACE_CACHEL_FONT_FINAL_STAGE (cachel),
|
|
293 charset_leading_byte - MIN_LEADING_BYTE);
|
3659
|
294 if (translate_to_ucs_2)
|
|
295 {
|
|
296 dimension = 2;
|
|
297 }
|
|
298 else
|
|
299 {
|
|
300 dimension = XCHARSET_DIMENSION (charset);
|
3895
|
301
|
3896
|
302 /* Check for CCL charset.
|
|
303 If setup_ccl_program fails, we'll get a garbaged display.
|
|
304 This should never happen, and even if it does, it should
|
|
305 be harmless (unless the X server has buggy handling of
|
|
306 characters undefined in the font). It may be marginally
|
|
307 more useful to users and debuggers than substituting a
|
|
308 fixed replacement character. */
|
3659
|
309 ccl_prog = XCHARSET_CCL_PROGRAM (charset);
|
|
310 if ((!NILP (ccl_prog))
|
444
|
311 && (setup_ccl_program (&char_converter, ccl_prog) >= 0))
|
3659
|
312 {
|
|
313 need_ccl_conversion = 1;
|
|
314 }
|
|
315 else
|
|
316 {
|
3896
|
317 /* The charset must have an ISO 2022-compatible font index.
|
|
318 There are 2 "registers" (what such fonts use as index).
|
|
319 GL (graphic == 0) has the high bit of each octet reset,
|
|
320 GR (graphic == 1) has it set. */
|
3659
|
321 graphic = XCHARSET_GRAPHIC (charset);
|
|
322 need_ccl_conversion = 0;
|
|
323 }
|
|
324 }
|
3896
|
325
|
|
326 /* Initialize metadata for current run. */
|
|
327 run_storage[runs_so_far].ptr = text_storage;
|
|
328 run_storage[runs_so_far].charset = charset;
|
|
329 run_storage[runs_so_far].dimension = dimension;
|
|
330
|
|
331 /* Update loop variables. */
|
3659
|
332 prev_charset = charset;
|
|
333 runs_so_far++;
|
|
334 }
|
|
335
|
3896
|
336 /* Must check flags in this order. See comment above. */
|
3659
|
337 if (translate_to_ucs_2)
|
428
|
338 {
|
3659
|
339 int ucs = ichar_to_unicode(ch);
|
|
340 /* If UCS is less than zero or greater than 0xFFFF, set ucs2 to
|
|
341 REPLACMENT CHARACTER. */
|
3895
|
342 ucs = (ucs & ~0xFFFF) ? 0xFFFD : ucs;
|
3659
|
343
|
3895
|
344 byte1 = ucs >> 8;
|
|
345 byte2 = ucs;
|
428
|
346 }
|
3659
|
347 else if (need_ccl_conversion)
|
428
|
348 {
|
3659
|
349 char_converter.reg[0] = charset_leading_byte;
|
428
|
350 char_converter.reg[1] = byte1;
|
|
351 char_converter.reg[2] = byte2;
|
|
352 ccl_driver (&char_converter, 0, 0, 0, 0, CCL_MODE_ENCODING);
|
|
353 byte1 = char_converter.reg[1];
|
|
354 byte2 = char_converter.reg[2];
|
|
355 }
|
3659
|
356 else if (graphic == 0)
|
|
357 {
|
|
358 byte1 &= 0x7F;
|
|
359 byte2 &= 0x7F;
|
|
360 }
|
|
361 else
|
|
362 {
|
|
363 byte1 |= 0x80;
|
|
364 byte2 |= 0x80;
|
|
365 }
|
|
366
|
|
367 *text_storage++ = (unsigned char)byte1;
|
|
368
|
|
369 if (2 == dimension) *text_storage++ = (unsigned char)byte2;
|
428
|
370 }
|
|
371
|
|
372 if (runs_so_far)
|
|
373 {
|
|
374 run_storage[runs_so_far - 1].len =
|
|
375 text_storage - run_storage[runs_so_far - 1].ptr;
|
3659
|
376 /* Dimension retains the relevant value for the run before it. */
|
|
377 if (2 == dimension)
|
428
|
378 run_storage[runs_so_far - 1].len >>= 1;
|
|
379 }
|
|
380
|
|
381 return runs_so_far;
|
|
382 }
|
3895
|
383 #endif
|
|
384
|
|
385 static int
|
|
386 separate_textual_runs (unsigned char *text_storage,
|
|
387 struct textual_run *run_storage,
|
|
388 const Ichar *str, Charcount len,
|
|
389 struct face_cachel *cachel)
|
|
390 {
|
|
391 #if defined(USE_XFT) && defined(MULE)
|
|
392 return separate_textual_runs_xft_mule(text_storage, run_storage, str, len, cachel);
|
|
393 #endif
|
|
394 #if defined(USE_XFT) && !defined(MULE)
|
|
395 return separate_textual_runs_xft_nomule(text_storage, run_storage, str, len, cachel);
|
|
396 #endif
|
|
397 #if !defined(USE_XFT) && defined(MULE)
|
|
398 return separate_textual_runs_mule(text_storage, run_storage, str, len, cachel);
|
|
399 #endif
|
|
400 #if !defined(USE_XFT) && !defined(MULE)
|
|
401 return separate_textual_runs_nomule(text_storage, run_storage, str, len, cachel);
|
|
402 #endif
|
|
403 }
|
428
|
404
|
|
405 /****************************************************************************/
|
|
406 /* */
|
|
407 /* X output routines */
|
|
408 /* */
|
|
409 /****************************************************************************/
|
|
410
|
|
411 static int
|
3094
|
412 x_text_width_single_run (struct frame * USED_IF_XFT (f),
|
|
413 struct face_cachel *cachel, struct textual_run *run)
|
428
|
414 {
|
|
415 Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset);
|
440
|
416 Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst);
|
428
|
417 if (!fi->proportional_p)
|
|
418 return fi->width * run->len;
|
3094
|
419 #ifdef USE_XFT
|
|
420 else if (FONT_INSTANCE_X_XFTFONT(fi))
|
|
421 {
|
|
422 static XGlyphInfo glyphinfo;
|
|
423 struct device *d = XDEVICE (f->device);
|
|
424 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
425
|
|
426 if (run->dimension == 2) {
|
|
427 XftTextExtents16 (dpy,
|
|
428 FONT_INSTANCE_X_XFTFONT(fi),
|
|
429 (XftChar16 *) run->ptr, run->len, &glyphinfo);
|
|
430 } else {
|
|
431 XftTextExtents8 (dpy,
|
|
432 FONT_INSTANCE_X_XFTFONT(fi),
|
|
433 run->ptr, run->len, &glyphinfo);
|
|
434 }
|
|
435
|
|
436 return glyphinfo.xOff;
|
|
437 }
|
|
438 #endif
|
|
439 else if (FONT_INSTANCE_X_FONT (fi))
|
428
|
440 {
|
|
441 if (run->dimension == 2)
|
|
442 return XTextWidth16 (FONT_INSTANCE_X_FONT (fi),
|
|
443 (XChar2b *) run->ptr, run->len);
|
|
444 else
|
|
445 return XTextWidth (FONT_INSTANCE_X_FONT (fi),
|
|
446 (char *) run->ptr, run->len);
|
|
447 }
|
3094
|
448 else
|
|
449 abort();
|
|
450 return 0; /* shut up GCC */
|
428
|
451 }
|
|
452
|
|
453 /*
|
|
454 x_text_width
|
|
455
|
3094
|
456 Given a string and a merged face, return the string's length in pixels
|
|
457 when displayed in the fonts associated with the face.
|
428
|
458 */
|
|
459
|
3094
|
460 /* #### Break me out into a separate header */
|
|
461 int x_text_width (struct frame *f, struct face_cachel *cachel,
|
|
462 const Ichar *str, Charcount len);
|
|
463 int
|
|
464 x_text_width (struct frame *f, struct face_cachel *cachel,
|
2286
|
465 const Ichar *str, Charcount len)
|
428
|
466 {
|
2367
|
467 /* !!#### Needs review */
|
428
|
468 int width_so_far = 0;
|
851
|
469 unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len);
|
428
|
470 struct textual_run *runs = alloca_array (struct textual_run, len);
|
|
471 int nruns;
|
|
472 int i;
|
|
473
|
3659
|
474 nruns = separate_textual_runs (text_storage, runs, str, len,
|
|
475 cachel);
|
428
|
476
|
|
477 for (i = 0; i < nruns; i++)
|
3094
|
478 width_so_far += x_text_width_single_run (f, cachel, runs + i);
|
428
|
479
|
|
480 return width_so_far;
|
|
481 }
|
|
482
|
|
483 /*****************************************************************************
|
|
484 x_divider_height
|
|
485
|
|
486 Return the height of the horizontal divider. This is a function because
|
|
487 divider_height is a device method.
|
|
488
|
|
489 #### If we add etched horizontal divider lines this will have to get
|
|
490 smarter.
|
|
491 ****************************************************************************/
|
|
492 static int
|
|
493 x_divider_height (void)
|
|
494 {
|
|
495 return 1;
|
|
496 }
|
|
497
|
|
498 /*****************************************************************************
|
|
499 x_eol_cursor_width
|
|
500
|
|
501 Return the width of the end-of-line cursor. This is a function
|
|
502 because eol_cursor_width is a device method.
|
|
503 ****************************************************************************/
|
|
504 static int
|
|
505 x_eol_cursor_width (void)
|
|
506 {
|
|
507 return EOL_CURSOR_WIDTH;
|
|
508 }
|
|
509
|
|
510 /*****************************************************************************
|
442
|
511 x_window_output_begin
|
428
|
512
|
|
513 Perform any necessary initialization prior to an update.
|
|
514 ****************************************************************************/
|
|
515 static void
|
2286
|
516 x_window_output_begin (struct window *UNUSED (w))
|
428
|
517 {
|
|
518 }
|
|
519
|
|
520 /*****************************************************************************
|
442
|
521 x_window_output_end
|
428
|
522
|
|
523 Perform any necessary flushing of queues when an update has completed.
|
|
524 ****************************************************************************/
|
|
525 static void
|
442
|
526 x_window_output_end (struct window *w)
|
428
|
527 {
|
1204
|
528 if (!(check_if_pending_expose_event (WINDOW_XDEVICE (w))))
|
|
529 XFlush (DEVICE_X_DISPLAY (WINDOW_XDEVICE (w)));
|
428
|
530 }
|
|
531
|
|
532 /*****************************************************************************
|
|
533 x_output_display_block
|
|
534
|
|
535 Given a display line, a block number for that start line, output all
|
|
536 runes between start and end in the specified display block.
|
|
537 ****************************************************************************/
|
|
538 static void
|
|
539 x_output_display_block (struct window *w, struct display_line *dl, int block,
|
|
540 int start, int end, int start_pixpos, int cursor_start,
|
|
541 int cursor_width, int cursor_height)
|
|
542 {
|
3094
|
543 #ifndef USE_XFT
|
428
|
544 struct frame *f = XFRAME (w->frame);
|
3094
|
545 #endif
|
3479
|
546 Ichar_dynarr *buf;
|
428
|
547 Lisp_Object window;
|
|
548
|
|
549 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
|
|
550 rune_dynarr *rba = db->runes;
|
|
551 struct rune *rb;
|
|
552
|
|
553 int elt = start;
|
|
554 face_index findex;
|
|
555 int xpos, width = 0;
|
|
556 Lisp_Object charset = Qunbound; /* Qnil is a valid charset when
|
|
557 MULE is not defined */
|
|
558
|
793
|
559 window = wrap_window (w);
|
428
|
560 rb = Dynarr_atp (rba, start);
|
|
561
|
|
562 if (!rb)
|
|
563 /* Nothing to do so don't do anything. */
|
|
564 return;
|
|
565
|
|
566 findex = rb->findex;
|
|
567 xpos = rb->xpos;
|
|
568 if (rb->type == RUNE_CHAR)
|
867
|
569 charset = ichar_charset (rb->object.chr.ch);
|
428
|
570
|
|
571 if (end < 0)
|
|
572 end = Dynarr_length (rba);
|
3479
|
573 buf = Dynarr_new (Ichar);
|
428
|
574
|
|
575 while (elt < end)
|
|
576 {
|
|
577 rb = Dynarr_atp (rba, elt);
|
|
578
|
|
579 if (rb->findex == findex && rb->type == RUNE_CHAR
|
|
580 && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON
|
867
|
581 && EQ (charset, ichar_charset (rb->object.chr.ch)))
|
428
|
582 {
|
|
583 Dynarr_add (buf, rb->object.chr.ch);
|
|
584 width += rb->width;
|
|
585 elt++;
|
|
586 }
|
|
587 else
|
|
588 {
|
|
589 if (Dynarr_length (buf))
|
|
590 {
|
|
591 x_output_string (w, dl, buf, xpos, 0, start_pixpos, width,
|
|
592 findex, 0, cursor_start, cursor_width,
|
|
593 cursor_height);
|
|
594 xpos = rb->xpos;
|
|
595 width = 0;
|
|
596 }
|
|
597 Dynarr_reset (buf);
|
|
598 width = 0;
|
|
599
|
|
600 if (rb->type == RUNE_CHAR)
|
|
601 {
|
|
602 findex = rb->findex;
|
|
603 xpos = rb->xpos;
|
867
|
604 charset = ichar_charset (rb->object.chr.ch);
|
428
|
605
|
|
606 if (rb->cursor_type == CURSOR_ON)
|
|
607 {
|
|
608 if (rb->object.chr.ch == '\n')
|
|
609 {
|
|
610 x_output_eol_cursor (w, dl, xpos, findex);
|
|
611 }
|
|
612 else
|
|
613 {
|
|
614 Dynarr_add (buf, rb->object.chr.ch);
|
|
615 x_output_string (w, dl, buf, xpos, 0, start_pixpos,
|
|
616 rb->width, findex, 1,
|
|
617 cursor_start, cursor_width,
|
|
618 cursor_height);
|
|
619 Dynarr_reset (buf);
|
|
620 }
|
|
621
|
|
622 xpos += rb->width;
|
|
623 elt++;
|
|
624 }
|
|
625 else if (rb->object.chr.ch == '\n')
|
|
626 {
|
|
627 /* Clear in case a cursor was formerly here. */
|
440
|
628 redisplay_clear_region (window, findex, xpos,
|
428
|
629 DISPLAY_LINE_YPOS (dl),
|
440
|
630 rb->width,
|
428
|
631 DISPLAY_LINE_HEIGHT (dl));
|
|
632 elt++;
|
|
633 }
|
|
634 }
|
|
635 else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE)
|
|
636 {
|
|
637 if (rb->type == RUNE_BLANK)
|
|
638 x_output_blank (w, dl, rb, start_pixpos, cursor_start,
|
|
639 cursor_width);
|
|
640 else
|
|
641 {
|
|
642 /* #### Our flagging of when we need to redraw the
|
|
643 modeline shadows sucks. Since RUNE_HLINE is only used
|
|
644 by the modeline at the moment it is a good bet
|
|
645 that if it gets redrawn then we should also
|
|
646 redraw the shadows. This won't be true forever.
|
|
647 We borrow the shadow_thickness_changed flag for
|
|
648 now. */
|
|
649 w->shadow_thickness_changed = 1;
|
|
650 x_output_hline (w, dl, rb);
|
|
651 }
|
|
652
|
|
653 elt++;
|
|
654 if (elt < end)
|
|
655 {
|
|
656 rb = Dynarr_atp (rba, elt);
|
|
657
|
|
658 findex = rb->findex;
|
|
659 xpos = rb->xpos;
|
|
660 }
|
|
661 }
|
|
662 else if (rb->type == RUNE_DGLYPH)
|
|
663 {
|
|
664 Lisp_Object instance;
|
|
665 struct display_box dbox;
|
|
666 struct display_glyph_area dga;
|
819
|
667
|
428
|
668 redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset,
|
819
|
669 rb->object.dglyph.yoffset, start_pixpos,
|
|
670 rb->width, &dbox, &dga);
|
428
|
671
|
793
|
672 window = wrap_window (w);
|
428
|
673 instance = glyph_image_instance (rb->object.dglyph.glyph,
|
793
|
674 window, ERROR_ME_DEBUG_WARN, 1);
|
428
|
675 findex = rb->findex;
|
|
676
|
|
677 if (IMAGE_INSTANCEP (instance))
|
442
|
678 {
|
|
679 switch (XIMAGE_INSTANCE_TYPE (instance))
|
428
|
680 {
|
442
|
681 case IMAGE_MONO_PIXMAP:
|
|
682 case IMAGE_COLOR_PIXMAP:
|
|
683 redisplay_output_pixmap (w, instance, &dbox, &dga, findex,
|
|
684 cursor_start, cursor_width,
|
|
685 cursor_height, 0);
|
|
686 break;
|
428
|
687
|
442
|
688 case IMAGE_WIDGET:
|
|
689 if (EQ (XIMAGE_INSTANCE_WIDGET_TYPE (instance),
|
|
690 Qlayout))
|
|
691 {
|
|
692 redisplay_output_layout (window, instance, &dbox, &dga, findex,
|
|
693 cursor_start, cursor_width,
|
|
694 cursor_height);
|
|
695 break;
|
|
696 }
|
|
697 case IMAGE_SUBWINDOW:
|
|
698 redisplay_output_subwindow (w, instance, &dbox, &dga, findex,
|
|
699 cursor_start, cursor_width,
|
|
700 cursor_height);
|
|
701 break;
|
428
|
702
|
442
|
703 case IMAGE_NOTHING:
|
|
704 /* nothing is as nothing does */
|
|
705 break;
|
428
|
706
|
442
|
707 case IMAGE_TEXT:
|
|
708 case IMAGE_POINTER:
|
|
709 default:
|
2500
|
710 ABORT ();
|
442
|
711 }
|
|
712 IMAGE_INSTANCE_OPTIMIZE_OUTPUT
|
|
713 (XIMAGE_INSTANCE (instance)) = 0;
|
|
714 }
|
428
|
715
|
|
716 xpos += rb->width;
|
|
717 elt++;
|
|
718 }
|
|
719 else
|
2500
|
720 ABORT ();
|
428
|
721 }
|
|
722 }
|
|
723
|
|
724 if (Dynarr_length (buf))
|
|
725 x_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex,
|
|
726 0, cursor_start, cursor_width, cursor_height);
|
|
727
|
|
728 if (dl->modeline
|
|
729 && !EQ (Qzero, w->modeline_shadow_thickness)
|
3094
|
730 #ifndef USE_XFT
|
|
731 /* This optimization doesn't work right with some Xft fonts, which
|
|
732 leave antialiasing turds at the boundary. I don't know if this
|
|
733 is an Xft bug or not, but I think it is. See x_output_string. */
|
428
|
734 && (f->clear
|
|
735 || f->windows_structure_changed
|
3094
|
736 || w->shadow_thickness_changed)
|
|
737 #endif
|
|
738 )
|
428
|
739 bevel_modeline (w, dl);
|
|
740
|
|
741 Dynarr_free (buf);
|
|
742 }
|
|
743
|
|
744 /*****************************************************************************
|
|
745 x_bevel_area
|
|
746
|
450
|
747 Draw shadows for the given area in the given face.
|
428
|
748 ****************************************************************************/
|
|
749 static void
|
|
750 x_bevel_area (struct window *w, face_index findex,
|
|
751 int x, int y, int width, int height,
|
|
752 int shadow_thickness, int edges, enum edge_style style)
|
|
753 {
|
|
754 struct frame *f = XFRAME (w->frame);
|
|
755 struct device *d = XDEVICE (f->device);
|
|
756
|
|
757 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
758 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
759 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
760 Pixel top_shadow_pixel, bottom_shadow_pixel, background_pixel;
|
|
761 Lisp_Object tmp_pixel;
|
|
762 XColor tmp_color;
|
|
763 XGCValues gcv;
|
|
764 GC top_shadow_gc, bottom_shadow_gc, background_gc;
|
|
765
|
|
766 int use_pixmap = 0;
|
|
767 int flip_gcs = 0;
|
|
768 unsigned long mask;
|
|
769
|
|
770 assert (shadow_thickness >=0);
|
|
771 memset (&gcv, ~0, sizeof (XGCValues));
|
|
772
|
|
773 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex);
|
|
774 tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
775
|
|
776 /* First, get the GC's. */
|
|
777 top_shadow_pixel = tmp_color.pixel;
|
|
778 bottom_shadow_pixel = tmp_color.pixel;
|
|
779 background_pixel = tmp_color.pixel;
|
|
780
|
|
781 x_generate_shadow_pixels (f, &top_shadow_pixel, &bottom_shadow_pixel,
|
|
782 background_pixel, ef->core.background_pixel);
|
|
783
|
|
784 tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex);
|
|
785 tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
786 gcv.background = tmp_color.pixel;
|
|
787 gcv.graphics_exposures = False;
|
|
788 mask = GCForeground | GCBackground | GCGraphicsExposures;
|
|
789
|
|
790 /* If we can't distinguish one of the shadows (the color is the same as the
|
|
791 background), it's better to use a pixmap to generate a dithered gray. */
|
|
792 if (top_shadow_pixel == background_pixel ||
|
|
793 bottom_shadow_pixel == background_pixel)
|
|
794 use_pixmap = 1;
|
|
795
|
|
796 if (use_pixmap)
|
|
797 {
|
|
798 if (DEVICE_X_GRAY_PIXMAP (d) == None)
|
|
799 {
|
|
800 DEVICE_X_GRAY_PIXMAP (d) =
|
|
801 XCreatePixmapFromBitmapData (dpy, x_win, (char *) gray_bits,
|
|
802 gray_width, gray_height, 1, 0, 1);
|
|
803 }
|
|
804
|
|
805 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex);
|
|
806 tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
807 gcv.foreground = tmp_color.pixel;
|
|
808 /* this is needed because the GC draws with a pixmap here */
|
|
809 gcv.fill_style = FillOpaqueStippled;
|
|
810 gcv.stipple = DEVICE_X_GRAY_PIXMAP (d);
|
|
811 top_shadow_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv,
|
|
812 (mask | GCStipple | GCFillStyle));
|
|
813
|
|
814 tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex);
|
|
815 tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
816 bottom_shadow_pixel = tmp_color.pixel;
|
|
817
|
|
818 flip_gcs = (bottom_shadow_pixel ==
|
|
819 WhitePixelOfScreen (DefaultScreenOfDisplay (dpy)));
|
|
820 }
|
|
821 else
|
|
822 {
|
|
823 gcv.foreground = top_shadow_pixel;
|
|
824 top_shadow_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask);
|
|
825 }
|
|
826
|
|
827 gcv.foreground = bottom_shadow_pixel;
|
|
828 bottom_shadow_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask);
|
|
829
|
|
830 if (use_pixmap && flip_gcs)
|
|
831 {
|
|
832 GC tmp_gc = bottom_shadow_gc;
|
|
833 bottom_shadow_gc = top_shadow_gc;
|
|
834 top_shadow_gc = tmp_gc;
|
|
835 }
|
|
836
|
|
837 gcv.foreground = background_pixel;
|
|
838 background_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask);
|
|
839
|
|
840 /* possibly revert the GC's This will give a depressed look to the
|
|
841 divider */
|
|
842 if (style == EDGE_ETCHED_IN || style == EDGE_BEVEL_IN)
|
|
843 {
|
|
844 GC temp;
|
|
845
|
|
846 temp = top_shadow_gc;
|
|
847 top_shadow_gc = bottom_shadow_gc;
|
|
848 bottom_shadow_gc = temp;
|
|
849 }
|
|
850
|
|
851 if (style == EDGE_ETCHED_IN || style == EDGE_ETCHED_OUT)
|
|
852 shadow_thickness /= 2;
|
|
853
|
|
854 /* Draw the shadows around the divider line */
|
|
855 x_output_shadows (f, x, y, width, height,
|
|
856 top_shadow_gc, bottom_shadow_gc,
|
|
857 background_gc, shadow_thickness, edges);
|
|
858
|
|
859 if (style == EDGE_ETCHED_IN || style == EDGE_ETCHED_OUT)
|
|
860 {
|
|
861 /* Draw the shadows around the divider line */
|
|
862 x_output_shadows (f, x + shadow_thickness, y + shadow_thickness,
|
|
863 width - 2*shadow_thickness, height - 2*shadow_thickness,
|
|
864 bottom_shadow_gc, top_shadow_gc,
|
|
865 background_gc, shadow_thickness, edges);
|
|
866 }
|
|
867 }
|
|
868
|
|
869 /*****************************************************************************
|
|
870 x_get_gc
|
|
871
|
|
872 Given a number of parameters return a GC with those properties.
|
|
873 ****************************************************************************/
|
|
874 static GC
|
|
875 x_get_gc (struct device *d, Lisp_Object font, Lisp_Object fg, Lisp_Object bg,
|
|
876 Lisp_Object bg_pmap, Lisp_Object lwidth)
|
|
877 {
|
|
878 XGCValues gcv;
|
|
879 unsigned long mask;
|
|
880
|
|
881 memset (&gcv, ~0, sizeof (XGCValues));
|
|
882 gcv.graphics_exposures = False;
|
|
883 /* Make absolutely sure that we don't pick up a clipping region in
|
|
884 the GC returned by this function. */
|
|
885 gcv.clip_mask = None;
|
|
886 gcv.clip_x_origin = 0;
|
|
887 gcv.clip_y_origin = 0;
|
|
888 gcv.fill_style = FillSolid;
|
|
889 mask = GCGraphicsExposures | GCClipMask | GCClipXOrigin | GCClipYOrigin;
|
|
890 mask |= GCFillStyle;
|
|
891
|
3094
|
892 if (!NILP (font)
|
|
893 #ifdef USE_XFT
|
|
894 /* Only set the font if it's a core font */
|
|
895 /* the renderfont will be set elsewhere (not part of gc) */
|
|
896 && !FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font))
|
|
897 #endif
|
|
898 )
|
428
|
899 {
|
|
900 gcv.font = FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font))->fid;
|
|
901 mask |= GCFont;
|
|
902 }
|
|
903
|
|
904 /* evil kludge! */
|
|
905 if (!NILP (fg) && !COLOR_INSTANCEP (fg) && !INTP (fg))
|
|
906 {
|
3094
|
907 /* #### I fixed one case where this was getting hit. It was a
|
428
|
908 bad macro expansion (compiler bug). */
|
442
|
909 stderr_out ("Help! x_get_gc got a bogus fg value! fg = ");
|
428
|
910 debug_print (fg);
|
|
911 fg = Qnil;
|
|
912 }
|
|
913
|
|
914 if (!NILP (fg))
|
|
915 {
|
|
916 if (COLOR_INSTANCEP (fg))
|
|
917 gcv.foreground = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (fg)).pixel;
|
|
918 else
|
|
919 gcv.foreground = XINT (fg);
|
|
920 mask |= GCForeground;
|
|
921 }
|
|
922
|
|
923 if (!NILP (bg))
|
|
924 {
|
|
925 if (COLOR_INSTANCEP (bg))
|
|
926 gcv.background = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (bg)).pixel;
|
|
927 else
|
|
928 gcv.background = XINT (bg);
|
|
929 mask |= GCBackground;
|
|
930 }
|
|
931
|
|
932 /* This special case comes from a request to draw text with a face which has
|
|
933 the dim property. We'll use a stippled foreground GC. */
|
|
934 if (EQ (bg_pmap, Qdim))
|
|
935 {
|
|
936 assert (DEVICE_X_GRAY_PIXMAP (d) != None);
|
|
937
|
|
938 gcv.fill_style = FillStippled;
|
|
939 gcv.stipple = DEVICE_X_GRAY_PIXMAP (d);
|
|
940 mask |= (GCFillStyle | GCStipple);
|
|
941 }
|
|
942 else if (IMAGE_INSTANCEP (bg_pmap)
|
|
943 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
944 {
|
|
945 if (XIMAGE_INSTANCE_PIXMAP_DEPTH (bg_pmap) == 0)
|
|
946 {
|
|
947 gcv.fill_style = FillOpaqueStippled;
|
|
948 gcv.stipple = XIMAGE_INSTANCE_X_PIXMAP (bg_pmap);
|
|
949 mask |= (GCStipple | GCFillStyle);
|
|
950 }
|
|
951 else
|
|
952 {
|
|
953 gcv.fill_style = FillTiled;
|
|
954 gcv.tile = XIMAGE_INSTANCE_X_PIXMAP (bg_pmap);
|
|
955 mask |= (GCTile | GCFillStyle);
|
|
956 }
|
|
957 }
|
|
958
|
|
959 if (!NILP (lwidth))
|
|
960 {
|
|
961 gcv.line_width = XINT (lwidth);
|
|
962 mask |= GCLineWidth;
|
|
963 }
|
|
964
|
3094
|
965 #if 0
|
|
966 debug_out ("\nx_get_gc: calling gc_cache_lookup\n");
|
|
967 #endif
|
428
|
968 return gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask);
|
|
969 }
|
|
970
|
|
971 /*****************************************************************************
|
|
972 x_output_string
|
|
973
|
|
974 Given a string and a starting position, output that string in the
|
|
975 given face. If cursor is true, draw a cursor around the string.
|
|
976 Correctly handles multiple charsets in the string.
|
|
977
|
|
978 The meaning of the parameters is something like this:
|
|
979
|
|
980 W Window that the text is to be displayed in.
|
|
981 DL Display line that this text is on. The values in the
|
|
982 structure are used to determine the vertical position and
|
|
983 clipping range of the text.
|
867
|
984 BUF Dynamic array of Ichars specifying what is actually to be
|
428
|
985 drawn.
|
|
986 XPOS X position in pixels where the text should start being drawn.
|
|
987 XOFFSET Number of pixels to be chopped off the left side of the
|
|
988 text. The effect is as if the text were shifted to the
|
|
989 left this many pixels and clipped at XPOS.
|
|
990 CLIP_START Clip everything left of this X position.
|
|
991 WIDTH Clip everything right of XPOS + WIDTH.
|
|
992 FINDEX Index for the face cache element describing how to display
|
|
993 the text.
|
|
994 CURSOR #### I don't understand this. There's something
|
|
995 strange and overcomplexified with this variable.
|
|
996 Chuck, explain please?
|
|
997 CURSOR_START Starting X position of cursor.
|
|
998 CURSOR_WIDTH Width of cursor in pixels.
|
|
999 CURSOR_HEIGHT Height of cursor in pixels.
|
|
1000
|
|
1001 Starting Y position of cursor is the top of the text line.
|
|
1002 The cursor is drawn sometimes whether or not CURSOR is set. ???
|
|
1003 ****************************************************************************/
|
|
1004 void
|
|
1005 x_output_string (struct window *w, struct display_line *dl,
|
867
|
1006 Ichar_dynarr *buf, int xpos, int xoffset, int clip_start,
|
428
|
1007 int width, face_index findex, int cursor,
|
|
1008 int cursor_start, int cursor_width, int cursor_height)
|
|
1009 {
|
|
1010 /* General variables */
|
|
1011 struct frame *f = XFRAME (w->frame);
|
|
1012 struct device *d = XDEVICE (f->device);
|
3094
|
1013 Lisp_Object window = wrap_window (w);
|
428
|
1014 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1015 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1016
|
|
1017 int clip_end;
|
|
1018
|
|
1019 /* Cursor-related variables */
|
|
1020 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
1021 int cursor_clip;
|
|
1022 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
1023 WINDOW_BUFFER (w));
|
|
1024 struct face_cachel *cursor_cachel = 0;
|
|
1025
|
|
1026 /* Text-related variables */
|
|
1027 Lisp_Object bg_pmap;
|
|
1028 GC bgc, gc;
|
3094
|
1029 int height = DISPLAY_LINE_HEIGHT (dl);
|
|
1030 int ypos = DISPLAY_LINE_YPOS (dl);
|
428
|
1031 int len = Dynarr_length (buf);
|
851
|
1032 unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len);
|
428
|
1033 struct textual_run *runs = alloca_array (struct textual_run, len);
|
|
1034 int nruns;
|
|
1035 int i;
|
|
1036 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex);
|
|
1037
|
3094
|
1038 int use_x_font = 1; /* #### bogus!!
|
|
1039 The logic of this function needs review! */
|
|
1040 #ifdef USE_XFT
|
|
1041 Colormap cmap = DEVICE_X_COLORMAP (d);
|
|
1042 Visual *visual = DEVICE_X_VISUAL (d);
|
|
1043 static XftColor fg, bg;
|
|
1044 XftDraw *xftDraw;
|
|
1045
|
|
1046 /* Lazily initialize frame's xftDraw member. */
|
|
1047 if (!FRAME_X_XFTDRAW (f)) {
|
|
1048 FRAME_X_XFTDRAW (f) = XftDrawCreate (dpy, x_win, visual, cmap);
|
|
1049 }
|
|
1050 xftDraw = FRAME_X_XFTDRAW (f);
|
|
1051
|
|
1052 /* #### This will probably cause asserts when passed a Lisp integer for a
|
|
1053 color. See ca. line 759 this file.
|
|
1054 #### Maybe xft_convert_color should take an XColor, not a pixel. */
|
|
1055 #define XFT_FROB_LISP_COLOR(color, dim) \
|
|
1056 xft_convert_color (dpy, cmap, visual, \
|
|
1057 COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color)).pixel, \
|
|
1058 (dim))
|
|
1059 #endif
|
428
|
1060
|
|
1061 if (width < 0)
|
|
1062 width = x_text_width (f, cachel, Dynarr_atp (buf, 0), Dynarr_length (buf));
|
|
1063
|
|
1064 /* Regularize the variables passed in. */
|
|
1065
|
|
1066 if (clip_start < xpos)
|
|
1067 clip_start = xpos;
|
|
1068 clip_end = xpos + width;
|
|
1069 if (clip_start >= clip_end)
|
|
1070 /* It's all clipped out. */
|
|
1071 return;
|
|
1072
|
|
1073 xpos -= xoffset;
|
|
1074
|
|
1075 /* make sure the area we are about to display is subwindow free. */
|
3094
|
1076 redisplay_unmap_subwindows_maybe (f, clip_start, ypos,
|
|
1077 clip_end - clip_start, height);
|
428
|
1078
|
|
1079 cursor_clip = (cursor_start >= clip_start &&
|
|
1080 cursor_start < clip_end);
|
|
1081
|
|
1082 /* This cursor code is really a mess. */
|
|
1083 if (!NILP (w->text_cursor_visible_p)
|
|
1084 && (cursor
|
|
1085 || cursor_clip
|
|
1086 || (cursor_width
|
|
1087 && (cursor_start + cursor_width >= clip_start)
|
|
1088 && !NILP (bar_cursor_value))))
|
|
1089 {
|
|
1090 /* These have to be in separate statements in order to avoid a
|
|
1091 compiler bug. */
|
|
1092 face_index sucks = get_builtin_face_cache_index (w, Vtext_cursor_face);
|
|
1093 cursor_cachel = WINDOW_FACE_CACHEL (w, sucks);
|
|
1094
|
|
1095 /* We have to reset this since any call to WINDOW_FACE_CACHEL
|
|
1096 may cause the cache to resize and any pointers to it to
|
|
1097 become invalid. */
|
|
1098 cachel = WINDOW_FACE_CACHEL (w, findex);
|
|
1099 }
|
|
1100
|
|
1101 #ifdef HAVE_XIM
|
|
1102 if (cursor && focus && (cursor_start == clip_start) && cursor_height)
|
|
1103 XIM_SetSpotLocation (f, xpos - 2, dl->ypos + dl->descent - 2);
|
|
1104 #endif /* HAVE_XIM */
|
|
1105
|
|
1106 bg_pmap = cachel->background_pixmap;
|
|
1107 if (!IMAGE_INSTANCEP (bg_pmap)
|
|
1108 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
1109 bg_pmap = Qnil;
|
|
1110
|
|
1111 if ((cursor && focus && NILP (bar_cursor_value)
|
|
1112 && !NILP (w->text_cursor_visible_p)) || NILP (bg_pmap))
|
|
1113 bgc = 0;
|
|
1114 else
|
3094
|
1115 {
|
|
1116 bgc = x_get_gc (d, Qnil, cachel->foreground, cachel->background,
|
|
1117 bg_pmap, Qnil);
|
|
1118 }
|
428
|
1119
|
|
1120 if (bgc)
|
3094
|
1121 {
|
|
1122 XFillRectangle (dpy, x_win, bgc, clip_start,
|
|
1123 ypos, clip_end - clip_start,
|
|
1124 height);
|
|
1125 }
|
|
1126
|
|
1127 nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0),
|
3659
|
1128 Dynarr_length (buf), cachel);
|
428
|
1129
|
|
1130 for (i = 0; i < nruns; i++)
|
|
1131 {
|
|
1132 Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset);
|
440
|
1133 Lisp_Font_Instance *fi = XFONT_INSTANCE (font);
|
428
|
1134 int this_width;
|
|
1135 int need_clipping;
|
|
1136
|
|
1137 if (EQ (font, Vthe_null_font_instance))
|
|
1138 continue;
|
|
1139
|
3094
|
1140 this_width = x_text_width_single_run (f, cachel, runs + i);
|
428
|
1141 need_clipping = (dl->clip || clip_start > xpos ||
|
|
1142 clip_end < xpos + this_width);
|
|
1143
|
|
1144 /* XDrawImageString only clears the area equal to the height of
|
|
1145 the given font. It is possible that a font is being displayed
|
|
1146 on a line taller than it is, so this would cause us to fail to
|
|
1147 clear some areas. */
|
|
1148 if ((int) fi->height < (int) (height + dl->clip + dl->top_clip))
|
|
1149 {
|
|
1150 int clear_start = max (xpos, clip_start);
|
|
1151 int clear_end = min (xpos + this_width, clip_end);
|
|
1152
|
|
1153 if (cursor)
|
|
1154 {
|
|
1155 int ypos1_line, ypos1_string, ypos2_line, ypos2_string;
|
|
1156
|
|
1157 ypos1_string = dl->ypos - fi->ascent;
|
|
1158 ypos2_string = dl->ypos + fi->descent;
|
3094
|
1159 ypos1_line = ypos;
|
|
1160 ypos2_line = ypos1_line + height;
|
428
|
1161
|
|
1162 /* Make sure we don't clear below the real bottom of the
|
|
1163 line. */
|
|
1164 if (ypos1_string > ypos2_line)
|
|
1165 ypos1_string = ypos2_line;
|
|
1166 if (ypos2_string > ypos2_line)
|
|
1167 ypos2_string = ypos2_line;
|
|
1168
|
|
1169 if (ypos1_line < ypos1_string)
|
|
1170 {
|
|
1171 redisplay_clear_region (window, findex, clear_start, ypos1_line,
|
|
1172 clear_end - clear_start,
|
|
1173 ypos1_string - ypos1_line);
|
|
1174 }
|
|
1175
|
|
1176 if (ypos2_line > ypos2_string)
|
|
1177 {
|
|
1178 redisplay_clear_region (window, findex, clear_start, ypos2_string,
|
|
1179 clear_end - clear_start,
|
|
1180 ypos2_line - ypos2_string);
|
|
1181 }
|
|
1182 }
|
|
1183 else
|
|
1184 {
|
|
1185 redisplay_clear_region (window, findex, clear_start,
|
3094
|
1186 ypos, clear_end - clear_start,
|
428
|
1187 height);
|
|
1188 }
|
|
1189 }
|
|
1190
|
|
1191 if (cursor && cursor_cachel && focus && NILP (bar_cursor_value))
|
3094
|
1192 {
|
|
1193 #ifdef USE_XFT
|
|
1194 fg = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0);
|
|
1195 bg = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0);
|
|
1196 #endif
|
|
1197 gc = x_get_gc (d, font, cursor_cachel->foreground,
|
|
1198 cursor_cachel->background, Qnil, Qnil);
|
|
1199 }
|
428
|
1200 else if (cachel->dim)
|
|
1201 {
|
|
1202 /* Ensure the gray bitmap exists */
|
|
1203 if (DEVICE_X_GRAY_PIXMAP (d) == None)
|
|
1204 DEVICE_X_GRAY_PIXMAP (d) =
|
|
1205 XCreateBitmapFromData (dpy, x_win, (char *)gray_bits,
|
|
1206 gray_width, gray_height);
|
|
1207
|
|
1208 /* Request a GC with the gray stipple pixmap to draw dimmed text */
|
3094
|
1209 #ifdef USE_XFT
|
|
1210 fg = XFT_FROB_LISP_COLOR (cachel->foreground, 1);
|
|
1211 bg = XFT_FROB_LISP_COLOR (cachel->background, 0);
|
|
1212 #endif
|
428
|
1213 gc = x_get_gc (d, font, cachel->foreground, cachel->background,
|
|
1214 Qdim, Qnil);
|
|
1215 }
|
|
1216 else
|
3094
|
1217 {
|
|
1218 #ifdef USE_XFT
|
|
1219 fg = XFT_FROB_LISP_COLOR (cachel->foreground, 0);
|
|
1220 bg = XFT_FROB_LISP_COLOR (cachel->background, 0);
|
|
1221 #endif
|
|
1222 gc = x_get_gc (d, font, cachel->foreground, cachel->background,
|
|
1223 Qnil, Qnil);
|
|
1224 }
|
|
1225 #ifdef USE_XFT
|
|
1226 {
|
|
1227 XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi);
|
428
|
1228
|
3094
|
1229 if (rf)
|
|
1230 {
|
|
1231 use_x_font = 0;
|
|
1232 if (need_clipping)
|
|
1233 {
|
|
1234 Region clip_reg = XCreateRegion();
|
|
1235 XRectangle clip_box = { clip_start, ypos,
|
|
1236 clip_end - clip_start, height };
|
428
|
1237
|
3094
|
1238 XUnionRectWithRegion (&clip_box, clip_reg, clip_reg);
|
|
1239 XftDrawSetClip(xftDraw, clip_reg);
|
|
1240 XDestroyRegion(clip_reg);
|
|
1241 }
|
428
|
1242
|
3094
|
1243 if (!bgc)
|
|
1244 {
|
|
1245 /* #### Neither rect_height nor XftTextExtents as computed
|
|
1246 below handles the vertical space taken up by antialiasing,
|
|
1247 which for some fonts (eg, Bitstream Vera Sans Mono-16 on
|
|
1248 my Mac PowerBook G4) leaves behind orphaned dots on
|
|
1249 insertion or deletion earlier in the line, especially in
|
|
1250 the case of the underscore character.
|
|
1251 Interestingly, insertion or deletion of a single character
|
|
1252 immediately after a refresh does not leave any droppings,
|
|
1253 but any further insertions or deletions do.
|
|
1254 While adding a pixel to rect_height (mostly) takes care of
|
|
1255 this, it trashes aggressively laid-out elements like the
|
|
1256 modeline (overwriting part of the bevel).
|
|
1257 OK, unconditionally redraw the bevel, and increment
|
|
1258 rect_height by 1. See x_output_display_block. -- sjt */
|
|
1259 struct textual_run *run = &runs[i];
|
|
1260 int rect_width = x_text_width_single_run (f, cachel, run);
|
|
1261 #ifndef USE_XFTTEXTENTS_TO_AVOID_FONT_DROPPINGS
|
|
1262 int rect_height = FONT_INSTANCE_ASCENT(fi)
|
|
1263 + FONT_INSTANCE_DESCENT(fi) + 1;
|
|
1264 #else
|
|
1265 int rect_height = FONT_INSTANCE_ASCENT(fi)
|
|
1266 + FONT_INSTANCE_DESCENT(fi);
|
|
1267 XGlyphInfo gi;
|
|
1268 if (run->dimension == 2) {
|
|
1269 XftTextExtents16 (dpy,
|
|
1270 FONT_INSTANCE_X_XFTFONT(fi),
|
|
1271 (XftChar16 *) run->ptr, run->len, &gi);
|
|
1272 } else {
|
|
1273 XftTextExtents8 (dpy,
|
|
1274 FONT_INSTANCE_X_XFTFONT(fi),
|
|
1275 run->ptr, run->len, &gi);
|
|
1276 }
|
|
1277 rect_height = rect_height > gi.height
|
|
1278 ? rect_height : gi.height;
|
|
1279 #endif
|
428
|
1280
|
3094
|
1281 XftDrawRect (xftDraw, &bg,
|
|
1282 xpos, ypos, rect_width, rect_height);
|
|
1283 }
|
|
1284
|
|
1285 if (runs[i].dimension == 1)
|
|
1286 XftDrawString8 (xftDraw, &fg, rf, xpos, dl->ypos,
|
|
1287 runs[i].ptr, runs[i].len);
|
|
1288 else
|
|
1289 XftDrawString16 (xftDraw, &fg, rf, xpos, dl->ypos,
|
|
1290 (XftChar16 *) runs[i].ptr, runs[i].len);
|
|
1291 }
|
|
1292 }
|
|
1293 #endif
|
|
1294 {
|
|
1295 if (use_x_font)
|
|
1296 {
|
|
1297 if (need_clipping)
|
|
1298 {
|
|
1299 XRectangle clip_box[1];
|
|
1300
|
|
1301 clip_box[0].x = 0;
|
|
1302 clip_box[0].y = 0;
|
|
1303 clip_box[0].width = clip_end - clip_start;
|
|
1304 clip_box[0].height = height;
|
|
1305
|
|
1306 XSetClipRectangles (dpy, gc, clip_start, ypos,
|
|
1307 clip_box, 1, YXBanded);
|
|
1308 }
|
|
1309
|
|
1310 if (runs[i].dimension == 1)
|
|
1311 (bgc ? XDrawString : XDrawImageString)
|
|
1312 (dpy, x_win, gc, xpos, dl->ypos,
|
|
1313 (char *) runs[i].ptr, runs[i].len);
|
|
1314 else
|
|
1315 (bgc ? XDrawString16 : XDrawImageString16)
|
|
1316 (dpy, x_win, gc, xpos, dl->ypos,
|
|
1317 (XChar2b *) runs[i].ptr, runs[i].len);
|
|
1318 }
|
|
1319 }
|
428
|
1320
|
|
1321 /* We draw underlines in the same color as the text. */
|
|
1322 if (cachel->underline)
|
|
1323 {
|
647
|
1324 int upos, uthick;
|
|
1325 unsigned long upos_ext, uthick_ext;
|
3094
|
1326 XFontStruct *fs =
|
|
1327 use_x_font ? FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)) : 0;
|
|
1328 /* #### the logic of the next two may be suboptimal: we may want
|
|
1329 to use the POSITION and/or THICKNESS information with Xft */
|
|
1330 if (fs && XGetFontProperty (fs, XA_UNDERLINE_POSITION, &upos_ext))
|
|
1331 upos = (int) upos_ext;
|
647
|
1332 else
|
3094
|
1333 upos = dl->descent / 2;
|
|
1334 if (fs && XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext))
|
|
1335 uthick = (int) uthick_ext;
|
|
1336 else
|
428
|
1337 uthick = 1;
|
|
1338 if (dl->ypos + upos < dl->ypos + dl->descent - dl->clip)
|
|
1339 {
|
|
1340 if (dl->ypos + upos + uthick > dl->ypos + dl->descent - dl->clip)
|
|
1341 uthick = dl->descent - dl->clip - upos;
|
|
1342
|
|
1343 if (uthick == 1)
|
|
1344 {
|
|
1345 XDrawLine (dpy, x_win, gc, xpos, dl->ypos + upos,
|
|
1346 xpos + this_width, dl->ypos + upos);
|
|
1347 }
|
|
1348 else if (uthick > 1)
|
|
1349 {
|
|
1350 XFillRectangle (dpy, x_win, gc, xpos,
|
|
1351 dl->ypos + upos, this_width, uthick);
|
|
1352 }
|
|
1353 }
|
|
1354 }
|
|
1355
|
647
|
1356 if (cachel->strikethru)
|
|
1357 {
|
|
1358 int ascent, descent, upos, uthick;
|
|
1359 unsigned long ascent_ext, descent_ext, uthick_ext;
|
3094
|
1360 XFontStruct *fs = FONT_INSTANCE_X_FONT (fi);
|
647
|
1361
|
3094
|
1362 if (!use_x_font)
|
|
1363 {
|
|
1364 ascent = dl->ascent;
|
|
1365 descent = dl->descent;
|
|
1366 uthick = 1;
|
|
1367 }
|
647
|
1368 else
|
3094
|
1369 {
|
|
1370 if (!XGetFontProperty (fs, XA_STRIKEOUT_ASCENT, &ascent_ext))
|
|
1371 ascent = fs->ascent;
|
|
1372 else
|
|
1373 ascent = (int) ascent_ext;
|
|
1374 if (!XGetFontProperty (fs, XA_STRIKEOUT_DESCENT, &descent_ext))
|
|
1375 descent = fs->descent;
|
|
1376 else
|
|
1377 descent = (int) descent_ext;
|
|
1378 if (!XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext))
|
|
1379 uthick = 1;
|
|
1380 else
|
|
1381 uthick = (int) uthick_ext;
|
|
1382 }
|
428
|
1383
|
647
|
1384 upos = ascent - ((ascent + descent) / 2) + 1;
|
428
|
1385
|
647
|
1386 /* Generally, upos will be positive (above the baseline),so
|
|
1387 subtract */
|
|
1388 if (dl->ypos - upos < dl->ypos + dl->descent - dl->clip)
|
|
1389 {
|
|
1390 if (dl->ypos - upos + uthick > dl->ypos + dl->descent - dl->clip)
|
|
1391 uthick = dl->descent - dl->clip + upos;
|
|
1392
|
|
1393 if (uthick == 1)
|
428
|
1394 XDrawLine (dpy, x_win, gc, xpos, dl->ypos - upos,
|
|
1395 xpos + this_width, dl->ypos - upos);
|
647
|
1396 else if (uthick > 1)
|
428
|
1397 XFillRectangle (dpy, x_win, gc, xpos, dl->ypos + upos,
|
|
1398 this_width, uthick);
|
647
|
1399 }
|
|
1400 }
|
428
|
1401
|
|
1402 /* Restore the GC */
|
|
1403 if (need_clipping)
|
|
1404 {
|
3094
|
1405 #ifdef USE_XFT
|
|
1406 if (!use_x_font)
|
|
1407 {
|
|
1408 XftDrawSetClip(xftDraw, 0);
|
|
1409 }
|
|
1410 else
|
|
1411 {
|
|
1412 #endif
|
|
1413 XSetClipMask (dpy, gc, None);
|
|
1414 XSetClipOrigin (dpy, gc, 0, 0);
|
|
1415 #ifdef USE_XFT
|
|
1416 }
|
|
1417 #endif
|
428
|
1418 }
|
|
1419
|
|
1420 /* If we are actually superimposing the cursor then redraw with just
|
|
1421 the appropriate section highlighted. */
|
|
1422 if (cursor_clip && !cursor && focus && cursor_cachel)
|
|
1423 {
|
3094
|
1424 #ifdef USE_XFT
|
|
1425 if (!use_x_font) /* Xft */
|
|
1426 {
|
|
1427 XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi);
|
|
1428
|
|
1429 { /* set up clipping */
|
|
1430 Region clip_reg = XCreateRegion();
|
|
1431 XRectangle clip_box = { cursor_start, ypos,
|
|
1432 cursor_width, height };
|
|
1433
|
|
1434 XUnionRectWithRegion (&clip_box, clip_reg, clip_reg);
|
|
1435 XftDrawSetClip(xftDraw, clip_reg);
|
|
1436 XDestroyRegion(clip_reg);
|
|
1437 }
|
|
1438 { /* draw background rectangle & draw text */
|
|
1439 int rect_height = FONT_INSTANCE_ASCENT(fi)
|
|
1440 + FONT_INSTANCE_DESCENT(fi);
|
|
1441 int rect_width = x_text_width_single_run(f, cachel, &runs[i]);
|
|
1442 XftColor xft_color;
|
428
|
1443
|
3094
|
1444 xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0);
|
|
1445 XftDrawRect (xftDraw, &xft_color,
|
|
1446 xpos, ypos, rect_width, rect_height);
|
428
|
1447
|
3094
|
1448 xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0);
|
|
1449 if (runs[i].dimension == 1)
|
|
1450 XftDrawString8 (xftDraw, &xft_color, rf, xpos, dl->ypos,
|
|
1451 runs[i].ptr, runs[i].len);
|
|
1452 else
|
|
1453 XftDrawString16 (xftDraw, &xft_color, rf, xpos, dl->ypos,
|
|
1454 (XftChar16 *) runs[i].ptr, runs[i].len);
|
|
1455 }
|
|
1456
|
|
1457 XftDrawSetClip(xftDraw, 0);
|
|
1458 }
|
|
1459 else /* core font, not Xft */
|
|
1460 {
|
|
1461 #endif
|
|
1462 GC cgc;
|
|
1463 XRectangle clip_box[1];
|
|
1464
|
|
1465 cgc = x_get_gc (d, font, cursor_cachel->foreground,
|
|
1466 cursor_cachel->background, Qnil, Qnil);
|
428
|
1467
|
3094
|
1468 clip_box[0].x = 0;
|
|
1469 clip_box[0].y = 0;
|
|
1470 clip_box[0].width = cursor_width;
|
|
1471 clip_box[0].height = height;
|
|
1472
|
|
1473 XSetClipRectangles (dpy, cgc, cursor_start, ypos,
|
|
1474 clip_box, 1, YXBanded);
|
|
1475 if (runs[i].dimension == 1)
|
|
1476 XDrawImageString (dpy, x_win, cgc, xpos, dl->ypos,
|
|
1477 (char *) runs[i].ptr, runs[i].len);
|
|
1478 else
|
|
1479 XDrawImageString16 (dpy, x_win, cgc, xpos, dl->ypos,
|
|
1480 (XChar2b *) runs[i].ptr, runs[i].len);
|
|
1481
|
|
1482 XSetClipMask (dpy, cgc, None);
|
|
1483 XSetClipOrigin (dpy, cgc, 0, 0);
|
|
1484 #ifdef USE_XFT
|
|
1485 }
|
|
1486 #endif
|
428
|
1487 }
|
|
1488
|
|
1489 xpos += this_width;
|
|
1490 }
|
|
1491
|
|
1492 /* Draw the non-focus box or bar-cursor as needed. */
|
|
1493 /* Can't this logic be simplified? */
|
|
1494 if (cursor_cachel
|
|
1495 && ((cursor && !focus && NILP (bar_cursor_value))
|
|
1496 || (cursor_width
|
|
1497 && (cursor_start + cursor_width >= clip_start)
|
|
1498 && !NILP (bar_cursor_value))))
|
|
1499 {
|
|
1500 int tmp_height, tmp_y;
|
|
1501 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
1502 int need_clipping = (cursor_start < clip_start
|
|
1503 || clip_end < cursor_start + cursor_width);
|
|
1504
|
|
1505 /* #### This value is correct (as far as I know) because
|
|
1506 all of the times we need to draw this cursor, we will
|
|
1507 be called with exactly one character, so we know we
|
|
1508 can always use runs[0].
|
|
1509
|
|
1510 This is bogus as all hell, however. The cursor handling in
|
|
1511 this function is way bogus and desperately needs to be
|
3094
|
1512 cleaned up. (In particular, the drawing of the cursor should
|
428
|
1513 really really be separated out of this function. This may be
|
|
1514 a bit tricky now because this function itself does way too
|
|
1515 much stuff, a lot of which needs to be moved into
|
3094
|
1516 redisplay.c.) This is the only way to be able to easily add
|
428
|
1517 new cursor types or (e.g.) make the bar cursor be able to
|
|
1518 span two characters instead of overlaying just one. */
|
|
1519 int bogusly_obtained_ascent_value =
|
|
1520 XFONT_INSTANCE (FACE_CACHEL_FONT (cachel, runs[0].charset))->ascent;
|
|
1521
|
|
1522 if (!NILP (bar_cursor_value))
|
|
1523 {
|
|
1524 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
1525 make_int (bar_width));
|
|
1526 }
|
|
1527 else
|
|
1528 {
|
|
1529 gc = x_get_gc (d, Qnil, cursor_cachel->background,
|
|
1530 Qnil, Qnil, Qnil);
|
|
1531 }
|
|
1532
|
|
1533 tmp_y = dl->ypos - bogusly_obtained_ascent_value;
|
|
1534 tmp_height = cursor_height;
|
3094
|
1535 if (tmp_y + tmp_height > (int) (ypos + height))
|
428
|
1536 {
|
3094
|
1537 tmp_y = ypos + height - tmp_height;
|
|
1538 if (tmp_y < (int) ypos)
|
|
1539 tmp_y = ypos;
|
|
1540 tmp_height = ypos + height - tmp_y;
|
428
|
1541 }
|
|
1542
|
|
1543 if (need_clipping)
|
|
1544 {
|
|
1545 XRectangle clip_box[1];
|
|
1546 clip_box[0].x = 0;
|
|
1547 clip_box[0].y = 0;
|
|
1548 clip_box[0].width = clip_end - clip_start;
|
|
1549 clip_box[0].height = tmp_height;
|
|
1550 XSetClipRectangles (dpy, gc, clip_start, tmp_y,
|
3094
|
1551 /* #### why not Unsorted? */
|
|
1552 clip_box, 1, YXBanded);
|
428
|
1553 }
|
|
1554
|
|
1555 if (!focus && NILP (bar_cursor_value))
|
|
1556 {
|
|
1557 XDrawRectangle (dpy, x_win, gc, cursor_start, tmp_y,
|
|
1558 cursor_width - 1, tmp_height - 1);
|
|
1559 }
|
|
1560 else if (focus && !NILP (bar_cursor_value))
|
|
1561 {
|
|
1562 XDrawLine (dpy, x_win, gc, cursor_start + bar_width - 1, tmp_y,
|
|
1563 cursor_start + bar_width - 1, tmp_y + tmp_height - 1);
|
|
1564 }
|
|
1565
|
|
1566 /* Restore the GC */
|
|
1567 if (need_clipping)
|
|
1568 {
|
|
1569 XSetClipMask (dpy, gc, None);
|
|
1570 XSetClipOrigin (dpy, gc, 0, 0);
|
|
1571 }
|
|
1572 }
|
3094
|
1573
|
|
1574 #ifdef USE_XFT
|
|
1575 #undef XFT_FROB_LISP_COLOR
|
|
1576 #endif
|
|
1577
|
428
|
1578 }
|
|
1579
|
|
1580 void
|
440
|
1581 x_output_x_pixmap (struct frame *f, Lisp_Image_Instance *p, int x,
|
428
|
1582 int y, int xoffset, int yoffset,
|
440
|
1583 int width, int height, unsigned long fg, unsigned long bg,
|
428
|
1584 GC override_gc)
|
|
1585 {
|
|
1586 struct device *d = XDEVICE (f->device);
|
|
1587 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1588 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1589
|
|
1590 GC gc;
|
|
1591 XGCValues gcv;
|
|
1592 unsigned long pixmap_mask;
|
|
1593
|
|
1594 if (!override_gc)
|
|
1595 {
|
|
1596 memset (&gcv, ~0, sizeof (XGCValues));
|
|
1597 gcv.graphics_exposures = False;
|
|
1598 gcv.foreground = fg;
|
|
1599 gcv.background = bg;
|
|
1600 pixmap_mask = GCForeground | GCBackground | GCGraphicsExposures;
|
|
1601
|
|
1602 if (IMAGE_INSTANCE_X_MASK (p))
|
|
1603 {
|
|
1604 gcv.function = GXcopy;
|
|
1605 gcv.clip_mask = IMAGE_INSTANCE_X_MASK (p);
|
|
1606 gcv.clip_x_origin = x - xoffset;
|
|
1607 gcv.clip_y_origin = y - yoffset;
|
|
1608 pixmap_mask |= (GCFunction | GCClipMask | GCClipXOrigin |
|
|
1609 GCClipYOrigin);
|
|
1610 /* Can't set a clip rectangle because we already have a mask.
|
|
1611 Is it possible to get an equivalent effect by changing the
|
|
1612 args to XCopyArea below rather than messing with a clip box?
|
|
1613 - dkindred@cs.cmu.edu
|
|
1614 Yes. We don't clip at all now - andy@xemacs.org
|
|
1615 */
|
|
1616 }
|
|
1617
|
|
1618 gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, pixmap_mask);
|
|
1619 }
|
|
1620 else
|
|
1621 {
|
|
1622 gc = override_gc;
|
|
1623 /* override_gc might have a mask already--we don't want to nuke it.
|
|
1624 Maybe we can insist that override_gc have no mask, or use
|
|
1625 one of the suggestions above. */
|
|
1626 }
|
|
1627
|
|
1628 /* depth of 0 means it's a bitmap, not a pixmap, and we should use
|
|
1629 XCopyPlane (1 = current foreground color, 0 = background) instead
|
|
1630 of XCopyArea, which means that the bits in the pixmap are actual
|
|
1631 pixel values, instead of symbolic of fg/bg. */
|
|
1632 if (IMAGE_INSTANCE_PIXMAP_DEPTH (p) > 0)
|
|
1633 {
|
440
|
1634 XCopyArea (dpy,
|
|
1635 IMAGE_INSTANCE_X_PIXMAP_SLICE
|
428
|
1636 (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc, xoffset,
|
|
1637 yoffset, width,
|
|
1638 height, x, y);
|
|
1639 }
|
|
1640 else
|
|
1641 {
|
440
|
1642 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP_SLICE
|
428
|
1643 (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc,
|
|
1644 xoffset, yoffset, width, height, x, y, 1L);
|
|
1645 }
|
|
1646 }
|
|
1647
|
|
1648 static void
|
|
1649 x_output_pixmap (struct window *w, Lisp_Object image_instance,
|
|
1650 struct display_box *db, struct display_glyph_area *dga,
|
|
1651 face_index findex, int cursor_start, int cursor_width,
|
2286
|
1652 int cursor_height, int UNUSED (bg_pixmap))
|
428
|
1653 {
|
|
1654 struct frame *f = XFRAME (w->frame);
|
|
1655 struct device *d = XDEVICE (f->device);
|
440
|
1656 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
428
|
1657
|
|
1658 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1659 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
440
|
1660
|
428
|
1661 /* Output the pixmap. */
|
|
1662 {
|
|
1663 Lisp_Object tmp_pixel;
|
|
1664 XColor tmp_bcolor, tmp_fcolor;
|
|
1665
|
|
1666 tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex);
|
|
1667 tmp_fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1668 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex);
|
|
1669 tmp_bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1670
|
|
1671 x_output_x_pixmap (f, p, db->xpos, db->ypos,
|
|
1672 dga->xoffset, dga->yoffset,
|
|
1673 dga->width, dga->height,
|
|
1674 tmp_fcolor.pixel, tmp_bcolor.pixel, 0);
|
|
1675 }
|
|
1676
|
|
1677 /* Draw a cursor over top of the pixmap. */
|
|
1678 if (cursor_width && cursor_height && (cursor_start >= db->xpos)
|
|
1679 && !NILP (w->text_cursor_visible_p)
|
|
1680 && (cursor_start < db->xpos + dga->width))
|
|
1681 {
|
|
1682 GC gc;
|
|
1683 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
1684 struct face_cachel *cursor_cachel =
|
|
1685 WINDOW_FACE_CACHEL (w,
|
|
1686 get_builtin_face_cache_index
|
|
1687 (w, Vtext_cursor_face));
|
|
1688
|
|
1689 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
1690
|
|
1691 if (cursor_width > db->xpos + dga->width - cursor_start)
|
|
1692 cursor_width = db->xpos + dga->width - cursor_start;
|
|
1693
|
|
1694 if (focus)
|
|
1695 {
|
|
1696 XFillRectangle (dpy, x_win, gc, cursor_start, db->ypos, cursor_width,
|
|
1697 cursor_height);
|
|
1698 }
|
|
1699 else
|
|
1700 {
|
|
1701 XDrawRectangle (dpy, x_win, gc, cursor_start, db->ypos, cursor_width,
|
|
1702 cursor_height);
|
|
1703 }
|
|
1704 }
|
|
1705 }
|
|
1706
|
|
1707 /*****************************************************************************
|
|
1708 x_output_vertical_divider
|
|
1709
|
|
1710 Draw a vertical divider down the right side of the given window.
|
|
1711 ****************************************************************************/
|
|
1712 static void
|
|
1713 x_output_vertical_divider (struct window *w, int clear)
|
|
1714 {
|
|
1715 struct frame *f = XFRAME (w->frame);
|
|
1716 struct device *d = XDEVICE (f->device);
|
|
1717
|
|
1718 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1719 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1720 Lisp_Object tmp_pixel;
|
|
1721 XColor tmp_color;
|
|
1722 XGCValues gcv;
|
|
1723 GC background_gc;
|
|
1724 enum edge_style style;
|
|
1725
|
|
1726 unsigned long mask;
|
|
1727 int x, y1, y2, width, shadow_thickness, spacing, line_width;
|
647
|
1728 face_index div_face =
|
|
1729 get_builtin_face_cache_index (w, Vvertical_divider_face);
|
428
|
1730
|
|
1731 width = window_divider_width (w);
|
|
1732 shadow_thickness = XINT (w->vertical_divider_shadow_thickness);
|
|
1733 spacing = XINT (w->vertical_divider_spacing);
|
|
1734 line_width = XINT (w->vertical_divider_line_width);
|
|
1735 x = WINDOW_RIGHT (w) - width;
|
442
|
1736 y1 = WINDOW_TOP (w);
|
|
1737 y2 = WINDOW_BOTTOM (w);
|
428
|
1738
|
|
1739 memset (&gcv, ~0, sizeof (XGCValues));
|
|
1740
|
|
1741 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, div_face);
|
|
1742 tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1743
|
|
1744 /* First, get the GC's. */
|
|
1745 gcv.background = tmp_color.pixel;
|
|
1746 gcv.foreground = tmp_color.pixel;
|
|
1747 gcv.graphics_exposures = False;
|
|
1748 mask = GCForeground | GCBackground | GCGraphicsExposures;
|
|
1749 background_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask);
|
|
1750
|
|
1751 /* Clear the divider area first. This needs to be done when a
|
|
1752 window split occurs. */
|
|
1753 if (clear)
|
|
1754 XClearArea (dpy, x_win, x, y1, width, y2 - y1, False);
|
|
1755
|
|
1756 /* Draw the divider line. */
|
|
1757 XFillRectangle (dpy, x_win, background_gc,
|
|
1758 x + spacing + shadow_thickness, y1,
|
|
1759 line_width, y2 - y1);
|
|
1760
|
|
1761 if (shadow_thickness < 0)
|
|
1762 {
|
|
1763 shadow_thickness = -shadow_thickness;
|
|
1764 style = EDGE_BEVEL_IN;
|
|
1765 }
|
|
1766 else
|
|
1767 {
|
|
1768 style = EDGE_BEVEL_OUT;
|
|
1769 }
|
|
1770
|
|
1771 /* Draw the shadows around the divider line */
|
|
1772 x_bevel_area (w, div_face, x + spacing, y1,
|
|
1773 width - 2 * spacing, y2 - y1,
|
|
1774 shadow_thickness, EDGE_ALL, style);
|
|
1775 }
|
|
1776
|
|
1777 /*****************************************************************************
|
|
1778 x_output_blank
|
|
1779
|
|
1780 Output a blank by clearing the area it covers in the foreground color
|
|
1781 of its face.
|
|
1782 ****************************************************************************/
|
|
1783 static void
|
|
1784 x_output_blank (struct window *w, struct display_line *dl, struct rune *rb,
|
|
1785 int start_pixpos, int cursor_start, int cursor_width)
|
|
1786 {
|
|
1787 struct frame *f = XFRAME (w->frame);
|
|
1788 struct device *d = XDEVICE (f->device);
|
|
1789
|
|
1790 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1791 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1792 GC gc;
|
|
1793 struct face_cachel *cursor_cachel =
|
|
1794 WINDOW_FACE_CACHEL (w,
|
|
1795 get_builtin_face_cache_index
|
|
1796 (w, Vtext_cursor_face));
|
|
1797 Lisp_Object bg_pmap;
|
|
1798 Lisp_Object buffer = WINDOW_BUFFER (w);
|
|
1799 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
1800 buffer);
|
|
1801
|
|
1802 int x = rb->xpos;
|
|
1803 int y = DISPLAY_LINE_YPOS (dl);
|
|
1804 int width = rb->width;
|
|
1805 int height = DISPLAY_LINE_HEIGHT (dl);
|
|
1806
|
|
1807 /* Unmap all subwindows in the area we are going to blank. */
|
|
1808 redisplay_unmap_subwindows_maybe (f, x, y, width, height);
|
|
1809
|
|
1810 if (start_pixpos > x)
|
|
1811 {
|
|
1812 if (start_pixpos >= (x + width))
|
|
1813 return;
|
|
1814 else
|
|
1815 {
|
|
1816 width -= (start_pixpos - x);
|
|
1817 x = start_pixpos;
|
|
1818 }
|
|
1819 }
|
|
1820
|
|
1821 bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex);
|
|
1822 if (!IMAGE_INSTANCEP (bg_pmap)
|
|
1823 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
1824 bg_pmap = Qnil;
|
|
1825
|
|
1826 if (NILP (bg_pmap))
|
|
1827 gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex),
|
|
1828 Qnil, Qnil, Qnil);
|
|
1829 else
|
|
1830 gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex),
|
|
1831 WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), bg_pmap,
|
|
1832 Qnil);
|
|
1833
|
|
1834 XFillRectangle (dpy, x_win, gc, x, y, width, height);
|
|
1835
|
|
1836 /* If this rune is marked as having the cursor, then it is actually
|
|
1837 representing a tab. */
|
|
1838 if (!NILP (w->text_cursor_visible_p)
|
|
1839 && (rb->cursor_type == CURSOR_ON
|
|
1840 || (cursor_width
|
|
1841 && (cursor_start + cursor_width > x)
|
|
1842 && cursor_start < (x + width))))
|
|
1843 {
|
|
1844 int cursor_height, cursor_y;
|
|
1845 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
440
|
1846 Lisp_Font_Instance *fi;
|
428
|
1847
|
|
1848 fi = XFONT_INSTANCE (FACE_CACHEL_FONT
|
|
1849 (WINDOW_FACE_CACHEL (w, rb->findex),
|
|
1850 Vcharset_ascii));
|
|
1851
|
|
1852 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
1853
|
|
1854 cursor_y = dl->ypos - fi->ascent;
|
|
1855 cursor_height = fi->height;
|
|
1856 if (cursor_y + cursor_height > y + height)
|
|
1857 cursor_height = y + height - cursor_y;
|
|
1858
|
|
1859 if (focus)
|
|
1860 {
|
|
1861 if (NILP (bar_cursor_value))
|
|
1862 {
|
|
1863 XFillRectangle (dpy, x_win, gc, cursor_start, cursor_y,
|
|
1864 fi->width, cursor_height);
|
|
1865 }
|
|
1866 else
|
|
1867 {
|
|
1868 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
1869
|
|
1870 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
1871 make_int (bar_width));
|
|
1872 XDrawLine (dpy, x_win, gc, cursor_start + bar_width - 1,
|
|
1873 cursor_y, cursor_start + bar_width - 1,
|
|
1874 cursor_y + cursor_height - 1);
|
|
1875 }
|
|
1876 }
|
|
1877 else if (NILP (bar_cursor_value))
|
|
1878 {
|
|
1879 XDrawRectangle (dpy, x_win, gc, cursor_start, cursor_y,
|
|
1880 fi->width - 1, cursor_height - 1);
|
|
1881 }
|
|
1882 }
|
|
1883 }
|
|
1884
|
|
1885 /*****************************************************************************
|
|
1886 x_output_hline
|
|
1887
|
|
1888 Output a horizontal line in the foreground of its face.
|
|
1889 ****************************************************************************/
|
|
1890 static void
|
|
1891 x_output_hline (struct window *w, struct display_line *dl, struct rune *rb)
|
|
1892 {
|
|
1893 struct frame *f = XFRAME (w->frame);
|
|
1894 struct device *d = XDEVICE (f->device);
|
|
1895
|
|
1896 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1897 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1898 GC gc;
|
|
1899
|
|
1900 int x = rb->xpos;
|
|
1901 int width = rb->width;
|
|
1902 int height = DISPLAY_LINE_HEIGHT (dl);
|
|
1903 int ypos1, ypos2, ypos3, ypos4;
|
|
1904
|
|
1905 ypos1 = DISPLAY_LINE_YPOS (dl);
|
|
1906 ypos2 = ypos1 + rb->object.hline.yoffset;
|
|
1907 ypos3 = ypos2 + rb->object.hline.thickness;
|
|
1908 ypos4 = dl->ypos + dl->descent - dl->clip;
|
|
1909
|
|
1910 /* First clear the area not covered by the line. */
|
|
1911 if (height - rb->object.hline.thickness > 0)
|
|
1912 {
|
|
1913 gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex),
|
|
1914 Qnil, Qnil, Qnil);
|
|
1915
|
|
1916 if (ypos2 - ypos1 > 0)
|
|
1917 XFillRectangle (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1);
|
|
1918 if (ypos4 - ypos3 > 0)
|
|
1919 XFillRectangle (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1);
|
|
1920 }
|
|
1921
|
|
1922 /* Now draw the line. */
|
|
1923 gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex),
|
|
1924 Qnil, Qnil, Qnil);
|
|
1925
|
|
1926 if (ypos2 < ypos1)
|
|
1927 ypos2 = ypos1;
|
|
1928 if (ypos3 > ypos4)
|
|
1929 ypos3 = ypos4;
|
|
1930
|
|
1931 if (ypos3 - ypos2 > 0)
|
|
1932 XFillRectangle (dpy, x_win, gc, x, ypos2, width, ypos3 - ypos2);
|
|
1933 }
|
|
1934
|
|
1935 /*****************************************************************************
|
|
1936 x_output_shadows
|
|
1937
|
|
1938 Draw a shadow around the given area using the given GC's. It is the
|
|
1939 callers responsibility to set the GC's appropriately.
|
|
1940 ****************************************************************************/
|
|
1941 void
|
|
1942 x_output_shadows (struct frame *f, int x, int y, int width, int height,
|
2286
|
1943 GC top_shadow_gc, GC bottom_shadow_gc,
|
|
1944 GC UNUSED (background_gc), int shadow_thickness, int edges)
|
428
|
1945 {
|
|
1946 struct device *d = XDEVICE (f->device);
|
|
1947
|
|
1948 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1949 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
1950
|
|
1951 XSegment top_shadow[20], bottom_shadow[20];
|
|
1952 int elt;
|
|
1953
|
|
1954 if (shadow_thickness > 10)
|
|
1955 shadow_thickness = 10;
|
|
1956 else if (shadow_thickness < 0)
|
|
1957 shadow_thickness = 0;
|
|
1958 if (shadow_thickness > (width / 2))
|
|
1959 shadow_thickness = width / 2;
|
|
1960 if (shadow_thickness > (height / 2))
|
|
1961 shadow_thickness = height / 2;
|
|
1962
|
|
1963 for (elt = 0; elt < shadow_thickness; elt++)
|
|
1964 {
|
|
1965 int seg1 = elt;
|
|
1966 int seg2 = (edges & EDGE_TOP) ? elt + shadow_thickness : elt;
|
|
1967 int bot_seg2 = (edges & EDGE_BOTTOM) ? elt + shadow_thickness : elt;
|
|
1968
|
|
1969 if (edges & EDGE_TOP)
|
|
1970 {
|
|
1971 top_shadow[seg1].x1 = x + elt;
|
|
1972 top_shadow[seg1].x2 = x + width - elt - 1;
|
|
1973 top_shadow[seg1].y1 = top_shadow[seg1].y2 = y + elt;
|
|
1974 }
|
|
1975 if (edges & EDGE_LEFT)
|
|
1976 {
|
|
1977 top_shadow[seg2].x1 = top_shadow[seg2].x2 = x + elt;
|
|
1978 top_shadow[seg2].y1 = y + elt;
|
|
1979 top_shadow[seg2].y2 = y + height - elt - 1;
|
|
1980 }
|
|
1981 if (edges & EDGE_BOTTOM)
|
|
1982 {
|
|
1983 bottom_shadow[seg1].x1 = x + elt;
|
|
1984 bottom_shadow[seg1].x2 = x + width - elt - 1;
|
|
1985 bottom_shadow[seg1].y1 = bottom_shadow[seg1].y2 = y + height - elt - 1;
|
|
1986 }
|
|
1987 if (edges & EDGE_RIGHT)
|
|
1988 {
|
|
1989 bottom_shadow[bot_seg2].x1 = bottom_shadow[bot_seg2].x2 = x + width - elt - 1;
|
|
1990 bottom_shadow[bot_seg2].y1 = y + elt;
|
|
1991 bottom_shadow[bot_seg2].y2 = y + height - elt - 1;
|
|
1992 }
|
|
1993 }
|
|
1994
|
|
1995 XDrawSegments (dpy, x_win, top_shadow_gc, top_shadow,
|
|
1996 ((edges & EDGE_TOP) ? shadow_thickness : 0)
|
|
1997 + ((edges & EDGE_LEFT) ? shadow_thickness : 0));
|
|
1998 XDrawSegments (dpy, x_win, bottom_shadow_gc, bottom_shadow,
|
|
1999 ((edges & EDGE_BOTTOM) ? shadow_thickness : 0)
|
|
2000 + ((edges & EDGE_RIGHT) ? shadow_thickness : 0));
|
|
2001 }
|
|
2002
|
|
2003 /*****************************************************************************
|
|
2004 x_generate_shadow_pixels
|
|
2005
|
|
2006 Given three pixels (top shadow, bottom shadow, background) massage
|
|
2007 the top and bottom shadow colors to guarantee that they differ. The
|
|
2008 background pixels are not allowed to be modified.
|
|
2009
|
|
2010 This function modifies its parameters.
|
|
2011
|
|
2012 This code is modified from code blatantly stolen from lwlib/xlwmenu.c
|
|
2013 ****************************************************************************/
|
|
2014 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
2015 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
2016
|
|
2017 void
|
|
2018 x_generate_shadow_pixels (struct frame *f, unsigned long *top_shadow,
|
|
2019 unsigned long *bottom_shadow,
|
|
2020 unsigned long background,
|
|
2021 unsigned long core_background)
|
|
2022 {
|
|
2023 struct device *d = XDEVICE (f->device);
|
|
2024 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
2025 Colormap cmap = DEVICE_X_COLORMAP (d);
|
|
2026 Visual *visual = DEVICE_X_VISUAL (d);
|
|
2027
|
|
2028 XColor topc, botc;
|
|
2029 int top_frobbed = 0, bottom_frobbed = 0;
|
|
2030
|
|
2031 /* If the top shadow is the same color as the background, try to
|
|
2032 adjust it. */
|
|
2033 if (*top_shadow == background)
|
|
2034 {
|
|
2035 topc.pixel = background;
|
|
2036 XQueryColor (dpy, cmap, &topc);
|
|
2037 /* don't overflow/wrap! */
|
|
2038 topc.red = MINL (65535, (unsigned long) topc.red * 6 / 5);
|
|
2039 topc.green = MINL (65535, (unsigned long) topc.green * 6 / 5);
|
|
2040 topc.blue = MINL (65535, (unsigned long) topc.blue * 6 / 5);
|
3094
|
2041 if (x_allocate_nearest_color (dpy, cmap, visual, &topc))
|
428
|
2042 {
|
|
2043 *top_shadow = topc.pixel;
|
|
2044 top_frobbed = 1;
|
|
2045 }
|
|
2046 }
|
|
2047
|
|
2048 /* If the bottom shadow is the same color as the background, try to
|
|
2049 adjust it. */
|
|
2050 if (*bottom_shadow == background)
|
|
2051 {
|
|
2052 botc.pixel = background;
|
|
2053 XQueryColor (dpy, cmap, &botc);
|
|
2054 botc.red = (unsigned short) ((unsigned long) botc.red * 3 / 5);
|
|
2055 botc.green = (unsigned short) ((unsigned long) botc.green * 3 / 5);
|
|
2056 botc.blue = (unsigned short) ((unsigned long) botc.blue * 3 / 5);
|
3094
|
2057 if (x_allocate_nearest_color (dpy, cmap, visual, &botc))
|
428
|
2058 {
|
|
2059 *bottom_shadow = botc.pixel;
|
|
2060 bottom_frobbed = 1;
|
|
2061 }
|
|
2062 }
|
|
2063
|
|
2064 /* If we had to adjust both shadows, then we have to do some
|
|
2065 additional work. */
|
|
2066 if (top_frobbed && bottom_frobbed)
|
|
2067 {
|
|
2068 int top_avg = ((topc.red / 3) + (topc.green / 3) + (topc.blue / 3));
|
|
2069 int bot_avg = ((botc.red / 3) + (botc.green / 3) + (botc.blue / 3));
|
|
2070 if (bot_avg > top_avg)
|
|
2071 {
|
|
2072 Pixel tmp = *top_shadow;
|
|
2073
|
|
2074 *top_shadow = *bottom_shadow;
|
|
2075 *bottom_shadow = tmp;
|
|
2076 }
|
|
2077 else if (topc.pixel == botc.pixel)
|
|
2078 {
|
|
2079 if (botc.pixel == background)
|
|
2080 *top_shadow = core_background;
|
|
2081 else
|
|
2082 *bottom_shadow = background;
|
|
2083 }
|
|
2084 }
|
|
2085 }
|
|
2086
|
|
2087 /****************************************************************************
|
|
2088 x_clear_region
|
|
2089
|
|
2090 Clear the area in the box defined by the given parameters using the
|
|
2091 given face.
|
|
2092 ****************************************************************************/
|
|
2093 static void
|
2286
|
2094 x_clear_region (Lisp_Object UNUSED (locale), struct device* d,
|
|
2095 struct frame* f, face_index UNUSED (findex),
|
428
|
2096 int x, int y,
|
|
2097 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
|
|
2098 Lisp_Object background_pixmap)
|
|
2099 {
|
|
2100 Display *dpy;
|
|
2101 Window x_win;
|
|
2102 GC gc = NULL;
|
|
2103
|
|
2104 dpy = DEVICE_X_DISPLAY (d);
|
|
2105 x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2106
|
|
2107 if (!UNBOUNDP (background_pixmap))
|
|
2108 {
|
|
2109 gc = x_get_gc (d, Qnil, fcolor, bcolor, background_pixmap, Qnil);
|
|
2110 }
|
|
2111
|
|
2112 if (gc)
|
|
2113 XFillRectangle (dpy, x_win, gc, x, y, width, height);
|
|
2114 else
|
|
2115 XClearArea (dpy, x_win, x, y, width, height, False);
|
|
2116 }
|
|
2117
|
|
2118 /*****************************************************************************
|
|
2119 x_output_eol_cursor
|
|
2120
|
|
2121 Draw a cursor at the end of a line. The end-of-line cursor is
|
|
2122 narrower than the normal cursor.
|
|
2123 ****************************************************************************/
|
|
2124 static void
|
|
2125 x_output_eol_cursor (struct window *w, struct display_line *dl, int xpos,
|
|
2126 face_index findex)
|
|
2127 {
|
|
2128 struct frame *f = XFRAME (w->frame);
|
|
2129 struct device *d = XDEVICE (f->device);
|
|
2130 Lisp_Object window;
|
|
2131
|
|
2132 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
2133 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2134 GC gc;
|
|
2135 face_index elt = get_builtin_face_cache_index (w, Vtext_cursor_face);
|
|
2136 struct face_cachel *cursor_cachel = WINDOW_FACE_CACHEL (w, elt);
|
|
2137
|
|
2138 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
2139 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
2140 WINDOW_BUFFER (w));
|
|
2141
|
|
2142 int x = xpos;
|
|
2143 int y = DISPLAY_LINE_YPOS (dl);
|
|
2144 int width = EOL_CURSOR_WIDTH;
|
|
2145 int height = DISPLAY_LINE_HEIGHT (dl);
|
|
2146 int cursor_height, cursor_y;
|
|
2147 int defheight, defascent;
|
|
2148
|
793
|
2149 window = wrap_window (w);
|
428
|
2150 redisplay_clear_region (window, findex, x, y, width, height);
|
|
2151
|
|
2152 if (NILP (w->text_cursor_visible_p))
|
|
2153 return;
|
|
2154
|
|
2155 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
2156
|
|
2157 default_face_font_info (window, &defascent, 0, &defheight, 0, 0);
|
|
2158
|
|
2159 /* make sure the cursor is entirely contained between y and y+height */
|
|
2160 cursor_height = min (defheight, height);
|
|
2161 cursor_y = max (y, min (y + height - cursor_height,
|
|
2162 dl->ypos - defascent));
|
|
2163
|
|
2164 if (focus)
|
|
2165 {
|
|
2166 #ifdef HAVE_XIM
|
|
2167 XIM_SetSpotLocation (f, x - 2 , cursor_y + cursor_height - 2);
|
|
2168 #endif /* HAVE_XIM */
|
|
2169
|
|
2170 if (NILP (bar_cursor_value))
|
|
2171 {
|
|
2172 XFillRectangle (dpy, x_win, gc, x, cursor_y, width, cursor_height);
|
|
2173 }
|
|
2174 else
|
|
2175 {
|
|
2176 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
2177
|
|
2178 gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
2179 make_int (bar_width));
|
|
2180 XDrawLine (dpy, x_win, gc, x + bar_width - 1, cursor_y,
|
|
2181 x + bar_width - 1, cursor_y + cursor_height - 1);
|
|
2182 }
|
|
2183 }
|
|
2184 else if (NILP (bar_cursor_value))
|
|
2185 {
|
|
2186 XDrawRectangle (dpy, x_win, gc, x, cursor_y, width - 1,
|
|
2187 cursor_height - 1);
|
|
2188 }
|
|
2189 }
|
|
2190
|
|
2191 static void
|
|
2192 x_clear_frame_window (Lisp_Object window)
|
|
2193 {
|
|
2194 struct window *w = XWINDOW (window);
|
|
2195
|
|
2196 if (!NILP (w->vchild))
|
|
2197 {
|
|
2198 x_clear_frame_windows (w->vchild);
|
|
2199 return;
|
|
2200 }
|
|
2201
|
|
2202 if (!NILP (w->hchild))
|
|
2203 {
|
|
2204 x_clear_frame_windows (w->hchild);
|
|
2205 return;
|
|
2206 }
|
|
2207
|
440
|
2208 redisplay_clear_to_window_end (w, WINDOW_TEXT_TOP (w),
|
428
|
2209 WINDOW_TEXT_BOTTOM (w));
|
|
2210 }
|
|
2211
|
|
2212 static void
|
|
2213 x_clear_frame_windows (Lisp_Object window)
|
|
2214 {
|
|
2215 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
2216 x_clear_frame_window (window);
|
|
2217 }
|
|
2218
|
|
2219 static void
|
|
2220 x_clear_frame (struct frame *f)
|
|
2221 {
|
|
2222 struct device *d = XDEVICE (f->device);
|
|
2223 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
2224 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2225 int x, y, width, height;
|
|
2226 Lisp_Object frame;
|
|
2227
|
|
2228 x = FRAME_LEFT_BORDER_START (f);
|
|
2229 width = (FRAME_PIXWIDTH (f) - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) -
|
|
2230 FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) -
|
|
2231 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f) -
|
|
2232 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f));
|
|
2233 /* #### This adjustment by 1 should be being done in the macros.
|
|
2234 There is some small differences between when the menubar is on
|
|
2235 and off that we still need to deal with. */
|
|
2236 y = FRAME_TOP_BORDER_START (f) - 1;
|
|
2237 height = (FRAME_PIXHEIGHT (f) - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) -
|
|
2238 FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) -
|
|
2239 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f) -
|
|
2240 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)) + 1;
|
|
2241
|
|
2242 XClearArea (dpy, x_win, x, y, width, height, False);
|
|
2243
|
793
|
2244 frame = wrap_frame (f);
|
428
|
2245
|
|
2246 if (!UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vdefault_face, frame))
|
|
2247 || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vleft_margin_face, frame))
|
|
2248 || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vright_margin_face, frame)))
|
|
2249 {
|
|
2250 x_clear_frame_windows (f->root_window);
|
|
2251 }
|
|
2252
|
1204
|
2253 if (!(check_if_pending_expose_event (d)))
|
|
2254 XFlush (DEVICE_X_DISPLAY (d));
|
428
|
2255 }
|
|
2256
|
|
2257 /* briefly swap the foreground and background colors.
|
|
2258 */
|
|
2259
|
|
2260 static int
|
|
2261 x_flash (struct device *d)
|
|
2262 {
|
|
2263 Display *dpy;
|
|
2264 Window win;
|
|
2265 XGCValues gcv;
|
|
2266 GC gc;
|
|
2267 XColor tmp_fcolor, tmp_bcolor;
|
|
2268 Lisp_Object tmp_pixel, frame;
|
|
2269 struct frame *f = device_selected_frame (d);
|
|
2270 struct window *w = XWINDOW (FRAME_ROOT_WINDOW (f));
|
|
2271 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
442
|
2272 int flash_height;
|
428
|
2273
|
793
|
2274 frame = wrap_frame (f);
|
428
|
2275
|
|
2276 tmp_pixel = FACE_FOREGROUND (Vdefault_face, frame);
|
|
2277 tmp_fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
2278 tmp_pixel = FACE_BACKGROUND (Vdefault_face, frame);
|
|
2279 tmp_bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
2280
|
|
2281 dpy = XtDisplay (shell);
|
|
2282 win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2283 memset (&gcv, ~0, sizeof (XGCValues)); /* initialize all slots to ~0 */
|
|
2284 gcv.foreground = (tmp_fcolor.pixel ^ tmp_bcolor.pixel);
|
|
2285 gcv.function = GXxor;
|
|
2286 gcv.graphics_exposures = False;
|
|
2287 gc = gc_cache_lookup (DEVICE_X_GC_CACHE (XDEVICE (f->device)), &gcv,
|
|
2288 (GCForeground | GCFunction | GCGraphicsExposures));
|
442
|
2289 default_face_height_and_width (frame, &flash_height, 0);
|
|
2290
|
|
2291 /* If window is tall, flash top and bottom line. */
|
|
2292 if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height)
|
|
2293 {
|
|
2294 XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top,
|
|
2295 w->pixel_width, flash_height);
|
|
2296 XFillRectangle (dpy, win, gc, w->pixel_left,
|
|
2297 w->pixel_top + w->pixel_height - flash_height,
|
|
2298 w->pixel_width, flash_height);
|
|
2299 }
|
|
2300 else
|
|
2301 /* If it is short, flash it all. */
|
|
2302 XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top,
|
|
2303 w->pixel_width, w->pixel_height);
|
|
2304
|
428
|
2305 XSync (dpy, False);
|
|
2306
|
|
2307 #ifdef HAVE_SELECT
|
|
2308 {
|
|
2309 int usecs = 100000;
|
|
2310 struct timeval tv;
|
|
2311 tv.tv_sec = usecs / 1000000L;
|
|
2312 tv.tv_usec = usecs % 1000000L;
|
|
2313 /* I'm sure someone is going to complain about this... */
|
|
2314 select (0, 0, 0, 0, &tv);
|
|
2315 }
|
|
2316 #else
|
|
2317 #ifdef HAVE_POLL
|
|
2318 poll (0, 0, 100);
|
|
2319 #else /* !HAVE_POLL */
|
|
2320 bite me
|
|
2321 #endif /* HAVE_POLL */
|
|
2322 #endif /* HAVE_SELECT */
|
|
2323
|
442
|
2324 /* If window is tall, flash top and bottom line. */
|
|
2325 if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height)
|
|
2326 {
|
|
2327 XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top,
|
|
2328 w->pixel_width, flash_height);
|
|
2329 XFillRectangle (dpy, win, gc, w->pixel_left,
|
|
2330 w->pixel_top + w->pixel_height - flash_height,
|
|
2331 w->pixel_width, flash_height);
|
|
2332 }
|
|
2333 else
|
|
2334 /* If it is short, flash it all. */
|
|
2335 XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top,
|
|
2336 w->pixel_width, w->pixel_height);
|
|
2337
|
428
|
2338 XSync (dpy, False);
|
|
2339
|
|
2340 return 1;
|
|
2341 }
|
|
2342
|
|
2343 /* Make audible bell. */
|
|
2344
|
|
2345 static void
|
|
2346 x_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
2347 {
|
|
2348 Display *display = DEVICE_X_DISPLAY (d);
|
|
2349
|
|
2350 if (volume < 0) volume = 0;
|
|
2351 else if (volume > 100) volume = 100;
|
|
2352 if (pitch < 0 && duration < 0)
|
|
2353 {
|
|
2354 XBell (display, (volume * 2) - 100);
|
|
2355 XFlush (display);
|
|
2356 }
|
|
2357 else
|
|
2358 {
|
|
2359 XKeyboardState state;
|
|
2360 XKeyboardControl ctl;
|
|
2361 XSync (display, 0);
|
|
2362 /* #### grab server? */
|
|
2363 XGetKeyboardControl (display, &state);
|
|
2364
|
664
|
2365 ctl.bell_pitch = (pitch >= 0 ? pitch : (int) state.bell_pitch);
|
|
2366 ctl.bell_duration = (duration >= 0 ? duration : (int) state.bell_duration);
|
428
|
2367 XChangeKeyboardControl (display, KBBellPitch|KBBellDuration, &ctl);
|
|
2368
|
|
2369 XBell (display, (volume * 2) - 100);
|
|
2370
|
|
2371 ctl.bell_pitch = state.bell_pitch;
|
|
2372 ctl.bell_duration = state.bell_duration;
|
|
2373 XChangeKeyboardControl (display, KBBellPitch|KBBellDuration, &ctl);
|
|
2374
|
|
2375 /* #### ungrab server? */
|
|
2376 XSync (display, 0);
|
|
2377 }
|
|
2378 }
|
|
2379
|
|
2380
|
|
2381 /************************************************************************/
|
|
2382 /* initialization */
|
|
2383 /************************************************************************/
|
|
2384
|
|
2385 void
|
|
2386 console_type_create_redisplay_x (void)
|
|
2387 {
|
|
2388 /* redisplay methods */
|
|
2389 CONSOLE_HAS_METHOD (x, text_width);
|
|
2390 CONSOLE_HAS_METHOD (x, output_display_block);
|
|
2391 CONSOLE_HAS_METHOD (x, divider_height);
|
|
2392 CONSOLE_HAS_METHOD (x, eol_cursor_width);
|
|
2393 CONSOLE_HAS_METHOD (x, output_vertical_divider);
|
|
2394 CONSOLE_HAS_METHOD (x, clear_region);
|
|
2395 CONSOLE_HAS_METHOD (x, clear_frame);
|
442
|
2396 CONSOLE_HAS_METHOD (x, window_output_begin);
|
|
2397 CONSOLE_HAS_METHOD (x, window_output_end);
|
428
|
2398 CONSOLE_HAS_METHOD (x, flash);
|
|
2399 CONSOLE_HAS_METHOD (x, ring_bell);
|
|
2400 CONSOLE_HAS_METHOD (x, bevel_area);
|
|
2401 CONSOLE_HAS_METHOD (x, output_string);
|
|
2402 CONSOLE_HAS_METHOD (x, output_pixmap);
|
|
2403 }
|