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