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