714
|
1 /* GTK output and frame manipulation routines.
|
462
|
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 /* Gtk flavor by William Perry */
|
|
27
|
|
28 /* Lots of work done by Ben Wing for Mule */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "console-gtk.h"
|
|
34 #include "gccache-gtk.h"
|
|
35 #include "glyphs-gtk.h"
|
|
36 #include "objects-gtk.h"
|
|
37
|
|
38 #include "buffer.h"
|
|
39 #include "debug.h"
|
|
40 #include "faces.h"
|
|
41 #include "frame.h"
|
|
42 #include "gutter.h"
|
|
43 #include "redisplay.h"
|
|
44 #include "sysdep.h"
|
|
45 #include "window.h"
|
|
46
|
|
47 #include "sysproc.h" /* for select() */
|
|
48
|
|
49 #ifdef MULE
|
|
50 #include "mule-ccl.h"
|
|
51 #include "file-coding.h" /* for CCL conversion */
|
|
52 #endif
|
|
53
|
|
54 #define CONST const
|
|
55
|
|
56 #define EOL_CURSOR_WIDTH 5
|
|
57
|
714
|
58 static void gtk_output_pixmap (struct window *w,
|
|
59 Lisp_Object image_instance,
|
|
60 struct display_box *db,
|
|
61 struct display_glyph_area *dga,
|
|
62 face_index findex,
|
|
63 int cursor_start,
|
|
64 int cursor_width,
|
|
65 int cursor_height,
|
|
66 int bgpixmap);
|
462
|
67 static void gtk_output_vertical_divider (struct window *w, int clear);
|
|
68 static void gtk_output_blank (struct window *w, struct display_line *dl,
|
|
69 struct rune *rb, int start_pixpos,
|
|
70 int cursor_start, int cursor_width);
|
714
|
71 static void gtk_output_horizontal_line (struct window *w,
|
|
72 struct display_line *dl,
|
|
73 struct rune *rb);
|
462
|
74 static void gtk_redraw_exposed_window (struct window *w, int x, int y,
|
|
75 int width, int height);
|
|
76 static void gtk_redraw_exposed_windows (Lisp_Object window, int x, int y,
|
|
77 int width, int height);
|
|
78 static void gtk_clear_region (Lisp_Object locale, struct device* d, struct frame* f,
|
|
79 face_index findex, int x, int y,
|
|
80 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
|
|
81 Lisp_Object background_pixmap);
|
|
82 static void gtk_output_eol_cursor (struct window *w, struct display_line *dl,
|
|
83 int xpos, face_index findex);
|
|
84 static void gtk_clear_frame (struct frame *f);
|
|
85 static void gtk_clear_frame_windows (Lisp_Object window);
|
|
86 static void gtk_bevel_modeline (struct window *w, struct display_line *dl);
|
|
87
|
|
88 #if 0
|
|
89 static void __describe_gc (GdkGC *);
|
|
90 #endif
|
|
91
|
|
92 struct textual_run
|
|
93 {
|
|
94 Lisp_Object charset;
|
|
95 unsigned char *ptr;
|
|
96 int len;
|
|
97 int dimension;
|
|
98 };
|
|
99
|
|
100 /* Separate out the text in DYN into a series of textual runs of a
|
|
101 particular charset. Also convert the characters as necessary into
|
|
102 the format needed by XDrawImageString(), XDrawImageString16(), et
|
|
103 al. (This means converting to one or two byte format, possibly
|
|
104 tweaking the high bits, and possibly running a CCL program.) You
|
|
105 must pre-allocate the space used and pass it in. (This is done so
|
|
106 you can alloca() the space.) You need to allocate (2 * len) bytes
|
|
107 of TEXT_STORAGE and (len * sizeof (struct textual_run)) bytes of
|
|
108 RUN_STORAGE, where LEN is the length of the dynarr.
|
|
109
|
|
110 Returns the number of runs actually used. */
|
|
111
|
|
112 static int
|
|
113 separate_textual_runs (unsigned char *text_storage,
|
|
114 struct textual_run *run_storage,
|
|
115 CONST Emchar *str, Charcount len)
|
|
116 {
|
|
117 Lisp_Object prev_charset = Qunbound; /* not Qnil because that is a
|
|
118 possible valid charset when
|
|
119 MULE is not defined */
|
|
120 int runs_so_far = 0;
|
|
121 int i;
|
|
122 #ifdef MULE
|
|
123 struct ccl_program char_converter;
|
|
124 int need_ccl_conversion = 0;
|
|
125 #endif
|
|
126
|
|
127 for (i = 0; i < len; i++)
|
|
128 {
|
|
129 Emchar ch = str[i];
|
|
130 Lisp_Object charset;
|
|
131 int byte1, byte2;
|
|
132 int dimension;
|
|
133 int graphic;
|
|
134
|
|
135 BREAKUP_CHAR (ch, charset, byte1, byte2);
|
|
136 dimension = XCHARSET_DIMENSION (charset);
|
|
137 graphic = XCHARSET_GRAPHIC (charset);
|
|
138
|
|
139 if (!EQ (charset, prev_charset))
|
|
140 {
|
|
141 run_storage[runs_so_far].ptr = text_storage;
|
|
142 run_storage[runs_so_far].charset = charset;
|
|
143 run_storage[runs_so_far].dimension = dimension;
|
|
144
|
|
145 if (runs_so_far)
|
|
146 {
|
|
147 run_storage[runs_so_far - 1].len =
|
|
148 text_storage - run_storage[runs_so_far - 1].ptr;
|
|
149 if (run_storage[runs_so_far - 1].dimension == 2)
|
|
150 run_storage[runs_so_far - 1].len >>= 1;
|
|
151 }
|
|
152 runs_so_far++;
|
|
153 prev_charset = charset;
|
|
154 #ifdef MULE
|
|
155 {
|
|
156 Lisp_Object ccl_prog = XCHARSET_CCL_PROGRAM (charset);
|
|
157 need_ccl_conversion = !NILP (ccl_prog);
|
|
158 if (need_ccl_conversion)
|
|
159 setup_ccl_program (&char_converter, ccl_prog);
|
|
160 }
|
|
161 #endif
|
|
162 }
|
|
163
|
|
164 if (graphic == 0)
|
|
165 {
|
|
166 byte1 &= 0x7F;
|
|
167 byte2 &= 0x7F;
|
|
168 }
|
|
169 else if (graphic == 1)
|
|
170 {
|
|
171 byte1 |= 0x80;
|
|
172 byte2 |= 0x80;
|
|
173 }
|
|
174 #ifdef MULE
|
|
175 if (need_ccl_conversion)
|
|
176 {
|
|
177 char_converter.reg[0] = XCHARSET_ID (charset);
|
|
178 char_converter.reg[1] = byte1;
|
|
179 char_converter.reg[2] = byte2;
|
|
180 ccl_driver (&char_converter, 0, 0, 0, 0, CCL_MODE_ENCODING);
|
|
181 byte1 = char_converter.reg[1];
|
|
182 byte2 = char_converter.reg[2];
|
|
183 }
|
|
184 #endif
|
|
185 *text_storage++ = (unsigned char) byte1;
|
|
186 if (dimension == 2)
|
|
187 *text_storage++ = (unsigned char) byte2;
|
|
188 }
|
|
189
|
|
190 if (runs_so_far)
|
|
191 {
|
|
192 run_storage[runs_so_far - 1].len =
|
|
193 text_storage - run_storage[runs_so_far - 1].ptr;
|
|
194 if (run_storage[runs_so_far - 1].dimension == 2)
|
|
195 run_storage[runs_so_far - 1].len >>= 1;
|
|
196 }
|
|
197
|
|
198 return runs_so_far;
|
|
199 }
|
|
200
|
|
201 /****************************************************************************/
|
|
202 /* */
|
|
203 /* Gtk output routines */
|
|
204 /* */
|
|
205 /****************************************************************************/
|
|
206
|
|
207 static int
|
|
208 gtk_text_width_single_run (struct face_cachel *cachel, struct textual_run *run)
|
|
209 {
|
|
210 Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset);
|
|
211 struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst);
|
|
212
|
|
213 if (!fi->proportional_p)
|
|
214 {
|
|
215 return fi->width * run->len;
|
|
216 }
|
|
217 else
|
|
218 {
|
|
219 if (run->dimension == 2)
|
|
220 {
|
|
221 stderr_out ("Measuring wide characters\n");
|
|
222 return gdk_text_width_wc (FONT_INSTANCE_GTK_FONT (fi),
|
|
223 (GdkWChar *) run->ptr, run->len);
|
|
224 }
|
|
225 else
|
|
226 {
|
|
227 return gdk_text_width (FONT_INSTANCE_GTK_FONT (fi),
|
|
228 (char *) run->ptr, run->len);
|
|
229 }
|
|
230 }
|
|
231 }
|
|
232
|
|
233 /*
|
|
234 gtk_text_width
|
|
235
|
|
236 Given a string and a face, return the string's length in pixels when
|
|
237 displayed in the font associated with the face.
|
|
238 */
|
|
239
|
|
240 static int
|
|
241 gtk_text_width (struct frame *f, struct face_cachel *cachel, CONST Emchar *str,
|
|
242 Charcount len)
|
|
243 {
|
|
244 int width_so_far = 0;
|
|
245 unsigned char *text_storage = (unsigned char *) alloca (2 * len);
|
|
246 struct textual_run *runs = alloca_array (struct textual_run, len);
|
|
247 int nruns;
|
|
248 int i;
|
|
249
|
|
250 nruns = separate_textual_runs (text_storage, runs, str, len);
|
|
251
|
|
252 for (i = 0; i < nruns; i++)
|
|
253 width_so_far += gtk_text_width_single_run (cachel, runs + i);
|
|
254
|
|
255 return width_so_far;
|
|
256 }
|
|
257
|
|
258 /*****************************************************************************
|
|
259 gtk_divider_height
|
|
260
|
|
261 Return the height of the horizontal divider. This is a function because
|
|
262 divider_height is a device method.
|
|
263
|
|
264 #### If we add etched horizontal divider lines this will have to get
|
|
265 smarter.
|
|
266 ****************************************************************************/
|
|
267 static int
|
|
268 gtk_divider_height (void)
|
|
269 {
|
|
270 return 2;
|
|
271 }
|
|
272
|
|
273 /*****************************************************************************
|
|
274 gtk_eol_cursor_width
|
|
275
|
|
276 Return the width of the end-of-line cursor. This is a function
|
|
277 because eol_cursor_width is a device method.
|
|
278 ****************************************************************************/
|
|
279 static int
|
|
280 gtk_eol_cursor_width (void)
|
|
281 {
|
|
282 return EOL_CURSOR_WIDTH;
|
|
283 }
|
|
284
|
|
285 /*****************************************************************************
|
|
286 gtk_output_display_block
|
|
287
|
|
288 Given a display line, a block number for that start line, output all
|
|
289 runes between start and end in the specified display block.
|
|
290 ****************************************************************************/
|
|
291 static void
|
|
292 gtk_output_display_block (struct window *w, struct display_line *dl, int block,
|
|
293 int start, int end, int start_pixpos, int cursor_start,
|
|
294 int cursor_width, int cursor_height)
|
|
295 {
|
|
296 struct frame *f = XFRAME (w->frame);
|
|
297 Emchar_dynarr *buf = Dynarr_new (Emchar);
|
|
298 Lisp_Object window;
|
|
299
|
|
300 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
|
|
301 rune_dynarr *rba = db->runes;
|
|
302 struct rune *rb;
|
|
303
|
|
304 int elt = start;
|
|
305 face_index findex;
|
|
306 int xpos, width;
|
|
307 Lisp_Object charset = Qunbound; /* Qnil is a valid charset when
|
|
308 MULE is not defined */
|
|
309
|
793
|
310 window = wrap_window (w);
|
462
|
311 rb = Dynarr_atp (rba, start);
|
|
312
|
|
313 if (!rb)
|
|
314 {
|
|
315 /* Nothing to do so don't do anything. */
|
|
316 return;
|
|
317 }
|
|
318 else
|
|
319 {
|
|
320 findex = rb->findex;
|
|
321 xpos = rb->xpos;
|
|
322 width = 0;
|
|
323 if (rb->type == RUNE_CHAR)
|
|
324 charset = CHAR_CHARSET (rb->object.chr.ch);
|
|
325 }
|
|
326
|
|
327 if (end < 0)
|
|
328 end = Dynarr_length (rba);
|
|
329 Dynarr_reset (buf);
|
|
330
|
|
331 while (elt < end)
|
|
332 {
|
|
333 rb = Dynarr_atp (rba, elt);
|
|
334
|
|
335 if (rb->findex == findex && rb->type == RUNE_CHAR
|
|
336 && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON
|
|
337 && EQ (charset, CHAR_CHARSET (rb->object.chr.ch)))
|
|
338 {
|
|
339 Dynarr_add (buf, rb->object.chr.ch);
|
|
340 width += rb->width;
|
|
341 elt++;
|
|
342 }
|
|
343 else
|
|
344 {
|
|
345 if (Dynarr_length (buf))
|
|
346 {
|
|
347 gtk_output_string (w, dl, buf, xpos, 0, start_pixpos, width,
|
|
348 findex, 0, cursor_start, cursor_width,
|
|
349 cursor_height);
|
|
350 xpos = rb->xpos;
|
|
351 width = 0;
|
|
352 }
|
|
353 Dynarr_reset (buf);
|
|
354 width = 0;
|
|
355
|
|
356 if (rb->type == RUNE_CHAR)
|
|
357 {
|
|
358 findex = rb->findex;
|
|
359 xpos = rb->xpos;
|
|
360 charset = CHAR_CHARSET (rb->object.chr.ch);
|
|
361
|
|
362 if (rb->cursor_type == CURSOR_ON)
|
|
363 {
|
|
364 if (rb->object.chr.ch == '\n')
|
|
365 {
|
|
366 gtk_output_eol_cursor (w, dl, xpos, findex);
|
|
367 }
|
|
368 else
|
|
369 {
|
|
370 Dynarr_add (buf, rb->object.chr.ch);
|
|
371 gtk_output_string (w, dl, buf, xpos, 0, start_pixpos,
|
|
372 rb->width, findex, 1,
|
|
373 cursor_start, cursor_width,
|
|
374 cursor_height);
|
|
375 Dynarr_reset (buf);
|
|
376 }
|
|
377
|
|
378 xpos += rb->width;
|
|
379 elt++;
|
|
380 }
|
|
381 else if (rb->object.chr.ch == '\n')
|
|
382 {
|
|
383 /* Clear in case a cursor was formerly here. */
|
|
384 int height = dl->ascent + dl->descent - dl->clip;
|
|
385
|
|
386 redisplay_clear_region (window, findex, xpos, dl->ypos - dl->ascent,
|
|
387 rb->width, height);
|
|
388 elt++;
|
|
389 }
|
|
390 }
|
|
391 else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE)
|
|
392 {
|
|
393 if (rb->type == RUNE_BLANK)
|
|
394 gtk_output_blank (w, dl, rb, start_pixpos, cursor_start,
|
|
395 cursor_width);
|
|
396 else
|
|
397 {
|
|
398 /* #### Our flagging of when we need to redraw the
|
|
399 modeline shadows sucks. Since RUNE_HLINE is only used
|
|
400 by the modeline at the moment it is a good bet
|
|
401 that if it gets redrawn then we should also
|
|
402 redraw the shadows. This won't be true forever.
|
|
403 We borrow the shadow_thickness_changed flag for
|
|
404 now. */
|
|
405 w->shadow_thickness_changed = 1;
|
714
|
406 gtk_output_horizontal_line (w, dl, rb);
|
462
|
407 }
|
|
408
|
|
409 elt++;
|
|
410 if (elt < end)
|
|
411 {
|
|
412 rb = Dynarr_atp (rba, elt);
|
|
413
|
|
414 findex = rb->findex;
|
|
415 xpos = rb->xpos;
|
|
416 }
|
|
417 }
|
|
418 else if (rb->type == RUNE_DGLYPH)
|
|
419 {
|
|
420 Lisp_Object instance;
|
|
421 struct display_box dbox;
|
|
422 struct display_glyph_area dga;
|
|
423 redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset,
|
|
424 start_pixpos, rb->width,
|
|
425 &dbox, &dga);
|
|
426
|
793
|
427 window = wrap_window (w);
|
462
|
428 instance = glyph_image_instance (rb->object.dglyph.glyph,
|
793
|
429 window, ERROR_ME_DEBUG_WARN, 1);
|
462
|
430 findex = rb->findex;
|
|
431
|
|
432 if (IMAGE_INSTANCEP (instance))
|
|
433 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
434 {
|
|
435 case IMAGE_TEXT:
|
|
436 {
|
|
437 /* #### This is way losing. See the comment in
|
|
438 add_glyph_rune(). */
|
|
439 Lisp_Object string =
|
|
440 XIMAGE_INSTANCE_TEXT_STRING (instance);
|
665
|
441 convert_intbyte_string_into_emchar_dynarr
|
462
|
442 (XSTRING_DATA (string), XSTRING_LENGTH (string), buf);
|
|
443
|
|
444 gtk_output_string (w, dl, buf, xpos,
|
|
445 rb->object.dglyph.xoffset,
|
|
446 start_pixpos, -1, findex,
|
|
447 (rb->cursor_type == CURSOR_ON),
|
|
448 cursor_start, cursor_width,
|
|
449 cursor_height);
|
|
450 Dynarr_reset (buf);
|
|
451 }
|
|
452 break;
|
|
453
|
|
454 case IMAGE_MONO_PIXMAP:
|
|
455 case IMAGE_COLOR_PIXMAP:
|
714
|
456 redisplay_output_pixmap (w, instance, &dbox, &dga,
|
|
457 findex,cursor_start,
|
|
458 cursor_width, cursor_height, 0);
|
462
|
459 break;
|
|
460
|
|
461 case IMAGE_POINTER:
|
|
462 abort ();
|
|
463
|
|
464 case IMAGE_WIDGET:
|
|
465 if (EQ (XIMAGE_INSTANCE_WIDGET_TYPE (instance),
|
|
466 Qlayout))
|
|
467 {
|
|
468 redisplay_output_layout (window, instance, &dbox,
|
|
469 &dga, findex,
|
|
470 cursor_start, cursor_width,
|
|
471 cursor_height);
|
|
472 break;
|
|
473 }
|
|
474
|
|
475 case IMAGE_SUBWINDOW:
|
|
476 redisplay_output_subwindow (w, instance, &dbox, &dga,
|
|
477 findex, cursor_start,
|
|
478 cursor_width, cursor_height);
|
|
479 break;
|
|
480
|
|
481 case IMAGE_NOTHING:
|
|
482 /* nothing is as nothing does */
|
|
483 break;
|
|
484
|
|
485 default:
|
|
486 abort ();
|
|
487 }
|
|
488
|
|
489 xpos += rb->width;
|
|
490 elt++;
|
|
491 }
|
|
492 else
|
|
493 abort ();
|
|
494 }
|
|
495 }
|
|
496
|
|
497 if (Dynarr_length (buf))
|
|
498 gtk_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex,
|
|
499 0, cursor_start, cursor_width, cursor_height);
|
|
500
|
|
501 /* #### This is really conditionalized well for optimized
|
|
502 performance. */
|
|
503 if (dl->modeline
|
|
504 && !EQ (Qzero, w->modeline_shadow_thickness)
|
|
505 && (f->clear
|
|
506 || f->windows_structure_changed
|
|
507 || w->shadow_thickness_changed))
|
|
508 gtk_bevel_modeline (w, dl);
|
|
509
|
|
510 Dynarr_free (buf);
|
|
511 }
|
|
512
|
|
513 /*****************************************************************************
|
|
514 gtk_bevel_modeline
|
|
515
|
|
516 Draw a 3d border around the modeline on window W.
|
|
517 ****************************************************************************/
|
|
518 static void
|
|
519 gtk_bevel_modeline (struct window *w, struct display_line *dl)
|
|
520 {
|
|
521 struct frame *f = XFRAME (w->frame);
|
|
522 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w);
|
|
523 int x,y, width, height;
|
|
524
|
|
525 x = WINDOW_MODELINE_LEFT (w);
|
|
526 width = WINDOW_MODELINE_RIGHT (w) - x;
|
|
527 y = dl->ypos - dl->ascent - shadow_thickness;
|
|
528 height = dl->ascent + dl->descent + 2 * shadow_thickness;
|
|
529
|
|
530 gtk_output_shadows (f, x, y, width, height, shadow_thickness);
|
|
531 }
|
|
532
|
|
533 /*****************************************************************************
|
|
534 gtk_get_gc
|
|
535
|
|
536 Given a number of parameters return a GC with those properties.
|
|
537 ****************************************************************************/
|
|
538 GdkGC *
|
|
539 gtk_get_gc (struct device *d, Lisp_Object font, Lisp_Object fg, Lisp_Object bg,
|
|
540 Lisp_Object bg_pmap, Lisp_Object lwidth)
|
|
541 {
|
|
542 GdkGCValues gcv;
|
|
543 unsigned long mask;
|
|
544
|
|
545 memset (&gcv, ~0, sizeof (gcv));
|
|
546 gcv.graphics_exposures = FALSE;
|
|
547 /* Make absolutely sure that we don't pick up a clipping region in
|
|
548 the GC returned by this function. */
|
|
549 gcv.clip_mask = 0;
|
|
550 gcv.clip_x_origin = 0;
|
|
551 gcv.clip_y_origin = 0;
|
|
552 gcv.fill = GDK_SOLID;
|
|
553 mask = GDK_GC_EXPOSURES | GDK_GC_CLIP_MASK | GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN;
|
|
554 mask |= GDK_GC_FILL;
|
|
555
|
|
556 if (!NILP (font))
|
|
557 {
|
|
558 gcv.font = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (font));
|
|
559 mask |= GDK_GC_FONT;
|
|
560 }
|
|
561
|
|
562 /* evil kludge! */
|
|
563 if (!NILP (fg) && !COLOR_INSTANCEP (fg) && !INTP (fg))
|
|
564 {
|
|
565 /* #### I fixed once case where this was getting it. It was a
|
|
566 bad macro expansion (compiler bug). */
|
|
567 fprintf (stderr, "Help! gtk_get_gc got a bogus fg value! fg = ");
|
|
568 debug_print (fg);
|
|
569 fg = Qnil;
|
|
570 }
|
|
571
|
|
572 if (!NILP (fg))
|
|
573 {
|
|
574 if (COLOR_INSTANCEP (fg))
|
|
575 gcv.foreground = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (fg));
|
|
576 else
|
|
577 gcv.foreground.pixel = XINT (fg);
|
|
578 mask |= GDK_GC_FOREGROUND;
|
|
579 }
|
|
580
|
|
581 if (!NILP (bg))
|
|
582 {
|
|
583 if (COLOR_INSTANCEP (bg))
|
|
584 gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (bg));
|
|
585 else
|
|
586 gcv.background.pixel = XINT (fg);
|
|
587 mask |= GDK_GC_BACKGROUND;
|
|
588 }
|
|
589
|
|
590 if (IMAGE_INSTANCEP (bg_pmap)
|
|
591 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
592 {
|
|
593 if (XIMAGE_INSTANCE_PIXMAP_DEPTH (bg_pmap) == 0)
|
|
594 {
|
|
595 gcv.fill = GDK_OPAQUE_STIPPLED;
|
|
596 gcv.stipple = XIMAGE_INSTANCE_GTK_PIXMAP (bg_pmap);
|
|
597 mask |= (GDK_GC_STIPPLE | GDK_GC_FILL);
|
|
598 }
|
|
599 else
|
|
600 {
|
|
601 gcv.fill = GDK_TILED;
|
|
602 gcv.tile = XIMAGE_INSTANCE_GTK_PIXMAP (bg_pmap);
|
|
603 mask |= (GDK_GC_TILE | GDK_GC_FILL);
|
|
604 }
|
|
605 }
|
|
606
|
|
607 if (!NILP (lwidth))
|
|
608 {
|
|
609 gcv.line_width = XINT (lwidth);
|
|
610 mask |= GDK_GC_LINE_WIDTH;
|
|
611 }
|
|
612
|
|
613 return gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, mask);
|
|
614 }
|
|
615
|
|
616 /*****************************************************************************
|
|
617 gtk_output_string
|
|
618
|
|
619 Given a string and a starting position, output that string in the
|
|
620 given face. If cursor is true, draw a cursor around the string.
|
|
621 Correctly handles multiple charsets in the string.
|
|
622
|
|
623 The meaning of the parameters is something like this:
|
|
624
|
|
625 W Window that the text is to be displayed in.
|
|
626 DL Display line that this text is on. The values in the
|
|
627 structure are used to determine the vertical position and
|
|
628 clipping range of the text.
|
|
629 BUF Dynamic array of Emchars specifying what is actually to be
|
|
630 drawn.
|
|
631 XPOS X position in pixels where the text should start being drawn.
|
|
632 XOFFSET Number of pixels to be chopped off the left side of the
|
|
633 text. The effect is as if the text were shifted to the
|
|
634 left this many pixels and clipped at XPOS.
|
|
635 CLIP_START Clip everything left of this X position.
|
|
636 WIDTH Clip everything right of XPOS + WIDTH.
|
|
637 FINDEX Index for the face cache element describing how to display
|
|
638 the text.
|
|
639 CURSOR #### I don't understand this. There's something
|
|
640 strange and overcomplexified with this variable.
|
|
641 Chuck, explain please?
|
|
642 CURSOR_START Starting X position of cursor.
|
|
643 CURSOR_WIDTH Width of cursor in pixels.
|
|
644 CURSOR_HEIGHT Height of cursor in pixels.
|
|
645
|
|
646 Starting Y position of cursor is the top of the text line.
|
|
647 The cursor is drawn sometimes whether or not CURSOR is set. ???
|
|
648 ****************************************************************************/
|
714
|
649 static
|
|
650 void gdk_draw_text_image (GdkDrawable *drawable,
|
|
651 GdkFont *font,
|
|
652 GdkGC *gc,
|
|
653 gint x,
|
|
654 gint y,
|
|
655 const gchar *text,
|
|
656 gint text_length);
|
462
|
657
|
|
658 void
|
|
659 gtk_output_string (struct window *w, struct display_line *dl,
|
|
660 Emchar_dynarr *buf, int xpos, int xoffset, int clip_start,
|
|
661 int width, face_index findex, int cursor,
|
|
662 int cursor_start, int cursor_width, int cursor_height)
|
|
663 {
|
|
664 /* General variables */
|
|
665 struct frame *f = XFRAME (w->frame);
|
|
666 struct device *d = XDEVICE (f->device);
|
|
667 Lisp_Object device;
|
|
668 Lisp_Object window;
|
|
669 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
670
|
|
671 int clip_end;
|
|
672
|
|
673 /* Cursor-related variables */
|
|
674 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
675 int cursor_clip;
|
|
676 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
677 WINDOW_BUFFER (w));
|
|
678 struct face_cachel *cursor_cachel = 0;
|
|
679
|
|
680 /* Text-related variables */
|
|
681 Lisp_Object bg_pmap;
|
|
682 GdkGC *bgc, *gc;
|
|
683 int height;
|
|
684 int len = Dynarr_length (buf);
|
|
685 unsigned char *text_storage = (unsigned char *) alloca (2 * len);
|
|
686 struct textual_run *runs = alloca_array (struct textual_run, len);
|
|
687 int nruns;
|
|
688 int i;
|
|
689 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex);
|
|
690
|
793
|
691 device = wrap_device (d);
|
|
692 window = wrap_window (w);
|
462
|
693
|
|
694 if (width < 0)
|
|
695 width = gtk_text_width (f, cachel, Dynarr_atp (buf, 0), Dynarr_length (buf));
|
|
696 height = dl->ascent + dl->descent - dl->clip;
|
|
697
|
|
698 /* Regularize the variables passed in. */
|
|
699
|
|
700 if (clip_start < xpos)
|
|
701 clip_start = xpos;
|
|
702 clip_end = xpos + width;
|
|
703 if (clip_start >= clip_end)
|
|
704 /* It's all clipped out. */
|
|
705 return;
|
|
706
|
|
707 xpos -= xoffset;
|
|
708
|
|
709 nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0),
|
|
710 Dynarr_length (buf));
|
|
711
|
|
712 cursor_clip = (cursor_start >= clip_start &&
|
|
713 cursor_start < clip_end);
|
|
714
|
|
715 /* This cursor code is really a mess. */
|
|
716 if (!NILP (w->text_cursor_visible_p)
|
|
717 && (cursor
|
|
718 || cursor_clip
|
|
719 || (cursor_width
|
|
720 && (cursor_start + cursor_width >= clip_start)
|
|
721 && !NILP (bar_cursor_value))))
|
|
722 {
|
|
723 /* These have to be in separate statements in order to avoid a
|
|
724 compiler bug. */
|
|
725 face_index sucks = get_builtin_face_cache_index (w, Vtext_cursor_face);
|
|
726 cursor_cachel = WINDOW_FACE_CACHEL (w, sucks);
|
|
727
|
|
728 /* We have to reset this since any call to WINDOW_FACE_CACHEL
|
|
729 may cause the cache to resize and any pointers to it to
|
|
730 become invalid. */
|
|
731 cachel = WINDOW_FACE_CACHEL (w, findex);
|
|
732 }
|
|
733
|
|
734 bg_pmap = cachel->background_pixmap;
|
|
735 if (!IMAGE_INSTANCEP (bg_pmap)
|
|
736 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
737 bg_pmap = Qnil;
|
|
738
|
|
739 if ((cursor && focus && NILP (bar_cursor_value)
|
|
740 && !NILP (w->text_cursor_visible_p)) || NILP (bg_pmap))
|
|
741 bgc = 0;
|
|
742 else
|
|
743 bgc = gtk_get_gc (d, Qnil, cachel->foreground, cachel->background,
|
|
744 bg_pmap, Qnil);
|
|
745
|
|
746 if (bgc)
|
|
747 gdk_draw_rectangle (GDK_DRAWABLE (x_win), bgc, TRUE, clip_start,
|
|
748 dl->ypos - dl->ascent, clip_end - clip_start,
|
|
749 height);
|
|
750
|
|
751 for (i = 0; i < nruns; i++)
|
|
752 {
|
|
753 Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset);
|
|
754 struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font);
|
|
755 GdkFont *gdk_font = FONT_INSTANCE_GTK_FONT (fi);
|
|
756 int this_width;
|
|
757 int need_clipping;
|
|
758
|
|
759 if (EQ (font, Vthe_null_font_instance))
|
|
760 continue;
|
|
761
|
|
762 this_width = gtk_text_width_single_run (cachel, runs + i);
|
|
763 need_clipping = (dl->clip || clip_start > xpos ||
|
|
764 clip_end < xpos + this_width);
|
|
765
|
|
766 /* XDrawImageString only clears the area equal to the height of
|
|
767 the given font. It is possible that a font is being displayed
|
|
768 on a line taller than it is, so this would cause us to fail to
|
|
769 clear some areas. */
|
|
770 if ((int) fi->height < (int) (height + dl->clip))
|
|
771 {
|
|
772 int clear_start = max (xpos, clip_start);
|
|
773 int clear_end = min (xpos + this_width, clip_end);
|
|
774
|
|
775 if (cursor)
|
|
776 {
|
|
777 int ypos1_line, ypos1_string, ypos2_line, ypos2_string;
|
|
778
|
|
779 ypos1_string = dl->ypos - fi->ascent;
|
|
780 ypos2_string = dl->ypos + fi->descent;
|
|
781 ypos1_line = dl->ypos - dl->ascent;
|
|
782 ypos2_line = dl->ypos + dl->descent - dl->clip;
|
|
783
|
|
784 /* Make sure we don't clear below the real bottom of the
|
|
785 line. */
|
|
786 if (ypos1_string > ypos2_line)
|
|
787 ypos1_string = ypos2_line;
|
|
788 if (ypos2_string > ypos2_line)
|
|
789 ypos2_string = ypos2_line;
|
|
790
|
|
791 if (ypos1_line < ypos1_string)
|
|
792 {
|
|
793 redisplay_clear_region (window, findex, clear_start, ypos1_line,
|
|
794 clear_end - clear_start,
|
|
795 ypos1_string - ypos1_line);
|
|
796 }
|
|
797
|
|
798 if (ypos2_line > ypos2_string)
|
|
799 {
|
|
800 redisplay_clear_region (window, findex, clear_start, ypos2_string,
|
|
801 clear_end - clear_start,
|
|
802 ypos2_line - ypos2_string);
|
|
803 }
|
|
804 }
|
|
805 else
|
|
806 {
|
|
807 redisplay_clear_region (window, findex, clear_start,
|
|
808 dl->ypos - dl->ascent, clear_end - clear_start,
|
|
809 height);
|
|
810 }
|
|
811 }
|
|
812
|
|
813 if (cursor && cursor_cachel && focus && NILP (bar_cursor_value))
|
|
814 {
|
|
815 gc = gtk_get_gc (d, font, cursor_cachel->foreground,
|
|
816 cursor_cachel->background, Qnil, Qnil);
|
|
817 }
|
|
818 else
|
|
819 {
|
|
820 gc = gtk_get_gc (d, font, cachel->foreground, cachel->background,
|
|
821 Qnil, Qnil);
|
|
822 }
|
|
823
|
|
824 if (need_clipping)
|
|
825 {
|
|
826 GdkRectangle clip_box;
|
|
827
|
|
828 clip_box.x = 0;
|
|
829 clip_box.y = 0;
|
|
830 clip_box.width = clip_end - clip_start;
|
|
831 clip_box.height = height;
|
|
832
|
|
833 gdk_gc_set_clip_rectangle (gc, &clip_box);
|
|
834 gdk_gc_set_clip_origin (gc, clip_start, dl->ypos - dl->ascent);
|
|
835 }
|
|
836
|
|
837 /* The X specific called different functions (XDraw*String
|
|
838 vs. XDraw*String16), but apparently gdk_draw_text takes care
|
|
839 of that for us.
|
|
840
|
|
841 BUT, gdk_draw_text also does too much, by dividing the length
|
|
842 by 2. So we fake them out my multiplying the length by the
|
|
843 dimension of the text. This will do the right thing for
|
|
844 single-dimension runs as well of course.
|
|
845 */
|
|
846 (bgc ? gdk_draw_text : gdk_draw_text_image) (GDK_DRAWABLE (x_win), gdk_font, gc, xpos,
|
|
847 dl->ypos, (char *) runs[i].ptr,
|
|
848 runs[i].len * runs[i].dimension);
|
|
849
|
|
850 /* We draw underlines in the same color as the text. */
|
|
851 if (cachel->underline)
|
|
852 {
|
|
853 unsigned long upos, uthick;
|
|
854
|
|
855 /* Cannot get at font properties in Gtk, so we resort to
|
|
856 guessing */
|
|
857 upos = dl->descent / 2;
|
|
858 uthick = 1;
|
|
859
|
778
|
860 if ((dl->ypos + upos) < (dl->ypos + dl->descent - dl->clip))
|
462
|
861 {
|
|
862 if (dl->ypos + upos + uthick > dl->ypos + dl->descent - dl->clip)
|
|
863 uthick = dl->descent - dl->clip - upos;
|
|
864
|
|
865 if (uthick == 1)
|
|
866 {
|
|
867 gdk_draw_line (GDK_DRAWABLE (x_win), gc, xpos, dl->ypos + upos,
|
|
868 xpos + this_width, dl->ypos + upos);
|
|
869 }
|
|
870 else if (uthick > 1)
|
|
871 {
|
|
872 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, xpos,
|
|
873 dl->ypos + upos, this_width, uthick);
|
|
874 }
|
|
875 }
|
|
876 }
|
|
877
|
|
878 if (cachel->strikethru) {
|
|
879 unsigned long ascent,descent,upos, uthick;
|
|
880 GdkFont *gfont = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (font));
|
|
881
|
|
882 /* Cannot get at font properties in Gtk, so we resort to
|
|
883 guessing */
|
|
884
|
|
885 ascent = gfont->ascent;
|
|
886 descent = gfont->descent;
|
|
887 uthick = 1;
|
|
888
|
|
889 upos = ascent - ((ascent + descent) / 2) + 1;
|
|
890
|
|
891 /* Generally, upos will be positive (above the baseline),so subtract */
|
|
892 if (dl->ypos - upos < dl->ypos + dl->descent - dl->clip)
|
|
893 {
|
|
894 if (dl->ypos - upos + uthick > dl->ypos + dl->descent - dl->clip)
|
|
895 uthick = dl->descent - dl->clip + upos;
|
|
896
|
|
897 if (uthick == 1)
|
|
898 {
|
|
899 gdk_draw_line (GDK_DRAWABLE (x_win), gc, xpos, dl->ypos - upos,
|
|
900 xpos + this_width, dl->ypos - upos);
|
|
901 }
|
|
902 else if (uthick > 1)
|
|
903 {
|
|
904 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, xpos, dl->ypos + upos,
|
|
905 this_width, uthick);
|
|
906 }
|
|
907 }
|
|
908 }
|
|
909
|
|
910 /* Restore the GC */
|
|
911 if (need_clipping)
|
|
912 {
|
|
913 gdk_gc_set_clip_rectangle (gc, NULL);
|
|
914 gdk_gc_set_clip_origin (gc, 0, 0);
|
|
915 }
|
|
916
|
|
917 /* If we are actually superimposing the cursor then redraw with just
|
|
918 the appropriate section highlighted. */
|
|
919 if (cursor_clip && !cursor && focus && cursor_cachel)
|
|
920 {
|
|
921 GdkGC *cgc;
|
|
922 GdkRectangle clip_box;
|
|
923
|
|
924 cgc = gtk_get_gc (d, font, cursor_cachel->foreground,
|
|
925 cursor_cachel->background, Qnil, Qnil);
|
|
926
|
|
927 clip_box.x = 0;
|
|
928 clip_box.y = 0;
|
|
929 clip_box.width = cursor_width;
|
|
930 clip_box.height = height;
|
|
931
|
|
932 gdk_gc_set_clip_rectangle (cgc, &clip_box);
|
|
933 gdk_gc_set_clip_origin (cgc, cursor_start, dl->ypos - dl->ascent);
|
|
934
|
|
935 /* The X specific called different functions (XDraw*String
|
|
936 vs. XDraw*String16), but apparently gdk_draw_text takes care
|
|
937 of that for us.
|
|
938
|
|
939 BUT, gdk_draw_text also does too much, by dividing the
|
|
940 length by 2. So we fake them out my multiplying the
|
|
941 length by the dimension of the text. This will do the
|
|
942 right thing for single-dimension runs as well of course.
|
|
943 */
|
|
944 gdk_draw_text_image (GDK_DRAWABLE (x_win), gdk_font, cgc, xpos,
|
|
945 dl->ypos, (char *) runs[i].ptr,
|
|
946 runs[i].len * runs[i].dimension);
|
|
947
|
|
948 gdk_gc_set_clip_rectangle (cgc, NULL);
|
|
949 gdk_gc_set_clip_origin (cgc, 0, 0);
|
|
950 }
|
|
951
|
|
952 xpos += this_width;
|
|
953 }
|
|
954
|
|
955 /* Draw the non-focus box or bar-cursor as needed. */
|
|
956 /* Can't this logic be simplified? */
|
|
957 if (cursor_cachel
|
|
958 && ((cursor && !focus && NILP (bar_cursor_value))
|
|
959 || (cursor_width
|
|
960 && (cursor_start + cursor_width >= clip_start)
|
|
961 && !NILP (bar_cursor_value))))
|
|
962 {
|
|
963 int tmp_height, tmp_y;
|
|
964 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
965 int need_clipping = (cursor_start < clip_start
|
|
966 || clip_end < cursor_start + cursor_width);
|
|
967
|
|
968 /* #### This value is correct (as far as I know) because
|
|
969 all of the times we need to draw this cursor, we will
|
|
970 be called with exactly one character, so we know we
|
|
971 can always use runs[0].
|
|
972
|
|
973 This is bogus as all hell, however. The cursor handling in
|
|
974 this function is way bogus and desperately needs to be
|
|
975 cleaned up. (In particular, the drawing of the cursor should
|
|
976 really really be separated out of this function. This may be
|
|
977 a bit tricky now because this function itself does way too
|
|
978 much stuff, a lot of which needs to be moved into
|
|
979 redisplay.c) This is the only way to be able to easily add
|
|
980 new cursor types or (e.g.) make the bar cursor be able to
|
|
981 span two characters instead of overlaying just one. */
|
|
982 int bogusly_obtained_ascent_value =
|
|
983 XFONT_INSTANCE (FACE_CACHEL_FONT (cachel, runs[0].charset))->ascent;
|
|
984
|
|
985 if (!NILP (bar_cursor_value))
|
|
986 {
|
|
987 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
988 make_int (bar_width));
|
|
989 }
|
|
990 else
|
|
991 {
|
|
992 gc = gtk_get_gc (d, Qnil, cursor_cachel->background,
|
|
993 Qnil, Qnil, Qnil);
|
|
994 }
|
|
995
|
|
996 tmp_y = dl->ypos - bogusly_obtained_ascent_value;
|
|
997 tmp_height = cursor_height;
|
|
998 if (tmp_y + tmp_height > (int) (dl->ypos - dl->ascent + height))
|
|
999 {
|
|
1000 tmp_y = dl->ypos - dl->ascent + height - tmp_height;
|
|
1001 if (tmp_y < (int) (dl->ypos - dl->ascent))
|
|
1002 tmp_y = dl->ypos - dl->ascent;
|
|
1003 tmp_height = dl->ypos - dl->ascent + height - tmp_y;
|
|
1004 }
|
|
1005
|
|
1006 if (need_clipping)
|
|
1007 {
|
|
1008 GdkRectangle clip_box;
|
|
1009 clip_box.x = 0;
|
|
1010 clip_box.y = 0;
|
|
1011 clip_box.width = clip_end - clip_start;
|
|
1012 clip_box.height = tmp_height;
|
|
1013
|
|
1014 gdk_gc_set_clip_rectangle (gc, &clip_box);
|
|
1015 gdk_gc_set_clip_origin (gc, clip_start, tmp_y);
|
|
1016 }
|
|
1017
|
|
1018 if (!focus && NILP (bar_cursor_value))
|
|
1019 {
|
|
1020 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE,
|
|
1021 cursor_start, tmp_y,
|
|
1022 cursor_width - 1, tmp_height - 1);
|
|
1023 }
|
|
1024 else if (focus && !NILP (bar_cursor_value))
|
|
1025 {
|
|
1026 gdk_draw_line (GDK_DRAWABLE (x_win), gc,
|
|
1027 cursor_start + bar_width - 1, tmp_y,
|
|
1028 cursor_start + bar_width - 1, tmp_y + tmp_height - 1);
|
|
1029 }
|
|
1030
|
|
1031 /* Restore the GC */
|
|
1032 if (need_clipping)
|
|
1033 {
|
|
1034 gdk_gc_set_clip_rectangle (gc, NULL);
|
|
1035 gdk_gc_set_clip_origin (gc, 0, 0);
|
|
1036 }
|
|
1037 }
|
|
1038 }
|
|
1039
|
|
1040 static void
|
|
1041 our_draw_bitmap (GdkDrawable *drawable,
|
|
1042 GdkGC *gc,
|
|
1043 GdkPixmap *src,
|
|
1044 gint xsrc,
|
|
1045 gint ysrc,
|
|
1046 gint xdest,
|
|
1047 gint ydest,
|
|
1048 gint width,
|
|
1049 gint height);
|
|
1050
|
714
|
1051 static void
|
462
|
1052 gtk_output_gdk_pixmap (struct frame *f, struct Lisp_Image_Instance *p, int x,
|
714
|
1053 int y, int xoffset, int yoffset,
|
|
1054 int width, int height,
|
462
|
1055 GdkColor *fg, GdkColor *bg, GdkGC *override_gc)
|
|
1056 {
|
|
1057 struct device *d = XDEVICE (f->device);
|
|
1058 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1059
|
|
1060 GdkGC *gc;
|
|
1061 GdkGCValues gcv;
|
|
1062 unsigned long pixmap_mask;
|
|
1063
|
|
1064 if (!override_gc)
|
|
1065 {
|
|
1066 memset (&gcv, ~0, sizeof (gcv));
|
|
1067 gcv.graphics_exposures = FALSE;
|
|
1068 gcv.foreground = *fg;
|
|
1069 gcv.background = *bg;
|
|
1070 pixmap_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_EXPOSURES;
|
|
1071
|
|
1072 if (IMAGE_INSTANCE_GTK_MASK (p))
|
|
1073 {
|
|
1074 gcv.function = GDK_COPY;
|
|
1075 gcv.clip_mask = IMAGE_INSTANCE_GTK_MASK (p);
|
714
|
1076 gcv.clip_x_origin = x - xoffset;
|
|
1077 gcv.clip_y_origin = y - yoffset;
|
462
|
1078 pixmap_mask |= (GDK_GC_FUNCTION | GDK_GC_CLIP_MASK | GDK_GC_CLIP_X_ORIGIN |
|
|
1079 GDK_GC_CLIP_Y_ORIGIN);
|
|
1080 /* Can't set a clip rectangle below because we already have a mask.
|
|
1081 We could conceivably create a new clipmask by zeroing out
|
|
1082 everything outside the clip region. Is it worth it?
|
|
1083 Is it possible to get an equivalent effect by changing the
|
|
1084 args to XCopyArea below rather than messing with a clip box?
|
714
|
1085 - dkindred@cs.cmu.edu
|
|
1086 Yes. We don't clip at all now - andy@xemacs.org
|
|
1087 */
|
462
|
1088 }
|
|
1089
|
|
1090 gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, pixmap_mask);
|
|
1091 }
|
|
1092 else
|
|
1093 {
|
|
1094 gc = override_gc;
|
|
1095 /* override_gc might have a mask already--we don't want to nuke it.
|
|
1096 Maybe we can insist that override_gc have no mask, or use
|
|
1097 one of the suggestions above. */
|
|
1098 }
|
|
1099
|
|
1100 if (IMAGE_INSTANCE_PIXMAP_DEPTH (p) > 0)
|
|
1101 {
|
|
1102 gdk_draw_pixmap (GDK_DRAWABLE (x_win), gc,
|
|
1103 IMAGE_INSTANCE_GTK_PIXMAP (p),
|
714
|
1104 xoffset, yoffset, x, y, width, height);
|
462
|
1105 }
|
|
1106 else
|
|
1107 {
|
|
1108 our_draw_bitmap (GDK_DRAWABLE (x_win), gc,
|
|
1109 IMAGE_INSTANCE_GTK_PIXMAP (p),
|
714
|
1110 xoffset, yoffset, x, y, width, height);
|
462
|
1111 }
|
|
1112 }
|
|
1113
|
|
1114 static void
|
714
|
1115 gtk_output_pixmap (struct window *w,
|
|
1116 Lisp_Object image_instance,
|
|
1117 struct display_box *db,
|
|
1118 struct display_glyph_area *dga,
|
|
1119 face_index findex,
|
|
1120 int cursor_start,
|
|
1121 int cursor_width,
|
|
1122 int cursor_height,
|
|
1123 int bg_pixmap)
|
462
|
1124 {
|
|
1125 struct frame *f = XFRAME (w->frame);
|
|
1126 struct device *d = XDEVICE (f->device);
|
|
1127 struct Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
1128 Lisp_Object window;
|
|
1129
|
|
1130 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1131
|
793
|
1132 window = wrap_window (w);
|
462
|
1133
|
|
1134 /* Output the pixmap. */
|
|
1135 {
|
|
1136 Lisp_Object tmp_pixel;
|
|
1137 GdkColor *tmp_bcolor, *tmp_fcolor;
|
|
1138
|
|
1139 tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex);
|
|
1140 tmp_fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1141 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex);
|
|
1142 tmp_bcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1143
|
714
|
1144 gtk_output_gdk_pixmap (f, p, db->xpos, db->ypos,
|
|
1145 dga->xoffset, dga->yoffset,
|
|
1146 dga->width, dga->height,
|
|
1147 tmp_fcolor, tmp_bcolor, NULL);
|
462
|
1148 }
|
|
1149
|
|
1150 /* Draw a cursor over top of the pixmap. */
|
714
|
1151 if (cursor_width && cursor_height && (cursor_start >= db->xpos)
|
462
|
1152 && !NILP (w->text_cursor_visible_p)
|
714
|
1153 && (cursor_start < (db->xpos + dga->width)))
|
462
|
1154 {
|
|
1155 GdkGC *gc;
|
|
1156 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
1157 struct face_cachel *cursor_cachel =
|
|
1158 WINDOW_FACE_CACHEL (w,
|
|
1159 get_builtin_face_cache_index
|
|
1160 (w, Vtext_cursor_face));
|
|
1161
|
|
1162 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
1163
|
714
|
1164 if (cursor_width > db->xpos + dga->width - cursor_start)
|
|
1165 cursor_width = db->xpos + dga->width - cursor_start;
|
462
|
1166
|
|
1167 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, focus ? TRUE : FALSE,
|
714
|
1168 cursor_start, db->ypos, cursor_width,
|
462
|
1169 cursor_height);
|
|
1170 }
|
|
1171 }
|
|
1172
|
|
1173 /*****************************************************************************
|
|
1174 gtk_output_vertical_divider
|
|
1175
|
|
1176 Draw a vertical divider down the right side of the given window.
|
|
1177 ****************************************************************************/
|
|
1178 static void
|
|
1179 gtk_output_vertical_divider (struct window *w, int clear)
|
|
1180 {
|
|
1181 struct frame *f = XFRAME (w->frame);
|
|
1182 struct device *d = XDEVICE (f->device);
|
|
1183 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1184 GdkGC *background_gc;
|
|
1185 Lisp_Object tmp_pixel;
|
|
1186 GdkGCValues gcv;
|
|
1187 unsigned long mask;
|
|
1188 int x, y1, y2, width, shadow_thickness, spacing, line_width;
|
|
1189 face_index div_face = get_builtin_face_cache_index (w, Vvertical_divider_face);
|
|
1190
|
|
1191 width = window_divider_width (w);
|
|
1192 shadow_thickness = XINT (w->vertical_divider_shadow_thickness);
|
|
1193 spacing = XINT (w->vertical_divider_spacing);
|
|
1194 line_width = XINT (w->vertical_divider_line_width);
|
|
1195 x = WINDOW_RIGHT (w) - width;
|
|
1196 y1 = WINDOW_TOP (w);
|
|
1197 y2 = WINDOW_BOTTOM (w);
|
|
1198
|
|
1199 memset (&gcv, ~0, sizeof (gcv));
|
|
1200
|
|
1201 tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, div_face);
|
|
1202
|
|
1203 gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel));
|
|
1204 gcv.foreground = gcv.background;
|
|
1205 gcv.graphics_exposures = FALSE;
|
|
1206 mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_EXPOSURES;
|
|
1207
|
|
1208 background_gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, mask);
|
|
1209
|
|
1210 /* Clear the divider area first. This needs to be done when a
|
|
1211 window split occurs. */
|
|
1212 /* if (clear) */
|
|
1213 gdk_draw_rectangle (GDK_DRAWABLE (x_win), background_gc, TRUE,
|
|
1214 x, y1, width, y2 - y1);
|
|
1215
|
|
1216 #if 0
|
|
1217 /* Draw the divider line. */
|
|
1218 gdk_draw_rectangle (GDK_DRAWABLE (x_win), background_gc, TRUE,
|
|
1219 x + spacing + shadow_thickness, y1,
|
|
1220 line_width, y2 - y1);
|
|
1221 #endif
|
|
1222
|
|
1223 /* Draw the shadows around the divider line */
|
|
1224 gtk_output_shadows (f, x + spacing, y1,
|
|
1225 width - 2 * spacing, y2 - y1,
|
|
1226 shadow_thickness);
|
|
1227 }
|
|
1228
|
|
1229 /*****************************************************************************
|
|
1230 gtk_output_blank
|
|
1231
|
|
1232 Output a blank by clearing the area it covers in the foreground color
|
|
1233 of its face.
|
|
1234 ****************************************************************************/
|
|
1235 static void
|
|
1236 gtk_output_blank (struct window *w, struct display_line *dl, struct rune *rb,
|
|
1237 int start_pixpos, int cursor_start, int cursor_width)
|
|
1238 {
|
|
1239 struct frame *f = XFRAME (w->frame);
|
|
1240 struct device *d = XDEVICE (f->device);
|
|
1241
|
|
1242 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1243 GdkGC *gc;
|
|
1244 struct face_cachel *cursor_cachel =
|
|
1245 WINDOW_FACE_CACHEL (w,
|
|
1246 get_builtin_face_cache_index
|
|
1247 (w, Vtext_cursor_face));
|
|
1248 Lisp_Object bg_pmap;
|
|
1249 Lisp_Object buffer = WINDOW_BUFFER (w);
|
|
1250 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
1251 buffer);
|
|
1252
|
|
1253 int x = rb->xpos;
|
|
1254 int y = dl->ypos - dl->ascent;
|
|
1255 int width = rb->width;
|
|
1256 int height = dl->ascent + dl->descent - dl->clip;
|
|
1257
|
|
1258 if (start_pixpos > x)
|
|
1259 {
|
|
1260 if (start_pixpos >= (x + width))
|
|
1261 return;
|
|
1262 else
|
|
1263 {
|
|
1264 width -= (start_pixpos - x);
|
|
1265 x = start_pixpos;
|
|
1266 }
|
|
1267 }
|
|
1268
|
|
1269 bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex);
|
|
1270 if (!IMAGE_INSTANCEP (bg_pmap)
|
|
1271 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
|
|
1272 bg_pmap = Qnil;
|
|
1273
|
|
1274 if (NILP (bg_pmap))
|
|
1275 gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex),
|
|
1276 Qnil, Qnil, Qnil);
|
|
1277 else
|
|
1278 gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex),
|
|
1279 WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), bg_pmap,
|
|
1280 Qnil);
|
|
1281
|
|
1282 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, y, width, height);
|
|
1283
|
|
1284 /* If this rune is marked as having the cursor, then it is actually
|
|
1285 representing a tab. */
|
|
1286 if (!NILP (w->text_cursor_visible_p)
|
|
1287 && (rb->cursor_type == CURSOR_ON
|
|
1288 || (cursor_width
|
|
1289 && (cursor_start + cursor_width > x)
|
|
1290 && cursor_start < (x + width))))
|
|
1291 {
|
|
1292 int cursor_height, cursor_y;
|
|
1293 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
1294 struct Lisp_Font_Instance *fi;
|
|
1295
|
|
1296 fi = XFONT_INSTANCE (FACE_CACHEL_FONT
|
|
1297 (WINDOW_FACE_CACHEL (w, rb->findex),
|
|
1298 Vcharset_ascii));
|
|
1299
|
|
1300 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
1301
|
|
1302 cursor_y = dl->ypos - fi->ascent;
|
|
1303 cursor_height = fi->height;
|
|
1304 if (cursor_y + cursor_height > y + height)
|
|
1305 cursor_height = y + height - cursor_y;
|
|
1306
|
|
1307 if (focus)
|
|
1308 {
|
|
1309 if (NILP (bar_cursor_value))
|
|
1310 {
|
|
1311 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE,
|
|
1312 cursor_start, cursor_y,
|
|
1313 fi->width, cursor_height);
|
|
1314 }
|
|
1315 else
|
|
1316 {
|
|
1317 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
1318
|
|
1319 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
1320 make_int (bar_width));
|
|
1321 gdk_draw_line (GDK_DRAWABLE (x_win), gc, cursor_start + bar_width - 1,
|
|
1322 cursor_y, cursor_start + bar_width - 1,
|
|
1323 cursor_y + cursor_height - 1);
|
|
1324 }
|
|
1325 }
|
|
1326 else if (NILP (bar_cursor_value))
|
|
1327 {
|
|
1328 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE,
|
|
1329 cursor_start, cursor_y,
|
|
1330 fi->width - 1, cursor_height - 1);
|
|
1331 }
|
|
1332 }
|
|
1333 }
|
|
1334
|
|
1335 /*****************************************************************************
|
714
|
1336 gtk_output_horizontal_line
|
462
|
1337
|
|
1338 Output a horizontal line in the foreground of its face.
|
|
1339 ****************************************************************************/
|
|
1340 static void
|
714
|
1341 gtk_output_horizontal_line (struct window *w,
|
|
1342 struct display_line *dl,
|
|
1343 struct rune *rb)
|
462
|
1344 {
|
|
1345 struct frame *f = XFRAME (w->frame);
|
|
1346 struct device *d = XDEVICE (f->device);
|
|
1347 GtkStyle *style = FRAME_GTK_TEXT_WIDGET (f)->style;
|
|
1348
|
|
1349 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1350 GdkGC *gc;
|
|
1351
|
|
1352 int x = rb->xpos;
|
|
1353 int width = rb->width;
|
|
1354 int height = dl->ascent + dl->descent - dl->clip;
|
|
1355
|
|
1356 int ypos1, ypos2, ypos3, ypos4;
|
|
1357
|
|
1358 ypos1 = dl->ypos - dl->ascent;
|
|
1359 ypos2 = ypos1 + rb->object.hline.yoffset;
|
|
1360 ypos3 = ypos2 + rb->object.hline.thickness;
|
|
1361 ypos4 = dl->ypos + dl->descent - dl->clip;
|
|
1362
|
|
1363 /* First clear the area not covered by the line. */
|
|
1364 if (height - rb->object.hline.thickness > 0)
|
|
1365 {
|
|
1366 gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex),
|
|
1367 Qnil, Qnil, Qnil);
|
|
1368
|
|
1369 if (ypos2 - ypos1 > 0)
|
|
1370 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos1, width, ypos2 - ypos1);
|
|
1371 if (ypos4 - ypos3 > 0)
|
|
1372 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos1, width, ypos2 - ypos1);
|
|
1373 }
|
|
1374
|
|
1375 gtk_paint_hline (style, x_win, GTK_STATE_NORMAL, NULL, FRAME_GTK_TEXT_WIDGET (f),
|
|
1376 "hline", x, x + width, ypos2);
|
|
1377 #if 0
|
|
1378 /* Now draw the line. */
|
|
1379 gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex),
|
|
1380 Qnil, Qnil, Qnil);
|
|
1381
|
|
1382 if (ypos2 < ypos1)
|
|
1383 ypos2 = ypos1;
|
|
1384 if (ypos3 > ypos4)
|
|
1385 ypos3 = ypos4;
|
|
1386
|
|
1387 if (ypos3 - ypos2 > 0)
|
|
1388 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos2, width, ypos3 - ypos2);
|
|
1389 #endif
|
|
1390 }
|
|
1391
|
|
1392 /*****************************************************************************
|
|
1393 gtk_output_shadows
|
|
1394
|
|
1395 Draw a shadow around the given area using the standard theme engine routines.
|
|
1396 ****************************************************************************/
|
|
1397 void
|
|
1398 gtk_output_shadows (struct frame *f, int x, int y, int width, int height,
|
|
1399 int shadow_thickness)
|
|
1400 {
|
|
1401 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1402 GtkStyle *style = FRAME_GTK_TEXT_WIDGET (f)->style;
|
|
1403 GtkShadowType stype = GTK_SHADOW_OUT;
|
|
1404
|
|
1405 if (shadow_thickness < 0)
|
|
1406 {
|
|
1407 stype = GTK_SHADOW_IN;
|
|
1408 }
|
|
1409 else if (shadow_thickness == 0)
|
|
1410 {
|
|
1411 stype = GTK_SHADOW_NONE;
|
|
1412 }
|
|
1413
|
|
1414 /* Do we want to have some magic constants to set
|
|
1415 GTK_SHADOW_ETCHED_IN or GTK_SHADOW_ETCHED_OUT? */
|
|
1416
|
|
1417 gtk_paint_shadow (style, x_win, GTK_STATE_NORMAL, stype, NULL,
|
|
1418 FRAME_GTK_TEXT_WIDGET (f), "modeline",
|
|
1419 x, y, width, height);
|
|
1420 }
|
|
1421
|
|
1422 /*****************************************************************************
|
|
1423 gtk_clear_to_window_end
|
|
1424
|
|
1425 Clear the area between ypos1 and ypos2. Each margin area and the
|
|
1426 text area is handled separately since they may each have their own
|
|
1427 background color.
|
|
1428 ****************************************************************************/
|
|
1429 static void
|
|
1430 gtk_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
1431 {
|
|
1432 int height = ypos2 - ypos1;
|
|
1433
|
|
1434 if (height)
|
|
1435 {
|
|
1436 struct frame *f = XFRAME (w->frame);
|
|
1437 Lisp_Object window;
|
|
1438 int bflag = (window_needs_vertical_divider (w) ? 0 : 1);
|
|
1439 layout_bounds bounds;
|
|
1440
|
|
1441 bounds = calculate_display_line_boundaries (w, bflag);
|
793
|
1442 window = wrap_window (w);
|
462
|
1443
|
|
1444 if (window_is_leftmost (w))
|
|
1445 redisplay_clear_region (window, DEFAULT_INDEX, FRAME_LEFT_BORDER_START (f),
|
|
1446 ypos1, FRAME_BORDER_WIDTH (f), height);
|
|
1447
|
|
1448 if (bounds.left_in - bounds.left_out > 0)
|
|
1449 redisplay_clear_region (window,
|
|
1450 get_builtin_face_cache_index (w, Vleft_margin_face),
|
|
1451 bounds.left_out, ypos1,
|
|
1452 bounds.left_in - bounds.left_out, height);
|
|
1453
|
|
1454 if (bounds.right_in - bounds.left_in > 0)
|
|
1455 redisplay_clear_region (window, DEFAULT_INDEX, bounds.left_in, ypos1,
|
|
1456 bounds.right_in - bounds.left_in, height);
|
|
1457
|
|
1458 if (bounds.right_out - bounds.right_in > 0)
|
|
1459 redisplay_clear_region (window,
|
|
1460 get_builtin_face_cache_index (w, Vright_margin_face),
|
|
1461 bounds.right_in, ypos1,
|
|
1462 bounds.right_out - bounds.right_in, height);
|
|
1463
|
|
1464 if (window_is_rightmost (w))
|
|
1465 redisplay_clear_region (window, DEFAULT_INDEX, FRAME_RIGHT_BORDER_START (f),
|
|
1466 ypos1, FRAME_BORDER_WIDTH (f), height);
|
|
1467 }
|
|
1468 }
|
|
1469
|
|
1470 /*****************************************************************************
|
|
1471 gtk_redraw_exposed_window
|
|
1472
|
|
1473 Given a bounding box for an area that needs to be redrawn, determine
|
|
1474 what parts of what lines are contained within and re-output their
|
|
1475 contents.
|
|
1476 ****************************************************************************/
|
|
1477 static void
|
|
1478 gtk_redraw_exposed_window (struct window *w, int x, int y, int width, int height)
|
|
1479 {
|
|
1480 struct frame *f = XFRAME (w->frame);
|
|
1481 int line;
|
|
1482 int start_x, start_y, end_x, end_y;
|
|
1483 int orig_windows_structure_changed;
|
|
1484
|
|
1485 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
|
|
1486
|
|
1487 if (!NILP (w->vchild))
|
|
1488 {
|
|
1489 gtk_redraw_exposed_windows (w->vchild, x, y, width, height);
|
|
1490 return;
|
|
1491 }
|
|
1492 else if (!NILP (w->hchild))
|
|
1493 {
|
|
1494 gtk_redraw_exposed_windows (w->hchild, x, y, width, height);
|
|
1495 return;
|
|
1496 }
|
|
1497
|
|
1498 /* If the window doesn't intersect the exposed region, we're done here. */
|
|
1499 if (x >= WINDOW_RIGHT (w) || (x + width) <= WINDOW_LEFT (w)
|
|
1500 || y >= WINDOW_BOTTOM (w) || (y + height) <= WINDOW_TOP (w))
|
|
1501 {
|
|
1502 return;
|
|
1503 }
|
|
1504 else
|
|
1505 {
|
|
1506 start_x = max (WINDOW_LEFT (w), x);
|
|
1507 end_x = min (WINDOW_RIGHT (w), (x + width));
|
|
1508 start_y = max (WINDOW_TOP (w), y);
|
|
1509 end_y = min (WINDOW_BOTTOM (w), y + height);
|
|
1510
|
|
1511 /* We do this to make sure that the 3D modelines get redrawn if
|
|
1512 they are in the exposed region. */
|
|
1513 orig_windows_structure_changed = f->windows_structure_changed;
|
|
1514 f->windows_structure_changed = 1;
|
|
1515 }
|
|
1516
|
|
1517 if (window_needs_vertical_divider (w))
|
|
1518 {
|
|
1519 gtk_output_vertical_divider (w, 0);
|
|
1520 }
|
|
1521
|
|
1522 for (line = 0; line < Dynarr_length (cdla); line++)
|
|
1523 {
|
|
1524 struct display_line *cdl = Dynarr_atp (cdla, line);
|
|
1525 int top_y = cdl->ypos - cdl->ascent;
|
|
1526 int bottom_y = cdl->ypos + cdl->descent;
|
|
1527
|
|
1528 if (bottom_y >= start_y)
|
|
1529 {
|
|
1530 if (top_y > end_y)
|
|
1531 {
|
|
1532 if (line == 0)
|
|
1533 continue;
|
|
1534 else
|
|
1535 break;
|
|
1536 }
|
|
1537 else
|
|
1538 {
|
|
1539 output_display_line (w, 0, cdla, line, start_x, end_x);
|
|
1540 }
|
|
1541 }
|
|
1542 }
|
|
1543
|
|
1544 f->windows_structure_changed = orig_windows_structure_changed;
|
|
1545
|
|
1546 /* If there have never been any face cache_elements created, then this
|
|
1547 expose event doesn't actually have anything to do. */
|
|
1548 if (Dynarr_largest (w->face_cachels))
|
|
1549 redisplay_clear_bottom_of_window (w, cdla, start_y, end_y);
|
|
1550 }
|
|
1551
|
|
1552 /*****************************************************************************
|
|
1553 gtk_redraw_exposed_windows
|
|
1554
|
|
1555 For each window beneath the given window in the window hierarchy,
|
|
1556 ensure that it is redrawn if necessary after an Expose event.
|
|
1557 ****************************************************************************/
|
|
1558 static void
|
|
1559 gtk_redraw_exposed_windows (Lisp_Object window, int x, int y, int width,
|
|
1560 int height)
|
|
1561 {
|
|
1562 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
1563 gtk_redraw_exposed_window (XWINDOW (window), x, y, width, height);
|
|
1564 }
|
|
1565
|
|
1566 /*****************************************************************************
|
|
1567 gtk_redraw_exposed_area
|
|
1568
|
|
1569 For each window on the given frame, ensure that any area in the
|
|
1570 Exposed area is redrawn.
|
|
1571 ****************************************************************************/
|
|
1572 void
|
|
1573 gtk_redraw_exposed_area (struct frame *f, int x, int y, int width, int height)
|
|
1574 {
|
|
1575 /* If any window on the frame has had its face cache reset then the
|
|
1576 redisplay structures are effectively invalid. If we attempt to
|
|
1577 use them we'll blow up. We mark the frame as changed to ensure
|
|
1578 that redisplay will do a full update. This probably isn't
|
|
1579 necessary but it can't hurt. */
|
|
1580
|
|
1581 #ifdef HAVE_TOOLBARS
|
|
1582 /* #### We would rather put these off as well but there is currently
|
|
1583 no combination of flags which will force an unchanged toolbar to
|
|
1584 redraw anyhow. */
|
|
1585 MAYBE_FRAMEMETH (f, redraw_exposed_toolbars, (f, x, y, width, height));
|
|
1586 #endif
|
|
1587 redraw_exposed_gutters (f, x, y, width, height);
|
|
1588
|
|
1589 if (!f->window_face_cache_reset)
|
|
1590 {
|
|
1591 gtk_redraw_exposed_windows (f->root_window, x, y, width, height);
|
|
1592 }
|
|
1593 else
|
|
1594 MARK_FRAME_CHANGED (f);
|
|
1595 }
|
|
1596
|
|
1597 /****************************************************************************
|
|
1598 gtk_clear_region
|
|
1599
|
|
1600 Clear the area in the box defined by the given parameters using the
|
|
1601 given face.
|
|
1602 ****************************************************************************/
|
|
1603 static void
|
|
1604 gtk_clear_region (Lisp_Object locale, struct device* d, struct frame* f, face_index findex,
|
|
1605 int x, int y,
|
|
1606 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
|
|
1607 Lisp_Object background_pixmap)
|
|
1608 {
|
|
1609 GdkWindow *x_win;
|
|
1610 GdkGC *gc = NULL;
|
|
1611
|
|
1612 x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1613
|
|
1614 if (!UNBOUNDP (background_pixmap))
|
|
1615 {
|
|
1616 gc = gtk_get_gc (d, Qnil, fcolor, bcolor, background_pixmap, Qnil);
|
|
1617 }
|
|
1618
|
|
1619 if (gc)
|
|
1620 {
|
|
1621 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc,TRUE,
|
|
1622 x, y, width, height);
|
|
1623 }
|
|
1624 else
|
|
1625 {
|
|
1626 gdk_window_clear_area (x_win, x, y, width, height);
|
|
1627 }
|
|
1628 }
|
|
1629
|
|
1630 /*****************************************************************************
|
|
1631 gtk_output_eol_cursor
|
|
1632
|
|
1633 Draw a cursor at the end of a line. The end-of-line cursor is
|
|
1634 narrower than the normal cursor.
|
|
1635 ****************************************************************************/
|
|
1636 static void
|
|
1637 gtk_output_eol_cursor (struct window *w, struct display_line *dl, int xpos,
|
|
1638 face_index findex)
|
|
1639 {
|
|
1640 struct frame *f = XFRAME (w->frame);
|
|
1641 struct device *d = XDEVICE (f->device);
|
|
1642 Lisp_Object window;
|
|
1643
|
|
1644 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1645 GdkGC *gc;
|
|
1646 face_index elt = get_builtin_face_cache_index (w, Vtext_cursor_face);
|
|
1647 struct face_cachel *cursor_cachel = WINDOW_FACE_CACHEL (w, elt);
|
|
1648
|
|
1649 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
|
|
1650 Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor,
|
|
1651 WINDOW_BUFFER (w));
|
|
1652
|
|
1653 int x = xpos;
|
|
1654 int y = dl->ypos - dl->ascent;
|
|
1655 int width = EOL_CURSOR_WIDTH;
|
|
1656 int height = dl->ascent + dl->descent - dl->clip;
|
|
1657 int cursor_height, cursor_y;
|
|
1658 int defheight, defascent;
|
|
1659
|
793
|
1660 window = wrap_window (w);
|
462
|
1661 redisplay_clear_region (window, findex, x, y, width, height);
|
|
1662
|
|
1663 if (NILP (w->text_cursor_visible_p))
|
|
1664 return;
|
|
1665
|
|
1666 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil);
|
|
1667
|
|
1668 default_face_font_info (window, &defascent, 0, &defheight, 0, 0);
|
|
1669
|
|
1670 /* make sure the cursor is entirely contained between y and y+height */
|
|
1671 cursor_height = min (defheight, height);
|
|
1672 cursor_y = max (y, min (y + height - cursor_height,
|
|
1673 dl->ypos - defascent));
|
|
1674
|
|
1675 if (focus)
|
|
1676 {
|
|
1677 if (NILP (bar_cursor_value))
|
|
1678 {
|
|
1679 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, cursor_y, width, cursor_height);
|
|
1680 }
|
|
1681 else
|
|
1682 {
|
|
1683 int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
|
|
1684
|
|
1685 gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil,
|
|
1686 make_int (bar_width));
|
|
1687 gdk_draw_line (GDK_DRAWABLE (x_win), gc, x + bar_width - 1, cursor_y,
|
|
1688 x + bar_width - 1, cursor_y + cursor_height - 1);
|
|
1689 }
|
|
1690 }
|
|
1691 else if (NILP (bar_cursor_value))
|
|
1692 {
|
|
1693 gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE, x, cursor_y, width - 1,
|
|
1694 cursor_height - 1);
|
|
1695 }
|
|
1696 }
|
|
1697
|
|
1698 static void
|
|
1699 gtk_clear_frame_window (Lisp_Object window)
|
|
1700 {
|
|
1701 struct window *w = XWINDOW (window);
|
|
1702
|
|
1703 if (!NILP (w->vchild))
|
|
1704 {
|
|
1705 gtk_clear_frame_windows (w->vchild);
|
|
1706 return;
|
|
1707 }
|
|
1708
|
|
1709 if (!NILP (w->hchild))
|
|
1710 {
|
|
1711 gtk_clear_frame_windows (w->hchild);
|
|
1712 return;
|
|
1713 }
|
|
1714
|
|
1715 gtk_clear_to_window_end (w, WINDOW_TEXT_TOP (w), WINDOW_TEXT_BOTTOM (w));
|
|
1716 }
|
|
1717
|
|
1718 static void
|
|
1719 gtk_clear_frame_windows (Lisp_Object window)
|
|
1720 {
|
|
1721 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
1722 gtk_clear_frame_window (window);
|
|
1723 }
|
|
1724
|
|
1725 static void
|
|
1726 gtk_clear_frame (struct frame *f)
|
|
1727 {
|
|
1728 GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f));
|
|
1729 int x, y, width, height;
|
|
1730 Lisp_Object frame;
|
|
1731
|
|
1732 x = FRAME_LEFT_BORDER_START (f);
|
|
1733 width = (FRAME_PIXWIDTH (f) - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) -
|
|
1734 FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) -
|
|
1735 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f) -
|
|
1736 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f));
|
|
1737 /* #### This adjustment by 1 should be being done in the macros.
|
|
1738 There is some small differences between when the menubar is on
|
|
1739 and off that we still need to deal with. */
|
|
1740 y = FRAME_TOP_BORDER_START (f) - 1;
|
|
1741 height = (FRAME_PIXHEIGHT (f) - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) -
|
|
1742 FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) -
|
|
1743 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f) -
|
|
1744 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)) + 1;
|
|
1745
|
|
1746 gdk_window_clear_area (x_win, x, y, width, height);
|
|
1747
|
793
|
1748 frame = wrap_frame (f);
|
462
|
1749
|
|
1750 if (!UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vdefault_face, frame))
|
|
1751 || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vleft_margin_face, frame))
|
|
1752 || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vright_margin_face, frame)))
|
|
1753 {
|
|
1754 gtk_clear_frame_windows (f->root_window);
|
|
1755 }
|
|
1756 }
|
|
1757
|
|
1758 static int
|
|
1759 gtk_flash (struct device *d)
|
|
1760 {
|
|
1761 GdkGCValues gcv;
|
|
1762 GdkGC *gc;
|
|
1763 GdkColor tmp_fcolor, tmp_bcolor;
|
|
1764 Lisp_Object tmp_pixel, frame;
|
|
1765 struct frame *f = device_selected_frame (d);
|
|
1766 struct window *w = XWINDOW (FRAME_ROOT_WINDOW (f));
|
|
1767
|
793
|
1768 frame = wrap_frame (f);
|
462
|
1769
|
|
1770 tmp_pixel = FACE_FOREGROUND (Vdefault_face, frame);
|
|
1771 tmp_fcolor = * (COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel)));
|
|
1772 tmp_pixel = FACE_BACKGROUND (Vdefault_face, frame);
|
|
1773 tmp_bcolor = * (COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel)));
|
|
1774
|
|
1775 memset (&gcv, ~0, sizeof (gcv)); /* initialize all slots to ~0 */
|
|
1776 gcv.foreground.pixel = (tmp_fcolor.pixel ^ tmp_bcolor.pixel);
|
|
1777 gcv.function = GDK_XOR;
|
|
1778 gcv.graphics_exposures = FALSE;
|
|
1779 gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (XDEVICE (f->device)), &gcv,
|
|
1780 GDK_GC_FOREGROUND | GDK_GC_FUNCTION | GDK_GC_EXPOSURES);
|
|
1781
|
|
1782 gdk_draw_rectangle (GDK_DRAWABLE (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f))),
|
|
1783 gc, TRUE, w->pixel_left, w->pixel_top,
|
|
1784 w->pixel_width, w->pixel_height);
|
|
1785
|
|
1786 gdk_flush ();
|
|
1787
|
|
1788 #ifdef HAVE_SELECT
|
|
1789 {
|
|
1790 int usecs = 100000;
|
|
1791 struct timeval tv;
|
|
1792 tv.tv_sec = usecs / 1000000L;
|
|
1793 tv.tv_usec = usecs % 1000000L;
|
|
1794 /* I'm sure someone is going to complain about this... */
|
|
1795 select (0, 0, 0, 0, &tv);
|
|
1796 }
|
|
1797 #else
|
778
|
1798 #ifdef HAVE_POLL
|
|
1799 poll (0, 0, 100);
|
|
1800 #else
|
462
|
1801 bite me
|
778
|
1802 #endif
|
|
1803 #endif
|
462
|
1804
|
|
1805 gdk_draw_rectangle (GDK_DRAWABLE (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f))),
|
|
1806 gc, TRUE, w->pixel_left, w->pixel_top,
|
|
1807 w->pixel_width, w->pixel_height);
|
|
1808
|
|
1809 gdk_flush ();
|
|
1810
|
|
1811 return 1;
|
|
1812 }
|
|
1813
|
|
1814 static void
|
|
1815 gtk_bevel_area (struct window *w, face_index findex,
|
|
1816 int x, int y, int width, int height,
|
|
1817 int shadow_thickness, int edges, enum edge_style style)
|
|
1818 {
|
|
1819 struct frame *f = XFRAME (w->frame);
|
|
1820
|
|
1821 gtk_output_shadows (f, x, y, width, height, shadow_thickness);
|
|
1822 }
|
|
1823
|
|
1824
|
|
1825
|
|
1826 /* Make audible bell. */
|
|
1827 static void
|
|
1828 gtk_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
1829 {
|
714
|
1830 /* Gdk does not allow us to control the duration / pitch / volume */
|
|
1831 if (volume > 0)
|
|
1832 {
|
|
1833 gdk_beep ();
|
|
1834 }
|
462
|
1835 }
|
|
1836
|
|
1837
|
|
1838 /************************************************************************/
|
|
1839 /* initialization */
|
|
1840 /************************************************************************/
|
|
1841
|
|
1842 void
|
|
1843 console_type_create_redisplay_gtk (void)
|
|
1844 {
|
|
1845 /* redisplay methods */
|
|
1846 CONSOLE_HAS_METHOD (gtk, text_width);
|
|
1847 CONSOLE_HAS_METHOD (gtk, output_display_block);
|
|
1848 CONSOLE_HAS_METHOD (gtk, divider_height);
|
|
1849 CONSOLE_HAS_METHOD (gtk, eol_cursor_width);
|
|
1850 CONSOLE_HAS_METHOD (gtk, output_vertical_divider);
|
|
1851 CONSOLE_HAS_METHOD (gtk, clear_to_window_end);
|
|
1852 CONSOLE_HAS_METHOD (gtk, clear_region);
|
|
1853 CONSOLE_HAS_METHOD (gtk, clear_frame);
|
|
1854 CONSOLE_HAS_METHOD (gtk, flash);
|
|
1855 CONSOLE_HAS_METHOD (gtk, ring_bell);
|
|
1856 CONSOLE_HAS_METHOD (gtk, bevel_area);
|
|
1857 CONSOLE_HAS_METHOD (gtk, output_string);
|
714
|
1858 CONSOLE_HAS_METHOD (gtk, output_pixmap);
|
462
|
1859 }
|
|
1860
|
|
1861 /* This makes me feel incredibly dirty... but there is no other way to
|
|
1862 get this done right other than calling clear_area before every
|
|
1863 single $#!%@ing piece of text, which I do NOT want to do. */
|
|
1864 #define USE_X_SPECIFIC_DRAW_ROUTINES 1
|
|
1865
|
|
1866 #include <gdk/gdkx.h>
|
|
1867
|
714
|
1868 static
|
|
1869 void gdk_draw_text_image (GdkDrawable *drawable,
|
|
1870 GdkFont *font,
|
|
1871 GdkGC *gc,
|
|
1872 gint x,
|
|
1873 gint y,
|
|
1874 const gchar *text,
|
|
1875 gint text_length)
|
462
|
1876 {
|
|
1877 #if !USE_X_SPECIFIC_DRAW_ROUTINES
|
|
1878 int width = gdk_text_measure (font, text, text_length);
|
|
1879 int height = gdk_text_height (font, text, text_length);
|
|
1880
|
|
1881 gdk_draw_rectangle (drawable, gc, TRUE, x, y, width, height);
|
|
1882 gdk_draw_text (drawable, font, gc, x, y, text, text_length);
|
|
1883 #else
|
|
1884 GdkWindowPrivate *drawable_private;
|
|
1885 GdkFontPrivate *font_private;
|
|
1886 GdkGCPrivate *gc_private;
|
|
1887
|
|
1888 g_return_if_fail (drawable != NULL);
|
|
1889 g_return_if_fail (font != NULL);
|
|
1890 g_return_if_fail (gc != NULL);
|
|
1891 g_return_if_fail (text != NULL);
|
|
1892
|
|
1893 drawable_private = (GdkWindowPrivate*) drawable;
|
|
1894 if (drawable_private->destroyed)
|
|
1895 return;
|
|
1896 gc_private = (GdkGCPrivate*) gc;
|
|
1897 font_private = (GdkFontPrivate*) font;
|
|
1898
|
|
1899 if (font->type == GDK_FONT_FONT)
|
|
1900 {
|
|
1901 XFontStruct *xfont = (XFontStruct *) font_private->xfont;
|
|
1902 XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
|
|
1903 if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
|
|
1904 {
|
|
1905 XDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
|
|
1906 gc_private->xgc, x, y, text, text_length);
|
|
1907 }
|
|
1908 else
|
|
1909 {
|
|
1910 XDrawImageString16 (drawable_private->xdisplay, drawable_private->xwindow,
|
|
1911 gc_private->xgc, x, y, (XChar2b *) text, text_length / 2);
|
|
1912 }
|
|
1913 }
|
|
1914 else if (font->type == GDK_FONT_FONTSET)
|
|
1915 {
|
|
1916 XFontSet fontset = (XFontSet) font_private->xfont;
|
|
1917 XmbDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
|
|
1918 fontset, gc_private->xgc, x, y, text, text_length);
|
|
1919 }
|
|
1920 else
|
|
1921 g_error("undefined font type\n");
|
|
1922 #endif
|
|
1923 }
|
|
1924
|
|
1925 static void
|
|
1926 our_draw_bitmap (GdkDrawable *drawable,
|
|
1927 GdkGC *gc,
|
|
1928 GdkPixmap *src,
|
|
1929 gint xsrc,
|
|
1930 gint ysrc,
|
|
1931 gint xdest,
|
|
1932 gint ydest,
|
|
1933 gint width,
|
|
1934 gint height)
|
|
1935 {
|
|
1936 GdkWindowPrivate *drawable_private;
|
|
1937 GdkWindowPrivate *src_private;
|
|
1938 GdkGCPrivate *gc_private;
|
|
1939
|
|
1940 g_return_if_fail (drawable != NULL);
|
|
1941 g_return_if_fail (src != NULL);
|
|
1942 g_return_if_fail (gc != NULL);
|
|
1943
|
|
1944 drawable_private = (GdkWindowPrivate*) drawable;
|
|
1945 src_private = (GdkWindowPrivate*) src;
|
|
1946 if (drawable_private->destroyed || src_private->destroyed)
|
|
1947 return;
|
|
1948 gc_private = (GdkGCPrivate*) gc;
|
|
1949
|
|
1950 if (width == -1)
|
|
1951 width = src_private->width;
|
|
1952 if (height == -1)
|
|
1953 height = src_private->height;
|
|
1954
|
|
1955 XCopyPlane (drawable_private->xdisplay,
|
|
1956 src_private->xwindow,
|
|
1957 drawable_private->xwindow,
|
|
1958 gc_private->xgc,
|
|
1959 xsrc, ysrc,
|
|
1960 width, height,
|
|
1961 xdest, ydest, 1L);
|
|
1962 }
|