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