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