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