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