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