(Fset_char_table_range): If range is t, really set all chars to that value.
[emacs.git] / src / w32term.c
bloba40fe2edc4878904aefd63a38f7a5acc3e774a44
1 /* Implementation of GUI terminal on the Microsoft W32 API.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 #include <config.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "lisp.h"
28 #include "blockinput.h"
29 #include "w32term.h"
31 #include "systty.h"
32 #include "systime.h"
34 #include <ctype.h>
35 #include <errno.h>
36 #include <setjmp.h>
37 #include <sys/stat.h>
39 #include "charset.h"
40 #include "character.h"
41 #include "coding.h"
42 #include "ccl.h"
43 #include "frame.h"
44 #include "dispextern.h"
45 #include "fontset.h"
46 #include "termhooks.h"
47 #include "termopts.h"
48 #include "termchar.h"
49 #include "disptab.h"
50 #include "buffer.h"
51 #include "window.h"
52 #include "keyboard.h"
53 #include "intervals.h"
54 #include "process.h"
55 #include "atimer.h"
56 #include "keymap.h"
58 #include "w32heap.h"
59 #include "w32bdf.h"
60 #include <shellapi.h>
62 #ifdef USE_FONT_BACKEND
63 #include "font.h"
64 #endif /* USE_FONT_BACKEND */
67 /* Fringe bitmaps. */
69 static int max_fringe_bmp = 0;
70 static HBITMAP *fringe_bmp = 0;
72 /* Non-nil means Emacs uses toolkit scroll bars. */
74 Lisp_Object Vx_toolkit_scroll_bars;
76 /* Temporary variables for w32_read_socket. */
78 static int last_mousemove_x = 0;
79 static int last_mousemove_y = 0;
81 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
82 #ifndef GET_WHEEL_DELTA_WPARAM
83 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
84 #endif
86 /* Non-zero means that a HELP_EVENT has been generated since Emacs
87 start. */
89 static int any_help_event_p;
91 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
92 static Lisp_Object last_window;
94 /* Non-zero means make use of UNDERLINE_POSITION font properties.
95 (Not yet supported, see TODO in x_draw_glyph_string.) */
96 int x_use_underline_position_properties;
98 /* Non-zero means to draw the underline at the same place as the descent line. */
100 int x_underline_at_descent_line;
102 extern unsigned int msh_mousewheel;
104 extern void free_frame_menubar ();
106 extern int w32_codepage_for_font (char *fontname);
107 extern Cursor w32_load_cursor (LPCTSTR name);
109 extern glyph_metric *w32_BDF_TextMetric(bdffont *fontp,
110 unsigned char *text, int dim);
111 extern Lisp_Object Vwindow_system;
113 #define x_any_window_to_frame x_window_to_frame
114 #define x_top_window_to_frame x_window_to_frame
117 /* This is display since w32 does not support multiple ones. */
118 struct w32_display_info one_w32_display_info;
119 struct w32_display_info *x_display_list;
121 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
122 one for each element of w32_display_list and in the same order.
123 NAME is the name of the frame.
124 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
125 Lisp_Object w32_display_name_list;
128 #ifndef GLYPHSET
129 /* Pre Windows 2000, this was not available, but define it here so
130 that Emacs compiled on such a platform will run on newer versions. */
132 typedef struct tagWCRANGE
134 WCHAR wcLow;
135 USHORT cGlyphs;
136 } WCRANGE;
138 typedef struct tagGLYPHSET
140 DWORD cbThis;
141 DWORD flAccel;
142 DWORD cGlyphsSupported;
143 DWORD cRanges;
144 WCRANGE ranges[1];
145 } GLYPHSET;
147 #endif
149 /* Dynamic linking to GetFontUnicodeRanges (not available on 95, 98, ME). */
150 DWORD (PASCAL *pfnGetFontUnicodeRanges) (HDC device, GLYPHSET *ranges);
152 /* Frame being updated by update_frame. This is declared in term.c.
153 This is set by update_begin and looked at by all the
154 w32 functions. It is zero while not inside an update.
155 In that case, the w32 functions assume that `SELECTED_FRAME ()'
156 is the frame to apply to. */
157 extern struct frame *updating_frame;
159 /* This is a frame waiting to be autoraised, within w32_read_socket. */
160 struct frame *pending_autoraise_frame;
162 /* The handle of the frame that currently owns the system caret. */
163 HWND w32_system_caret_hwnd;
164 int w32_system_caret_height;
165 int w32_system_caret_x;
166 int w32_system_caret_y;
167 int w32_use_visible_system_caret;
169 /* Flag to enable Unicode output in case users wish to use programs
170 like Twinbridge on '95 rather than installed system level support
171 for Far East languages. */
172 int w32_enable_unicode_output;
174 /* Flag to enable Cleartype hack for font metrics. */
175 static int cleartype_active;
177 DWORD dwWindowsThreadId = 0;
178 HANDLE hWindowsThread = NULL;
179 DWORD dwMainThreadId = 0;
180 HANDLE hMainThread = NULL;
182 int vertical_scroll_bar_min_handle;
183 int vertical_scroll_bar_top_border;
184 int vertical_scroll_bar_bottom_border;
186 int last_scroll_bar_drag_pos;
188 /* Mouse movement. */
190 /* Where the mouse was last time we reported a mouse event. */
192 static RECT last_mouse_glyph;
193 static FRAME_PTR last_mouse_glyph_frame;
194 static Lisp_Object last_mouse_press_frame;
196 int w32_num_mouse_buttons;
198 Lisp_Object Vw32_swap_mouse_buttons;
200 /* Control whether x_raise_frame also sets input focus. */
201 Lisp_Object Vw32_grab_focus_on_raise;
203 /* Control whether Caps Lock affects non-ascii characters. */
204 Lisp_Object Vw32_capslock_is_shiftlock;
206 /* Control whether right-alt and left-ctrl should be recognized as AltGr. */
207 Lisp_Object Vw32_recognize_altgr;
209 /* The scroll bar in which the last motion event occurred.
211 If the last motion event occurred in a scroll bar, we set this
212 so w32_mouse_position can know whether to report a scroll bar motion or
213 an ordinary motion.
215 If the last motion event didn't occur in a scroll bar, we set this
216 to Qnil, to tell w32_mouse_position to return an ordinary motion event. */
217 static Lisp_Object last_mouse_scroll_bar;
218 static int last_mouse_scroll_bar_pos;
220 /* This is a hack. We would really prefer that w32_mouse_position would
221 return the time associated with the position it returns, but there
222 doesn't seem to be any way to wrest the time-stamp from the server
223 along with the position query. So, we just keep track of the time
224 of the last movement we received, and return that in hopes that
225 it's somewhat accurate. */
227 static Time last_mouse_movement_time;
229 /* Incremented by w32_read_socket whenever it really tries to read
230 events. */
232 #ifdef __STDC__
233 static int volatile input_signal_count;
234 #else
235 static int input_signal_count;
236 #endif
238 extern Lisp_Object Vcommand_line_args, Vsystem_name;
240 #ifndef USE_CRT_DLL
241 extern int errno;
242 #endif
244 /* A mask of extra modifier bits to put into every keyboard char. */
246 extern EMACS_INT extra_keyboard_modifiers;
248 static void x_update_window_end P_ ((struct window *, int, int));
249 static void w32_handle_tool_bar_click P_ ((struct frame *,
250 struct input_event *));
251 static void w32_define_cursor P_ ((Window, Cursor));
253 void x_lower_frame P_ ((struct frame *));
254 void x_scroll_bar_clear P_ ((struct frame *));
255 void x_wm_set_size_hint P_ ((struct frame *, long, int));
256 void x_raise_frame P_ ((struct frame *));
257 void x_set_window_size P_ ((struct frame *, int, int, int));
258 void x_wm_set_window_state P_ ((struct frame *, int));
259 void x_wm_set_icon_pixmap P_ ((struct frame *, int));
260 static void w32_initialize P_ ((void));
261 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
262 int x_compute_min_glyph_bounds P_ ((struct frame *));
263 static void x_update_end P_ ((struct frame *));
264 static void w32_frame_up_to_date P_ ((struct frame *));
265 static void w32_set_terminal_modes P_ ((struct terminal *));
266 static void w32_reset_terminal_modes P_ ((struct terminal *));
267 static void x_clear_frame P_ ((struct frame *));
268 static void frame_highlight P_ ((struct frame *));
269 static void frame_unhighlight P_ ((struct frame *));
270 static void x_new_focus_frame P_ ((struct w32_display_info *,
271 struct frame *));
272 static void x_focus_changed P_ ((int, int, struct w32_display_info *,
273 struct frame *, struct input_event *));
274 static void w32_detect_focus_change P_ ((struct w32_display_info *,
275 W32Msg *, struct input_event *));
276 static void w32_frame_rehighlight P_ ((struct frame *));
277 static void x_frame_rehighlight P_ ((struct w32_display_info *));
278 static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *));
279 static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int,
280 enum text_cursor_kinds));
281 static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, int, HDC));
282 static BOOL my_show_window P_ ((struct frame *, HWND, int));
283 static void my_set_window_pos P_ ((HWND, HWND, int, int, int, int, UINT));
284 static void my_set_focus P_ ((struct frame *, HWND));
285 static void my_set_foreground_window P_ ((HWND));
286 static void my_destroy_window P_ ((struct frame *, HWND));
288 static Lisp_Object Qvendor_specific_keysyms;
291 /***********************************************************************
292 Debugging
293 ***********************************************************************/
295 #if 0
297 /* This is a function useful for recording debugging information about
298 the sequence of occurrences in this file. */
300 struct record
302 char *locus;
303 int type;
306 struct record event_record[100];
308 int event_record_index;
310 record_event (locus, type)
311 char *locus;
312 int type;
314 if (event_record_index == sizeof (event_record) / sizeof (struct record))
315 event_record_index = 0;
317 event_record[event_record_index].locus = locus;
318 event_record[event_record_index].type = type;
319 event_record_index++;
322 #endif /* 0 */
325 void
326 XChangeGC (void * ignore, XGCValues* gc, unsigned long mask,
327 XGCValues *xgcv)
329 if (mask & GCForeground)
330 gc->foreground = xgcv->foreground;
331 if (mask & GCBackground)
332 gc->background = xgcv->background;
333 if (mask & GCFont)
334 gc->font = xgcv->font;
337 XGCValues *XCreateGC (void * ignore, Window window, unsigned long mask,
338 XGCValues *xgcv)
340 XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues));
341 bzero (gc, sizeof (XGCValues));
343 XChangeGC (ignore, gc, mask, xgcv);
345 return gc;
348 void
349 XGetGCValues (void* ignore, XGCValues *gc,
350 unsigned long mask, XGCValues *xgcv)
352 XChangeGC (ignore, xgcv, mask, gc);
355 static void
356 w32_set_clip_rectangle (HDC hdc, RECT *rect)
358 if (rect)
360 HRGN clip_region = CreateRectRgnIndirect (rect);
361 SelectClipRgn (hdc, clip_region);
362 DeleteObject (clip_region);
364 else
365 SelectClipRgn (hdc, NULL);
369 /* Draw a hollow rectangle at the specified position. */
370 void
371 w32_draw_rectangle (HDC hdc, XGCValues *gc, int x, int y,
372 int width, int height)
374 HBRUSH hb, oldhb;
375 HPEN hp, oldhp;
377 hb = CreateSolidBrush (gc->background);
378 hp = CreatePen (PS_SOLID, 0, gc->foreground);
379 oldhb = SelectObject (hdc, hb);
380 oldhp = SelectObject (hdc, hp);
382 Rectangle (hdc, x, y, x + width, y + height);
384 SelectObject (hdc, oldhb);
385 SelectObject (hdc, oldhp);
386 DeleteObject (hb);
387 DeleteObject (hp);
390 /* Draw a filled rectangle at the specified position. */
391 void
392 w32_fill_rect (f, hdc, pix, lprect)
393 FRAME_PTR f;
394 HDC hdc;
395 COLORREF pix;
396 RECT * lprect;
398 HBRUSH hb;
400 hb = CreateSolidBrush (pix);
401 FillRect (hdc, lprect, hb);
402 DeleteObject (hb);
405 void
406 w32_clear_window (f)
407 FRAME_PTR f;
409 RECT rect;
410 HDC hdc = get_frame_dc (f);
412 /* Under certain conditions, this can be called at startup with
413 a console frame pointer before the GUI frame is created. An HDC
414 of 0 indicates this. */
415 if (hdc)
417 GetClientRect (FRAME_W32_WINDOW (f), &rect);
418 w32_clear_rect (f, hdc, &rect);
421 release_frame_dc (f, hdc);
425 /***********************************************************************
426 Starting and ending an update
427 ***********************************************************************/
429 /* Start an update of frame F. This function is installed as a hook
430 for update_begin, i.e. it is called when update_begin is called.
431 This function is called prior to calls to x_update_window_begin for
432 each window being updated. */
434 static void
435 x_update_begin (f)
436 struct frame *f;
438 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f);
440 if (! FRAME_W32_P (f))
441 return;
443 /* Regenerate display palette before drawing if list of requested
444 colors has changed. */
445 if (display_info->regen_palette)
447 w32_regenerate_palette (f);
448 display_info->regen_palette = FALSE;
453 /* Start update of window W. Set the global variable updated_window
454 to the window being updated and set output_cursor to the cursor
455 position of W. */
457 static void
458 x_update_window_begin (w)
459 struct window *w;
461 struct frame *f = XFRAME (WINDOW_FRAME (w));
462 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f);
464 /* Hide the system caret during an update. */
465 if (w32_use_visible_system_caret && w32_system_caret_hwnd)
467 SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0);
470 updated_window = w;
471 set_output_cursor (&w->cursor);
473 BLOCK_INPUT;
475 if (f == display_info->mouse_face_mouse_frame)
477 /* Don't do highlighting for mouse motion during the update. */
478 display_info->mouse_face_defer = 1;
480 /* If F needs to be redrawn, simply forget about any prior mouse
481 highlighting. */
482 if (FRAME_GARBAGED_P (f))
483 display_info->mouse_face_window = Qnil;
485 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
486 their mouse_face_p flag set, which means that they are always
487 unequal to rows in a desired matrix which never have that
488 flag set. So, rows containing mouse-face glyphs are never
489 scrolled, and we don't have to switch the mouse highlight off
490 here to prevent it from being scrolled. */
492 /* Can we tell that this update does not affect the window
493 where the mouse highlight is? If so, no need to turn off.
494 Likewise, don't do anything if the frame is garbaged;
495 in that case, the frame's current matrix that we would use
496 is all wrong, and we will redisplay that line anyway. */
497 if (!NILP (display_info->mouse_face_window)
498 && w == XWINDOW (display_info->mouse_face_window))
500 int i;
502 for (i = 0; i < w->desired_matrix->nrows; ++i)
503 if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i))
504 break;
506 if (i < w->desired_matrix->nrows)
507 clear_mouse_face (display_info);
509 #endif /* 0 */
512 UNBLOCK_INPUT;
515 /* Draw a vertical window border from (x,y0) to (x,y1) */
517 static void
518 w32_draw_vertical_window_border (w, x, y0, y1)
519 struct window *w;
520 int x, y0, y1;
522 struct frame *f = XFRAME (WINDOW_FRAME (w));
523 RECT r;
524 HDC hdc;
525 struct face *face;
527 r.left = x;
528 r.right = x + 1;
529 r.top = y0;
530 r.bottom = y1;
532 hdc = get_frame_dc (f);
533 face = FACE_FROM_ID (f, VERTICAL_BORDER_FACE_ID);
534 if (face)
535 w32_fill_rect (f, hdc, face->foreground, &r);
536 else
537 w32_fill_rect (f, hdc, FRAME_FOREGROUND_PIXEL (f), &r);
539 release_frame_dc (f, hdc);
543 /* End update of window W (which is equal to updated_window).
545 Draw vertical borders between horizontally adjacent windows, and
546 display W's cursor if CURSOR_ON_P is non-zero.
548 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
549 glyphs in mouse-face were overwritten. In that case we have to
550 make sure that the mouse-highlight is properly redrawn.
552 W may be a menu bar pseudo-window in case we don't have X toolkit
553 support. Such windows don't have a cursor, so don't display it
554 here. */
556 static void
557 x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
558 struct window *w;
559 int cursor_on_p, mouse_face_overwritten_p;
561 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (XFRAME (w->frame));
563 if (!w->pseudo_window_p)
565 BLOCK_INPUT;
567 if (cursor_on_p)
568 display_and_set_cursor (w, 1, output_cursor.hpos,
569 output_cursor.vpos,
570 output_cursor.x, output_cursor.y);
572 if (draw_window_fringes (w, 1))
573 x_draw_vertical_border (w);
575 UNBLOCK_INPUT;
578 /* If a row with mouse-face was overwritten, arrange for
579 XTframe_up_to_date to redisplay the mouse highlight. */
580 if (mouse_face_overwritten_p)
582 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
583 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
584 dpyinfo->mouse_face_window = Qnil;
587 /* Unhide the caret. This won't actually show the cursor, unless it
588 was visible before the corresponding call to HideCaret in
589 x_update_window_begin. */
590 if (w32_use_visible_system_caret && w32_system_caret_hwnd)
592 SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0);
595 updated_window = NULL;
599 /* End update of frame F. This function is installed as a hook in
600 update_end. */
602 static void
603 x_update_end (f)
604 struct frame *f;
606 if (! FRAME_W32_P (f))
607 return;
609 /* Mouse highlight may be displayed again. */
610 FRAME_W32_DISPLAY_INFO (f)->mouse_face_defer = 0;
614 /* This function is called from various places in xdisp.c whenever a
615 complete update has been performed. The global variable
616 updated_window is not available here. */
618 static void
619 w32_frame_up_to_date (f)
620 struct frame *f;
622 if (FRAME_W32_P (f))
624 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
626 if (dpyinfo->mouse_face_deferred_gc
627 || f == dpyinfo->mouse_face_mouse_frame)
629 BLOCK_INPUT;
630 if (dpyinfo->mouse_face_mouse_frame)
631 note_mouse_highlight (dpyinfo->mouse_face_mouse_frame,
632 dpyinfo->mouse_face_mouse_x,
633 dpyinfo->mouse_face_mouse_y);
634 dpyinfo->mouse_face_deferred_gc = 0;
635 UNBLOCK_INPUT;
641 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
642 arrow bitmaps, or clear the fringes if no bitmaps are required
643 before DESIRED_ROW is made current. The window being updated is
644 found in updated_window. This function is called from
645 update_window_line only if it is known that there are differences
646 between bitmaps to be drawn between current row and DESIRED_ROW. */
648 static void
649 x_after_update_window_line (desired_row)
650 struct glyph_row *desired_row;
652 struct window *w = updated_window;
653 struct frame *f;
654 int width, height;
656 xassert (w);
658 if (!desired_row->mode_line_p && !w->pseudo_window_p)
659 desired_row->redraw_fringe_bitmaps_p = 1;
661 /* When a window has disappeared, make sure that no rest of
662 full-width rows stays visible in the internal border. Could
663 check here if updated_window is the leftmost/rightmost window,
664 but I guess it's not worth doing since vertically split windows
665 are almost never used, internal border is rarely set, and the
666 overhead is very small. */
667 if (windows_or_buffers_changed
668 && desired_row->full_width_p
669 && (f = XFRAME (w->frame),
670 width = FRAME_INTERNAL_BORDER_WIDTH (f),
671 width != 0)
672 && (height = desired_row->visible_height,
673 height > 0))
675 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
677 /* Internal border is drawn below the tool bar. */
678 if (WINDOWP (f->tool_bar_window)
679 && w == XWINDOW (f->tool_bar_window))
680 y -= width;
682 BLOCK_INPUT;
684 HDC hdc = get_frame_dc (f);
685 w32_clear_area (f, hdc, 0, y, width, height);
686 w32_clear_area (f, hdc, FRAME_PIXEL_WIDTH (f) - width,
687 y, width, height);
688 release_frame_dc (f, hdc);
690 UNBLOCK_INPUT;
695 /* Draw the bitmap WHICH in one of the left or right fringes of
696 window W. ROW is the glyph row for which to display the bitmap; it
697 determines the vertical position at which the bitmap has to be
698 drawn. */
700 static void
701 w32_draw_fringe_bitmap (w, row, p)
702 struct window *w;
703 struct glyph_row *row;
704 struct draw_fringe_bitmap_params *p;
706 struct frame *f = XFRAME (WINDOW_FRAME (w));
707 HDC hdc;
708 struct face *face = p->face;
709 int rowY;
711 hdc = get_frame_dc (f);
713 if (!p->overlay_p)
715 int bx = p->bx, by = p->by, nx = p->nx, ny = p->ny;
717 /* If the fringe is adjacent to the left (right) scroll bar of a
718 leftmost (rightmost, respectively) window, then extend its
719 background to the gap between the fringe and the bar. */
720 if ((WINDOW_LEFTMOST_P (w)
721 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
722 || (WINDOW_RIGHTMOST_P (w)
723 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)))
725 int sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w);
727 if (sb_width > 0)
729 int left = WINDOW_SCROLL_BAR_AREA_X (w);
730 int width = (WINDOW_CONFIG_SCROLL_BAR_COLS (w)
731 * FRAME_COLUMN_WIDTH (f));
733 if (bx < 0)
735 /* Bitmap fills the fringe. */
736 if (left + width == p->x)
737 bx = left + sb_width;
738 else if (p->x + p->wd == left)
739 bx = left;
740 if (bx >= 0)
742 int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
744 nx = width - sb_width;
745 by = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height,
746 row->y));
747 ny = row->visible_height;
750 else
752 if (left + width == bx)
754 bx = left + sb_width;
755 nx += width - sb_width;
757 else if (bx + nx == left)
758 nx += width - sb_width;
763 if (bx >= 0 && nx > 0)
764 w32_fill_area (f, hdc, face->background, bx, by, nx, ny);
767 /* Must clip because of partially visible lines. */
768 rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y);
769 if (p->y < rowY)
771 /* Adjust position of "bottom aligned" bitmap on partially
772 visible last row. */
773 int oldY = row->y;
774 int oldVH = row->visible_height;
775 row->visible_height = p->h;
776 row->y -= rowY - p->y;
777 w32_clip_to_row (w, row, -1, hdc);
778 row->y = oldY;
779 row->visible_height = oldVH;
781 else
782 w32_clip_to_row (w, row, -1, hdc);
784 if (p->which && p->which < max_fringe_bmp)
786 HBITMAP pixmap = fringe_bmp[p->which];
787 HDC compat_hdc;
788 HANDLE horig_obj;
790 compat_hdc = CreateCompatibleDC (hdc);
792 SaveDC (hdc);
794 horig_obj = SelectObject (compat_hdc, pixmap);
796 /* Paint overlays transparently. */
797 if (p->overlay_p)
799 HBRUSH h_brush, h_orig_brush;
801 SetTextColor (hdc, BLACK_PIX_DEFAULT (f));
802 SetBkColor (hdc, WHITE_PIX_DEFAULT (f));
803 h_brush = CreateSolidBrush (face->foreground);
804 h_orig_brush = SelectObject (hdc, h_brush);
806 BitBlt (hdc, p->x, p->y, p->wd, p->h,
807 compat_hdc, 0, p->dh,
808 DSTINVERT);
809 BitBlt (hdc, p->x, p->y, p->wd, p->h,
810 compat_hdc, 0, p->dh,
811 0x2E064A);
812 BitBlt (hdc, p->x, p->y, p->wd, p->h,
813 compat_hdc, 0, p->dh,
814 DSTINVERT);
816 SelectObject (hdc, h_orig_brush);
817 DeleteObject (h_brush);
819 else
821 SetTextColor (hdc, face->background);
822 SetBkColor (hdc, (p->cursor_p
823 ? f->output_data.w32->cursor_pixel
824 : face->foreground));
826 BitBlt (hdc, p->x, p->y, p->wd, p->h,
827 compat_hdc, 0, p->dh,
828 SRCCOPY);
831 SelectObject (compat_hdc, horig_obj);
832 DeleteDC (compat_hdc);
833 RestoreDC (hdc, -1);
836 w32_set_clip_rectangle (hdc, NULL);
838 release_frame_dc (f, hdc);
841 static void
842 w32_define_fringe_bitmap (which, bits, h, wd)
843 int which;
844 unsigned short *bits;
845 int h, wd;
847 if (which >= max_fringe_bmp)
849 int i = max_fringe_bmp;
850 max_fringe_bmp = which + 20;
851 fringe_bmp = (HBITMAP *) xrealloc (fringe_bmp, max_fringe_bmp * sizeof (HBITMAP));
852 while (i < max_fringe_bmp)
853 fringe_bmp[i++] = 0;
856 fringe_bmp[which] = CreateBitmap (wd, h, 1, 1, bits);
859 static void
860 w32_destroy_fringe_bitmap (which)
861 int which;
863 if (which >= max_fringe_bmp)
864 return;
866 if (fringe_bmp[which])
867 DeleteObject (fringe_bmp[which]);
868 fringe_bmp[which] = 0;
873 /* This is called when starting Emacs and when restarting after
874 suspend. When starting Emacs, no window is mapped. And nothing
875 must be done to Emacs's own window if it is suspended (though that
876 rarely happens). */
878 static void
879 w32_set_terminal_modes (struct terminal *term)
883 /* This is called when exiting or suspending Emacs. Exiting will make
884 the W32 windows go away, and suspending requires no action. */
886 static void
887 w32_reset_terminal_modes (struct terminal *term)
893 /***********************************************************************
894 Display Iterator
895 ***********************************************************************/
897 /* Function prototypes of this page. */
899 XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int));
900 static int w32_encode_char P_ ((int, wchar_t *, struct font_info *,
901 struct charset *, int *));
904 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
905 If CHAR2B is not contained in FONT, the font's default character
906 metric is returned. */
908 static int
909 w32_bdf_per_char_metric (font, char2b, dim, pcm)
910 XFontStruct *font;
911 wchar_t *char2b;
912 int dim;
913 XCharStruct * pcm;
915 glyph_metric * bdf_metric;
916 char buf[2];
918 if (dim == 1)
919 buf[0] = (char)(*char2b);
920 else
922 buf[0] = XCHAR2B_BYTE1 (char2b);
923 buf[1] = XCHAR2B_BYTE2 (char2b);
926 bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim);
928 if (bdf_metric)
930 pcm->width = bdf_metric->dwidth;
931 pcm->lbearing = bdf_metric->bbox;
932 pcm->rbearing = bdf_metric->dwidth
933 - (bdf_metric->bbox + bdf_metric->bbw);
934 pcm->ascent = bdf_metric->bboy + bdf_metric->bbh;
935 pcm->descent = -bdf_metric->bboy;
937 return 1;
939 return 0;
943 static int
944 w32_native_per_char_metric (font, char2b, font_type, pcm)
945 XFontStruct *font;
946 wchar_t *char2b;
947 enum w32_char_font_type font_type;
948 XCharStruct * pcm;
950 HDC hdc = GetDC (NULL);
951 HFONT old_font;
952 BOOL retval = FALSE;
954 xassert (font && char2b);
955 xassert (font->hfont);
956 xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT);
958 old_font = SelectObject (hdc, font->hfont);
960 if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0)
962 ABC char_widths;
964 if (font_type == UNICODE_FONT)
965 retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths);
966 else
967 retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths);
969 if (retval)
971 #if 0
972 /* Disabled until we can find a way to get the right results
973 on all versions of Windows. */
975 /* Don't trust the ABC widths. For synthesized fonts they are
976 wrong, and so is the result of GetCharWidth()! */
977 int real_width;
978 GetCharWidth (hdc, *char2b, *char2b, &real_width);
979 #endif
980 if (cleartype_active)
982 /* Cleartype antialiasing causes characters to overhang
983 by a pixel on each side compared with what GetCharABCWidths
984 reports. */
985 char_widths.abcA -= 1;
986 char_widths.abcC -= 1;
987 char_widths.abcB += 2;
990 pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC;
991 #if 0
992 /* As far as I can tell, this is the best way to determine what
993 ExtTextOut will do with the broken font. */
994 if (pcm->width != real_width)
995 pcm->width = (pcm->width + real_width) / 2;
996 #endif
997 pcm->lbearing = char_widths.abcA;
998 pcm->rbearing = char_widths.abcA + char_widths.abcB;
999 pcm->ascent = FONT_BASE (font);
1000 pcm->descent = FONT_DESCENT (font);
1004 if (!retval)
1006 /* Either font is not a True-type font, or GetCharABCWidthsW
1007 failed (it is not supported on Windows 9x for instance), so we
1008 can't determine the full info we would like. All is not lost
1009 though - we can call GetTextExtentPoint32 to get rbearing and
1010 deduce width based on the font's per-string overhang. lbearing
1011 is assumed to be zero. */
1013 /* TODO: Some Thai characters (and other composites if Windows
1014 supports them) do have lbearing, and report their total width
1015 as zero. Need some way of handling them when
1016 GetCharABCWidthsW fails. */
1017 SIZE sz;
1019 if (font_type == UNICODE_FONT)
1020 retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz);
1021 else
1022 retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz);
1024 if (retval)
1026 pcm->width = sz.cx;
1027 pcm->rbearing = sz.cx + font->tm.tmOverhang;
1028 pcm->lbearing = 0;
1029 pcm->ascent = FONT_BASE (font);
1030 pcm->descent = FONT_DESCENT (font);
1035 if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)
1037 retval = FALSE;
1040 SelectObject (hdc, old_font);
1041 ReleaseDC (NULL, hdc);
1043 return retval;
1047 XCharStruct *
1048 w32_per_char_metric (font, char2b, font_type)
1049 XFontStruct *font;
1050 wchar_t *char2b;
1051 int /* enum w32_char_font_type */ font_type;
1053 /* The result metric information. */
1054 XCharStruct *pcm;
1055 BOOL retval;
1057 xassert (font && char2b);
1059 /* TODO: This function is currently called through the RIF, and in
1060 some cases font_type is UNKNOWN_FONT. We currently allow the
1061 cached metrics to be used, which seems to work, but in cases
1062 where font_type is UNKNOWN_FONT, we probably haven't encoded
1063 char2b appropriately. All callers need checking to see what they
1064 are passing. This is most likely to affect variable width fonts
1065 outside the Latin-1 range, particularly in languages like Thai
1066 that rely on rbearing and lbearing to provide composition. I
1067 don't think that is working currently anyway, but we don't seem
1068 to have anyone testing such languages on Windows. */
1070 /* Handle the common cases quickly. */
1071 if (!font->bdf && font->per_char == NULL)
1072 /* TODO: determine whether char2b exists in font? */
1073 return &font->max_bounds;
1074 else if (!font->bdf && *char2b < 128)
1075 return &font->per_char[*char2b];
1077 xassert (font_type != UNKNOWN_FONT);
1079 pcm = &font->scratch;
1081 if (font_type == BDF_1D_FONT)
1082 retval = w32_bdf_per_char_metric (font, char2b, 1, pcm);
1083 else if (font_type == BDF_2D_FONT)
1084 retval = w32_bdf_per_char_metric (font, char2b, 2, pcm);
1085 else
1086 retval = w32_native_per_char_metric (font, char2b, font_type, pcm);
1088 if (retval)
1089 return pcm;
1091 return NULL;
1094 void
1095 w32_cache_char_metrics (font)
1096 XFontStruct *font;
1098 wchar_t char2b = L'x';
1100 /* Cache char metrics for the common cases. */
1101 if (font->bdf)
1103 /* TODO: determine whether font is fixed-pitch. */
1104 if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds))
1106 /* Use the font width and height as max bounds, as not all BDF
1107 fonts contain the letter 'x'. */
1108 font->max_bounds.width = FONT_WIDTH (font);
1109 font->max_bounds.lbearing = -font->bdf->llx;
1110 font->max_bounds.rbearing = FONT_WIDTH (font) - font->bdf->urx;
1111 font->max_bounds.ascent = FONT_BASE (font);
1112 font->max_bounds.descent = FONT_DESCENT (font);
1115 else
1117 if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0)
1118 /* Some fonts (eg DBCS fonts) are marked as fixed width even
1119 though they contain characters of different widths. */
1120 || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth))
1122 /* Font is not fixed pitch, so cache per_char info for the
1123 ASCII characters. It would be much more work, and probably
1124 not worth it, to cache other chars, since we may change
1125 between using Unicode and ANSI text drawing functions at
1126 run-time. */
1127 int i;
1129 font->per_char = xmalloc (128 * sizeof(XCharStruct));
1130 for (i = 0; i < 128; i++)
1132 char2b = i;
1133 w32_native_per_char_metric (font, &char2b, ANSI_FONT,
1134 &font->per_char[i]);
1137 else
1138 w32_native_per_char_metric (font, &char2b, ANSI_FONT,
1139 &font->max_bounds);
1144 /* Determine if a font is double byte. */
1145 static int
1146 w32_font_is_double_byte (XFontStruct *font)
1148 return font->double_byte_p;
1152 static BOOL
1153 w32_use_unicode_for_codepage (codepage)
1154 int codepage;
1156 /* If the current codepage is supported, use Unicode for output. */
1157 return (w32_enable_unicode_output
1158 && codepage != CP_8BIT
1159 && (codepage == CP_UNICODE || IsValidCodePage (codepage)));
1162 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1163 the two-byte form of C. Encoding is returned in *CHAR2B. */
1165 static int /* enum w32_char_font_type */
1166 w32_encode_char (c, char2b, font_info, charset, two_byte_p)
1167 int c;
1168 wchar_t *char2b;
1169 struct font_info *font_info;
1170 struct charset *charset;
1171 int * two_byte_p;
1173 int codepage;
1174 int unicode_p = 0;
1175 int internal_two_byte_p = 0;
1177 XFontStruct *font = font_info->font;
1179 internal_two_byte_p = w32_font_is_double_byte (font);
1180 codepage = font_info->codepage;
1182 /* If font can output unicode, use the original unicode character. */
1183 if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage)
1184 && c >= 0x100)
1186 *char2b = c;
1187 unicode_p = 1;
1188 internal_two_byte_p = 1;
1191 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1192 This may be either a program in a special encoder language or a
1193 fixed encoding. */
1194 else if (font_info->font_encoder)
1196 /* It's a program. */
1197 struct ccl_program *ccl = font_info->font_encoder;
1199 if (CHARSET_DIMENSION (charset) == 1)
1201 ccl->reg[0] = CHARSET_ID (charset);
1202 ccl->reg[1] = XCHAR2B_BYTE2 (char2b);
1203 ccl->reg[2] = -1;
1205 else
1207 ccl->reg[0] = CHARSET_ID (charset);
1208 ccl->reg[1] = XCHAR2B_BYTE1 (char2b);
1209 ccl->reg[2] = XCHAR2B_BYTE2 (char2b);
1212 ccl_driver (ccl, NULL, NULL, 0, 0, Qnil);
1214 /* We assume that MSBs are appropriately set/reset by CCL
1215 program. */
1216 if (!internal_two_byte_p) /* 1-byte font */
1217 STORE_XCHAR2B (char2b, 0, ccl->reg[1]);
1218 else
1219 STORE_XCHAR2B (char2b, ccl->reg[1], ccl->reg[2]);
1221 else if (font_info->encoding_type)
1223 /* Fixed encoding scheme. See fontset.h for the meaning of the
1224 encoding numbers. */
1225 unsigned char enc = font_info->encoding_type;
1227 if ((enc == 1 || enc == 2)
1228 && CHARSET_DIMENSION (charset) == 2)
1229 STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b) | 0x80, XCHAR2B_BYTE2 (char2b));
1231 if (enc == 1 || enc == 3 || (enc == 4 && CHARSET_DIMENSION (charset) == 1))
1232 STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b), XCHAR2B_BYTE2 (char2b) | 0x80);
1233 else if (enc == 4)
1235 int code = (int) (*char2b);
1237 JIS_TO_SJIS (code);
1238 STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
1242 if (two_byte_p)
1243 *two_byte_p = internal_two_byte_p;
1245 if (!font)
1246 return UNKNOWN_FONT;
1247 else if (font->bdf && CHARSET_DIMENSION (charset) == 1)
1248 return BDF_1D_FONT;
1249 else if (font->bdf)
1250 return BDF_2D_FONT;
1251 else if (unicode_p)
1252 return UNICODE_FONT;
1253 else
1254 return ANSI_FONT;
1258 /* Return a char-table whose elements are t if the font FONT_INFO
1259 contains a glyph for the corresponding character, and nil if not.
1261 Fixme: For the moment, this function works only for fonts whose
1262 glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts). */
1264 Lisp_Object
1265 x_get_font_repertory (f, font_info)
1266 FRAME_PTR f;
1267 struct font_info *font_info;
1269 XFontStruct *font = (XFontStruct *) font_info->font;
1270 Lisp_Object table;
1271 int min_byte1, max_byte1, min_byte2, max_byte2;
1272 int c;
1273 struct charset *charset = CHARSET_FROM_ID (font_info->charset);
1274 int offset = CHARSET_OFFSET (charset);
1276 table = Fmake_char_table (Qnil, Qnil);
1278 if (!font->bdf && pfnGetFontUnicodeRanges)
1280 GLYPHSET *glyphset;
1281 DWORD glyphset_size;
1282 HDC display = get_frame_dc (f);
1283 HFONT prev_font;
1284 int i;
1286 prev_font = SelectObject (display, font->hfont);
1288 /* First call GetFontUnicodeRanges to find out how big a structure
1289 we need. */
1290 glyphset_size = pfnGetFontUnicodeRanges (display, NULL);
1291 if (glyphset_size)
1293 glyphset = (GLYPHSET *) alloca (glyphset_size);
1294 glyphset->cbThis = glyphset_size;
1296 /* Now call it again to get the ranges. */
1297 glyphset_size = pfnGetFontUnicodeRanges (display, glyphset);
1299 if (glyphset_size)
1301 /* Store the ranges in TABLE. */
1302 for (i = 0; i < glyphset->cRanges; i++)
1304 int from = glyphset->ranges[i].wcLow;
1305 int to = from + glyphset->ranges[i].cGlyphs - 1;
1306 char_table_set_range (table, from, to, Qt);
1311 SelectObject (display, prev_font);
1312 release_frame_dc (f, display);
1314 /* If we got the information we wanted above, then return it. */
1315 if (glyphset_size)
1316 return table;
1319 #if 0 /* TODO: Convert to work on Windows so BDF and older platforms work. */
1320 /* When GetFontUnicodeRanges is not available or does not work,
1321 work it out manually. */
1322 min_byte1 = font->min_byte1;
1323 max_byte1 = font->max_byte1;
1324 min_byte2 = font->min_char_or_byte2;
1325 max_byte2 = font->max_char_or_byte2;
1326 if (min_byte1 == 0 && max_byte1 == 0)
1328 if (! font->per_char || font->all_chars_exist == True)
1330 if (offset >= 0)
1331 char_table_set_range (table, offset + min_byte2,
1332 offset + max_byte2, Qt);
1333 else
1334 for (; min_byte2 <= max_byte2; min_byte2++)
1336 c = DECODE_CHAR (charset, min_byte2);
1337 CHAR_TABLE_SET (table, c, Qt);
1340 else
1342 XCharStruct *pcm = font->per_char;
1343 int from = -1;
1344 int i;
1346 for (i = min_byte2; i <= max_byte2; i++, pcm++)
1348 if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
1350 if (from >= 0)
1352 if (offset >= 0)
1353 char_table_set_range (table, offset + from,
1354 offset + i - 1, Qt);
1355 else
1356 for (; from < i; from++)
1358 c = DECODE_CHAR (charset, from);
1359 CHAR_TABLE_SET (table, c, Qt);
1361 from = -1;
1364 else if (from < 0)
1365 from = i;
1367 if (from >= 0)
1369 if (offset >= 0)
1370 char_table_set_range (table, offset + from, offset + i - 1,
1371 Qt);
1372 else
1373 for (; from < i; from++)
1375 c = DECODE_CHAR (charset, from);
1376 CHAR_TABLE_SET (table, c, Qt);
1381 else
1383 if (! font->per_char || font->all_chars_exist == True)
1385 int i, j;
1387 if (offset >= 0)
1388 for (i = min_byte1; i <= max_byte1; i++)
1389 char_table_set_range
1390 (table, offset + ((i << 8) | min_byte2),
1391 offset + ((i << 8) | max_byte2), Qt);
1392 else
1393 for (i = min_byte1; i <= max_byte1; i++)
1394 for (j = min_byte2; j <= max_byte2; j++)
1396 unsiged code = (i << 8) | j;
1397 c = DECODE_CHAR (charset, code);
1398 CHAR_TABLE_SET (table, c, Qt);
1401 else
1403 XCharStruct *pcm = font->per_char;
1404 int i;
1406 for (i = min_byte1; i <= max_byte1; i++)
1408 int from = -1;
1409 int j;
1411 for (j = min_byte2; j <= max_byte2; j++, pcm++)
1413 if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
1415 if (from >= 0)
1417 if (offset >= 0)
1418 char_table_set_range
1419 (table, offset + ((i << 8) | from),
1420 offset + ((i << 8) | (j - 1)), Qt);
1421 else
1423 for (; from < j; from++)
1425 unsigned code = (i << 8) | from;
1426 c = ENCODE_CHAR (charset, code);
1427 CHAR_TABLE_SET (table, c, Qt);
1430 from = -1;
1433 else if (from < 0)
1434 from = j;
1436 if (from >= 0)
1438 if (offset >= 0)
1439 char_table_set_range
1440 (table, offset + ((i << 8) | from),
1441 offset + ((i << 8) | (j - 1)), Qt);
1442 else
1444 for (; from < j; from++)
1446 unsigned code = (i << 8) | from;
1447 c = DECODE_CHAR (charset, code);
1448 CHAR_TABLE_SET (table, c, Qt);
1455 #endif
1456 return table;
1460 /***********************************************************************
1461 Glyph display
1462 ***********************************************************************/
1465 /* Encapsulate the different ways of displaying text under W32. */
1467 static void
1468 w32_text_out (s, x, y,chars,nchars)
1469 struct glyph_string * s;
1470 int x, y;
1471 wchar_t * chars;
1472 int nchars;
1474 int charset_dim = w32_font_is_double_byte (s->font) ? 2 : 1;
1475 if (s->font->bdf)
1476 w32_BDF_TextOut (s->font->bdf, s->hdc,
1477 x, y, (char *) chars, charset_dim,
1478 nchars * charset_dim, 0);
1479 else if (s->first_glyph->font_type == UNICODE_FONT)
1480 ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL);
1481 else
1482 ExtTextOutA (s->hdc, x, y, 0, NULL, (char *) chars,
1483 nchars * charset_dim, NULL);
1487 static void x_set_glyph_string_clipping P_ ((struct glyph_string *));
1488 static void x_set_glyph_string_gc P_ ((struct glyph_string *));
1489 static void x_draw_glyph_string_background P_ ((struct glyph_string *,
1490 int));
1491 static void x_draw_glyph_string_foreground P_ ((struct glyph_string *));
1492 static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *));
1493 static void x_draw_glyph_string_box P_ ((struct glyph_string *));
1494 static void x_draw_glyph_string P_ ((struct glyph_string *));
1495 static void x_set_cursor_gc P_ ((struct glyph_string *));
1496 static void x_set_mode_line_face_gc P_ ((struct glyph_string *));
1497 static void x_set_mouse_face_gc P_ ((struct glyph_string *));
1498 static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int);
1499 static void w32_setup_relief_color P_ ((struct frame *, struct relief *,
1500 double, int, COLORREF));
1501 static void x_setup_relief_colors P_ ((struct glyph_string *));
1502 static void x_draw_image_glyph_string P_ ((struct glyph_string *));
1503 static void x_draw_image_relief P_ ((struct glyph_string *));
1504 static void x_draw_image_foreground P_ ((struct glyph_string *));
1505 static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP));
1506 static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int,
1507 int, int, int));
1508 static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int,
1509 int, int, int, int, int, int,
1510 RECT *));
1511 static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
1512 int, int, int, RECT *));
1514 #if GLYPH_DEBUG
1515 static void x_check_font P_ ((struct frame *, XFontStruct *));
1516 #endif
1519 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1520 face. */
1522 static void
1523 x_set_cursor_gc (s)
1524 struct glyph_string *s;
1526 if (s->font == FRAME_FONT (s->f)
1527 && s->face->background == FRAME_BACKGROUND_PIXEL (s->f)
1528 && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f)
1529 && !s->cmp)
1530 s->gc = s->f->output_data.w32->cursor_gc;
1531 else
1533 /* Cursor on non-default face: must merge. */
1534 XGCValues xgcv;
1535 unsigned long mask;
1537 xgcv.background = s->f->output_data.w32->cursor_pixel;
1538 xgcv.foreground = s->face->background;
1540 /* If the glyph would be invisible, try a different foreground. */
1541 if (xgcv.foreground == xgcv.background)
1542 xgcv.foreground = s->face->foreground;
1543 if (xgcv.foreground == xgcv.background)
1544 xgcv.foreground = s->f->output_data.w32->cursor_foreground_pixel;
1545 if (xgcv.foreground == xgcv.background)
1546 xgcv.foreground = s->face->foreground;
1548 /* Make sure the cursor is distinct from text in this face. */
1549 if (xgcv.background == s->face->background
1550 && xgcv.foreground == s->face->foreground)
1552 xgcv.background = s->face->foreground;
1553 xgcv.foreground = s->face->background;
1556 IF_DEBUG (x_check_font (s->f, s->font));
1557 xgcv.font = s->font;
1558 mask = GCForeground | GCBackground | GCFont;
1560 if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc)
1561 XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc,
1562 mask, &xgcv);
1563 else
1564 FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc
1565 = XCreateGC (NULL, s->window, mask, &xgcv);
1567 s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc;
1572 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1574 static void
1575 x_set_mouse_face_gc (s)
1576 struct glyph_string *s;
1578 int face_id;
1579 struct face *face;
1581 /* What face has to be used last for the mouse face? */
1582 face_id = FRAME_W32_DISPLAY_INFO (s->f)->mouse_face_face_id;
1583 face = FACE_FROM_ID (s->f, face_id);
1584 if (face == NULL)
1585 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
1587 if (s->first_glyph->type == CHAR_GLYPH)
1588 face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch, -1, Qnil);
1589 else
1590 face_id = FACE_FOR_CHAR (s->f, face, 0, -1, Qnil);
1591 s->face = FACE_FROM_ID (s->f, face_id);
1592 PREPARE_FACE_FOR_DISPLAY (s->f, s->face);
1594 /* If font in this face is same as S->font, use it. */
1595 if (s->font == s->face->font)
1596 s->gc = s->face->gc;
1597 #ifdef USE_FONT_BACKEND
1598 else if (enable_font_backend)
1599 /* No need of setting a font for s->gc. */
1600 s->gc = s->face->gc;
1601 #endif /* USE_FONT_BACKEND */
1602 else
1604 /* Otherwise construct scratch_cursor_gc with values from FACE
1605 but font FONT. */
1606 XGCValues xgcv;
1607 unsigned long mask;
1609 xgcv.background = s->face->background;
1610 xgcv.foreground = s->face->foreground;
1611 IF_DEBUG (x_check_font (s->f, s->font));
1612 xgcv.font = s->font;
1613 mask = GCForeground | GCBackground | GCFont;
1615 if (FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc)
1616 XChangeGC (NULL, FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc,
1617 mask, &xgcv);
1618 else
1619 FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc
1620 = XCreateGC (NULL, s->window, mask, &xgcv);
1622 s->gc = FRAME_W32_DISPLAY_INFO (s->f)->scratch_cursor_gc;
1625 xassert (s->gc != 0);
1629 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1630 Faces to use in the mode line have already been computed when the
1631 matrix was built, so there isn't much to do, here. */
1633 static INLINE void
1634 x_set_mode_line_face_gc (s)
1635 struct glyph_string *s;
1637 s->gc = s->face->gc;
1641 /* Set S->gc of glyph string S for drawing that glyph string. Set
1642 S->stippled_p to a non-zero value if the face of S has a stipple
1643 pattern. */
1645 static INLINE void
1646 x_set_glyph_string_gc (s)
1647 struct glyph_string *s;
1649 PREPARE_FACE_FOR_DISPLAY (s->f, s->face);
1651 if (s->hl == DRAW_NORMAL_TEXT)
1653 s->gc = s->face->gc;
1654 s->stippled_p = s->face->stipple != 0;
1656 else if (s->hl == DRAW_INVERSE_VIDEO)
1658 x_set_mode_line_face_gc (s);
1659 s->stippled_p = s->face->stipple != 0;
1661 else if (s->hl == DRAW_CURSOR)
1663 x_set_cursor_gc (s);
1664 s->stippled_p = 0;
1666 else if (s->hl == DRAW_MOUSE_FACE)
1668 x_set_mouse_face_gc (s);
1669 s->stippled_p = s->face->stipple != 0;
1671 else if (s->hl == DRAW_IMAGE_RAISED
1672 || s->hl == DRAW_IMAGE_SUNKEN)
1674 s->gc = s->face->gc;
1675 s->stippled_p = s->face->stipple != 0;
1677 else
1679 s->gc = s->face->gc;
1680 s->stippled_p = s->face->stipple != 0;
1683 /* GC must have been set. */
1684 xassert (s->gc != 0);
1688 /* Set clipping for output of glyph string S. S may be part of a mode
1689 line or menu if we don't have X toolkit support. */
1691 static INLINE void
1692 x_set_glyph_string_clipping (s)
1693 struct glyph_string *s;
1695 #ifdef USE_FONT_BACKEND
1696 RECT *r = s->clip;
1697 #else
1698 RECT r[2];
1699 #endif
1700 int n = get_glyph_string_clip_rects (s, r, 2);
1702 if (n == 1)
1703 w32_set_clip_rectangle (s->hdc, r);
1704 else if (n > 1)
1706 HRGN full_clip, clip1, clip2;
1707 clip1 = CreateRectRgnIndirect (r);
1708 clip2 = CreateRectRgnIndirect (r + 1);
1709 if (CombineRgn (full_clip, clip1, clip2, RGN_OR) != ERROR)
1711 SelectClipRgn (s->hdc, full_clip);
1713 DeleteObject (clip1);
1714 DeleteObject (clip2);
1715 DeleteObject (full_clip);
1717 #ifdef USE_FONT_BACKEND
1718 s->num_clips = n;
1719 #endif /* USE_FONT_BACKEND */
1722 /* Set SRC's clipping for output of glyph string DST. This is called
1723 when we are drawing DST's left_overhang or right_overhang only in
1724 the area of SRC. */
1726 static void
1727 x_set_glyph_string_clipping_exactly (src, dst)
1728 struct glyph_string *src, *dst;
1730 RECT r;
1732 #ifdef USE_FONT_BACKEND
1733 if (enable_font_backend)
1735 r.left = src->x;
1736 r.right = r.left + src->width;
1737 r.top = src->y;
1738 r.bottom = r.top + src->height;
1739 dst->clip[0] = r;
1740 dst->num_clips = 1;
1742 else
1744 #endif /* USE_FONT_BACKEND */
1745 struct glyph_string *clip_head = src->clip_head;
1746 struct glyph_string *clip_tail = src->clip_tail;
1748 /* This foces clipping just this glyph string. */
1749 src->clip_head = src->clip_tail = src;
1750 get_glyph_string_clip_rect (src, &r);
1751 src->clip_head = clip_head, src->clip_tail = clip_tail;
1752 #ifdef USE_FONT_BACKEND
1754 #endif /* USE_FONT_BACKEND */
1755 w32_set_clip_rectangle (dst->hdc, &r);
1758 /* RIF:
1759 Compute left and right overhang of glyph string S. If S is a glyph
1760 string for a composition, assume overhangs don't exist. */
1762 static void
1763 w32_compute_glyph_string_overhangs (s)
1764 struct glyph_string *s;
1766 if (s->cmp == NULL
1767 && s->first_glyph->type == CHAR_GLYPH)
1769 #ifdef USE_FONT_BACKEND
1770 if (enable_font_backend)
1772 unsigned *code = alloca (sizeof (unsigned) * s->nchars);
1773 struct font *font = (struct font *) s->font_info;
1774 struct font_metrics metrics;
1775 int i;
1777 for (i = 0; i < s->nchars; i++)
1778 code[i] = s->char2b[i];
1779 font->driver->text_extents (font, code, s->nchars, &metrics);
1780 s->right_overhang = (metrics.rbearing > metrics.width
1781 ? metrics.rbearing - metrics.width : 0);
1782 s->left_overhang = metrics.lbearing < 0 ? -metrics.lbearing : 0;
1784 #else
1785 /* TODO: Windows does not appear to have a method for
1786 getting this info without getting the ABC widths for each
1787 individual character and working it out manually. */
1788 #endif
1790 else if (s->cmp)
1792 s->right_overhang = s->cmp->rbearing - s->cmp->pixel_width;
1793 s->left_overhang = -s->cmp->lbearing;
1798 static void
1799 w32_get_glyph_overhangs (glyph, f, left, right)
1800 struct glyph *glyph;
1801 struct frame *f;
1802 int *left, *right;
1804 HDC hdc = get_frame_dc (f);
1805 /* Convert to unicode! */
1806 x_get_glyph_overhangs (glyph, f, left, right);
1807 release_frame_dc (f, hdc);
1811 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1813 static INLINE void
1814 x_clear_glyph_string_rect (s, x, y, w, h)
1815 struct glyph_string *s;
1816 int x, y, w, h;
1818 int real_x = x;
1819 int real_y = y;
1820 int real_w = w;
1821 int real_h = h;
1822 #if 0
1823 /* Take clipping into account. */
1824 if (s->gc->clip_mask == Rect)
1826 real_x = max (real_x, s->gc->clip_rectangle.left);
1827 real_y = max (real_y, s->gc->clip_rectangle.top);
1828 real_w = min (real_w, s->gc->clip_rectangle.right
1829 - s->gc->clip_rectangle.left);
1830 real_h = min (real_h, s->gc->clip_rectangle.bottom
1831 - s->gc->clip_rectangle.top);
1833 #endif
1834 w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y,
1835 real_w, real_h);
1839 /* Draw the background of glyph_string S. If S->background_filled_p
1840 is non-zero don't draw it. FORCE_P non-zero means draw the
1841 background even if it wouldn't be drawn normally. This is used
1842 when a string preceding S draws into the background of S, or S
1843 contains the first component of a composition. */
1845 static void
1846 x_draw_glyph_string_background (s, force_p)
1847 struct glyph_string *s;
1848 int force_p;
1850 /* Nothing to do if background has already been drawn or if it
1851 shouldn't be drawn in the first place. */
1852 if (!s->background_filled_p)
1854 int box_line_width = max (s->face->box_line_width, 0);
1856 #if 0 /* TODO: stipple */
1857 if (s->stippled_p)
1859 /* Fill background with a stipple pattern. */
1860 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
1861 XFillRectangle (s->display, s->window, s->gc, s->x,
1862 s->y + box_line_width,
1863 s->background_width,
1864 s->height - 2 * box_line_width);
1865 XSetFillStyle (s->display, s->gc, FillSolid);
1866 s->background_filled_p = 1;
1868 else
1869 #endif
1870 if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
1871 || s->font_not_found_p
1872 || s->extends_to_end_of_line_p
1873 || s->font->bdf
1874 || cleartype_active
1875 || force_p)
1877 x_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
1878 s->background_width,
1879 s->height - 2 * box_line_width);
1880 s->background_filled_p = 1;
1886 /* Draw the foreground of glyph string S. */
1888 static void
1889 x_draw_glyph_string_foreground (s)
1890 struct glyph_string *s;
1892 int i, x;
1893 HFONT old_font;
1895 /* If first glyph of S has a left box line, start drawing the text
1896 of S to the right of that box line. */
1897 if (s->face->box != FACE_NO_BOX
1898 && s->first_glyph->left_box_line_p)
1899 x = s->x + eabs (s->face->box_line_width);
1900 else
1901 x = s->x;
1903 if (s->for_overlaps || (s->background_filled_p && s->hl != DRAW_CURSOR)
1904 || cleartype_active)
1905 SetBkMode (s->hdc, TRANSPARENT);
1906 else
1907 SetBkMode (s->hdc, OPAQUE);
1909 SetTextColor (s->hdc, s->gc->foreground);
1910 SetBkColor (s->hdc, s->gc->background);
1911 SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
1913 if (s->font && s->font->hfont)
1914 old_font = SelectObject (s->hdc, s->font->hfont);
1916 /* Draw characters of S as rectangles if S's font could not be
1917 loaded. */
1918 if (s->font_not_found_p)
1920 for (i = 0; i < s->nchars; ++i)
1922 struct glyph *g = s->first_glyph + i;
1924 w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1,
1925 s->height - 1);
1926 x += g->pixel_width;
1929 #ifdef USE_FONT_BACKEND
1930 else if (enable_font_backend)
1932 int boff = s->font_info->baseline_offset;
1933 struct font *font = (struct font *) s->font_info;
1934 int y;
1936 if (s->font_info->vertical_centering)
1937 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
1939 y = s->ybase - boff;
1940 if (s->for_overlaps
1941 || (s->background_filled_p && s->hl != DRAW_CURSOR))
1942 font->driver->draw (s, 0, s->nchars, x, y, 0);
1943 else
1944 font->driver->draw (s, 0, s->nchars, x, y, 1);
1945 if (s->face->overstrike)
1946 font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
1948 #endif /* USE_FONT_BACKEND */
1949 else
1951 char *char1b = (char *) s->char2b;
1952 int boff = s->font_info->baseline_offset;
1954 if (s->font_info->vertical_centering)
1955 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
1957 /* If we can use 8-bit functions, condense S->char2b. */
1958 if (!s->two_byte_p)
1959 for (i = 0; i < s->nchars; ++i)
1960 char1b[i] = XCHAR2B_BYTE2 (&s->char2b[i]);
1962 /* Draw text with TextOut and friends. */
1963 w32_text_out (s, x, s->ybase - boff, s->char2b, s->nchars);
1965 if (s->face->overstrike)
1967 /* For overstriking (to simulate bold-face), draw the
1968 characters again shifted to the right by one pixel. */
1969 int old_BkMode = SetBkMode (s->hdc, TRANSPARENT);
1970 w32_text_out (s, x + 1, s->ybase - boff, s->char2b, s->nchars);
1971 if (old_BkMode && old_BkMode != TRANSPARENT)
1972 SetBkMode (s->hdc, old_BkMode);
1975 if (s->font && s->font->hfont)
1976 SelectObject (s->hdc, old_font);
1979 /* Draw the foreground of composite glyph string S. */
1981 static void
1982 x_draw_composite_glyph_string_foreground (s)
1983 struct glyph_string *s;
1985 int i, j, x;
1986 HFONT old_font;
1988 /* If first glyph of S has a left box line, start drawing the text
1989 of S to the right of that box line. */
1990 if (s->face && s->face->box != FACE_NO_BOX
1991 && s->first_glyph->left_box_line_p)
1992 x = s->x + eabs (s->face->box_line_width);
1993 else
1994 x = s->x;
1996 /* S is a glyph string for a composition. S->gidx is the index of
1997 the first character drawn for glyphs of this composition.
1998 S->gidx == 0 means we are drawing the very first character of
1999 this composition. */
2001 SetTextColor (s->hdc, s->gc->foreground);
2002 SetBkColor (s->hdc, s->gc->background);
2003 SetBkMode (s->hdc, TRANSPARENT);
2004 SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
2006 if (s->font && s->font->hfont)
2007 old_font = SelectObject (s->hdc, s->font->hfont);
2009 /* Draw a rectangle for the composition if the font for the very
2010 first character of the composition could not be loaded. */
2011 if (s->font_not_found_p)
2013 if (s->gidx == 0)
2014 w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1,
2015 s->height - 1);
2017 #ifdef USE_FONT_BACKEND
2018 else if (enable_font_backend)
2020 struct font *font = (struct font *) s->font_info;
2021 int y = s->ybase;
2022 int width = 0;
2024 if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING)
2026 Lisp_Object gstring = AREF (XHASH_TABLE (composition_hash_table)
2027 ->key_and_value,
2028 s->cmp->hash_index * 2);
2029 int from;
2031 for (i = from = 0; i < s->nchars; i++)
2033 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
2034 Lisp_Object adjustment = LGLYPH_ADJUSTMENT (g);
2035 int xoff, yoff, wadjust;
2037 if (! VECTORP (adjustment))
2039 width += LGLYPH_WIDTH (g);
2040 continue;
2042 if (from < i)
2044 font->driver->draw (s, from, i, x, y, 0);
2045 x += width;
2047 xoff = XINT (AREF (adjustment, 0));
2048 yoff = XINT (AREF (adjustment, 1));
2049 wadjust = XINT (AREF (adjustment, 2));
2051 font->driver->draw (s, i, i + 1, x + xoff, y + yoff, 0);
2052 x += wadjust;
2053 from = i + 1;
2054 width = 0;
2056 if (from < i)
2057 font->driver->draw (s, from, i, x, y, 0);
2059 else
2061 for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
2062 if (COMPOSITION_GLYPH (s->cmp, j) != '\t')
2064 int xx = x + s->cmp->offsets[j * 2];
2065 int yy = y - s->cmp->offsets[j * 2 + 1];
2067 font->driver->draw (s, j, j + 1, xx, yy, 0);
2068 if (s->face->overstrike)
2069 font->driver->draw (s, j, j + 1, xx + 1, yy, 0);
2073 #endif /* USE_FONT_BACKEND */
2074 else
2076 for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
2077 if (s->face)
2079 w32_text_out (s, x + s->cmp->offsets[j * 2],
2080 s->ybase - s->cmp->offsets[j * 2 + 1],
2081 s->char2b + j, 1);
2082 if (s->face->overstrike)
2083 w32_text_out (s, x + s->cmp->offsets[j * 2] + 1,
2084 s->ybase - s->cmp->offsets[j + 1],
2085 s->char2b + j, 1);
2089 if (s->font && s->font->hfont)
2090 SelectObject (s->hdc, old_font);
2094 /* Brightness beyond which a color won't have its highlight brightness
2095 boosted.
2097 Nominally, highlight colors for `3d' faces are calculated by
2098 brightening an object's color by a constant scale factor, but this
2099 doesn't yield good results for dark colors, so for colors who's
2100 brightness is less than this value (on a scale of 0-255) have to
2101 use an additional additive factor.
2103 The value here is set so that the default menu-bar/mode-line color
2104 (grey75) will not have its highlights changed at all. */
2105 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
2108 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
2109 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2110 If this produces the same color as COLOR, try a color where all RGB
2111 values have DELTA added. Return the allocated color in *COLOR.
2112 DISPLAY is the X display, CMAP is the colormap to operate on.
2113 Value is non-zero if successful. */
2115 static int
2116 w32_alloc_lighter_color (f, color, factor, delta)
2117 struct frame *f;
2118 COLORREF *color;
2119 double factor;
2120 int delta;
2122 COLORREF new;
2123 long bright;
2125 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
2126 delta /= 256;
2128 /* Change RGB values by specified FACTOR. Avoid overflow! */
2129 xassert (factor >= 0);
2130 new = PALETTERGB (min (0xff, factor * GetRValue (*color)),
2131 min (0xff, factor * GetGValue (*color)),
2132 min (0xff, factor * GetBValue (*color)));
2134 /* Calculate brightness of COLOR. */
2135 bright = (2 * GetRValue (*color) + 3 * GetGValue (*color)
2136 + GetBValue (*color)) / 6;
2138 /* We only boost colors that are darker than
2139 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2140 if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT)
2141 /* Make an additive adjustment to NEW, because it's dark enough so
2142 that scaling by FACTOR alone isn't enough. */
2144 /* How far below the limit this color is (0 - 1, 1 being darker). */
2145 double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT;
2146 /* The additive adjustment. */
2147 int min_delta = delta * dimness * factor / 2;
2149 if (factor < 1)
2150 new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))),
2151 max (0, min (0xff, min_delta - GetGValue (*color))),
2152 max (0, min (0xff, min_delta - GetBValue (*color))));
2153 else
2154 new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))),
2155 max (0, min (0xff, min_delta + GetGValue (*color))),
2156 max (0, min (0xff, min_delta + GetBValue (*color))));
2159 if (new == *color)
2160 new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))),
2161 max (0, min (0xff, delta + GetGValue (*color))),
2162 max (0, min (0xff, delta + GetBValue (*color))));
2164 /* TODO: Map to palette and retry with delta if same? */
2165 /* TODO: Free colors (if using palette)? */
2167 if (new == *color)
2168 return 0;
2170 *color = new;
2172 return 1;
2176 /* Set up the foreground color for drawing relief lines of glyph
2177 string S. RELIEF is a pointer to a struct relief containing the GC
2178 with which lines will be drawn. Use a color that is FACTOR or
2179 DELTA lighter or darker than the relief's background which is found
2180 in S->f->output_data.x->relief_background. If such a color cannot
2181 be allocated, use DEFAULT_PIXEL, instead. */
2183 static void
2184 w32_setup_relief_color (f, relief, factor, delta, default_pixel)
2185 struct frame *f;
2186 struct relief *relief;
2187 double factor;
2188 int delta;
2189 COLORREF default_pixel;
2191 XGCValues xgcv;
2192 struct w32_output *di = f->output_data.w32;
2193 unsigned long mask = GCForeground;
2194 COLORREF pixel;
2195 COLORREF background = di->relief_background;
2196 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
2198 /* TODO: Free colors (if using palette)? */
2200 /* Allocate new color. */
2201 xgcv.foreground = default_pixel;
2202 pixel = background;
2203 if (w32_alloc_lighter_color (f, &pixel, factor, delta))
2205 relief->allocated_p = 1;
2206 xgcv.foreground = relief->pixel = pixel;
2209 if (relief->gc == 0)
2211 #if 0 /* TODO: stipple */
2212 xgcv.stipple = dpyinfo->gray;
2213 mask |= GCStipple;
2214 #endif
2215 relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv);
2217 else
2218 XChangeGC (NULL, relief->gc, mask, &xgcv);
2222 /* Set up colors for the relief lines around glyph string S. */
2224 static void
2225 x_setup_relief_colors (s)
2226 struct glyph_string *s;
2228 struct w32_output *di = s->f->output_data.w32;
2229 COLORREF color;
2231 if (s->face->use_box_color_for_shadows_p)
2232 color = s->face->box_color;
2233 else if (s->first_glyph->type == IMAGE_GLYPH
2234 && s->img->pixmap
2235 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2236 color = IMAGE_BACKGROUND (s->img, s->f, 0);
2237 else
2238 color = s->gc->background;
2240 if (di->white_relief.gc == 0
2241 || color != di->relief_background)
2243 di->relief_background = color;
2244 w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000,
2245 WHITE_PIX_DEFAULT (s->f));
2246 w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000,
2247 BLACK_PIX_DEFAULT (s->f));
2252 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2253 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2254 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2255 relief. LEFT_P non-zero means draw a relief on the left side of
2256 the rectangle. RIGHT_P non-zero means draw a relief on the right
2257 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2258 when drawing. */
2260 static void
2261 w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
2262 raised_p, top_p, bot_p, left_p, right_p, clip_rect)
2263 struct frame *f;
2264 int left_x, top_y, right_x, bottom_y, width;
2265 int top_p, bot_p, left_p, right_p, raised_p;
2266 RECT *clip_rect;
2268 int i;
2269 XGCValues gc;
2270 HDC hdc = get_frame_dc (f);
2272 if (raised_p)
2273 gc.foreground = f->output_data.w32->white_relief.gc->foreground;
2274 else
2275 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
2277 w32_set_clip_rectangle (hdc, clip_rect);
2279 /* Top. */
2280 if (top_p)
2281 for (i = 0; i < width; ++i)
2282 w32_fill_area (f, hdc, gc.foreground,
2283 left_x + i * left_p, top_y + i,
2284 right_x - left_x - i * (left_p + right_p ) + 1, 1);
2286 /* Left. */
2287 if (left_p)
2288 for (i = 0; i < width; ++i)
2289 w32_fill_area (f, hdc, gc.foreground,
2290 left_x + i, top_y + i, 1,
2291 bottom_y - top_y - 2 * i + 1);
2293 if (raised_p)
2294 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
2295 else
2296 gc.foreground = f->output_data.w32->white_relief.gc->foreground;
2298 /* Bottom. */
2299 if (bot_p)
2300 for (i = 0; i < width; ++i)
2301 w32_fill_area (f, hdc, gc.foreground,
2302 left_x + i * left_p, bottom_y - i,
2303 right_x - left_x - i * (left_p + right_p) + 1, 1);
2305 /* Right. */
2306 if (right_p)
2307 for (i = 0; i < width; ++i)
2308 w32_fill_area (f, hdc, gc.foreground,
2309 right_x - i, top_y + i + 1, 1,
2310 bottom_y - top_y - 2 * i - 1);
2312 w32_set_clip_rectangle (hdc, NULL);
2314 release_frame_dc (f, hdc);
2318 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2319 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2320 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2321 left side of the rectangle. RIGHT_P non-zero means draw a line
2322 on the right side of the rectangle. CLIP_RECT is the clipping
2323 rectangle to use when drawing. */
2325 static void
2326 w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
2327 left_p, right_p, clip_rect)
2328 struct glyph_string *s;
2329 int left_x, top_y, right_x, bottom_y, width, left_p, right_p;
2330 RECT *clip_rect;
2332 w32_set_clip_rectangle (s->hdc, clip_rect);
2334 /* Top. */
2335 w32_fill_area (s->f, s->hdc, s->face->box_color,
2336 left_x, top_y, right_x - left_x + 1, width);
2338 /* Left. */
2339 if (left_p)
2341 w32_fill_area (s->f, s->hdc, s->face->box_color,
2342 left_x, top_y, width, bottom_y - top_y + 1);
2345 /* Bottom. */
2346 w32_fill_area (s->f, s->hdc, s->face->box_color,
2347 left_x, bottom_y - width + 1, right_x - left_x + 1, width);
2349 /* Right. */
2350 if (right_p)
2352 w32_fill_area (s->f, s->hdc, s->face->box_color,
2353 right_x - width + 1, top_y, width, bottom_y - top_y + 1);
2356 w32_set_clip_rectangle (s->hdc, NULL);
2360 /* Draw a box around glyph string S. */
2362 static void
2363 x_draw_glyph_string_box (s)
2364 struct glyph_string *s;
2366 int width, left_x, right_x, top_y, bottom_y, last_x, raised_p;
2367 int left_p, right_p;
2368 struct glyph *last_glyph;
2369 RECT clip_rect;
2371 last_x = ((s->row->full_width_p && !s->w->pseudo_window_p)
2372 ? WINDOW_RIGHT_EDGE_X (s->w)
2373 : window_box_right (s->w, s->area));
2375 /* The glyph that may have a right box line. */
2376 last_glyph = (s->cmp || s->img
2377 ? s->first_glyph
2378 : s->first_glyph + s->nchars - 1);
2380 width = eabs (s->face->box_line_width);
2381 raised_p = s->face->box == FACE_RAISED_BOX;
2382 left_x = s->x;
2383 right_x = ((s->row->full_width_p && s->extends_to_end_of_line_p
2384 ? last_x - 1
2385 : min (last_x, s->x + s->background_width) - 1));
2386 top_y = s->y;
2387 bottom_y = top_y + s->height - 1;
2389 left_p = (s->first_glyph->left_box_line_p
2390 || (s->hl == DRAW_MOUSE_FACE
2391 && (s->prev == NULL
2392 || s->prev->hl != s->hl)));
2393 right_p = (last_glyph->right_box_line_p
2394 || (s->hl == DRAW_MOUSE_FACE
2395 && (s->next == NULL
2396 || s->next->hl != s->hl)));
2398 get_glyph_string_clip_rect (s, &clip_rect);
2400 if (s->face->box == FACE_SIMPLE_BOX)
2401 w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
2402 left_p, right_p, &clip_rect);
2403 else
2405 x_setup_relief_colors (s);
2406 w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y,
2407 width, raised_p, 1, 1, left_p, right_p, &clip_rect);
2412 /* Draw foreground of image glyph string S. */
2414 static void
2415 x_draw_image_foreground (s)
2416 struct glyph_string *s;
2418 int x = s->x;
2419 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2421 /* If first glyph of S has a left box line, start drawing it to the
2422 right of that line. */
2423 if (s->face->box != FACE_NO_BOX
2424 && s->first_glyph->left_box_line_p
2425 && s->slice.x == 0)
2426 x += eabs (s->face->box_line_width);
2428 /* If there is a margin around the image, adjust x- and y-position
2429 by that margin. */
2430 if (s->slice.x == 0)
2431 x += s->img->hmargin;
2432 if (s->slice.y == 0)
2433 y += s->img->vmargin;
2435 SaveDC (s->hdc);
2437 if (s->img->pixmap)
2439 HDC compat_hdc = CreateCompatibleDC (s->hdc);
2440 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2441 HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
2442 HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
2443 SetBkColor (compat_hdc, RGB (255, 255, 255));
2444 SetTextColor (s->hdc, RGB (0, 0, 0));
2445 x_set_glyph_string_clipping (s);
2447 if (s->img->mask)
2449 HDC mask_dc = CreateCompatibleDC (s->hdc);
2450 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
2452 SetTextColor (s->hdc, RGB (255, 255, 255));
2453 SetBkColor (s->hdc, RGB (0, 0, 0));
2455 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2456 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2457 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2458 mask_dc, s->slice.x, s->slice.y, SRCAND);
2459 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2460 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2462 SelectObject (mask_dc, mask_orig_obj);
2463 DeleteDC (mask_dc);
2465 else
2467 SetTextColor (s->hdc, s->gc->foreground);
2468 SetBkColor (s->hdc, s->gc->background);
2470 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2471 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2473 /* When the image has a mask, we can expect that at
2474 least part of a mouse highlight or a block cursor will
2475 be visible. If the image doesn't have a mask, make
2476 a block cursor visible by drawing a rectangle around
2477 the image. I believe it's looking better if we do
2478 nothing here for mouse-face. */
2479 if (s->hl == DRAW_CURSOR)
2481 int r = s->img->relief;
2482 if (r < 0) r = -r;
2483 w32_draw_rectangle (s->hdc, s->gc, x - r, y - r ,
2484 s->slice.width + r*2 - 1,
2485 s->slice.height + r*2 - 1);
2489 w32_set_clip_rectangle (s->hdc, NULL);
2490 SelectObject (s->hdc, orig_brush);
2491 DeleteObject (fg_brush);
2492 SelectObject (compat_hdc, orig_obj);
2493 DeleteDC (compat_hdc);
2495 else
2496 w32_draw_rectangle (s->hdc, s->gc, x, y,
2497 s->slice.width - 1, s->slice.height - 1);
2499 RestoreDC (s->hdc ,-1);
2503 /* Draw a relief around the image glyph string S. */
2505 static void
2506 x_draw_image_relief (s)
2507 struct glyph_string *s;
2509 int x0, y0, x1, y1, thick, raised_p;
2510 RECT r;
2511 int x = s->x;
2512 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2514 /* If first glyph of S has a left box line, start drawing it to the
2515 right of that line. */
2516 if (s->face->box != FACE_NO_BOX
2517 && s->first_glyph->left_box_line_p
2518 && s->slice.x == 0)
2519 x += eabs (s->face->box_line_width);
2521 /* If there is a margin around the image, adjust x- and y-position
2522 by that margin. */
2523 if (s->slice.x == 0)
2524 x += s->img->hmargin;
2525 if (s->slice.y == 0)
2526 y += s->img->vmargin;
2528 if (s->hl == DRAW_IMAGE_SUNKEN
2529 || s->hl == DRAW_IMAGE_RAISED)
2531 thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF;
2532 raised_p = s->hl == DRAW_IMAGE_RAISED;
2534 else
2536 thick = eabs (s->img->relief);
2537 raised_p = s->img->relief > 0;
2540 x0 = x - thick;
2541 y0 = y - thick;
2542 x1 = x + s->slice.width + thick - 1;
2543 y1 = y + s->slice.height + thick - 1;
2545 x_setup_relief_colors (s);
2546 get_glyph_string_clip_rect (s, &r);
2547 w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p,
2548 s->slice.y == 0,
2549 s->slice.y + s->slice.height == s->img->height,
2550 s->slice.x == 0,
2551 s->slice.x + s->slice.width == s->img->width,
2552 &r);
2556 /* Draw the foreground of image glyph string S to PIXMAP. */
2558 static void
2559 w32_draw_image_foreground_1 (s, pixmap)
2560 struct glyph_string *s;
2561 HBITMAP pixmap;
2563 HDC hdc = CreateCompatibleDC (s->hdc);
2564 HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap);
2565 int x = 0;
2566 int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice);
2568 /* If first glyph of S has a left box line, start drawing it to the
2569 right of that line. */
2570 if (s->face->box != FACE_NO_BOX
2571 && s->first_glyph->left_box_line_p
2572 && s->slice.x == 0)
2573 x += eabs (s->face->box_line_width);
2575 /* If there is a margin around the image, adjust x- and y-position
2576 by that margin. */
2577 if (s->slice.x == 0)
2578 x += s->img->hmargin;
2579 if (s->slice.y == 0)
2580 y += s->img->vmargin;
2582 if (s->img->pixmap)
2584 HDC compat_hdc = CreateCompatibleDC (hdc);
2585 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2586 HBRUSH orig_brush = SelectObject (hdc, fg_brush);
2587 HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
2589 if (s->img->mask)
2591 HDC mask_dc = CreateCompatibleDC (hdc);
2592 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
2594 SetTextColor (hdc, RGB (0, 0, 0));
2595 SetBkColor (hdc, RGB (255, 255, 255));
2596 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2597 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2598 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2599 mask_dc, s->slice.x, s->slice.y, SRCAND);
2600 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2601 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2603 SelectObject (mask_dc, mask_orig_obj);
2604 DeleteDC (mask_dc);
2606 else
2608 SetTextColor (hdc, s->gc->foreground);
2609 SetBkColor (hdc, s->gc->background);
2611 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2612 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2614 /* When the image has a mask, we can expect that at
2615 least part of a mouse highlight or a block cursor will
2616 be visible. If the image doesn't have a mask, make
2617 a block cursor visible by drawing a rectangle around
2618 the image. I believe it's looking better if we do
2619 nothing here for mouse-face. */
2620 if (s->hl == DRAW_CURSOR)
2622 int r = s->img->relief;
2623 if (r < 0) r = -r;
2624 w32_draw_rectangle (hdc, s->gc, x - r, y - r,
2625 s->slice.width + r*2 - 1,
2626 s->slice.height + r*2 - 1);
2630 SelectObject (hdc, orig_brush);
2631 DeleteObject (fg_brush);
2632 SelectObject (compat_hdc, orig_obj);
2633 DeleteDC (compat_hdc);
2635 else
2636 w32_draw_rectangle (hdc, s->gc, x, y,
2637 s->slice.width - 1, s->slice.height - 1);
2639 SelectObject (hdc, orig_hdc_obj);
2640 DeleteDC (hdc);
2644 /* Draw part of the background of glyph string S. X, Y, W, and H
2645 give the rectangle to draw. */
2647 static void
2648 x_draw_glyph_string_bg_rect (s, x, y, w, h)
2649 struct glyph_string *s;
2650 int x, y, w, h;
2652 #if 0 /* TODO: stipple */
2653 if (s->stippled_p)
2655 /* Fill background with a stipple pattern. */
2656 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
2657 XFillRectangle (s->display, s->window, s->gc, x, y, w, h);
2658 XSetFillStyle (s->display, s->gc, FillSolid);
2660 else
2661 #endif
2662 x_clear_glyph_string_rect (s, x, y, w, h);
2666 /* Draw image glyph string S.
2668 s->y
2669 s->x +-------------------------
2670 | s->face->box
2672 | +-------------------------
2673 | | s->img->vmargin
2675 | | +-------------------
2676 | | | the image
2680 static void
2681 x_draw_image_glyph_string (s)
2682 struct glyph_string *s;
2684 int x, y;
2685 int box_line_hwidth = eabs (s->face->box_line_width);
2686 int box_line_vwidth = max (s->face->box_line_width, 0);
2687 int height;
2688 HBITMAP pixmap = 0;
2690 height = s->height - 2 * box_line_vwidth;
2692 /* Fill background with face under the image. Do it only if row is
2693 taller than image or if image has a clip mask to reduce
2694 flickering. */
2695 s->stippled_p = s->face->stipple != 0;
2696 if (height > s->slice.height
2697 || s->img->hmargin
2698 || s->img->vmargin
2699 || s->img->mask
2700 || s->img->pixmap == 0
2701 || s->width != s->background_width)
2703 x = s->x;
2704 if (s->first_glyph->left_box_line_p
2705 && s->slice.x == 0)
2706 x += box_line_hwidth;
2708 y = s->y;
2709 if (s->slice.y == 0)
2710 y += box_line_vwidth;
2712 #if 0 /* TODO: figure out if we need to do this on Windows. */
2713 if (s->img->mask)
2715 /* Create a pixmap as large as the glyph string. Fill it
2716 with the background color. Copy the image to it, using
2717 its mask. Copy the temporary pixmap to the display. */
2718 Screen *screen = FRAME_X_SCREEN (s->f);
2719 int depth = DefaultDepthOfScreen (screen);
2721 /* Create a pixmap as large as the glyph string. */
2722 pixmap = XCreatePixmap (s->display, s->window,
2723 s->background_width,
2724 s->height, depth);
2726 /* Don't clip in the following because we're working on the
2727 pixmap. */
2728 XSetClipMask (s->display, s->gc, None);
2730 /* Fill the pixmap with the background color/stipple. */
2731 if (s->stippled_p)
2733 /* Fill background with a stipple pattern. */
2734 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
2735 XFillRectangle (s->display, pixmap, s->gc,
2736 0, 0, s->background_width, s->height);
2737 XSetFillStyle (s->display, s->gc, FillSolid);
2739 else
2741 XGCValues xgcv;
2742 XGetGCValues (s->display, s->gc, GCForeground | GCBackground,
2743 &xgcv);
2744 XSetForeground (s->display, s->gc, xgcv.background);
2745 XFillRectangle (s->display, pixmap, s->gc,
2746 0, 0, s->background_width, s->height);
2747 XSetForeground (s->display, s->gc, xgcv.foreground);
2750 else
2751 #endif
2752 x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height);
2754 s->background_filled_p = 1;
2757 /* Draw the foreground. */
2758 if (pixmap != 0)
2760 w32_draw_image_foreground_1 (s, pixmap);
2761 x_set_glyph_string_clipping (s);
2763 HDC compat_hdc = CreateCompatibleDC (s->hdc);
2764 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2765 HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
2766 HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap);
2768 SetTextColor (s->hdc, s->gc->foreground);
2769 SetBkColor (s->hdc, s->gc->background);
2770 BitBlt (s->hdc, s->x, s->y, s->background_width, s->height,
2771 compat_hdc, 0, 0, SRCCOPY);
2773 SelectObject (s->hdc, orig_brush);
2774 DeleteObject (fg_brush);
2775 SelectObject (compat_hdc, orig_obj);
2776 DeleteDC (compat_hdc);
2778 DeleteObject (pixmap);
2779 pixmap = 0;
2781 else
2782 x_draw_image_foreground (s);
2784 /* If we must draw a relief around the image, do it. */
2785 if (s->img->relief
2786 || s->hl == DRAW_IMAGE_RAISED
2787 || s->hl == DRAW_IMAGE_SUNKEN)
2788 x_draw_image_relief (s);
2792 /* Draw stretch glyph string S. */
2794 static void
2795 x_draw_stretch_glyph_string (s)
2796 struct glyph_string *s;
2798 xassert (s->first_glyph->type == STRETCH_GLYPH);
2800 if (s->hl == DRAW_CURSOR
2801 && !x_stretch_cursor_p)
2803 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2804 as wide as the stretch glyph. */
2805 int width, background_width = s->background_width;
2806 int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA);
2808 if (x < left_x)
2810 background_width -= left_x - x;
2811 x = left_x;
2813 width = min (FRAME_COLUMN_WIDTH (s->f), background_width);
2815 /* Draw cursor. */
2816 x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height);
2818 /* Clear rest using the GC of the original non-cursor face. */
2819 if (width < background_width)
2821 XGCValues *gc = s->face->gc;
2822 int y = s->y;
2823 int w = background_width - width, h = s->height;
2824 RECT r;
2825 HDC hdc = s->hdc;
2827 x += width;
2828 if (s->row->mouse_face_p
2829 && cursor_in_mouse_face_p (s->w))
2831 x_set_mouse_face_gc (s);
2832 gc = s->gc;
2834 else
2835 gc = s->face->gc;
2837 get_glyph_string_clip_rect (s, &r);
2838 w32_set_clip_rectangle (hdc, &r);
2840 #if 0 /* TODO: stipple */
2841 if (s->face->stipple)
2843 /* Fill background with a stipple pattern. */
2844 XSetFillStyle (s->display, gc, FillOpaqueStippled);
2845 XFillRectangle (s->display, s->window, gc, x, y, w, h);
2846 XSetFillStyle (s->display, gc, FillSolid);
2848 else
2849 #endif
2851 w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h);
2855 else if (!s->background_filled_p)
2857 int background_width = s->background_width;
2858 int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA);
2860 /* Don't draw into left margin, fringe or scrollbar area
2861 except for header line and mode line. */
2862 if (x < left_x && !s->row->mode_line_p)
2864 background_width -= left_x - x;
2865 x = left_x;
2867 if (background_width > 0)
2868 x_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height);
2871 s->background_filled_p = 1;
2875 /* Draw glyph string S. */
2877 static void
2878 x_draw_glyph_string (s)
2879 struct glyph_string *s;
2881 int relief_drawn_p = 0;
2883 /* If S draws into the background of its successor, draw the
2884 background of the successor first so that S can draw into it.
2885 This makes S->next use XDrawString instead of XDrawImageString. */
2886 if (s->next && s->right_overhang && !s->for_overlaps)
2888 int width;
2889 struct glyph_string *next;
2890 for (width = 0, next = s->next; next;
2891 width += next->width, next = next->next)
2892 if (next->first_glyph->type != IMAGE_GLYPH)
2894 x_set_glyph_string_gc (next);
2895 x_set_glyph_string_clipping (next);
2896 x_draw_glyph_string_background (next, 1);
2897 #ifdef USE_FONT_BACKEND
2898 next->num_clips = 0;
2899 #endif /* USE_FONT_BACKEND */
2903 /* Set up S->gc, set clipping and draw S. */
2904 x_set_glyph_string_gc (s);
2906 /* Draw relief (if any) in advance for char/composition so that the
2907 glyph string can be drawn over it. */
2908 if (!s->for_overlaps
2909 && s->face->box != FACE_NO_BOX
2910 && (s->first_glyph->type == CHAR_GLYPH
2911 || s->first_glyph->type == COMPOSITE_GLYPH))
2914 x_set_glyph_string_clipping (s);
2915 x_draw_glyph_string_background (s, 1);
2916 x_draw_glyph_string_box (s);
2917 x_set_glyph_string_clipping (s);
2918 relief_drawn_p = 1;
2920 else if ((s->prev && s->prev->hl != s->hl && s->left_overhang)
2921 || (s->next && s->next->hl != s->hl && s->right_overhang))
2922 /* We must clip just this glyph. left_overhang part has already
2923 drawn when s->prev was drawn, and right_overhang part will be
2924 drawn later when s->next is drawn. */
2925 x_set_glyph_string_clipping_exactly (s, s);
2926 else
2927 x_set_glyph_string_clipping (s);
2929 switch (s->first_glyph->type)
2931 case IMAGE_GLYPH:
2932 x_draw_image_glyph_string (s);
2933 break;
2935 case STRETCH_GLYPH:
2936 x_draw_stretch_glyph_string (s);
2937 break;
2939 case CHAR_GLYPH:
2940 if (s->for_overlaps)
2941 s->background_filled_p = 1;
2942 else
2943 x_draw_glyph_string_background (s, 0);
2944 x_draw_glyph_string_foreground (s);
2945 break;
2947 case COMPOSITE_GLYPH:
2948 if (s->for_overlaps || s->gidx > 0)
2949 s->background_filled_p = 1;
2950 else
2951 x_draw_glyph_string_background (s, 1);
2952 x_draw_composite_glyph_string_foreground (s);
2953 break;
2955 default:
2956 abort ();
2959 if (!s->for_overlaps)
2961 /* Draw underline. */
2962 if (s->face->underline_p
2963 && (s->font->bdf || !s->font->tm.tmUnderlined))
2965 unsigned long h;
2966 int y;
2967 /* Get the underline thickness. Default is 1 pixel. */
2968 #ifdef USE_FONT_BACKEND
2969 if (enable_font_backend)
2970 /* In the future, we must use information of font. */
2971 h = 1;
2972 else
2973 #endif /* USE_FONT_BACKEND */
2974 h = 1;
2976 #ifdef USE_FONT_BACKEND
2977 if (enable_font_backend)
2979 if (s->face->font)
2980 /* In the future, we must use information of font. */
2981 y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
2982 else
2983 y = s->y + s->height - h;
2985 else
2986 #endif
2988 y = s->y + s->height - h;
2989 /* TODO: Use font information for positioning and
2990 thickness of underline. See OUTLINETEXTMETRIC,
2991 and xterm.c. Note: If you make this work,
2992 don't forget to change the doc string of
2993 x-use-underline_color-position-properties
2994 below. */
2995 #if 0
2996 if (!x_underline_at_descent_line)
3000 #endif
3002 if (s->face->underline_defaulted_p)
3004 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
3005 y, s->background_width, 1);
3007 else
3009 w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x,
3010 y, s->background_width, 1);
3013 /* Draw overline. */
3014 if (s->face->overline_p)
3016 unsigned long dy = 0, h = 1;
3018 if (s->face->overline_color_defaulted_p)
3020 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
3021 s->y + dy, s->background_width, h);
3023 else
3025 w32_fill_area (s->f, s->hdc, s->face->overline_color, s->x,
3026 s->y + dy, s->background_width, h);
3030 /* Draw strike-through. */
3031 if (s->face->strike_through_p
3032 && (s->font->bdf || !s->font->tm.tmStruckOut))
3034 unsigned long h = 1;
3035 unsigned long dy = (s->height - h) / 2;
3037 if (s->face->strike_through_color_defaulted_p)
3039 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy,
3040 s->width, h);
3042 else
3044 w32_fill_area (s->f, s->hdc, s->face->strike_through_color, s->x,
3045 s->y + dy, s->width, h);
3049 /* Draw relief if not yet drawn. */
3050 if (!relief_drawn_p && s->face->box != FACE_NO_BOX)
3051 x_draw_glyph_string_box (s);
3053 if (s->prev)
3055 struct glyph_string *prev;
3057 for (prev = s->prev; prev; prev = prev->prev)
3058 if (prev->hl != s->hl
3059 && prev->x + prev->width + prev->right_overhang > s->x)
3061 /* As prev was drawn while clipped to its own area, we
3062 must draw the right_overhang part using s->hl now. */
3063 enum draw_glyphs_face save = prev->hl;
3065 prev->hl = s->hl;
3066 x_set_glyph_string_gc (prev);
3067 x_set_glyph_string_clipping_exactly (s, prev);
3068 if (prev->first_glyph->type == CHAR_GLYPH)
3069 x_draw_glyph_string_foreground (prev);
3070 else
3071 x_draw_composite_glyph_string_foreground (prev);
3072 w32_set_clip_rectangle (prev->hdc, NULL);
3073 prev->hl = save;
3074 #ifdef USE_FONT_BACKEND
3075 prev->num_clips = 0;
3076 #endif /* USE_FONT_BACKEND */
3080 if (s->next)
3082 struct glyph_string *next;
3084 for (next = s->next; next; next = next->next)
3085 if (next->hl != s->hl
3086 && next->x - next->left_overhang < s->x + s->width)
3088 /* As next will be drawn while clipped to its own area,
3089 we must draw the left_overhang part using s->hl now. */
3090 enum draw_glyphs_face save = next->hl;
3092 next->hl = s->hl;
3093 x_set_glyph_string_gc (next);
3094 x_set_glyph_string_clipping_exactly (s, next);
3095 if (next->first_glyph->type == CHAR_GLYPH)
3096 x_draw_glyph_string_foreground (next);
3097 else
3098 x_draw_composite_glyph_string_foreground (next);
3099 w32_set_clip_rectangle (next->hdc, NULL);
3100 next->hl = save;
3101 #ifdef USE_FONT_BACKEND
3102 next->num_clips = 0;
3103 #endif /* USE_FONT_BACKEND */
3108 /* Reset clipping. */
3109 w32_set_clip_rectangle (s->hdc, NULL);
3110 #ifdef USE_FONT_BACKEND
3111 s->num_clips = 0;
3112 #endif /* USE_FONT_BACKEND */
3116 /* Shift display to make room for inserted glyphs. */
3118 void
3119 w32_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
3120 struct frame *f;
3121 int x, y, width, height, shift_by;
3123 HDC hdc;
3125 hdc = get_frame_dc (f);
3126 BitBlt (hdc, x + shift_by, y, width, height,
3127 hdc, x, y, SRCCOPY);
3129 release_frame_dc (f, hdc);
3133 /* Delete N glyphs at the nominal cursor position. Not implemented
3134 for X frames. */
3136 static void
3137 x_delete_glyphs (f, n)
3138 struct frame *f;
3139 register int n;
3141 if (! FRAME_W32_P (f))
3142 return;
3144 abort ();
3148 /* Clear entire frame. If updating_frame is non-null, clear that
3149 frame. Otherwise clear the selected frame. */
3151 static void
3152 x_clear_frame (struct frame *f)
3154 if (! FRAME_W32_P (f))
3155 return;
3157 /* Clearing the frame will erase any cursor, so mark them all as no
3158 longer visible. */
3159 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
3160 output_cursor.hpos = output_cursor.vpos = 0;
3161 output_cursor.x = -1;
3163 /* We don't set the output cursor here because there will always
3164 follow an explicit cursor_to. */
3165 BLOCK_INPUT;
3167 w32_clear_window (f);
3169 /* We have to clear the scroll bars, too. If we have changed
3170 colors or something like that, then they should be notified. */
3171 x_scroll_bar_clear (f);
3173 UNBLOCK_INPUT;
3177 /* Make audible bell. */
3179 static void
3180 w32_ring_bell (struct frame *f)
3182 BLOCK_INPUT;
3184 if (FRAME_W32_P (f) && visible_bell)
3186 int i;
3187 HWND hwnd = FRAME_W32_WINDOW (f);
3189 for (i = 0; i < 5; i++)
3191 FlashWindow (hwnd, TRUE);
3192 Sleep (10);
3194 FlashWindow (hwnd, FALSE);
3196 else
3197 w32_sys_ring_bell (f);
3199 UNBLOCK_INPUT;
3203 /* Specify how many text lines, from the top of the window,
3204 should be affected by insert-lines and delete-lines operations.
3205 This, and those operations, are used only within an update
3206 that is bounded by calls to x_update_begin and x_update_end. */
3208 static void
3209 w32_set_terminal_window (n)
3210 register int n;
3212 /* This function intentionally left blank. */
3216 /***********************************************************************
3217 Line Dance
3218 ***********************************************************************/
3220 /* Perform an insert-lines or delete-lines operation, inserting N
3221 lines or deleting -N lines at vertical position VPOS. */
3223 static void
3224 x_ins_del_lines (f, vpos, n)
3225 struct frame *f;
3226 int vpos, n;
3228 if (! FRAME_W32_P (f))
3229 return;
3231 abort ();
3235 /* Scroll part of the display as described by RUN. */
3237 static void
3238 x_scroll_run (w, run)
3239 struct window *w;
3240 struct run *run;
3242 struct frame *f = XFRAME (w->frame);
3243 int x, y, width, height, from_y, to_y, bottom_y;
3244 HWND hwnd = FRAME_W32_WINDOW (f);
3245 HRGN expect_dirty;
3247 /* Get frame-relative bounding box of the text display area of W,
3248 without mode lines. Include in this box the left and right
3249 fringes of W. */
3250 window_box (w, -1, &x, &y, &width, &height);
3252 from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y);
3253 to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y);
3254 bottom_y = y + height;
3256 if (to_y < from_y)
3258 /* Scrolling up. Make sure we don't copy part of the mode
3259 line at the bottom. */
3260 if (from_y + run->height > bottom_y)
3261 height = bottom_y - from_y;
3262 else
3263 height = run->height;
3264 expect_dirty = CreateRectRgn (x, y + height, x + width, bottom_y);
3266 else
3268 /* Scolling down. Make sure we don't copy over the mode line.
3269 at the bottom. */
3270 if (to_y + run->height > bottom_y)
3271 height = bottom_y - to_y;
3272 else
3273 height = run->height;
3274 expect_dirty = CreateRectRgn (x, y, x + width, to_y);
3277 BLOCK_INPUT;
3279 /* Cursor off. Will be switched on again in x_update_window_end. */
3280 updated_window = w;
3281 x_clear_cursor (w);
3284 RECT from;
3285 RECT to;
3286 HRGN dirty = CreateRectRgn (0, 0, 0, 0);
3287 HRGN combined = CreateRectRgn (0, 0, 0, 0);
3289 from.left = to.left = x;
3290 from.right = to.right = x + width;
3291 from.top = from_y;
3292 from.bottom = from_y + height;
3293 to.top = y;
3294 to.bottom = bottom_y;
3296 ScrollWindowEx (hwnd, 0, to_y - from_y, &from, &to, dirty,
3297 NULL, SW_INVALIDATE);
3299 /* Combine this with what we expect to be dirty. This covers the
3300 case where not all of the region we expect is actually dirty. */
3301 CombineRgn (combined, dirty, expect_dirty, RGN_OR);
3303 /* If the dirty region is not what we expected, redraw the entire frame. */
3304 if (!EqualRgn (combined, expect_dirty))
3305 SET_FRAME_GARBAGED (f);
3307 DeleteObject (dirty);
3308 DeleteObject (combined);
3311 UNBLOCK_INPUT;
3312 DeleteObject (expect_dirty);
3317 /***********************************************************************
3318 Exposure Events
3319 ***********************************************************************/
3321 static void
3322 frame_highlight (f)
3323 struct frame *f;
3325 x_update_cursor (f, 1);
3328 static void
3329 frame_unhighlight (f)
3330 struct frame *f;
3332 x_update_cursor (f, 1);
3335 /* The focus has changed. Update the frames as necessary to reflect
3336 the new situation. Note that we can't change the selected frame
3337 here, because the Lisp code we are interrupting might become confused.
3338 Each event gets marked with the frame in which it occurred, so the
3339 Lisp code can tell when the switch took place by examining the events. */
3341 static void
3342 x_new_focus_frame (dpyinfo, frame)
3343 struct w32_display_info *dpyinfo;
3344 struct frame *frame;
3346 struct frame *old_focus = dpyinfo->w32_focus_frame;
3348 if (frame != dpyinfo->w32_focus_frame)
3350 /* Set this before calling other routines, so that they see
3351 the correct value of w32_focus_frame. */
3352 dpyinfo->w32_focus_frame = frame;
3354 if (old_focus && old_focus->auto_lower)
3355 x_lower_frame (old_focus);
3357 if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise)
3358 pending_autoraise_frame = dpyinfo->w32_focus_frame;
3359 else
3360 pending_autoraise_frame = 0;
3363 x_frame_rehighlight (dpyinfo);
3367 /* Handle FocusIn and FocusOut state changes for FRAME.
3368 If FRAME has focus and there exists more than one frame, puts
3369 a FOCUS_IN_EVENT into *BUFP. */
3371 static void
3372 x_focus_changed (type, state, dpyinfo, frame, bufp)
3373 int type;
3374 int state;
3375 struct w32_display_info *dpyinfo;
3376 struct frame *frame;
3377 struct input_event *bufp;
3379 if (type == WM_SETFOCUS)
3381 if (dpyinfo->w32_focus_event_frame != frame)
3383 x_new_focus_frame (dpyinfo, frame);
3384 dpyinfo->w32_focus_event_frame = frame;
3386 /* Don't stop displaying the initial startup message
3387 for a switch-frame event we don't need. */
3388 if (NILP (Vterminal_frame)
3389 && CONSP (Vframe_list)
3390 && !NILP (XCDR (Vframe_list)))
3392 bufp->kind = FOCUS_IN_EVENT;
3393 XSETFRAME (bufp->frame_or_window, frame);
3397 frame->output_data.x->focus_state |= state;
3399 /* TODO: IME focus? */
3401 else if (type == WM_KILLFOCUS)
3403 frame->output_data.x->focus_state &= ~state;
3405 if (dpyinfo->w32_focus_event_frame == frame)
3407 dpyinfo->w32_focus_event_frame = 0;
3408 x_new_focus_frame (dpyinfo, 0);
3411 /* TODO: IME focus? */
3416 /* The focus may have changed. Figure out if it is a real focus change,
3417 by checking both FocusIn/Out and Enter/LeaveNotify events.
3419 Returns FOCUS_IN_EVENT event in *BUFP. */
3421 static void
3422 w32_detect_focus_change (dpyinfo, event, bufp)
3423 struct w32_display_info *dpyinfo;
3424 W32Msg *event;
3425 struct input_event *bufp;
3427 struct frame *frame;
3429 frame = x_any_window_to_frame (dpyinfo, event->msg.hwnd);
3430 if (! frame)
3431 return;
3433 /* On w32, this is only called from focus events, so no switch needed. */
3434 x_focus_changed (event->msg.message,
3435 (event->msg.message == WM_KILLFOCUS ?
3436 FOCUS_IMPLICIT : FOCUS_EXPLICIT),
3437 dpyinfo, frame, bufp);
3441 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3443 void
3444 x_mouse_leave (dpyinfo)
3445 struct w32_display_info *dpyinfo;
3447 x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame);
3450 /* The focus has changed, or we have redirected a frame's focus to
3451 another frame (this happens when a frame uses a surrogate
3452 mini-buffer frame). Shift the highlight as appropriate.
3454 The FRAME argument doesn't necessarily have anything to do with which
3455 frame is being highlighted or un-highlighted; we only use it to find
3456 the appropriate X display info. */
3458 static void
3459 w32_frame_rehighlight (frame)
3460 struct frame *frame;
3462 if (! FRAME_W32_P (frame))
3463 return;
3464 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame));
3467 static void
3468 x_frame_rehighlight (dpyinfo)
3469 struct w32_display_info *dpyinfo;
3471 struct frame *old_highlight = dpyinfo->x_highlight_frame;
3473 if (dpyinfo->w32_focus_frame)
3475 dpyinfo->x_highlight_frame
3476 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)))
3477 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))
3478 : dpyinfo->w32_focus_frame);
3479 if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame))
3481 FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil;
3482 dpyinfo->x_highlight_frame = dpyinfo->w32_focus_frame;
3485 else
3486 dpyinfo->x_highlight_frame = 0;
3488 if (dpyinfo->x_highlight_frame != old_highlight)
3490 if (old_highlight)
3491 frame_unhighlight (old_highlight);
3492 if (dpyinfo->x_highlight_frame)
3493 frame_highlight (dpyinfo->x_highlight_frame);
3497 /* Keyboard processing - modifier keys, etc. */
3499 /* Convert a keysym to its name. */
3501 char *
3502 x_get_keysym_name (keysym)
3503 int keysym;
3505 /* Make static so we can always return it */
3506 static char value[100];
3508 BLOCK_INPUT;
3509 GetKeyNameText (keysym, value, 100);
3510 UNBLOCK_INPUT;
3512 return value;
3517 /* Mouse clicks and mouse movement. Rah. */
3519 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
3520 the state in PUP. XBUTTON provides extra information for extended mouse
3521 button messages. Returns FALSE if unable to parse the message. */
3522 BOOL
3523 parse_button (message, xbutton, pbutton, pup)
3524 int message;
3525 int xbutton;
3526 int * pbutton;
3527 int * pup;
3529 int button = 0;
3530 int up = 0;
3532 switch (message)
3534 case WM_LBUTTONDOWN:
3535 button = 0;
3536 up = 0;
3537 break;
3538 case WM_LBUTTONUP:
3539 button = 0;
3540 up = 1;
3541 break;
3542 case WM_MBUTTONDOWN:
3543 if (NILP (Vw32_swap_mouse_buttons))
3544 button = 1;
3545 else
3546 button = 2;
3547 up = 0;
3548 break;
3549 case WM_MBUTTONUP:
3550 if (NILP (Vw32_swap_mouse_buttons))
3551 button = 1;
3552 else
3553 button = 2;
3554 up = 1;
3555 break;
3556 case WM_RBUTTONDOWN:
3557 if (NILP (Vw32_swap_mouse_buttons))
3558 button = 2;
3559 else
3560 button = 1;
3561 up = 0;
3562 break;
3563 case WM_RBUTTONUP:
3564 if (NILP (Vw32_swap_mouse_buttons))
3565 button = 2;
3566 else
3567 button = 1;
3568 up = 1;
3569 break;
3570 case WM_XBUTTONDOWN:
3571 button = xbutton + 2;
3572 up = 0;
3573 break;
3574 case WM_XBUTTONUP:
3575 button = xbutton + 2;
3576 up = 1;
3577 break;
3578 default:
3579 return (FALSE);
3582 if (pup) *pup = up;
3583 if (pbutton) *pbutton = button;
3585 return (TRUE);
3589 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3591 If the event is a button press, then note that we have grabbed
3592 the mouse. */
3594 static Lisp_Object
3595 construct_mouse_click (result, msg, f)
3596 struct input_event *result;
3597 W32Msg *msg;
3598 struct frame *f;
3600 int button;
3601 int up;
3603 parse_button (msg->msg.message, HIWORD (msg->msg.wParam),
3604 &button, &up);
3606 /* Make the event type NO_EVENT; we'll change that when we decide
3607 otherwise. */
3608 result->kind = MOUSE_CLICK_EVENT;
3609 result->code = button;
3610 result->timestamp = msg->msg.time;
3611 result->modifiers = (msg->dwModifiers
3612 | (up
3613 ? up_modifier
3614 : down_modifier));
3616 XSETINT (result->x, LOWORD (msg->msg.lParam));
3617 XSETINT (result->y, HIWORD (msg->msg.lParam));
3618 XSETFRAME (result->frame_or_window, f);
3619 result->arg = Qnil;
3620 return Qnil;
3623 static Lisp_Object
3624 construct_mouse_wheel (result, msg, f)
3625 struct input_event *result;
3626 W32Msg *msg;
3627 struct frame *f;
3629 POINT p;
3630 int delta;
3632 result->kind = msg->msg.message == WM_MOUSEHWHEEL ? HORIZ_WHEEL_EVENT
3633 : WHEEL_EVENT;
3634 result->code = 0;
3635 result->timestamp = msg->msg.time;
3637 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
3638 forward, away from the user (up); a negative value indicates that
3639 the wheel was rotated backward, toward the user (down). */
3640 delta = GET_WHEEL_DELTA_WPARAM (msg->msg.wParam);
3642 /* The up and down modifiers indicate if the wheel was rotated up or
3643 down based on WHEEL_DELTA value. */
3644 result->modifiers = (msg->dwModifiers
3645 | ((delta < 0 ) ? down_modifier : up_modifier));
3647 /* With multiple monitors, we can legitimately get negative
3648 coordinates, so cast to short to interpret them correctly. */
3649 p.x = (short) LOWORD (msg->msg.lParam);
3650 p.y = (short) HIWORD (msg->msg.lParam);
3651 ScreenToClient (msg->msg.hwnd, &p);
3652 XSETINT (result->x, p.x);
3653 XSETINT (result->y, p.y);
3654 XSETFRAME (result->frame_or_window, f);
3655 result->arg = Qnil;
3656 return Qnil;
3659 static Lisp_Object
3660 construct_drag_n_drop (result, msg, f)
3661 struct input_event *result;
3662 W32Msg *msg;
3663 struct frame *f;
3665 Lisp_Object files;
3666 Lisp_Object frame;
3667 HDROP hdrop;
3668 POINT p;
3669 WORD num_files;
3670 char *name;
3671 int i, len;
3673 result->kind = DRAG_N_DROP_EVENT;
3674 result->code = 0;
3675 result->timestamp = msg->msg.time;
3676 result->modifiers = msg->dwModifiers;
3678 hdrop = (HDROP) msg->msg.wParam;
3679 DragQueryPoint (hdrop, &p);
3681 #if 0
3682 p.x = LOWORD (msg->msg.lParam);
3683 p.y = HIWORD (msg->msg.lParam);
3684 ScreenToClient (msg->msg.hwnd, &p);
3685 #endif
3687 XSETINT (result->x, p.x);
3688 XSETINT (result->y, p.y);
3690 num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
3691 files = Qnil;
3693 for (i = 0; i < num_files; i++)
3695 len = DragQueryFile (hdrop, i, NULL, 0);
3696 if (len <= 0)
3697 continue;
3698 name = alloca (len + 1);
3699 DragQueryFile (hdrop, i, name, len + 1);
3700 files = Fcons (DECODE_FILE (build_string (name)), files);
3703 DragFinish (hdrop);
3705 XSETFRAME (frame, f);
3706 result->frame_or_window = frame;
3707 result->arg = files;
3708 return Qnil;
3712 /* Function to report a mouse movement to the mainstream Emacs code.
3713 The input handler calls this.
3715 We have received a mouse movement event, which is given in *event.
3716 If the mouse is over a different glyph than it was last time, tell
3717 the mainstream emacs code by setting mouse_moved. If not, ask for
3718 another motion event, so we can check again the next time it moves. */
3720 static MSG last_mouse_motion_event;
3721 static Lisp_Object last_mouse_motion_frame;
3723 static int
3724 note_mouse_movement (frame, msg)
3725 FRAME_PTR frame;
3726 MSG *msg;
3728 int mouse_x = LOWORD (msg->lParam);
3729 int mouse_y = HIWORD (msg->lParam);
3731 last_mouse_movement_time = msg->time;
3732 memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event));
3733 XSETFRAME (last_mouse_motion_frame, frame);
3735 if (!FRAME_X_OUTPUT (frame))
3736 return 0;
3738 if (msg->hwnd != FRAME_W32_WINDOW (frame))
3740 frame->mouse_moved = 1;
3741 last_mouse_scroll_bar = Qnil;
3742 note_mouse_highlight (frame, -1, -1);
3743 last_mouse_glyph_frame = 0;
3744 return 1;
3747 /* Has the mouse moved off the glyph it was on at the last sighting? */
3748 if (frame != last_mouse_glyph_frame
3749 || mouse_x < last_mouse_glyph.left
3750 || mouse_x >= last_mouse_glyph.right
3751 || mouse_y < last_mouse_glyph.top
3752 || mouse_y >= last_mouse_glyph.bottom)
3754 frame->mouse_moved = 1;
3755 last_mouse_scroll_bar = Qnil;
3756 note_mouse_highlight (frame, mouse_x, mouse_y);
3757 /* Remember the mouse position here, as w32_mouse_position only
3758 gets called when mouse tracking is enabled but we also need
3759 to keep track of the mouse for help_echo and highlighting at
3760 other times. */
3761 remember_mouse_glyph (frame, mouse_x, mouse_y, &last_mouse_glyph);
3762 last_mouse_glyph_frame = frame;
3763 return 1;
3766 return 0;
3770 /************************************************************************
3771 Mouse Face
3772 ************************************************************************/
3774 static struct scroll_bar *x_window_to_scroll_bar ();
3775 static void x_scroll_bar_report_motion ();
3776 static void x_check_fullscreen P_ ((struct frame *));
3778 static void
3779 redo_mouse_highlight ()
3781 if (!NILP (last_mouse_motion_frame)
3782 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame)))
3783 note_mouse_highlight (XFRAME (last_mouse_motion_frame),
3784 LOWORD (last_mouse_motion_event.lParam),
3785 HIWORD (last_mouse_motion_event.lParam));
3788 static void
3789 w32_define_cursor (window, cursor)
3790 Window window;
3791 Cursor cursor;
3793 PostMessage (window, WM_EMACS_SETCURSOR, (WPARAM) cursor, 0);
3795 /* Return the current position of the mouse.
3796 *fp should be a frame which indicates which display to ask about.
3798 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3799 and *part to the frame, window, and scroll bar part that the mouse
3800 is over. Set *x and *y to the portion and whole of the mouse's
3801 position on the scroll bar.
3803 If the mouse movement started elsewhere, set *fp to the frame the
3804 mouse is on, *bar_window to nil, and *x and *y to the character cell
3805 the mouse is over.
3807 Set *time to the server time-stamp for the time at which the mouse
3808 was at this position.
3810 Don't store anything if we don't have a valid set of values to report.
3812 This clears the mouse_moved flag, so we can wait for the next mouse
3813 movement. */
3815 static void
3816 w32_mouse_position (fp, insist, bar_window, part, x, y, time)
3817 FRAME_PTR *fp;
3818 int insist;
3819 Lisp_Object *bar_window;
3820 enum scroll_bar_part *part;
3821 Lisp_Object *x, *y;
3822 unsigned long *time;
3824 FRAME_PTR f1;
3826 BLOCK_INPUT;
3828 if (! NILP (last_mouse_scroll_bar) && insist == 0)
3829 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
3830 else
3832 POINT pt;
3834 Lisp_Object frame, tail;
3836 /* Clear the mouse-moved flag for every frame on this display. */
3837 FOR_EACH_FRAME (tail, frame)
3838 XFRAME (frame)->mouse_moved = 0;
3840 last_mouse_scroll_bar = Qnil;
3842 GetCursorPos (&pt);
3844 /* Now we have a position on the root; find the innermost window
3845 containing the pointer. */
3847 if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame
3848 && FRAME_LIVE_P (last_mouse_frame))
3850 /* If mouse was grabbed on a frame, give coords for that frame
3851 even if the mouse is now outside it. */
3852 f1 = last_mouse_frame;
3854 else
3856 /* Is window under mouse one of our frames? */
3857 f1 = x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp),
3858 WindowFromPoint (pt));
3861 /* If not, is it one of our scroll bars? */
3862 if (! f1)
3864 struct scroll_bar *bar
3865 = x_window_to_scroll_bar (WindowFromPoint (pt));
3867 if (bar)
3869 f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3873 if (f1 == 0 && insist > 0)
3874 f1 = SELECTED_FRAME ();
3876 if (f1)
3878 /* Ok, we found a frame. Store all the values.
3879 last_mouse_glyph is a rectangle used to reduce the
3880 generation of mouse events. To not miss any motion
3881 events, we must divide the frame into rectangles of the
3882 size of the smallest character that could be displayed
3883 on it, i.e. into the same rectangles that matrices on
3884 the frame are divided into. */
3886 ScreenToClient (FRAME_W32_WINDOW (f1), &pt);
3887 remember_mouse_glyph (f1, pt.x, pt.y, &last_mouse_glyph);
3888 last_mouse_glyph_frame = f1;
3890 *bar_window = Qnil;
3891 *part = 0;
3892 *fp = f1;
3893 XSETINT (*x, pt.x);
3894 XSETINT (*y, pt.y);
3895 *time = last_mouse_movement_time;
3900 UNBLOCK_INPUT;
3904 /***********************************************************************
3905 Tool-bars
3906 ***********************************************************************/
3908 /* Handle mouse button event on the tool-bar of frame F, at
3909 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
3910 or ButtonRelase. */
3912 static void
3913 w32_handle_tool_bar_click (f, button_event)
3914 struct frame *f;
3915 struct input_event *button_event;
3917 int x = XFASTINT (button_event->x);
3918 int y = XFASTINT (button_event->y);
3920 if (button_event->modifiers & down_modifier)
3921 handle_tool_bar_click (f, x, y, 1, 0);
3922 else
3923 handle_tool_bar_click (f, x, y, 0,
3924 button_event->modifiers & ~up_modifier);
3929 /***********************************************************************
3930 Scroll bars
3931 ***********************************************************************/
3933 /* Scroll bar support. */
3935 /* Given a window ID, find the struct scroll_bar which manages it.
3936 This can be called in GC, so we have to make sure to strip off mark
3937 bits. */
3939 static struct scroll_bar *
3940 x_window_to_scroll_bar (window_id)
3941 Window window_id;
3943 Lisp_Object tail;
3945 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
3947 Lisp_Object frame, bar, condemned;
3949 frame = XCAR (tail);
3950 /* All elements of Vframe_list should be frames. */
3951 if (! FRAMEP (frame))
3952 abort ();
3954 /* Scan this frame's scroll bar list for a scroll bar with the
3955 right window ID. */
3956 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
3957 for (bar = FRAME_SCROLL_BARS (XFRAME (frame));
3958 /* This trick allows us to search both the ordinary and
3959 condemned scroll bar lists with one loop. */
3960 ! NILP (bar) || (bar = condemned,
3961 condemned = Qnil,
3962 ! NILP (bar));
3963 bar = XSCROLL_BAR (bar)->next)
3964 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id)
3965 return XSCROLL_BAR (bar);
3968 return 0;
3973 /* Set the thumb size and position of scroll bar BAR. We are currently
3974 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3976 static void
3977 w32_set_scroll_bar_thumb (bar, portion, position, whole)
3978 struct scroll_bar *bar;
3979 int portion, position, whole;
3981 Window w = SCROLL_BAR_W32_WINDOW (bar);
3982 /* We use the whole scroll-bar height in the calculations below, to
3983 avoid strange effects like scrolling backwards when just clicking
3984 on the handle (without moving it). */
3985 double range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height))
3986 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
3987 int sb_page, sb_pos;
3988 BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE;
3989 SCROLLINFO si;
3991 /* We used to change the nPage setting while dragging the handle,
3992 but that had very strange effects (such as scrolling backwards
3993 while dragging downwards).
3995 Now, we don't change the nPage setting while dragging unless we
3996 get near to the end of the buffer, in which case we often have to
3997 resize the handle to "go all the way". */
3999 if (draggingp)
4001 int near_bottom_p;
4002 BLOCK_INPUT;
4003 si.cbSize = sizeof (si);
4004 si.fMask = SIF_POS | SIF_PAGE;
4005 GetScrollInfo(w, SB_CTL, &si);
4006 near_bottom_p = si.nPos + si.nPage >= range;
4007 UNBLOCK_INPUT;
4008 if (!near_bottom_p)
4009 return;
4012 if (whole)
4014 /* Position scroll bar at rock bottom if the bottom of the
4015 buffer is visible. This avoids shinking the thumb away
4016 to nothing if it is held at the bottom of the buffer. */
4017 if (position + portion >= whole && !draggingp)
4019 sb_page = range * (whole - position) / whole;
4020 sb_pos = range;
4022 else
4024 sb_pos = position * range / whole;
4025 sb_page = (min (portion, (whole - position)) * range) / whole;
4028 else
4030 sb_page = range;
4031 sb_pos = 0;
4034 sb_page = max (sb_page, VERTICAL_SCROLL_BAR_MIN_HANDLE);
4036 BLOCK_INPUT;
4038 si.cbSize = sizeof (si);
4039 si.fMask = SIF_PAGE | SIF_POS;
4040 si.nPage = sb_page;
4041 si.nPos = sb_pos;
4043 SetScrollInfo (w, SB_CTL, &si, TRUE);
4045 UNBLOCK_INPUT;
4049 /************************************************************************
4050 Scroll bars, general
4051 ************************************************************************/
4053 static HWND
4054 my_create_scrollbar (f, bar)
4055 struct frame * f;
4056 struct scroll_bar * bar;
4058 return (HWND) SendMessage (FRAME_W32_WINDOW (f),
4059 WM_EMACS_CREATESCROLLBAR, (WPARAM) f,
4060 (LPARAM) bar);
4063 /*#define ATTACH_THREADS*/
4065 static BOOL
4066 my_show_window (FRAME_PTR f, HWND hwnd, int how)
4068 #ifndef ATTACH_THREADS
4069 return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW,
4070 (WPARAM) hwnd, (LPARAM) how);
4071 #else
4072 return ShowWindow (hwnd, how);
4073 #endif
4076 static void
4077 my_set_window_pos (HWND hwnd, HWND hwndAfter,
4078 int x, int y, int cx, int cy, UINT flags)
4080 #ifndef ATTACH_THREADS
4081 WINDOWPOS pos;
4082 pos.hwndInsertAfter = hwndAfter;
4083 pos.x = x;
4084 pos.y = y;
4085 pos.cx = cx;
4086 pos.cy = cy;
4087 pos.flags = flags;
4088 SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0);
4089 #else
4090 SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags);
4091 #endif
4094 static void
4095 my_set_focus (f, hwnd)
4096 struct frame * f;
4097 HWND hwnd;
4099 SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS,
4100 (WPARAM) hwnd, 0);
4103 static void
4104 my_set_foreground_window (hwnd)
4105 HWND hwnd;
4107 SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0);
4111 static void
4112 my_destroy_window (f, hwnd)
4113 struct frame * f;
4114 HWND hwnd;
4116 SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW,
4117 (WPARAM) hwnd, 0);
4120 /* Create a scroll bar and return the scroll bar vector for it. W is
4121 the Emacs window on which to create the scroll bar. TOP, LEFT,
4122 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
4123 scroll bar. */
4125 static struct scroll_bar *
4126 x_scroll_bar_create (w, top, left, width, height)
4127 struct window *w;
4128 int top, left, width, height;
4130 struct frame *f = XFRAME (WINDOW_FRAME (w));
4131 HWND hwnd;
4132 SCROLLINFO si;
4133 struct scroll_bar *bar
4134 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
4136 BLOCK_INPUT;
4138 XSETWINDOW (bar->window, w);
4139 XSETINT (bar->top, top);
4140 XSETINT (bar->left, left);
4141 XSETINT (bar->width, width);
4142 XSETINT (bar->height, height);
4143 XSETINT (bar->start, 0);
4144 XSETINT (bar->end, 0);
4145 bar->dragging = Qnil;
4146 bar->fringe_extended_p = Qnil;
4148 /* Requires geometry to be set before call to create the real window */
4150 hwnd = my_create_scrollbar (f, bar);
4152 si.cbSize = sizeof (si);
4153 si.fMask = SIF_ALL;
4154 si.nMin = 0;
4155 si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height)
4156 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4157 si.nPage = si.nMax;
4158 si.nPos = 0;
4160 SetScrollInfo (hwnd, SB_CTL, &si, FALSE);
4162 SET_SCROLL_BAR_W32_WINDOW (bar, hwnd);
4164 /* Add bar to its frame's list of scroll bars. */
4165 bar->next = FRAME_SCROLL_BARS (f);
4166 bar->prev = Qnil;
4167 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
4168 if (! NILP (bar->next))
4169 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
4171 UNBLOCK_INPUT;
4173 return bar;
4177 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4178 nil. */
4180 static void
4181 x_scroll_bar_remove (bar)
4182 struct scroll_bar *bar;
4184 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
4186 BLOCK_INPUT;
4188 /* Destroy the window. */
4189 my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar));
4191 /* Disassociate this scroll bar from its window. */
4192 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
4194 UNBLOCK_INPUT;
4197 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4198 that we are displaying PORTION characters out of a total of WHOLE
4199 characters, starting at POSITION. If WINDOW has no scroll bar,
4200 create one. */
4201 static void
4202 w32_set_vertical_scroll_bar (w, portion, whole, position)
4203 struct window *w;
4204 int portion, whole, position;
4206 struct frame *f = XFRAME (w->frame);
4207 struct scroll_bar *bar;
4208 int top, height, left, sb_left, width, sb_width;
4209 int window_y, window_height;
4210 int fringe_extended_p;
4212 /* Get window dimensions. */
4213 window_box (w, -1, 0, &window_y, 0, &window_height);
4214 top = window_y;
4215 width = WINDOW_CONFIG_SCROLL_BAR_COLS (w) * FRAME_COLUMN_WIDTH (f);
4216 height = window_height;
4218 /* Compute the left edge of the scroll bar area. */
4219 left = WINDOW_SCROLL_BAR_AREA_X (w);
4221 /* Compute the width of the scroll bar which might be less than
4222 the width of the area reserved for the scroll bar. */
4223 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) > 0)
4224 sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w);
4225 else
4226 sb_width = width;
4228 /* Compute the left edge of the scroll bar. */
4229 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w))
4230 sb_left = left + (WINDOW_RIGHTMOST_P (w) ? width - sb_width : 0);
4231 else
4232 sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width);
4234 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
4235 fringe_extended_p = (WINDOW_LEFTMOST_P (w)
4236 && WINDOW_LEFT_FRINGE_WIDTH (w)
4237 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
4238 || WINDOW_LEFT_MARGIN_COLS (w) == 0));
4239 else
4240 fringe_extended_p = (WINDOW_RIGHTMOST_P (w)
4241 && WINDOW_RIGHT_FRINGE_WIDTH (w)
4242 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
4243 || WINDOW_RIGHT_MARGIN_COLS (w) == 0));
4245 /* Does the scroll bar exist yet? */
4246 if (NILP (w->vertical_scroll_bar))
4248 HDC hdc;
4249 BLOCK_INPUT;
4250 if (width > 0 && height > 0)
4252 hdc = get_frame_dc (f);
4253 if (fringe_extended_p)
4254 w32_clear_area (f, hdc, sb_left, top, sb_width, height);
4255 else
4256 w32_clear_area (f, hdc, left, top, width, height);
4257 release_frame_dc (f, hdc);
4259 UNBLOCK_INPUT;
4261 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height);
4263 else
4265 /* It may just need to be moved and resized. */
4266 HWND hwnd;
4268 bar = XSCROLL_BAR (w->vertical_scroll_bar);
4269 hwnd = SCROLL_BAR_W32_WINDOW (bar);
4271 /* If already correctly positioned, do nothing. */
4272 if ( XINT (bar->left) == sb_left
4273 && XINT (bar->top) == top
4274 && XINT (bar->width) == sb_width
4275 && XINT (bar->height) == height
4276 && !NILP (bar->fringe_extended_p) == fringe_extended_p )
4278 /* Redraw after clear_frame. */
4279 if (!my_show_window (f, hwnd, SW_NORMAL))
4280 InvalidateRect (hwnd, NULL, FALSE);
4282 else
4284 HDC hdc;
4285 SCROLLINFO si;
4287 BLOCK_INPUT;
4288 if (width && height)
4290 hdc = get_frame_dc (f);
4291 /* Since Windows scroll bars are smaller than the space reserved
4292 for them on the frame, we have to clear "under" them. */
4293 if (fringe_extended_p)
4294 w32_clear_area (f, hdc, sb_left, top, sb_width, height);
4295 else
4296 w32_clear_area (f, hdc, left, top, width, height);
4297 release_frame_dc (f, hdc);
4299 /* Make sure scroll bar is "visible" before moving, to ensure the
4300 area of the parent window now exposed will be refreshed. */
4301 my_show_window (f, hwnd, SW_HIDE);
4302 MoveWindow (hwnd, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
4303 top, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
4304 max (height, 1), TRUE);
4306 si.cbSize = sizeof (si);
4307 si.fMask = SIF_RANGE;
4308 si.nMin = 0;
4309 si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height)
4310 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4312 SetScrollInfo (hwnd, SB_CTL, &si, FALSE);
4314 my_show_window (f, hwnd, SW_NORMAL);
4315 /* InvalidateRect (w, NULL, FALSE); */
4317 /* Remember new settings. */
4318 XSETINT (bar->left, sb_left);
4319 XSETINT (bar->top, top);
4320 XSETINT (bar->width, sb_width);
4321 XSETINT (bar->height, height);
4323 UNBLOCK_INPUT;
4326 bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil;
4328 w32_set_scroll_bar_thumb (bar, portion, position, whole);
4330 XSETVECTOR (w->vertical_scroll_bar, bar);
4334 /* The following three hooks are used when we're doing a thorough
4335 redisplay of the frame. We don't explicitly know which scroll bars
4336 are going to be deleted, because keeping track of when windows go
4337 away is a real pain - "Can you say set-window-configuration, boys
4338 and girls?" Instead, we just assert at the beginning of redisplay
4339 that *all* scroll bars are to be removed, and then save a scroll bar
4340 from the fiery pit when we actually redisplay its window. */
4342 /* Arrange for all scroll bars on FRAME to be removed at the next call
4343 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4344 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4346 static void
4347 w32_condemn_scroll_bars (frame)
4348 FRAME_PTR frame;
4350 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
4351 while (! NILP (FRAME_SCROLL_BARS (frame)))
4353 Lisp_Object bar;
4354 bar = FRAME_SCROLL_BARS (frame);
4355 FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next;
4356 XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame);
4357 XSCROLL_BAR (bar)->prev = Qnil;
4358 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame)))
4359 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar;
4360 FRAME_CONDEMNED_SCROLL_BARS (frame) = bar;
4365 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4366 Note that WINDOW isn't necessarily condemned at all. */
4368 static void
4369 w32_redeem_scroll_bar (window)
4370 struct window *window;
4372 struct scroll_bar *bar;
4373 struct frame *f;
4375 /* We can't redeem this window's scroll bar if it doesn't have one. */
4376 if (NILP (window->vertical_scroll_bar))
4377 abort ();
4379 bar = XSCROLL_BAR (window->vertical_scroll_bar);
4381 /* Unlink it from the condemned list. */
4382 f = XFRAME (WINDOW_FRAME (window));
4383 if (NILP (bar->prev))
4385 /* If the prev pointer is nil, it must be the first in one of
4386 the lists. */
4387 if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar))
4388 /* It's not condemned. Everything's fine. */
4389 return;
4390 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f),
4391 window->vertical_scroll_bar))
4392 FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next;
4393 else
4394 /* If its prev pointer is nil, it must be at the front of
4395 one or the other! */
4396 abort ();
4398 else
4399 XSCROLL_BAR (bar->prev)->next = bar->next;
4401 if (! NILP (bar->next))
4402 XSCROLL_BAR (bar->next)->prev = bar->prev;
4404 bar->next = FRAME_SCROLL_BARS (f);
4405 bar->prev = Qnil;
4406 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
4407 if (! NILP (bar->next))
4408 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
4411 /* Remove all scroll bars on FRAME that haven't been saved since the
4412 last call to `*condemn_scroll_bars_hook'. */
4414 static void
4415 w32_judge_scroll_bars (f)
4416 FRAME_PTR f;
4418 Lisp_Object bar, next;
4420 bar = FRAME_CONDEMNED_SCROLL_BARS (f);
4422 /* Clear out the condemned list now so we won't try to process any
4423 more events on the hapless scroll bars. */
4424 FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil;
4426 for (; ! NILP (bar); bar = next)
4428 struct scroll_bar *b = XSCROLL_BAR (bar);
4430 x_scroll_bar_remove (b);
4432 next = b->next;
4433 b->next = b->prev = Qnil;
4436 /* Now there should be no references to the condemned scroll bars,
4437 and they should get garbage-collected. */
4440 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
4441 is set to something other than NO_EVENT, it is enqueued.
4443 This may be called from a signal handler, so we have to ignore GC
4444 mark bits. */
4446 static int
4447 w32_scroll_bar_handle_click (bar, msg, emacs_event)
4448 struct scroll_bar *bar;
4449 W32Msg *msg;
4450 struct input_event *emacs_event;
4452 if (! WINDOWP (bar->window))
4453 abort ();
4455 emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
4456 emacs_event->code = 0;
4457 /* not really meaningful to distinguish up/down */
4458 emacs_event->modifiers = msg->dwModifiers;
4459 emacs_event->frame_or_window = bar->window;
4460 emacs_event->arg = Qnil;
4461 emacs_event->timestamp = msg->msg.time;
4464 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4465 int y;
4466 int dragging = !NILP (bar->dragging);
4467 SCROLLINFO si;
4469 si.cbSize = sizeof (si);
4470 si.fMask = SIF_POS;
4472 GetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si);
4473 y = si.nPos;
4475 bar->dragging = Qnil;
4478 last_mouse_scroll_bar_pos = msg->msg.wParam;
4480 switch (LOWORD (msg->msg.wParam))
4482 case SB_LINEDOWN:
4483 emacs_event->part = scroll_bar_down_arrow;
4484 break;
4485 case SB_LINEUP:
4486 emacs_event->part = scroll_bar_up_arrow;
4487 break;
4488 case SB_PAGEUP:
4489 emacs_event->part = scroll_bar_above_handle;
4490 break;
4491 case SB_PAGEDOWN:
4492 emacs_event->part = scroll_bar_below_handle;
4493 break;
4494 case SB_TOP:
4495 emacs_event->part = scroll_bar_handle;
4496 y = 0;
4497 break;
4498 case SB_BOTTOM:
4499 emacs_event->part = scroll_bar_handle;
4500 y = top_range;
4501 break;
4502 case SB_THUMBTRACK:
4503 case SB_THUMBPOSITION:
4504 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff)
4505 y = HIWORD (msg->msg.wParam);
4506 bar->dragging = Qt;
4507 emacs_event->part = scroll_bar_handle;
4509 /* "Silently" update current position. */
4511 SCROLLINFO si;
4513 si.cbSize = sizeof (si);
4514 si.fMask = SIF_POS;
4515 si.nPos = y;
4516 /* Remember apparent position (we actually lag behind the real
4517 position, so don't set that directly. */
4518 last_scroll_bar_drag_pos = y;
4520 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE);
4522 break;
4523 case SB_ENDSCROLL:
4524 /* If this is the end of a drag sequence, then reset the scroll
4525 handle size to normal and do a final redraw. Otherwise do
4526 nothing. */
4527 if (dragging)
4529 SCROLLINFO si;
4530 int start = XINT (bar->start);
4531 int end = XINT (bar->end);
4533 si.cbSize = sizeof (si);
4534 si.fMask = SIF_PAGE | SIF_POS;
4535 si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4536 si.nPos = last_scroll_bar_drag_pos;
4537 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE);
4539 /* fall through */
4540 default:
4541 emacs_event->kind = NO_EVENT;
4542 return FALSE;
4545 XSETINT (emacs_event->x, y);
4546 XSETINT (emacs_event->y, top_range);
4548 return TRUE;
4552 /* Return information to the user about the current position of the mouse
4553 on the scroll bar. */
4555 static void
4556 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
4557 FRAME_PTR *fp;
4558 Lisp_Object *bar_window;
4559 enum scroll_bar_part *part;
4560 Lisp_Object *x, *y;
4561 unsigned long *time;
4563 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4564 Window w = SCROLL_BAR_W32_WINDOW (bar);
4565 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
4566 int pos;
4567 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4568 SCROLLINFO si;
4570 BLOCK_INPUT;
4572 *fp = f;
4573 *bar_window = bar->window;
4575 si.cbSize = sizeof (si);
4576 si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
4578 GetScrollInfo (w, SB_CTL, &si);
4579 pos = si.nPos;
4580 top_range = si.nMax - si.nPage + 1;
4582 switch (LOWORD (last_mouse_scroll_bar_pos))
4584 case SB_THUMBPOSITION:
4585 case SB_THUMBTRACK:
4586 *part = scroll_bar_handle;
4587 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff)
4588 pos = HIWORD (last_mouse_scroll_bar_pos);
4589 break;
4590 case SB_LINEDOWN:
4591 *part = scroll_bar_handle;
4592 pos++;
4593 break;
4594 default:
4595 *part = scroll_bar_handle;
4596 break;
4599 XSETINT (*x, pos);
4600 XSETINT (*y, top_range);
4602 f->mouse_moved = 0;
4603 last_mouse_scroll_bar = Qnil;
4605 *time = last_mouse_movement_time;
4607 UNBLOCK_INPUT;
4611 /* The screen has been cleared so we may have changed foreground or
4612 background colors, and the scroll bars may need to be redrawn.
4613 Clear out the scroll bars, and ask for expose events, so we can
4614 redraw them. */
4616 void
4617 x_scroll_bar_clear (f)
4618 FRAME_PTR f;
4620 Lisp_Object bar;
4622 /* We can have scroll bars even if this is 0,
4623 if we just turned off scroll bar mode.
4624 But in that case we should not clear them. */
4625 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4626 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
4627 bar = XSCROLL_BAR (bar)->next)
4629 HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar));
4630 HDC hdc = GetDC (window);
4631 RECT rect;
4633 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
4634 arranges to refresh the scroll bar if hidden. */
4635 my_show_window (f, window, SW_HIDE);
4637 GetClientRect (window, &rect);
4638 select_palette (f, hdc);
4639 w32_clear_rect (f, hdc, &rect);
4640 deselect_palette (f, hdc);
4642 ReleaseDC (window, hdc);
4647 /* The main W32 event-reading loop - w32_read_socket. */
4649 /* Record the last 100 characters stored
4650 to help debug the loss-of-chars-during-GC problem. */
4652 static int temp_index;
4653 static short temp_buffer[100];
4655 /* Temporarily store lead byte of DBCS input sequences. */
4656 static char dbcs_lead = 0;
4658 /* Read events coming from the W32 shell.
4659 This routine is called by the SIGIO handler.
4660 We return as soon as there are no more events to be read.
4662 We return the number of characters stored into the buffer,
4663 thus pretending to be `read'.
4665 EXPECTED is nonzero if the caller knows input is available.
4667 Some of these messages are reposted back to the message queue since the
4668 system calls the windows proc directly in a context where we cannot return
4669 the data nor can we guarantee the state we are in. So if we dispatch them
4670 we will get into an infinite loop. To prevent this from ever happening we
4671 will set a variable to indicate we are in the read_socket call and indicate
4672 which message we are processing since the windows proc gets called
4673 recursively with different messages by the system.
4677 w32_read_socket (sd, expected, hold_quit)
4678 register int sd;
4679 int expected;
4680 struct input_event *hold_quit;
4682 int count = 0;
4683 int check_visibility = 0;
4684 W32Msg msg;
4685 struct frame *f;
4686 struct w32_display_info *dpyinfo = &one_w32_display_info;
4688 if (interrupt_input_blocked)
4690 interrupt_input_pending = 1;
4691 return -1;
4694 interrupt_input_pending = 0;
4695 BLOCK_INPUT;
4697 /* So people can tell when we have read the available input. */
4698 input_signal_count++;
4700 /* TODO: ghostscript integration. */
4701 while (get_next_msg (&msg, FALSE))
4703 struct input_event inev;
4704 int do_help = 0;
4706 EVENT_INIT (inev);
4707 inev.kind = NO_EVENT;
4708 inev.arg = Qnil;
4710 switch (msg.msg.message)
4712 case WM_PAINT:
4713 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4715 if (f)
4717 if (msg.rect.right == msg.rect.left ||
4718 msg.rect.bottom == msg.rect.top)
4720 /* We may get paint messages even though the client
4721 area is clipped - these are not expose events. */
4722 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f,
4723 SDATA (f->name)));
4725 else if (f->async_visible != 1)
4727 /* Definitely not obscured, so mark as visible. */
4728 f->async_visible = 1;
4729 f->async_iconified = 0;
4730 SET_FRAME_GARBAGED (f);
4731 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f,
4732 SDATA (f->name)));
4734 /* WM_PAINT serves as MapNotify as well, so report
4735 visibility changes properly. */
4736 if (f->iconified)
4738 inev.kind = DEICONIFY_EVENT;
4739 XSETFRAME (inev.frame_or_window, f);
4741 else if (! NILP (Vframe_list)
4742 && ! NILP (XCDR (Vframe_list)))
4743 /* Force a redisplay sooner or later to update the
4744 frame titles in case this is the second frame. */
4745 record_asynch_buffer_change ();
4747 else
4749 HDC hdc = get_frame_dc (f);
4751 /* Erase background again for safety. */
4752 w32_clear_rect (f, hdc, &msg.rect);
4753 release_frame_dc (f, hdc);
4754 expose_frame (f,
4755 msg.rect.left,
4756 msg.rect.top,
4757 msg.rect.right - msg.rect.left,
4758 msg.rect.bottom - msg.rect.top);
4761 break;
4763 case WM_INPUTLANGCHANGE:
4764 /* Generate a language change event. */
4765 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4767 if (f)
4769 inev.kind = LANGUAGE_CHANGE_EVENT;
4770 XSETFRAME (inev.frame_or_window, f);
4771 inev.code = msg.msg.wParam;
4772 inev.modifiers = msg.msg.lParam & 0xffff;
4774 break;
4776 case WM_KEYDOWN:
4777 case WM_SYSKEYDOWN:
4778 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4780 if (f && !f->iconified)
4782 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4783 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4785 clear_mouse_face (dpyinfo);
4786 dpyinfo->mouse_face_hidden = 1;
4789 if (temp_index == sizeof temp_buffer / sizeof (short))
4790 temp_index = 0;
4791 temp_buffer[temp_index++] = msg.msg.wParam;
4792 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
4793 inev.code = msg.msg.wParam;
4794 inev.modifiers = msg.dwModifiers;
4795 XSETFRAME (inev.frame_or_window, f);
4796 inev.timestamp = msg.msg.time;
4798 break;
4800 case WM_UNICHAR:
4801 case WM_SYSCHAR:
4802 case WM_CHAR:
4803 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4805 if (f && !f->iconified)
4807 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4808 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4810 clear_mouse_face (dpyinfo);
4811 dpyinfo->mouse_face_hidden = 1;
4814 if (temp_index == sizeof temp_buffer / sizeof (short))
4815 temp_index = 0;
4816 temp_buffer[temp_index++] = msg.msg.wParam;
4818 inev.modifiers = msg.dwModifiers;
4819 XSETFRAME (inev.frame_or_window, f);
4820 inev.timestamp = msg.msg.time;
4822 if (msg.msg.message == WM_UNICHAR)
4824 inev.code = msg.msg.wParam;
4826 else if (msg.msg.wParam < 256)
4828 wchar_t code;
4829 char dbcs[2];
4830 dbcs[0] = 0;
4831 dbcs[1] = (char) msg.msg.wParam;
4833 if (dbcs_lead)
4835 dbcs[0] = dbcs_lead;
4836 dbcs_lead = 0;
4837 if (!MultiByteToWideChar (CP_ACP, 0, dbcs, 2, &code, 1))
4839 /* Garbage */
4840 DebPrint (("Invalid DBCS sequence: %d %d\n",
4841 dbcs[0], dbcs[1]));
4842 inev.kind = NO_EVENT;
4843 break;
4846 else if (IsDBCSLeadByteEx (CP_ACP, (BYTE) msg.msg.wParam))
4848 dbcs_lead = (char) msg.msg.wParam;
4849 inev.kind = NO_EVENT;
4850 break;
4852 else
4854 if (!MultiByteToWideChar (CP_ACP, 0, &dbcs[1], 1,
4855 &code, 1))
4857 /* What to do with garbage? */
4858 DebPrint (("Invalid character: %d\n", dbcs[1]));
4859 inev.kind = NO_EVENT;
4860 break;
4863 inev.code = code;
4865 else
4867 /* Windows shouldn't generate WM_CHAR events above 0xFF
4868 in non-Unicode message handlers. */
4869 DebPrint (("Non-byte WM_CHAR: %d\n", msg.msg.wParam));
4870 inev.kind = NO_EVENT;
4871 break;
4873 inev.kind = inev.code < 128 ? ASCII_KEYSTROKE_EVENT
4874 : MULTIBYTE_CHAR_KEYSTROKE_EVENT;
4876 break;
4878 case WM_APPCOMMAND:
4879 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4881 if (f && !f->iconified)
4883 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4884 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4886 clear_mouse_face (dpyinfo);
4887 dpyinfo->mouse_face_hidden = 1;
4890 if (temp_index == sizeof temp_buffer / sizeof (short))
4891 temp_index = 0;
4892 temp_buffer[temp_index++] = msg.msg.wParam;
4893 inev.kind = MULTIMEDIA_KEY_EVENT;
4894 inev.code = GET_APPCOMMAND_LPARAM(msg.msg.lParam);
4895 inev.modifiers = msg.dwModifiers;
4896 XSETFRAME (inev.frame_or_window, f);
4897 inev.timestamp = msg.msg.time;
4899 break;
4901 case WM_MOUSEMOVE:
4902 /* Ignore non-movement. */
4904 int x = LOWORD (msg.msg.lParam);
4905 int y = HIWORD (msg.msg.lParam);
4906 if (x == last_mousemove_x && y == last_mousemove_y)
4907 break;
4908 last_mousemove_x = x;
4909 last_mousemove_y = y;
4912 previous_help_echo_string = help_echo_string;
4913 help_echo_string = Qnil;
4915 if (dpyinfo->grabbed && last_mouse_frame
4916 && FRAME_LIVE_P (last_mouse_frame))
4917 f = last_mouse_frame;
4918 else
4919 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4921 if (dpyinfo->mouse_face_hidden)
4923 dpyinfo->mouse_face_hidden = 0;
4924 clear_mouse_face (dpyinfo);
4927 if (f)
4929 /* Generate SELECT_WINDOW_EVENTs when needed. */
4930 if (!NILP (Vmouse_autoselect_window))
4932 Lisp_Object window;
4933 int x = LOWORD (msg.msg.lParam);
4934 int y = HIWORD (msg.msg.lParam);
4936 window = window_from_coordinates (f, x, y, 0, 0, 0, 0);
4938 /* Window will be selected only when it is not
4939 selected now and last mouse movement event was
4940 not in it. Minibuffer window will be selected
4941 only when it is active. */
4942 if (WINDOWP(window)
4943 && !EQ (window, last_window)
4944 && !EQ (window, selected_window)
4945 /* For click-to-focus window managers
4946 create event iff we don't leave the
4947 selected frame. */
4948 && (focus_follows_mouse
4949 || (EQ (XWINDOW (window)->frame,
4950 XWINDOW (selected_window)->frame))))
4952 inev.kind = SELECT_WINDOW_EVENT;
4953 inev.frame_or_window = window;
4956 last_window=window;
4958 if (!note_mouse_movement (f, &msg.msg))
4959 help_echo_string = previous_help_echo_string;
4961 else
4963 /* If we move outside the frame, then we're
4964 certainly no longer on any text in the frame. */
4965 clear_mouse_face (dpyinfo);
4968 /* If the contents of the global variable help_echo_string
4969 has changed, generate a HELP_EVENT. */
4970 #if 0 /* The below is an invalid comparison when USE_LISP_UNION_TYPE.
4971 But it was originally changed to this to fix a bug, so I have
4972 not removed it completely in case the bug is still there. */
4973 if (help_echo_string != previous_help_echo_string ||
4974 (!NILP (help_echo_string) && !STRINGP (help_echo_string) && f->mouse_moved))
4975 #else /* This is what xterm.c does. */
4976 if (!NILP (help_echo_string)
4977 || !NILP (previous_help_echo_string))
4978 do_help = 1;
4979 #endif
4980 break;
4982 case WM_LBUTTONDOWN:
4983 case WM_LBUTTONUP:
4984 case WM_MBUTTONDOWN:
4985 case WM_MBUTTONUP:
4986 case WM_RBUTTONDOWN:
4987 case WM_RBUTTONUP:
4988 case WM_XBUTTONDOWN:
4989 case WM_XBUTTONUP:
4991 /* If we decide we want to generate an event to be seen
4992 by the rest of Emacs, we put it here. */
4993 int tool_bar_p = 0;
4994 int button;
4995 int up;
4997 if (dpyinfo->grabbed && last_mouse_frame
4998 && FRAME_LIVE_P (last_mouse_frame))
4999 f = last_mouse_frame;
5000 else
5001 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5003 if (f)
5005 construct_mouse_click (&inev, &msg, f);
5007 /* Is this in the tool-bar? */
5008 if (WINDOWP (f->tool_bar_window)
5009 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)))
5011 Lisp_Object window;
5012 int x = XFASTINT (inev.x);
5013 int y = XFASTINT (inev.y);
5015 window = window_from_coordinates (f, x, y, 0, 0, 0, 1);
5017 if (EQ (window, f->tool_bar_window))
5019 w32_handle_tool_bar_click (f, &inev);
5020 tool_bar_p = 1;
5024 if (tool_bar_p
5025 || (dpyinfo->w32_focus_frame
5026 && f != dpyinfo->w32_focus_frame))
5027 inev.kind = NO_EVENT;
5030 parse_button (msg.msg.message, HIWORD (msg.msg.wParam),
5031 &button, &up);
5033 if (up)
5035 dpyinfo->grabbed &= ~ (1 << button);
5037 else
5039 dpyinfo->grabbed |= (1 << button);
5040 last_mouse_frame = f;
5041 /* Ignore any mouse motion that happened
5042 before this event; any subsequent mouse-movement
5043 Emacs events should reflect only motion after
5044 the ButtonPress. */
5045 if (f != 0)
5046 f->mouse_moved = 0;
5048 if (!tool_bar_p)
5049 last_tool_bar_item = -1;
5051 break;
5054 case WM_MOUSEWHEEL:
5055 case WM_MOUSEHWHEEL:
5057 if (dpyinfo->grabbed && last_mouse_frame
5058 && FRAME_LIVE_P (last_mouse_frame))
5059 f = last_mouse_frame;
5060 else
5061 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5063 if (f)
5066 if (!dpyinfo->w32_focus_frame
5067 || f == dpyinfo->w32_focus_frame)
5069 /* Emit an Emacs wheel-up/down event. */
5070 construct_mouse_wheel (&inev, &msg, f);
5072 /* Ignore any mouse motion that happened before this
5073 event; any subsequent mouse-movement Emacs events
5074 should reflect only motion after the
5075 ButtonPress. */
5076 f->mouse_moved = 0;
5078 last_mouse_frame = f;
5079 last_tool_bar_item = -1;
5081 break;
5083 case WM_DROPFILES:
5084 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5086 if (f)
5087 construct_drag_n_drop (&inev, &msg, f);
5088 break;
5090 case WM_VSCROLL:
5092 struct scroll_bar *bar =
5093 x_window_to_scroll_bar ((HWND)msg.msg.lParam);
5095 if (bar)
5096 w32_scroll_bar_handle_click (bar, &msg, &inev);
5097 break;
5100 case WM_WINDOWPOSCHANGED:
5101 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5102 if (f)
5104 if (f->want_fullscreen & FULLSCREEN_WAIT)
5105 f->want_fullscreen &= ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH);
5107 check_visibility = 1;
5108 break;
5110 case WM_ACTIVATE:
5111 case WM_ACTIVATEAPP:
5112 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5113 if (f)
5114 x_check_fullscreen (f);
5115 check_visibility = 1;
5116 break;
5118 case WM_MOVE:
5119 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5121 if (f && !f->async_iconified)
5123 int x, y;
5125 x_real_positions (f, &x, &y);
5126 f->left_pos = x;
5127 f->top_pos = y;
5130 check_visibility = 1;
5131 break;
5133 case WM_SHOWWINDOW:
5134 /* wParam non-zero means Window is about to be shown, 0 means
5135 about to be hidden. */
5136 /* Redo the mouse-highlight after the tooltip has gone. */
5137 if (!msg.msg.wParam && msg.msg.hwnd == tip_window)
5139 tip_window = NULL;
5140 redo_mouse_highlight ();
5143 /* If window has been obscured or exposed by another window
5144 being maximised or minimised/restored, then recheck
5145 visibility of all frames. Direct changes to our own
5146 windows get handled by WM_SIZE. */
5147 #if 0
5148 if (msg.msg.lParam != 0)
5149 check_visibility = 1;
5150 else
5152 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5153 f->async_visible = msg.msg.wParam;
5155 #endif
5157 check_visibility = 1;
5158 break;
5160 case WM_SIZE:
5161 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5163 /* Inform lisp of whether frame has been iconified etc. */
5164 if (f)
5166 switch (msg.msg.wParam)
5168 case SIZE_MINIMIZED:
5169 f->async_visible = 0;
5170 f->async_iconified = 1;
5172 inev.kind = ICONIFY_EVENT;
5173 XSETFRAME (inev.frame_or_window, f);
5174 break;
5176 case SIZE_MAXIMIZED:
5177 case SIZE_RESTORED:
5178 f->async_visible = 1;
5179 f->async_iconified = 0;
5181 /* wait_reading_process_output will notice this and update
5182 the frame's display structures. */
5183 SET_FRAME_GARBAGED (f);
5185 if (f->iconified)
5187 int x, y;
5189 /* Reset top and left positions of the Window
5190 here since Windows sends a WM_MOVE message
5191 BEFORE telling us the Window is minimized
5192 when the Window is iconified, with 3000,3000
5193 as the co-ords. */
5194 x_real_positions (f, &x, &y);
5195 f->left_pos = x;
5196 f->top_pos = y;
5198 inev.kind = DEICONIFY_EVENT;
5199 XSETFRAME (inev.frame_or_window, f);
5201 else if (! NILP (Vframe_list)
5202 && ! NILP (XCDR (Vframe_list)))
5203 /* Force a redisplay sooner or later
5204 to update the frame titles
5205 in case this is the second frame. */
5206 record_asynch_buffer_change ();
5207 break;
5211 if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED)
5213 RECT rect;
5214 int rows;
5215 int columns;
5216 int width;
5217 int height;
5219 GetClientRect (msg.msg.hwnd, &rect);
5221 height = rect.bottom - rect.top;
5222 width = rect.right - rect.left;
5224 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
5225 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
5227 /* TODO: Clip size to the screen dimensions. */
5229 /* Even if the number of character rows and columns has
5230 not changed, the font size may have changed, so we need
5231 to check the pixel dimensions as well. */
5233 if (columns != FRAME_COLS (f)
5234 || rows != FRAME_LINES (f)
5235 || width != FRAME_PIXEL_WIDTH (f)
5236 || height != FRAME_PIXEL_HEIGHT (f))
5238 change_frame_size (f, rows, columns, 0, 1, 0);
5239 SET_FRAME_GARBAGED (f);
5240 cancel_mouse_face (f);
5241 FRAME_PIXEL_WIDTH (f) = width;
5242 FRAME_PIXEL_HEIGHT (f) = height;
5243 f->win_gravity = NorthWestGravity;
5247 check_visibility = 1;
5248 break;
5250 case WM_MOUSELEAVE:
5251 f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd);
5252 if (f)
5254 if (f == dpyinfo->mouse_face_mouse_frame)
5256 /* If we move outside the frame, then we're
5257 certainly no longer on any text in the frame. */
5258 clear_mouse_face (dpyinfo);
5259 dpyinfo->mouse_face_mouse_frame = 0;
5262 /* Generate a nil HELP_EVENT to cancel a help-echo.
5263 Do it only if there's something to cancel.
5264 Otherwise, the startup message is cleared when
5265 the mouse leaves the frame. */
5266 if (any_help_event_p)
5267 do_help = -1;
5269 break;
5271 case WM_SETFOCUS:
5272 w32_detect_focus_change (dpyinfo, &msg, &inev);
5274 dpyinfo->grabbed = 0;
5275 check_visibility = 1;
5276 break;
5278 case WM_KILLFOCUS:
5279 f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd);
5281 if (f)
5283 if (f == dpyinfo->w32_focus_event_frame)
5284 dpyinfo->w32_focus_event_frame = 0;
5286 if (f == dpyinfo->w32_focus_frame)
5287 x_new_focus_frame (dpyinfo, 0);
5289 if (f == dpyinfo->mouse_face_mouse_frame)
5291 /* If we move outside the frame, then we're
5292 certainly no longer on any text in the frame. */
5293 clear_mouse_face (dpyinfo);
5294 dpyinfo->mouse_face_mouse_frame = 0;
5297 /* Generate a nil HELP_EVENT to cancel a help-echo.
5298 Do it only if there's something to cancel.
5299 Otherwise, the startup message is cleared when
5300 the mouse leaves the frame. */
5301 if (any_help_event_p)
5302 do_help = -1;
5305 dpyinfo->grabbed = 0;
5306 check_visibility = 1;
5307 break;
5309 case WM_CLOSE:
5310 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5312 if (f)
5314 inev.kind = DELETE_WINDOW_EVENT;
5315 XSETFRAME (inev.frame_or_window, f);
5317 break;
5319 case WM_INITMENU:
5320 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5322 if (f)
5324 inev.kind = MENU_BAR_ACTIVATE_EVENT;
5325 XSETFRAME (inev.frame_or_window, f);
5327 break;
5329 case WM_COMMAND:
5330 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5332 if (f)
5334 extern void menubar_selection_callback
5335 (FRAME_PTR f, void * client_data);
5336 menubar_selection_callback (f, (void *)msg.msg.wParam);
5339 check_visibility = 1;
5340 break;
5342 case WM_DISPLAYCHANGE:
5343 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5345 if (f)
5347 dpyinfo->width = (short) LOWORD (msg.msg.lParam);
5348 dpyinfo->height = (short) HIWORD (msg.msg.lParam);
5349 dpyinfo->n_cbits = msg.msg.wParam;
5350 DebPrint (("display change: %d %d\n", dpyinfo->width,
5351 dpyinfo->height));
5354 check_visibility = 1;
5355 break;
5357 default:
5358 /* Check for messages registered at runtime. */
5359 if (msg.msg.message == msh_mousewheel)
5361 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
5362 msg.msg.message = WM_MOUSEWHEEL;
5363 prepend_msg (&msg);
5365 break;
5368 if (inev.kind != NO_EVENT)
5370 kbd_buffer_store_event_hold (&inev, hold_quit);
5371 count++;
5374 if (do_help
5375 && !(hold_quit && hold_quit->kind != NO_EVENT))
5377 Lisp_Object frame;
5379 if (f)
5380 XSETFRAME (frame, f);
5381 else
5382 frame = Qnil;
5384 if (do_help > 0)
5386 if (NILP (help_echo_string))
5388 help_echo_object = help_echo_window = Qnil;
5389 help_echo_pos = -1;
5392 any_help_event_p = 1;
5393 gen_help_event (help_echo_string, frame, help_echo_window,
5394 help_echo_object, help_echo_pos);
5396 else
5398 help_echo_string = Qnil;
5399 gen_help_event (Qnil, frame, Qnil, Qnil, 0);
5401 count++;
5405 /* If the focus was just given to an autoraising frame,
5406 raise it now. */
5407 /* ??? This ought to be able to handle more than one such frame. */
5408 if (pending_autoraise_frame)
5410 x_raise_frame (pending_autoraise_frame);
5411 pending_autoraise_frame = 0;
5414 /* Check which frames are still visisble, if we have enqueued any user
5415 events or been notified of events that may affect visibility. We
5416 do this here because there doesn't seem to be any direct
5417 notification from Windows that the visibility of a window has
5418 changed (at least, not in all cases). */
5419 if (count > 0 || check_visibility)
5421 Lisp_Object tail, frame;
5423 FOR_EACH_FRAME (tail, frame)
5425 FRAME_PTR f = XFRAME (frame);
5426 /* The tooltip has been drawn already. Avoid the
5427 SET_FRAME_GARBAGED below. */
5428 if (EQ (frame, tip_frame))
5429 continue;
5431 /* Check "visible" frames and mark each as obscured or not.
5432 Note that async_visible is nonzero for unobscured and
5433 obscured frames, but zero for hidden and iconified frames. */
5434 if (FRAME_W32_P (f) && f->async_visible)
5436 RECT clipbox;
5437 HDC hdc;
5439 enter_crit ();
5440 /* Query clipping rectangle for the entire window area
5441 (GetWindowDC), not just the client portion (GetDC).
5442 Otherwise, the scrollbars and menubar aren't counted as
5443 part of the visible area of the frame, and we may think
5444 the frame is obscured when really a scrollbar is still
5445 visible and gets WM_PAINT messages above. */
5446 hdc = GetWindowDC (FRAME_W32_WINDOW (f));
5447 GetClipBox (hdc, &clipbox);
5448 ReleaseDC (FRAME_W32_WINDOW (f), hdc);
5449 leave_crit ();
5451 if (clipbox.right == clipbox.left
5452 || clipbox.bottom == clipbox.top)
5454 /* Frame has become completely obscured so mark as
5455 such (we do this by setting async_visible to 2 so
5456 that FRAME_VISIBLE_P is still true, but redisplay
5457 will skip it). */
5458 f->async_visible = 2;
5460 if (!FRAME_OBSCURED_P (f))
5462 DebPrint (("frame %p (%s) obscured\n", f,
5463 SDATA (f->name)));
5466 else
5468 /* Frame is not obscured, so mark it as such. */
5469 f->async_visible = 1;
5471 if (FRAME_OBSCURED_P (f))
5473 SET_FRAME_GARBAGED (f);
5474 DebPrint (("obscured frame %p (%s) found to be visible\n", f,
5475 SDATA (f->name)));
5477 /* Force a redisplay sooner or later. */
5478 record_asynch_buffer_change ();
5485 UNBLOCK_INPUT;
5486 return count;
5491 /***********************************************************************
5492 Text Cursor
5493 ***********************************************************************/
5495 /* Set clipping for output in glyph row ROW. W is the window in which
5496 we operate. GC is the graphics context to set clipping in.
5498 ROW may be a text row or, e.g., a mode line. Text rows must be
5499 clipped to the interior of the window dedicated to text display,
5500 mode lines must be clipped to the whole window. */
5502 static void
5503 w32_clip_to_row (w, row, area, hdc)
5504 struct window *w;
5505 struct glyph_row *row;
5506 int area;
5507 HDC hdc;
5509 struct frame *f = XFRAME (WINDOW_FRAME (w));
5510 RECT clip_rect;
5511 int window_x, window_y, window_width;
5513 window_box (w, area, &window_x, &window_y, &window_width, 0);
5515 clip_rect.left = window_x;
5516 clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y);
5517 clip_rect.top = max (clip_rect.top, window_y);
5518 clip_rect.right = clip_rect.left + window_width;
5519 clip_rect.bottom = clip_rect.top + row->visible_height;
5521 w32_set_clip_rectangle (hdc, &clip_rect);
5525 /* Draw a hollow box cursor on window W in glyph row ROW. */
5527 static void
5528 x_draw_hollow_cursor (w, row)
5529 struct window *w;
5530 struct glyph_row *row;
5532 struct frame *f = XFRAME (WINDOW_FRAME (w));
5533 HDC hdc;
5534 RECT rect;
5535 int left, top, h;
5536 struct glyph *cursor_glyph;
5537 HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel);
5539 /* Get the glyph the cursor is on. If we can't tell because
5540 the current matrix is invalid or such, give up. */
5541 cursor_glyph = get_phys_cursor_glyph (w);
5542 if (cursor_glyph == NULL)
5543 return;
5545 /* Compute frame-relative coordinates for phys cursor. */
5546 get_phys_cursor_geometry (w, row, cursor_glyph, &left, &top, &h);
5547 rect.left = left;
5548 rect.top = top;
5549 rect.bottom = rect.top + h;
5550 rect.right = rect.left + w->phys_cursor_width;
5552 hdc = get_frame_dc (f);
5553 /* Set clipping, draw the rectangle, and reset clipping again. */
5554 w32_clip_to_row (w, row, TEXT_AREA, hdc);
5555 FrameRect (hdc, &rect, hb);
5556 DeleteObject (hb);
5557 w32_set_clip_rectangle (hdc, NULL);
5558 release_frame_dc (f, hdc);
5562 /* Draw a bar cursor on window W in glyph row ROW.
5564 Implementation note: One would like to draw a bar cursor with an
5565 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5566 Unfortunately, I didn't find a font yet that has this property set.
5567 --gerd. */
5569 static void
5570 x_draw_bar_cursor (w, row, width, kind)
5571 struct window *w;
5572 struct glyph_row *row;
5573 int width;
5574 enum text_cursor_kinds kind;
5576 struct frame *f = XFRAME (w->frame);
5577 struct glyph *cursor_glyph;
5578 int x;
5579 HDC hdc;
5581 /* If cursor is out of bounds, don't draw garbage. This can happen
5582 in mini-buffer windows when switching between echo area glyphs
5583 and mini-buffer. */
5584 cursor_glyph = get_phys_cursor_glyph (w);
5585 if (cursor_glyph == NULL)
5586 return;
5588 /* If on an image, draw like a normal cursor. That's usually better
5589 visible than drawing a bar, esp. if the image is large so that
5590 the bar might not be in the window. */
5591 if (cursor_glyph->type == IMAGE_GLYPH)
5593 struct glyph_row *row;
5594 row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos);
5595 draw_phys_cursor_glyph (w, row, DRAW_CURSOR);
5597 else
5599 COLORREF cursor_color = f->output_data.w32->cursor_pixel;
5600 struct face *face = FACE_FROM_ID (f, cursor_glyph->face_id);
5602 /* If the glyph's background equals the color we normally draw
5603 the bar cursor in, the bar cursor in its normal color is
5604 invisible. Use the glyph's foreground color instead in this
5605 case, on the assumption that the glyph's colors are chosen so
5606 that the glyph is legible. */
5607 if (face->background == cursor_color)
5608 cursor_color = face->foreground;
5610 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
5612 if (width < 0)
5613 width = FRAME_CURSOR_WIDTH (f);
5614 width = min (cursor_glyph->pixel_width, width);
5616 w->phys_cursor_width = width;
5619 hdc = get_frame_dc (f);
5620 w32_clip_to_row (w, row, TEXT_AREA, hdc);
5622 if (kind == BAR_CURSOR)
5624 w32_fill_area (f, hdc, cursor_color, x,
5625 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
5626 width, row->height);
5628 else
5630 w32_fill_area (f, hdc, cursor_color, x,
5631 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y +
5632 row->height - width),
5633 cursor_glyph->pixel_width, width);
5636 w32_set_clip_rectangle (hdc, NULL);
5637 release_frame_dc (f, hdc);
5642 /* RIF: Define cursor CURSOR on frame F. */
5644 static void
5645 w32_define_frame_cursor (f, cursor)
5646 struct frame *f;
5647 Cursor cursor;
5649 w32_define_cursor (FRAME_W32_WINDOW (f), cursor);
5653 /* RIF: Clear area on frame F. */
5655 static void
5656 w32_clear_frame_area (f, x, y, width, height)
5657 struct frame *f;
5658 int x, y, width, height;
5660 HDC hdc;
5662 hdc = get_frame_dc (f);
5663 w32_clear_area (f, hdc, x, y, width, height);
5664 release_frame_dc (f, hdc);
5667 /* RIF: Draw or clear cursor on window W. */
5669 static void
5670 w32_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, active_p)
5671 struct window *w;
5672 struct glyph_row *glyph_row;
5673 int x, y;
5674 int cursor_type, cursor_width;
5675 int on_p, active_p;
5677 if (on_p)
5679 /* If the user wants to use the system caret, make sure our own
5680 cursor remains invisible. */
5681 if (w32_use_visible_system_caret)
5683 /* Call to erase_phys_cursor here seems to use the
5684 wrong values of w->phys_cursor, as they have been
5685 overwritten before this function was called. */
5686 if (w->phys_cursor_type != NO_CURSOR)
5687 erase_phys_cursor (w);
5689 cursor_type = w->phys_cursor_type = NO_CURSOR;
5690 w->phys_cursor_width = -1;
5692 else
5694 w->phys_cursor_type = cursor_type;
5697 w->phys_cursor_on_p = 1;
5699 /* If this is the active cursor, we need to track it with the
5700 system caret, so third party software like screen magnifiers
5701 and speech synthesizers can follow the cursor. */
5702 if (active_p)
5704 struct frame *f = XFRAME (WINDOW_FRAME (w));
5705 HWND hwnd = FRAME_W32_WINDOW (f);
5707 w32_system_caret_x
5708 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
5709 w32_system_caret_y
5710 = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y)
5711 + glyph_row->ascent - w->phys_cursor_ascent);
5713 /* If the size of the active cursor changed, destroy the old
5714 system caret. */
5715 if (w32_system_caret_hwnd
5716 && (w32_system_caret_height != w->phys_cursor_height))
5717 PostMessage (hwnd, WM_EMACS_DESTROY_CARET, 0, 0);
5719 w32_system_caret_height = w->phys_cursor_height;
5721 /* Move the system caret. */
5722 PostMessage (hwnd, WM_EMACS_TRACK_CARET, 0, 0);
5725 if (glyph_row->exact_window_width_line_p
5726 && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])
5728 glyph_row->cursor_in_fringe_p = 1;
5729 draw_fringe_bitmap (w, glyph_row, 0);
5730 return;
5733 switch (cursor_type)
5735 case HOLLOW_BOX_CURSOR:
5736 x_draw_hollow_cursor (w, glyph_row);
5737 break;
5739 case FILLED_BOX_CURSOR:
5740 draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
5741 break;
5743 case BAR_CURSOR:
5744 x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
5745 break;
5747 case HBAR_CURSOR:
5748 x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
5749 break;
5751 case NO_CURSOR:
5752 w->phys_cursor_width = 0;
5753 break;
5755 default:
5756 abort ();
5763 /* Icons. */
5766 x_bitmap_icon (f, icon)
5767 struct frame *f;
5768 Lisp_Object icon;
5770 HANDLE main_icon;
5771 HANDLE small_icon = NULL;
5773 if (FRAME_W32_WINDOW (f) == 0)
5774 return 1;
5776 if (NILP (icon))
5777 main_icon = LoadIcon (hinst, EMACS_CLASS);
5778 else if (STRINGP (icon))
5780 /* Load the main icon from the named file. */
5781 main_icon = LoadImage (NULL, (LPCTSTR) SDATA (icon), IMAGE_ICON, 0, 0,
5782 LR_DEFAULTSIZE | LR_LOADFROMFILE);
5783 /* Try to load a small icon to go with it. */
5784 small_icon = LoadImage (NULL, (LPCSTR) SDATA (icon), IMAGE_ICON,
5785 GetSystemMetrics (SM_CXSMICON),
5786 GetSystemMetrics (SM_CYSMICON),
5787 LR_LOADFROMFILE);
5789 else if (SYMBOLP (icon))
5791 LPCTSTR name;
5793 if (EQ (icon, intern ("application")))
5794 name = (LPCTSTR) IDI_APPLICATION;
5795 else if (EQ (icon, intern ("hand")))
5796 name = (LPCTSTR) IDI_HAND;
5797 else if (EQ (icon, intern ("question")))
5798 name = (LPCTSTR) IDI_QUESTION;
5799 else if (EQ (icon, intern ("exclamation")))
5800 name = (LPCTSTR) IDI_EXCLAMATION;
5801 else if (EQ (icon, intern ("asterisk")))
5802 name = (LPCTSTR) IDI_ASTERISK;
5803 else if (EQ (icon, intern ("winlogo")))
5804 name = (LPCTSTR) IDI_WINLOGO;
5805 else
5806 return 1;
5808 main_icon = LoadIcon (NULL, name);
5810 else
5811 return 1;
5813 if (main_icon == NULL)
5814 return 1;
5816 PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG,
5817 (LPARAM) main_icon);
5819 /* If there is a small icon that goes with it, set that too. */
5820 if (small_icon)
5821 PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_SMALL,
5822 (LPARAM) small_icon);
5824 return 0;
5828 /************************************************************************
5829 Handling X errors
5830 ************************************************************************/
5832 /* Display Error Handling functions not used on W32. Listing them here
5833 helps diff stay in step when comparing w32term.c with xterm.c.
5835 x_error_catcher (display, error)
5836 x_catch_errors (dpy)
5837 x_catch_errors_unwind (old_val)
5838 x_check_errors (dpy, format)
5839 x_fully_uncatch_errors ()
5840 x_catching_errors ()
5841 x_had_errors_p (dpy)
5842 x_clear_errors (dpy)
5843 x_uncatch_errors (dpy, count)
5844 x_trace_wire ()
5845 x_connection_signal (signalnum)
5846 x_connection_closed (dpy, error_message)
5847 x_error_quitter (display, error)
5848 x_error_handler (display, error)
5849 x_io_error_quitter (display)
5854 /* Changing the font of the frame. */
5856 /* Give frame F the font named FONTNAME as its default font, and
5857 return the full name of that font. FONTNAME may be a wildcard
5858 pattern; in that case, we choose some font that fits the pattern.
5859 The return value shows which font we chose. */
5861 Lisp_Object
5862 x_new_font (f, fontname)
5863 struct frame *f;
5864 register char *fontname;
5866 struct font_info *fontp
5867 = FS_LOAD_FONT (f, fontname);
5869 if (!fontp)
5870 return Qnil;
5872 if (FRAME_FONT (f) == (XFontStruct *) (fontp->font))
5873 /* This font is already set in frame F. There's nothing more to
5874 do. */
5875 return build_string (fontp->full_name);
5877 FRAME_FONT (f) = (XFontStruct *) (fontp->font);
5878 FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
5879 FRAME_FONTSET (f) = -1;
5881 FRAME_COLUMN_WIDTH (f) = fontp->average_width;
5882 FRAME_SPACE_WIDTH (f) = fontp->space_width;
5883 FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f));
5885 compute_fringe_widths (f, 1);
5887 /* Compute the scroll bar width in character columns. */
5888 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
5890 int wid = FRAME_COLUMN_WIDTH (f);
5891 FRAME_CONFIG_SCROLL_BAR_COLS (f)
5892 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid;
5894 else
5896 int wid = FRAME_COLUMN_WIDTH (f);
5897 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
5900 /* Now make the frame display the given font. */
5901 if (FRAME_W32_WINDOW (f) != 0)
5903 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
5904 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
5907 return build_string (fontp->full_name);
5910 /* Give frame F the fontset named FONTSETNAME as its default fontset,
5911 and return the full name of that fontset. FONTSETNAME may be a
5912 wildcard pattern; in that case, we choose some fontset that fits
5913 the pattern. FONTSETNAME may be a font name for ASCII characters;
5914 in that case, we create a fontset from that font name.
5916 The return value shows which fontset we chose.
5917 If FONTSETNAME specifies the default fontset, return Qt.
5918 If an ASCII font in the specified fontset can't be loaded, return
5919 Qnil. */
5921 Lisp_Object
5922 x_new_fontset (f, fontsetname)
5923 struct frame *f;
5924 Lisp_Object fontsetname;
5926 int fontset = fs_query_fontset (fontsetname, 0);
5927 Lisp_Object result;
5929 if (fontset > 0 && FRAME_FONTSET(f) == fontset)
5930 /* This fontset is already set in frame F. There's nothing more
5931 to do. */
5932 return fontset_name (fontset);
5933 else if (fontset == 0)
5934 /* The default fontset can't be the default font. */
5935 return Qt;
5937 if (fontset > 0)
5938 result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
5939 else
5940 result = x_new_font (f, SDATA (fontsetname));
5942 if (!STRINGP (result))
5943 /* Can't load ASCII font. */
5944 return Qnil;
5946 if (fontset < 0)
5947 fontset = new_fontset_from_font_name (result);
5949 /* Since x_new_font doesn't update any fontset information, do it now. */
5950 FRAME_FONTSET(f) = fontset;
5952 return fontset_name (fontset);
5955 #ifdef USE_FONT_BACKEND
5956 Lisp_Object
5957 x_new_fontset2 (f, fontset, font_object)
5958 struct frame *f;
5959 int fontset;
5960 Lisp_Object font_object;
5962 struct font *font = XSAVE_VALUE (font_object)->pointer;
5964 if (FRAME_FONT_OBJECT (f) == font)
5965 /* This font is already set in frame F. There's nothing more to
5966 do. */
5967 return fontset_name (fontset);
5969 BLOCK_INPUT;
5971 FRAME_FONT_OBJECT (f) = font;
5972 FRAME_FONT (f) = font->font.font;
5973 FRAME_BASELINE_OFFSET (f) = font->font.baseline_offset;
5974 FRAME_FONTSET (f) = fontset;
5976 FRAME_COLUMN_WIDTH (f) = font->font.average_width;
5977 FRAME_SPACE_WIDTH (f) = font->font.space_width;
5978 FRAME_LINE_HEIGHT (f) = font->font.height;
5980 compute_fringe_widths (f, 1);
5982 /* Compute the scroll bar width in character columns. */
5983 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
5985 int wid = FRAME_COLUMN_WIDTH (f);
5986 FRAME_CONFIG_SCROLL_BAR_COLS (f)
5987 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid - 1) / wid;
5989 else
5991 int wid = FRAME_COLUMN_WIDTH (f);
5992 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
5995 /* Now make the frame display the given font. */
5996 if (FRAME_X_WINDOW (f) != 0)
5998 /* Don't change the size of a tip frame; there's no point in
5999 doing it because it's done in Fx_show_tip, and it leads to
6000 problems because the tip frame has no widget. */
6001 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
6002 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
6005 #ifdef HAVE_X_I18N
6006 if (FRAME_XIC (f)
6007 && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
6008 xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
6009 #endif
6011 UNBLOCK_INPUT;
6013 return fontset_name (fontset);
6015 #endif /* USE_FONT_BACKEND */
6018 /***********************************************************************
6019 TODO: W32 Input Methods
6020 ***********************************************************************/
6021 /* Listing missing functions from xterm.c helps diff stay in step.
6023 xim_destroy_callback (xim, client_data, call_data)
6024 xim_open_dpy (dpyinfo, resource_name)
6025 struct xim_inst_t
6026 xim_instantiate_callback (display, client_data, call_data)
6027 xim_initialize (dpyinfo, resource_name)
6028 xim_close_dpy (dpyinfo)
6033 /* Calculate the absolute position in frame F
6034 from its current recorded position values and gravity. */
6036 void
6037 x_calc_absolute_position (f)
6038 struct frame *f;
6040 int flags = f->size_hint_flags;
6042 /* The sum of the widths of the frame's left and right borders, and
6043 the sum of the heights of the frame's top and bottom borders (in
6044 pixels) drawn by Windows. */
6045 unsigned int left_right_borders_width, top_bottom_borders_height;
6047 /* Try to get the actual values of these two variables. We compute
6048 the border width (height) by subtracting the width (height) of
6049 the frame's client area from the width (height) of the frame's
6050 entire window. */
6051 WINDOWPLACEMENT wp = { 0 };
6052 RECT client_rect = { 0 };
6054 if (GetWindowPlacement (FRAME_W32_WINDOW (f), &wp)
6055 && GetClientRect (FRAME_W32_WINDOW (f), &client_rect))
6057 left_right_borders_width =
6058 (wp.rcNormalPosition.right - wp.rcNormalPosition.left) -
6059 (client_rect.right - client_rect.left);
6061 top_bottom_borders_height =
6062 (wp.rcNormalPosition.bottom - wp.rcNormalPosition.top) -
6063 (client_rect.bottom - client_rect.top);
6065 else
6067 /* Use sensible default values. */
6068 left_right_borders_width = 8;
6069 top_bottom_borders_height = 32;
6072 /* Treat negative positions as relative to the rightmost bottommost
6073 position that fits on the screen. */
6074 if (flags & XNegative)
6075 f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
6076 - FRAME_PIXEL_WIDTH (f)
6077 + f->left_pos
6078 - (left_right_borders_width - 1));
6080 if (flags & YNegative)
6081 f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
6082 - FRAME_PIXEL_HEIGHT (f)
6083 + f->top_pos
6084 - (top_bottom_borders_height - 1));
6086 /* The left_pos and top_pos are now relative to the top and left
6087 screen edges, so the flags should correspond. */
6088 f->size_hint_flags &= ~ (XNegative | YNegative);
6091 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
6092 to really change the position, and 0 when calling from
6093 x_make_frame_visible (in that case, XOFF and YOFF are the current
6094 position values). It is -1 when calling from x_set_frame_parameters,
6095 which means, do adjust for borders but don't change the gravity. */
6097 void
6098 x_set_offset (f, xoff, yoff, change_gravity)
6099 struct frame *f;
6100 register int xoff, yoff;
6101 int change_gravity;
6103 int modified_top, modified_left;
6105 if (change_gravity > 0)
6107 f->top_pos = yoff;
6108 f->left_pos = xoff;
6109 f->size_hint_flags &= ~ (XNegative | YNegative);
6110 if (xoff < 0)
6111 f->size_hint_flags |= XNegative;
6112 if (yoff < 0)
6113 f->size_hint_flags |= YNegative;
6114 f->win_gravity = NorthWestGravity;
6116 x_calc_absolute_position (f);
6118 BLOCK_INPUT;
6119 x_wm_set_size_hint (f, (long) 0, 0);
6121 modified_left = f->left_pos;
6122 modified_top = f->top_pos;
6124 my_set_window_pos (FRAME_W32_WINDOW (f),
6125 NULL,
6126 modified_left, modified_top,
6127 0, 0,
6128 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
6129 UNBLOCK_INPUT;
6133 /* Check if we need to resize the frame due to a fullscreen request.
6134 If so needed, resize the frame. */
6135 static void
6136 x_check_fullscreen (f)
6137 struct frame *f;
6139 if (f->want_fullscreen & FULLSCREEN_BOTH)
6141 int width, height, ign;
6143 x_real_positions (f, &f->left_pos, &f->top_pos);
6145 x_fullscreen_adjust (f, &width, &height, &ign, &ign);
6147 /* We do not need to move the window, it shall be taken care of
6148 when setting WM manager hints. */
6149 if (FRAME_COLS (f) != width || FRAME_LINES (f) != height)
6151 change_frame_size (f, height, width, 0, 1, 0);
6152 SET_FRAME_GARBAGED (f);
6153 cancel_mouse_face (f);
6155 /* Wait for the change of frame size to occur */
6156 f->want_fullscreen |= FULLSCREEN_WAIT;
6161 /* Call this to change the size of frame F's x-window.
6162 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
6163 for this size change and subsequent size changes.
6164 Otherwise we leave the window gravity unchanged. */
6166 void
6167 x_set_window_size (f, change_gravity, cols, rows)
6168 struct frame *f;
6169 int change_gravity;
6170 int cols, rows;
6172 int pixelwidth, pixelheight;
6174 BLOCK_INPUT;
6176 check_frame_size (f, &rows, &cols);
6177 f->scroll_bar_actual_width
6178 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
6180 compute_fringe_widths (f, 0);
6182 pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols);
6183 pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
6185 f->win_gravity = NorthWestGravity;
6186 x_wm_set_size_hint (f, (long) 0, 0);
6189 RECT rect;
6191 rect.left = rect.top = 0;
6192 rect.right = pixelwidth;
6193 rect.bottom = pixelheight;
6195 AdjustWindowRect(&rect, f->output_data.w32->dwStyle,
6196 FRAME_EXTERNAL_MENU_BAR (f));
6198 my_set_window_pos (FRAME_W32_WINDOW (f),
6199 NULL,
6200 0, 0,
6201 rect.right - rect.left,
6202 rect.bottom - rect.top,
6203 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
6206 #if 0
6207 /* The following mirrors what is done in xterm.c. It appears to be
6208 for informing lisp of the new size immediately, while the actual
6209 resize will happen asynchronously. But on Windows, the menu bar
6210 automatically wraps when the frame is too narrow to contain it,
6211 and that causes any calculations made here to come out wrong. The
6212 end is some nasty buggy behaviour, including the potential loss
6213 of the minibuffer.
6215 Disabling this code is either not sufficient to fix the problems
6216 completely, or it causes fresh problems, but at least it removes
6217 the most problematic symptom of the minibuffer becoming unusable.
6219 -----------------------------------------------------------------
6221 Now, strictly speaking, we can't be sure that this is accurate,
6222 but the window manager will get around to dealing with the size
6223 change request eventually, and we'll hear how it went when the
6224 ConfigureNotify event gets here.
6226 We could just not bother storing any of this information here,
6227 and let the ConfigureNotify event set everything up, but that
6228 might be kind of confusing to the Lisp code, since size changes
6229 wouldn't be reported in the frame parameters until some random
6230 point in the future when the ConfigureNotify event arrives.
6232 We pass 1 for DELAY since we can't run Lisp code inside of
6233 a BLOCK_INPUT. */
6234 change_frame_size (f, rows, cols, 0, 1, 0);
6235 FRAME_PIXEL_WIDTH (f) = pixelwidth;
6236 FRAME_PIXEL_HEIGHT (f) = pixelheight;
6238 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
6239 receive in the ConfigureNotify event; if we get what we asked
6240 for, then the event won't cause the screen to become garbaged, so
6241 we have to make sure to do it here. */
6242 SET_FRAME_GARBAGED (f);
6244 /* If cursor was outside the new size, mark it as off. */
6245 mark_window_cursors_off (XWINDOW (f->root_window));
6247 /* Clear out any recollection of where the mouse highlighting was,
6248 since it might be in a place that's outside the new frame size.
6249 Actually checking whether it is outside is a pain in the neck,
6250 so don't try--just let the highlighting be done afresh with new size. */
6251 cancel_mouse_face (f);
6252 #endif
6254 UNBLOCK_INPUT;
6257 /* Mouse warping. */
6259 void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
6261 void
6262 x_set_mouse_position (f, x, y)
6263 struct frame *f;
6264 int x, y;
6266 int pix_x, pix_y;
6268 pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
6269 pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
6271 if (pix_x < 0) pix_x = 0;
6272 if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f);
6274 if (pix_y < 0) pix_y = 0;
6275 if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
6277 x_set_mouse_pixel_position (f, pix_x, pix_y);
6280 void
6281 x_set_mouse_pixel_position (f, pix_x, pix_y)
6282 struct frame *f;
6283 int pix_x, pix_y;
6285 RECT rect;
6286 POINT pt;
6288 BLOCK_INPUT;
6290 GetClientRect (FRAME_W32_WINDOW (f), &rect);
6291 pt.x = rect.left + pix_x;
6292 pt.y = rect.top + pix_y;
6293 ClientToScreen (FRAME_W32_WINDOW (f), &pt);
6295 SetCursorPos (pt.x, pt.y);
6297 UNBLOCK_INPUT;
6301 /* focus shifting, raising and lowering. */
6303 void
6304 x_focus_on_frame (f)
6305 struct frame *f;
6307 struct w32_display_info *dpyinfo = &one_w32_display_info;
6309 /* Give input focus to frame. */
6310 BLOCK_INPUT;
6311 #if 0
6312 /* Try not to change its Z-order if possible. */
6313 if (x_window_to_frame (dpyinfo, GetForegroundWindow ()))
6314 my_set_focus (f, FRAME_W32_WINDOW (f));
6315 else
6316 #endif
6317 my_set_foreground_window (FRAME_W32_WINDOW (f));
6318 UNBLOCK_INPUT;
6321 void
6322 x_unfocus_frame (f)
6323 struct frame *f;
6327 /* Raise frame F. */
6328 void
6329 x_raise_frame (f)
6330 struct frame *f;
6332 BLOCK_INPUT;
6334 /* Strictly speaking, raise-frame should only change the frame's Z
6335 order, leaving input focus unchanged. This is reasonable behaviour
6336 on X where the usual policy is point-to-focus. However, this
6337 behaviour would be very odd on Windows where the usual policy is
6338 click-to-focus.
6340 On X, if the mouse happens to be over the raised frame, it gets
6341 input focus anyway (so the window with focus will never be
6342 completely obscured) - if not, then just moving the mouse over it
6343 is sufficient to give it focus. On Windows, the user must actually
6344 click on the frame (preferrably the title bar so as not to move
6345 point), which is more awkward. Also, no other Windows program
6346 raises a window to the top but leaves another window (possibly now
6347 completely obscured) with input focus.
6349 Because there is a system setting on Windows that allows the user
6350 to choose the point to focus policy, we make the strict semantics
6351 optional, but by default we grab focus when raising. */
6353 if (NILP (Vw32_grab_focus_on_raise))
6355 /* The obvious call to my_set_window_pos doesn't work if Emacs is
6356 not already the foreground application: the frame is raised
6357 above all other frames belonging to us, but not above the
6358 current top window. To achieve that, we have to resort to this
6359 more cumbersome method. */
6361 HDWP handle = BeginDeferWindowPos (2);
6362 if (handle)
6364 DeferWindowPos (handle,
6365 FRAME_W32_WINDOW (f),
6366 HWND_TOP,
6367 0, 0, 0, 0,
6368 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6370 DeferWindowPos (handle,
6371 GetForegroundWindow (),
6372 FRAME_W32_WINDOW (f),
6373 0, 0, 0, 0,
6374 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6376 EndDeferWindowPos (handle);
6379 else
6381 my_set_foreground_window (FRAME_W32_WINDOW (f));
6384 UNBLOCK_INPUT;
6387 /* Lower frame F. */
6388 void
6389 x_lower_frame (f)
6390 struct frame *f;
6392 BLOCK_INPUT;
6393 my_set_window_pos (FRAME_W32_WINDOW (f),
6394 HWND_BOTTOM,
6395 0, 0, 0, 0,
6396 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6397 UNBLOCK_INPUT;
6400 static void
6401 w32_frame_raise_lower (f, raise_flag)
6402 FRAME_PTR f;
6403 int raise_flag;
6405 if (! FRAME_W32_P (f))
6406 return;
6408 if (raise_flag)
6409 x_raise_frame (f);
6410 else
6411 x_lower_frame (f);
6414 /* Change of visibility. */
6416 /* This tries to wait until the frame is really visible.
6417 However, if the window manager asks the user where to position
6418 the frame, this will return before the user finishes doing that.
6419 The frame will not actually be visible at that time,
6420 but it will become visible later when the window manager
6421 finishes with it. */
6423 void
6424 x_make_frame_visible (f)
6425 struct frame *f;
6427 Lisp_Object type;
6429 BLOCK_INPUT;
6431 type = x_icon_type (f);
6432 if (!NILP (type))
6433 x_bitmap_icon (f, type);
6435 if (! FRAME_VISIBLE_P (f))
6437 /* We test FRAME_GARBAGED_P here to make sure we don't
6438 call x_set_offset a second time
6439 if we get to x_make_frame_visible a second time
6440 before the window gets really visible. */
6441 if (! FRAME_ICONIFIED_P (f)
6442 && ! f->output_data.w32->asked_for_visible)
6444 RECT workarea_rect;
6445 RECT window_rect;
6447 /* Adjust vertical window position in order to avoid being
6448 covered by a task bar placed at the bottom of the desktop. */
6449 SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea_rect, 0);
6450 GetWindowRect(FRAME_W32_WINDOW(f), &window_rect);
6451 if (window_rect.bottom > workarea_rect.bottom
6452 && window_rect.top > workarea_rect.top)
6453 f->top_pos = max (window_rect.top
6454 - window_rect.bottom + workarea_rect.bottom,
6455 workarea_rect.top);
6457 x_set_offset (f, f->left_pos, f->top_pos, 0);
6460 f->output_data.w32->asked_for_visible = 1;
6462 /* my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); */
6463 my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL);
6466 /* Synchronize to ensure Emacs knows the frame is visible
6467 before we do anything else. We do this loop with input not blocked
6468 so that incoming events are handled. */
6470 Lisp_Object frame;
6471 int count;
6473 /* This must come after we set COUNT. */
6474 UNBLOCK_INPUT;
6476 XSETFRAME (frame, f);
6478 /* Wait until the frame is visible. Process X events until a
6479 MapNotify event has been seen, or until we think we won't get a
6480 MapNotify at all.. */
6481 for (count = input_signal_count + 10;
6482 input_signal_count < count && !FRAME_VISIBLE_P (f);)
6484 /* Force processing of queued events. */
6485 /* TODO: x_sync equivalent? */
6487 /* Machines that do polling rather than SIGIO have been observed
6488 to go into a busy-wait here. So we'll fake an alarm signal
6489 to let the handler know that there's something to be read.
6490 We used to raise a real alarm, but it seems that the handler
6491 isn't always enabled here. This is probably a bug. */
6492 if (input_polling_used ())
6494 /* It could be confusing if a real alarm arrives while processing
6495 the fake one. Turn it off and let the handler reset it. */
6496 int old_poll_suppress_count = poll_suppress_count;
6497 poll_suppress_count = 1;
6498 poll_for_input_1 ();
6499 poll_suppress_count = old_poll_suppress_count;
6502 FRAME_SAMPLE_VISIBILITY (f);
6506 /* Change from mapped state to withdrawn state. */
6508 /* Make the frame visible (mapped and not iconified). */
6510 x_make_frame_invisible (f)
6511 struct frame *f;
6513 /* Don't keep the highlight on an invisible frame. */
6514 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f)
6515 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0;
6517 BLOCK_INPUT;
6519 my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE);
6521 /* We can't distinguish this from iconification
6522 just by the event that we get from the server.
6523 So we can't win using the usual strategy of letting
6524 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
6525 and synchronize with the server to make sure we agree. */
6526 f->visible = 0;
6527 FRAME_ICONIFIED_P (f) = 0;
6528 f->async_visible = 0;
6529 f->async_iconified = 0;
6531 UNBLOCK_INPUT;
6534 /* Change window state from mapped to iconified. */
6536 void
6537 x_iconify_frame (f)
6538 struct frame *f;
6540 Lisp_Object type;
6542 /* Don't keep the highlight on an invisible frame. */
6543 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f)
6544 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0;
6546 if (f->async_iconified)
6547 return;
6549 BLOCK_INPUT;
6551 type = x_icon_type (f);
6552 if (!NILP (type))
6553 x_bitmap_icon (f, type);
6555 /* Simulate the user minimizing the frame. */
6556 SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0);
6558 UNBLOCK_INPUT;
6562 /* Free X resources of frame F. */
6564 void
6565 x_free_frame_resources (f)
6566 struct frame *f;
6568 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6570 BLOCK_INPUT;
6572 #ifdef USE_FONT_BACKEND
6573 /* We must free faces before destroying windows because some
6574 font-driver (e.g. xft) access a window while finishing a
6575 face. */
6576 if (enable_font_backend
6577 && FRAME_FACE_CACHE (f))
6578 free_frame_faces (f);
6579 #endif /* USE_FONT_BACKEND */
6581 if (FRAME_W32_WINDOW (f))
6582 my_destroy_window (f, FRAME_W32_WINDOW (f));
6584 free_frame_menubar (f);
6586 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
6587 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
6588 unload_color (f, f->output_data.w32->cursor_pixel);
6589 unload_color (f, f->output_data.w32->cursor_foreground_pixel);
6590 unload_color (f, f->output_data.w32->border_pixel);
6591 unload_color (f, f->output_data.w32->mouse_pixel);
6592 if (f->output_data.w32->white_relief.allocated_p)
6593 unload_color (f, f->output_data.w32->white_relief.pixel);
6594 if (f->output_data.w32->black_relief.allocated_p)
6595 unload_color (f, f->output_data.w32->black_relief.pixel);
6597 if (FRAME_FACE_CACHE (f))
6598 free_frame_faces (f);
6600 xfree (f->output_data.w32);
6601 f->output_data.w32 = NULL;
6603 if (f == dpyinfo->w32_focus_frame)
6604 dpyinfo->w32_focus_frame = 0;
6605 if (f == dpyinfo->w32_focus_event_frame)
6606 dpyinfo->w32_focus_event_frame = 0;
6607 if (f == dpyinfo->x_highlight_frame)
6608 dpyinfo->x_highlight_frame = 0;
6610 if (f == dpyinfo->mouse_face_mouse_frame)
6612 dpyinfo->mouse_face_beg_row
6613 = dpyinfo->mouse_face_beg_col = -1;
6614 dpyinfo->mouse_face_end_row
6615 = dpyinfo->mouse_face_end_col = -1;
6616 dpyinfo->mouse_face_window = Qnil;
6617 dpyinfo->mouse_face_deferred_gc = 0;
6618 dpyinfo->mouse_face_mouse_frame = 0;
6621 UNBLOCK_INPUT;
6625 /* Destroy the window of frame F. */
6626 void
6627 x_destroy_window (f)
6628 struct frame *f;
6630 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6632 x_free_frame_resources (f);
6633 dpyinfo->reference_count--;
6637 /* Setting window manager hints. */
6639 /* Set the normal size hints for the window manager, for frame F.
6640 FLAGS is the flags word to use--or 0 meaning preserve the flags
6641 that the window now has.
6642 If USER_POSITION is nonzero, we set the USPosition
6643 flag (this is useful when FLAGS is 0). */
6644 void
6645 x_wm_set_size_hint (f, flags, user_position)
6646 struct frame *f;
6647 long flags;
6648 int user_position;
6650 Window window = FRAME_W32_WINDOW (f);
6652 enter_crit ();
6654 SetWindowLong (window, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f));
6655 SetWindowLong (window, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f));
6656 SetWindowLong (window, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f));
6657 SetWindowLong (window, WND_SCROLLBAR_INDEX, f->scroll_bar_actual_width);
6659 leave_crit ();
6662 /* Window manager things */
6663 void
6664 x_wm_set_icon_position (f, icon_x, icon_y)
6665 struct frame *f;
6666 int icon_x, icon_y;
6668 #if 0
6669 Window window = FRAME_W32_WINDOW (f);
6671 f->display.x->wm_hints.flags |= IconPositionHint;
6672 f->display.x->wm_hints.icon_x = icon_x;
6673 f->display.x->wm_hints.icon_y = icon_y;
6675 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
6676 #endif
6680 /***********************************************************************
6681 Fonts
6682 ***********************************************************************/
6684 /* The following functions are listed here to help diff stay in step
6685 with xterm.c. See w32fns.c for definitions.
6687 x_get_font_info (f, font_idx)
6688 x_list_fonts (f, pattern, size, maxnames)
6692 #if GLYPH_DEBUG
6694 /* Check that FONT is valid on frame F. It is if it can be found in F's
6695 font table. */
6697 static void
6698 x_check_font (f, font)
6699 struct frame *f;
6700 XFontStruct *font;
6702 int i;
6703 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6705 xassert (font != NULL);
6707 for (i = 0; i < dpyinfo->n_fonts; i++)
6708 if (dpyinfo->font_table[i].name
6709 && font == dpyinfo->font_table[i].font)
6710 break;
6712 xassert (i < dpyinfo->n_fonts);
6715 #endif /* GLYPH_DEBUG != 0 */
6717 /* Set *W to the minimum width, *H to the minimum font height of FONT.
6718 Note: There are (broken) X fonts out there with invalid XFontStruct
6719 min_bounds contents. For example, handa@etl.go.jp reports that
6720 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
6721 have font->min_bounds.width == 0. */
6723 static INLINE void
6724 x_font_min_bounds (font, w, h)
6725 XFontStruct *font;
6726 int *w, *h;
6729 * TODO: Windows does not appear to offer min bound, only
6730 * average and maximum width, and maximum height.
6732 *h = FONT_HEIGHT (font);
6733 *w = FONT_AVG_WIDTH (font);
6737 /* Compute the smallest character width and smallest font height over
6738 all fonts available on frame F. Set the members smallest_char_width
6739 and smallest_font_height in F's x_display_info structure to
6740 the values computed. Value is non-zero if smallest_font_height or
6741 smallest_char_width become smaller than they were before. */
6744 x_compute_min_glyph_bounds (f)
6745 struct frame *f;
6747 int i;
6748 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6749 XFontStruct *font;
6750 int old_width = dpyinfo->smallest_char_width;
6751 int old_height = dpyinfo->smallest_font_height;
6753 dpyinfo->smallest_font_height = 100000;
6754 dpyinfo->smallest_char_width = 100000;
6756 for (i = 0; i < dpyinfo->n_fonts; ++i)
6757 if (dpyinfo->font_table[i].name)
6759 struct font_info *fontp = dpyinfo->font_table + i;
6760 int w, h;
6762 font = (XFontStruct *) fontp->font;
6763 xassert (font != (XFontStruct *) ~0);
6764 x_font_min_bounds (font, &w, &h);
6766 dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h);
6767 dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w);
6770 xassert (dpyinfo->smallest_char_width > 0
6771 && dpyinfo->smallest_font_height > 0);
6773 return (dpyinfo->n_fonts == 1
6774 || dpyinfo->smallest_char_width < old_width
6775 || dpyinfo->smallest_font_height < old_height);
6778 /* The following functions are listed here to help diff stay in step
6779 with xterm.c. See w32fns.c for definitions.
6781 x_load_font (f, fontname, size)
6782 x_query_font (f, fontname)
6783 x_find_ccl_program (fontp)
6787 /***********************************************************************
6788 Initialization
6789 ***********************************************************************/
6791 static int w32_initialized = 0;
6793 void
6794 w32_initialize_display_info (display_name)
6795 Lisp_Object display_name;
6797 struct w32_display_info *dpyinfo = &one_w32_display_info;
6799 bzero (dpyinfo, sizeof (*dpyinfo));
6801 /* Put it on w32_display_name_list. */
6802 w32_display_name_list = Fcons (Fcons (display_name, Qnil),
6803 w32_display_name_list);
6804 dpyinfo->name_list_element = XCAR (w32_display_name_list);
6806 dpyinfo->w32_id_name
6807 = (char *) xmalloc (SCHARS (Vinvocation_name)
6808 + SCHARS (Vsystem_name)
6809 + 2);
6810 sprintf (dpyinfo->w32_id_name, "%s@%s",
6811 SDATA (Vinvocation_name), SDATA (Vsystem_name));
6813 /* Default Console mode values - overridden when running in GUI mode
6814 with values obtained from system metrics. */
6815 dpyinfo->resx = 1;
6816 dpyinfo->resy = 1;
6817 dpyinfo->height_in = 1;
6818 dpyinfo->width_in = 1;
6819 dpyinfo->n_planes = 1;
6820 dpyinfo->n_cbits = 4;
6821 dpyinfo->n_fonts = 0;
6822 dpyinfo->smallest_font_height = 1;
6823 dpyinfo->smallest_char_width = 1;
6825 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
6826 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
6827 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
6828 dpyinfo->mouse_face_window = Qnil;
6829 dpyinfo->mouse_face_overlay = Qnil;
6830 dpyinfo->mouse_face_hidden = 0;
6832 dpyinfo->vertical_scroll_bar_cursor = w32_load_cursor (IDC_ARROW);
6833 /* TODO: dpyinfo->gray */
6837 /* Create an xrdb-style database of resources to supercede registry settings.
6838 The database is just a concatenation of C strings, finished by an additional
6839 \0. The strings are submitted to some basic normalization, so
6841 [ *]option[ *]:[ *]value...
6843 becomes
6845 option:value...
6847 but any whitespace following value is not removed. */
6849 static char *
6850 w32_make_rdb (xrm_option)
6851 char *xrm_option;
6853 char *buffer = xmalloc (strlen (xrm_option) + 2);
6854 char *current = buffer;
6855 char ch;
6856 int in_option = 1;
6857 int before_value = 0;
6859 do {
6860 ch = *xrm_option++;
6862 if (ch == '\n')
6864 *current++ = '\0';
6865 in_option = 1;
6866 before_value = 0;
6868 else if (ch != ' ')
6870 *current++ = ch;
6871 if (in_option && (ch == ':'))
6873 in_option = 0;
6874 before_value = 1;
6876 else if (before_value)
6878 before_value = 0;
6881 else if (!(in_option || before_value))
6883 *current++ = ch;
6885 } while (ch);
6887 *current = '\0';
6889 return buffer;
6892 void
6893 x_flush (struct frame * f)
6894 { /* Nothing to do */ }
6897 extern frame_parm_handler w32_frame_parm_handlers[];
6899 static struct redisplay_interface w32_redisplay_interface =
6901 w32_frame_parm_handlers,
6902 x_produce_glyphs,
6903 x_write_glyphs,
6904 x_insert_glyphs,
6905 x_clear_end_of_line,
6906 x_scroll_run,
6907 x_after_update_window_line,
6908 x_update_window_begin,
6909 x_update_window_end,
6910 x_cursor_to,
6911 x_flush,
6912 0, /* flush_display_optional */
6913 x_clear_window_mouse_face,
6914 w32_get_glyph_overhangs,
6915 x_fix_overlapping_area,
6916 w32_draw_fringe_bitmap,
6917 w32_define_fringe_bitmap,
6918 w32_destroy_fringe_bitmap,
6919 w32_per_char_metric,
6920 w32_encode_char,
6921 w32_compute_glyph_string_overhangs,
6922 x_draw_glyph_string,
6923 w32_define_frame_cursor,
6924 w32_clear_frame_area,
6925 w32_draw_window_cursor,
6926 w32_draw_vertical_window_border,
6927 w32_shift_glyphs_for_insert
6930 static void x_delete_terminal (struct terminal *term);
6932 static struct terminal *
6933 w32_create_terminal (struct w32_display_info *dpyinfo)
6935 struct terminal *terminal;
6937 terminal = create_terminal ();
6939 terminal->type = output_w32;
6940 terminal->display_info.w32 = dpyinfo;
6941 dpyinfo->terminal = terminal;
6943 /* MSVC does not type K&R functions with no arguments correctly, and
6944 so we must explicitly cast them. */
6945 terminal->clear_frame_hook = x_clear_frame;
6946 terminal->ins_del_lines_hook = x_ins_del_lines;
6947 terminal->delete_glyphs_hook = x_delete_glyphs;
6948 terminal->ring_bell_hook = w32_ring_bell;
6949 terminal->reset_terminal_modes_hook = w32_reset_terminal_modes;
6950 terminal->set_terminal_modes_hook = w32_set_terminal_modes;
6951 terminal->update_begin_hook = x_update_begin;
6952 terminal->update_end_hook = x_update_end;
6953 terminal->set_terminal_window_hook = w32_set_terminal_window;
6954 terminal->read_socket_hook = w32_read_socket;
6955 terminal->frame_up_to_date_hook = w32_frame_up_to_date;
6956 terminal->mouse_position_hook = w32_mouse_position;
6957 terminal->frame_rehighlight_hook = w32_frame_rehighlight;
6958 terminal->frame_raise_lower_hook = w32_frame_raise_lower;
6959 // terminal->fullscreen_hook = XTfullscreen_hook;
6960 terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6961 terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6962 terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6963 terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
6965 terminal->delete_frame_hook = x_destroy_window;
6966 terminal->delete_terminal_hook = x_delete_terminal;
6968 terminal->rif = &w32_redisplay_interface;
6969 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
6970 terminal->char_ins_del_ok = 1;
6971 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
6972 terminal->fast_clear_end_of_line = 1; /* X does this well. */
6973 terminal->memory_below_frame = 0; /* We don't remember what scrolls
6974 off the bottom. */
6976 #ifdef MULTI_KBOARD
6977 /* We don't yet support separate terminals on W32, so don't try to share
6978 keyboards between virtual terminals that are on the same physical
6979 terminal like X does. */
6980 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
6981 init_kboard (terminal->kboard);
6982 terminal->kboard->Vwindow_system = intern ("w32");
6983 terminal->kboard->next_kboard = all_kboards;
6984 all_kboards = terminal->kboard;
6985 /* Don't let the initial kboard remain current longer than necessary.
6986 That would cause problems if a file loaded on startup tries to
6987 prompt in the mini-buffer. */
6988 if (current_kboard == initial_kboard)
6989 current_kboard = terminal->kboard;
6990 terminal->kboard->reference_count++;
6991 #endif
6993 return terminal;
6996 static void
6997 x_delete_terminal (struct terminal *terminal)
6999 struct w32_display_info *dpyinfo = terminal->display_info.w32;
7000 int i;
7002 /* Protect against recursive calls. Fdelete_frame in
7003 delete_terminal calls us back when it deletes our last frame. */
7004 if (!terminal->name)
7005 return;
7007 BLOCK_INPUT;
7008 /* Free the fonts in the font table. */
7009 for (i = 0; i < dpyinfo->n_fonts; i++)
7010 if (dpyinfo->font_table[i].name)
7012 DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont);
7015 x_delete_display (dpyinfo);
7016 UNBLOCK_INPUT;
7019 struct w32_display_info *
7020 w32_term_init (display_name, xrm_option, resource_name)
7021 Lisp_Object display_name;
7022 char *xrm_option;
7023 char *resource_name;
7025 struct w32_display_info *dpyinfo;
7026 struct terminal *terminal;
7027 HDC hdc;
7029 BLOCK_INPUT;
7031 if (!w32_initialized)
7033 w32_initialize ();
7034 w32_initialized = 1;
7037 w32_initialize_display_info (display_name);
7039 dpyinfo = &one_w32_display_info;
7040 terminal = w32_create_terminal (dpyinfo);
7042 /* Set the name of the terminal. */
7043 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
7044 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
7045 terminal->name[SBYTES (display_name)] = 0;
7047 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
7049 /* Put this display on the chain. */
7050 dpyinfo->next = x_display_list;
7051 x_display_list = dpyinfo;
7053 hdc = GetDC (GetDesktopWindow ());
7055 dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
7056 dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
7057 dpyinfo->root_window = GetDesktopWindow ();
7058 dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES);
7059 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
7060 dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX);
7061 dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
7062 dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
7063 dpyinfo->terminal->image_cache = make_image_cache ();
7064 dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
7065 dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
7066 ReleaseDC (GetDesktopWindow (), hdc);
7068 /* initialise palette with white and black */
7070 XColor color;
7071 w32_defined_color (0, "white", &color, 1);
7072 w32_defined_color (0, "black", &color, 1);
7075 /* Add the default keyboard. */
7076 add_keyboard_wait_descriptor (0);
7078 /* Create Fringe Bitmaps and store them for later use.
7080 On W32, bitmaps are all unsigned short, as Windows requires
7081 bitmap data to be Word aligned. For some reason they are
7082 horizontally reflected compared to how they appear on X, so we
7083 need to bitswap and convert to unsigned shorts before creating
7084 the bitmaps. */
7085 w32_init_fringe (terminal->rif);
7087 #ifdef F_SETOWN
7088 fcntl (connection, F_SETOWN, getpid ());
7089 #endif /* ! defined (F_SETOWN) */
7091 #ifdef SIGIO
7092 if (interrupt_input)
7093 init_sigio (connection);
7094 #endif /* ! defined (SIGIO) */
7096 UNBLOCK_INPUT;
7098 return dpyinfo;
7101 /* Get rid of display DPYINFO, assuming all frames are already gone. */
7102 void
7103 x_delete_display (dpyinfo)
7104 struct w32_display_info *dpyinfo;
7106 /* Discard this display from w32_display_name_list and w32_display_list.
7107 We can't use Fdelq because that can quit. */
7108 if (! NILP (w32_display_name_list)
7109 && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element))
7110 w32_display_name_list = XCDR (w32_display_name_list);
7111 else
7113 Lisp_Object tail;
7115 tail = w32_display_name_list;
7116 while (CONSP (tail) && CONSP (XCDR (tail)))
7118 if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element))
7120 XSETCDR (tail, XCDR (XCDR (tail)));
7121 break;
7123 tail = XCDR (tail);
7127 /* free palette table */
7129 struct w32_palette_entry * plist;
7131 plist = dpyinfo->color_list;
7132 while (plist)
7134 struct w32_palette_entry * pentry = plist;
7135 plist = plist->next;
7136 xfree (pentry);
7138 dpyinfo->color_list = NULL;
7139 if (dpyinfo->palette)
7140 DeleteObject(dpyinfo->palette);
7142 xfree (dpyinfo->font_table);
7143 xfree (dpyinfo->w32_id_name);
7145 w32_reset_fringes ();
7148 /* Set up use of W32. */
7150 DWORD WINAPI w32_msg_worker (void * arg);
7152 static void
7153 w32_initialize ()
7155 baud_rate = 19200;
7157 w32_system_caret_hwnd = NULL;
7158 w32_system_caret_height = 0;
7159 w32_system_caret_x = 0;
7160 w32_system_caret_y = 0;
7162 /* Initialize w32_use_visible_system_caret based on whether a screen
7163 reader is in use. */
7164 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0,
7165 &w32_use_visible_system_caret, 0))
7166 w32_use_visible_system_caret = 0;
7168 last_tool_bar_item = -1;
7169 any_help_event_p = 0;
7171 /* Initialize input mode: interrupt_input off, no flow control, allow
7172 8 bit character input, standard quit char. */
7173 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
7175 /* Create the window thread - it will terminate itself or when the app terminates */
7177 init_crit ();
7179 dwMainThreadId = GetCurrentThreadId ();
7180 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
7181 GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS);
7183 /* Wait for thread to start */
7186 MSG msg;
7188 PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE);
7190 hWindowsThread = CreateThread (NULL, 0,
7191 w32_msg_worker,
7192 0, 0, &dwWindowsThreadId);
7194 GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
7197 /* It is desirable that mainThread should have the same notion of
7198 focus window and active window as windowsThread. Unfortunately, the
7199 following call to AttachThreadInput, which should do precisely what
7200 we need, causes major problems when Emacs is linked as a console
7201 program. Unfortunately, we have good reasons for doing that, so
7202 instead we need to send messages to windowsThread to make some API
7203 calls for us (ones that affect, or depend on, the active/focus
7204 window state. */
7205 #ifdef ATTACH_THREADS
7206 AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE);
7207 #endif
7209 /* Dynamically link to optional system components. */
7211 UINT smoothing_type;
7212 BOOL smoothing_enabled;
7214 HANDLE gdi_lib = LoadLibrary ("gdi32.dll");
7216 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
7218 LOAD_PROC (gdi_lib, GetFontUnicodeRanges);
7220 #undef LOAD_PROC
7222 FreeLibrary (gdi_lib);
7224 /* Ensure scrollbar handle is at least 5 pixels. */
7225 vertical_scroll_bar_min_handle = 5;
7227 /* For either kind of scroll bar, take account of the arrows; these
7228 effectively form the border of the main scroll bar range. */
7229 vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border
7230 = GetSystemMetrics (SM_CYVSCROLL);
7232 /* Constants that are not always defined by the system headers
7233 since they only exist on certain versions of Windows. */
7234 #ifndef SPI_GETFONTSMOOTHING
7235 #define SPI_GETFONTSMOOTHING 0x4A
7236 #endif
7237 #ifndef SPI_GETFONTSMOOTHINGTYPE
7238 #define SPI_GETFONTSMOOTHINGTYPE 0x0200A
7239 #endif
7240 #ifndef FE_FONTSMOOTHINGCLEARTYPE
7241 #define FE_FONTSMOOTHINGCLEARTYPE 0x2
7242 #endif
7244 /* Determine if Cleartype is in use. Used to enable a hack in
7245 the char metric calculations which adds extra pixels to
7246 compensate for the "sub-pixels" that are not counted by the
7247 system APIs. */
7248 cleartype_active =
7249 SystemParametersInfo (SPI_GETFONTSMOOTHING, 0, &smoothing_enabled, 0)
7250 && smoothing_enabled
7251 && SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type, 0)
7252 && smoothing_type == FE_FONTSMOOTHINGCLEARTYPE;
7256 void
7257 syms_of_w32term ()
7259 staticpro (&w32_display_name_list);
7260 w32_display_name_list = Qnil;
7262 staticpro (&last_mouse_scroll_bar);
7263 last_mouse_scroll_bar = Qnil;
7265 DEFSYM (Qvendor_specific_keysyms, "vendor-specific-keysyms");
7267 DEFVAR_INT ("w32-num-mouse-buttons",
7268 &w32_num_mouse_buttons,
7269 doc: /* Number of physical mouse buttons. */);
7270 w32_num_mouse_buttons = 2;
7272 DEFVAR_LISP ("w32-swap-mouse-buttons",
7273 &Vw32_swap_mouse_buttons,
7274 doc: /* Swap the mapping of middle and right mouse buttons.
7275 When nil, middle button is mouse-2 and right button is mouse-3. */);
7276 Vw32_swap_mouse_buttons = Qnil;
7278 DEFVAR_LISP ("w32-grab-focus-on-raise",
7279 &Vw32_grab_focus_on_raise,
7280 doc: /* Raised frame grabs input focus.
7281 When t, `raise-frame' grabs input focus as well. This fits well
7282 with the normal Windows click-to-focus policy, but might not be
7283 desirable when using a point-to-focus policy. */);
7284 Vw32_grab_focus_on_raise = Qt;
7286 DEFVAR_LISP ("w32-capslock-is-shiftlock",
7287 &Vw32_capslock_is_shiftlock,
7288 doc: /* Apply CapsLock state to non character input keys.
7289 When nil, CapsLock only affects normal character input keys. */);
7290 Vw32_capslock_is_shiftlock = Qnil;
7292 DEFVAR_LISP ("w32-recognize-altgr",
7293 &Vw32_recognize_altgr,
7294 doc: /* Recognize right-alt and left-ctrl as AltGr.
7295 When nil, the right-alt and left-ctrl key combination is
7296 interpreted normally. */);
7297 Vw32_recognize_altgr = Qt;
7299 DEFVAR_BOOL ("w32-enable-unicode-output",
7300 &w32_enable_unicode_output,
7301 doc: /* Enable the use of Unicode for text output if non-nil.
7302 Unicode output may prevent some third party applications for displaying
7303 Far-East Languages on Windows 95/98 from working properly.
7304 NT uses Unicode internally anyway, so this flag will probably have no
7305 effect on NT machines. */);
7306 w32_enable_unicode_output = 1;
7308 DEFVAR_BOOL ("w32-use-visible-system-caret",
7309 &w32_use_visible_system_caret,
7310 doc: /* Flag to make the system caret visible.
7311 When this is non-nil, Emacs will indicate the position of point by
7312 using the system caret instead of drawing its own cursor. Some screen
7313 reader software does not track the system cursor properly when it is
7314 invisible, and gets confused by Emacs drawing its own cursor, so this
7315 variable is initialized to t when Emacs detects that screen reader
7316 software is running as it starts up.
7318 When this variable is set, other variables affecting the appearance of
7319 the cursor have no effect. */);
7321 w32_use_visible_system_caret = 0;
7323 /* We don't yet support this, but defining this here avoids whining
7324 from cus-start.el and other places, like "M-x set-variable". */
7325 DEFVAR_BOOL ("x-use-underline-position-properties",
7326 &x_use_underline_position_properties,
7327 doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
7328 A value of nil means ignore them. If you encounter fonts with bogus
7329 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7330 to 4.1, set this to nil.
7332 NOTE: Not supported on MS-Windows yet. */);
7333 x_use_underline_position_properties = 0;
7335 DEFVAR_BOOL ("x-underline-at-descent-line",
7336 &x_underline_at_descent_line,
7337 doc: /* *Non-nil means to draw the underline at the same place as the descent line.
7338 A value of nil means to draw the underline according to the value of the
7339 variable `x-use-underline-position-properties', which is usually at the
7340 baseline level. The default value is nil. */);
7341 x_underline_at_descent_line = 0;
7343 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
7344 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
7345 Vx_toolkit_scroll_bars = Qt;
7347 staticpro (&last_mouse_motion_frame);
7348 last_mouse_motion_frame = Qnil;
7351 /* arch-tag: 5fa70624-ab86-499c-8a85-473958ee4646
7352 (do not change this comment) */