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