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