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