Mercurial > hg > xemacs-beta
changeset 4882:eab9498ecc0e
merge most of rest of redisplay-x.c and redisplay-gtk.c into redisplay-xlike-inc.c
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-01-18 Ben Wing <ben@xemacs.org>
* redisplay-gtk.c:
* redisplay-gtk.c (gtk_bevel_area):
* redisplay-x.c:
* redisplay-x.c (THIS_IS_X):
* redisplay-xlike-inc.c:
* redisplay-xlike-inc.c (XLIKE_text_width_single_run):
* redisplay-xlike-inc.c (XLIKE_text_width):
* redisplay-xlike-inc.c (XLIKE_output_display_block):
* redisplay-xlike-inc.c (XLIKE_get_gc):
* redisplay-xlike-inc.c (XLIKE_output_string):
* redisplay-xlike-inc.c (XLIKE_OUTPUT_XLIKE_PIXMAP):
* redisplay-xlike-inc.c (XLIKE_output_pixmap):
* redisplay-xlike-inc.c (XLIKE_output_vertical_divider):
* redisplay-xlike-inc.c (XLIKE_output_blank):
* redisplay-xlike-inc.c (XLIKE_output_horizontal_line):
* redisplay-xlike-inc.c (XLIKE_clear_region):
* redisplay-xlike-inc.c (XLIKE_output_eol_cursor):
* redisplay-xlike-inc.c (XLIKE_clear_frame_window):
* redisplay-xlike-inc.c (XLIKE_clear_frame):
* redisplay-xlike-inc.c (XLIKE_flash):
* redisplay-xlike-inc.c (console_type_create_redisplay_XLIKE):
Move lots more code into redisplay-xlike-inc.c. Use macros to
isolate the code that differs among X vs. GTK, to reduce the need
for ifdefs in the middle of the code. Now, redisplay-x.c and
redisplay-gtk.c only contain a few functions whose implementation
is completely different from one to the other, or which are not
present at all in one of them.
GTK code not currently tested, but it has bitrotted somewhat
any. Doing this will help keep it less bitrotty.
* depend: Regenerate.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Mon, 18 Jan 2010 08:44:49 -0600 |
parents | a4322ac49e37 |
children | 65ad2cd9f2ff ea701c23ed84 |
files | src/ChangeLog src/depend src/redisplay-gtk.c src/redisplay-x.c src/redisplay-xlike-inc.c |
diffstat | 5 files changed, 2218 insertions(+), 3237 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Mon Jan 18 06:21:05 2010 -0600 +++ b/src/ChangeLog Mon Jan 18 08:44:49 2010 -0600 @@ -1,3 +1,38 @@ +2010-01-18 Ben Wing <ben@xemacs.org> + + * redisplay-gtk.c: + * redisplay-gtk.c (gtk_bevel_area): + * redisplay-x.c: + * redisplay-x.c (THIS_IS_X): + * redisplay-xlike-inc.c: + * redisplay-xlike-inc.c (XLIKE_text_width_single_run): + * redisplay-xlike-inc.c (XLIKE_text_width): + * redisplay-xlike-inc.c (XLIKE_output_display_block): + * redisplay-xlike-inc.c (XLIKE_get_gc): + * redisplay-xlike-inc.c (XLIKE_output_string): + * redisplay-xlike-inc.c (XLIKE_OUTPUT_XLIKE_PIXMAP): + * redisplay-xlike-inc.c (XLIKE_output_pixmap): + * redisplay-xlike-inc.c (XLIKE_output_vertical_divider): + * redisplay-xlike-inc.c (XLIKE_output_blank): + * redisplay-xlike-inc.c (XLIKE_output_horizontal_line): + * redisplay-xlike-inc.c (XLIKE_clear_region): + * redisplay-xlike-inc.c (XLIKE_output_eol_cursor): + * redisplay-xlike-inc.c (XLIKE_clear_frame_window): + * redisplay-xlike-inc.c (XLIKE_clear_frame): + * redisplay-xlike-inc.c (XLIKE_flash): + * redisplay-xlike-inc.c (console_type_create_redisplay_XLIKE): + Move lots more code into redisplay-xlike-inc.c. Use macros to + isolate the code that differs among X vs. GTK, to reduce the need + for ifdefs in the middle of the code. Now, redisplay-x.c and + redisplay-gtk.c only contain a few functions whose implementation + is completely different from one to the other, or which are not + present at all in one of them. + + GTK code not currently tested, but it has bitrotted somewhat + any. Doing this will help keep it less bitrotty. + + * depend: Regenerate. + 2010-01-18 Ben Wing <ben@xemacs.org> * redisplay-xlike-inc.c:
--- a/src/depend Mon Jan 18 06:21:05 2010 -0600 +++ b/src/depend Mon Jan 18 08:44:49 2010 -0600 @@ -33,7 +33,7 @@ #if defined(HAVE_XLIKE) event-xlike-inc.o: objects-xlike-inc.o: -redisplay-xlike-inc.o: +redisplay-xlike-inc.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h buffer.h bufslots.h casetab.h charset.h chartab.h coding-system-slots.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console-x-impl.h console-x.h console.h debug.h device-impl.h device.h devslots.h dumper.h faces.h file-coding.h frame-impl.h frame.h frameslots.h gc.h gccache-gtk.h general-slots.h glyphs-gtk.h glyphs-x.h glyphs.h gutter.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h mule-ccl.h number-gmp.h number-mp.h number.h objects-gtk-impl.h objects-gtk.h objects-impl.h objects-x-impl.h objects-x.h objects.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdep.h sysproc.h syssignal.h systime.h text.h vdb.h window-impl.h window.h winslots.h xgccache.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h #endif #if defined(HAVE_X_WINDOWS) EmacsFrame.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h EmacsManager.h charset.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h device-impl.h device.h devslots.h dumper.h faces.h frame-impl.h frame.h frameslots.h gc.h general-slots.h glyphs-x.h glyphs.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-x.h objects.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h text.h toolbar.h vdb.h window-impl.h window.h winslots.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h @@ -51,7 +51,7 @@ intl-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h compiler.h console-x.h console.h dumper.h gc.h general-slots.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h symeval.h symsinit.h text.h vdb.h xintrinsic.h menubar-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h buffer.h bufslots.h casetab.h charset.h chartab.h commands.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h device-impl.h device.h devslots.h dumper.h events.h frame-impl.h frame.h frameslots.h gc.h general-slots.h gui.h keymap.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h menubar.h number-gmp.h number-mp.h number.h opaque.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h systime.h text.h vdb.h window-impl.h window.h winslots.h xintrinsic.h objects-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h charset.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h device-impl.h device.h devslots.h dumper.h elhash.h font-mgr.h gc.h general-slots.h insdel.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-impl.h objects-x-impl.h objects-x.h objects-xlike-inc.c objects.h specifier.h symeval.h symsinit.h text.h vdb.h xintrinsic.h -redisplay-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h buffer.h bufslots.h casetab.h charset.h chartab.h coding-system-slots.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h debug.h device-impl.h device.h devslots.h dumper.h faces.h file-coding.h frame-impl.h frame.h frameslots.h gc.h general-slots.h glyphs-x.h glyphs.h gutter.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h mule-ccl.h number-gmp.h number-mp.h number.h objects-impl.h objects-x-impl.h objects-x.h objects.h redisplay-xlike-inc.c redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdep.h sysproc.h syssignal.h systime.h text.h vdb.h window-impl.h window.h winslots.h xgccache.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h +redisplay-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h buffer.h bufslots.h casetab.h charset.h chartab.h coding-system-slots.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console-x-impl.h console-x.h console.h debug.h device-impl.h device.h devslots.h dumper.h faces.h file-coding.h frame-impl.h frame.h frameslots.h gc.h gccache-gtk.h general-slots.h glyphs-gtk.h glyphs-x.h glyphs.h gutter.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h mule-ccl.h number-gmp.h number-mp.h number.h objects-gtk-impl.h objects-gtk.h objects-impl.h objects-x-impl.h objects-x.h objects.h redisplay-xlike-inc.c redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdep.h sysproc.h syssignal.h systime.h text.h vdb.h window-impl.h window.h winslots.h xgccache.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h scrollbar-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h device-impl.h device.h devslots.h dumper.h frame-impl.h frame.h frameslots.h gc.h general-slots.h glyphs-x.h glyphs.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h redisplay.h scrollbar-x.h scrollbar.h specifier.h symeval.h symsinit.h text.h vdb.h window-impl.h window.h winslots.h xintrinsic.h select-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h charset.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h device-impl.h device.h devslots.h dumper.h frame-impl.h frame.h frameslots.h gc.h general-slots.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-x.h objects.h opaque.h redisplay.h select-common.h select.h specifier.h symeval.h symsinit.h systime.h text.h vdb.h xintrinsic.h xmotif.h toolbar-x.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h charset.h compiler.h conslots.h console-impl.h console-x-impl.h console-x.h console.h dumper.h faces.h frame-impl.h frame.h frameslots.h gc.h general-slots.h glyphs-x.h glyphs.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-x.h objects.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h text.h toolbar-common.h toolbar.h vdb.h window-impl.h window.h winslots.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h @@ -82,7 +82,7 @@ menubar-gtk.o: $(CONFIG_H) $(LISP_H) buffer.h bufslots.h casetab.h charset.h chartab.h commands.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h device-impl.h device.h devslots.h dumper.h events.h frame-impl.h frame.h frameslots.h gc.h general-slots.h gui.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h menubar.h number-gmp.h number-mp.h number.h opaque.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdll.h systime.h text.h ui-gtk.h vdb.h window-impl.h window.h winslots.h native-gtk-toolbar.o: $(CONFIG_H) $(LISP_H) charset.h compiler.h console-gtk.h console.h dumper.h faces.h frame.h gc.h general-slots.h glyphs-gtk.h glyphs.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-gtk.h objects.h redisplay.h scrollbar.h specifier.h symeval.h symsinit.h text.h toolbar.h vdb.h window-impl.h window.h winslots.h objects-gtk.o: $(CONFIG_H) $(LISP_H) buffer.h bufslots.h casetab.h charset.h chartab.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h device-impl.h device.h devslots.h dumper.h gc.h general-slots.h insdel.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h objects-gtk-impl.h objects-gtk.h objects-impl.h objects-xlike-inc.c objects.h specifier.h symeval.h symsinit.h text.h vdb.h -redisplay-gtk.o: $(CONFIG_H) $(LISP_H) buffer.h bufslots.h casetab.h charset.h chartab.h coding-system-slots.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h debug.h device-impl.h device.h devslots.h dumper.h faces.h file-coding.h frame-impl.h frame.h frameslots.h gc.h gccache-gtk.h general-slots.h glyphs-gtk.h glyphs.h gutter.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h mule-ccl.h number-gmp.h number-mp.h number.h objects-gtk-impl.h objects-gtk.h objects-impl.h objects.h redisplay-xlike-inc.c redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdep.h sysproc.h syssignal.h systime.h text.h vdb.h window-impl.h window.h winslots.h +redisplay-gtk.o: $(CONFIG_H) $(LISP_H) $(LWLIB_SRCDIR)/lwlib.h EmacsFrame.h EmacsFrameP.h buffer.h bufslots.h casetab.h charset.h chartab.h coding-system-slots.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console-x-impl.h console-x.h console.h debug.h device-impl.h device.h devslots.h dumper.h faces.h file-coding.h frame-impl.h frame.h frameslots.h gc.h gccache-gtk.h general-slots.h glyphs-gtk.h glyphs-x.h glyphs.h gutter.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h mule-ccl.h number-gmp.h number-mp.h number.h objects-gtk-impl.h objects-gtk.h objects-impl.h objects-x-impl.h objects-x.h objects.h redisplay-xlike-inc.c redisplay.h scrollbar.h specifier.h symeval.h symsinit.h sysdep.h sysproc.h syssignal.h systime.h text.h vdb.h window-impl.h window.h winslots.h xgccache.h xintrinsic.h xintrinsicp.h xmotif.h xmprimitivep.h scrollbar-gtk.o: $(CONFIG_H) $(LISP_H) compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h dumper.h frame-impl.h frame.h frameslots.h gc.h general-slots.h glyphs-gtk.h glyphs.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h redisplay.h scrollbar-gtk.h scrollbar.h specifier.h symeval.h symsinit.h text.h vdb.h window-impl.h window.h winslots.h select-gtk.o: $(CONFIG_H) $(LISP_H) buffer.h bufslots.h casetab.h charset.h chartab.h compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h device-impl.h device.h devslots.h dumper.h events.h frame.h gc.h general-slots.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h opaque.h redisplay.h select-common.h select.h specifier.h symeval.h symsinit.h systime.h text.h vdb.h toolbar-gtk.o: $(CONFIG_H) $(LISP_H) compiler.h conslots.h console-gtk-impl.h console-gtk.h console-impl.h console.h dumper.h frame.h gc.h general-slots.h lisp-disunion.h lisp-union.h lisp.h lrecord.h mc-alloc.h number-gmp.h number-mp.h number.h redisplay.h specifier.h symeval.h symsinit.h text.h toolbar-common.h vdb.h
--- a/src/redisplay-gtk.c Mon Jan 18 06:21:05 2010 -0600 +++ b/src/redisplay-gtk.c Mon Jan 18 08:44:49 2010 -0600 @@ -23,385 +23,8 @@ /* Synched up with: Not in FSF. */ -/* Author: Chuck Thompson */ -/* Gtk flavor by William Perry */ - -/* Lots of work done by Ben Wing for Mule */ - -#include <config.h> -#include "lisp.h" - -#include "buffer.h" -#include "debug.h" -#include "device-impl.h" -#include "faces.h" -#include "file-coding.h" -#include "frame-impl.h" -#include "gutter.h" -#include "redisplay.h" -#include "sysdep.h" -#include "window.h" - -#include "console-gtk-impl.h" -#include "gccache-gtk.h" -#include "glyphs-gtk.h" -#include "objects-gtk-impl.h" - -#include "sysproc.h" /* for select() */ - -#ifdef MULE -#include "mule-ccl.h" -#endif - -#define CONST const - -#define EOL_CURSOR_WIDTH 5 - -static void gtk_output_pixmap (struct window *w, - Lisp_Object image_instance, - struct display_box *db, - struct display_glyph_area *dga, - face_index findex, - int cursor_start, - int cursor_width, - int cursor_height, - int bgpixmap); -static void gtk_output_vertical_divider (struct window *w, int clear); -static void gtk_output_blank (struct window *w, struct display_line *dl, - struct rune *rb, int start_pixpos, - int cursor_start, int cursor_width); -static void gtk_output_horizontal_line (struct window *w, - struct display_line *dl, - struct rune *rb); -static void gtk_clear_region (Lisp_Object locale, struct device* d, struct frame* f, - face_index findex, int x, int y, - int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, - Lisp_Object background_pixmap); -static void gtk_output_eol_cursor (struct window *w, struct display_line *dl, - int xpos, face_index findex); -static void gtk_clear_frame (struct frame *f); -static void gtk_clear_frame_windows (Lisp_Object window); -static void gtk_bevel_modeline (struct window *w, struct display_line *dl); - -#if 0 -static void __describe_gc (GdkGC *); -#endif - #include "redisplay-xlike-inc.c" -/****************************************************************************/ -/* */ -/* Gtk output routines */ -/* */ -/****************************************************************************/ - -static int -gtk_text_width_single_run (struct face_cachel *cachel, struct textual_run *run) -{ - Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset); - struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst); - - if (!fi->proportional_p) - { - return fi->width * run->len; - } - else - { - if (run->dimension == 2) - { - stderr_out ("Measuring wide characters\n"); - return gdk_text_width_wc (FONT_INSTANCE_GTK_FONT (fi), - (GdkWChar *) run->ptr, run->len); - } - else - { - return gdk_text_width (FONT_INSTANCE_GTK_FONT (fi), - (char *) run->ptr, run->len); - } - } -} - -/* - gtk_text_width - - Given a string and a face, return the string's length in pixels when - displayed in the font associated with the face. - */ - -static int -gtk_text_width (struct frame *UNUSED (f), struct face_cachel *cachel, - CONST Ichar *str, Charcount len) -{ - /* !!#### */ - int width_so_far = 0; - unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); - struct textual_run *runs = alloca_array (struct textual_run, len); - int nruns; - int i; - - nruns = separate_textual_runs (text_storage, runs, str, len); - - for (i = 0; i < nruns; i++) - width_so_far += gtk_text_width_single_run (cachel, runs + i); - - return width_so_far; -} - -/***************************************************************************** - gtk_divider_height - - Return the height of the horizontal divider. This is a function because - divider_height is a device method. - - #### If we add etched horizontal divider lines this will have to get - smarter. - ****************************************************************************/ -static int -gtk_divider_height (void) -{ - return 2; -} - -/***************************************************************************** - gtk_eol_cursor_width - - Return the width of the end-of-line cursor. This is a function - because eol_cursor_width is a device method. - ****************************************************************************/ -static int -gtk_eol_cursor_width (void) -{ - return EOL_CURSOR_WIDTH; -} - -/***************************************************************************** - gtk_output_display_block - - Given a display line, a block number for that start line, output all - runes between start and end in the specified display block. - ****************************************************************************/ -static void -gtk_output_display_block (struct window *w, struct display_line *dl, int block, - int start, int end, int start_pixpos, int cursor_start, - int cursor_width, int cursor_height) -{ - struct frame *f = XFRAME (w->frame); - Ichar_dynarr *buf; - Lisp_Object window; - - struct display_block *db = Dynarr_atp (dl->display_blocks, block); - rune_dynarr *rba = db->runes; - struct rune *rb; - - int elt = start; - face_index findex; - int xpos, width; - Lisp_Object charset = Qunbound; /* Qnil is a valid charset when - MULE is not defined */ - - window = wrap_window (w); - rb = Dynarr_atp (rba, start); - - if (!rb) - { - /* Nothing to do so don't do anything. */ - return; - } - else - { - findex = rb->findex; - xpos = rb->xpos; - width = 0; - if (rb->type == RUNE_CHAR) - charset = ichar_charset (rb->object.chr.ch); - } - - if (end < 0) - end = Dynarr_length (rba); - buf = Dynarr_new (Ichar); - - while (elt < end) - { - rb = Dynarr_atp (rba, elt); - - if (rb->findex == findex && rb->type == RUNE_CHAR - && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON - && EQ (charset, ichar_charset (rb->object.chr.ch))) - { - Dynarr_add (buf, rb->object.chr.ch); - width += rb->width; - elt++; - } - else - { - if (Dynarr_length (buf)) - { - gtk_output_string (w, dl, buf, xpos, 0, start_pixpos, width, - findex, 0, cursor_start, cursor_width, - cursor_height); - xpos = rb->xpos; - width = 0; - } - Dynarr_reset (buf); - width = 0; - - if (rb->type == RUNE_CHAR) - { - findex = rb->findex; - xpos = rb->xpos; - charset = ichar_charset (rb->object.chr.ch); - - if (rb->cursor_type == CURSOR_ON) - { - if (rb->object.chr.ch == '\n') - { - gtk_output_eol_cursor (w, dl, xpos, findex); - } - else - { - Dynarr_add (buf, rb->object.chr.ch); - gtk_output_string (w, dl, buf, xpos, 0, start_pixpos, - rb->width, findex, 1, - cursor_start, cursor_width, - cursor_height); - Dynarr_reset (buf); - } - - xpos += rb->width; - elt++; - } - else if (rb->object.chr.ch == '\n') - { - /* Clear in case a cursor was formerly here. */ - int height = dl->ascent + dl->descent - dl->clip; - - redisplay_clear_region (window, findex, xpos, dl->ypos - dl->ascent, - rb->width, height); - elt++; - } - } - else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE) - { - if (rb->type == RUNE_BLANK) - gtk_output_blank (w, dl, rb, start_pixpos, cursor_start, - cursor_width); - else - { - /* #### Our flagging of when we need to redraw the - modeline shadows sucks. Since RUNE_HLINE is only used - by the modeline at the moment it is a good bet - that if it gets redrawn then we should also - redraw the shadows. This won't be true forever. - We borrow the shadow_thickness_changed flag for - now. */ - w->shadow_thickness_changed = 1; - gtk_output_horizontal_line (w, dl, rb); - } - - elt++; - if (elt < end) - { - rb = Dynarr_atp (rba, elt); - - findex = rb->findex; - xpos = rb->xpos; - } - } - else if (rb->type == RUNE_DGLYPH) - { - Lisp_Object instance; - struct display_box dbox; - struct display_glyph_area dga; - redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset, - rb->object.dglyph.yoffset ,start_pixpos, - rb->width, &dbox, &dga); - - window = wrap_window (w); - instance = glyph_image_instance (rb->object.dglyph.glyph, - window, ERROR_ME_DEBUG_WARN, 1); - findex = rb->findex; - - if (IMAGE_INSTANCEP (instance)) - switch (XIMAGE_INSTANCE_TYPE (instance)) - { - case IMAGE_TEXT: - { - /* #### This is way losing. See the comment in - add_glyph_rune(). */ - Lisp_Object string = - XIMAGE_INSTANCE_TEXT_STRING (instance); - convert_ibyte_string_into_ichar_dynarr - (XSTRING_DATA (string), XSTRING_LENGTH (string), buf); - - gtk_output_string (w, dl, buf, xpos, - rb->object.dglyph.xoffset, - start_pixpos, -1, findex, - (rb->cursor_type == CURSOR_ON), - cursor_start, cursor_width, - cursor_height); - Dynarr_reset (buf); - } - break; - - case IMAGE_MONO_PIXMAP: - case IMAGE_COLOR_PIXMAP: - redisplay_output_pixmap (w, instance, &dbox, &dga, - findex,cursor_start, - cursor_width, cursor_height, 0); - break; - - case IMAGE_POINTER: - ABORT (); - - case IMAGE_WIDGET: - if (EQ (XIMAGE_INSTANCE_WIDGET_TYPE (instance), - Qlayout)) - { - redisplay_output_layout (window, instance, &dbox, - &dga, findex, - cursor_start, cursor_width, - cursor_height); - break; - } - - case IMAGE_SUBWINDOW: - redisplay_output_subwindow (w, instance, &dbox, &dga, - findex, cursor_start, - cursor_width, cursor_height); - break; - - case IMAGE_NOTHING: - /* nothing is as nothing does */ - break; - - default: - ABORT (); - } - - xpos += rb->width; - elt++; - } - else - ABORT (); - } - } - - if (Dynarr_length (buf)) - gtk_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex, - 0, cursor_start, cursor_width, cursor_height); - - /* #### This is really conditionalized well for optimized - performance. */ - if (dl->modeline - && !EQ (Qzero, w->modeline_shadow_thickness) - && (f->clear - || f->windows_structure_changed - || w->shadow_thickness_changed)) - gtk_bevel_modeline (w, dl); - - Dynarr_free (buf); -} - /***************************************************************************** gtk_bevel_modeline @@ -423,866 +46,6 @@ } /***************************************************************************** - gtk_get_gc - - Given a number of parameters return a GC with those properties. - ****************************************************************************/ -GdkGC * -gtk_get_gc (struct device *d, Lisp_Object font, Lisp_Object fg, Lisp_Object bg, - Lisp_Object bg_pmap, Lisp_Object lwidth) -{ - GdkGCValues gcv; - unsigned long mask; - - memset (&gcv, ~0, sizeof (gcv)); - gcv.graphics_exposures = FALSE; - /* Make absolutely sure that we don't pick up a clipping region in - the GC returned by this function. */ - gcv.clip_mask = 0; - gcv.clip_x_origin = 0; - gcv.clip_y_origin = 0; - gcv.fill = GDK_SOLID; - mask = GDK_GC_EXPOSURES | GDK_GC_CLIP_MASK | GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN; - mask |= GDK_GC_FILL; - - if (!NILP (font)) - { - gcv.font = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (font)); - mask |= GDK_GC_FONT; - } - - /* evil kludge! */ - if (!NILP (fg) && !COLOR_INSTANCEP (fg) && !INTP (fg)) - { - /* #### I fixed once case where this was getting it. It was a - bad macro expansion (compiler bug). */ - fprintf (stderr, "Help! gtk_get_gc got a bogus fg value! fg = "); - debug_print (fg); - fg = Qnil; - } - - if (!NILP (fg)) - { - if (COLOR_INSTANCEP (fg)) - gcv.foreground = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (fg)); - else - gcv.foreground.pixel = XINT (fg); - mask |= GDK_GC_FOREGROUND; - } - - if (!NILP (bg)) - { - if (COLOR_INSTANCEP (bg)) - gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (bg)); - else - gcv.background.pixel = XINT (fg); - mask |= GDK_GC_BACKGROUND; - } - - if (IMAGE_INSTANCEP (bg_pmap) - && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - { - if (XIMAGE_INSTANCE_PIXMAP_DEPTH (bg_pmap) == 0) - { - gcv.fill = GDK_OPAQUE_STIPPLED; - gcv.stipple = XIMAGE_INSTANCE_GTK_PIXMAP (bg_pmap); - mask |= (GDK_GC_STIPPLE | GDK_GC_FILL); - } - else - { - gcv.fill = GDK_TILED; - gcv.tile = XIMAGE_INSTANCE_GTK_PIXMAP (bg_pmap); - mask |= (GDK_GC_TILE | GDK_GC_FILL); - } - } - - if (!NILP (lwidth)) - { - gcv.line_width = XINT (lwidth); - mask |= GDK_GC_LINE_WIDTH; - } - - return gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, (GdkGCValuesMask) mask); -} - -/***************************************************************************** - gtk_output_string - - Given a string and a starting position, output that string in the - given face. If cursor is true, draw a cursor around the string. - Correctly handles multiple charsets in the string. - - The meaning of the parameters is something like this: - - W Window that the text is to be displayed in. - DL Display line that this text is on. The values in the - structure are used to determine the vertical position and - clipping range of the text. - BUF Dynamic array of Ichars specifying what is actually to be - drawn. - XPOS X position in pixels where the text should start being drawn. - XOFFSET Number of pixels to be chopped off the left side of the - text. The effect is as if the text were shifted to the - left this many pixels and clipped at XPOS. - CLIP_START Clip everything left of this X position. - WIDTH Clip everything right of XPOS + WIDTH. - FINDEX Index for the face cache element describing how to display - the text. - CURSOR #### I don't understand this. There's something - strange and overcomplexified with this variable. - Chuck, explain please? - CURSOR_START Starting X position of cursor. - CURSOR_WIDTH Width of cursor in pixels. - CURSOR_HEIGHT Height of cursor in pixels. - - Starting Y position of cursor is the top of the text line. - The cursor is drawn sometimes whether or not CURSOR is set. ??? - ****************************************************************************/ -static -void gdk_draw_text_image (GdkDrawable *drawable, - GdkFont *font, - GdkGC *gc, - gint x, - gint y, - const gchar *text, - gint text_length); - -void -gtk_output_string (struct window *w, struct display_line *dl, - Ichar_dynarr *buf, int xpos, int xoffset, int clip_start, - int width, face_index findex, int cursor, - int cursor_start, int cursor_width, int cursor_height) -{ - /* !!#### Needs review */ - /* General variables */ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - Lisp_Object device; - Lisp_Object window; - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - - int clip_end; - - /* Cursor-related variables */ - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - int cursor_clip; - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - WINDOW_BUFFER (w)); - struct face_cachel *cursor_cachel = 0; - - /* Text-related variables */ - Lisp_Object bg_pmap; - GdkGC *bgc, *gc; - int height; - int len = Dynarr_length (buf); - unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); - struct textual_run *runs = alloca_array (struct textual_run, len); - int nruns; - int i; - struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex); - - device = wrap_device (d); - window = wrap_window (w); - - if (width < 0) - width = gtk_text_width (f, cachel, Dynarr_atp (buf, 0), Dynarr_length (buf)); - height = dl->ascent + dl->descent - dl->clip; - - /* Regularize the variables passed in. */ - - if (clip_start < xpos) - clip_start = xpos; - clip_end = xpos + width; - if (clip_start >= clip_end) - /* It's all clipped out. */ - return; - - xpos -= xoffset; - - nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0), - Dynarr_length (buf)); - - cursor_clip = (cursor_start >= clip_start && - cursor_start < clip_end); - - /* This cursor code is really a mess. */ - if (!NILP (w->text_cursor_visible_p) - && (cursor - || cursor_clip - || (cursor_width - && (cursor_start + cursor_width >= clip_start) - && !NILP (bar_cursor_value)))) - { - /* These have to be in separate statements in order to avoid a - compiler bug. */ - face_index sucks = get_builtin_face_cache_index (w, Vtext_cursor_face); - cursor_cachel = WINDOW_FACE_CACHEL (w, sucks); - - /* We have to reset this since any call to WINDOW_FACE_CACHEL - may cause the cache to resize and any pointers to it to - become invalid. */ - cachel = WINDOW_FACE_CACHEL (w, findex); - } - - bg_pmap = cachel->background_pixmap; - if (!IMAGE_INSTANCEP (bg_pmap) - || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - bg_pmap = Qnil; - - if ((cursor && focus && NILP (bar_cursor_value) - && !NILP (w->text_cursor_visible_p)) || NILP (bg_pmap)) - bgc = 0; - else - bgc = gtk_get_gc (d, Qnil, cachel->foreground, cachel->background, - bg_pmap, Qnil); - - if (bgc) - gdk_draw_rectangle (GDK_DRAWABLE (x_win), bgc, TRUE, clip_start, - dl->ypos - dl->ascent, clip_end - clip_start, - height); - - for (i = 0; i < nruns; i++) - { - Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset); - struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font); - GdkFont *gdk_font = FONT_INSTANCE_GTK_FONT (fi); - int this_width; - int need_clipping; - - if (EQ (font, Vthe_null_font_instance)) - continue; - - this_width = gtk_text_width_single_run (cachel, runs + i); - need_clipping = (dl->clip || clip_start > xpos || - clip_end < xpos + this_width); - - /* XDrawImageString only clears the area equal to the height of - the given font. It is possible that a font is being displayed - on a line taller than it is, so this would cause us to fail to - clear some areas. */ - if ((int) fi->height < (int) (height + dl->clip)) - { - int clear_start = max (xpos, clip_start); - int clear_end = min (xpos + this_width, clip_end); - - if (cursor) - { - int ypos1_line, ypos1_string, ypos2_line, ypos2_string; - - ypos1_string = dl->ypos - fi->ascent; - ypos2_string = dl->ypos + fi->descent; - ypos1_line = dl->ypos - dl->ascent; - ypos2_line = dl->ypos + dl->descent - dl->clip; - - /* Make sure we don't clear below the real bottom of the - line. */ - if (ypos1_string > ypos2_line) - ypos1_string = ypos2_line; - if (ypos2_string > ypos2_line) - ypos2_string = ypos2_line; - - if (ypos1_line < ypos1_string) - { - redisplay_clear_region (window, findex, clear_start, ypos1_line, - clear_end - clear_start, - ypos1_string - ypos1_line); - } - - if (ypos2_line > ypos2_string) - { - redisplay_clear_region (window, findex, clear_start, ypos2_string, - clear_end - clear_start, - ypos2_line - ypos2_string); - } - } - else - { - redisplay_clear_region (window, findex, clear_start, - dl->ypos - dl->ascent, clear_end - clear_start, - height); - } - } - - if (cursor && cursor_cachel && focus && NILP (bar_cursor_value)) - { - gc = gtk_get_gc (d, font, cursor_cachel->foreground, - cursor_cachel->background, Qnil, Qnil); - } - else - { - gc = gtk_get_gc (d, font, cachel->foreground, cachel->background, - Qnil, Qnil); - } - - if (need_clipping) - { - GdkRectangle clip_box; - - clip_box.x = 0; - clip_box.y = 0; - clip_box.width = clip_end - clip_start; - clip_box.height = height; - - gdk_gc_set_clip_rectangle (gc, &clip_box); - gdk_gc_set_clip_origin (gc, clip_start, dl->ypos - dl->ascent); - } - - /* The X specific called different functions (XDraw*String - vs. XDraw*String16), but apparently gdk_draw_text takes care - of that for us. - - BUT, gdk_draw_text also does too much, by dividing the length - by 2. So we fake them out my multiplying the length by the - dimension of the text. This will do the right thing for - single-dimension runs as well of course. - */ - (bgc ? gdk_draw_text : gdk_draw_text_image) (GDK_DRAWABLE (x_win), gdk_font, gc, xpos, - dl->ypos, (char *) runs[i].ptr, - runs[i].len * runs[i].dimension); - - /* We draw underlines in the same color as the text. */ - if (cachel->underline) - { - int upos, uthick; - - /* Cannot get at font properties in Gtk, so we resort to - guessing */ - upos = dl->descent / 2; - uthick = 1; - - if ((dl->ypos + upos) < (dl->ypos + dl->descent - dl->clip)) - { - if (dl->ypos + upos + uthick > dl->ypos + dl->descent - dl->clip) - uthick = dl->descent - dl->clip - upos; - - if (uthick == 1) - { - gdk_draw_line (GDK_DRAWABLE (x_win), gc, xpos, dl->ypos + upos, - xpos + this_width, dl->ypos + upos); - } - else if (uthick > 1) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, xpos, - dl->ypos + upos, this_width, uthick); - } - } - } - - if (cachel->strikethru) { - gint ascent,descent,upos, uthick; - GdkFont *gfont = FONT_INSTANCE_GTK_FONT (XFONT_INSTANCE (font)); - - /* Cannot get at font properties in Gtk, so we resort to - guessing */ - - ascent = gfont->ascent; - descent = gfont->descent; - uthick = 1; - - upos = ascent - ((ascent + descent) / 2) + 1; - - /* Generally, upos will be positive (above the baseline),so subtract */ - if (dl->ypos - upos < dl->ypos + dl->descent - dl->clip) - { - if (dl->ypos - upos + uthick > dl->ypos + dl->descent - dl->clip) - uthick = dl->descent - dl->clip + upos; - - if (uthick == 1) - { - gdk_draw_line (GDK_DRAWABLE (x_win), gc, xpos, dl->ypos - upos, - xpos + this_width, dl->ypos - upos); - } - else if (uthick > 1) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, xpos, dl->ypos + upos, - this_width, uthick); - } - } - } - - /* Restore the GC */ - if (need_clipping) - { - gdk_gc_set_clip_rectangle (gc, NULL); - gdk_gc_set_clip_origin (gc, 0, 0); - } - - /* If we are actually superimposing the cursor then redraw with just - the appropriate section highlighted. */ - if (cursor_clip && !cursor && focus && cursor_cachel) - { - GdkGC *cgc; - GdkRectangle clip_box; - - cgc = gtk_get_gc (d, font, cursor_cachel->foreground, - cursor_cachel->background, Qnil, Qnil); - - clip_box.x = 0; - clip_box.y = 0; - clip_box.width = cursor_width; - clip_box.height = height; - - gdk_gc_set_clip_rectangle (cgc, &clip_box); - gdk_gc_set_clip_origin (cgc, cursor_start, dl->ypos - dl->ascent); - - /* The X specific called different functions (XDraw*String - vs. XDraw*String16), but apparently gdk_draw_text takes care - of that for us. - - BUT, gdk_draw_text also does too much, by dividing the - length by 2. So we fake them out my multiplying the - length by the dimension of the text. This will do the - right thing for single-dimension runs as well of course. - */ - gdk_draw_text_image (GDK_DRAWABLE (x_win), gdk_font, cgc, xpos, - dl->ypos, (char *) runs[i].ptr, - runs[i].len * runs[i].dimension); - - gdk_gc_set_clip_rectangle (cgc, NULL); - gdk_gc_set_clip_origin (cgc, 0, 0); - } - - xpos += this_width; - } - - /* Draw the non-focus box or bar-cursor as needed. */ - /* Can't this logic be simplified? */ - if (cursor_cachel - && ((cursor && !focus && NILP (bar_cursor_value)) - || (cursor_width - && (cursor_start + cursor_width >= clip_start) - && !NILP (bar_cursor_value)))) - { - int tmp_height, tmp_y; - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - int need_clipping = (cursor_start < clip_start - || clip_end < cursor_start + cursor_width); - - /* #### This value is correct (as far as I know) because - all of the times we need to draw this cursor, we will - be called with exactly one character, so we know we - can always use runs[0]. - - This is bogus as all hell, however. The cursor handling in - this function is way bogus and desperately needs to be - cleaned up. (In particular, the drawing of the cursor should - really really be separated out of this function. This may be - a bit tricky now because this function itself does way too - much stuff, a lot of which needs to be moved into - redisplay.c) This is the only way to be able to easily add - new cursor types or (e.g.) make the bar cursor be able to - span two characters instead of overlaying just one. */ - int bogusly_obtained_ascent_value = - XFONT_INSTANCE (FACE_CACHEL_FONT (cachel, runs[0].charset))->ascent; - - if (!NILP (bar_cursor_value)) - { - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - } - else - { - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, - Qnil, Qnil, Qnil); - } - - tmp_y = dl->ypos - bogusly_obtained_ascent_value; - tmp_height = cursor_height; - if (tmp_y + tmp_height > (int) (dl->ypos - dl->ascent + height)) - { - tmp_y = dl->ypos - dl->ascent + height - tmp_height; - if (tmp_y < (int) (dl->ypos - dl->ascent)) - tmp_y = dl->ypos - dl->ascent; - tmp_height = dl->ypos - dl->ascent + height - tmp_y; - } - - if (need_clipping) - { - GdkRectangle clip_box; - clip_box.x = 0; - clip_box.y = 0; - clip_box.width = clip_end - clip_start; - clip_box.height = tmp_height; - - gdk_gc_set_clip_rectangle (gc, &clip_box); - gdk_gc_set_clip_origin (gc, clip_start, tmp_y); - } - - if (!focus && NILP (bar_cursor_value)) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE, - cursor_start, tmp_y, - cursor_width - 1, tmp_height - 1); - } - else if (focus && !NILP (bar_cursor_value)) - { - gdk_draw_line (GDK_DRAWABLE (x_win), gc, - cursor_start + bar_width - 1, tmp_y, - cursor_start + bar_width - 1, tmp_y + tmp_height - 1); - } - - /* Restore the GC */ - if (need_clipping) - { - gdk_gc_set_clip_rectangle (gc, NULL); - gdk_gc_set_clip_origin (gc, 0, 0); - } - } -} - -static void -our_draw_bitmap (GdkDrawable *drawable, - GdkGC *gc, - GdkPixmap *src, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height); - -static void -gtk_output_gdk_pixmap (struct frame *f, struct Lisp_Image_Instance *p, int x, - int y, int xoffset, int yoffset, - int width, int height, - GdkColor *fg, GdkColor *bg, GdkGC *override_gc) -{ - struct device *d = XDEVICE (f->device); - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - - GdkGC *gc; - GdkGCValues gcv; - unsigned long pixmap_mask; - - if (!override_gc) - { - memset (&gcv, ~0, sizeof (gcv)); - gcv.graphics_exposures = FALSE; - gcv.foreground = *fg; - gcv.background = *bg; - pixmap_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_EXPOSURES; - - if (IMAGE_INSTANCE_GTK_MASK (p)) - { - gcv.function = GDK_COPY; - gcv.clip_mask = IMAGE_INSTANCE_GTK_MASK (p); - gcv.clip_x_origin = x - xoffset; - gcv.clip_y_origin = y - yoffset; - pixmap_mask |= (GDK_GC_FUNCTION | GDK_GC_CLIP_MASK | GDK_GC_CLIP_X_ORIGIN | - GDK_GC_CLIP_Y_ORIGIN); - /* Can't set a clip rectangle below because we already have a mask. - We could conceivably create a new clipmask by zeroing out - everything outside the clip region. Is it worth it? - Is it possible to get an equivalent effect by changing the - args to XCopyArea below rather than messing with a clip box? - - dkindred@cs.cmu.edu - Yes. We don't clip at all now - andy@xemacs.org - */ - } - - gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, pixmap_mask); - } - else - { - gc = override_gc; - /* override_gc might have a mask already--we don't want to nuke it. - Maybe we can insist that override_gc have no mask, or use - one of the suggestions above. */ - } - - if (IMAGE_INSTANCE_PIXMAP_DEPTH (p) > 0) - { - gdk_draw_pixmap (GDK_DRAWABLE (x_win), gc, - IMAGE_INSTANCE_GTK_PIXMAP (p), - xoffset, yoffset, x, y, width, height); - } - else - { - our_draw_bitmap (GDK_DRAWABLE (x_win), gc, - IMAGE_INSTANCE_GTK_PIXMAP (p), - xoffset, yoffset, x, y, width, height); - } -} - -static void -gtk_output_pixmap (struct window *w, - Lisp_Object image_instance, - struct display_box *db, - struct display_glyph_area *dga, - face_index findex, - int cursor_start, - int cursor_width, - int cursor_height, - int UNUSED (bg_pixmap)) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - struct Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance); - Lisp_Object window; - - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - - window = wrap_window (w); - - /* Output the pixmap. */ - { - Lisp_Object tmp_pixel; - GdkColor *tmp_bcolor, *tmp_fcolor; - - tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex); - tmp_fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex); - tmp_bcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - - gtk_output_gdk_pixmap (f, p, db->xpos, db->ypos, - dga->xoffset, dga->yoffset, - dga->width, dga->height, - tmp_fcolor, tmp_bcolor, NULL); - } - - /* Draw a cursor over top of the pixmap. */ - if (cursor_width && cursor_height && (cursor_start >= db->xpos) - && !NILP (w->text_cursor_visible_p) - && (cursor_start < (db->xpos + dga->width))) - { - GdkGC *gc; - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - struct face_cachel *cursor_cachel = - WINDOW_FACE_CACHEL (w, - get_builtin_face_cache_index - (w, Vtext_cursor_face)); - - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - if (cursor_width > db->xpos + dga->width - cursor_start) - cursor_width = db->xpos + dga->width - cursor_start; - - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, focus ? TRUE : FALSE, - cursor_start, db->ypos, cursor_width, - cursor_height); - } -} - -/***************************************************************************** - gtk_output_vertical_divider - - Draw a vertical divider down the right side of the given window. - ****************************************************************************/ -static void -gtk_output_vertical_divider (struct window *w, int UNUSED(clear)) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - GdkGC *background_gc; - Lisp_Object tmp_pixel; - GdkGCValues gcv; - unsigned long mask; - int x, y1, y2, width, shadow_thickness, spacing, line_width; - face_index div_face = get_builtin_face_cache_index (w, Vvertical_divider_face); - - width = window_divider_width (w); - shadow_thickness = XINT (w->vertical_divider_shadow_thickness); - spacing = XINT (w->vertical_divider_spacing); - line_width = XINT (w->vertical_divider_line_width); - x = WINDOW_RIGHT (w) - width; - y1 = WINDOW_TOP (w); - y2 = WINDOW_BOTTOM (w); - - memset (&gcv, ~0, sizeof (gcv)); - - tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, div_face); - - gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - gcv.foreground = gcv.background; - gcv.graphics_exposures = FALSE; - mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_EXPOSURES; - - background_gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (d), &gcv, mask); - - /* Clear the divider area first. This needs to be done when a - window split occurs. */ - /* if (clear) */ - gdk_draw_rectangle (GDK_DRAWABLE (x_win), background_gc, TRUE, - x, y1, width, y2 - y1); - -#if 0 - /* Draw the divider line. */ - gdk_draw_rectangle (GDK_DRAWABLE (x_win), background_gc, TRUE, - x + spacing + shadow_thickness, y1, - line_width, y2 - y1); -#endif - - /* Draw the shadows around the divider line */ - gtk_output_shadows (f, x + spacing, y1, - width - 2 * spacing, y2 - y1, - shadow_thickness); -} - -/***************************************************************************** - gtk_output_blank - - Output a blank by clearing the area it covers in the foreground color - of its face. - ****************************************************************************/ -static void -gtk_output_blank (struct window *w, struct display_line *dl, struct rune *rb, - int start_pixpos, int cursor_start, int cursor_width) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - GdkGC *gc; - struct face_cachel *cursor_cachel = - WINDOW_FACE_CACHEL (w, - get_builtin_face_cache_index - (w, Vtext_cursor_face)); - Lisp_Object bg_pmap; - Lisp_Object buffer = WINDOW_BUFFER (w); - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - buffer); - - int x = rb->xpos; - int y = dl->ypos - dl->ascent; - int width = rb->width; - int height = dl->ascent + dl->descent - dl->clip; - - if (start_pixpos > x) - { - if (start_pixpos >= (x + width)) - return; - else - { - width -= (start_pixpos - x); - x = start_pixpos; - } - } - - bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex); - if (!IMAGE_INSTANCEP (bg_pmap) - || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - bg_pmap = Qnil; - - if (NILP (bg_pmap)) - gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - else - gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), - WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), bg_pmap, - Qnil); - - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, y, width, height); - - /* If this rune is marked as having the cursor, then it is actually - representing a tab. */ - if (!NILP (w->text_cursor_visible_p) - && (rb->cursor_type == CURSOR_ON - || (cursor_width - && (cursor_start + cursor_width > x) - && cursor_start < (x + width)))) - { - int cursor_height, cursor_y; - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - struct Lisp_Font_Instance *fi; - - fi = XFONT_INSTANCE (FACE_CACHEL_FONT - (WINDOW_FACE_CACHEL (w, rb->findex), - Vcharset_ascii)); - - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - cursor_y = dl->ypos - fi->ascent; - cursor_height = fi->height; - if (cursor_y + cursor_height > y + height) - cursor_height = y + height - cursor_y; - - if (focus) - { - if (NILP (bar_cursor_value)) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, - cursor_start, cursor_y, - fi->width, cursor_height); - } - else - { - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - gdk_draw_line (GDK_DRAWABLE (x_win), gc, cursor_start + bar_width - 1, - cursor_y, cursor_start + bar_width - 1, - cursor_y + cursor_height - 1); - } - } - else if (NILP (bar_cursor_value)) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE, - cursor_start, cursor_y, - fi->width - 1, cursor_height - 1); - } - } -} - -/***************************************************************************** - gtk_output_horizontal_line - - Output a horizontal line in the foreground of its face. - ****************************************************************************/ -static void -gtk_output_horizontal_line (struct window *w, - struct display_line *dl, - struct rune *rb) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - GtkStyle *style = FRAME_GTK_TEXT_WIDGET (f)->style; - - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - GdkGC *gc; - - int x = rb->xpos; - int width = rb->width; - int height = dl->ascent + dl->descent - dl->clip; - - int ypos1, ypos2, ypos3, ypos4; - - ypos1 = dl->ypos - dl->ascent; - ypos2 = ypos1 + rb->object.hline.yoffset; - ypos3 = ypos2 + rb->object.hline.thickness; - ypos4 = dl->ypos + dl->descent - dl->clip; - - /* First clear the area not covered by the line. */ - if (height - rb->object.hline.thickness > 0) - { - gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - - if (ypos2 - ypos1 > 0) - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos1, width, ypos2 - ypos1); - if (ypos4 - ypos3 > 0) - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos1, width, ypos2 - ypos1); - } - - gtk_paint_hline (style, x_win, GTK_STATE_NORMAL, NULL, FRAME_GTK_TEXT_WIDGET (f), - "hline", x, x + width, ypos2); -#if 0 - /* Now draw the line. */ - gc = gtk_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - - if (ypos2 < ypos1) - ypos2 = ypos1; - if (ypos3 > ypos4) - ypos3 = ypos4; - - if (ypos3 - ypos2 > 0) - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, ypos2, width, ypos3 - ypos2); -#endif -} - -/***************************************************************************** gtk_output_shadows Draw a shadow around the given area using the standard theme engine routines. @@ -1312,271 +75,6 @@ x, y, width, height); } -/***************************************************************************** - gtk_clear_to_window_end - - Clear the area between ypos1 and ypos2. Each margin area and the - text area is handled separately since they may each have their own - background color. - ****************************************************************************/ -static void -gtk_clear_to_window_end (struct window *w, int ypos1, int ypos2) -{ - int height = ypos2 - ypos1; - - if (height) - { - struct frame *f = XFRAME (w->frame); - Lisp_Object window; - int bflag = (window_needs_vertical_divider (w) ? 0 : 1); - layout_bounds bounds; - - bounds = calculate_display_line_boundaries (w, bflag); - window = wrap_window (w); - - if (window_is_leftmost (w)) - redisplay_clear_region (window, DEFAULT_INDEX, FRAME_LEFT_BORDER_START (f), - ypos1, FRAME_BORDER_WIDTH (f), height); - - if (bounds.left_in - bounds.left_out > 0) - redisplay_clear_region (window, - get_builtin_face_cache_index (w, Vleft_margin_face), - bounds.left_out, ypos1, - bounds.left_in - bounds.left_out, height); - - if (bounds.right_in - bounds.left_in > 0) - redisplay_clear_region (window, DEFAULT_INDEX, bounds.left_in, ypos1, - bounds.right_in - bounds.left_in, height); - - if (bounds.right_out - bounds.right_in > 0) - redisplay_clear_region (window, - get_builtin_face_cache_index (w, Vright_margin_face), - bounds.right_in, ypos1, - bounds.right_out - bounds.right_in, height); - - if (window_is_rightmost (w)) - redisplay_clear_region (window, DEFAULT_INDEX, FRAME_RIGHT_BORDER_START (f), - ypos1, FRAME_BORDER_WIDTH (f), height); - } -} - -/**************************************************************************** - gtk_clear_region - - Clear the area in the box defined by the given parameters using the - given face. - ****************************************************************************/ -static void -gtk_clear_region (Lisp_Object UNUSED (locale), struct device* d, - struct frame* f, face_index UNUSED (findex), int x, int y, - int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, - Lisp_Object background_pixmap) -{ - GdkWindow *x_win; - GdkGC *gc = NULL; - - x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - - if (!UNBOUNDP (background_pixmap)) - { - gc = gtk_get_gc (d, Qnil, fcolor, bcolor, background_pixmap, Qnil); - } - - if (gc) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc,TRUE, - x, y, width, height); - } - else - { - gdk_window_clear_area (x_win, x, y, width, height); - } -} - -/***************************************************************************** - gtk_output_eol_cursor - - Draw a cursor at the end of a line. The end-of-line cursor is - narrower than the normal cursor. - ****************************************************************************/ -static void -gtk_output_eol_cursor (struct window *w, struct display_line *dl, int xpos, - face_index findex) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - Lisp_Object window; - - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - GdkGC *gc; - face_index elt = get_builtin_face_cache_index (w, Vtext_cursor_face); - struct face_cachel *cursor_cachel = WINDOW_FACE_CACHEL (w, elt); - - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - WINDOW_BUFFER (w)); - - int x = xpos; - int y = dl->ypos - dl->ascent; - int width = EOL_CURSOR_WIDTH; - int height = dl->ascent + dl->descent - dl->clip; - int cursor_height, cursor_y; - int defheight, defascent; - - window = wrap_window (w); - redisplay_clear_region (window, findex, x, y, width, height); - - if (NILP (w->text_cursor_visible_p)) - return; - - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - default_face_font_info (window, &defascent, 0, &defheight, 0, 0); - - /* make sure the cursor is entirely contained between y and y+height */ - cursor_height = min (defheight, height); - cursor_y = max (y, min (y + height - cursor_height, - dl->ypos - defascent)); - - if (focus) - { - if (NILP (bar_cursor_value)) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, cursor_y, width, cursor_height); - } - else - { - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - - gc = gtk_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - gdk_draw_line (GDK_DRAWABLE (x_win), gc, x + bar_width - 1, cursor_y, - x + bar_width - 1, cursor_y + cursor_height - 1); - } - } - else if (NILP (bar_cursor_value)) - { - gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE, x, cursor_y, width - 1, - cursor_height - 1); - } -} - -static void -gtk_clear_frame_window (Lisp_Object window) -{ - struct window *w = XWINDOW (window); - - if (!NILP (w->vchild)) - { - gtk_clear_frame_windows (w->vchild); - return; - } - - if (!NILP (w->hchild)) - { - gtk_clear_frame_windows (w->hchild); - return; - } - - gtk_clear_to_window_end (w, WINDOW_TEXT_TOP (w), WINDOW_TEXT_BOTTOM (w)); -} - -static void -gtk_clear_frame_windows (Lisp_Object window) -{ - for (; !NILP (window); window = XWINDOW (window)->next) - gtk_clear_frame_window (window); -} - -static void -gtk_clear_frame (struct frame *f) -{ - GdkWindow *x_win = GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)); - int x, y, width, height; - Lisp_Object frame; - - x = FRAME_LEFT_BORDER_START (f); - width = (FRAME_PIXWIDTH (f) - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) - - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) - - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f) - - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)); - /* #### This adjustment by 1 should be being done in the macros. - There is some small differences between when the menubar is on - and off that we still need to deal with. */ - y = FRAME_TOP_BORDER_START (f) - 1; - height = (FRAME_PIXHEIGHT (f) - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) - - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) - - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f) - - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)) + 1; - - gdk_window_clear_area (x_win, x, y, width, height); - - frame = wrap_frame (f); - - if (!UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vdefault_face, frame)) - || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vleft_margin_face, frame)) - || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vright_margin_face, frame))) - { - gtk_clear_frame_windows (f->root_window); - } -} - -static int -gtk_flash (struct device *d) -{ - GdkGCValues gcv; - GdkGC *gc; - GdkColor tmp_fcolor, tmp_bcolor; - Lisp_Object tmp_pixel, frame; - struct frame *f = device_selected_frame (d); - struct window *w = XWINDOW (FRAME_ROOT_WINDOW (f)); - - frame = wrap_frame (f); - - tmp_pixel = FACE_FOREGROUND (Vdefault_face, frame); - tmp_fcolor = * (COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel))); - tmp_pixel = FACE_BACKGROUND (Vdefault_face, frame); - tmp_bcolor = * (COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (tmp_pixel))); - - memset (&gcv, ~0, sizeof (gcv)); /* initialize all slots to ~0 */ - gcv.foreground.pixel = (tmp_fcolor.pixel ^ tmp_bcolor.pixel); - gcv.function = GDK_XOR; - gcv.graphics_exposures = FALSE; - gc = gc_cache_lookup (DEVICE_GTK_GC_CACHE (XDEVICE (f->device)), &gcv, - GDK_GC_FOREGROUND | GDK_GC_FUNCTION | GDK_GC_EXPOSURES); - - gdk_draw_rectangle (GDK_DRAWABLE (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f))), - gc, TRUE, w->pixel_left, w->pixel_top, - w->pixel_width, w->pixel_height); - - gdk_flush (); - -#ifdef HAVE_SELECT - { - int usecs = 100000; - struct timeval tv; - tv.tv_sec = usecs / 1000000L; - tv.tv_usec = usecs % 1000000L; - /* I'm sure someone is going to complain about this... */ - select (0, 0, 0, 0, &tv); - } -#else -#ifdef HAVE_POLL - poll (0, 0, 100); -#else - bite me -#endif -#endif - - gdk_draw_rectangle (GDK_DRAWABLE (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f))), - gc, TRUE, w->pixel_left, w->pixel_top, - w->pixel_width, w->pixel_height); - - gdk_flush (); - - return 1; -} - static void gtk_bevel_area (struct window *w, face_index UNUSED (findex), int x, int y, int width, int height, @@ -1603,29 +101,6 @@ } -/************************************************************************/ -/* initialization */ -/************************************************************************/ - -void -console_type_create_redisplay_gtk (void) -{ - /* redisplay methods */ - CONSOLE_HAS_METHOD (gtk, text_width); - CONSOLE_HAS_METHOD (gtk, output_display_block); - CONSOLE_HAS_METHOD (gtk, divider_height); - CONSOLE_HAS_METHOD (gtk, eol_cursor_width); - CONSOLE_HAS_METHOD (gtk, output_vertical_divider); - CONSOLE_HAS_METHOD (gtk, clear_to_window_end); - CONSOLE_HAS_METHOD (gtk, clear_region); - CONSOLE_HAS_METHOD (gtk, clear_frame); - CONSOLE_HAS_METHOD (gtk, flash); - CONSOLE_HAS_METHOD (gtk, ring_bell); - CONSOLE_HAS_METHOD (gtk, bevel_area); - CONSOLE_HAS_METHOD (gtk, output_string); - CONSOLE_HAS_METHOD (gtk, output_pixmap); -} - /* This makes me feel incredibly dirty... but there is no other way to get this done right other than calling clear_area before every single $#!%@ing piece of text, which I do NOT want to do. */
--- a/src/redisplay-x.c Mon Jan 18 06:21:05 2010 -0600 +++ b/src/redisplay-x.c Mon Jan 18 08:44:49 2010 -0600 @@ -27,163 +27,14 @@ /* Lots of work done by Ben Wing for Mule */ -#include <config.h> -#include "lisp.h" - -#include "buffer.h" -#include "debug.h" -#include "device-impl.h" -#include "faces.h" -#include "file-coding.h" -#include "frame-impl.h" -#include "gutter.h" -#include "redisplay.h" -#include "sysdep.h" -#include "window.h" - -#include "mule-ccl.h" -#include "charset.h" - -#include "console-x-impl.h" -#include "glyphs-x.h" -#include "objects-x-impl.h" -#include "xgccache.h" - -#include "EmacsFrame.h" -#include "EmacsFrameP.h" - -#include "sysproc.h" /* for select() */ - -#include <X11/bitmaps/gray> /* Number of pixels below each line. */ int x_interline_space; /* #### this needs to be implemented, but per-font */ -#define EOL_CURSOR_WIDTH 5 - -static void x_output_vertical_divider (struct window *w, int clear); -static void x_output_blank (struct window *w, struct display_line *dl, - struct rune *rb, int start_pixpos, - int cursor_start, int cursor_width); -static void x_output_hline (struct window *w, struct display_line *dl, - struct rune *rb); -static void x_output_eol_cursor (struct window *w, struct display_line *dl, - int xpos, face_index findex); -static void x_clear_frame (struct frame *f); -static void x_clear_frame_windows (Lisp_Object window); - -#ifdef USE_XFT -#define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ - ? ((unsigned long) (x)) : ((unsigned long) (y))) -#endif /* USE_XFT */ +#define THIS_IS_X #include "redisplay-xlike-inc.c" -/****************************************************************************/ -/* */ -/* X output routines */ -/* */ -/****************************************************************************/ - -static int -x_text_width_single_run (struct frame * USED_IF_XFT (f), - struct face_cachel *cachel, struct textual_run *run) -{ - Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset); - Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst); - if (!fi->proportional_p) - return fi->width * run->len; -#ifdef USE_XFT - else if (FONT_INSTANCE_X_XFTFONT(fi)) - { - static XGlyphInfo glyphinfo; - struct device *d = XDEVICE (f->device); - Display *dpy = DEVICE_X_DISPLAY (d); - - if (run->dimension == 2) { - XftTextExtents16 (dpy, - FONT_INSTANCE_X_XFTFONT(fi), - (XftChar16 *) run->ptr, run->len, &glyphinfo); - } else { - XftTextExtents8 (dpy, - FONT_INSTANCE_X_XFTFONT(fi), - run->ptr, run->len, &glyphinfo); - } - - return glyphinfo.xOff; - } -#endif - else if (FONT_INSTANCE_X_FONT (fi)) - { - if (run->dimension == 2) - return XTextWidth16 (FONT_INSTANCE_X_FONT (fi), - (XChar2b *) run->ptr, run->len); - else - return XTextWidth (FONT_INSTANCE_X_FONT (fi), - (char *) run->ptr, run->len); - } - else - abort(); - return 0; /* shut up GCC */ -} - -/* - x_text_width - - Given a string and a merged face, return the string's length in pixels - when displayed in the fonts associated with the face. - */ - -/* #### Break me out into a separate header */ -int x_text_width (struct frame *f, struct face_cachel *cachel, - const Ichar *str, Charcount len); -int -x_text_width (struct frame *f, struct face_cachel *cachel, - const Ichar *str, Charcount len) -{ - /* !!#### Needs review */ - int width_so_far = 0; - unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); - struct textual_run *runs = alloca_array (struct textual_run, len); - int nruns; - int i; - - nruns = separate_textual_runs (text_storage, runs, str, len, - cachel); - - for (i = 0; i < nruns; i++) - width_so_far += x_text_width_single_run (f, cachel, runs + i); - - return width_so_far; -} - -/***************************************************************************** - x_divider_height - - Return the height of the horizontal divider. This is a function because - divider_height is a device method. - - #### If we add etched horizontal divider lines this will have to get - smarter. - ****************************************************************************/ -static int -x_divider_height (void) -{ - return 1; -} - -/***************************************************************************** - x_eol_cursor_width - - Return the width of the end-of-line cursor. This is a function - because eol_cursor_width is a device method. - ****************************************************************************/ -static int -x_eol_cursor_width (void) -{ - return EOL_CURSOR_WIDTH; -} - /***************************************************************************** x_window_output_begin @@ -207,218 +58,6 @@ } /***************************************************************************** - x_output_display_block - - Given a display line, a block number for that start line, output all - runes between start and end in the specified display block. - ****************************************************************************/ -static void -x_output_display_block (struct window *w, struct display_line *dl, int block, - int start, int end, int start_pixpos, int cursor_start, - int cursor_width, int cursor_height) -{ -#ifndef USE_XFT - struct frame *f = XFRAME (w->frame); -#endif - Ichar_dynarr *buf; - Lisp_Object window; - - struct display_block *db = Dynarr_atp (dl->display_blocks, block); - rune_dynarr *rba = db->runes; - struct rune *rb; - - int elt = start; - face_index findex; - int xpos, width = 0; - Lisp_Object charset = Qunbound; /* Qnil is a valid charset when - MULE is not defined */ - - window = wrap_window (w); - rb = Dynarr_atp (rba, start); - - if (!rb) - /* Nothing to do so don't do anything. */ - return; - - findex = rb->findex; - xpos = rb->xpos; - if (rb->type == RUNE_CHAR) - charset = ichar_charset (rb->object.chr.ch); - - if (end < 0) - end = Dynarr_length (rba); - buf = Dynarr_new (Ichar); - - while (elt < end) - { - rb = Dynarr_atp (rba, elt); - - if (rb->findex == findex && rb->type == RUNE_CHAR - && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON - && EQ (charset, ichar_charset (rb->object.chr.ch))) - { - Dynarr_add (buf, rb->object.chr.ch); - width += rb->width; - elt++; - } - else - { - if (Dynarr_length (buf)) - { - x_output_string (w, dl, buf, xpos, 0, start_pixpos, width, - findex, 0, cursor_start, cursor_width, - cursor_height); - xpos = rb->xpos; - width = 0; - } - Dynarr_reset (buf); - width = 0; - - if (rb->type == RUNE_CHAR) - { - findex = rb->findex; - xpos = rb->xpos; - charset = ichar_charset (rb->object.chr.ch); - - if (rb->cursor_type == CURSOR_ON) - { - if (rb->object.chr.ch == '\n') - { - x_output_eol_cursor (w, dl, xpos, findex); - } - else - { - Dynarr_add (buf, rb->object.chr.ch); - x_output_string (w, dl, buf, xpos, 0, start_pixpos, - rb->width, findex, 1, - cursor_start, cursor_width, - cursor_height); - Dynarr_reset (buf); - } - - xpos += rb->width; - elt++; - } - else if (rb->object.chr.ch == '\n') - { - /* Clear in case a cursor was formerly here. */ - redisplay_clear_region (window, findex, xpos, - DISPLAY_LINE_YPOS (dl), - rb->width, - DISPLAY_LINE_HEIGHT (dl)); - elt++; - } - } - else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE) - { - if (rb->type == RUNE_BLANK) - x_output_blank (w, dl, rb, start_pixpos, cursor_start, - cursor_width); - else - { - /* #### Our flagging of when we need to redraw the - modeline shadows sucks. Since RUNE_HLINE is only used - by the modeline at the moment it is a good bet - that if it gets redrawn then we should also - redraw the shadows. This won't be true forever. - We borrow the shadow_thickness_changed flag for - now. */ - w->shadow_thickness_changed = 1; - x_output_hline (w, dl, rb); - } - - elt++; - if (elt < end) - { - rb = Dynarr_atp (rba, elt); - - findex = rb->findex; - xpos = rb->xpos; - } - } - else if (rb->type == RUNE_DGLYPH) - { - Lisp_Object instance; - struct display_box dbox; - struct display_glyph_area dga; - - redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset, - rb->object.dglyph.yoffset, start_pixpos, - rb->width, &dbox, &dga); - - window = wrap_window (w); - instance = glyph_image_instance (rb->object.dglyph.glyph, - window, ERROR_ME_DEBUG_WARN, 1); - findex = rb->findex; - - if (IMAGE_INSTANCEP (instance)) - { - switch (XIMAGE_INSTANCE_TYPE (instance)) - { - case IMAGE_MONO_PIXMAP: - case IMAGE_COLOR_PIXMAP: - redisplay_output_pixmap (w, instance, &dbox, &dga, findex, - cursor_start, cursor_width, - cursor_height, 0); - break; - - case IMAGE_WIDGET: - if (EQ (XIMAGE_INSTANCE_WIDGET_TYPE (instance), - Qlayout)) - { - redisplay_output_layout (window, instance, &dbox, &dga, findex, - cursor_start, cursor_width, - cursor_height); - break; - } - case IMAGE_SUBWINDOW: - redisplay_output_subwindow (w, instance, &dbox, &dga, findex, - cursor_start, cursor_width, - cursor_height); - break; - - case IMAGE_NOTHING: - /* nothing is as nothing does */ - break; - - case IMAGE_TEXT: - case IMAGE_POINTER: - default: - ABORT (); - } - IMAGE_INSTANCE_OPTIMIZE_OUTPUT - (XIMAGE_INSTANCE (instance)) = 0; - } - - xpos += rb->width; - elt++; - } - else - ABORT (); - } - } - - if (Dynarr_length (buf)) - x_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex, - 0, cursor_start, cursor_width, cursor_height); - - if (dl->modeline - && !EQ (Qzero, w->modeline_shadow_thickness) -#ifndef USE_XFT - /* This optimization doesn't work right with some Xft fonts, which - leave antialiasing turds at the boundary. I don't know if this - is an Xft bug or not, but I think it is. See x_output_string. */ - && (f->clear - || f->windows_structure_changed - || w->shadow_thickness_changed) -#endif - ) - bevel_modeline (w, dl); - - Dynarr_free (buf); -} - -/***************************************************************************** x_bevel_area Draw shadows for the given area in the given face. @@ -544,1072 +183,6 @@ } /***************************************************************************** - x_get_gc - - Given a number of parameters return a GC with those properties. - ****************************************************************************/ -static GC -x_get_gc (struct device *d, Lisp_Object font, Lisp_Object fg, Lisp_Object bg, - Lisp_Object bg_pmap, Lisp_Object lwidth) -{ - XGCValues gcv; - unsigned long mask; - - memset (&gcv, ~0, sizeof (XGCValues)); - gcv.graphics_exposures = False; - /* Make absolutely sure that we don't pick up a clipping region in - the GC returned by this function. */ - gcv.clip_mask = None; - gcv.clip_x_origin = 0; - gcv.clip_y_origin = 0; - gcv.fill_style = FillSolid; - mask = GCGraphicsExposures | GCClipMask | GCClipXOrigin | GCClipYOrigin; - mask |= GCFillStyle; - - if (!NILP (font) -#ifdef USE_XFT - /* Only set the font if it's a core font */ - /* the renderfont will be set elsewhere (not part of gc) */ - && !FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font)) -#endif - ) - { - gcv.font = FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font))->fid; - mask |= GCFont; - } - - /* evil kludge! */ - if (!NILP (fg) && !COLOR_INSTANCEP (fg) && !INTP (fg)) - { - /* #### I fixed one case where this was getting hit. It was a - bad macro expansion (compiler bug). */ - stderr_out ("Help! x_get_gc got a bogus fg value! fg = "); - debug_print (fg); - fg = Qnil; - } - - if (!NILP (fg)) - { - if (COLOR_INSTANCEP (fg)) - gcv.foreground = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (fg)).pixel; - else - gcv.foreground = XINT (fg); - mask |= GCForeground; - } - - if (!NILP (bg)) - { - if (COLOR_INSTANCEP (bg)) - gcv.background = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (bg)).pixel; - else - gcv.background = XINT (bg); - mask |= GCBackground; - } - - /* This special case comes from a request to draw text with a face which has - the dim property. We'll use a stippled foreground GC. */ - if (EQ (bg_pmap, Qdim)) - { - assert (DEVICE_X_GRAY_PIXMAP (d) != None); - - gcv.fill_style = FillStippled; - gcv.stipple = DEVICE_X_GRAY_PIXMAP (d); - mask |= (GCFillStyle | GCStipple); - } - else if (IMAGE_INSTANCEP (bg_pmap) - && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - { - if (XIMAGE_INSTANCE_PIXMAP_DEPTH (bg_pmap) == 0) - { - gcv.fill_style = FillOpaqueStippled; - gcv.stipple = XIMAGE_INSTANCE_X_PIXMAP (bg_pmap); - mask |= (GCStipple | GCFillStyle); - } - else - { - gcv.fill_style = FillTiled; - gcv.tile = XIMAGE_INSTANCE_X_PIXMAP (bg_pmap); - mask |= (GCTile | GCFillStyle); - } - } - - if (!NILP (lwidth)) - { - gcv.line_width = XINT (lwidth); - mask |= GCLineWidth; - } - -#if 0 - debug_out ("\nx_get_gc: calling gc_cache_lookup\n"); -#endif - return gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask); -} - -/***************************************************************************** - x_output_string - - Given a string and a starting position, output that string in the - given face. If cursor is true, draw a cursor around the string. - Correctly handles multiple charsets in the string. - - The meaning of the parameters is something like this: - - W Window that the text is to be displayed in. - DL Display line that this text is on. The values in the - structure are used to determine the vertical position and - clipping range of the text. - BUF Dynamic array of Ichars specifying what is actually to be - drawn. - XPOS X position in pixels where the text should start being drawn. - XOFFSET Number of pixels to be chopped off the left side of the - text. The effect is as if the text were shifted to the - left this many pixels and clipped at XPOS. - CLIP_START Clip everything left of this X position. - WIDTH Clip everything right of XPOS + WIDTH. - FINDEX Index for the face cache element describing how to display - the text. - CURSOR #### I don't understand this. There's something - strange and overcomplexified with this variable. - Chuck, explain please? - CURSOR_START Starting X position of cursor. - CURSOR_WIDTH Width of cursor in pixels. - CURSOR_HEIGHT Height of cursor in pixels. - - Starting Y position of cursor is the top of the text line. - The cursor is drawn sometimes whether or not CURSOR is set. ??? - ****************************************************************************/ -void -x_output_string (struct window *w, struct display_line *dl, - Ichar_dynarr *buf, int xpos, int xoffset, int clip_start, - int width, face_index findex, int cursor, - int cursor_start, int cursor_width, int cursor_height) -{ - /* General variables */ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - Lisp_Object window = wrap_window (w); - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - - int clip_end; - - /* Cursor-related variables */ - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - int cursor_clip; - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - WINDOW_BUFFER (w)); - struct face_cachel *cursor_cachel = 0; - - /* Text-related variables */ - Lisp_Object bg_pmap; - GC bgc, gc; - int height = DISPLAY_LINE_HEIGHT (dl); - int ypos = DISPLAY_LINE_YPOS (dl); - int len = Dynarr_length (buf); - unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); - struct textual_run *runs = alloca_array (struct textual_run, len); - int nruns; - int i; - struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex); - - int use_x_font = 1; /* #### bogus!! - The logic of this function needs review! */ -#ifdef USE_XFT - Colormap cmap = DEVICE_X_COLORMAP (d); - Visual *visual = DEVICE_X_VISUAL (d); - static XftColor fg, bg; - XftDraw *xftDraw; - - /* Lazily initialize frame's xftDraw member. */ - if (!FRAME_X_XFTDRAW (f)) { - FRAME_X_XFTDRAW (f) = XftDrawCreate (dpy, x_win, visual, cmap); - } - xftDraw = FRAME_X_XFTDRAW (f); - - /* #### This will probably cause asserts when passed a Lisp integer for a - color. See ca. line 759 this file. - #### Maybe xft_convert_color should take an XColor, not a pixel. */ -#define XFT_FROB_LISP_COLOR(color, dim) \ - xft_convert_color (dpy, cmap, visual, \ - COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color)).pixel, \ - (dim)) -#endif - - if (width < 0) - width = x_text_width (f, cachel, Dynarr_atp (buf, 0), Dynarr_length (buf)); - - /* Regularize the variables passed in. */ - - if (clip_start < xpos) - clip_start = xpos; - clip_end = xpos + width; - if (clip_start >= clip_end) - /* It's all clipped out. */ - return; - - xpos -= xoffset; - - /* make sure the area we are about to display is subwindow free. */ - redisplay_unmap_subwindows_maybe (f, clip_start, ypos, - clip_end - clip_start, height); - - cursor_clip = (cursor_start >= clip_start && - cursor_start < clip_end); - - /* This cursor code is really a mess. */ - if (!NILP (w->text_cursor_visible_p) - && (cursor - || cursor_clip - || (cursor_width - && (cursor_start + cursor_width >= clip_start) - && !NILP (bar_cursor_value)))) - { - /* These have to be in separate statements in order to avoid a - compiler bug. */ - face_index sucks = get_builtin_face_cache_index (w, Vtext_cursor_face); - cursor_cachel = WINDOW_FACE_CACHEL (w, sucks); - - /* We have to reset this since any call to WINDOW_FACE_CACHEL - may cause the cache to resize and any pointers to it to - become invalid. */ - cachel = WINDOW_FACE_CACHEL (w, findex); - } - -#ifdef HAVE_XIM - if (cursor && focus && (cursor_start == clip_start) && cursor_height) - XIM_SetSpotLocation (f, xpos - 2, dl->ypos + dl->descent - 2); -#endif /* HAVE_XIM */ - - bg_pmap = cachel->background_pixmap; - if (!IMAGE_INSTANCEP (bg_pmap) - || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - bg_pmap = Qnil; - - if ((cursor && focus && NILP (bar_cursor_value) - && !NILP (w->text_cursor_visible_p)) || NILP (bg_pmap)) - bgc = 0; - else - { - bgc = x_get_gc (d, Qnil, cachel->foreground, cachel->background, - bg_pmap, Qnil); - } - - if (bgc) - { - XFillRectangle (dpy, x_win, bgc, clip_start, - ypos, clip_end - clip_start, - height); - } - - nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0), - Dynarr_length (buf), cachel); - - for (i = 0; i < nruns; i++) - { - Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset); - Lisp_Font_Instance *fi = XFONT_INSTANCE (font); - int this_width; - int need_clipping; - - if (EQ (font, Vthe_null_font_instance)) - continue; - - this_width = x_text_width_single_run (f, cachel, runs + i); - need_clipping = (dl->clip || clip_start > xpos || - clip_end < xpos + this_width); - - /* XDrawImageString only clears the area equal to the height of - the given font. It is possible that a font is being displayed - on a line taller than it is, so this would cause us to fail to - clear some areas. */ - if ((int) fi->height < (int) (height + dl->clip + dl->top_clip)) - { - int clear_start = max (xpos, clip_start); - int clear_end = min (xpos + this_width, clip_end); - - if (cursor) - { - int ypos1_line, ypos1_string, ypos2_line, ypos2_string; - - ypos1_string = dl->ypos - fi->ascent; - ypos2_string = dl->ypos + fi->descent; - ypos1_line = ypos; - ypos2_line = ypos1_line + height; - - /* Make sure we don't clear below the real bottom of the - line. */ - if (ypos1_string > ypos2_line) - ypos1_string = ypos2_line; - if (ypos2_string > ypos2_line) - ypos2_string = ypos2_line; - - if (ypos1_line < ypos1_string) - { - redisplay_clear_region (window, findex, clear_start, ypos1_line, - clear_end - clear_start, - ypos1_string - ypos1_line); - } - - if (ypos2_line > ypos2_string) - { - redisplay_clear_region (window, findex, clear_start, ypos2_string, - clear_end - clear_start, - ypos2_line - ypos2_string); - } - } - else - { - redisplay_clear_region (window, findex, clear_start, - ypos, clear_end - clear_start, - height); - } - } - - if (cursor && cursor_cachel && focus && NILP (bar_cursor_value)) - { -#ifdef USE_XFT - fg = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0); - bg = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0); -#endif - gc = x_get_gc (d, font, cursor_cachel->foreground, - cursor_cachel->background, Qnil, Qnil); - } - else if (cachel->dim) - { - /* Ensure the gray bitmap exists */ - if (DEVICE_X_GRAY_PIXMAP (d) == None) - DEVICE_X_GRAY_PIXMAP (d) = - XCreateBitmapFromData (dpy, x_win, (char *)gray_bits, - gray_width, gray_height); - - /* Request a GC with the gray stipple pixmap to draw dimmed text */ -#ifdef USE_XFT - fg = XFT_FROB_LISP_COLOR (cachel->foreground, 1); - bg = XFT_FROB_LISP_COLOR (cachel->background, 0); -#endif - gc = x_get_gc (d, font, cachel->foreground, cachel->background, - Qdim, Qnil); - } - else - { -#ifdef USE_XFT - fg = XFT_FROB_LISP_COLOR (cachel->foreground, 0); - bg = XFT_FROB_LISP_COLOR (cachel->background, 0); -#endif - gc = x_get_gc (d, font, cachel->foreground, cachel->background, - Qnil, Qnil); - } -#ifdef USE_XFT - { - XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi); - - if (rf) - { - use_x_font = 0; - if (need_clipping) - { - Region clip_reg = XCreateRegion(); - XRectangle clip_box = { clip_start, ypos, - clip_end - clip_start, height }; - - XUnionRectWithRegion (&clip_box, clip_reg, clip_reg); - XftDrawSetClip(xftDraw, clip_reg); - XDestroyRegion(clip_reg); - } - - if (!bgc) - { - /* #### Neither rect_height nor XftTextExtents as computed - below handles the vertical space taken up by antialiasing, - which for some fonts (eg, Bitstream Vera Sans Mono-16 on - my Mac PowerBook G4) leaves behind orphaned dots on - insertion or deletion earlier in the line, especially in - the case of the underscore character. - Interestingly, insertion or deletion of a single character - immediately after a refresh does not leave any droppings, - but any further insertions or deletions do. - While adding a pixel to rect_height (mostly) takes care of - this, it trashes aggressively laid-out elements like the - modeline (overwriting part of the bevel). - OK, unconditionally redraw the bevel, and increment - rect_height by 1. See x_output_display_block. -- sjt */ - struct textual_run *run = &runs[i]; - int rect_width = x_text_width_single_run (f, cachel, run); -#ifndef USE_XFTTEXTENTS_TO_AVOID_FONT_DROPPINGS - int rect_height = FONT_INSTANCE_ASCENT(fi) - + FONT_INSTANCE_DESCENT(fi) + 1; -#else - int rect_height = FONT_INSTANCE_ASCENT(fi) - + FONT_INSTANCE_DESCENT(fi); - XGlyphInfo gi; - if (run->dimension == 2) { - XftTextExtents16 (dpy, - FONT_INSTANCE_X_XFTFONT(fi), - (XftChar16 *) run->ptr, run->len, &gi); - } else { - XftTextExtents8 (dpy, - FONT_INSTANCE_X_XFTFONT(fi), - run->ptr, run->len, &gi); - } - rect_height = rect_height > gi.height - ? rect_height : gi.height; -#endif - - XftDrawRect (xftDraw, &bg, - xpos, ypos, rect_width, rect_height); - } - - if (runs[i].dimension == 1) - XftDrawString8 (xftDraw, &fg, rf, xpos, dl->ypos, - runs[i].ptr, runs[i].len); - else - XftDrawString16 (xftDraw, &fg, rf, xpos, dl->ypos, - (XftChar16 *) runs[i].ptr, runs[i].len); - } - } -#endif - { - if (use_x_font) - { - if (need_clipping) - { - XRectangle clip_box[1]; - - clip_box[0].x = 0; - clip_box[0].y = 0; - clip_box[0].width = clip_end - clip_start; - clip_box[0].height = height; - - XSetClipRectangles (dpy, gc, clip_start, ypos, - clip_box, 1, YXBanded); - } - - if (runs[i].dimension == 1) - (bgc ? XDrawString : XDrawImageString) - (dpy, x_win, gc, xpos, dl->ypos, - (char *) runs[i].ptr, runs[i].len); - else - (bgc ? XDrawString16 : XDrawImageString16) - (dpy, x_win, gc, xpos, dl->ypos, - (XChar2b *) runs[i].ptr, runs[i].len); - } - } - - /* We draw underlines in the same color as the text. */ - if (cachel->underline) - { - int upos, uthick; - unsigned long upos_ext, uthick_ext; - XFontStruct *fs = - use_x_font ? FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)) : 0; - /* #### the logic of the next two may be suboptimal: we may want - to use the POSITION and/or THICKNESS information with Xft */ - if (fs && XGetFontProperty (fs, XA_UNDERLINE_POSITION, &upos_ext)) - upos = (int) upos_ext; - else - upos = dl->descent / 2; - if (fs && XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext)) - uthick = (int) uthick_ext; - else - uthick = 1; - if (dl->ypos + upos < dl->ypos + dl->descent - dl->clip) - { - if (dl->ypos + upos + uthick > dl->ypos + dl->descent - dl->clip) - uthick = dl->descent - dl->clip - upos; - - if (uthick == 1) - { - XDrawLine (dpy, x_win, gc, xpos, dl->ypos + upos, - xpos + this_width, dl->ypos + upos); - } - else if (uthick > 1) - { - XFillRectangle (dpy, x_win, gc, xpos, - dl->ypos + upos, this_width, uthick); - } - } - } - - if (cachel->strikethru) - { - int ascent, descent, upos, uthick; - unsigned long ascent_ext, descent_ext, uthick_ext; - XFontStruct *fs = FONT_INSTANCE_X_FONT (fi); - - if (!use_x_font) - { - ascent = dl->ascent; - descent = dl->descent; - uthick = 1; - } - else - { - if (!XGetFontProperty (fs, XA_STRIKEOUT_ASCENT, &ascent_ext)) - ascent = fs->ascent; - else - ascent = (int) ascent_ext; - if (!XGetFontProperty (fs, XA_STRIKEOUT_DESCENT, &descent_ext)) - descent = fs->descent; - else - descent = (int) descent_ext; - if (!XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext)) - uthick = 1; - else - uthick = (int) uthick_ext; - } - - upos = ascent - ((ascent + descent) / 2) + 1; - - /* Generally, upos will be positive (above the baseline),so - subtract */ - if (dl->ypos - upos < dl->ypos + dl->descent - dl->clip) - { - if (dl->ypos - upos + uthick > dl->ypos + dl->descent - dl->clip) - uthick = dl->descent - dl->clip + upos; - - if (uthick == 1) - XDrawLine (dpy, x_win, gc, xpos, dl->ypos - upos, - xpos + this_width, dl->ypos - upos); - else if (uthick > 1) - XFillRectangle (dpy, x_win, gc, xpos, dl->ypos + upos, - this_width, uthick); - } - } - - /* Restore the GC */ - if (need_clipping) - { -#ifdef USE_XFT - if (!use_x_font) - { - XftDrawSetClip(xftDraw, 0); - } - else - { -#endif - XSetClipMask (dpy, gc, None); - XSetClipOrigin (dpy, gc, 0, 0); -#ifdef USE_XFT - } -#endif - } - - /* If we are actually superimposing the cursor then redraw with just - the appropriate section highlighted. */ - if (cursor_clip && !cursor && focus && cursor_cachel) - { -#ifdef USE_XFT - if (!use_x_font) /* Xft */ - { - XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi); - - { /* set up clipping */ - Region clip_reg = XCreateRegion(); - XRectangle clip_box = { cursor_start, ypos, - cursor_width, height }; - - XUnionRectWithRegion (&clip_box, clip_reg, clip_reg); - XftDrawSetClip(xftDraw, clip_reg); - XDestroyRegion(clip_reg); - } - { /* draw background rectangle & draw text */ - int rect_height = FONT_INSTANCE_ASCENT(fi) - + FONT_INSTANCE_DESCENT(fi); - int rect_width = x_text_width_single_run(f, cachel, &runs[i]); - XftColor xft_color; - - xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0); - XftDrawRect (xftDraw, &xft_color, - xpos, ypos, rect_width, rect_height); - - xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0); - if (runs[i].dimension == 1) - XftDrawString8 (xftDraw, &xft_color, rf, xpos, dl->ypos, - runs[i].ptr, runs[i].len); - else - XftDrawString16 (xftDraw, &xft_color, rf, xpos, dl->ypos, - (XftChar16 *) runs[i].ptr, runs[i].len); - } - - XftDrawSetClip(xftDraw, 0); - } - else /* core font, not Xft */ - { -#endif - GC cgc; - XRectangle clip_box[1]; - - cgc = x_get_gc (d, font, cursor_cachel->foreground, - cursor_cachel->background, Qnil, Qnil); - - clip_box[0].x = 0; - clip_box[0].y = 0; - clip_box[0].width = cursor_width; - clip_box[0].height = height; - - XSetClipRectangles (dpy, cgc, cursor_start, ypos, - clip_box, 1, YXBanded); - if (runs[i].dimension == 1) - XDrawImageString (dpy, x_win, cgc, xpos, dl->ypos, - (char *) runs[i].ptr, runs[i].len); - else - XDrawImageString16 (dpy, x_win, cgc, xpos, dl->ypos, - (XChar2b *) runs[i].ptr, runs[i].len); - - XSetClipMask (dpy, cgc, None); - XSetClipOrigin (dpy, cgc, 0, 0); -#ifdef USE_XFT - } -#endif - } - - xpos += this_width; - } - - /* Draw the non-focus box or bar-cursor as needed. */ - /* Can't this logic be simplified? */ - if (cursor_cachel - && ((cursor && !focus && NILP (bar_cursor_value)) - || (cursor_width - && (cursor_start + cursor_width >= clip_start) - && !NILP (bar_cursor_value)))) - { - int tmp_height, tmp_y; - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - int need_clipping = (cursor_start < clip_start - || clip_end < cursor_start + cursor_width); - - /* #### This value is correct (as far as I know) because - all of the times we need to draw this cursor, we will - be called with exactly one character, so we know we - can always use runs[0]. - - This is bogus as all hell, however. The cursor handling in - this function is way bogus and desperately needs to be - cleaned up. (In particular, the drawing of the cursor should - really really be separated out of this function. This may be - a bit tricky now because this function itself does way too - much stuff, a lot of which needs to be moved into - redisplay.c.) This is the only way to be able to easily add - new cursor types or (e.g.) make the bar cursor be able to - span two characters instead of overlaying just one. */ - int bogusly_obtained_ascent_value = - XFONT_INSTANCE (FACE_CACHEL_FONT (cachel, runs[0].charset))->ascent; - - if (!NILP (bar_cursor_value)) - { - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - } - else - { - gc = x_get_gc (d, Qnil, cursor_cachel->background, - Qnil, Qnil, Qnil); - } - - tmp_y = dl->ypos - bogusly_obtained_ascent_value; - tmp_height = cursor_height; - if (tmp_y + tmp_height > (int) (ypos + height)) - { - tmp_y = ypos + height - tmp_height; - if (tmp_y < (int) ypos) - tmp_y = ypos; - tmp_height = ypos + height - tmp_y; - } - - if (need_clipping) - { - XRectangle clip_box[1]; - clip_box[0].x = 0; - clip_box[0].y = 0; - clip_box[0].width = clip_end - clip_start; - clip_box[0].height = tmp_height; - XSetClipRectangles (dpy, gc, clip_start, tmp_y, - /* #### why not Unsorted? */ - clip_box, 1, YXBanded); - } - - if (!focus && NILP (bar_cursor_value)) - { - XDrawRectangle (dpy, x_win, gc, cursor_start, tmp_y, - cursor_width - 1, tmp_height - 1); - } - else if (focus && !NILP (bar_cursor_value)) - { - XDrawLine (dpy, x_win, gc, cursor_start + bar_width - 1, tmp_y, - cursor_start + bar_width - 1, tmp_y + tmp_height - 1); - } - - /* Restore the GC */ - if (need_clipping) - { - XSetClipMask (dpy, gc, None); - XSetClipOrigin (dpy, gc, 0, 0); - } - } - -#ifdef USE_XFT -#undef XFT_FROB_LISP_COLOR -#endif - -} - -void -x_output_x_pixmap (struct frame *f, Lisp_Image_Instance *p, int x, - int y, int xoffset, int yoffset, - int width, int height, unsigned long fg, unsigned long bg, - GC override_gc) -{ - struct device *d = XDEVICE (f->device); - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - - GC gc; - XGCValues gcv; - unsigned long pixmap_mask; - - if (!override_gc) - { - memset (&gcv, ~0, sizeof (XGCValues)); - gcv.graphics_exposures = False; - gcv.foreground = fg; - gcv.background = bg; - pixmap_mask = GCForeground | GCBackground | GCGraphicsExposures; - - if (IMAGE_INSTANCE_X_MASK (p)) - { - gcv.function = GXcopy; - gcv.clip_mask = IMAGE_INSTANCE_X_MASK (p); - gcv.clip_x_origin = x - xoffset; - gcv.clip_y_origin = y - yoffset; - pixmap_mask |= (GCFunction | GCClipMask | GCClipXOrigin | - GCClipYOrigin); - /* Can't set a clip rectangle because we already have a mask. - Is it possible to get an equivalent effect by changing the - args to XCopyArea below rather than messing with a clip box? - - dkindred@cs.cmu.edu - Yes. We don't clip at all now - andy@xemacs.org - */ - } - - gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, pixmap_mask); - } - else - { - gc = override_gc; - /* override_gc might have a mask already--we don't want to nuke it. - Maybe we can insist that override_gc have no mask, or use - one of the suggestions above. */ - } - - /* depth of 0 means it's a bitmap, not a pixmap, and we should use - XCopyPlane (1 = current foreground color, 0 = background) instead - of XCopyArea, which means that the bits in the pixmap are actual - pixel values, instead of symbolic of fg/bg. */ - if (IMAGE_INSTANCE_PIXMAP_DEPTH (p) > 0) - { - XCopyArea (dpy, - IMAGE_INSTANCE_X_PIXMAP_SLICE - (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc, xoffset, - yoffset, width, - height, x, y); - } - else - { - XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP_SLICE - (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc, - xoffset, yoffset, width, height, x, y, 1L); - } -} - -static void -x_output_pixmap (struct window *w, Lisp_Object image_instance, - struct display_box *db, struct display_glyph_area *dga, - face_index findex, int cursor_start, int cursor_width, - int cursor_height, int UNUSED (bg_pixmap)) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance); - - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - - /* Output the pixmap. */ - { - Lisp_Object tmp_pixel; - XColor tmp_bcolor, tmp_fcolor; - - tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex); - tmp_fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex); - tmp_bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - - x_output_x_pixmap (f, p, db->xpos, db->ypos, - dga->xoffset, dga->yoffset, - dga->width, dga->height, - tmp_fcolor.pixel, tmp_bcolor.pixel, 0); - } - - /* Draw a cursor over top of the pixmap. */ - if (cursor_width && cursor_height && (cursor_start >= db->xpos) - && !NILP (w->text_cursor_visible_p) - && (cursor_start < db->xpos + dga->width)) - { - GC gc; - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - struct face_cachel *cursor_cachel = - WINDOW_FACE_CACHEL (w, - get_builtin_face_cache_index - (w, Vtext_cursor_face)); - - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - if (cursor_width > db->xpos + dga->width - cursor_start) - cursor_width = db->xpos + dga->width - cursor_start; - - if (focus) - { - XFillRectangle (dpy, x_win, gc, cursor_start, db->ypos, cursor_width, - cursor_height); - } - else - { - XDrawRectangle (dpy, x_win, gc, cursor_start, db->ypos, cursor_width, - cursor_height); - } - } -} - -/***************************************************************************** - x_output_vertical_divider - - Draw a vertical divider down the right side of the given window. - ****************************************************************************/ -static void -x_output_vertical_divider (struct window *w, int clear) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - Lisp_Object tmp_pixel; - XColor tmp_color; - XGCValues gcv; - GC background_gc; - enum edge_style style; - - unsigned long mask; - int x, y1, y2, width, shadow_thickness, spacing, line_width; - face_index div_face = - get_builtin_face_cache_index (w, Vvertical_divider_face); - - width = window_divider_width (w); - shadow_thickness = XINT (w->vertical_divider_shadow_thickness); - spacing = XINT (w->vertical_divider_spacing); - line_width = XINT (w->vertical_divider_line_width); - x = WINDOW_RIGHT (w) - width; - y1 = WINDOW_TOP (w); - y2 = WINDOW_BOTTOM (w); - - memset (&gcv, ~0, sizeof (XGCValues)); - - tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, div_face); - tmp_color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - - /* First, get the GC's. */ - gcv.background = tmp_color.pixel; - gcv.foreground = tmp_color.pixel; - gcv.graphics_exposures = False; - mask = GCForeground | GCBackground | GCGraphicsExposures; - background_gc = gc_cache_lookup (DEVICE_X_GC_CACHE (d), &gcv, mask); - - /* Clear the divider area first. This needs to be done when a - window split occurs. */ - if (clear) - XClearArea (dpy, x_win, x, y1, width, y2 - y1, False); - - /* Draw the divider line. */ - XFillRectangle (dpy, x_win, background_gc, - x + spacing + shadow_thickness, y1, - line_width, y2 - y1); - - if (shadow_thickness < 0) - { - shadow_thickness = -shadow_thickness; - style = EDGE_BEVEL_IN; - } - else - { - style = EDGE_BEVEL_OUT; - } - - /* Draw the shadows around the divider line */ - x_bevel_area (w, div_face, x + spacing, y1, - width - 2 * spacing, y2 - y1, - shadow_thickness, EDGE_ALL, style); -} - -/***************************************************************************** - x_output_blank - - Output a blank by clearing the area it covers in the foreground color - of its face. - ****************************************************************************/ -static void -x_output_blank (struct window *w, struct display_line *dl, struct rune *rb, - int start_pixpos, int cursor_start, int cursor_width) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - GC gc; - struct face_cachel *cursor_cachel = - WINDOW_FACE_CACHEL (w, - get_builtin_face_cache_index - (w, Vtext_cursor_face)); - Lisp_Object bg_pmap; - Lisp_Object buffer = WINDOW_BUFFER (w); - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - buffer); - - int x = rb->xpos; - int y = DISPLAY_LINE_YPOS (dl); - int width = rb->width; - int height = DISPLAY_LINE_HEIGHT (dl); - - /* Unmap all subwindows in the area we are going to blank. */ - redisplay_unmap_subwindows_maybe (f, x, y, width, height); - - if (start_pixpos > x) - { - if (start_pixpos >= (x + width)) - return; - else - { - width -= (start_pixpos - x); - x = start_pixpos; - } - } - - bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex); - if (!IMAGE_INSTANCEP (bg_pmap) - || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) - bg_pmap = Qnil; - - if (NILP (bg_pmap)) - gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - else - gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), - WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), bg_pmap, - Qnil); - - XFillRectangle (dpy, x_win, gc, x, y, width, height); - - /* If this rune is marked as having the cursor, then it is actually - representing a tab. */ - if (!NILP (w->text_cursor_visible_p) - && (rb->cursor_type == CURSOR_ON - || (cursor_width - && (cursor_start + cursor_width > x) - && cursor_start < (x + width)))) - { - int cursor_height, cursor_y; - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - Lisp_Font_Instance *fi; - - fi = XFONT_INSTANCE (FACE_CACHEL_FONT - (WINDOW_FACE_CACHEL (w, rb->findex), - Vcharset_ascii)); - - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - cursor_y = dl->ypos - fi->ascent; - cursor_height = fi->height; - if (cursor_y + cursor_height > y + height) - cursor_height = y + height - cursor_y; - - if (focus) - { - if (NILP (bar_cursor_value)) - { - XFillRectangle (dpy, x_win, gc, cursor_start, cursor_y, - fi->width, cursor_height); - } - else - { - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - XDrawLine (dpy, x_win, gc, cursor_start + bar_width - 1, - cursor_y, cursor_start + bar_width - 1, - cursor_y + cursor_height - 1); - } - } - else if (NILP (bar_cursor_value)) - { - XDrawRectangle (dpy, x_win, gc, cursor_start, cursor_y, - fi->width - 1, cursor_height - 1); - } - } -} - -/***************************************************************************** - x_output_hline - - Output a horizontal line in the foreground of its face. - ****************************************************************************/ -static void -x_output_hline (struct window *w, struct display_line *dl, struct rune *rb) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - GC gc; - - int x = rb->xpos; - int width = rb->width; - int height = DISPLAY_LINE_HEIGHT (dl); - int ypos1, ypos2, ypos3, ypos4; - - ypos1 = DISPLAY_LINE_YPOS (dl); - ypos2 = ypos1 + rb->object.hline.yoffset; - ypos3 = ypos2 + rb->object.hline.thickness; - ypos4 = dl->ypos + dl->descent - dl->clip; - - /* First clear the area not covered by the line. */ - if (height - rb->object.hline.thickness > 0) - { - gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - - if (ypos2 - ypos1 > 0) - XFillRectangle (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1); - if (ypos4 - ypos3 > 0) - XFillRectangle (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1); - } - - /* Now draw the line. */ - gc = x_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), - Qnil, Qnil, Qnil); - - if (ypos2 < ypos1) - ypos2 = ypos1; - if (ypos3 > ypos4) - ypos3 = ypos4; - - if (ypos3 - ypos2 > 0) - XFillRectangle (dpy, x_win, gc, x, ypos2, width, ypos3 - ypos2); -} - -/***************************************************************************** x_output_shadows Draw a shadow around the given area using the given GC's. It is the @@ -1761,261 +334,6 @@ } } -/**************************************************************************** - x_clear_region - - Clear the area in the box defined by the given parameters using the - given face. - ****************************************************************************/ -static void -x_clear_region (Lisp_Object UNUSED (locale), struct device* d, - struct frame* f, face_index UNUSED (findex), - int x, int y, - int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, - Lisp_Object background_pixmap) -{ - Display *dpy; - Window x_win; - GC gc = NULL; - - dpy = DEVICE_X_DISPLAY (d); - x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - - if (!UNBOUNDP (background_pixmap)) - { - gc = x_get_gc (d, Qnil, fcolor, bcolor, background_pixmap, Qnil); - } - - if (gc) - XFillRectangle (dpy, x_win, gc, x, y, width, height); - else - XClearArea (dpy, x_win, x, y, width, height, False); -} - -/***************************************************************************** - x_output_eol_cursor - - Draw a cursor at the end of a line. The end-of-line cursor is - narrower than the normal cursor. - ****************************************************************************/ -static void -x_output_eol_cursor (struct window *w, struct display_line *dl, int xpos, - face_index findex) -{ - struct frame *f = XFRAME (w->frame); - struct device *d = XDEVICE (f->device); - Lisp_Object window; - - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - GC gc; - face_index elt = get_builtin_face_cache_index (w, Vtext_cursor_face); - struct face_cachel *cursor_cachel = WINDOW_FACE_CACHEL (w, elt); - - int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); - Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, - WINDOW_BUFFER (w)); - - int x = xpos; - int y = DISPLAY_LINE_YPOS (dl); - int width = EOL_CURSOR_WIDTH; - int height = DISPLAY_LINE_HEIGHT (dl); - int cursor_height, cursor_y; - int defheight, defascent; - - window = wrap_window (w); - redisplay_clear_region (window, findex, x, y, width, height); - - if (NILP (w->text_cursor_visible_p)) - return; - - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); - - default_face_font_info (window, &defascent, 0, &defheight, 0, 0); - - /* make sure the cursor is entirely contained between y and y+height */ - cursor_height = min (defheight, height); - cursor_y = max (y, min (y + height - cursor_height, - dl->ypos - defascent)); - - if (focus) - { -#ifdef HAVE_XIM - XIM_SetSpotLocation (f, x - 2 , cursor_y + cursor_height - 2); -#endif /* HAVE_XIM */ - - if (NILP (bar_cursor_value)) - { - XFillRectangle (dpy, x_win, gc, x, cursor_y, width, cursor_height); - } - else - { - int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; - - gc = x_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, - make_int (bar_width)); - XDrawLine (dpy, x_win, gc, x + bar_width - 1, cursor_y, - x + bar_width - 1, cursor_y + cursor_height - 1); - } - } - else if (NILP (bar_cursor_value)) - { - XDrawRectangle (dpy, x_win, gc, x, cursor_y, width - 1, - cursor_height - 1); - } -} - -static void -x_clear_frame_window (Lisp_Object window) -{ - struct window *w = XWINDOW (window); - - if (!NILP (w->vchild)) - { - x_clear_frame_windows (w->vchild); - return; - } - - if (!NILP (w->hchild)) - { - x_clear_frame_windows (w->hchild); - return; - } - - redisplay_clear_to_window_end (w, WINDOW_TEXT_TOP (w), - WINDOW_TEXT_BOTTOM (w)); -} - -static void -x_clear_frame_windows (Lisp_Object window) -{ - for (; !NILP (window); window = XWINDOW (window)->next) - x_clear_frame_window (window); -} - -static void -x_clear_frame (struct frame *f) -{ - struct device *d = XDEVICE (f->device); - Display *dpy = DEVICE_X_DISPLAY (d); - Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - int x, y, width, height; - Lisp_Object frame; - - x = FRAME_LEFT_BORDER_START (f); - width = (FRAME_PIXWIDTH (f) - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) - - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) - - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f) - - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)); - /* #### This adjustment by 1 should be being done in the macros. - There is some small differences between when the menubar is on - and off that we still need to deal with. */ - y = FRAME_TOP_BORDER_START (f) - 1; - height = (FRAME_PIXHEIGHT (f) - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) - - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) - - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f) - - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)) + 1; - - XClearArea (dpy, x_win, x, y, width, height, False); - - frame = wrap_frame (f); - - if (!UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vdefault_face, frame)) - || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vleft_margin_face, frame)) - || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vright_margin_face, frame))) - { - x_clear_frame_windows (f->root_window); - } - - if (!(check_if_pending_expose_event (d))) - XFlush (DEVICE_X_DISPLAY (d)); -} - -/* briefly swap the foreground and background colors. - */ - -static int -x_flash (struct device *d) -{ - Display *dpy; - Window win; - XGCValues gcv; - GC gc; - XColor tmp_fcolor, tmp_bcolor; - Lisp_Object tmp_pixel, frame; - struct frame *f = device_selected_frame (d); - struct window *w = XWINDOW (FRAME_ROOT_WINDOW (f)); - Widget shell = FRAME_X_SHELL_WIDGET (f); - int flash_height; - - frame = wrap_frame (f); - - tmp_pixel = FACE_FOREGROUND (Vdefault_face, frame); - tmp_fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - tmp_pixel = FACE_BACKGROUND (Vdefault_face, frame); - tmp_bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (tmp_pixel)); - - dpy = XtDisplay (shell); - win = XtWindow (FRAME_X_TEXT_WIDGET (f)); - memset (&gcv, ~0, sizeof (XGCValues)); /* initialize all slots to ~0 */ - gcv.foreground = (tmp_fcolor.pixel ^ tmp_bcolor.pixel); - gcv.function = GXxor; - gcv.graphics_exposures = False; - gc = gc_cache_lookup (DEVICE_X_GC_CACHE (XDEVICE (f->device)), &gcv, - (GCForeground | GCFunction | GCGraphicsExposures)); - default_face_height_and_width (frame, &flash_height, 0); - - /* If window is tall, flash top and bottom line. */ - if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height) - { - XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top, - w->pixel_width, flash_height); - XFillRectangle (dpy, win, gc, w->pixel_left, - w->pixel_top + w->pixel_height - flash_height, - w->pixel_width, flash_height); - } - else - /* If it is short, flash it all. */ - XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top, - w->pixel_width, w->pixel_height); - - XSync (dpy, False); - -#ifdef HAVE_SELECT - { - int usecs = 100000; - struct timeval tv; - tv.tv_sec = usecs / 1000000L; - tv.tv_usec = usecs % 1000000L; - /* I'm sure someone is going to complain about this... */ - select (0, 0, 0, 0, &tv); - } -#else -#ifdef HAVE_POLL - poll (0, 0, 100); -#else /* !HAVE_POLL */ - bite me -#endif /* HAVE_POLL */ -#endif /* HAVE_SELECT */ - - /* If window is tall, flash top and bottom line. */ - if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height) - { - XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top, - w->pixel_width, flash_height); - XFillRectangle (dpy, win, gc, w->pixel_left, - w->pixel_top + w->pixel_height - flash_height, - w->pixel_width, flash_height); - } - else - /* If it is short, flash it all. */ - XFillRectangle (dpy, win, gc, w->pixel_left, w->pixel_top, - w->pixel_width, w->pixel_height); - - XSync (dpy, False); - - return 1; -} /* Make audible bell. */ @@ -2053,28 +371,3 @@ XSync (display, 0); } } - - -/************************************************************************/ -/* initialization */ -/************************************************************************/ - -void -console_type_create_redisplay_x (void) -{ - /* redisplay methods */ - CONSOLE_HAS_METHOD (x, text_width); - CONSOLE_HAS_METHOD (x, output_display_block); - CONSOLE_HAS_METHOD (x, divider_height); - CONSOLE_HAS_METHOD (x, eol_cursor_width); - CONSOLE_HAS_METHOD (x, output_vertical_divider); - CONSOLE_HAS_METHOD (x, clear_region); - CONSOLE_HAS_METHOD (x, clear_frame); - CONSOLE_HAS_METHOD (x, window_output_begin); - CONSOLE_HAS_METHOD (x, window_output_end); - CONSOLE_HAS_METHOD (x, flash); - CONSOLE_HAS_METHOD (x, ring_bell); - CONSOLE_HAS_METHOD (x, bevel_area); - CONSOLE_HAS_METHOD (x, output_string); - CONSOLE_HAS_METHOD (x, output_pixmap); -}
--- a/src/redisplay-xlike-inc.c Mon Jan 18 06:21:05 2010 -0600 +++ b/src/redisplay-xlike-inc.c Mon Jan 18 08:44:49 2010 -0600 @@ -2,7 +2,7 @@ Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. Copyright (C) 1994 Lucid, Inc. Copyright (C) 1995 Sun Microsystems, Inc. - Copyright (C) 2002, 2003, 2005 Ben Wing. + Copyright (C) 2002, 2003, 2005, 2009, 2010 Ben Wing. This file is part of XEmacs. @@ -23,6 +23,344 @@ /* Synched up with: Not in FSF. */ +/* Author: Chuck Thompson */ +/* Gtk flavor by William Perry */ +/* X and GTK code merged by Ben Wing, 1-10 */ + +/* Lots of work done by Ben Wing for Mule */ + +#include <config.h> +#include "lisp.h" + +#include "buffer.h" +#include "debug.h" +#include "device-impl.h" +#include "faces.h" +#include "file-coding.h" +#include "frame-impl.h" +#include "gutter.h" +#include "redisplay.h" +#include "sysdep.h" +#include "window.h" + +#ifdef MULE +#include "mule-ccl.h" +#endif +#include "charset.h" + +#ifdef THIS_IS_X +#include "console-x-impl.h" +#include "glyphs-x.h" +#include "objects-x-impl.h" +#include "xgccache.h" +#else /* THIS_IS_GTK */ +#include "console-gtk-impl.h" +#include "gccache-gtk.h" +#include "glyphs-gtk.h" +#include "objects-gtk-impl.h" +#endif /* THIS_IS_GTK */ + +#include "EmacsFrame.h" +#include "EmacsFrameP.h" + +#include "sysproc.h" /* for select() */ + +#ifdef THIS_IS_X +#include <X11/bitmaps/gray> +#endif /* THIS_IS_X */ + +#define EOL_CURSOR_WIDTH 5 + +/* About some of the types below: + + X has two ways of representing a color: (a) as an unsigned long + representing a color pixel value, i.e. the actual value stored in memory + or a file at a particular pixel location to indicate that the pixel + takes on a specific color; and (b) an XColor structure, which + encapsulates both the RGB components of a color and the associated color + pixel value. + + We call the former type XLIKE_PIXCOLOR and the latter XLIKE_COLOR. + GTK uses the same GdkColor structure for both, and normally passes in + a pointer. We provide routines to handle the two logical color types. */ + +#ifdef THIS_IS_X + +/***************************************************************************/ +/* Definitions implementing X flavor of XLIKE */ +/***************************************************************************/ + +#define XLIKE_NAME x +#define USED_IF_X(var) var + +/* types */ +#define XLIKE_DISPLAY Display * +#define XLIKE_WINDOW Window +#define XLIKE_GC GC +#define XLIKE_RECTANGLE XRectangle +#define XLIKE_GCVALUES XGCValues +#define XLIKE_COLOR XColor +#define XLIKE_PIXCOLOR unsigned long + +/* constants */ +#define XLIKE_NONE None +#define XLIKE_FALSE False + +#define XLIKE_GC_BACKGROUND GCBackground +#define XLIKE_GC_CLIP_MASK GCClipMask +#define XLIKE_GC_CLIP_X_ORIGIN GCClipXOrigin +#define XLIKE_GC_CLIP_Y_ORIGIN GCClipYOrigin +#define XLIKE_GC_EXPOSURES GCGraphicsExposures +#define XLIKE_GC_FILL GCFillStyle +#define XLIKE_GC_FONT GCFont +#define XLIKE_GC_FOREGROUND GCForeground +#define XLIKE_GC_FUNCTION GCFunction +#define XLIKE_GC_LINE_WIDTH GCLineWidth +#define XLIKE_GC_STIPPLE GCStipple +#define XLIKE_GC_TILE GCTile + +#define XLIKE_GX_COPY GXcopy +#define XLIKE_GX_XOR GXxor + +#define XLIKE_FILL_MEMBER fill_style +#define XLIKE_FILL_STIPPLED FillStippled +#define XLIKE_FILL_OPAQUE_STIPPLED FillOpaqueStippled +#define XLIKE_FILL_TILED FillTiled +#define XLIKE_FILL_SOLID FillSolid + +/* functions */ +#define GET_XLIKE_DISPLAY(d) DEVICE_X_DISPLAY (d) +#define GET_XLIKE_WINDOW(w) XtWindow (FRAME_X_TEXT_WIDGET (f)) +#define XLIKE_FILL_RECTANGLE(dpy, x_win, gc, x, y, width, height) \ + XFillRectangle (dpy, x_win, gc, x, y, width, height) +#define XLIKE_DRAW_RECTANGLE(dpy, x_win, gc, x, y, width, height) \ + XDrawRectangle (dpy, x_win, gc, x, y, width, height) +#define XLIKE_DRAW_LINE(dpy, x_win, gc, x1, y1, x2, y2) \ + XDrawLine (dpy, x_win, gc, x1, y1, x2, y2) +#define XLIKE_OUTPUT_XLIKE_PIXMAP x_output_x_pixmap + +#define XLIKE_DISPLAY_LINE_HEIGHT(dl) DISPLAY_LINE_HEIGHT (dl) +#define XLIKE_DISPLAY_LINE_YPOS(dl) DISPLAY_LINE_YPOS (dl) +#define XLIKE_DISPLAY_LINE_TOP_CLIP(dl) ((dl)->top_clip) +#define XLIKE_SET_CLIP_RECTANGLE(dpy, gc, xorig, yorig, prect) \ + /* #### why not Unsorted? */ \ + XSetClipRectangles (dpy, gc, xorig, yorig, prect, 1, YXBanded) +#define XLIKE_CLEAR_CLIP_MASK(dpy, gc) \ +do \ + { \ + XSetClipMask (dpy, gc, None); \ + XSetClipOrigin (dpy, gc, 0, 0); \ + } \ +while (0) +#define XLIKE_FLUSH(dpy) XSync (dpy, False) +#define XLIKE_CLEAR_AREA(dpy, win, x, y, width, height) \ + XClearArea (dpy, win, x, y, width, height, False) + +#define IMAGE_INSTANCE_XLIKE_MASK IMAGE_INSTANCE_X_MASK +#define XIMAGE_INSTANCE_XLIKE_PIXMAP XIMAGE_INSTANCE_X_PIXMAP +#define COLOR_INSTANCE_XLIKE_COLOR COLOR_INSTANCE_X_COLOR +#define FONT_INSTANCE_XLIKE_FONT FONT_INSTANCE_X_FONT +#define DEVICE_XLIKE_GC_CACHE DEVICE_X_GC_CACHE +#define DEVICE_XLIKE_GRAY_PIXMAP DEVICE_X_GRAY_PIXMAP +#define XLIKE_COLOR_TO_PIXCOLOR(ci) ((ci).pixel) +#define XLIKE_SET_PIXCOLOR_COPY(lval, rval) ((lval) = (rval)) +#define XLIKE_SET_PIXCOLOR_NUM(lval, rval) ((lval) = (rval)) +#define XLIKE_FONT_NUM(val) ((val)->fid) + +#define XLIKE_OUTPUT_XLIKE_PIXMAP x_output_x_pixmap + +/************ End X flavor of XLIKE **********/ + + + + +#else /* THIS_IS_GTK */ + +/***************************************************************************/ +/* Definitions implementing GTK flavor of XLIKE */ +/***************************************************************************/ + +#define XLIKE_NAME gtk +#define USED_IF_X(var) UNUSED (var) + +/*types */ +#define XLIKE_DISPLAY void * +#define XLIKE_WINDOW GdkWindow * +#define XLIKE_GC GdkGC * +#define XLIKE_RECTANGLE GdkRectangle +#define XLIKE_GCVALUES GdkGCValues +#define XLIKE_COLOR GdkColor * +#define XLIKE_PIXCOLOR GdkColor * + +/* constants */ +#define XLIKE_NONE 0 +#define XLIKE_FALSE FALSE + +#define XLIKE_GC_BACKGROUND GDK_GC_BACKGROUND +#define XLIKE_GC_CLIP_MASK GDK_GC_CLIP_MASK +#define XLIKE_GC_CLIP_X_ORIGIN GDK_GC_CLIP_X_ORIGIN +#define XLIKE_GC_CLIP_Y_ORIGIN GDK_GC_CLIP_Y_ORIGIN +#define XLIKE_GC_EXPOSURES GDK_GC_EXPOSURES +#define XLIKE_GC_FILL GDK_GC_FILL +#define XLIKE_GC_FONT GDK_GC_FONT +#define XLIKE_GC_FOREGROUND GDK_GC_FOREGROUND +#define XLIKE_GC_FUNCTION GDK_GC_FUNCTION +#define XLIKE_GC_LINE_WIDTH GDK_GC_LINE_WIDTH +#define XLIKE_GC_STIPPLE GDK_GC_STIPPLE +#define XLIKE_GC_TILE GDK_GC_TILE + +#define XLIKE_GX_COPY GDK_COPY +#define XLIKE_GX_XOR GDK_XOR + +#define XLIKE_FILL_MEMBER fill +#define XLIKE_FILL_STIPPLED GDK_STIPPLED +#define XLIKE_FILL_OPAQUE_STIPPLED GDK_OPAQUE_STIPPLED +#define XLIKE_FILL_TILED GDK_TILED +#define XLIKE_FILL_SOLID GDK_SOLID + +/* functions */ + +#define GET_XLIKE_DISPLAY(d) NULL +#define GET_XLIKE_WINDOW(w) GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (w)) +#define XLIKE_FILL_RECTANGLE(dpy, x_win, gc, x, y, width, height) \ + gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, TRUE, x, y, width, height) +#define XLIKE_DRAW_RECTANGLE(dpy, x_win, gc, x, y, width, height) \ + gdk_draw_rectangle (GDK_DRAWABLE (x_win), gc, FALSE, x, y, width, height) +#define XLIKE_DRAW_LINE(dpy, x_win, gc, x1, y1, x2, y2) \ + gdk_draw_line (GDK_DRAWABLE (x_win), gc, x1, y1, x2, y2) +#define XLIKE_OUTPUT_XLIKE_PIXMAP gtk_output_gdk_pixmap + +/* FIXME: This is totally bogus. It removes dl->top_clip from the + equations. If there is a bug involving this, fix it properly! + Or just ensure that top_clip is 0. */ +#define XLIKE_DISPLAY_LINE_HEIGHT(dl) \ + ((dl)->ascent + ((dl)->descent - (dl)->clip) +#define XLIKE_DISPLAY_LINE_YPOS(dl) ((dl)->ypos - (dl)->ascent) +#define XLIKE_DISPLAY_LINE_TOP_CLIP(dl) ((0) +#define XLIKE_SET_CLIP_RECTANGLE(dpy, gc, xorig, yorig, prect) \ +do \ + { \ + gdk_gc_set_clip_rectangle (gc, prect); \ + gdk_gc_set_clip_origin (gc, xorig, yorig); \ + } \ +while (0) +#define XLIKE_CLEAR_CLIP_MASK(dpy, gc) \ +do \ + { \ + gdk_gc_set_clip_rectangle (gc, NULL); \ + gdk_gc_set_clip_origin (gc, 0, 0); \ + } \ +while (0) +#define XLIKE_FLUSH(dpy) gdk_flush () +#define XLIKE_CLEAR_AREA(dpy, win, x, y, width, height) \ + gdk_window_clear_area (win, x, y, width, height) + +#define IMAGE_INSTANCE_XLIKE_MASK IMAGE_INSTANCE_GTK_MASK +#define XIMAGE_INSTANCE_XLIKE_PIXMAP XIMAGE_INSTANCE_GTK_PIXMAP +#define COLOR_INSTANCE_XLIKE_COLOR COLOR_INSTANCE_GTK_COLOR +#define FONT_INSTANCE_XLIKE_FONT FONT_INSTANCE_GTK_FONT +#define DEVICE_XLIKE_GRAY_PIXMAP DEVICE_GTK_GRAY_PIXMAP +#define DEVICE_XLIKE_GC_CACHE DEVICE_GTK_GC_CACHE +#define XLIKE_COLOR_TO_PIXCOLOR(ci) (ci) +#define XLIKE_SET_PIXCOLOR_COPY(lval, rval) ((lval) = *(rval)) +#define XLIKE_SET_PIXCOLOR_NUM(lval, rval) ((lval).pixel = (rval)) +#define XLIKE_FONT_NUM(val) (val) + +#define XLIKE_OUTPUT_XLIKE_PIXMAP gtk_output_gdk_pixmap + +static void gtk_output_pixmap (struct window *w, + Lisp_Object image_instance, + struct display_box *db, + struct display_glyph_area *dga, + face_index findex, + int cursor_start, + int cursor_width, + int cursor_height, + int bgpixmap); +static void gtk_clear_region (Lisp_Object locale, struct device* d, + struct frame* f, face_index findex, int x, int y, + int width, int height, Lisp_Object fcolor, + Lisp_Object bcolor, + Lisp_Object background_pixmap); +static void gtk_bevel_modeline (struct window *w, struct display_line *dl); + +#if 0 +static void __describe_gc (GdkGC *); +#endif + +/************ End GTK flavor of XLIKE **********/ + +#endif /* (not) THIS_IS_X */ + + + +/***************************************************************************/ +/* Common definitions */ +/***************************************************************************/ + +#define XCOLOR_INSTANCE_XLIKE_COLOR(x) \ + COLOR_INSTANCE_XLIKE_COLOR (XCOLOR_INSTANCE (x)) + +#define XLIKE_PASTE_1(a,b) a##_##b +#define XLIKE_PASTE(a,b) XLIKE_PASTE_1(a,b) +#define XLIKE_CONSOLE_HAS_METHOD_1(xlike, name) CONSOLE_HAS_METHOD (xlike, name) +#define XLIKE_CONSOLE_HAS_METHOD(name) \ + XLIKE_CONSOLE_HAS_METHOD_1 (XLIKE_NAME, name) + +/* Device methods */ + +#define XLIKE_text_width XLIKE_PASTE (XLIKE_NAME, text_width) +#define XLIKE_output_display_block XLIKE_PASTE (XLIKE_NAME, output_display_block) +#define XLIKE_divider_height XLIKE_PASTE (XLIKE_NAME, divider_height) +#define XLIKE_eol_cursor_width XLIKE_PASTE (XLIKE_NAME, eol_cursor_width) +#define XLIKE_output_vertical_divider XLIKE_PASTE (XLIKE_NAME, output_vertical_divider) +#define XLIKE_clear_region XLIKE_PASTE (XLIKE_NAME, clear_region) +#define XLIKE_clear_frame XLIKE_PASTE (XLIKE_NAME, clear_frame) +#define XLIKE_flash XLIKE_PASTE (XLIKE_NAME, flash) +#define XLIKE_ring_bell XLIKE_PASTE (XLIKE_NAME, ring_bell) +#define XLIKE_bevel_area XLIKE_PASTE (XLIKE_NAME, bevel_area) +#define XLIKE_output_string XLIKE_PASTE (XLIKE_NAME, output_string) +#define XLIKE_output_pixmap XLIKE_PASTE (XLIKE_NAME, output_pixmap) +#define XLIKE_window_output_begin XLIKE_PASTE (XLIKE_NAME, window_output_begin) +#define XLIKE_window_output_end XLIKE_PASTE (XLIKE_NAME, window_output_end) + +/* Miscellaneous split functions */ + +#define console_type_create_redisplay_XLIKE XLIKE_PASTE (console_type_create_redisplay, XLIKE_NAME) +#define XLIKE_get_gc XLIKE_PASTE (XLIKE_NAME, get_gc) +#define XLIKE_output_blank XLIKE_PASTE (XLIKE_NAME, output_blank) +#define XLIKE_text_width_single_run XLIKE_PASTE (XLIKE_NAME, text_width_single_run) + +static void XLIKE_output_blank (struct window *w, struct display_line *dl, + struct rune *rb, int start_pixpos, + int cursor_start, int cursor_width); +static void XLIKE_output_horizontal_line (struct window *w, + struct display_line *dl, + struct rune *rb); + +static void XLIKE_output_vertical_divider (struct window *w, int clear); + +static void XLIKE_output_eol_cursor (struct window *w, + struct display_line *dl, + int xpos, face_index findex); +static void XLIKE_clear_frame (struct frame *f); +static void XLIKE_clear_frame_windows (Lisp_Object window); +static void XLIKE_window_output_begin (struct window *w); +static void XLIKE_window_output_end (struct window *w); +static void XLIKE_bevel_area (struct window *w, face_index findex, + int x, int y, int width, int height, + int shadow_thickness, int edges, + enum edge_style style); +static void XLIKE_ring_bell (struct device *d, int volume, int pitch, + int duration); + +/****************************************************************************/ +/* */ +/* Separate textual runs */ +/* */ +/****************************************************************************/ + + /* Note: We do not use the Xmb*() functions and XFontSets, nor the Motif XFontLists and CompoundStrings. Those functions are generally losing for a number of reasons. @@ -353,3 +691,1843 @@ str, len, cachel); #endif } + +/****************************************************************************/ +/* */ +/* Xlike output routines */ +/* */ +/****************************************************************************/ + +static int +XLIKE_text_width_single_run (struct frame * USED_IF_XFT (f), + struct face_cachel *cachel, + struct textual_run *run) +{ + Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset); + Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst); + + if (!fi->proportional_p) + return fi->width * run->len; +#ifdef USE_XFT + else if (FONT_INSTANCE_X_XFTFONT (fi)) + { + static XGlyphInfo glyphinfo; + struct device *d = XDEVICE (f->device); + Display *dpy = DEVICE_X_DISPLAY (d); + + if (run->dimension == 2) + { + XftTextExtents16 (dpy, + FONT_INSTANCE_X_XFTFONT (fi), + (XftChar16 *) run->ptr, run->len, &glyphinfo); + } + else + { + XftTextExtents8 (dpy, + FONT_INSTANCE_X_XFTFONT (fi), + run->ptr, run->len, &glyphinfo); + } + + return glyphinfo.xOff; + } +#endif + else if (FONT_INSTANCE_XLIKE_FONT (fi)) + { + if (run->dimension == 2) + { +#ifdef THIS_IS_X + return XTextWidth16 (FONT_INSTANCE_X_FONT (fi), + (XChar2b *) run->ptr, run->len); +#else /* THIS_IS_GTK */ + /* stderr_out ("Measuring wide characters\n"); */ + return gdk_text_width_wc (FONT_INSTANCE_GTK_FONT (fi), + (GdkWChar *) run->ptr, run->len); +#endif /* THIS_IS_GTK */ + } + else + { +#ifdef THIS_IS_X + return XTextWidth (FONT_INSTANCE_X_FONT (fi), + (char *) run->ptr, run->len); +#else /* THIS_IS_GTK */ + return gdk_text_width (FONT_INSTANCE_GTK_FONT (fi), + (char *) run->ptr, run->len); +#endif /* THIS_IS_GTK */ + } + } + else + abort(); + return 0; /* shut up GCC */ +} + +/* + XLIKE_text_width + + Given a string and a merged face, return the string's length in pixels + when displayed in the fonts associated with the face. + */ + +/* #### Break me out into a separate header */ +int XLIKE_text_width (struct frame *USED_IF_X (f), struct face_cachel *cachel, + const Ichar *str, Charcount len); +int +XLIKE_text_width (struct frame *USED_IF_X (f), struct face_cachel *cachel, + const Ichar *str, Charcount len) +{ + /* !!#### Needs review */ + int width_so_far = 0; + unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); + struct textual_run *runs = alloca_array (struct textual_run, len); + int nruns; + int i; + + nruns = separate_textual_runs (text_storage, runs, str, len, + cachel); + + for (i = 0; i < nruns; i++) + width_so_far += XLIKE_text_width_single_run (f, cachel, runs + i); + + return width_so_far; +} + +/***************************************************************************** + XLIKE_divider_height + + Return the height of the horizontal divider. This is a function because + divider_height is a device method. + + #### If we add etched horizontal divider lines this will have to get + smarter. + ****************************************************************************/ +static int +XLIKE_divider_height (void) +{ +#ifdef THIS_IS_X + return 1; +#else /* THIS_IS_GTK */ + return 2; +#endif /* THIS_IS_GTK */ +} + +/***************************************************************************** + XLIKE_eol_cursor_width + + Return the width of the end-of-line cursor. This is a function + because eol_cursor_width is a device method. + ****************************************************************************/ +static int +XLIKE_eol_cursor_width (void) +{ + return EOL_CURSOR_WIDTH; +} + +/***************************************************************************** + XLIKE_output_display_block + + Given a display line, a block number for that start line, output all + runes between start and end in the specified display block. + ****************************************************************************/ +static void +XLIKE_output_display_block (struct window *w, struct display_line *dl, + int block, int start, int end, int start_pixpos, + int cursor_start, int cursor_width, + int cursor_height) +{ +#ifndef USE_XFT + struct frame *f = XFRAME (w->frame); +#endif + Ichar_dynarr *buf; + Lisp_Object window; + + struct display_block *db = Dynarr_atp (dl->display_blocks, block); + rune_dynarr *rba = db->runes; + struct rune *rb; + + int elt = start; + face_index findex; + int xpos, width = 0; + Lisp_Object charset = Qunbound; /* Qnil is a valid charset when + MULE is not defined */ + + window = wrap_window (w); + rb = Dynarr_atp (rba, start); + + if (!rb) + /* Nothing to do so don't do anything. */ + return; + + findex = rb->findex; + xpos = rb->xpos; + if (rb->type == RUNE_CHAR) + charset = ichar_charset (rb->object.chr.ch); + + if (end < 0) + end = Dynarr_length (rba); + buf = Dynarr_new (Ichar); + + while (elt < end) + { + rb = Dynarr_atp (rba, elt); + + if (rb->findex == findex && rb->type == RUNE_CHAR + && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON + && EQ (charset, ichar_charset (rb->object.chr.ch))) + { + Dynarr_add (buf, rb->object.chr.ch); + width += rb->width; + elt++; + } + else + { + if (Dynarr_length (buf)) + { + XLIKE_output_string (w, dl, buf, xpos, 0, start_pixpos, width, + findex, 0, cursor_start, cursor_width, + cursor_height); + xpos = rb->xpos; + width = 0; + } + Dynarr_reset (buf); + width = 0; + + if (rb->type == RUNE_CHAR) + { + findex = rb->findex; + xpos = rb->xpos; + charset = ichar_charset (rb->object.chr.ch); + + if (rb->cursor_type == CURSOR_ON) + { + if (rb->object.chr.ch == '\n') + { + XLIKE_output_eol_cursor (w, dl, xpos, findex); + } + else + { + Dynarr_add (buf, rb->object.chr.ch); + XLIKE_output_string (w, dl, buf, xpos, 0, start_pixpos, + rb->width, findex, 1, + cursor_start, cursor_width, + cursor_height); + Dynarr_reset (buf); + } + + xpos += rb->width; + elt++; + } + else if (rb->object.chr.ch == '\n') + { + /* Clear in case a cursor was formerly here. */ + redisplay_clear_region (window, findex, xpos, + XLIKE_DISPLAY_LINE_YPOS (dl), + rb->width, + XLIKE_DISPLAY_LINE_HEIGHT (dl)); + elt++; + } + } + else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE) + { + if (rb->type == RUNE_BLANK) + XLIKE_output_blank (w, dl, rb, start_pixpos, cursor_start, + cursor_width); + else + { + /* #### Our flagging of when we need to redraw the + modeline shadows sucks. Since RUNE_HLINE is only used + by the modeline at the moment it is a good bet + that if it gets redrawn then we should also + redraw the shadows. This won't be true forever. + We borrow the shadow_thickness_changed flag for + now. */ + w->shadow_thickness_changed = 1; + XLIKE_output_horizontal_line (w, dl, rb); + } + + elt++; + if (elt < end) + { + rb = Dynarr_atp (rba, elt); + + findex = rb->findex; + xpos = rb->xpos; + } + } + else if (rb->type == RUNE_DGLYPH) + { + Lisp_Object instance; + struct display_box dbox; + struct display_glyph_area dga; + + redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset, + rb->object.dglyph.yoffset, start_pixpos, + rb->width, &dbox, &dga); + + window = wrap_window (w); + instance = glyph_image_instance (rb->object.dglyph.glyph, + window, ERROR_ME_DEBUG_WARN, 1); + findex = rb->findex; + + if (IMAGE_INSTANCEP (instance)) + { + switch (XIMAGE_INSTANCE_TYPE (instance)) + { + case IMAGE_TEXT: +#ifdef THIS_IS_GTK + { + /* !!#### Examine for Mule-izing */ + /* #### This is way losing. See the comment in + add_glyph_rune(). */ + Lisp_Object string = + XIMAGE_INSTANCE_TEXT_STRING (instance); + convert_ibyte_string_into_ichar_dynarr + (XSTRING_DATA (string), XSTRING_LENGTH (string), + buf); + + gtk_output_string (w, dl, buf, xpos, + rb->object.dglyph.xoffset, + start_pixpos, -1, findex, + (rb->cursor_type == CURSOR_ON), + cursor_start, cursor_width, + cursor_height); + Dynarr_reset (buf); + } + break; +#else + ABORT (); +#endif /* THIS_IS_GTK */ + case IMAGE_MONO_PIXMAP: + case IMAGE_COLOR_PIXMAP: + redisplay_output_pixmap (w, instance, &dbox, &dga, + findex, cursor_start, + cursor_width, + cursor_height, 0); + break; + + case IMAGE_WIDGET: + if (EQ (XIMAGE_INSTANCE_WIDGET_TYPE (instance), + Qlayout)) + { + redisplay_output_layout (window, instance, &dbox, + &dga, findex, + cursor_start, cursor_width, + cursor_height); + break; + } + + case IMAGE_SUBWINDOW: + redisplay_output_subwindow (w, instance, &dbox, &dga, + findex, cursor_start, + cursor_width, cursor_height); + break; + + case IMAGE_NOTHING: + /* nothing is as nothing does */ + break; + + case IMAGE_POINTER: + default: + ABORT (); + } + IMAGE_INSTANCE_OPTIMIZE_OUTPUT + (XIMAGE_INSTANCE (instance)) = 0; + } + + xpos += rb->width; + elt++; + } + else + ABORT (); + } + } + + if (Dynarr_length (buf)) + XLIKE_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex, + 0, cursor_start, cursor_width, cursor_height); + + if (dl->modeline + && !EQ (Qzero, w->modeline_shadow_thickness) +#ifndef USE_XFT + /* This optimization doesn't work right with some Xft fonts, which + leave antialiasing turds at the boundary. I don't know if this + is an Xft bug or not, but I think it is. See x_output_string. */ + && (f->clear + || f->windows_structure_changed + || w->shadow_thickness_changed) +#endif + ) + bevel_modeline (w, dl); + + Dynarr_free (buf); +} + +/***************************************************************************** + XLIKE_get_gc + + Given a number of parameters return a GC with those properties. + ****************************************************************************/ +static XLIKE_GC +XLIKE_get_gc (struct device *d, Lisp_Object font, Lisp_Object fg, + Lisp_Object bg, Lisp_Object bg_pmap, Lisp_Object lwidth) +{ + XLIKE_GCVALUES gcv; + unsigned long mask; + + memset (&gcv, ~0, sizeof (gcv)); + gcv.graphics_exposures = XLIKE_FALSE; + /* Make absolutely sure that we don't pick up a clipping region in + the GC returned by this function. */ + gcv.clip_mask = XLIKE_NONE; + gcv.clip_x_origin = 0; + gcv.clip_y_origin = 0; + gcv.XLIKE_FILL_MEMBER = XLIKE_FILL_SOLID; + mask = XLIKE_GC_EXPOSURES | XLIKE_GC_CLIP_MASK | XLIKE_GC_CLIP_X_ORIGIN | XLIKE_GC_CLIP_Y_ORIGIN; + mask |= XLIKE_GC_FILL; + + if (!NILP (font) +#ifdef USE_XFT + /* Only set the font if it's a core font */ + /* the renderfont will be set elsewhere (not part of gc) */ + && !FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font)) +#endif + ) + { + gcv.font = + XLIKE_FONT_NUM (FONT_INSTANCE_XLIKE_FONT (XFONT_INSTANCE (font))); + mask |= XLIKE_GC_FONT; + } + + /* evil kludge! */ + if (!NILP (fg) && !COLOR_INSTANCEP (fg) && !INTP (fg)) + { + /* #### I fixed one case where this was getting hit. It was a + bad macro expansion (compiler bug). */ + stderr_out ("Help! x_get_gc got a bogus fg value! fg = "); + debug_print (fg); + fg = Qnil; + } + + if (!NILP (fg)) + { + if (COLOR_INSTANCEP (fg)) + XLIKE_SET_PIXCOLOR_COPY + (gcv.foreground, + XLIKE_COLOR_TO_PIXCOLOR (XCOLOR_INSTANCE_XLIKE_COLOR (fg))); + else + XLIKE_SET_PIXCOLOR_NUM (gcv.foreground, XINT (fg)); + mask |= XLIKE_GC_FOREGROUND; + } + + if (!NILP (bg)) + { + if (COLOR_INSTANCEP (bg)) + XLIKE_SET_PIXCOLOR_COPY + (gcv.background, + XLIKE_COLOR_TO_PIXCOLOR (XCOLOR_INSTANCE_XLIKE_COLOR (bg))); + else + XLIKE_SET_PIXCOLOR_NUM (gcv.background, XINT (bg)); + mask |= XLIKE_GC_BACKGROUND; + } + + /* This special case comes from a request to draw text with a face which has + the dim property. We'll use a stippled foreground GC. */ + if (EQ (bg_pmap, Qdim)) + { + assert (DEVICE_XLIKE_GRAY_PIXMAP (d) != XLIKE_NONE); + + gcv.XLIKE_FILL_MEMBER = XLIKE_FILL_STIPPLED; + gcv.stipple = DEVICE_XLIKE_GRAY_PIXMAP (d); + mask |= (XLIKE_GC_FILL | XLIKE_GC_STIPPLE); + } + else if (IMAGE_INSTANCEP (bg_pmap) + && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) + { + if (XIMAGE_INSTANCE_PIXMAP_DEPTH (bg_pmap) == 0) + { + gcv.XLIKE_FILL_MEMBER = XLIKE_FILL_OPAQUE_STIPPLED; + gcv.stipple = XIMAGE_INSTANCE_XLIKE_PIXMAP (bg_pmap); + mask |= (XLIKE_GC_STIPPLE | XLIKE_GC_FILL); + } + else + { + gcv.XLIKE_FILL_MEMBER = XLIKE_FILL_TILED; + gcv.tile = XIMAGE_INSTANCE_XLIKE_PIXMAP (bg_pmap); + mask |= (XLIKE_GC_TILE | XLIKE_GC_FILL); + } + } + + if (!NILP (lwidth)) + { + gcv.line_width = XINT (lwidth); + mask |= XLIKE_GC_LINE_WIDTH; + } + +#if 0 + debug_out ("\nx_get_gc: calling gc_cache_lookup\n"); +#endif + return gc_cache_lookup (DEVICE_XLIKE_GC_CACHE (d), &gcv, mask); +} + +/***************************************************************************** + XLIKE_output_string + + Given a string and a starting position, output that string in the + given face. If cursor is true, draw a cursor around the string. + Correctly handles multiple charsets in the string. + + The meaning of the parameters is something like this: + + W Window that the text is to be displayed in. + DL Display line that this text is on. The values in the + structure are used to determine the vertical position and + clipping range of the text. + BUF Dynamic array of Ichars specifying what is actually to be + drawn. + XPOS X position in pixels where the text should start being drawn. + XOFFSET Number of pixels to be chopped off the left side of the + text. The effect is as if the text were shifted to the + left this many pixels and clipped at XPOS. + CLIP_START Clip everything left of this X position. + WIDTH Clip everything right of XPOS + WIDTH. + FINDEX Index for the face cache element describing how to display + the text. + CURSOR #### I don't understand this. There's something + strange and overcomplexified with this variable. + Chuck, explain please? + CURSOR_START Starting X position of cursor. + CURSOR_WIDTH Width of cursor in pixels. + CURSOR_HEIGHT Height of cursor in pixels. + + Starting Y position of cursor is the top of the text line. + The cursor is drawn sometimes whether or not CURSOR is set. ??? + ****************************************************************************/ +#ifdef THIS_IS_GTK +static +void gdk_draw_text_image (GdkDrawable *drawable, + GdkFont *font, + GdkGC *gc, + gint x, + gint y, + const gchar *text, + gint text_length); + +#endif /* THIS_IS_GTK */ +void +XLIKE_output_string (struct window *w, struct display_line *dl, + Ichar_dynarr *buf, int xpos, int xoffset, int clip_start, + int width, face_index findex, int cursor, + int cursor_start, int cursor_width, int cursor_height) +{ + /* General variables */ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + Lisp_Object window = wrap_window (w); + + int clip_end; + + /* Cursor-related variables */ + int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); + int cursor_clip; + Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, + WINDOW_BUFFER (w)); + struct face_cachel *cursor_cachel = 0; + + /* Text-related variables */ + Lisp_Object bg_pmap; + XLIKE_GC bgc, gc; + int height = XLIKE_DISPLAY_LINE_HEIGHT (dl); + int ypos = XLIKE_DISPLAY_LINE_YPOS (dl); + int len = Dynarr_length (buf); + unsigned char *text_storage = (unsigned char *) ALLOCA (2 * len); + struct textual_run *runs = alloca_array (struct textual_run, len); + int nruns; + int i; + struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex); + +#ifdef THIS_IS_X + int use_x_font = 1; /* #### bogus!! + The logic of this function needs review! */ +#endif +#ifdef USE_XFT + Colormap cmap = DEVICE_X_COLORMAP (d); + Visual *visual = DEVICE_X_VISUAL (d); + static XftColor fg, bg; + XftDraw *xftDraw; + + /* Lazily initialize frame's xftDraw member. */ + if (!FRAME_X_XFTDRAW (f)) { + FRAME_X_XFTDRAW (f) = XftDrawCreate (dpy, x_win, visual, cmap); + } + xftDraw = FRAME_X_XFTDRAW (f); + + /* #### This will probably cause asserts when passed a Lisp integer for a + color. See ca. line 759 this file. + #### Maybe xft_convert_color should take an XColor, not a pixel. */ +#define XFT_FROB_LISP_COLOR(color, dim) \ + xft_convert_color (dpy, cmap, visual, \ + COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color)).pixel, \ + (dim)) +#endif /* USE_XFT */ + + if (width < 0) + width = XLIKE_text_width (f, cachel, Dynarr_atp (buf, 0), + Dynarr_length (buf)); + + /* Regularize the variables passed in. */ + + if (clip_start < xpos) + clip_start = xpos; + clip_end = xpos + width; + if (clip_start >= clip_end) + /* It's all clipped out. */ + return; + + xpos -= xoffset; + + /* make sure the area we are about to display is subwindow free. */ + redisplay_unmap_subwindows_maybe (f, clip_start, ypos, + clip_end - clip_start, height); + + cursor_clip = (cursor_start >= clip_start && + cursor_start < clip_end); + + /* This cursor code is really a mess. */ + if (!NILP (w->text_cursor_visible_p) + && (cursor + || cursor_clip + || (cursor_width + && (cursor_start + cursor_width >= clip_start) + && !NILP (bar_cursor_value)))) + { + /* These have to be in separate statements in order to avoid a + compiler bug. */ + face_index sucks = get_builtin_face_cache_index (w, Vtext_cursor_face); + cursor_cachel = WINDOW_FACE_CACHEL (w, sucks); + + /* We have to reset this since any call to WINDOW_FACE_CACHEL + may cause the cache to resize and any pointers to it to + become invalid. */ + cachel = WINDOW_FACE_CACHEL (w, findex); + } + +#ifdef HAVE_XIM + if (cursor && focus && (cursor_start == clip_start) && cursor_height) + XIM_SetSpotLocation (f, xpos - 2, dl->ypos + dl->descent - 2); +#endif /* HAVE_XIM */ + + bg_pmap = cachel->background_pixmap; + if (!IMAGE_INSTANCEP (bg_pmap) + || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) + bg_pmap = Qnil; + + if ((cursor && focus && NILP (bar_cursor_value) + && !NILP (w->text_cursor_visible_p)) || NILP (bg_pmap)) + bgc = 0; + else + bgc = XLIKE_get_gc (d, Qnil, cachel->foreground, cachel->background, + bg_pmap, Qnil); + + if (bgc) + { + XLIKE_FILL_RECTANGLE (dpy, x_win, bgc, clip_start, + ypos, clip_end - clip_start, + height); + } + + nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0), + Dynarr_length (buf), cachel); + + for (i = 0; i < nruns; i++) + { + Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset); + Lisp_Font_Instance *fi = XFONT_INSTANCE (font); + int this_width; + int need_clipping; + + if (EQ (font, Vthe_null_font_instance)) + continue; + + this_width = XLIKE_text_width_single_run (f, cachel, runs + i); + need_clipping = (dl->clip || clip_start > xpos || + clip_end < xpos + this_width); + + /* XDrawImageString only clears the area equal to the height of + the given font. It is possible that a font is being displayed + on a line taller than it is, so this would cause us to fail to + clear some areas. */ + if ((int) fi->height < (int) (height + dl->clip + + XLIKE_DISPLAY_LINE_TOP_CLIP (dl))) + { + int clear_start = max (xpos, clip_start); + int clear_end = min (xpos + this_width, clip_end); + + if (cursor) + { + int ypos1_line, ypos1_string, ypos2_line, ypos2_string; + + ypos1_string = dl->ypos - fi->ascent; + ypos2_string = dl->ypos + fi->descent; + ypos1_line = ypos; + ypos2_line = ypos1_line + height; + + /* Make sure we don't clear below the real bottom of the + line. */ + if (ypos1_string > ypos2_line) + ypos1_string = ypos2_line; + if (ypos2_string > ypos2_line) + ypos2_string = ypos2_line; + + if (ypos1_line < ypos1_string) + { + redisplay_clear_region (window, findex, clear_start, ypos1_line, + clear_end - clear_start, + ypos1_string - ypos1_line); + } + + if (ypos2_line > ypos2_string) + { + redisplay_clear_region (window, findex, clear_start, ypos2_string, + clear_end - clear_start, + ypos2_line - ypos2_string); + } + } + else + { + redisplay_clear_region (window, findex, clear_start, + ypos, clear_end - clear_start, + height); + } + } + + if (cursor && cursor_cachel && focus && NILP (bar_cursor_value)) + { +#ifdef USE_XFT + fg = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0); + bg = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0); +#endif + gc = XLIKE_get_gc (d, font, cursor_cachel->foreground, + cursor_cachel->background, Qnil, Qnil); + } + else if (cachel->dim) + { + /* Ensure the gray bitmap exists */ + if (DEVICE_XLIKE_GRAY_PIXMAP (d) == XLIKE_NONE) + DEVICE_XLIKE_GRAY_PIXMAP (d) = +#ifdef THIS_IS_X + XCreateBitmapFromData (dpy, x_win, (char *)gray_bits, + gray_width, gray_height) +#else + /* #### FIXME! Implement me! */ + XLIKE_NONE +#endif + ; + + /* Request a GC with the gray stipple pixmap to draw dimmed text */ +#ifdef USE_XFT + fg = XFT_FROB_LISP_COLOR (cachel->foreground, 1); + bg = XFT_FROB_LISP_COLOR (cachel->background, 0); +#endif + gc = XLIKE_get_gc (d, font, cachel->foreground, cachel->background, + Qdim, Qnil); + } + else + { +#ifdef USE_XFT + fg = XFT_FROB_LISP_COLOR (cachel->foreground, 0); + bg = XFT_FROB_LISP_COLOR (cachel->background, 0); +#endif + gc = XLIKE_get_gc (d, font, cachel->foreground, cachel->background, + Qnil, Qnil); + } +#ifdef USE_XFT + { + XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi); + + if (rf) + { + use_x_font = 0; + if (need_clipping) + { + Region clip_reg = XCreateRegion(); + XRectangle clip_box = { clip_start, ypos, + clip_end - clip_start, height }; + + XUnionRectWithRegion (&clip_box, clip_reg, clip_reg); + XftDrawSetClip(xftDraw, clip_reg); + XDestroyRegion(clip_reg); + } + + if (!bgc) + { + /* #### Neither rect_height nor XftTextExtents as computed + below handles the vertical space taken up by antialiasing, + which for some fonts (eg, Bitstream Vera Sans Mono-16 on + my Mac PowerBook G4) leaves behind orphaned dots on + insertion or deletion earlier in the line, especially in + the case of the underscore character. + Interestingly, insertion or deletion of a single character + immediately after a refresh does not leave any droppings, + but any further insertions or deletions do. + While adding a pixel to rect_height (mostly) takes care of + this, it trashes aggressively laid-out elements like the + modeline (overwriting part of the bevel). + OK, unconditionally redraw the bevel, and increment + rect_height by 1. See x_output_display_block. -- sjt */ + struct textual_run *run = &runs[i]; + int rect_width = x_text_width_single_run (f, cachel, run); +#ifndef USE_XFTTEXTENTS_TO_AVOID_FONT_DROPPINGS + int rect_height = FONT_INSTANCE_ASCENT(fi) + + FONT_INSTANCE_DESCENT(fi) + 1; +#else + int rect_height = FONT_INSTANCE_ASCENT(fi) + + FONT_INSTANCE_DESCENT(fi); + XGlyphInfo gi; + if (run->dimension == 2) { + XftTextExtents16 (dpy, + FONT_INSTANCE_X_XFTFONT(fi), + (XftChar16 *) run->ptr, run->len, &gi); + } else { + XftTextExtents8 (dpy, + FONT_INSTANCE_X_XFTFONT(fi), + run->ptr, run->len, &gi); + } + rect_height = rect_height > gi.height + ? rect_height : gi.height; +#endif + + XftDrawRect (xftDraw, &bg, + xpos, ypos, rect_width, rect_height); + } + + if (runs[i].dimension == 1) + XftDrawString8 (xftDraw, &fg, rf, xpos, dl->ypos, + runs[i].ptr, runs[i].len); + else + XftDrawString16 (xftDraw, &fg, rf, xpos, dl->ypos, + (XftChar16 *) runs[i].ptr, runs[i].len); + } + } +#endif /* USE_XFT */ + +#ifdef THIS_IS_X + if (use_x_font) +#endif + { + if (need_clipping) + { + XLIKE_RECTANGLE clip_box; + + clip_box.x = 0; + clip_box.y = 0; + clip_box.width = clip_end - clip_start; + clip_box.height = height; + + XLIKE_SET_CLIP_RECTANGLE (dpy, gc, clip_start, ypos, &clip_box); + } + +#ifdef THIS_IS_X + if (runs[i].dimension == 1) + (bgc ? XDrawString : XDrawImageString) + (dpy, x_win, gc, xpos, dl->ypos, + (char *) runs[i].ptr, runs[i].len); + else + (bgc ? XDrawString16 : XDrawImageString16) + (dpy, x_win, gc, xpos, dl->ypos, + (XChar2b *) runs[i].ptr, runs[i].len); +#else /* THIS_IS_GTK */ + + /* The X specific called different functions (XDraw*String + vs. XDraw*String16), but apparently gdk_draw_text takes care + of that for us. + + BUT, gdk_draw_text also does too much, by dividing the length + by 2. So we fake them out my multiplying the length by the + dimension of the text. This will do the right thing for + single-dimension runs as well of course. + */ + (bgc ? gdk_draw_text : gdk_draw_text_image) + (GDK_DRAWABLE (x_win), FONT_INSTANCE_GTK_FONT (fi), gc, xpos, + dl->ypos, (char *) runs[i].ptr, runs[i].len * runs[i].dimension); +#endif /* (not) THIS_IS_X */ + } + + /* We draw underlines in the same color as the text. */ + if (cachel->underline) + { + int upos, uthick; +#ifdef THIS_IS_X + unsigned long upos_ext, uthick_ext; + XFontStruct *fs = + use_x_font ? FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)) : 0; + /* #### the logic of the next two may be suboptimal: we may want + to use the POSITION and/or THICKNESS information with Xft */ + if (fs && XGetFontProperty (fs, XA_UNDERLINE_POSITION, &upos_ext)) + upos = (int) upos_ext; + else +#else /* THIS_IS_GTK */ + /* Cannot get at font properties in Gtk, so we resort to + guessing */ +#endif /* THIS_IS_GTK */ + upos = dl->descent / 2; +#ifdef THIS_IS_X + if (fs && XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext)) + uthick = (int) uthick_ext; + else +#endif /* THIS_IS_X */ + uthick = 1; + if (dl->ypos + upos < dl->ypos + dl->descent - dl->clip) + { + if (dl->ypos + upos + uthick > dl->ypos + dl->descent - dl->clip) + uthick = dl->descent - dl->clip - upos; + + if (uthick == 1) + { + XLIKE_DRAW_LINE (dpy, x_win, gc, xpos, dl->ypos + upos, + xpos + this_width, dl->ypos + upos); + } + else if (uthick > 1) + { + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, xpos, + dl->ypos + upos, this_width, uthick); + } + } + } + + if (cachel->strikethru) + { +#ifdef THIS_IS_X + int ascent, descent, upos, uthick; + unsigned long ascent_ext, descent_ext, uthick_ext; + XFontStruct *fs = FONT_INSTANCE_X_FONT (fi); +#else /* THIS_IS_GTK */ + gint ascent, descent, upos, uthick; + GdkFont *gfont = FONT_INSTANCE_GTK_FONT (fi); +#endif /* THIS_IS_GTK */ + +#ifdef THIS_IS_X + if (!use_x_font) + { + ascent = dl->ascent; + descent = dl->descent; + uthick = 1; + } + else + { + if (!XGetFontProperty (fs, XA_STRIKEOUT_ASCENT, &ascent_ext)) + ascent = fs->ascent; + else + ascent = (int) ascent_ext; + if (!XGetFontProperty (fs, XA_STRIKEOUT_DESCENT, &descent_ext)) + descent = fs->descent; + else + descent = (int) descent_ext; + if (!XGetFontProperty (fs, XA_UNDERLINE_THICKNESS, &uthick_ext)) + uthick = 1; + else + uthick = (int) uthick_ext; + } +#else /* THIS_IS_GTK */ + /* Cannot get at font properties in Gtk, so we resort to + guessing */ + + ascent = gfont->ascent; + descent = gfont->descent; + uthick = 1; +#endif /* THIS_IS_GTK */ + + upos = ascent - ((ascent + descent) / 2) + 1; + + /* Generally, upos will be positive (above the baseline),so + subtract */ + if (dl->ypos - upos < dl->ypos + dl->descent - dl->clip) + { + if (dl->ypos - upos + uthick > dl->ypos + dl->descent - dl->clip) + uthick = dl->descent - dl->clip + upos; + + if (uthick == 1) + XLIKE_DRAW_LINE (dpy, x_win, gc, xpos, dl->ypos - upos, + xpos + this_width, dl->ypos - upos); + else if (uthick > 1) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, xpos, dl->ypos + upos, + this_width, uthick); + } + } + + /* Restore the GC */ + if (need_clipping) + { +#ifdef USE_XFT + if (!use_x_font) + { + XftDrawSetClip (xftDraw, 0); + } + else +#endif + XLIKE_CLEAR_CLIP_MASK (dpy, gc); + } + + /* If we are actually superimposing the cursor then redraw with just + the appropriate section highlighted. */ + if (cursor_clip && !cursor && focus && cursor_cachel) + { +#ifdef USE_XFT + if (!use_x_font) /* Xft */ + { + XftFont *rf = FONT_INSTANCE_X_XFTFONT (fi); + + { /* set up clipping */ + Region clip_reg = XCreateRegion(); + XRectangle clip_box = { cursor_start, ypos, + cursor_width, height }; + + XUnionRectWithRegion (&clip_box, clip_reg, clip_reg); + XftDrawSetClip(xftDraw, clip_reg); + XDestroyRegion(clip_reg); + } + { /* draw background rectangle & draw text */ + int rect_height = FONT_INSTANCE_ASCENT(fi) + + FONT_INSTANCE_DESCENT(fi); + int rect_width = x_text_width_single_run(f, cachel, &runs[i]); + XftColor xft_color; + + xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->background, 0); + XftDrawRect (xftDraw, &xft_color, + xpos, ypos, rect_width, rect_height); + + xft_color = XFT_FROB_LISP_COLOR (cursor_cachel->foreground, 0); + if (runs[i].dimension == 1) + XftDrawString8 (xftDraw, &xft_color, rf, xpos, dl->ypos, + runs[i].ptr, runs[i].len); + else + XftDrawString16 (xftDraw, &xft_color, rf, xpos, dl->ypos, + (XftChar16 *) runs[i].ptr, runs[i].len); + } + + XftDrawSetClip(xftDraw, 0); + } + else /* core font, not Xft */ +#endif /* USE_XFT */ + { + XLIKE_RECTANGLE clip_box; + XLIKE_GC cgc; + cgc = XLIKE_get_gc (d, font, cursor_cachel->foreground, + cursor_cachel->background, Qnil, Qnil); + + clip_box.x = 0; + clip_box.y = 0; + clip_box.width = cursor_width; + clip_box.height = height; + + XLIKE_SET_CLIP_RECTANGLE (dpy, cgc, cursor_start, ypos, + &clip_box); +#ifdef THIS_IS_X + if (runs[i].dimension == 1) + XDrawImageString (dpy, x_win, cgc, xpos, dl->ypos, + (char *) runs[i].ptr, runs[i].len); + else + XDrawImageString16 (dpy, x_win, cgc, xpos, dl->ypos, + (XChar2b *) runs[i].ptr, runs[i].len); +#else + /* The X specific called different functions (XDraw*String + vs. XDraw*String16), but apparently gdk_draw_text takes care + of that for us. + + BUT, gdk_draw_text also does too much, by dividing the + length by 2. So we fake them out my multiplying the + length by the dimension of the text. This will do the + right thing for single-dimension runs as well of course. + */ + gdk_draw_text_image (GDK_DRAWABLE (x_win), + FONT_INSTANCE_GTK_FONT (fi), cgc, xpos, + dl->ypos, (char *) runs[i].ptr, + runs[i].len * runs[i].dimension); +#endif /* (not) THIS_IS_X */ + + XLIKE_CLEAR_CLIP_MASK (dpy, cgc); + } + } + + xpos += this_width; + } + + /* Draw the non-focus box or bar-cursor as needed. */ + /* Can't this logic be simplified? */ + if (cursor_cachel + && ((cursor && !focus && NILP (bar_cursor_value)) + || (cursor_width + && (cursor_start + cursor_width >= clip_start) + && !NILP (bar_cursor_value)))) + { + int tmp_height, tmp_y; + int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; + int need_clipping = (cursor_start < clip_start + || clip_end < cursor_start + cursor_width); + + /* #### This value is correct (as far as I know) because + all of the times we need to draw this cursor, we will + be called with exactly one character, so we know we + can always use runs[0]. + + This is bogus as all hell, however. The cursor handling in + this function is way bogus and desperately needs to be + cleaned up. (In particular, the drawing of the cursor should + really really be separated out of this function. This may be + a bit tricky now because this function itself does way too + much stuff, a lot of which needs to be moved into + redisplay.c.) This is the only way to be able to easily add + new cursor types or (e.g.) make the bar cursor be able to + span two characters instead of overlaying just one. */ + int bogusly_obtained_ascent_value = + XFONT_INSTANCE (FACE_CACHEL_FONT (cachel, runs[0].charset))->ascent; + + if (!NILP (bar_cursor_value)) + { + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, + make_int (bar_width)); + } + else + { + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, + Qnil, Qnil, Qnil); + } + + tmp_y = dl->ypos - bogusly_obtained_ascent_value; + tmp_height = cursor_height; + if (tmp_y + tmp_height > (int) (ypos + height)) + { + tmp_y = ypos + height - tmp_height; + if (tmp_y < (int) ypos) + tmp_y = ypos; + tmp_height = ypos + height - tmp_y; + } + + if (need_clipping) + { + XLIKE_RECTANGLE clip_box; + clip_box.x = 0; + clip_box.y = 0; + clip_box.width = clip_end - clip_start; + clip_box.height = tmp_height; + XLIKE_SET_CLIP_RECTANGLE (dpy, gc, clip_start, tmp_y, &clip_box); + } + + if (!focus && NILP (bar_cursor_value)) + { + XLIKE_DRAW_RECTANGLE (dpy, x_win, gc, cursor_start, tmp_y, + cursor_width - 1, tmp_height - 1); + } + else if (focus && !NILP (bar_cursor_value)) + { + XLIKE_DRAW_LINE (dpy, x_win, gc, cursor_start + bar_width - 1, tmp_y, + cursor_start + bar_width - 1, + tmp_y + tmp_height - 1); + } + + /* Restore the GC */ + if (need_clipping) + { + XLIKE_CLEAR_CLIP_MASK (dpy, gc); + } + } + +#ifdef USE_XFT +#undef XFT_FROB_LISP_COLOR +#endif +} + +#ifdef THIS_IS_GTK +static void +our_draw_bitmap (GdkDrawable *drawable, + GdkGC *gc, + GdkPixmap *src, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height); +#endif /* THIS_IS_GTK */ + + +void +XLIKE_OUTPUT_XLIKE_PIXMAP (struct frame *f, Lisp_Image_Instance *p, int x, + int y, int xoffset, int yoffset, + int width, int height, + XLIKE_PIXCOLOR fg, XLIKE_PIXCOLOR bg, + XLIKE_GC override_gc) +{ + struct device *d = XDEVICE (f->device); + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc; + XLIKE_GCVALUES gcv; + unsigned long pixmap_mask; + + if (!override_gc) + { + memset (&gcv, ~0, sizeof (gcv)); + gcv.graphics_exposures = XLIKE_FALSE; + XLIKE_SET_PIXCOLOR_COPY (gcv.foreground, fg); + XLIKE_SET_PIXCOLOR_COPY (gcv.background, bg); + pixmap_mask = XLIKE_GC_FOREGROUND | XLIKE_GC_BACKGROUND | XLIKE_GC_EXPOSURES; + + if (IMAGE_INSTANCE_XLIKE_MASK (p)) + { + gcv.function = XLIKE_GX_COPY; + gcv.clip_mask = IMAGE_INSTANCE_XLIKE_MASK (p); + gcv.clip_x_origin = x - xoffset; + gcv.clip_y_origin = y - yoffset; + pixmap_mask |= (XLIKE_GC_FUNCTION | XLIKE_GC_CLIP_MASK | + XLIKE_GC_CLIP_X_ORIGIN | + XLIKE_GC_CLIP_Y_ORIGIN); + /* Can't set a clip rectangle below because we already have a mask. + We could conceivably create a new clipmask by zeroing out + everything outside the clip region. Is it worth it? + Is it possible to get an equivalent effect by changing the + args to XCopyArea below rather than messing with a clip box? + - dkindred@cs.cmu.edu + Yes. We don't clip at all now - andy@xemacs.org + */ + } + + gc = gc_cache_lookup (DEVICE_XLIKE_GC_CACHE (d), &gcv, pixmap_mask); + } + else + { + gc = override_gc; + /* override_gc might have a mask already--we don't want to nuke it. + Maybe we can insist that override_gc have no mask, or use + one of the suggestions above. */ + } + +#ifdef THIS_IS_X + /* depth of 0 means it's a bitmap, not a pixmap, and we should use + XCopyPlane (1 = current foreground color, 0 = background) instead + of XCopyArea, which means that the bits in the pixmap are actual + pixel values, instead of symbolic of fg/bg. */ +#endif /* THIS_IS_X */ + if (IMAGE_INSTANCE_PIXMAP_DEPTH (p) > 0) + { +#ifdef THIS_IS_X + XCopyArea (dpy, + IMAGE_INSTANCE_X_PIXMAP_SLICE + (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc, xoffset, + yoffset, width, + height, x, y); +#else /* THIS_IS_GTK */ + gdk_draw_pixmap (GDK_DRAWABLE (x_win), gc, + IMAGE_INSTANCE_GTK_PIXMAP (p), + xoffset, yoffset, x, y, width, height); +#endif /* THIS_IS_GTK */ + } + else + { +#ifdef THIS_IS_X + XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP_SLICE + (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)), x_win, gc, + xoffset, yoffset, width, height, x, y, 1L); +#else /* THIS_IS_GTK */ + our_draw_bitmap (GDK_DRAWABLE (x_win), gc, + IMAGE_INSTANCE_GTK_PIXMAP (p), + xoffset, yoffset, x, y, width, height); +#endif /* THIS_IS_GTK */ + } +} + +static void +XLIKE_output_pixmap (struct window *w, Lisp_Object image_instance, + struct display_box *db, struct display_glyph_area *dga, + face_index findex, int cursor_start, int cursor_width, + int cursor_height, int UNUSED (bg_pixmap)) +{ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance); + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + + /* Output the pixmap. */ + { + Lisp_Object tmp_pixel; + XLIKE_COLOR tmp_bcolor, tmp_fcolor; + + tmp_pixel = WINDOW_FACE_CACHEL_FOREGROUND (w, findex); + tmp_fcolor = XCOLOR_INSTANCE_XLIKE_COLOR (tmp_pixel); + tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, findex); + tmp_bcolor = XCOLOR_INSTANCE_XLIKE_COLOR (tmp_pixel); + + XLIKE_OUTPUT_XLIKE_PIXMAP (f, p, db->xpos, db->ypos, + dga->xoffset, dga->yoffset, + dga->width, dga->height, + XLIKE_COLOR_TO_PIXCOLOR (tmp_fcolor), + XLIKE_COLOR_TO_PIXCOLOR (tmp_bcolor), 0); + } + + /* Draw a cursor over top of the pixmap. */ + if (cursor_width && cursor_height && (cursor_start >= db->xpos) + && !NILP (w->text_cursor_visible_p) + && (cursor_start < db->xpos + dga->width)) + { + XLIKE_GC gc; + int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); + struct face_cachel *cursor_cachel = + WINDOW_FACE_CACHEL (w, + get_builtin_face_cache_index + (w, Vtext_cursor_face)); + + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); + + if (cursor_width > db->xpos + dga->width - cursor_start) + cursor_width = db->xpos + dga->width - cursor_start; + + if (focus) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, cursor_start, db->ypos, + cursor_width, cursor_height); + else + { + XLIKE_DRAW_RECTANGLE (dpy, x_win, gc, cursor_start, db->ypos, + cursor_width, cursor_height); + } + } +} + +/***************************************************************************** + XLIKE_output_vertical_divider + + Draw a vertical divider down the right side of the given window. + ****************************************************************************/ +static void +XLIKE_output_vertical_divider (struct window *w, int USED_IF_X(clear)) +{ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + Lisp_Object tmp_pixel; + XLIKE_GCVALUES gcv; + XLIKE_GC background_gc; +#ifdef THIS_IS_X + enum edge_style style; +#endif /* THIS_IS_X */ + unsigned long mask; + int x, y1, y2, width, shadow_thickness, spacing, line_width; + face_index div_face = + get_builtin_face_cache_index (w, Vvertical_divider_face); + + width = window_divider_width (w); + shadow_thickness = XINT (w->vertical_divider_shadow_thickness); + spacing = XINT (w->vertical_divider_spacing); + line_width = XINT (w->vertical_divider_line_width); + x = WINDOW_RIGHT (w) - width; + y1 = WINDOW_TOP (w); + y2 = WINDOW_BOTTOM (w); + + memset (&gcv, ~0, sizeof (gcv)); + + tmp_pixel = WINDOW_FACE_CACHEL_BACKGROUND (w, div_face); + + /* First, get the GC's. */ + XLIKE_SET_PIXCOLOR_COPY + (gcv.background, + XLIKE_COLOR_TO_PIXCOLOR (XCOLOR_INSTANCE_XLIKE_COLOR (tmp_pixel))); + gcv.foreground = gcv.background; + gcv.graphics_exposures = XLIKE_FALSE; + mask = XLIKE_GC_FOREGROUND | XLIKE_GC_BACKGROUND | XLIKE_GC_EXPOSURES; + + background_gc = gc_cache_lookup (DEVICE_XLIKE_GC_CACHE (d), &gcv, mask); + + /* Clear the divider area first. This needs to be done when a + window split occurs. */ +#ifdef THIS_IS_X + if (clear) + XClearArea (dpy, x_win, x, y1, width, y2 - y1, False); +#else /* THIS_IS_GTK */ + /* if (clear) */ + gdk_draw_rectangle (GDK_DRAWABLE (x_win), background_gc, TRUE, + x, y1, width, y2 - y1); +#endif /* THIS_IS_GTK */ + +#ifndef THIS_IS_GTK + /* #### FIXME Why not? Formerly '#if 0' in the GDK code */ + /* Draw the divider line. */ + XLIKE_FILL_RECTANGLE (dpy, x_win, background_gc, + x + spacing + shadow_thickness, y1, + line_width, y2 - y1); + + /* This code not formerly present in GTK version, maybe the omittal + is intentional? */ + if (shadow_thickness < 0) + { + shadow_thickness = -shadow_thickness; + style = EDGE_BEVEL_IN; + } + else + { + style = EDGE_BEVEL_OUT; + } +#endif /* not THIS_IS_GTK */ + + /* Draw the shadows around the divider line */ +#ifdef THIS_IS_X + x_bevel_area (w, div_face, x + spacing, y1, + width - 2 * spacing, y2 - y1, + shadow_thickness, EDGE_ALL, style); +#else /* THIS_IS_GTK */ + gtk_output_shadows (f, x + spacing, y1, + width - 2 * spacing, y2 - y1, + shadow_thickness); +#endif /* THIS_IS_GTK */ +} + +/***************************************************************************** + XLIKE_output_blank + + Output a blank by clearing the area it covers in the foreground color + of its face. + ****************************************************************************/ +static void +XLIKE_output_blank (struct window *w, struct display_line *dl, struct rune *rb, + int start_pixpos, int cursor_start, int cursor_width) +{ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc; + struct face_cachel *cursor_cachel = + WINDOW_FACE_CACHEL (w, + get_builtin_face_cache_index + (w, Vtext_cursor_face)); + Lisp_Object bg_pmap; + Lisp_Object buffer = WINDOW_BUFFER (w); + Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, + buffer); + + int x = rb->xpos; + int y = XLIKE_DISPLAY_LINE_YPOS (dl); + int height = XLIKE_DISPLAY_LINE_HEIGHT (dl); + int width = rb->width; + + /* Unmap all subwindows in the area we are going to blank. */ + redisplay_unmap_subwindows_maybe (f, x, y, width, height); + + if (start_pixpos > x) + { + if (start_pixpos >= (x + width)) + return; + else + { + width -= (start_pixpos - x); + x = start_pixpos; + } + } + + bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex); + if (!IMAGE_INSTANCEP (bg_pmap) + || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap))) + bg_pmap = Qnil; + + if (NILP (bg_pmap)) + gc = XLIKE_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), + Qnil, Qnil, Qnil); + else + gc = XLIKE_get_gc (d, Qnil, WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), + WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), bg_pmap, + Qnil); + + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, y, width, height); + + /* If this rune is marked as having the cursor, then it is actually + representing a tab. */ + if (!NILP (w->text_cursor_visible_p) + && (rb->cursor_type == CURSOR_ON + || (cursor_width + && (cursor_start + cursor_width > x) + && cursor_start < (x + width)))) + { + int cursor_height, cursor_y; + int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); + Lisp_Font_Instance *fi; + + fi = XFONT_INSTANCE (FACE_CACHEL_FONT + (WINDOW_FACE_CACHEL (w, rb->findex), + Vcharset_ascii)); + + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); + + cursor_y = dl->ypos - fi->ascent; + cursor_height = fi->height; + if (cursor_y + cursor_height > y + height) + cursor_height = y + height - cursor_y; + + if (focus) + { + if (NILP (bar_cursor_value)) + { + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, cursor_start, cursor_y, + fi->width, cursor_height); + } + else + { + int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; + + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, + Qnil, Qnil, make_int (bar_width)); + XLIKE_DRAW_LINE (dpy, x_win, gc, cursor_start + bar_width - 1, + cursor_y, cursor_start + bar_width - 1, + cursor_y + cursor_height - 1); + } + } + else if (NILP (bar_cursor_value)) + { + XLIKE_DRAW_RECTANGLE (dpy, x_win, gc, cursor_start, cursor_y, + fi->width - 1, cursor_height - 1); + } + } +} + +/***************************************************************************** + XLIKE_output_horizontal_line + + Output a horizontal line in the foreground of its face. + ****************************************************************************/ +static void +XLIKE_output_horizontal_line (struct window *w, struct display_line *dl, + struct rune *rb) +{ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc; + + int x = rb->xpos; + int width = rb->width; + int height = XLIKE_DISPLAY_LINE_HEIGHT (dl); + int ypos1, ypos2, ypos3, ypos4; + + ypos1 = XLIKE_DISPLAY_LINE_YPOS (dl); + ypos2 = ypos1 + rb->object.hline.yoffset; + ypos3 = ypos2 + rb->object.hline.thickness; + ypos4 = dl->ypos + dl->descent - dl->clip; + + /* First clear the area not covered by the line. */ + if (height - rb->object.hline.thickness > 0) + { + gc = XLIKE_get_gc (d, Qnil, + WINDOW_FACE_CACHEL_FOREGROUND (w, rb->findex), + Qnil, Qnil, Qnil); + + if (ypos2 - ypos1 > 0) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1); + if (ypos4 - ypos3 > 0) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, ypos1, width, ypos2 - ypos1); + } + +#ifdef THIS_IS_GTK + { + GtkStyle *style = FRAME_GTK_TEXT_WIDGET (f)->style; + gtk_paint_hline (style, x_win, GTK_STATE_NORMAL, NULL, + FRAME_GTK_TEXT_WIDGET (f), "hline", x, x + width, ypos2); + } +#else /* THIS_IS_X */ + /* Now draw the line. */ + gc = XLIKE_get_gc (d, Qnil, WINDOW_FACE_CACHEL_BACKGROUND (w, rb->findex), + Qnil, Qnil, Qnil); + + if (ypos2 < ypos1) + ypos2 = ypos1; + if (ypos3 > ypos4) + ypos3 = ypos4; + + if (ypos3 - ypos2 > 0) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, ypos2, width, ypos3 - ypos2); +#endif /* THIS_IS_X */ +} + +/**************************************************************************** + XLIKE_clear_region + + Clear the area in the box defined by the given parameters using the + given face. + ****************************************************************************/ +static void +XLIKE_clear_region (Lisp_Object UNUSED (locale), struct device* d, + struct frame* f, face_index UNUSED (findex), int x, int y, + int width, int height, Lisp_Object fcolor, + Lisp_Object bcolor, Lisp_Object background_pixmap) +{ + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc = NULL; + + if (!UNBOUNDP (background_pixmap)) + { + gc = XLIKE_get_gc (d, Qnil, fcolor, bcolor, background_pixmap, Qnil); + } + + if (gc) + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, y, width, height); + else + XLIKE_CLEAR_AREA (dpy, x_win, x, y, width, height); +} + +/***************************************************************************** + xlike_output_eol_cursor + + Draw a cursor at the end of a line. The end-of-line cursor is + narrower than the normal cursor. + ****************************************************************************/ +static void +XLIKE_output_eol_cursor (struct window *w, struct display_line *dl, int xpos, + face_index findex) +{ + struct frame *f = XFRAME (w->frame); + struct device *d = XDEVICE (f->device); + Lisp_Object window; + + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc = NULL; + face_index elt = get_builtin_face_cache_index (w, Vtext_cursor_face); + struct face_cachel *cursor_cachel = WINDOW_FACE_CACHEL (w, elt); + + int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)); + Lisp_Object bar_cursor_value = symbol_value_in_buffer (Qbar_cursor, + WINDOW_BUFFER (w)); + + int x = xpos; + int y = XLIKE_DISPLAY_LINE_YPOS (dl); + int width = EOL_CURSOR_WIDTH; + int height = XLIKE_DISPLAY_LINE_HEIGHT (dl); + int cursor_height, cursor_y; + int defheight, defascent; + + window = wrap_window (w); + redisplay_clear_region (window, findex, x, y, width, height); + + if (NILP (w->text_cursor_visible_p)) + return; + + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, Qnil); + + default_face_font_info (window, &defascent, 0, &defheight, 0, 0); + + /* make sure the cursor is entirely contained between y and y+height */ + cursor_height = min (defheight, height); + cursor_y = max (y, min (y + height - cursor_height, + dl->ypos - defascent)); + + if (focus) + { +#ifdef HAVE_XIM + XIM_SetSpotLocation (f, x - 2 , cursor_y + cursor_height - 2); +#endif /* HAVE_XIM */ + + if (NILP (bar_cursor_value)) + { + XLIKE_FILL_RECTANGLE (dpy, x_win, gc, x, cursor_y, width, + cursor_height); + } + else + { + int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2; + + gc = XLIKE_get_gc (d, Qnil, cursor_cachel->background, Qnil, Qnil, + make_int (bar_width)); + XLIKE_DRAW_LINE (dpy, x_win, gc, x + bar_width - 1, cursor_y, + x + bar_width - 1, cursor_y + cursor_height - 1); + } + } + else if (NILP (bar_cursor_value)) + { + XLIKE_DRAW_RECTANGLE (dpy, x_win, gc, x, cursor_y, width - 1, + cursor_height - 1); + } +} + +static void +XLIKE_clear_frame_window (Lisp_Object window) +{ + struct window *w = XWINDOW (window); + + if (!NILP (w->vchild)) + { + XLIKE_clear_frame_windows (w->vchild); + return; + } + + if (!NILP (w->hchild)) + { + XLIKE_clear_frame_windows (w->hchild); + return; + } + + redisplay_clear_to_window_end (w, WINDOW_TEXT_TOP (w), + WINDOW_TEXT_BOTTOM (w)); +} + +static void +XLIKE_clear_frame_windows (Lisp_Object window) +{ + for (; !NILP (window); window = XWINDOW (window)->next) + XLIKE_clear_frame_window (window); +} + +static void +XLIKE_clear_frame (struct frame *f) +{ + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (XDEVICE (f->device)); + XLIKE_WINDOW x_win = GET_XLIKE_WINDOW (f); + int x, y, width, height; + Lisp_Object frame; + + x = FRAME_LEFT_BORDER_START (f); + width = (FRAME_PIXWIDTH (f) - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) - + FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) - + 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f) - + 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)); + /* #### This adjustment by 1 should be being done in the macros. + There is some small differences between when the menubar is on + and off that we still need to deal with. */ + y = FRAME_TOP_BORDER_START (f) - 1; + height = (FRAME_PIXHEIGHT (f) - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) - + FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) - + 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f) - + 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)) + 1; + + XLIKE_CLEAR_AREA (dpy, x_win, x, y, width, height); + + frame = wrap_frame (f); + + if (!UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vdefault_face, frame)) + || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vleft_margin_face, frame)) + || !UNBOUNDP (FACE_BACKGROUND_PIXMAP (Vright_margin_face, frame))) + { + XLIKE_clear_frame_windows (f->root_window); + } +#ifdef THIS_IS_X + { + struct device *d = XDEVICE (f->device); + if (!(check_if_pending_expose_event (d))) + XFlush (DEVICE_X_DISPLAY (d)); + } +#endif /* THIS_IS_X */ +} + +/* briefly swap the foreground and background colors. + */ + +static int +XLIKE_flash (struct device *d) +{ + struct frame *f = device_selected_frame (d); + XLIKE_DISPLAY dpy = GET_XLIKE_DISPLAY (d); + XLIKE_WINDOW win = GET_XLIKE_WINDOW (f); + XLIKE_GC gc = NULL; + XLIKE_GCVALUES gcv; + XLIKE_COLOR tmp_fcolor, tmp_bcolor; + Lisp_Object tmp_pixel, frame; + struct window *w = XWINDOW (FRAME_ROOT_WINDOW (f)); + int flash_height; + + frame = wrap_frame (f); + + tmp_pixel = FACE_FOREGROUND (Vdefault_face, frame); + XLIKE_SET_PIXCOLOR_COPY (tmp_fcolor, + XCOLOR_INSTANCE_XLIKE_COLOR (tmp_pixel)); + tmp_pixel = FACE_BACKGROUND (Vdefault_face, frame); + XLIKE_SET_PIXCOLOR_COPY (tmp_bcolor, + XCOLOR_INSTANCE_XLIKE_COLOR (tmp_pixel)); + memset (&gcv, ~0, sizeof (gcv)); /* initialize all slots to ~0 */ + XLIKE_SET_PIXCOLOR_NUM (gcv.foreground, + (tmp_fcolor.pixel ^ tmp_bcolor.pixel)); + gcv.function = XLIKE_GX_XOR; + gcv.graphics_exposures = XLIKE_FALSE; + gc = gc_cache_lookup (DEVICE_XLIKE_GC_CACHE (XDEVICE (f->device)), &gcv, + XLIKE_GC_FOREGROUND | XLIKE_GC_FUNCTION | XLIKE_GC_EXPOSURES); + default_face_height_and_width (frame, &flash_height, 0); + + /* If window is tall, flash top and bottom line. */ + if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height) + { + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, w->pixel_top, + w->pixel_width, flash_height); + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, + w->pixel_top + w->pixel_height - flash_height, + w->pixel_width, flash_height); + } + else + /* If it is short, flash it all. */ + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, w->pixel_top, + w->pixel_width, w->pixel_height); + + XLIKE_FLUSH (dpy); + +#ifdef HAVE_SELECT + { + int usecs = 100000; + struct timeval tv; + tv.tv_sec = usecs / 1000000L; + tv.tv_usec = usecs % 1000000L; + /* I'm sure someone is going to complain about this... */ + select (0, 0, 0, 0, &tv); + } +#else +#ifdef HAVE_POLL + poll (0, 0, 100); +#else /* !HAVE_POLL */ +#error bite me +#endif /* HAVE_POLL */ +#endif /* HAVE_SELECT */ + + /* If window is tall, flash top and bottom line. */ + if (EQ (Vvisible_bell, Qtop_bottom) && w->pixel_height > 3 * flash_height) + { + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, w->pixel_top, + w->pixel_width, flash_height); + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, + w->pixel_top + w->pixel_height - flash_height, + w->pixel_width, flash_height); + } + else + /* If it is short, flash it all. */ + XLIKE_FILL_RECTANGLE (dpy, win, gc, w->pixel_left, w->pixel_top, + w->pixel_width, w->pixel_height); + + XLIKE_FLUSH (dpy); + + return 1; +} + + +/************************************************************************/ +/* initialization */ +/************************************************************************/ + +void +console_type_create_redisplay_XLIKE (void) +{ + /* redisplay methods */ + XLIKE_CONSOLE_HAS_METHOD (text_width); + XLIKE_CONSOLE_HAS_METHOD (output_display_block); + XLIKE_CONSOLE_HAS_METHOD (divider_height); + XLIKE_CONSOLE_HAS_METHOD (eol_cursor_width); + XLIKE_CONSOLE_HAS_METHOD (output_vertical_divider); + XLIKE_CONSOLE_HAS_METHOD (clear_region); + XLIKE_CONSOLE_HAS_METHOD (clear_frame); + XLIKE_CONSOLE_HAS_METHOD (flash); + XLIKE_CONSOLE_HAS_METHOD (ring_bell); + XLIKE_CONSOLE_HAS_METHOD (bevel_area); + XLIKE_CONSOLE_HAS_METHOD (output_string); + XLIKE_CONSOLE_HAS_METHOD (output_pixmap); + +#ifdef THIS_IS_X + XLIKE_CONSOLE_HAS_METHOD (window_output_begin); + XLIKE_CONSOLE_HAS_METHOD (window_output_end); +#endif +}