1 /* mswindows output and frame manipulation routines.
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1994 Lucid, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc.
6 This file is part of XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: Not in FSF. */
28 Lots of work done by Ben Wing for Mule
29 Partially rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
35 #include "console-msw.h"
36 #include "objects-msw.h"
43 #include "glyphs-msw.h"
45 #include "redisplay.h"
52 #include "character.h"
55 #define MSWINDOWS_EOL_CURSOR_WIDTH 5
58 * Random forward declarations
60 static void mswindows_update_dc (HDC hdc, Lisp_Object font, Lisp_Object fg,
61 Lisp_Object bg, Lisp_Object bg_pmap);
62 static void mswindows_output_vertical_divider (struct window *w, int clear);
63 static void mswindows_redraw_exposed_windows (Lisp_Object window, int x,
64 int y, int width, int height);
65 static void mswindows_output_dibitmap (struct frame *f,
66 struct Lisp_Image_Instance *p,
67 struct display_box* db,
68 struct display_glyph_area* dga);
70 typedef struct textual_run
78 /* Separate out the text in DYN into a series of textual runs of a
79 particular charset. Also convert the characters as necessary into
80 the format needed by XDrawImageString(), XDrawImageString16(), et
81 al. (This means converting to one or two byte format, possibly
82 tweaking the high bits, and possibly running a CCL program.) You
83 must pre-allocate the space used and pass it in. (This is done so
84 you can alloca() the space.) You need to allocate (2 * len) bytes
85 of TEXT_STORAGE and (len * sizeof (textual_run)) bytes of
86 RUN_STORAGE, where LEN is the length of the dynarr.
88 Returns the number of runs actually used. */
91 separate_textual_runs (unsigned char *text_storage,
92 textual_run *run_storage,
93 CONST Emchar *str, Charcount len)
95 Lisp_Object prev_charset = Qunbound; /* not Qnil because that is a
96 possible valid charset when
97 MULE is not defined */
101 struct ccl_program char_converter;
102 int need_ccl_conversion = 0;
105 for (i = 0; i < len; i++)
113 BREAKUP_CHAR (ch, charset, byte1, byte2);
114 dimension = XCHARSET_DIMENSION (charset);
115 graphic = XCHARSET_GRAPHIC (charset);
117 if (!EQ (charset, prev_charset))
119 run_storage[runs_so_far].ptr = text_storage;
120 run_storage[runs_so_far].charset = charset;
121 run_storage[runs_so_far].dimension = dimension;
125 run_storage[runs_so_far - 1].len =
126 text_storage - run_storage[runs_so_far - 1].ptr;
127 if (run_storage[runs_so_far - 1].dimension == 2)
128 run_storage[runs_so_far - 1].len >>= 1;
131 prev_charset = charset;
134 Lisp_Object ccl_prog = XCHARSET_CCL_PROGRAM (charset);
135 need_ccl_conversion = !NILP (ccl_prog);
136 if (need_ccl_conversion)
137 setup_ccl_program (&char_converter, ccl_prog);
147 else if (graphic == 1)
153 if (need_ccl_conversion)
155 char_converter.reg[0] = XCHARSET_ID (charset);
156 char_converter.reg[1] = byte1;
157 char_converter.reg[2] = byte2;
158 char_converter.ic = 0; /* start at beginning each time */
159 ccl_driver (&char_converter, 0, 0, 0, 0, CCL_MODE_ENCODING);
160 byte1 = char_converter.reg[1];
161 byte2 = char_converter.reg[2];
164 *text_storage++ = (unsigned char) byte1;
166 *text_storage++ = (unsigned char) byte2;
171 run_storage[runs_so_far - 1].len =
172 text_storage - run_storage[runs_so_far - 1].ptr;
173 if (run_storage[runs_so_far - 1].dimension == 2)
174 run_storage[runs_so_far - 1].len >>= 1;
182 mswindows_text_width_single_run (HDC hdc, struct face_cachel *cachel,
185 Lisp_Object font_inst = FACE_CACHEL_FONT (cachel, run->charset);
186 struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font_inst);
189 if (!fi->proportional_p || !hdc)
190 return (fi->width * run->len);
193 assert(run->dimension == 1); /* #### FIXME! */
194 mswindows_update_dc (hdc, font_inst, Qnil, Qnil, Qnil);
195 GetTextExtentPoint32 (hdc, run->ptr, run->len, &size);
201 /*****************************************************************************
204 Given a number of parameters munge the DC so it has those properties.
205 ****************************************************************************/
207 mswindows_update_dc (HDC hdc, Lisp_Object font, Lisp_Object fg,
208 Lisp_Object bg, Lisp_Object bg_pmap)
211 SelectObject(hdc, FONT_INSTANCE_MSWINDOWS_HFONT (XFONT_INSTANCE (font)));
216 SetTextColor (hdc, COLOR_INSTANCE_MSWINDOWS_COLOR
217 (XCOLOR_INSTANCE (fg)));
221 SetBkMode (hdc, OPAQUE);
222 SetBkColor (hdc, COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (bg)));
226 SetBkMode (hdc, TRANSPARENT);
231 /*****************************************************************************
232 mswindows_apply_face_effects
234 Draw underline and strikeout as if this was X.
235 #### On mswindows this really should be done as part of drawing the font.
236 The line width used is chosen arbitrarily from the font height.
237 ****************************************************************************/
239 mswindows_apply_face_effects (HDC hdc, struct display_line *dl, int xpos,
240 int width, struct Lisp_Font_Instance *fi,
241 struct face_cachel *cachel,
242 struct face_cachel *color_cachel)
245 HBRUSH brush, oldbrush;
248 brush = CreateSolidBrush (COLOR_INSTANCE_MSWINDOWS_COLOR (
249 XCOLOR_INSTANCE (color_cachel->foreground)));
252 yclip = dl->ypos + dl->descent - dl->clip;
254 rect.right = xpos + width;
255 oldbrush = SelectObject (hdc, brush);
257 if (cachel->underline)
259 rect.top = dl->ypos + dl->descent/2;
260 rect.bottom = rect.top + (fi->height >= 0x20 ? 2 : 1);
261 if (rect.bottom <= yclip)
262 FillRect (hdc, &rect, brush);
264 if (cachel->strikethru)
266 rect.top = dl->ypos + dl->descent - (dl->ascent + dl->descent)/2;
267 rect.bottom = rect.top + (fi->height >= 0x20 ? 2 : 1);
268 if (rect.bottom <= yclip)
269 FillRect (hdc, &rect, brush);
272 SelectObject (hdc, oldbrush);
273 DeleteObject (brush);
278 /*****************************************************************************
279 mswindows_output_hline
281 Output a horizontal line in the foreground of its face.
282 ****************************************************************************/
284 mswindows_output_hline (struct window *w, struct display_line *dl, struct rune *rb)
285 { /* XXX Implement me */
289 /*****************************************************************************
290 mswindows_output_blank
292 Output a blank by clearing the area it covers in the background color
294 ****************************************************************************/
296 mswindows_output_blank (struct window *w, struct display_line *dl,
297 struct rune *rb, int start_pixpos)
299 struct frame *f = XFRAME (w->frame);
300 RECT rect = { rb->xpos, DISPLAY_LINE_YPOS (dl),
302 DISPLAY_LINE_YEND (dl) };
303 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, rb->findex);
305 Lisp_Object bg_pmap = WINDOW_FACE_CACHEL_BACKGROUND_PIXMAP (w, rb->findex);
307 /* Unmap all subwindows in the area we are going to blank. */
308 redisplay_unmap_subwindows_maybe (f, rb->xpos, DISPLAY_LINE_YPOS (dl),
309 rb->width, DISPLAY_LINE_HEIGHT (dl));
311 if (!IMAGE_INSTANCEP (bg_pmap)
312 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
317 struct display_box db;
318 struct display_glyph_area dga;
319 redisplay_calculate_display_boxes (dl, rb->xpos,
320 /*rb->object.dglyph.xoffset*/ 0,
321 start_pixpos, rb->width,
323 /* blank the background in the appropriate color */
324 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, cachel->foreground,
325 cachel->background, Qnil);
326 redisplay_output_pixmap (w, bg_pmap, &db, &dga, rb->findex,
331 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, Qnil,
332 cachel->background, Qnil);
334 ExtTextOut (FRAME_MSWINDOWS_DC (f), 0, 0, ETO_OPAQUE,
335 &rect, NULL, 0, NULL);
340 /*****************************************************************************
341 mswindows_output_cursor
343 Draw a normal or end-of-line cursor. The end-of-line cursor is
344 narrower than the normal cursor.
345 ****************************************************************************/
347 mswindows_output_cursor (struct window *w, struct display_line *dl, int xpos,
348 int width, face_index findex, Emchar ch, int image_p)
350 struct frame *f = XFRAME (w->frame);
351 struct device *d = XDEVICE (f->device);
352 struct face_cachel *cachel=0;
353 Lisp_Object font = Qnil;
354 int focus = EQ (w->frame, DEVICE_FRAME_WITH_FOCUS_REAL (d));
355 HDC hdc = FRAME_MSWINDOWS_DC (f);
356 unsigned int face_index=0;
360 DISPLAY_LINE_YPOS (dl),
362 DISPLAY_LINE_YEND (dl) };
363 Lisp_Object bar = symbol_value_in_buffer (Qbar_cursor,
365 int bar_p = image_p || !NILP (bar);
366 int cursor_p = !NILP (w->text_cursor_visible_p);
367 int real_char_p = ch != 0;
369 /* Unmap all subwindows in the area we are going to blank. */
370 redisplay_unmap_subwindows_maybe (f, xpos, DISPLAY_LINE_YPOS (dl),
371 width, DISPLAY_LINE_HEIGHT (dl));
375 /* Use the font from the underlying character */
376 cachel = WINDOW_FACE_CACHEL (w, findex);
378 /* #### MULE: Need to know the charset! */
379 font = FACE_CACHEL_FONT (cachel, Vcharset_ascii);
382 if ((focus || bar_p) && real_char_p)
384 p_char = (char*) &ch;
390 struct face_cachel *color_cachel;
392 /* Use cursor fg/bg for block cursor, or character fg/bg for the bar
393 or when we need to erase the cursor. Output nothing at eol if bar
395 face_index = get_builtin_face_cache_index (w, Vtext_cursor_face);
396 color_cachel = WINDOW_FACE_CACHEL (w, ((!cursor_p || bar_p) ?
397 findex : face_index));
398 mswindows_update_dc (hdc, font, color_cachel->foreground,
399 color_cachel->background, Qnil);
400 ExtTextOut (hdc, xpos, dl->ypos, ETO_OPAQUE|ETO_CLIPPED, &rect, p_char, n_char, NULL);
401 if (real_char_p && (cachel->underline || cachel->strikethru))
402 mswindows_apply_face_effects (hdc, dl, xpos, width,
403 XFONT_INSTANCE (font),
404 cachel, color_cachel);
412 rect.right = rect.left + (EQ (bar, Qt) ? 1 : min (2, width));
413 face_index = get_builtin_face_cache_index (w, Vtext_cursor_face);
414 cachel = WINDOW_FACE_CACHEL (w, face_index);
415 mswindows_update_dc (hdc, Qnil, Qnil, cachel->background, Qnil);
416 ExtTextOut (hdc, xpos, dl->ypos, ETO_OPAQUE, &rect, NULL, 0, NULL);
420 /* Now have real character drawn in its own color. We deflate
421 the rectangle so character cell will be bounded by the
422 previously drawn cursor shape */
423 InflateRect (&rect, -1, -1);
427 p_char = (char*) &ch;
431 face_index = get_builtin_face_cache_index (w, Vdefault_face);
432 cachel = WINDOW_FACE_CACHEL (w, (real_char_p ? findex : face_index));
433 mswindows_update_dc (hdc, Qnil, cachel->foreground,
434 cachel->background, Qnil);
435 ExtTextOut (hdc, xpos, dl->ypos, ETO_OPAQUE | ETO_CLIPPED,
436 &rect, p_char, n_char, NULL);
437 if (cachel->underline || cachel->strikethru)
438 mswindows_apply_face_effects (hdc, dl, xpos+1, width-2,
439 XFONT_INSTANCE (font),
445 /*****************************************************************************
446 mswindows_output_string
448 Given a string and a starting position, output that string in the
450 Correctly handles multiple charsets in the string.
452 The meaning of the parameters is something like this:
454 W Window that the text is to be displayed in.
455 DL Display line that this text is on. The values in the
456 structure are used to determine the vertical position and
457 clipping range of the text.
458 BUF Dynamic array of Emchars specifying what is actually to be
460 XPOS X position in pixels where the text should start being drawn.
461 XOFFSET Number of pixels to be chopped off the left side of the
462 text. The effect is as if the text were shifted to the
463 left this many pixels and clipped at XPOS.
464 CLIP_START Clip everything left of this X position.
465 WIDTH Clip everything right of XPOS + WIDTH.
466 FINDEX Index for the face cache element describing how to display
468 ****************************************************************************/
470 mswindows_output_string (struct window *w, struct display_line *dl,
471 Emchar_dynarr *buf, int xpos, int xoffset, int clip_start,
472 int width, face_index findex,
473 int cursor, int cursor_start, int cursor_width,
476 struct frame *f = XFRAME (w->frame);
477 /* struct device *d = XDEVICE (f->device);*/
479 HDC hdc = FRAME_MSWINDOWS_DC (f);
482 int len = Dynarr_length (buf);
483 unsigned char *text_storage = (unsigned char *) alloca (2 * len);
484 textual_run *runs = alloca_array (textual_run, len);
488 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex);
490 XSETWINDOW (window, w);
492 #if 0 /* #### FIXME? */
493 /* We can't work out the width before we've set the font in the DC */
495 width = mswindows_text_width (cachel, Dynarr_atp (buf, 0), Dynarr_length (buf));
500 /* Regularize the variables passed in. */
501 if (clip_start < xpos)
503 clip_end = xpos + width;
504 if (clip_start >= clip_end)
505 /* It's all clipped out. */
510 /* sort out the destination rectangle */
511 height = DISPLAY_LINE_HEIGHT (dl);
512 rect.left = clip_start;
513 rect.top = DISPLAY_LINE_YPOS (dl);
514 rect.right = clip_end;
515 rect.bottom = rect.top + height;
517 /* make sure the area we are about to display is subwindow free. */
518 redisplay_unmap_subwindows_maybe (f, clip_start, DISPLAY_LINE_YPOS (dl),
519 clip_end - clip_start, DISPLAY_LINE_HEIGHT (dl));
521 /* output the background pixmap if there is one */
522 bg_pmap = cachel->background_pixmap;
523 if (!IMAGE_INSTANCEP (bg_pmap)
524 || !IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (bg_pmap)))
529 struct display_box db;
530 struct display_glyph_area dga;
531 redisplay_calculate_display_boxes (dl, xpos + xoffset, 0,
532 clip_start, width, &db, &dga);
533 /* blank the background in the appropriate color */
534 mswindows_update_dc (hdc, Qnil, cachel->foreground,
535 cachel->background, Qnil);
536 redisplay_output_pixmap (w, bg_pmap, &db, &dga, findex,
538 /* output pixmap calls this so we have to recall to get correct
540 cachel = WINDOW_FACE_CACHEL (w, findex);
543 nruns = separate_textual_runs (text_storage, runs, Dynarr_atp (buf, 0),
544 Dynarr_length (buf));
546 for (i = 0; i < nruns; i++)
548 Lisp_Object font = FACE_CACHEL_FONT (cachel, runs[i].charset);
549 struct Lisp_Font_Instance *fi = XFONT_INSTANCE (font);
552 if (EQ (font, Vthe_null_font_instance))
555 mswindows_update_dc (hdc, font, cachel->foreground,
556 NILP(bg_pmap) ? cachel->background : Qnil, Qnil);
558 this_width = mswindows_text_width_single_run (hdc, cachel, runs + i);
560 /* cope with fonts taller than lines */
561 if ((int) fi->height < (int) (height + dl->clip + dl->top_clip))
563 int clear_start = max (xpos, clip_start);
564 int clear_end = min (xpos + this_width, clip_end);
567 redisplay_clear_region (window, findex, clear_start,
568 DISPLAY_LINE_YPOS (dl),
569 clear_end - clear_start,
571 /* output pixmap calls this so we have to recall to get correct
573 cachel = WINDOW_FACE_CACHEL (w, findex);
577 assert (runs[i].dimension == 1); /* #### FIXME: Broken when Mule? */
578 ExtTextOut (hdc, xpos, dl->ypos,
579 NILP(bg_pmap) ? ETO_CLIPPED | ETO_OPAQUE : ETO_CLIPPED,
580 &rect, (char *) runs[i].ptr, runs[i].len, NULL);
582 /* #### X does underline/strikethrough here so we do the same.
583 On mswindows, underline/strikethrough really belongs to the font */
584 if (cachel->underline || cachel->strikethru)
585 mswindows_apply_face_effects (hdc, dl, xpos, this_width, fi,
592 mswindows_output_dibitmap (struct frame *f, struct Lisp_Image_Instance *p,
593 struct display_box* db,
594 struct display_glyph_area* dga)
596 HDC hdc = FRAME_MSWINDOWS_DC (f);
598 COLORREF bgcolor = GetBkColor (hdc);
600 /* first blt the mask */
601 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
604 col.rgbBlue = GetBValue (bgcolor);
605 col.rgbRed = GetRValue (bgcolor);
606 col.rgbGreen = GetGValue (bgcolor);
609 old = SelectObject (FRAME_MSWINDOWS_CDC (f),
610 IMAGE_INSTANCE_MSWINDOWS_MASK (p));
612 SetDIBColorTable (FRAME_MSWINDOWS_CDC (f), 1, 1, &col);
616 dga->width, dga->height,
617 FRAME_MSWINDOWS_CDC (f),
618 dga->xoffset, dga->yoffset,
621 SelectObject (FRAME_MSWINDOWS_CDC (f), old);
624 /* Now blt the bitmap itself, or one of its slices. */
625 old = SelectObject (FRAME_MSWINDOWS_CDC (f),
626 IMAGE_INSTANCE_MSWINDOWS_BITMAP_SLICE
627 (p, IMAGE_INSTANCE_PIXMAP_SLICE (p)));
631 dga->width, dga->height,
632 FRAME_MSWINDOWS_CDC (f),
633 dga->xoffset, dga->yoffset,
634 IMAGE_INSTANCE_MSWINDOWS_MASK (p) ? SRCINVERT : SRCCOPY);
636 SelectObject (FRAME_MSWINDOWS_CDC (f),old);
639 /* X gc's have this nice property that setting the bg pixmap will
640 * output it offset relative to the window. Windows doesn't have this
641 * feature so we have to emulate this by outputting multiple pixmaps.
642 * This is only used for background pixmaps. Normal pixmaps are
643 * outputted once and are scrollable */
645 mswindows_output_dibitmap_region (struct frame *f,
646 struct Lisp_Image_Instance *p,
647 struct display_box *db,
648 struct display_glyph_area *dga)
650 struct display_box xdb = { db->xpos, db->ypos, db->width, db->height };
651 struct display_glyph_area xdga
652 = { 0, 0, IMAGE_INSTANCE_PIXMAP_WIDTH (p),
653 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) };
654 int pxoffset = 0, pyoffset = 0;
658 xdga.width = dga->width;
659 xdga.height = dga->height;
661 else if (!redisplay_normalize_glyph_area (&xdb, &xdga))
664 /* when doing a bg pixmap do a partial pixmap first so that we
665 blt whole pixmaps thereafter */
666 xdga.height = min (xdga.height, IMAGE_INSTANCE_PIXMAP_HEIGHT (p) -
667 db->ypos % IMAGE_INSTANCE_PIXMAP_HEIGHT (p));
669 while (xdga.height > 0)
671 xdga.width = min (min (db->width, IMAGE_INSTANCE_PIXMAP_WIDTH (p)),
672 IMAGE_INSTANCE_PIXMAP_WIDTH (p) -
673 db->xpos % IMAGE_INSTANCE_PIXMAP_WIDTH (p));
675 while (xdga.width > 0)
677 xdb.xpos = db->xpos + pxoffset;
678 xdb.ypos = db->ypos + pyoffset;
679 /* do we need to offset the pixmap vertically? this is necessary
680 for background pixmaps. */
681 xdga.yoffset = xdb.ypos % IMAGE_INSTANCE_PIXMAP_HEIGHT (p);
682 xdga.xoffset = xdb.xpos % IMAGE_INSTANCE_PIXMAP_WIDTH (p);
683 /* the width is handled by mswindows_output_pixmap_region */
684 mswindows_output_dibitmap (f, p, &xdb, &xdga);
685 pxoffset += xdga.width;
686 xdga.width = min ((db->width - pxoffset),
687 IMAGE_INSTANCE_PIXMAP_WIDTH (p));
689 pyoffset += xdga.height;
690 xdga.height = min ((db->height - pyoffset),
691 IMAGE_INSTANCE_PIXMAP_HEIGHT (p));
695 /* Output a pixmap at the desired location.
696 DB normalized display_box.
697 DGA normalized display_glyph_area. */
699 mswindows_output_pixmap (struct window *w, Lisp_Object image_instance,
700 struct display_box *db, struct display_glyph_area *dga,
701 face_index findex, int cursor_start, int cursor_width,
702 int cursor_height, int bg_pixmap)
704 struct frame *f = XFRAME (w->frame);
705 HDC hdc = FRAME_MSWINDOWS_DC (f);
707 struct Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
710 XSETWINDOW (window, w);
712 /* Output the pixmap. Have to do this as many times as is required
713 to fill the given area */
714 mswindows_update_dc (hdc, Qnil,
715 WINDOW_FACE_CACHEL_FOREGROUND (w, findex),
716 WINDOW_FACE_CACHEL_BACKGROUND (w, findex), Qnil);
719 mswindows_output_dibitmap_region (f, p, db, dga);
721 mswindows_output_dibitmap (f, p, db, dga);
724 #ifdef HAVE_SCROLLBARS
726 * This function paints window's deadbox, a rectangle between window
727 * borders and two short edges of both scrollbars.
729 * Function checks whether deadbox intersects with the rectangle pointed
730 * to by PRC, and paints only the intersection
733 mswindows_redisplay_deadbox_maybe (struct window *w, CONST RECT* prc)
735 int sbh = window_scrollbar_height (w);
736 int sbw = window_scrollbar_width (w);
737 RECT rect_dead, rect_paint;
738 if (sbh == 0 || sbw == 0)
741 if (!NILP (w->scrollbar_on_left_p))
742 rect_dead.left = WINDOW_LEFT (w);
744 rect_dead.left = WINDOW_TEXT_RIGHT (w);
745 rect_dead.right = rect_dead.left + sbw;
747 if (!NILP (w->scrollbar_on_top_p))
748 rect_dead.top = WINDOW_TOP (w);
750 rect_dead.top = WINDOW_TEXT_BOTTOM (w);
751 rect_dead.bottom = rect_dead.top + sbh;
753 if (IntersectRect (&rect_paint, &rect_dead, prc))
755 struct frame *f = XFRAME (WINDOW_FRAME (w));
756 FillRect (FRAME_MSWINDOWS_DC (f), &rect_paint,
757 (HBRUSH) (COLOR_BTNFACE+1));
761 #endif /* HAVE_SCROLLBARS */
763 /*****************************************************************************
764 mswindows_redraw_exposed_window
766 Given a bounding box for an area that needs to be redrawn, determine
767 what parts of what lines are contained within and re-output their
769 Copied from redisplay-x.c
770 ****************************************************************************/
772 mswindows_redraw_exposed_window (struct window *w, int x, int y, int width,
775 struct frame *f = XFRAME (w->frame);
777 int orig_windows_structure_changed;
778 RECT rect_window = { WINDOW_LEFT (w), WINDOW_TOP (w),
779 WINDOW_RIGHT (w), WINDOW_BOTTOM (w) };
780 RECT rect_expose = { x, y, x + width, y + height };
783 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
785 if (!NILP (w->vchild))
787 mswindows_redraw_exposed_windows (w->vchild, x, y, width, height);
790 else if (!NILP (w->hchild))
792 mswindows_redraw_exposed_windows (w->hchild, x, y, width, height);
796 /* If the window doesn't intersect the exposed region, we're done here. */
797 if (!IntersectRect (&rect_draw, &rect_window, &rect_expose))
800 /* We do this to make sure that the 3D modelines get redrawn if
801 they are in the exposed region. */
802 orig_windows_structure_changed = f->windows_structure_changed;
803 f->windows_structure_changed = 1;
805 if (window_needs_vertical_divider (w))
807 mswindows_output_vertical_divider (w, 0);
810 for (line = 0; line < Dynarr_length (cdla); line++)
812 struct display_line *cdl = Dynarr_atp (cdla, line);
814 if (DISPLAY_LINE_YPOS (cdl) + DISPLAY_LINE_HEIGHT (cdl)
817 if (DISPLAY_LINE_YPOS (cdl) > rect_draw.bottom)
826 output_display_line (w, 0, cdla, line,
827 rect_draw.left, rect_draw.right);
832 f->windows_structure_changed = orig_windows_structure_changed;
834 /* If there have never been any face cache_elements created, then this
835 expose event doesn't actually have anything to do. */
836 if (Dynarr_largest (w->face_cachels))
837 redisplay_clear_bottom_of_window (w, cdla, rect_draw.top, rect_draw.bottom);
839 #ifdef HAVE_SCROLLBARS
840 mswindows_redisplay_deadbox_maybe (w, &rect_expose);
844 /*****************************************************************************
845 mswindows_redraw_exposed_windows
847 For each window beneath the given window in the window hierarchy,
848 ensure that it is redrawn if necessary after an Expose event.
849 ****************************************************************************/
851 mswindows_redraw_exposed_windows (Lisp_Object window, int x, int y, int width,
854 for (; !NILP (window); window = XWINDOW (window)->next)
855 mswindows_redraw_exposed_window (XWINDOW (window), x, y, width, height);
858 /*****************************************************************************
859 mswindows_redraw_exposed_area
861 For each window on the given frame, ensure that any area in the
862 Exposed area is redrawn.
863 ****************************************************************************/
865 mswindows_redraw_exposed_area (struct frame *f, int x, int y, int width, int height)
867 /* If any window on the frame has had its face cache reset then the
868 redisplay structures are effectively invalid. If we attempt to
869 use them we'll blow up. We mark the frame as changed to ensure
870 that redisplay will do a full update. This probably isn't
871 necessary but it can't hurt. */
873 /* #### We would rather put these off as well but there is currently
874 no combination of flags which will force an unchanged toolbar to
876 MAYBE_FRAMEMETH (f, redraw_exposed_toolbars, (f, x, y, width, height));
878 redraw_exposed_gutters (f, x, y, width, height);
880 if (!f->window_face_cache_reset)
882 mswindows_redraw_exposed_windows (f->root_window, x, y, width, height);
886 MARK_FRAME_CHANGED (f);
890 /*****************************************************************************
893 Draw a 3d border around the specified area on window W.
894 ****************************************************************************/
896 mswindows_bevel_area (struct window *w, face_index findex, int x, int y,
897 int width, int height, int thickness,
898 int edges, enum edge_style style)
900 struct frame *f = XFRAME (w->frame);
904 if (style == EDGE_ETCHED_IN)
906 else if (style == EDGE_ETCHED_OUT)
908 else if (style == EDGE_BEVEL_IN)
911 edge = BDR_SUNKENINNER;
915 else /* EDGE_BEVEL_OUT */
918 edge = BDR_RAISEDINNER;
923 if (edges & EDGE_TOP)
925 if (edges & EDGE_LEFT)
927 if (edges & EDGE_BOTTOM)
929 if (edges & EDGE_RIGHT)
933 RECT rect = { x, y, x + width, y + height };
934 Lisp_Object color = WINDOW_FACE_CACHEL_BACKGROUND (w, findex);
935 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, Qnil, color, Qnil);
937 DrawEdge (FRAME_MSWINDOWS_DC (f), &rect, edge, border);
942 /*****************************************************************************
944 *****************************************************************************/
946 /*****************************************************************************
947 mswindows_divider_height
949 Return the height of the horizontal divider.
950 ****************************************************************************/
952 mswindows_divider_height (void)
954 return 1; /* XXX Copied from redisplay-X.c. What is this? */
957 /*****************************************************************************
958 mswindows_eol_cursor_width
960 Return the width of the end-of-line cursor.
961 ****************************************************************************/
963 mswindows_eol_cursor_width (void)
965 return MSWINDOWS_EOL_CURSOR_WIDTH;
968 /*****************************************************************************
969 mswindows_output_begin
971 Perform any necessary initialization prior to an update.
972 ****************************************************************************/
974 mswindows_output_begin (struct device *d)
978 /*****************************************************************************
981 Perform any necessary flushing of queues when an update has completed.
982 ****************************************************************************/
984 mswindows_output_end (struct device *d)
990 mswindows_flash (struct device *d)
992 struct frame *f = device_selected_frame (d);
995 GetClientRect (FRAME_MSWINDOWS_HANDLE (f), &rc);
996 InvertRect (FRAME_MSWINDOWS_DC (f), &rc);
999 InvertRect (FRAME_MSWINDOWS_DC (f), &rc);
1005 mswindows_ring_bell (struct device *d, int volume, int pitch, int duration)
1007 /* Beep does not work at all, anyways! -kkm */
1008 MessageBeep (MB_OK);
1011 /*****************************************************************************
1012 mswindows_output_display_block
1014 Given a display line, a block number for that start line, output all
1015 runes between start and end in the specified display block.
1016 Ripped off with minimal thought from the corresponding X routine.
1017 ****************************************************************************/
1019 mswindows_output_display_block (struct window *w, struct display_line *dl, int block,
1020 int start, int end, int start_pixpos, int cursor_start,
1021 int cursor_width, int cursor_height)
1023 struct frame *f = XFRAME (w->frame);
1024 Emchar_dynarr *buf = Dynarr_new (Emchar);
1027 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
1028 rune_dynarr *rba = db->runes;
1034 Lisp_Object charset = Qunbound; /* Qnil is a valid charset when
1035 MULE is not defined */
1036 XSETWINDOW (window, w);
1037 rb = Dynarr_atp (rba, start);
1040 /* Nothing to do so don't do anything. */
1043 findex = rb->findex;
1046 if (rb->type == RUNE_CHAR)
1047 charset = CHAR_CHARSET (rb->object.chr.ch);
1050 end = Dynarr_length (rba);
1055 rb = Dynarr_atp (rba, elt);
1057 if (rb->findex == findex && rb->type == RUNE_CHAR
1058 && rb->object.chr.ch != '\n' && rb->cursor_type != CURSOR_ON
1059 && EQ (charset, CHAR_CHARSET (rb->object.chr.ch)))
1061 Dynarr_add (buf, rb->object.chr.ch);
1067 if (Dynarr_length (buf))
1069 mswindows_output_string (w, dl, buf, xpos, 0, start_pixpos, width,
1070 findex, 0, 0, 0, 0);
1077 if (rb->type == RUNE_CHAR)
1079 findex = rb->findex;
1081 charset = CHAR_CHARSET (rb->object.chr.ch);
1083 if (rb->cursor_type == CURSOR_ON)
1085 if (rb->object.chr.ch == '\n')
1087 mswindows_output_cursor (w, dl, xpos, cursor_width,
1092 Dynarr_add (buf, rb->object.chr.ch);
1093 mswindows_output_cursor (w, dl, xpos, cursor_width,
1094 findex, rb->object.chr.ch, 0);
1101 else if (rb->object.chr.ch == '\n')
1103 /* Clear in case a cursor was formerly here. */
1104 redisplay_clear_region (window, findex, xpos,
1105 DISPLAY_LINE_YPOS (dl),
1106 rb->width, DISPLAY_LINE_HEIGHT (dl));
1110 else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE)
1112 if (rb->type == RUNE_BLANK)
1113 mswindows_output_blank (w, dl, rb, start_pixpos);
1116 /* #### Our flagging of when we need to redraw the
1117 modeline shadows sucks. Since RUNE_HLINE is only used
1118 by the modeline at the moment it is a good bet
1119 that if it gets redrawn then we should also
1120 redraw the shadows. This won't be true forever.
1121 We borrow the shadow_thickness_changed flag for
1123 w->shadow_thickness_changed = 1;
1124 mswindows_output_hline (w, dl, rb);
1127 if (rb->cursor_type == CURSOR_ON)
1128 mswindows_output_cursor (w, dl, xpos, cursor_width, rb->findex, 0, 0);
1133 rb = Dynarr_atp (rba, elt);
1135 findex = rb->findex;
1139 else if (rb->type == RUNE_DGLYPH)
1141 Lisp_Object instance;
1142 struct display_box db;
1143 struct display_glyph_area dga;
1144 redisplay_calculate_display_boxes (dl, rb->xpos, rb->object.dglyph.xoffset,
1145 start_pixpos, rb->width,
1148 XSETWINDOW (window, w);
1149 instance = glyph_image_instance (rb->object.dglyph.glyph,
1150 window, ERROR_ME_NOT, 1);
1151 findex = rb->findex;
1153 if (IMAGE_INSTANCEP (instance))
1154 switch (XIMAGE_INSTANCE_TYPE (instance))
1158 /* #### This is way losing. See the comment in
1159 add_glyph_rune(). */
1160 Lisp_Object string =
1161 XIMAGE_INSTANCE_TEXT_STRING (instance);
1162 convert_bufbyte_string_into_emchar_dynarr
1163 (XSTRING_DATA (string), XSTRING_LENGTH (string), buf);
1165 if (rb->cursor_type == CURSOR_ON)
1166 mswindows_output_cursor (w, dl, xpos, cursor_width,
1167 findex, Dynarr_at (buf, 0), 0);
1168 else /* #### redisplay-x passes -1 as the width: why ? */
1169 mswindows_output_string (w, dl, buf, xpos,
1170 rb->object.dglyph.xoffset,
1171 start_pixpos, rb->width, findex,
1177 case IMAGE_MONO_PIXMAP:
1178 case IMAGE_COLOR_PIXMAP:
1179 redisplay_output_pixmap (w, instance, &db, &dga, findex,
1180 cursor_start, cursor_width,
1182 if (rb->cursor_type == CURSOR_ON)
1183 mswindows_output_cursor (w, dl, xpos, cursor_width,
1190 case IMAGE_SUBWINDOW:
1192 redisplay_output_subwindow (w, instance, &db, &dga, findex,
1193 cursor_start, cursor_width,
1195 if (rb->cursor_type == CURSOR_ON)
1196 mswindows_output_cursor (w, dl, xpos, cursor_width,
1201 redisplay_output_layout (w, instance, &db, &dga, findex,
1202 cursor_start, cursor_width,
1204 if (rb->cursor_type == CURSOR_ON)
1205 mswindows_output_cursor (w, dl, xpos, cursor_width,
1210 /* nothing is as nothing does */
1225 if (Dynarr_length (buf))
1226 mswindows_output_string (w, dl, buf, xpos, 0, start_pixpos, width, findex,
1230 && !EQ (Qzero, w->modeline_shadow_thickness)
1232 || f->windows_structure_changed
1233 || w->shadow_thickness_changed))
1234 bevel_modeline (w, dl);
1240 /*****************************************************************************
1241 mswindows_output_vertical_divider
1243 Draw a vertical divider down the right side of the given window.
1244 ****************************************************************************/
1246 mswindows_output_vertical_divider (struct window *w, int clear_unused)
1248 struct frame *f = XFRAME (w->frame);
1250 int spacing = XINT (w->vertical_divider_spacing);
1251 int shadow = XINT (w->vertical_divider_shadow_thickness);
1252 int abs_shadow = abs (shadow);
1253 int line_width = XINT (w->vertical_divider_line_width);
1254 int div_left = WINDOW_RIGHT (w) - window_divider_width (w);
1255 int y1 = WINDOW_TOP (w) + FRAME_TOP_GUTTER_BOUNDS (f);
1256 int y2 = WINDOW_BOTTOM (w) + FRAME_BOTTOM_GUTTER_BOUNDS (f);
1258 /* Clear left and right spacing areas */
1263 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, Qnil,
1264 WINDOW_FACE_CACHEL_BACKGROUND (w, DEFAULT_INDEX), Qnil);
1265 rect.right = WINDOW_RIGHT (w);
1266 rect.left = rect.right - spacing;
1267 ExtTextOut (FRAME_MSWINDOWS_DC (f), 0, 0, ETO_OPAQUE,
1268 &rect, NULL, 0, NULL);
1269 rect.left = div_left;
1270 rect.right = div_left + spacing;
1271 ExtTextOut (FRAME_MSWINDOWS_DC (f), 0, 0, ETO_OPAQUE,
1272 &rect, NULL, 0, NULL);
1275 /* Clear divider face */
1276 rect.top = y1 + abs_shadow;
1277 rect.bottom = y2 - abs_shadow;
1278 rect.left = div_left + spacing + abs_shadow;
1279 rect.right = rect.left + line_width;
1280 if (rect.left < rect.right)
1283 = get_builtin_face_cache_index (w, Vvertical_divider_face);
1284 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, Qnil,
1285 WINDOW_FACE_CACHEL_BACKGROUND (w, div_face), Qnil);
1286 ExtTextOut (FRAME_MSWINDOWS_DC (f), 0, 0, ETO_OPAQUE,
1287 &rect, NULL, 0, NULL);
1290 /* Draw a shadow around the divider */
1293 /* #### This will be fixed to support arbitrary thickness */
1294 InflateRect (&rect, abs_shadow, abs_shadow);
1295 DrawEdge (FRAME_MSWINDOWS_DC (f), &rect,
1296 shadow > 0 ? EDGE_RAISED : EDGE_SUNKEN, BF_RECT);
1300 /****************************************************************************
1301 mswindows_text_width
1303 Given a string and a face, return the string's length in pixels when
1304 displayed in the font associated with the face.
1305 ****************************************************************************/
1307 mswindows_text_width (struct frame *f, struct face_cachel *cachel,
1308 CONST Emchar *str, Charcount len)
1310 int width_so_far = 0;
1311 unsigned char *text_storage = (unsigned char *) alloca (2 * len);
1312 textual_run *runs = alloca_array (textual_run, len);
1316 nruns = separate_textual_runs (text_storage, runs, str, len);
1318 for (i = 0; i < nruns; i++)
1319 width_so_far += mswindows_text_width_single_run (FRAME_MSWINDOWS_DC (f),
1322 return width_so_far;
1326 /****************************************************************************
1327 mswindows_clear_region
1329 Clear the area in the box defined by the given parameters using the
1331 ****************************************************************************/
1333 mswindows_clear_region (Lisp_Object locale, struct device* d, struct frame* f,
1334 face_index findex, int x, int y,
1335 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
1336 Lisp_Object background_pixmap)
1338 RECT rect = { x, y, x+width, y+height };
1340 if (!NILP (background_pixmap))
1342 struct display_box db = { x, y, width, height };
1343 mswindows_update_dc (FRAME_MSWINDOWS_DC (f),
1344 Qnil, fcolor, bcolor, background_pixmap);
1345 mswindows_output_dibitmap_region
1346 ( f, XIMAGE_INSTANCE (background_pixmap), &db, 0);
1350 mswindows_update_dc (FRAME_MSWINDOWS_DC (f), Qnil, Qnil, fcolor, Qnil);
1351 ExtTextOut (FRAME_MSWINDOWS_DC (f), 0, 0, ETO_OPAQUE,
1352 &rect, NULL, 0, NULL);
1355 #ifdef HAVE_SCROLLBARS
1356 if (WINDOWP (locale))
1357 mswindows_redisplay_deadbox_maybe (XWINDOW (locale), &rect);
1361 /* XXX Implement me! */
1363 mswindows_clear_frame (struct frame *f)
1370 /************************************************************************/
1371 /* initialization */
1372 /************************************************************************/
1375 console_type_create_redisplay_mswindows (void)
1377 /* redisplay methods */
1378 CONSOLE_HAS_METHOD (mswindows, text_width);
1379 CONSOLE_HAS_METHOD (mswindows, output_display_block);
1380 CONSOLE_HAS_METHOD (mswindows, divider_height);
1381 CONSOLE_HAS_METHOD (mswindows, eol_cursor_width);
1382 CONSOLE_HAS_METHOD (mswindows, output_vertical_divider);
1383 CONSOLE_HAS_METHOD (mswindows, clear_region);
1384 CONSOLE_HAS_METHOD (mswindows, clear_frame);
1385 CONSOLE_HAS_METHOD (mswindows, output_begin);
1386 CONSOLE_HAS_METHOD (mswindows, output_end);
1387 CONSOLE_HAS_METHOD (mswindows, flash);
1388 CONSOLE_HAS_METHOD (mswindows, ring_bell);
1389 CONSOLE_HAS_METHOD (mswindows, bevel_area);
1390 CONSOLE_HAS_METHOD (mswindows, output_string);
1391 CONSOLE_HAS_METHOD (mswindows, output_pixmap);