(calendar-chinese-from-absolute, calendar-chinese-date-string): Expand
[emacs.git] / src / w32term.c
blob944c0f9fa430d76bae6b042f5c14dd919f3e6e2c
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 /* TODO: Windows does not appear to have a method for
1767 getting this info without getting the ABC widths for each
1768 individual character and working it out manually. */
1772 static void
1773 w32_get_glyph_overhangs (glyph, f, left, right)
1774 struct glyph *glyph;
1775 struct frame *f;
1776 int *left, *right;
1778 HDC hdc = get_frame_dc (f);
1779 /* Convert to unicode! */
1780 x_get_glyph_overhangs (glyph, f, left, right);
1781 release_frame_dc (f, hdc);
1785 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1787 static INLINE void
1788 x_clear_glyph_string_rect (s, x, y, w, h)
1789 struct glyph_string *s;
1790 int x, y, w, h;
1792 int real_x = x;
1793 int real_y = y;
1794 int real_w = w;
1795 int real_h = h;
1796 #if 0
1797 /* Take clipping into account. */
1798 if (s->gc->clip_mask == Rect)
1800 real_x = max (real_x, s->gc->clip_rectangle.left);
1801 real_y = max (real_y, s->gc->clip_rectangle.top);
1802 real_w = min (real_w, s->gc->clip_rectangle.right
1803 - s->gc->clip_rectangle.left);
1804 real_h = min (real_h, s->gc->clip_rectangle.bottom
1805 - s->gc->clip_rectangle.top);
1807 #endif
1808 w32_fill_area (s->f, s->hdc, s->gc->background, real_x, real_y,
1809 real_w, real_h);
1813 /* Draw the background of glyph_string S. If S->background_filled_p
1814 is non-zero don't draw it. FORCE_P non-zero means draw the
1815 background even if it wouldn't be drawn normally. This is used
1816 when a string preceding S draws into the background of S, or S
1817 contains the first component of a composition. */
1819 static void
1820 x_draw_glyph_string_background (s, force_p)
1821 struct glyph_string *s;
1822 int force_p;
1824 /* Nothing to do if background has already been drawn or if it
1825 shouldn't be drawn in the first place. */
1826 if (!s->background_filled_p)
1828 int box_line_width = max (s->face->box_line_width, 0);
1830 #if 0 /* TODO: stipple */
1831 if (s->stippled_p)
1833 /* Fill background with a stipple pattern. */
1834 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
1835 XFillRectangle (s->display, s->window, s->gc, s->x,
1836 s->y + box_line_width,
1837 s->background_width,
1838 s->height - 2 * box_line_width);
1839 XSetFillStyle (s->display, s->gc, FillSolid);
1840 s->background_filled_p = 1;
1842 else
1843 #endif
1844 if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
1845 || s->font_not_found_p
1846 || s->extends_to_end_of_line_p
1847 || s->font->bdf
1848 || cleartype_active
1849 || force_p)
1851 x_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
1852 s->background_width,
1853 s->height - 2 * box_line_width);
1854 s->background_filled_p = 1;
1860 /* Draw the foreground of glyph string S. */
1862 static void
1863 x_draw_glyph_string_foreground (s)
1864 struct glyph_string *s;
1866 int i, x;
1867 HFONT old_font;
1869 /* If first glyph of S has a left box line, start drawing the text
1870 of S to the right of that box line. */
1871 if (s->face->box != FACE_NO_BOX
1872 && s->first_glyph->left_box_line_p)
1873 x = s->x + eabs (s->face->box_line_width);
1874 else
1875 x = s->x;
1877 if (s->for_overlaps || (s->background_filled_p && s->hl != DRAW_CURSOR)
1878 || cleartype_active)
1879 SetBkMode (s->hdc, TRANSPARENT);
1880 else
1881 SetBkMode (s->hdc, OPAQUE);
1883 SetTextColor (s->hdc, s->gc->foreground);
1884 SetBkColor (s->hdc, s->gc->background);
1885 SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
1887 if (s->font && s->font->hfont)
1888 old_font = SelectObject (s->hdc, s->font->hfont);
1890 /* Draw characters of S as rectangles if S's font could not be
1891 loaded. */
1892 if (s->font_not_found_p)
1894 for (i = 0; i < s->nchars; ++i)
1896 struct glyph *g = s->first_glyph + i;
1898 w32_draw_rectangle (s->hdc, s->gc, x, s->y, g->pixel_width - 1,
1899 s->height - 1);
1900 x += g->pixel_width;
1903 #ifdef USE_FONT_BACKEND
1904 else if (enable_font_backend)
1906 int boff = s->font_info->baseline_offset;
1907 struct font *font = (struct font *) s->font_info;
1908 int y;
1910 if (s->font_info->vertical_centering)
1911 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
1913 y = s->ybase - boff;
1914 if (s->for_overlaps
1915 || (s->background_filled_p && s->hl != DRAW_CURSOR))
1916 font->driver->draw (s, 0, s->nchars, x, y, 0);
1917 else
1918 font->driver->draw (s, 0, s->nchars, x, y, 1);
1919 if (s->face->overstrike)
1920 font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
1922 #endif /* USE_FONT_BACKEND */
1923 else
1925 char *char1b = (char *) s->char2b;
1926 int boff = s->font_info->baseline_offset;
1928 if (s->font_info->vertical_centering)
1929 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
1931 /* If we can use 8-bit functions, condense S->char2b. */
1932 if (!s->two_byte_p)
1933 for (i = 0; i < s->nchars; ++i)
1934 char1b[i] = XCHAR2B_BYTE2 (&s->char2b[i]);
1936 /* Draw text with TextOut and friends. */
1937 w32_text_out (s, x, s->ybase - boff, s->char2b, s->nchars);
1939 if (s->face->overstrike)
1941 /* For overstriking (to simulate bold-face), draw the
1942 characters again shifted to the right by one pixel. */
1943 int old_BkMode = SetBkMode (s->hdc, TRANSPARENT);
1944 w32_text_out (s, x + 1, s->ybase - boff, s->char2b, s->nchars);
1945 if (old_BkMode && old_BkMode != TRANSPARENT)
1946 SetBkMode (s->hdc, old_BkMode);
1949 if (s->font && s->font->hfont)
1950 SelectObject (s->hdc, old_font);
1953 /* Draw the foreground of composite glyph string S. */
1955 static void
1956 x_draw_composite_glyph_string_foreground (s)
1957 struct glyph_string *s;
1959 int i, j, x;
1960 HFONT old_font;
1962 /* If first glyph of S has a left box line, start drawing the text
1963 of S to the right of that box line. */
1964 if (s->face && s->face->box != FACE_NO_BOX
1965 && s->first_glyph->left_box_line_p)
1966 x = s->x + eabs (s->face->box_line_width);
1967 else
1968 x = s->x;
1970 /* S is a glyph string for a composition. S->gidx is the index of
1971 the first character drawn for glyphs of this composition.
1972 S->gidx == 0 means we are drawing the very first character of
1973 this composition. */
1975 SetTextColor (s->hdc, s->gc->foreground);
1976 SetBkColor (s->hdc, s->gc->background);
1977 SetBkMode (s->hdc, TRANSPARENT);
1978 SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
1980 if (s->font && s->font->hfont)
1981 old_font = SelectObject (s->hdc, s->font->hfont);
1983 /* Draw a rectangle for the composition if the font for the very
1984 first character of the composition could not be loaded. */
1985 if (s->font_not_found_p)
1987 if (s->gidx == 0)
1988 w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1,
1989 s->height - 1);
1991 #ifdef USE_FONT_BACKEND
1992 else if (enable_font_backend)
1994 struct font *font = (struct font *) s->font_info;
1995 int y = s->ybase;
1996 int width = 0;
1998 if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING)
2000 Lisp_Object gstring = AREF (XHASH_TABLE (composition_hash_table)
2001 ->key_and_value,
2002 s->cmp->hash_index * 2);
2003 int from;
2005 for (i = from = 0; i < s->nchars; i++)
2007 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
2008 Lisp_Object adjustment = LGLYPH_ADJUSTMENT (g);
2009 int xoff, yoff, wadjust;
2011 if (! VECTORP (adjustment))
2013 width += LGLYPH_WIDTH (g);
2014 continue;
2016 if (from < i)
2018 font->driver->draw (s, from, i, x, y, 0);
2019 x += width;
2021 xoff = XINT (AREF (adjustment, 0));
2022 yoff = XINT (AREF (adjustment, 1));
2023 wadjust = XINT (AREF (adjustment, 2));
2025 font->driver->draw (s, i, i + 1, x + xoff, y + yoff, 0);
2026 x += wadjust;
2027 from = i + 1;
2028 width = 0;
2030 if (from < i)
2031 font->driver->draw (s, from, i, x, y, 0);
2033 else
2035 for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
2036 if (COMPOSITION_GLYPH (s->cmp, j) != '\t')
2038 int xx = x + s->cmp->offsets[j * 2];
2039 int yy = y - s->cmp->offsets[j * 2 + 1];
2041 font->driver->draw (s, j, j + 1, xx, yy, 0);
2042 if (s->face->overstrike)
2043 font->driver->draw (s, j, j + 1, xx + 1, yy, 0);
2047 #endif /* USE_FONT_BACKEND */
2048 else
2050 for (i = 0, j = s->gidx; i < s->nchars; i++, j++)
2051 if (s->face)
2053 w32_text_out (s, x + s->cmp->offsets[j * 2],
2054 s->ybase - s->cmp->offsets[j * 2 + 1],
2055 s->char2b + j, 1);
2056 if (s->face->overstrike)
2057 w32_text_out (s, x + s->cmp->offsets[j * 2] + 1,
2058 s->ybase - s->cmp->offsets[j + 1],
2059 s->char2b + j, 1);
2063 if (s->font && s->font->hfont)
2064 SelectObject (s->hdc, old_font);
2068 /* Brightness beyond which a color won't have its highlight brightness
2069 boosted.
2071 Nominally, highlight colors for `3d' faces are calculated by
2072 brightening an object's color by a constant scale factor, but this
2073 doesn't yield good results for dark colors, so for colors who's
2074 brightness is less than this value (on a scale of 0-255) have to
2075 use an additional additive factor.
2077 The value here is set so that the default menu-bar/mode-line color
2078 (grey75) will not have its highlights changed at all. */
2079 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
2082 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
2083 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2084 If this produces the same color as COLOR, try a color where all RGB
2085 values have DELTA added. Return the allocated color in *COLOR.
2086 DISPLAY is the X display, CMAP is the colormap to operate on.
2087 Value is non-zero if successful. */
2089 static int
2090 w32_alloc_lighter_color (f, color, factor, delta)
2091 struct frame *f;
2092 COLORREF *color;
2093 double factor;
2094 int delta;
2096 COLORREF new;
2097 long bright;
2099 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
2100 delta /= 256;
2102 /* Change RGB values by specified FACTOR. Avoid overflow! */
2103 xassert (factor >= 0);
2104 new = PALETTERGB (min (0xff, factor * GetRValue (*color)),
2105 min (0xff, factor * GetGValue (*color)),
2106 min (0xff, factor * GetBValue (*color)));
2108 /* Calculate brightness of COLOR. */
2109 bright = (2 * GetRValue (*color) + 3 * GetGValue (*color)
2110 + GetBValue (*color)) / 6;
2112 /* We only boost colors that are darker than
2113 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2114 if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT)
2115 /* Make an additive adjustment to NEW, because it's dark enough so
2116 that scaling by FACTOR alone isn't enough. */
2118 /* How far below the limit this color is (0 - 1, 1 being darker). */
2119 double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT;
2120 /* The additive adjustment. */
2121 int min_delta = delta * dimness * factor / 2;
2123 if (factor < 1)
2124 new = PALETTERGB (max (0, min (0xff, min_delta - GetRValue (*color))),
2125 max (0, min (0xff, min_delta - GetGValue (*color))),
2126 max (0, min (0xff, min_delta - GetBValue (*color))));
2127 else
2128 new = PALETTERGB (max (0, min (0xff, min_delta + GetRValue (*color))),
2129 max (0, min (0xff, min_delta + GetGValue (*color))),
2130 max (0, min (0xff, min_delta + GetBValue (*color))));
2133 if (new == *color)
2134 new = PALETTERGB (max (0, min (0xff, delta + GetRValue (*color))),
2135 max (0, min (0xff, delta + GetGValue (*color))),
2136 max (0, min (0xff, delta + GetBValue (*color))));
2138 /* TODO: Map to palette and retry with delta if same? */
2139 /* TODO: Free colors (if using palette)? */
2141 if (new == *color)
2142 return 0;
2144 *color = new;
2146 return 1;
2150 /* Set up the foreground color for drawing relief lines of glyph
2151 string S. RELIEF is a pointer to a struct relief containing the GC
2152 with which lines will be drawn. Use a color that is FACTOR or
2153 DELTA lighter or darker than the relief's background which is found
2154 in S->f->output_data.x->relief_background. If such a color cannot
2155 be allocated, use DEFAULT_PIXEL, instead. */
2157 static void
2158 w32_setup_relief_color (f, relief, factor, delta, default_pixel)
2159 struct frame *f;
2160 struct relief *relief;
2161 double factor;
2162 int delta;
2163 COLORREF default_pixel;
2165 XGCValues xgcv;
2166 struct w32_output *di = f->output_data.w32;
2167 unsigned long mask = GCForeground;
2168 COLORREF pixel;
2169 COLORREF background = di->relief_background;
2170 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
2172 /* TODO: Free colors (if using palette)? */
2174 /* Allocate new color. */
2175 xgcv.foreground = default_pixel;
2176 pixel = background;
2177 if (w32_alloc_lighter_color (f, &pixel, factor, delta))
2179 relief->allocated_p = 1;
2180 xgcv.foreground = relief->pixel = pixel;
2183 if (relief->gc == 0)
2185 #if 0 /* TODO: stipple */
2186 xgcv.stipple = dpyinfo->gray;
2187 mask |= GCStipple;
2188 #endif
2189 relief->gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, &xgcv);
2191 else
2192 XChangeGC (NULL, relief->gc, mask, &xgcv);
2196 /* Set up colors for the relief lines around glyph string S. */
2198 static void
2199 x_setup_relief_colors (s)
2200 struct glyph_string *s;
2202 struct w32_output *di = s->f->output_data.w32;
2203 COLORREF color;
2205 if (s->face->use_box_color_for_shadows_p)
2206 color = s->face->box_color;
2207 else if (s->first_glyph->type == IMAGE_GLYPH
2208 && s->img->pixmap
2209 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2210 color = IMAGE_BACKGROUND (s->img, s->f, 0);
2211 else
2212 color = s->gc->background;
2214 if (di->white_relief.gc == 0
2215 || color != di->relief_background)
2217 di->relief_background = color;
2218 w32_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000,
2219 WHITE_PIX_DEFAULT (s->f));
2220 w32_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000,
2221 BLACK_PIX_DEFAULT (s->f));
2226 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2227 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2228 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2229 relief. LEFT_P non-zero means draw a relief on the left side of
2230 the rectangle. RIGHT_P non-zero means draw a relief on the right
2231 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2232 when drawing. */
2234 static void
2235 w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
2236 raised_p, top_p, bot_p, left_p, right_p, clip_rect)
2237 struct frame *f;
2238 int left_x, top_y, right_x, bottom_y, width;
2239 int top_p, bot_p, left_p, right_p, raised_p;
2240 RECT *clip_rect;
2242 int i;
2243 XGCValues gc;
2244 HDC hdc = get_frame_dc (f);
2246 if (raised_p)
2247 gc.foreground = f->output_data.w32->white_relief.gc->foreground;
2248 else
2249 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
2251 w32_set_clip_rectangle (hdc, clip_rect);
2253 /* Top. */
2254 if (top_p)
2255 for (i = 0; i < width; ++i)
2256 w32_fill_area (f, hdc, gc.foreground,
2257 left_x + i * left_p, top_y + i,
2258 right_x - left_x - i * (left_p + right_p ) + 1, 1);
2260 /* Left. */
2261 if (left_p)
2262 for (i = 0; i < width; ++i)
2263 w32_fill_area (f, hdc, gc.foreground,
2264 left_x + i, top_y + i, 1,
2265 bottom_y - top_y - 2 * i + 1);
2267 if (raised_p)
2268 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
2269 else
2270 gc.foreground = f->output_data.w32->white_relief.gc->foreground;
2272 /* Bottom. */
2273 if (bot_p)
2274 for (i = 0; i < width; ++i)
2275 w32_fill_area (f, hdc, gc.foreground,
2276 left_x + i * left_p, bottom_y - i,
2277 right_x - left_x - i * (left_p + right_p) + 1, 1);
2279 /* Right. */
2280 if (right_p)
2281 for (i = 0; i < width; ++i)
2282 w32_fill_area (f, hdc, gc.foreground,
2283 right_x - i, top_y + i + 1, 1,
2284 bottom_y - top_y - 2 * i - 1);
2286 w32_set_clip_rectangle (hdc, NULL);
2288 release_frame_dc (f, hdc);
2292 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2293 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2294 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2295 left side of the rectangle. RIGHT_P non-zero means draw a line
2296 on the right side of the rectangle. CLIP_RECT is the clipping
2297 rectangle to use when drawing. */
2299 static void
2300 w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
2301 left_p, right_p, clip_rect)
2302 struct glyph_string *s;
2303 int left_x, top_y, right_x, bottom_y, width, left_p, right_p;
2304 RECT *clip_rect;
2306 w32_set_clip_rectangle (s->hdc, clip_rect);
2308 /* Top. */
2309 w32_fill_area (s->f, s->hdc, s->face->box_color,
2310 left_x, top_y, right_x - left_x + 1, width);
2312 /* Left. */
2313 if (left_p)
2315 w32_fill_area (s->f, s->hdc, s->face->box_color,
2316 left_x, top_y, width, bottom_y - top_y + 1);
2319 /* Bottom. */
2320 w32_fill_area (s->f, s->hdc, s->face->box_color,
2321 left_x, bottom_y - width + 1, right_x - left_x + 1, width);
2323 /* Right. */
2324 if (right_p)
2326 w32_fill_area (s->f, s->hdc, s->face->box_color,
2327 right_x - width + 1, top_y, width, bottom_y - top_y + 1);
2330 w32_set_clip_rectangle (s->hdc, NULL);
2334 /* Draw a box around glyph string S. */
2336 static void
2337 x_draw_glyph_string_box (s)
2338 struct glyph_string *s;
2340 int width, left_x, right_x, top_y, bottom_y, last_x, raised_p;
2341 int left_p, right_p;
2342 struct glyph *last_glyph;
2343 RECT clip_rect;
2345 last_x = ((s->row->full_width_p && !s->w->pseudo_window_p)
2346 ? WINDOW_RIGHT_EDGE_X (s->w)
2347 : window_box_right (s->w, s->area));
2349 /* The glyph that may have a right box line. */
2350 last_glyph = (s->cmp || s->img
2351 ? s->first_glyph
2352 : s->first_glyph + s->nchars - 1);
2354 width = eabs (s->face->box_line_width);
2355 raised_p = s->face->box == FACE_RAISED_BOX;
2356 left_x = s->x;
2357 right_x = ((s->row->full_width_p && s->extends_to_end_of_line_p
2358 ? last_x - 1
2359 : min (last_x, s->x + s->background_width) - 1));
2360 top_y = s->y;
2361 bottom_y = top_y + s->height - 1;
2363 left_p = (s->first_glyph->left_box_line_p
2364 || (s->hl == DRAW_MOUSE_FACE
2365 && (s->prev == NULL
2366 || s->prev->hl != s->hl)));
2367 right_p = (last_glyph->right_box_line_p
2368 || (s->hl == DRAW_MOUSE_FACE
2369 && (s->next == NULL
2370 || s->next->hl != s->hl)));
2372 get_glyph_string_clip_rect (s, &clip_rect);
2374 if (s->face->box == FACE_SIMPLE_BOX)
2375 w32_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
2376 left_p, right_p, &clip_rect);
2377 else
2379 x_setup_relief_colors (s);
2380 w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y,
2381 width, raised_p, 1, 1, left_p, right_p, &clip_rect);
2386 /* Draw foreground of image glyph string S. */
2388 static void
2389 x_draw_image_foreground (s)
2390 struct glyph_string *s;
2392 int x = s->x;
2393 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2395 /* If first glyph of S has a left box line, start drawing it to the
2396 right of that line. */
2397 if (s->face->box != FACE_NO_BOX
2398 && s->first_glyph->left_box_line_p
2399 && s->slice.x == 0)
2400 x += eabs (s->face->box_line_width);
2402 /* If there is a margin around the image, adjust x- and y-position
2403 by that margin. */
2404 if (s->slice.x == 0)
2405 x += s->img->hmargin;
2406 if (s->slice.y == 0)
2407 y += s->img->vmargin;
2409 SaveDC (s->hdc);
2411 if (s->img->pixmap)
2413 HDC compat_hdc = CreateCompatibleDC (s->hdc);
2414 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2415 HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
2416 HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
2417 SetBkColor (compat_hdc, RGB (255, 255, 255));
2418 SetTextColor (s->hdc, RGB (0, 0, 0));
2419 x_set_glyph_string_clipping (s);
2421 if (s->img->mask)
2423 HDC mask_dc = CreateCompatibleDC (s->hdc);
2424 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
2426 SetTextColor (s->hdc, RGB (255, 255, 255));
2427 SetBkColor (s->hdc, RGB (0, 0, 0));
2429 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2430 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2431 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2432 mask_dc, s->slice.x, s->slice.y, SRCAND);
2433 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2434 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2436 SelectObject (mask_dc, mask_orig_obj);
2437 DeleteDC (mask_dc);
2439 else
2441 SetTextColor (s->hdc, s->gc->foreground);
2442 SetBkColor (s->hdc, s->gc->background);
2444 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2445 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2447 /* When the image has a mask, we can expect that at
2448 least part of a mouse highlight or a block cursor will
2449 be visible. If the image doesn't have a mask, make
2450 a block cursor visible by drawing a rectangle around
2451 the image. I believe it's looking better if we do
2452 nothing here for mouse-face. */
2453 if (s->hl == DRAW_CURSOR)
2455 int r = s->img->relief;
2456 if (r < 0) r = -r;
2457 w32_draw_rectangle (s->hdc, s->gc, x - r, y - r ,
2458 s->slice.width + r*2 - 1,
2459 s->slice.height + r*2 - 1);
2463 w32_set_clip_rectangle (s->hdc, NULL);
2464 SelectObject (s->hdc, orig_brush);
2465 DeleteObject (fg_brush);
2466 SelectObject (compat_hdc, orig_obj);
2467 DeleteDC (compat_hdc);
2469 else
2470 w32_draw_rectangle (s->hdc, s->gc, x, y,
2471 s->slice.width - 1, s->slice.height - 1);
2473 RestoreDC (s->hdc ,-1);
2477 /* Draw a relief around the image glyph string S. */
2479 static void
2480 x_draw_image_relief (s)
2481 struct glyph_string *s;
2483 int x0, y0, x1, y1, thick, raised_p;
2484 RECT r;
2485 int x = s->x;
2486 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2488 /* If first glyph of S has a left box line, start drawing it to the
2489 right of that line. */
2490 if (s->face->box != FACE_NO_BOX
2491 && s->first_glyph->left_box_line_p
2492 && s->slice.x == 0)
2493 x += eabs (s->face->box_line_width);
2495 /* If there is a margin around the image, adjust x- and y-position
2496 by that margin. */
2497 if (s->slice.x == 0)
2498 x += s->img->hmargin;
2499 if (s->slice.y == 0)
2500 y += s->img->vmargin;
2502 if (s->hl == DRAW_IMAGE_SUNKEN
2503 || s->hl == DRAW_IMAGE_RAISED)
2505 thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF;
2506 raised_p = s->hl == DRAW_IMAGE_RAISED;
2508 else
2510 thick = eabs (s->img->relief);
2511 raised_p = s->img->relief > 0;
2514 x0 = x - thick;
2515 y0 = y - thick;
2516 x1 = x + s->slice.width + thick - 1;
2517 y1 = y + s->slice.height + thick - 1;
2519 x_setup_relief_colors (s);
2520 get_glyph_string_clip_rect (s, &r);
2521 w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p,
2522 s->slice.y == 0,
2523 s->slice.y + s->slice.height == s->img->height,
2524 s->slice.x == 0,
2525 s->slice.x + s->slice.width == s->img->width,
2526 &r);
2530 /* Draw the foreground of image glyph string S to PIXMAP. */
2532 static void
2533 w32_draw_image_foreground_1 (s, pixmap)
2534 struct glyph_string *s;
2535 HBITMAP pixmap;
2537 HDC hdc = CreateCompatibleDC (s->hdc);
2538 HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap);
2539 int x = 0;
2540 int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice);
2542 /* If first glyph of S has a left box line, start drawing it to the
2543 right of that line. */
2544 if (s->face->box != FACE_NO_BOX
2545 && s->first_glyph->left_box_line_p
2546 && s->slice.x == 0)
2547 x += eabs (s->face->box_line_width);
2549 /* If there is a margin around the image, adjust x- and y-position
2550 by that margin. */
2551 if (s->slice.x == 0)
2552 x += s->img->hmargin;
2553 if (s->slice.y == 0)
2554 y += s->img->vmargin;
2556 if (s->img->pixmap)
2558 HDC compat_hdc = CreateCompatibleDC (hdc);
2559 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2560 HBRUSH orig_brush = SelectObject (hdc, fg_brush);
2561 HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
2563 if (s->img->mask)
2565 HDC mask_dc = CreateCompatibleDC (hdc);
2566 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
2568 SetTextColor (hdc, RGB (0, 0, 0));
2569 SetBkColor (hdc, RGB (255, 255, 255));
2570 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2571 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2572 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2573 mask_dc, s->slice.x, s->slice.y, SRCAND);
2574 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2575 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2577 SelectObject (mask_dc, mask_orig_obj);
2578 DeleteDC (mask_dc);
2580 else
2582 SetTextColor (hdc, s->gc->foreground);
2583 SetBkColor (hdc, s->gc->background);
2585 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2586 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2588 /* When the image has a mask, we can expect that at
2589 least part of a mouse highlight or a block cursor will
2590 be visible. If the image doesn't have a mask, make
2591 a block cursor visible by drawing a rectangle around
2592 the image. I believe it's looking better if we do
2593 nothing here for mouse-face. */
2594 if (s->hl == DRAW_CURSOR)
2596 int r = s->img->relief;
2597 if (r < 0) r = -r;
2598 w32_draw_rectangle (hdc, s->gc, x - r, y - r,
2599 s->slice.width + r*2 - 1,
2600 s->slice.height + r*2 - 1);
2604 SelectObject (hdc, orig_brush);
2605 DeleteObject (fg_brush);
2606 SelectObject (compat_hdc, orig_obj);
2607 DeleteDC (compat_hdc);
2609 else
2610 w32_draw_rectangle (hdc, s->gc, x, y,
2611 s->slice.width - 1, s->slice.height - 1);
2613 SelectObject (hdc, orig_hdc_obj);
2614 DeleteDC (hdc);
2618 /* Draw part of the background of glyph string S. X, Y, W, and H
2619 give the rectangle to draw. */
2621 static void
2622 x_draw_glyph_string_bg_rect (s, x, y, w, h)
2623 struct glyph_string *s;
2624 int x, y, w, h;
2626 #if 0 /* TODO: stipple */
2627 if (s->stippled_p)
2629 /* Fill background with a stipple pattern. */
2630 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
2631 XFillRectangle (s->display, s->window, s->gc, x, y, w, h);
2632 XSetFillStyle (s->display, s->gc, FillSolid);
2634 else
2635 #endif
2636 x_clear_glyph_string_rect (s, x, y, w, h);
2640 /* Draw image glyph string S.
2642 s->y
2643 s->x +-------------------------
2644 | s->face->box
2646 | +-------------------------
2647 | | s->img->vmargin
2649 | | +-------------------
2650 | | | the image
2654 static void
2655 x_draw_image_glyph_string (s)
2656 struct glyph_string *s;
2658 int x, y;
2659 int box_line_hwidth = eabs (s->face->box_line_width);
2660 int box_line_vwidth = max (s->face->box_line_width, 0);
2661 int height;
2662 HBITMAP pixmap = 0;
2664 height = s->height - 2 * box_line_vwidth;
2666 /* Fill background with face under the image. Do it only if row is
2667 taller than image or if image has a clip mask to reduce
2668 flickering. */
2669 s->stippled_p = s->face->stipple != 0;
2670 if (height > s->slice.height
2671 || s->img->hmargin
2672 || s->img->vmargin
2673 || s->img->mask
2674 || s->img->pixmap == 0
2675 || s->width != s->background_width)
2677 x = s->x;
2678 if (s->first_glyph->left_box_line_p
2679 && s->slice.x == 0)
2680 x += box_line_hwidth;
2682 y = s->y;
2683 if (s->slice.y == 0)
2684 y += box_line_vwidth;
2686 #if 0 /* TODO: figure out if we need to do this on Windows. */
2687 if (s->img->mask)
2689 /* Create a pixmap as large as the glyph string. Fill it
2690 with the background color. Copy the image to it, using
2691 its mask. Copy the temporary pixmap to the display. */
2692 Screen *screen = FRAME_X_SCREEN (s->f);
2693 int depth = DefaultDepthOfScreen (screen);
2695 /* Create a pixmap as large as the glyph string. */
2696 pixmap = XCreatePixmap (s->display, s->window,
2697 s->background_width,
2698 s->height, depth);
2700 /* Don't clip in the following because we're working on the
2701 pixmap. */
2702 XSetClipMask (s->display, s->gc, None);
2704 /* Fill the pixmap with the background color/stipple. */
2705 if (s->stippled_p)
2707 /* Fill background with a stipple pattern. */
2708 XSetFillStyle (s->display, s->gc, FillOpaqueStippled);
2709 XFillRectangle (s->display, pixmap, s->gc,
2710 0, 0, s->background_width, s->height);
2711 XSetFillStyle (s->display, s->gc, FillSolid);
2713 else
2715 XGCValues xgcv;
2716 XGetGCValues (s->display, s->gc, GCForeground | GCBackground,
2717 &xgcv);
2718 XSetForeground (s->display, s->gc, xgcv.background);
2719 XFillRectangle (s->display, pixmap, s->gc,
2720 0, 0, s->background_width, s->height);
2721 XSetForeground (s->display, s->gc, xgcv.foreground);
2724 else
2725 #endif
2726 x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height);
2728 s->background_filled_p = 1;
2731 /* Draw the foreground. */
2732 if (pixmap != 0)
2734 w32_draw_image_foreground_1 (s, pixmap);
2735 x_set_glyph_string_clipping (s);
2737 HDC compat_hdc = CreateCompatibleDC (s->hdc);
2738 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2739 HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
2740 HGDIOBJ orig_obj = SelectObject (compat_hdc, pixmap);
2742 SetTextColor (s->hdc, s->gc->foreground);
2743 SetBkColor (s->hdc, s->gc->background);
2744 BitBlt (s->hdc, s->x, s->y, s->background_width, s->height,
2745 compat_hdc, 0, 0, SRCCOPY);
2747 SelectObject (s->hdc, orig_brush);
2748 DeleteObject (fg_brush);
2749 SelectObject (compat_hdc, orig_obj);
2750 DeleteDC (compat_hdc);
2752 DeleteObject (pixmap);
2753 pixmap = 0;
2755 else
2756 x_draw_image_foreground (s);
2758 /* If we must draw a relief around the image, do it. */
2759 if (s->img->relief
2760 || s->hl == DRAW_IMAGE_RAISED
2761 || s->hl == DRAW_IMAGE_SUNKEN)
2762 x_draw_image_relief (s);
2766 /* Draw stretch glyph string S. */
2768 static void
2769 x_draw_stretch_glyph_string (s)
2770 struct glyph_string *s;
2772 xassert (s->first_glyph->type == STRETCH_GLYPH);
2774 if (s->hl == DRAW_CURSOR
2775 && !x_stretch_cursor_p)
2777 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2778 as wide as the stretch glyph. */
2779 int width, background_width = s->background_width;
2780 int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA);
2782 if (x < left_x)
2784 background_width -= left_x - x;
2785 x = left_x;
2787 width = min (FRAME_COLUMN_WIDTH (s->f), background_width);
2789 /* Draw cursor. */
2790 x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height);
2792 /* Clear rest using the GC of the original non-cursor face. */
2793 if (width < background_width)
2795 XGCValues *gc = s->face->gc;
2796 int y = s->y;
2797 int w = background_width - width, h = s->height;
2798 RECT r;
2799 HDC hdc = s->hdc;
2801 x += width;
2802 if (s->row->mouse_face_p
2803 && cursor_in_mouse_face_p (s->w))
2805 x_set_mouse_face_gc (s);
2806 gc = s->gc;
2808 else
2809 gc = s->face->gc;
2811 get_glyph_string_clip_rect (s, &r);
2812 w32_set_clip_rectangle (hdc, &r);
2814 #if 0 /* TODO: stipple */
2815 if (s->face->stipple)
2817 /* Fill background with a stipple pattern. */
2818 XSetFillStyle (s->display, gc, FillOpaqueStippled);
2819 XFillRectangle (s->display, s->window, gc, x, y, w, h);
2820 XSetFillStyle (s->display, gc, FillSolid);
2822 else
2823 #endif
2825 w32_fill_area (s->f, s->hdc, gc->background, x, y, w, h);
2829 else if (!s->background_filled_p)
2831 int background_width = s->background_width;
2832 int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA);
2834 /* Don't draw into left margin, fringe or scrollbar area
2835 except for header line and mode line. */
2836 if (x < left_x && !s->row->mode_line_p)
2838 background_width -= left_x - x;
2839 x = left_x;
2841 if (background_width > 0)
2842 x_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height);
2845 s->background_filled_p = 1;
2849 /* Draw glyph string S. */
2851 static void
2852 x_draw_glyph_string (s)
2853 struct glyph_string *s;
2855 int relief_drawn_p = 0;
2857 /* If S draws into the background of its successor, draw the
2858 background of the successor first so that S can draw into it.
2859 This makes S->next use XDrawString instead of XDrawImageString. */
2860 if (s->next && s->right_overhang && !s->for_overlaps)
2862 int width;
2863 struct glyph_string *next;
2864 for (width = 0, next = s->next; next;
2865 width += next->width, next = next->next)
2866 if (next->first_glyph->type != IMAGE_GLYPH)
2868 x_set_glyph_string_gc (next);
2869 x_set_glyph_string_clipping (next);
2870 x_draw_glyph_string_background (next, 1);
2871 #ifdef USE_FONT_BACKEND
2872 next->num_clips = 0;
2873 #endif /* USE_FONT_BACKEND */
2877 /* Set up S->gc, set clipping and draw S. */
2878 x_set_glyph_string_gc (s);
2880 /* Draw relief (if any) in advance for char/composition so that the
2881 glyph string can be drawn over it. */
2882 if (!s->for_overlaps
2883 && s->face->box != FACE_NO_BOX
2884 && (s->first_glyph->type == CHAR_GLYPH
2885 || s->first_glyph->type == COMPOSITE_GLYPH))
2888 x_set_glyph_string_clipping (s);
2889 x_draw_glyph_string_background (s, 1);
2890 x_draw_glyph_string_box (s);
2891 x_set_glyph_string_clipping (s);
2892 relief_drawn_p = 1;
2894 else if ((s->prev && s->prev->hl != s->hl && s->left_overhang)
2895 || (s->next && s->next->hl != s->hl && s->right_overhang))
2896 /* We must clip just this glyph. left_overhang part has already
2897 drawn when s->prev was drawn, and right_overhang part will be
2898 drawn later when s->next is drawn. */
2899 x_set_glyph_string_clipping_exactly (s, s);
2900 else
2901 x_set_glyph_string_clipping (s);
2903 switch (s->first_glyph->type)
2905 case IMAGE_GLYPH:
2906 x_draw_image_glyph_string (s);
2907 break;
2909 case STRETCH_GLYPH:
2910 x_draw_stretch_glyph_string (s);
2911 break;
2913 case CHAR_GLYPH:
2914 if (s->for_overlaps)
2915 s->background_filled_p = 1;
2916 else
2917 x_draw_glyph_string_background (s, 0);
2918 x_draw_glyph_string_foreground (s);
2919 break;
2921 case COMPOSITE_GLYPH:
2922 if (s->for_overlaps || s->gidx > 0)
2923 s->background_filled_p = 1;
2924 else
2925 x_draw_glyph_string_background (s, 1);
2926 x_draw_composite_glyph_string_foreground (s);
2927 break;
2929 default:
2930 abort ();
2933 if (!s->for_overlaps)
2935 /* Draw underline. */
2936 if (s->face->underline_p
2937 && (s->font->bdf || !s->font->tm.tmUnderlined))
2939 unsigned long h;
2940 int y;
2941 /* Get the underline thickness. Default is 1 pixel. */
2942 #ifdef USE_FONT_BACKEND
2943 if (enable_font_backend)
2944 /* In the future, we must use information of font. */
2945 h = 1;
2946 else
2947 #endif /* USE_FONT_BACKEND */
2948 h = 1;
2950 #ifdef USE_FONT_BACKEND
2951 if (enable_font_backend)
2953 if (s->face->font)
2954 /* In the future, we must use information of font. */
2955 y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
2956 else
2957 y = s->y + s->height - h;
2959 else
2960 #endif
2962 y = s->y + s->height - h;
2963 /* TODO: Use font information for positioning and
2964 thickness of underline. See OUTLINETEXTMETRIC,
2965 and xterm.c. Note: If you make this work,
2966 don't forget to change the doc string of
2967 x-use-underline_color-position-properties
2968 below. */
2969 #if 0
2970 if (!x_underline_at_descent_line)
2974 #endif
2976 if (s->face->underline_defaulted_p)
2978 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
2979 y, s->background_width, 1);
2981 else
2983 w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x,
2984 y, s->background_width, 1);
2987 /* Draw overline. */
2988 if (s->face->overline_p)
2990 unsigned long dy = 0, h = 1;
2992 if (s->face->overline_color_defaulted_p)
2994 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
2995 s->y + dy, s->background_width, h);
2997 else
2999 w32_fill_area (s->f, s->hdc, s->face->overline_color, s->x,
3000 s->y + dy, s->background_width, h);
3004 /* Draw strike-through. */
3005 if (s->face->strike_through_p
3006 && (s->font->bdf || !s->font->tm.tmStruckOut))
3008 unsigned long h = 1;
3009 unsigned long dy = (s->height - h) / 2;
3011 if (s->face->strike_through_color_defaulted_p)
3013 w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x, s->y + dy,
3014 s->width, h);
3016 else
3018 w32_fill_area (s->f, s->hdc, s->face->strike_through_color, s->x,
3019 s->y + dy, s->width, h);
3023 /* Draw relief if not yet drawn. */
3024 if (!relief_drawn_p && s->face->box != FACE_NO_BOX)
3025 x_draw_glyph_string_box (s);
3027 if (s->prev)
3029 struct glyph_string *prev;
3031 for (prev = s->prev; prev; prev = prev->prev)
3032 if (prev->hl != s->hl
3033 && prev->x + prev->width + prev->right_overhang > s->x)
3035 /* As prev was drawn while clipped to its own area, we
3036 must draw the right_overhang part using s->hl now. */
3037 enum draw_glyphs_face save = prev->hl;
3039 prev->hl = s->hl;
3040 x_set_glyph_string_gc (prev);
3041 x_set_glyph_string_clipping_exactly (s, prev);
3042 if (prev->first_glyph->type == CHAR_GLYPH)
3043 x_draw_glyph_string_foreground (prev);
3044 else
3045 x_draw_composite_glyph_string_foreground (prev);
3046 w32_set_clip_rectangle (prev->hdc, NULL);
3047 prev->hl = save;
3048 #ifdef USE_FONT_BACKEND
3049 prev->num_clips = 0;
3050 #endif /* USE_FONT_BACKEND */
3054 if (s->next)
3056 struct glyph_string *next;
3058 for (next = s->next; next; next = next->next)
3059 if (next->hl != s->hl
3060 && next->x - next->left_overhang < s->x + s->width)
3062 /* As next will be drawn while clipped to its own area,
3063 we must draw the left_overhang part using s->hl now. */
3064 enum draw_glyphs_face save = next->hl;
3066 next->hl = s->hl;
3067 x_set_glyph_string_gc (next);
3068 x_set_glyph_string_clipping_exactly (s, next);
3069 if (next->first_glyph->type == CHAR_GLYPH)
3070 x_draw_glyph_string_foreground (next);
3071 else
3072 x_draw_composite_glyph_string_foreground (next);
3073 w32_set_clip_rectangle (next->hdc, NULL);
3074 next->hl = save;
3075 #ifdef USE_FONT_BACKEND
3076 next->num_clips = 0;
3077 #endif /* USE_FONT_BACKEND */
3082 /* Reset clipping. */
3083 w32_set_clip_rectangle (s->hdc, NULL);
3084 #ifdef USE_FONT_BACKEND
3085 s->num_clips = 0;
3086 #endif /* USE_FONT_BACKEND */
3090 /* Shift display to make room for inserted glyphs. */
3092 void
3093 w32_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
3094 struct frame *f;
3095 int x, y, width, height, shift_by;
3097 HDC hdc;
3099 hdc = get_frame_dc (f);
3100 BitBlt (hdc, x + shift_by, y, width, height,
3101 hdc, x, y, SRCCOPY);
3103 release_frame_dc (f, hdc);
3107 /* Delete N glyphs at the nominal cursor position. Not implemented
3108 for X frames. */
3110 static void
3111 x_delete_glyphs (f, n)
3112 struct frame *f;
3113 register int n;
3115 if (! FRAME_W32_P (f))
3116 return;
3118 abort ();
3122 /* Clear entire frame. If updating_frame is non-null, clear that
3123 frame. Otherwise clear the selected frame. */
3125 static void
3126 x_clear_frame (struct frame *f)
3128 if (! FRAME_W32_P (f))
3129 return;
3131 /* Clearing the frame will erase any cursor, so mark them all as no
3132 longer visible. */
3133 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
3134 output_cursor.hpos = output_cursor.vpos = 0;
3135 output_cursor.x = -1;
3137 /* We don't set the output cursor here because there will always
3138 follow an explicit cursor_to. */
3139 BLOCK_INPUT;
3141 w32_clear_window (f);
3143 /* We have to clear the scroll bars, too. If we have changed
3144 colors or something like that, then they should be notified. */
3145 x_scroll_bar_clear (f);
3147 UNBLOCK_INPUT;
3151 /* Make audible bell. */
3153 static void
3154 w32_ring_bell (struct frame *f)
3156 BLOCK_INPUT;
3158 if (FRAME_W32_P (f) && visible_bell)
3160 int i;
3161 HWND hwnd = FRAME_W32_WINDOW (f);
3163 for (i = 0; i < 5; i++)
3165 FlashWindow (hwnd, TRUE);
3166 Sleep (10);
3168 FlashWindow (hwnd, FALSE);
3170 else
3171 w32_sys_ring_bell (f);
3173 UNBLOCK_INPUT;
3177 /* Specify how many text lines, from the top of the window,
3178 should be affected by insert-lines and delete-lines operations.
3179 This, and those operations, are used only within an update
3180 that is bounded by calls to x_update_begin and x_update_end. */
3182 static void
3183 w32_set_terminal_window (n)
3184 register int n;
3186 /* This function intentionally left blank. */
3190 /***********************************************************************
3191 Line Dance
3192 ***********************************************************************/
3194 /* Perform an insert-lines or delete-lines operation, inserting N
3195 lines or deleting -N lines at vertical position VPOS. */
3197 static void
3198 x_ins_del_lines (f, vpos, n)
3199 struct frame *f;
3200 int vpos, n;
3202 if (! FRAME_W32_P (f))
3203 return;
3205 abort ();
3209 /* Scroll part of the display as described by RUN. */
3211 static void
3212 x_scroll_run (w, run)
3213 struct window *w;
3214 struct run *run;
3216 struct frame *f = XFRAME (w->frame);
3217 int x, y, width, height, from_y, to_y, bottom_y;
3218 HWND hwnd = FRAME_W32_WINDOW (f);
3219 HRGN expect_dirty;
3221 /* Get frame-relative bounding box of the text display area of W,
3222 without mode lines. Include in this box the left and right
3223 fringes of W. */
3224 window_box (w, -1, &x, &y, &width, &height);
3226 from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y);
3227 to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y);
3228 bottom_y = y + height;
3230 if (to_y < from_y)
3232 /* Scrolling up. Make sure we don't copy part of the mode
3233 line at the bottom. */
3234 if (from_y + run->height > bottom_y)
3235 height = bottom_y - from_y;
3236 else
3237 height = run->height;
3238 expect_dirty = CreateRectRgn (x, y + height, x + width, bottom_y);
3240 else
3242 /* Scolling down. Make sure we don't copy over the mode line.
3243 at the bottom. */
3244 if (to_y + run->height > bottom_y)
3245 height = bottom_y - to_y;
3246 else
3247 height = run->height;
3248 expect_dirty = CreateRectRgn (x, y, x + width, to_y);
3251 BLOCK_INPUT;
3253 /* Cursor off. Will be switched on again in x_update_window_end. */
3254 updated_window = w;
3255 x_clear_cursor (w);
3258 RECT from;
3259 RECT to;
3260 HRGN dirty = CreateRectRgn (0, 0, 0, 0);
3261 HRGN combined = CreateRectRgn (0, 0, 0, 0);
3263 from.left = to.left = x;
3264 from.right = to.right = x + width;
3265 from.top = from_y;
3266 from.bottom = from_y + height;
3267 to.top = y;
3268 to.bottom = bottom_y;
3270 ScrollWindowEx (hwnd, 0, to_y - from_y, &from, &to, dirty,
3271 NULL, SW_INVALIDATE);
3273 /* Combine this with what we expect to be dirty. This covers the
3274 case where not all of the region we expect is actually dirty. */
3275 CombineRgn (combined, dirty, expect_dirty, RGN_OR);
3277 /* If the dirty region is not what we expected, redraw the entire frame. */
3278 if (!EqualRgn (combined, expect_dirty))
3279 SET_FRAME_GARBAGED (f);
3281 DeleteObject (dirty);
3282 DeleteObject (combined);
3285 UNBLOCK_INPUT;
3286 DeleteObject (expect_dirty);
3291 /***********************************************************************
3292 Exposure Events
3293 ***********************************************************************/
3295 static void
3296 frame_highlight (f)
3297 struct frame *f;
3299 x_update_cursor (f, 1);
3302 static void
3303 frame_unhighlight (f)
3304 struct frame *f;
3306 x_update_cursor (f, 1);
3309 /* The focus has changed. Update the frames as necessary to reflect
3310 the new situation. Note that we can't change the selected frame
3311 here, because the Lisp code we are interrupting might become confused.
3312 Each event gets marked with the frame in which it occurred, so the
3313 Lisp code can tell when the switch took place by examining the events. */
3315 static void
3316 x_new_focus_frame (dpyinfo, frame)
3317 struct w32_display_info *dpyinfo;
3318 struct frame *frame;
3320 struct frame *old_focus = dpyinfo->w32_focus_frame;
3322 if (frame != dpyinfo->w32_focus_frame)
3324 /* Set this before calling other routines, so that they see
3325 the correct value of w32_focus_frame. */
3326 dpyinfo->w32_focus_frame = frame;
3328 if (old_focus && old_focus->auto_lower)
3329 x_lower_frame (old_focus);
3331 if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise)
3332 pending_autoraise_frame = dpyinfo->w32_focus_frame;
3333 else
3334 pending_autoraise_frame = 0;
3337 x_frame_rehighlight (dpyinfo);
3341 /* Handle FocusIn and FocusOut state changes for FRAME.
3342 If FRAME has focus and there exists more than one frame, puts
3343 a FOCUS_IN_EVENT into *BUFP. */
3345 static void
3346 x_focus_changed (type, state, dpyinfo, frame, bufp)
3347 int type;
3348 int state;
3349 struct w32_display_info *dpyinfo;
3350 struct frame *frame;
3351 struct input_event *bufp;
3353 if (type == WM_SETFOCUS)
3355 if (dpyinfo->w32_focus_event_frame != frame)
3357 x_new_focus_frame (dpyinfo, frame);
3358 dpyinfo->w32_focus_event_frame = frame;
3360 /* Don't stop displaying the initial startup message
3361 for a switch-frame event we don't need. */
3362 if (NILP (Vterminal_frame)
3363 && CONSP (Vframe_list)
3364 && !NILP (XCDR (Vframe_list)))
3366 bufp->kind = FOCUS_IN_EVENT;
3367 XSETFRAME (bufp->frame_or_window, frame);
3371 frame->output_data.x->focus_state |= state;
3373 /* TODO: IME focus? */
3375 else if (type == WM_KILLFOCUS)
3377 frame->output_data.x->focus_state &= ~state;
3379 if (dpyinfo->w32_focus_event_frame == frame)
3381 dpyinfo->w32_focus_event_frame = 0;
3382 x_new_focus_frame (dpyinfo, 0);
3385 /* TODO: IME focus? */
3390 /* The focus may have changed. Figure out if it is a real focus change,
3391 by checking both FocusIn/Out and Enter/LeaveNotify events.
3393 Returns FOCUS_IN_EVENT event in *BUFP. */
3395 static void
3396 w32_detect_focus_change (dpyinfo, event, bufp)
3397 struct w32_display_info *dpyinfo;
3398 W32Msg *event;
3399 struct input_event *bufp;
3401 struct frame *frame;
3403 frame = x_any_window_to_frame (dpyinfo, event->msg.hwnd);
3404 if (! frame)
3405 return;
3407 /* On w32, this is only called from focus events, so no switch needed. */
3408 x_focus_changed (event->msg.message,
3409 (event->msg.message == WM_KILLFOCUS ?
3410 FOCUS_IMPLICIT : FOCUS_EXPLICIT),
3411 dpyinfo, frame, bufp);
3415 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3417 void
3418 x_mouse_leave (dpyinfo)
3419 struct w32_display_info *dpyinfo;
3421 x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame);
3424 /* The focus has changed, or we have redirected a frame's focus to
3425 another frame (this happens when a frame uses a surrogate
3426 mini-buffer frame). Shift the highlight as appropriate.
3428 The FRAME argument doesn't necessarily have anything to do with which
3429 frame is being highlighted or un-highlighted; we only use it to find
3430 the appropriate X display info. */
3432 static void
3433 w32_frame_rehighlight (frame)
3434 struct frame *frame;
3436 if (! FRAME_W32_P (frame))
3437 return;
3438 x_frame_rehighlight (FRAME_W32_DISPLAY_INFO (frame));
3441 static void
3442 x_frame_rehighlight (dpyinfo)
3443 struct w32_display_info *dpyinfo;
3445 struct frame *old_highlight = dpyinfo->x_highlight_frame;
3447 if (dpyinfo->w32_focus_frame)
3449 dpyinfo->x_highlight_frame
3450 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame)))
3451 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame))
3452 : dpyinfo->w32_focus_frame);
3453 if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame))
3455 FRAME_FOCUS_FRAME (dpyinfo->w32_focus_frame) = Qnil;
3456 dpyinfo->x_highlight_frame = dpyinfo->w32_focus_frame;
3459 else
3460 dpyinfo->x_highlight_frame = 0;
3462 if (dpyinfo->x_highlight_frame != old_highlight)
3464 if (old_highlight)
3465 frame_unhighlight (old_highlight);
3466 if (dpyinfo->x_highlight_frame)
3467 frame_highlight (dpyinfo->x_highlight_frame);
3471 /* Keyboard processing - modifier keys, etc. */
3473 /* Convert a keysym to its name. */
3475 char *
3476 x_get_keysym_name (keysym)
3477 int keysym;
3479 /* Make static so we can always return it */
3480 static char value[100];
3482 BLOCK_INPUT;
3483 GetKeyNameText (keysym, value, 100);
3484 UNBLOCK_INPUT;
3486 return value;
3491 /* Mouse clicks and mouse movement. Rah. */
3493 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
3494 the state in PUP. XBUTTON provides extra information for extended mouse
3495 button messages. Returns FALSE if unable to parse the message. */
3496 BOOL
3497 parse_button (message, xbutton, pbutton, pup)
3498 int message;
3499 int xbutton;
3500 int * pbutton;
3501 int * pup;
3503 int button = 0;
3504 int up = 0;
3506 switch (message)
3508 case WM_LBUTTONDOWN:
3509 button = 0;
3510 up = 0;
3511 break;
3512 case WM_LBUTTONUP:
3513 button = 0;
3514 up = 1;
3515 break;
3516 case WM_MBUTTONDOWN:
3517 if (NILP (Vw32_swap_mouse_buttons))
3518 button = 1;
3519 else
3520 button = 2;
3521 up = 0;
3522 break;
3523 case WM_MBUTTONUP:
3524 if (NILP (Vw32_swap_mouse_buttons))
3525 button = 1;
3526 else
3527 button = 2;
3528 up = 1;
3529 break;
3530 case WM_RBUTTONDOWN:
3531 if (NILP (Vw32_swap_mouse_buttons))
3532 button = 2;
3533 else
3534 button = 1;
3535 up = 0;
3536 break;
3537 case WM_RBUTTONUP:
3538 if (NILP (Vw32_swap_mouse_buttons))
3539 button = 2;
3540 else
3541 button = 1;
3542 up = 1;
3543 break;
3544 case WM_XBUTTONDOWN:
3545 button = xbutton + 2;
3546 up = 0;
3547 break;
3548 case WM_XBUTTONUP:
3549 button = xbutton + 2;
3550 up = 1;
3551 break;
3552 default:
3553 return (FALSE);
3556 if (pup) *pup = up;
3557 if (pbutton) *pbutton = button;
3559 return (TRUE);
3563 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3565 If the event is a button press, then note that we have grabbed
3566 the mouse. */
3568 static Lisp_Object
3569 construct_mouse_click (result, msg, f)
3570 struct input_event *result;
3571 W32Msg *msg;
3572 struct frame *f;
3574 int button;
3575 int up;
3577 parse_button (msg->msg.message, HIWORD (msg->msg.wParam),
3578 &button, &up);
3580 /* Make the event type NO_EVENT; we'll change that when we decide
3581 otherwise. */
3582 result->kind = MOUSE_CLICK_EVENT;
3583 result->code = button;
3584 result->timestamp = msg->msg.time;
3585 result->modifiers = (msg->dwModifiers
3586 | (up
3587 ? up_modifier
3588 : down_modifier));
3590 XSETINT (result->x, LOWORD (msg->msg.lParam));
3591 XSETINT (result->y, HIWORD (msg->msg.lParam));
3592 XSETFRAME (result->frame_or_window, f);
3593 result->arg = Qnil;
3594 return Qnil;
3597 static Lisp_Object
3598 construct_mouse_wheel (result, msg, f)
3599 struct input_event *result;
3600 W32Msg *msg;
3601 struct frame *f;
3603 POINT p;
3604 int delta;
3606 result->kind = msg->msg.message == WM_MOUSEHWHEEL ? HORIZ_WHEEL_EVENT
3607 : WHEEL_EVENT;
3608 result->code = 0;
3609 result->timestamp = msg->msg.time;
3611 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
3612 forward, away from the user (up); a negative value indicates that
3613 the wheel was rotated backward, toward the user (down). */
3614 delta = GET_WHEEL_DELTA_WPARAM (msg->msg.wParam);
3616 /* The up and down modifiers indicate if the wheel was rotated up or
3617 down based on WHEEL_DELTA value. */
3618 result->modifiers = (msg->dwModifiers
3619 | ((delta < 0 ) ? down_modifier : up_modifier));
3621 /* With multiple monitors, we can legitimately get negative
3622 coordinates, so cast to short to interpret them correctly. */
3623 p.x = (short) LOWORD (msg->msg.lParam);
3624 p.y = (short) HIWORD (msg->msg.lParam);
3625 ScreenToClient (msg->msg.hwnd, &p);
3626 XSETINT (result->x, p.x);
3627 XSETINT (result->y, p.y);
3628 XSETFRAME (result->frame_or_window, f);
3629 result->arg = Qnil;
3630 return Qnil;
3633 static Lisp_Object
3634 construct_drag_n_drop (result, msg, f)
3635 struct input_event *result;
3636 W32Msg *msg;
3637 struct frame *f;
3639 Lisp_Object files;
3640 Lisp_Object frame;
3641 HDROP hdrop;
3642 POINT p;
3643 WORD num_files;
3644 char *name;
3645 int i, len;
3647 result->kind = DRAG_N_DROP_EVENT;
3648 result->code = 0;
3649 result->timestamp = msg->msg.time;
3650 result->modifiers = msg->dwModifiers;
3652 hdrop = (HDROP) msg->msg.wParam;
3653 DragQueryPoint (hdrop, &p);
3655 #if 0
3656 p.x = LOWORD (msg->msg.lParam);
3657 p.y = HIWORD (msg->msg.lParam);
3658 ScreenToClient (msg->msg.hwnd, &p);
3659 #endif
3661 XSETINT (result->x, p.x);
3662 XSETINT (result->y, p.y);
3664 num_files = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
3665 files = Qnil;
3667 for (i = 0; i < num_files; i++)
3669 len = DragQueryFile (hdrop, i, NULL, 0);
3670 if (len <= 0)
3671 continue;
3672 name = alloca (len + 1);
3673 DragQueryFile (hdrop, i, name, len + 1);
3674 files = Fcons (DECODE_FILE (build_string (name)), files);
3677 DragFinish (hdrop);
3679 XSETFRAME (frame, f);
3680 result->frame_or_window = frame;
3681 result->arg = files;
3682 return Qnil;
3686 /* Function to report a mouse movement to the mainstream Emacs code.
3687 The input handler calls this.
3689 We have received a mouse movement event, which is given in *event.
3690 If the mouse is over a different glyph than it was last time, tell
3691 the mainstream emacs code by setting mouse_moved. If not, ask for
3692 another motion event, so we can check again the next time it moves. */
3694 static MSG last_mouse_motion_event;
3695 static Lisp_Object last_mouse_motion_frame;
3697 static int
3698 note_mouse_movement (frame, msg)
3699 FRAME_PTR frame;
3700 MSG *msg;
3702 int mouse_x = LOWORD (msg->lParam);
3703 int mouse_y = HIWORD (msg->lParam);
3705 last_mouse_movement_time = msg->time;
3706 memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event));
3707 XSETFRAME (last_mouse_motion_frame, frame);
3709 if (!FRAME_X_OUTPUT (frame))
3710 return 0;
3712 if (msg->hwnd != FRAME_W32_WINDOW (frame))
3714 frame->mouse_moved = 1;
3715 last_mouse_scroll_bar = Qnil;
3716 note_mouse_highlight (frame, -1, -1);
3717 last_mouse_glyph_frame = 0;
3718 return 1;
3721 /* Has the mouse moved off the glyph it was on at the last sighting? */
3722 if (frame != last_mouse_glyph_frame
3723 || mouse_x < last_mouse_glyph.left
3724 || mouse_x >= last_mouse_glyph.right
3725 || mouse_y < last_mouse_glyph.top
3726 || mouse_y >= last_mouse_glyph.bottom)
3728 frame->mouse_moved = 1;
3729 last_mouse_scroll_bar = Qnil;
3730 note_mouse_highlight (frame, mouse_x, mouse_y);
3731 /* Remember the mouse position here, as w32_mouse_position only
3732 gets called when mouse tracking is enabled but we also need
3733 to keep track of the mouse for help_echo and highlighting at
3734 other times. */
3735 remember_mouse_glyph (frame, mouse_x, mouse_y, &last_mouse_glyph);
3736 last_mouse_glyph_frame = frame;
3737 return 1;
3740 return 0;
3744 /************************************************************************
3745 Mouse Face
3746 ************************************************************************/
3748 static struct scroll_bar *x_window_to_scroll_bar ();
3749 static void x_scroll_bar_report_motion ();
3750 static void x_check_fullscreen P_ ((struct frame *));
3752 static void
3753 redo_mouse_highlight ()
3755 if (!NILP (last_mouse_motion_frame)
3756 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame)))
3757 note_mouse_highlight (XFRAME (last_mouse_motion_frame),
3758 LOWORD (last_mouse_motion_event.lParam),
3759 HIWORD (last_mouse_motion_event.lParam));
3762 static void
3763 w32_define_cursor (window, cursor)
3764 Window window;
3765 Cursor cursor;
3767 PostMessage (window, WM_EMACS_SETCURSOR, (WPARAM) cursor, 0);
3769 /* Return the current position of the mouse.
3770 *fp should be a frame which indicates which display to ask about.
3772 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3773 and *part to the frame, window, and scroll bar part that the mouse
3774 is over. Set *x and *y to the portion and whole of the mouse's
3775 position on the scroll bar.
3777 If the mouse movement started elsewhere, set *fp to the frame the
3778 mouse is on, *bar_window to nil, and *x and *y to the character cell
3779 the mouse is over.
3781 Set *time to the server time-stamp for the time at which the mouse
3782 was at this position.
3784 Don't store anything if we don't have a valid set of values to report.
3786 This clears the mouse_moved flag, so we can wait for the next mouse
3787 movement. */
3789 static void
3790 w32_mouse_position (fp, insist, bar_window, part, x, y, time)
3791 FRAME_PTR *fp;
3792 int insist;
3793 Lisp_Object *bar_window;
3794 enum scroll_bar_part *part;
3795 Lisp_Object *x, *y;
3796 unsigned long *time;
3798 FRAME_PTR f1;
3800 BLOCK_INPUT;
3802 if (! NILP (last_mouse_scroll_bar) && insist == 0)
3803 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
3804 else
3806 POINT pt;
3808 Lisp_Object frame, tail;
3810 /* Clear the mouse-moved flag for every frame on this display. */
3811 FOR_EACH_FRAME (tail, frame)
3812 XFRAME (frame)->mouse_moved = 0;
3814 last_mouse_scroll_bar = Qnil;
3816 GetCursorPos (&pt);
3818 /* Now we have a position on the root; find the innermost window
3819 containing the pointer. */
3821 if (FRAME_W32_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame
3822 && FRAME_LIVE_P (last_mouse_frame))
3824 /* If mouse was grabbed on a frame, give coords for that frame
3825 even if the mouse is now outside it. */
3826 f1 = last_mouse_frame;
3828 else
3830 /* Is window under mouse one of our frames? */
3831 f1 = x_any_window_to_frame (FRAME_W32_DISPLAY_INFO (*fp),
3832 WindowFromPoint (pt));
3835 /* If not, is it one of our scroll bars? */
3836 if (! f1)
3838 struct scroll_bar *bar
3839 = x_window_to_scroll_bar (WindowFromPoint (pt));
3841 if (bar)
3843 f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3847 if (f1 == 0 && insist > 0)
3848 f1 = SELECTED_FRAME ();
3850 if (f1)
3852 /* Ok, we found a frame. Store all the values.
3853 last_mouse_glyph is a rectangle used to reduce the
3854 generation of mouse events. To not miss any motion
3855 events, we must divide the frame into rectangles of the
3856 size of the smallest character that could be displayed
3857 on it, i.e. into the same rectangles that matrices on
3858 the frame are divided into. */
3860 ScreenToClient (FRAME_W32_WINDOW (f1), &pt);
3861 remember_mouse_glyph (f1, pt.x, pt.y, &last_mouse_glyph);
3862 last_mouse_glyph_frame = f1;
3864 *bar_window = Qnil;
3865 *part = 0;
3866 *fp = f1;
3867 XSETINT (*x, pt.x);
3868 XSETINT (*y, pt.y);
3869 *time = last_mouse_movement_time;
3874 UNBLOCK_INPUT;
3878 /***********************************************************************
3879 Tool-bars
3880 ***********************************************************************/
3882 /* Handle mouse button event on the tool-bar of frame F, at
3883 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
3884 or ButtonRelase. */
3886 static void
3887 w32_handle_tool_bar_click (f, button_event)
3888 struct frame *f;
3889 struct input_event *button_event;
3891 int x = XFASTINT (button_event->x);
3892 int y = XFASTINT (button_event->y);
3894 if (button_event->modifiers & down_modifier)
3895 handle_tool_bar_click (f, x, y, 1, 0);
3896 else
3897 handle_tool_bar_click (f, x, y, 0,
3898 button_event->modifiers & ~up_modifier);
3903 /***********************************************************************
3904 Scroll bars
3905 ***********************************************************************/
3907 /* Scroll bar support. */
3909 /* Given a window ID, find the struct scroll_bar which manages it.
3910 This can be called in GC, so we have to make sure to strip off mark
3911 bits. */
3913 static struct scroll_bar *
3914 x_window_to_scroll_bar (window_id)
3915 Window window_id;
3917 Lisp_Object tail;
3919 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
3921 Lisp_Object frame, bar, condemned;
3923 frame = XCAR (tail);
3924 /* All elements of Vframe_list should be frames. */
3925 if (! FRAMEP (frame))
3926 abort ();
3928 /* Scan this frame's scroll bar list for a scroll bar with the
3929 right window ID. */
3930 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
3931 for (bar = FRAME_SCROLL_BARS (XFRAME (frame));
3932 /* This trick allows us to search both the ordinary and
3933 condemned scroll bar lists with one loop. */
3934 ! NILP (bar) || (bar = condemned,
3935 condemned = Qnil,
3936 ! NILP (bar));
3937 bar = XSCROLL_BAR (bar)->next)
3938 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar)) == window_id)
3939 return XSCROLL_BAR (bar);
3942 return 0;
3947 /* Set the thumb size and position of scroll bar BAR. We are currently
3948 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3950 static void
3951 w32_set_scroll_bar_thumb (bar, portion, position, whole)
3952 struct scroll_bar *bar;
3953 int portion, position, whole;
3955 Window w = SCROLL_BAR_W32_WINDOW (bar);
3956 /* We use the whole scroll-bar height in the calculations below, to
3957 avoid strange effects like scrolling backwards when just clicking
3958 on the handle (without moving it). */
3959 double range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height))
3960 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
3961 int sb_page, sb_pos;
3962 BOOL draggingp = !NILP (bar->dragging) ? TRUE : FALSE;
3963 SCROLLINFO si;
3965 /* We used to change the nPage setting while dragging the handle,
3966 but that had very strange effects (such as scrolling backwards
3967 while dragging downwards).
3969 Now, we don't change the nPage setting while dragging unless we
3970 get near to the end of the buffer, in which case we often have to
3971 resize the handle to "go all the way". */
3973 if (draggingp)
3975 int near_bottom_p;
3976 BLOCK_INPUT;
3977 si.cbSize = sizeof (si);
3978 si.fMask = SIF_POS | SIF_PAGE;
3979 GetScrollInfo(w, SB_CTL, &si);
3980 near_bottom_p = si.nPos + si.nPage >= range;
3981 UNBLOCK_INPUT;
3982 if (!near_bottom_p)
3983 return;
3986 if (whole)
3988 /* Position scroll bar at rock bottom if the bottom of the
3989 buffer is visible. This avoids shinking the thumb away
3990 to nothing if it is held at the bottom of the buffer. */
3991 if (position + portion >= whole && !draggingp)
3993 sb_page = range * (whole - position) / whole;
3994 sb_pos = range;
3996 else
3998 sb_pos = position * range / whole;
3999 sb_page = (min (portion, (whole - position)) * range) / whole;
4002 else
4004 sb_page = range;
4005 sb_pos = 0;
4008 sb_page = max (sb_page, VERTICAL_SCROLL_BAR_MIN_HANDLE);
4010 BLOCK_INPUT;
4012 si.cbSize = sizeof (si);
4013 si.fMask = SIF_PAGE | SIF_POS;
4014 si.nPage = sb_page;
4015 si.nPos = sb_pos;
4017 SetScrollInfo (w, SB_CTL, &si, TRUE);
4019 UNBLOCK_INPUT;
4023 /************************************************************************
4024 Scroll bars, general
4025 ************************************************************************/
4027 static HWND
4028 my_create_scrollbar (f, bar)
4029 struct frame * f;
4030 struct scroll_bar * bar;
4032 return (HWND) SendMessage (FRAME_W32_WINDOW (f),
4033 WM_EMACS_CREATESCROLLBAR, (WPARAM) f,
4034 (LPARAM) bar);
4037 /*#define ATTACH_THREADS*/
4039 static BOOL
4040 my_show_window (FRAME_PTR f, HWND hwnd, int how)
4042 #ifndef ATTACH_THREADS
4043 return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW,
4044 (WPARAM) hwnd, (LPARAM) how);
4045 #else
4046 return ShowWindow (hwnd, how);
4047 #endif
4050 static void
4051 my_set_window_pos (HWND hwnd, HWND hwndAfter,
4052 int x, int y, int cx, int cy, UINT flags)
4054 #ifndef ATTACH_THREADS
4055 WINDOWPOS pos;
4056 pos.hwndInsertAfter = hwndAfter;
4057 pos.x = x;
4058 pos.y = y;
4059 pos.cx = cx;
4060 pos.cy = cy;
4061 pos.flags = flags;
4062 SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0);
4063 #else
4064 SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags);
4065 #endif
4068 static void
4069 my_set_focus (f, hwnd)
4070 struct frame * f;
4071 HWND hwnd;
4073 SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SETFOCUS,
4074 (WPARAM) hwnd, 0);
4077 static void
4078 my_set_foreground_window (hwnd)
4079 HWND hwnd;
4081 SendMessage (hwnd, WM_EMACS_SETFOREGROUND, (WPARAM) hwnd, 0);
4085 static void
4086 my_destroy_window (f, hwnd)
4087 struct frame * f;
4088 HWND hwnd;
4090 SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_DESTROYWINDOW,
4091 (WPARAM) hwnd, 0);
4094 /* Create a scroll bar and return the scroll bar vector for it. W is
4095 the Emacs window on which to create the scroll bar. TOP, LEFT,
4096 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
4097 scroll bar. */
4099 static struct scroll_bar *
4100 x_scroll_bar_create (w, top, left, width, height)
4101 struct window *w;
4102 int top, left, width, height;
4104 struct frame *f = XFRAME (WINDOW_FRAME (w));
4105 HWND hwnd;
4106 SCROLLINFO si;
4107 struct scroll_bar *bar
4108 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
4110 BLOCK_INPUT;
4112 XSETWINDOW (bar->window, w);
4113 XSETINT (bar->top, top);
4114 XSETINT (bar->left, left);
4115 XSETINT (bar->width, width);
4116 XSETINT (bar->height, height);
4117 XSETINT (bar->start, 0);
4118 XSETINT (bar->end, 0);
4119 bar->dragging = Qnil;
4120 bar->fringe_extended_p = Qnil;
4122 /* Requires geometry to be set before call to create the real window */
4124 hwnd = my_create_scrollbar (f, bar);
4126 si.cbSize = sizeof (si);
4127 si.fMask = SIF_ALL;
4128 si.nMin = 0;
4129 si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height)
4130 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4131 si.nPage = si.nMax;
4132 si.nPos = 0;
4134 SetScrollInfo (hwnd, SB_CTL, &si, FALSE);
4136 SET_SCROLL_BAR_W32_WINDOW (bar, hwnd);
4138 /* Add bar to its frame's list of scroll bars. */
4139 bar->next = FRAME_SCROLL_BARS (f);
4140 bar->prev = Qnil;
4141 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
4142 if (! NILP (bar->next))
4143 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
4145 UNBLOCK_INPUT;
4147 return bar;
4151 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4152 nil. */
4154 static void
4155 x_scroll_bar_remove (bar)
4156 struct scroll_bar *bar;
4158 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
4160 BLOCK_INPUT;
4162 /* Destroy the window. */
4163 my_destroy_window (f, SCROLL_BAR_W32_WINDOW (bar));
4165 /* Disassociate this scroll bar from its window. */
4166 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
4168 UNBLOCK_INPUT;
4171 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4172 that we are displaying PORTION characters out of a total of WHOLE
4173 characters, starting at POSITION. If WINDOW has no scroll bar,
4174 create one. */
4175 static void
4176 w32_set_vertical_scroll_bar (w, portion, whole, position)
4177 struct window *w;
4178 int portion, whole, position;
4180 struct frame *f = XFRAME (w->frame);
4181 struct scroll_bar *bar;
4182 int top, height, left, sb_left, width, sb_width;
4183 int window_y, window_height;
4184 int fringe_extended_p;
4186 /* Get window dimensions. */
4187 window_box (w, -1, 0, &window_y, 0, &window_height);
4188 top = window_y;
4189 width = WINDOW_CONFIG_SCROLL_BAR_COLS (w) * FRAME_COLUMN_WIDTH (f);
4190 height = window_height;
4192 /* Compute the left edge of the scroll bar area. */
4193 left = WINDOW_SCROLL_BAR_AREA_X (w);
4195 /* Compute the width of the scroll bar which might be less than
4196 the width of the area reserved for the scroll bar. */
4197 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) > 0)
4198 sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w);
4199 else
4200 sb_width = width;
4202 /* Compute the left edge of the scroll bar. */
4203 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w))
4204 sb_left = left + (WINDOW_RIGHTMOST_P (w) ? width - sb_width : 0);
4205 else
4206 sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width);
4208 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
4209 fringe_extended_p = (WINDOW_LEFTMOST_P (w)
4210 && WINDOW_LEFT_FRINGE_WIDTH (w)
4211 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
4212 || WINDOW_LEFT_MARGIN_COLS (w) == 0));
4213 else
4214 fringe_extended_p = (WINDOW_RIGHTMOST_P (w)
4215 && WINDOW_RIGHT_FRINGE_WIDTH (w)
4216 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
4217 || WINDOW_RIGHT_MARGIN_COLS (w) == 0));
4219 /* Does the scroll bar exist yet? */
4220 if (NILP (w->vertical_scroll_bar))
4222 HDC hdc;
4223 BLOCK_INPUT;
4224 if (width > 0 && height > 0)
4226 hdc = get_frame_dc (f);
4227 if (fringe_extended_p)
4228 w32_clear_area (f, hdc, sb_left, top, sb_width, height);
4229 else
4230 w32_clear_area (f, hdc, left, top, width, height);
4231 release_frame_dc (f, hdc);
4233 UNBLOCK_INPUT;
4235 bar = x_scroll_bar_create (w, top, sb_left, sb_width, height);
4237 else
4239 /* It may just need to be moved and resized. */
4240 HWND hwnd;
4242 bar = XSCROLL_BAR (w->vertical_scroll_bar);
4243 hwnd = SCROLL_BAR_W32_WINDOW (bar);
4245 /* If already correctly positioned, do nothing. */
4246 if ( XINT (bar->left) == sb_left
4247 && XINT (bar->top) == top
4248 && XINT (bar->width) == sb_width
4249 && XINT (bar->height) == height
4250 && !NILP (bar->fringe_extended_p) == fringe_extended_p )
4252 /* Redraw after clear_frame. */
4253 if (!my_show_window (f, hwnd, SW_NORMAL))
4254 InvalidateRect (hwnd, NULL, FALSE);
4256 else
4258 HDC hdc;
4259 SCROLLINFO si;
4261 BLOCK_INPUT;
4262 if (width && height)
4264 hdc = get_frame_dc (f);
4265 /* Since Windows scroll bars are smaller than the space reserved
4266 for them on the frame, we have to clear "under" them. */
4267 if (fringe_extended_p)
4268 w32_clear_area (f, hdc, sb_left, top, sb_width, height);
4269 else
4270 w32_clear_area (f, hdc, left, top, width, height);
4271 release_frame_dc (f, hdc);
4273 /* Make sure scroll bar is "visible" before moving, to ensure the
4274 area of the parent window now exposed will be refreshed. */
4275 my_show_window (f, hwnd, SW_HIDE);
4276 MoveWindow (hwnd, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
4277 top, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
4278 max (height, 1), TRUE);
4280 si.cbSize = sizeof (si);
4281 si.fMask = SIF_RANGE;
4282 si.nMin = 0;
4283 si.nMax = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height)
4284 + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4286 SetScrollInfo (hwnd, SB_CTL, &si, FALSE);
4288 my_show_window (f, hwnd, SW_NORMAL);
4289 /* InvalidateRect (w, NULL, FALSE); */
4291 /* Remember new settings. */
4292 XSETINT (bar->left, sb_left);
4293 XSETINT (bar->top, top);
4294 XSETINT (bar->width, sb_width);
4295 XSETINT (bar->height, height);
4297 UNBLOCK_INPUT;
4300 bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil;
4302 w32_set_scroll_bar_thumb (bar, portion, position, whole);
4304 XSETVECTOR (w->vertical_scroll_bar, bar);
4308 /* The following three hooks are used when we're doing a thorough
4309 redisplay of the frame. We don't explicitly know which scroll bars
4310 are going to be deleted, because keeping track of when windows go
4311 away is a real pain - "Can you say set-window-configuration, boys
4312 and girls?" Instead, we just assert at the beginning of redisplay
4313 that *all* scroll bars are to be removed, and then save a scroll bar
4314 from the fiery pit when we actually redisplay its window. */
4316 /* Arrange for all scroll bars on FRAME to be removed at the next call
4317 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4318 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4320 static void
4321 w32_condemn_scroll_bars (frame)
4322 FRAME_PTR frame;
4324 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
4325 while (! NILP (FRAME_SCROLL_BARS (frame)))
4327 Lisp_Object bar;
4328 bar = FRAME_SCROLL_BARS (frame);
4329 FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next;
4330 XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame);
4331 XSCROLL_BAR (bar)->prev = Qnil;
4332 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame)))
4333 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar;
4334 FRAME_CONDEMNED_SCROLL_BARS (frame) = bar;
4339 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4340 Note that WINDOW isn't necessarily condemned at all. */
4342 static void
4343 w32_redeem_scroll_bar (window)
4344 struct window *window;
4346 struct scroll_bar *bar;
4347 struct frame *f;
4349 /* We can't redeem this window's scroll bar if it doesn't have one. */
4350 if (NILP (window->vertical_scroll_bar))
4351 abort ();
4353 bar = XSCROLL_BAR (window->vertical_scroll_bar);
4355 /* Unlink it from the condemned list. */
4356 f = XFRAME (WINDOW_FRAME (window));
4357 if (NILP (bar->prev))
4359 /* If the prev pointer is nil, it must be the first in one of
4360 the lists. */
4361 if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar))
4362 /* It's not condemned. Everything's fine. */
4363 return;
4364 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f),
4365 window->vertical_scroll_bar))
4366 FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next;
4367 else
4368 /* If its prev pointer is nil, it must be at the front of
4369 one or the other! */
4370 abort ();
4372 else
4373 XSCROLL_BAR (bar->prev)->next = bar->next;
4375 if (! NILP (bar->next))
4376 XSCROLL_BAR (bar->next)->prev = bar->prev;
4378 bar->next = FRAME_SCROLL_BARS (f);
4379 bar->prev = Qnil;
4380 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
4381 if (! NILP (bar->next))
4382 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
4385 /* Remove all scroll bars on FRAME that haven't been saved since the
4386 last call to `*condemn_scroll_bars_hook'. */
4388 static void
4389 w32_judge_scroll_bars (f)
4390 FRAME_PTR f;
4392 Lisp_Object bar, next;
4394 bar = FRAME_CONDEMNED_SCROLL_BARS (f);
4396 /* Clear out the condemned list now so we won't try to process any
4397 more events on the hapless scroll bars. */
4398 FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil;
4400 for (; ! NILP (bar); bar = next)
4402 struct scroll_bar *b = XSCROLL_BAR (bar);
4404 x_scroll_bar_remove (b);
4406 next = b->next;
4407 b->next = b->prev = Qnil;
4410 /* Now there should be no references to the condemned scroll bars,
4411 and they should get garbage-collected. */
4414 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
4415 is set to something other than NO_EVENT, it is enqueued.
4417 This may be called from a signal handler, so we have to ignore GC
4418 mark bits. */
4420 static int
4421 w32_scroll_bar_handle_click (bar, msg, emacs_event)
4422 struct scroll_bar *bar;
4423 W32Msg *msg;
4424 struct input_event *emacs_event;
4426 if (! WINDOWP (bar->window))
4427 abort ();
4429 emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
4430 emacs_event->code = 0;
4431 /* not really meaningful to distinguish up/down */
4432 emacs_event->modifiers = msg->dwModifiers;
4433 emacs_event->frame_or_window = bar->window;
4434 emacs_event->arg = Qnil;
4435 emacs_event->timestamp = msg->msg.time;
4438 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4439 int y;
4440 int dragging = !NILP (bar->dragging);
4441 SCROLLINFO si;
4443 si.cbSize = sizeof (si);
4444 si.fMask = SIF_POS;
4446 GetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si);
4447 y = si.nPos;
4449 bar->dragging = Qnil;
4452 last_mouse_scroll_bar_pos = msg->msg.wParam;
4454 switch (LOWORD (msg->msg.wParam))
4456 case SB_LINEDOWN:
4457 emacs_event->part = scroll_bar_down_arrow;
4458 break;
4459 case SB_LINEUP:
4460 emacs_event->part = scroll_bar_up_arrow;
4461 break;
4462 case SB_PAGEUP:
4463 emacs_event->part = scroll_bar_above_handle;
4464 break;
4465 case SB_PAGEDOWN:
4466 emacs_event->part = scroll_bar_below_handle;
4467 break;
4468 case SB_TOP:
4469 emacs_event->part = scroll_bar_handle;
4470 y = 0;
4471 break;
4472 case SB_BOTTOM:
4473 emacs_event->part = scroll_bar_handle;
4474 y = top_range;
4475 break;
4476 case SB_THUMBTRACK:
4477 case SB_THUMBPOSITION:
4478 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff)
4479 y = HIWORD (msg->msg.wParam);
4480 bar->dragging = Qt;
4481 emacs_event->part = scroll_bar_handle;
4483 /* "Silently" update current position. */
4485 SCROLLINFO si;
4487 si.cbSize = sizeof (si);
4488 si.fMask = SIF_POS;
4489 si.nPos = y;
4490 /* Remember apparent position (we actually lag behind the real
4491 position, so don't set that directly. */
4492 last_scroll_bar_drag_pos = y;
4494 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, FALSE);
4496 break;
4497 case SB_ENDSCROLL:
4498 /* If this is the end of a drag sequence, then reset the scroll
4499 handle size to normal and do a final redraw. Otherwise do
4500 nothing. */
4501 if (dragging)
4503 SCROLLINFO si;
4504 int start = XINT (bar->start);
4505 int end = XINT (bar->end);
4507 si.cbSize = sizeof (si);
4508 si.fMask = SIF_PAGE | SIF_POS;
4509 si.nPage = end - start + VERTICAL_SCROLL_BAR_MIN_HANDLE;
4510 si.nPos = last_scroll_bar_drag_pos;
4511 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE);
4513 /* fall through */
4514 default:
4515 emacs_event->kind = NO_EVENT;
4516 return FALSE;
4519 XSETINT (emacs_event->x, y);
4520 XSETINT (emacs_event->y, top_range);
4522 return TRUE;
4526 /* Return information to the user about the current position of the mouse
4527 on the scroll bar. */
4529 static void
4530 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
4531 FRAME_PTR *fp;
4532 Lisp_Object *bar_window;
4533 enum scroll_bar_part *part;
4534 Lisp_Object *x, *y;
4535 unsigned long *time;
4537 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4538 Window w = SCROLL_BAR_W32_WINDOW (bar);
4539 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
4540 int pos;
4541 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4542 SCROLLINFO si;
4544 BLOCK_INPUT;
4546 *fp = f;
4547 *bar_window = bar->window;
4549 si.cbSize = sizeof (si);
4550 si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
4552 GetScrollInfo (w, SB_CTL, &si);
4553 pos = si.nPos;
4554 top_range = si.nMax - si.nPage + 1;
4556 switch (LOWORD (last_mouse_scroll_bar_pos))
4558 case SB_THUMBPOSITION:
4559 case SB_THUMBTRACK:
4560 *part = scroll_bar_handle;
4561 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)) <= 0xffff)
4562 pos = HIWORD (last_mouse_scroll_bar_pos);
4563 break;
4564 case SB_LINEDOWN:
4565 *part = scroll_bar_handle;
4566 pos++;
4567 break;
4568 default:
4569 *part = scroll_bar_handle;
4570 break;
4573 XSETINT (*x, pos);
4574 XSETINT (*y, top_range);
4576 f->mouse_moved = 0;
4577 last_mouse_scroll_bar = Qnil;
4579 *time = last_mouse_movement_time;
4581 UNBLOCK_INPUT;
4585 /* The screen has been cleared so we may have changed foreground or
4586 background colors, and the scroll bars may need to be redrawn.
4587 Clear out the scroll bars, and ask for expose events, so we can
4588 redraw them. */
4590 void
4591 x_scroll_bar_clear (f)
4592 FRAME_PTR f;
4594 Lisp_Object bar;
4596 /* We can have scroll bars even if this is 0,
4597 if we just turned off scroll bar mode.
4598 But in that case we should not clear them. */
4599 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4600 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
4601 bar = XSCROLL_BAR (bar)->next)
4603 HWND window = SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar));
4604 HDC hdc = GetDC (window);
4605 RECT rect;
4607 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
4608 arranges to refresh the scroll bar if hidden. */
4609 my_show_window (f, window, SW_HIDE);
4611 GetClientRect (window, &rect);
4612 select_palette (f, hdc);
4613 w32_clear_rect (f, hdc, &rect);
4614 deselect_palette (f, hdc);
4616 ReleaseDC (window, hdc);
4621 /* The main W32 event-reading loop - w32_read_socket. */
4623 /* Record the last 100 characters stored
4624 to help debug the loss-of-chars-during-GC problem. */
4626 static int temp_index;
4627 static short temp_buffer[100];
4629 /* Temporarily store lead byte of DBCS input sequences. */
4630 static char dbcs_lead = 0;
4632 /* Read events coming from the W32 shell.
4633 This routine is called by the SIGIO handler.
4634 We return as soon as there are no more events to be read.
4636 We return the number of characters stored into the buffer,
4637 thus pretending to be `read'.
4639 EXPECTED is nonzero if the caller knows input is available.
4641 Some of these messages are reposted back to the message queue since the
4642 system calls the windows proc directly in a context where we cannot return
4643 the data nor can we guarantee the state we are in. So if we dispatch them
4644 we will get into an infinite loop. To prevent this from ever happening we
4645 will set a variable to indicate we are in the read_socket call and indicate
4646 which message we are processing since the windows proc gets called
4647 recursively with different messages by the system.
4651 w32_read_socket (sd, expected, hold_quit)
4652 register int sd;
4653 int expected;
4654 struct input_event *hold_quit;
4656 int count = 0;
4657 int check_visibility = 0;
4658 W32Msg msg;
4659 struct frame *f;
4660 struct w32_display_info *dpyinfo = &one_w32_display_info;
4662 if (interrupt_input_blocked)
4664 interrupt_input_pending = 1;
4665 return -1;
4668 interrupt_input_pending = 0;
4669 BLOCK_INPUT;
4671 /* So people can tell when we have read the available input. */
4672 input_signal_count++;
4674 /* TODO: ghostscript integration. */
4675 while (get_next_msg (&msg, FALSE))
4677 struct input_event inev;
4678 int do_help = 0;
4680 EVENT_INIT (inev);
4681 inev.kind = NO_EVENT;
4682 inev.arg = Qnil;
4684 switch (msg.msg.message)
4686 case WM_PAINT:
4687 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4689 if (f)
4691 if (msg.rect.right == msg.rect.left ||
4692 msg.rect.bottom == msg.rect.top)
4694 /* We may get paint messages even though the client
4695 area is clipped - these are not expose events. */
4696 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f,
4697 SDATA (f->name)));
4699 else if (f->async_visible != 1)
4701 /* Definitely not obscured, so mark as visible. */
4702 f->async_visible = 1;
4703 f->async_iconified = 0;
4704 SET_FRAME_GARBAGED (f);
4705 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f,
4706 SDATA (f->name)));
4708 /* WM_PAINT serves as MapNotify as well, so report
4709 visibility changes properly. */
4710 if (f->iconified)
4712 inev.kind = DEICONIFY_EVENT;
4713 XSETFRAME (inev.frame_or_window, f);
4715 else if (! NILP (Vframe_list)
4716 && ! NILP (XCDR (Vframe_list)))
4717 /* Force a redisplay sooner or later to update the
4718 frame titles in case this is the second frame. */
4719 record_asynch_buffer_change ();
4721 else
4723 HDC hdc = get_frame_dc (f);
4725 /* Erase background again for safety. */
4726 w32_clear_rect (f, hdc, &msg.rect);
4727 release_frame_dc (f, hdc);
4728 expose_frame (f,
4729 msg.rect.left,
4730 msg.rect.top,
4731 msg.rect.right - msg.rect.left,
4732 msg.rect.bottom - msg.rect.top);
4735 break;
4737 case WM_INPUTLANGCHANGE:
4738 /* Generate a language change event. */
4739 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4741 if (f)
4743 inev.kind = LANGUAGE_CHANGE_EVENT;
4744 XSETFRAME (inev.frame_or_window, f);
4745 inev.code = msg.msg.wParam;
4746 inev.modifiers = msg.msg.lParam & 0xffff;
4748 break;
4750 case WM_KEYDOWN:
4751 case WM_SYSKEYDOWN:
4752 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4754 if (f && !f->iconified)
4756 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4757 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4759 clear_mouse_face (dpyinfo);
4760 dpyinfo->mouse_face_hidden = 1;
4763 if (temp_index == sizeof temp_buffer / sizeof (short))
4764 temp_index = 0;
4765 temp_buffer[temp_index++] = msg.msg.wParam;
4766 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
4767 inev.code = msg.msg.wParam;
4768 inev.modifiers = msg.dwModifiers;
4769 XSETFRAME (inev.frame_or_window, f);
4770 inev.timestamp = msg.msg.time;
4772 break;
4774 case WM_UNICHAR:
4775 case WM_SYSCHAR:
4776 case WM_CHAR:
4777 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4779 if (f && !f->iconified)
4781 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4782 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4784 clear_mouse_face (dpyinfo);
4785 dpyinfo->mouse_face_hidden = 1;
4788 if (temp_index == sizeof temp_buffer / sizeof (short))
4789 temp_index = 0;
4790 temp_buffer[temp_index++] = msg.msg.wParam;
4792 inev.modifiers = msg.dwModifiers;
4793 XSETFRAME (inev.frame_or_window, f);
4794 inev.timestamp = msg.msg.time;
4796 if (msg.msg.message == WM_UNICHAR)
4798 inev.code = msg.msg.wParam;
4800 else if (msg.msg.wParam < 256)
4802 wchar_t code;
4803 char dbcs[2];
4804 dbcs[0] = 0;
4805 dbcs[1] = (char) msg.msg.wParam;
4807 if (dbcs_lead)
4809 dbcs[0] = dbcs_lead;
4810 dbcs_lead = 0;
4811 if (!MultiByteToWideChar (CP_ACP, 0, dbcs, 2, &code, 1))
4813 /* Garbage */
4814 DebPrint (("Invalid DBCS sequence: %d %d\n",
4815 dbcs[0], dbcs[1]));
4816 inev.kind = NO_EVENT;
4817 break;
4820 else if (IsDBCSLeadByteEx (CP_ACP, (BYTE) msg.msg.wParam))
4822 dbcs_lead = (char) msg.msg.wParam;
4823 inev.kind = NO_EVENT;
4824 break;
4826 else
4828 if (!MultiByteToWideChar (CP_ACP, 0, &dbcs[1], 1,
4829 &code, 1))
4831 /* What to do with garbage? */
4832 DebPrint (("Invalid character: %d\n", dbcs[1]));
4833 inev.kind = NO_EVENT;
4834 break;
4837 inev.code = code;
4839 else
4841 /* Windows shouldn't generate WM_CHAR events above 0xFF
4842 in non-Unicode message handlers. */
4843 DebPrint (("Non-byte WM_CHAR: %d\n", msg.msg.wParam));
4844 inev.kind = NO_EVENT;
4845 break;
4847 inev.kind = inev.code < 128 ? ASCII_KEYSTROKE_EVENT
4848 : MULTIBYTE_CHAR_KEYSTROKE_EVENT;
4850 break;
4852 case WM_APPCOMMAND:
4853 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4855 if (f && !f->iconified)
4857 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
4858 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
4860 clear_mouse_face (dpyinfo);
4861 dpyinfo->mouse_face_hidden = 1;
4864 if (temp_index == sizeof temp_buffer / sizeof (short))
4865 temp_index = 0;
4866 temp_buffer[temp_index++] = msg.msg.wParam;
4867 inev.kind = MULTIMEDIA_KEY_EVENT;
4868 inev.code = GET_APPCOMMAND_LPARAM(msg.msg.lParam);
4869 inev.modifiers = msg.dwModifiers;
4870 XSETFRAME (inev.frame_or_window, f);
4871 inev.timestamp = msg.msg.time;
4873 break;
4875 case WM_MOUSEMOVE:
4876 /* Ignore non-movement. */
4878 int x = LOWORD (msg.msg.lParam);
4879 int y = HIWORD (msg.msg.lParam);
4880 if (x == last_mousemove_x && y == last_mousemove_y)
4881 break;
4882 last_mousemove_x = x;
4883 last_mousemove_y = y;
4886 previous_help_echo_string = help_echo_string;
4887 help_echo_string = Qnil;
4889 if (dpyinfo->grabbed && last_mouse_frame
4890 && FRAME_LIVE_P (last_mouse_frame))
4891 f = last_mouse_frame;
4892 else
4893 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4895 if (dpyinfo->mouse_face_hidden)
4897 dpyinfo->mouse_face_hidden = 0;
4898 clear_mouse_face (dpyinfo);
4901 if (f)
4903 /* Generate SELECT_WINDOW_EVENTs when needed. */
4904 if (!NILP (Vmouse_autoselect_window))
4906 Lisp_Object window;
4907 int x = LOWORD (msg.msg.lParam);
4908 int y = HIWORD (msg.msg.lParam);
4910 window = window_from_coordinates (f, x, y, 0, 0, 0, 0);
4912 /* Window will be selected only when it is not
4913 selected now and last mouse movement event was
4914 not in it. Minibuffer window will be selected
4915 only when it is active. */
4916 if (WINDOWP(window)
4917 && !EQ (window, last_window)
4918 && !EQ (window, selected_window)
4919 /* For click-to-focus window managers
4920 create event iff we don't leave the
4921 selected frame. */
4922 && (focus_follows_mouse
4923 || (EQ (XWINDOW (window)->frame,
4924 XWINDOW (selected_window)->frame))))
4926 inev.kind = SELECT_WINDOW_EVENT;
4927 inev.frame_or_window = window;
4930 last_window=window;
4932 if (!note_mouse_movement (f, &msg.msg))
4933 help_echo_string = previous_help_echo_string;
4935 else
4937 /* If we move outside the frame, then we're
4938 certainly no longer on any text in the frame. */
4939 clear_mouse_face (dpyinfo);
4942 /* If the contents of the global variable help_echo_string
4943 has changed, generate a HELP_EVENT. */
4944 #if 0 /* The below is an invalid comparison when USE_LISP_UNION_TYPE.
4945 But it was originally changed to this to fix a bug, so I have
4946 not removed it completely in case the bug is still there. */
4947 if (help_echo_string != previous_help_echo_string ||
4948 (!NILP (help_echo_string) && !STRINGP (help_echo_string) && f->mouse_moved))
4949 #else /* This is what xterm.c does. */
4950 if (!NILP (help_echo_string)
4951 || !NILP (previous_help_echo_string))
4952 do_help = 1;
4953 #endif
4954 break;
4956 case WM_LBUTTONDOWN:
4957 case WM_LBUTTONUP:
4958 case WM_MBUTTONDOWN:
4959 case WM_MBUTTONUP:
4960 case WM_RBUTTONDOWN:
4961 case WM_RBUTTONUP:
4962 case WM_XBUTTONDOWN:
4963 case WM_XBUTTONUP:
4965 /* If we decide we want to generate an event to be seen
4966 by the rest of Emacs, we put it here. */
4967 int tool_bar_p = 0;
4968 int button;
4969 int up;
4971 if (dpyinfo->grabbed && last_mouse_frame
4972 && FRAME_LIVE_P (last_mouse_frame))
4973 f = last_mouse_frame;
4974 else
4975 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4977 if (f)
4979 construct_mouse_click (&inev, &msg, f);
4981 /* Is this in the tool-bar? */
4982 if (WINDOWP (f->tool_bar_window)
4983 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)))
4985 Lisp_Object window;
4986 int x = XFASTINT (inev.x);
4987 int y = XFASTINT (inev.y);
4989 window = window_from_coordinates (f, x, y, 0, 0, 0, 1);
4991 if (EQ (window, f->tool_bar_window))
4993 w32_handle_tool_bar_click (f, &inev);
4994 tool_bar_p = 1;
4998 if (tool_bar_p
4999 || (dpyinfo->w32_focus_frame
5000 && f != dpyinfo->w32_focus_frame))
5001 inev.kind = NO_EVENT;
5004 parse_button (msg.msg.message, HIWORD (msg.msg.wParam),
5005 &button, &up);
5007 if (up)
5009 dpyinfo->grabbed &= ~ (1 << button);
5011 else
5013 dpyinfo->grabbed |= (1 << button);
5014 last_mouse_frame = f;
5015 /* Ignore any mouse motion that happened
5016 before this event; any subsequent mouse-movement
5017 Emacs events should reflect only motion after
5018 the ButtonPress. */
5019 if (f != 0)
5020 f->mouse_moved = 0;
5022 if (!tool_bar_p)
5023 last_tool_bar_item = -1;
5025 break;
5028 case WM_MOUSEWHEEL:
5029 case WM_MOUSEHWHEEL:
5031 if (dpyinfo->grabbed && last_mouse_frame
5032 && FRAME_LIVE_P (last_mouse_frame))
5033 f = last_mouse_frame;
5034 else
5035 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5037 if (f)
5040 if (!dpyinfo->w32_focus_frame
5041 || f == dpyinfo->w32_focus_frame)
5043 /* Emit an Emacs wheel-up/down event. */
5044 construct_mouse_wheel (&inev, &msg, f);
5046 /* Ignore any mouse motion that happened before this
5047 event; any subsequent mouse-movement Emacs events
5048 should reflect only motion after the
5049 ButtonPress. */
5050 f->mouse_moved = 0;
5052 last_mouse_frame = f;
5053 last_tool_bar_item = -1;
5055 break;
5057 case WM_DROPFILES:
5058 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5060 if (f)
5061 construct_drag_n_drop (&inev, &msg, f);
5062 break;
5064 case WM_VSCROLL:
5066 struct scroll_bar *bar =
5067 x_window_to_scroll_bar ((HWND)msg.msg.lParam);
5069 if (bar)
5070 w32_scroll_bar_handle_click (bar, &msg, &inev);
5071 break;
5074 case WM_WINDOWPOSCHANGED:
5075 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5076 if (f)
5078 if (f->want_fullscreen & FULLSCREEN_WAIT)
5079 f->want_fullscreen &= ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH);
5081 check_visibility = 1;
5082 break;
5084 case WM_ACTIVATE:
5085 case WM_ACTIVATEAPP:
5086 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5087 if (f)
5088 x_check_fullscreen (f);
5089 check_visibility = 1;
5090 break;
5092 case WM_MOVE:
5093 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5095 if (f && !f->async_iconified)
5097 int x, y;
5099 x_real_positions (f, &x, &y);
5100 f->left_pos = x;
5101 f->top_pos = y;
5104 check_visibility = 1;
5105 break;
5107 case WM_SHOWWINDOW:
5108 /* wParam non-zero means Window is about to be shown, 0 means
5109 about to be hidden. */
5110 /* Redo the mouse-highlight after the tooltip has gone. */
5111 if (!msg.msg.wParam && msg.msg.hwnd == tip_window)
5113 tip_window = NULL;
5114 redo_mouse_highlight ();
5117 /* If window has been obscured or exposed by another window
5118 being maximised or minimised/restored, then recheck
5119 visibility of all frames. Direct changes to our own
5120 windows get handled by WM_SIZE. */
5121 #if 0
5122 if (msg.msg.lParam != 0)
5123 check_visibility = 1;
5124 else
5126 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5127 f->async_visible = msg.msg.wParam;
5129 #endif
5131 check_visibility = 1;
5132 break;
5134 case WM_SIZE:
5135 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5137 /* Inform lisp of whether frame has been iconified etc. */
5138 if (f)
5140 switch (msg.msg.wParam)
5142 case SIZE_MINIMIZED:
5143 f->async_visible = 0;
5144 f->async_iconified = 1;
5146 inev.kind = ICONIFY_EVENT;
5147 XSETFRAME (inev.frame_or_window, f);
5148 break;
5150 case SIZE_MAXIMIZED:
5151 case SIZE_RESTORED:
5152 f->async_visible = 1;
5153 f->async_iconified = 0;
5155 /* wait_reading_process_output will notice this and update
5156 the frame's display structures. */
5157 SET_FRAME_GARBAGED (f);
5159 if (f->iconified)
5161 int x, y;
5163 /* Reset top and left positions of the Window
5164 here since Windows sends a WM_MOVE message
5165 BEFORE telling us the Window is minimized
5166 when the Window is iconified, with 3000,3000
5167 as the co-ords. */
5168 x_real_positions (f, &x, &y);
5169 f->left_pos = x;
5170 f->top_pos = y;
5172 inev.kind = DEICONIFY_EVENT;
5173 XSETFRAME (inev.frame_or_window, f);
5175 else if (! NILP (Vframe_list)
5176 && ! NILP (XCDR (Vframe_list)))
5177 /* Force a redisplay sooner or later
5178 to update the frame titles
5179 in case this is the second frame. */
5180 record_asynch_buffer_change ();
5181 break;
5185 if (f && !f->async_iconified && msg.msg.wParam != SIZE_MINIMIZED)
5187 RECT rect;
5188 int rows;
5189 int columns;
5190 int width;
5191 int height;
5193 GetClientRect (msg.msg.hwnd, &rect);
5195 height = rect.bottom - rect.top;
5196 width = rect.right - rect.left;
5198 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
5199 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
5201 /* TODO: Clip size to the screen dimensions. */
5203 /* Even if the number of character rows and columns has
5204 not changed, the font size may have changed, so we need
5205 to check the pixel dimensions as well. */
5207 if (columns != FRAME_COLS (f)
5208 || rows != FRAME_LINES (f)
5209 || width != FRAME_PIXEL_WIDTH (f)
5210 || height != FRAME_PIXEL_HEIGHT (f))
5212 change_frame_size (f, rows, columns, 0, 1, 0);
5213 SET_FRAME_GARBAGED (f);
5214 cancel_mouse_face (f);
5215 FRAME_PIXEL_WIDTH (f) = width;
5216 FRAME_PIXEL_HEIGHT (f) = height;
5217 f->win_gravity = NorthWestGravity;
5221 check_visibility = 1;
5222 break;
5224 case WM_MOUSELEAVE:
5225 f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd);
5226 if (f)
5228 if (f == dpyinfo->mouse_face_mouse_frame)
5230 /* If we move outside the frame, then we're
5231 certainly no longer on any text in the frame. */
5232 clear_mouse_face (dpyinfo);
5233 dpyinfo->mouse_face_mouse_frame = 0;
5236 /* Generate a nil HELP_EVENT to cancel a help-echo.
5237 Do it only if there's something to cancel.
5238 Otherwise, the startup message is cleared when
5239 the mouse leaves the frame. */
5240 if (any_help_event_p)
5241 do_help = -1;
5243 break;
5245 case WM_SETFOCUS:
5246 w32_detect_focus_change (dpyinfo, &msg, &inev);
5248 dpyinfo->grabbed = 0;
5249 check_visibility = 1;
5250 break;
5252 case WM_KILLFOCUS:
5253 f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd);
5255 if (f)
5257 if (f == dpyinfo->w32_focus_event_frame)
5258 dpyinfo->w32_focus_event_frame = 0;
5260 if (f == dpyinfo->w32_focus_frame)
5261 x_new_focus_frame (dpyinfo, 0);
5263 if (f == dpyinfo->mouse_face_mouse_frame)
5265 /* If we move outside the frame, then we're
5266 certainly no longer on any text in the frame. */
5267 clear_mouse_face (dpyinfo);
5268 dpyinfo->mouse_face_mouse_frame = 0;
5271 /* Generate a nil HELP_EVENT to cancel a help-echo.
5272 Do it only if there's something to cancel.
5273 Otherwise, the startup message is cleared when
5274 the mouse leaves the frame. */
5275 if (any_help_event_p)
5276 do_help = -1;
5279 dpyinfo->grabbed = 0;
5280 check_visibility = 1;
5281 break;
5283 case WM_CLOSE:
5284 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5286 if (f)
5288 inev.kind = DELETE_WINDOW_EVENT;
5289 XSETFRAME (inev.frame_or_window, f);
5291 break;
5293 case WM_INITMENU:
5294 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5296 if (f)
5298 inev.kind = MENU_BAR_ACTIVATE_EVENT;
5299 XSETFRAME (inev.frame_or_window, f);
5301 break;
5303 case WM_COMMAND:
5304 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5306 if (f)
5308 extern void menubar_selection_callback
5309 (FRAME_PTR f, void * client_data);
5310 menubar_selection_callback (f, (void *)msg.msg.wParam);
5313 check_visibility = 1;
5314 break;
5316 case WM_DISPLAYCHANGE:
5317 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
5319 if (f)
5321 dpyinfo->width = (short) LOWORD (msg.msg.lParam);
5322 dpyinfo->height = (short) HIWORD (msg.msg.lParam);
5323 dpyinfo->n_cbits = msg.msg.wParam;
5324 DebPrint (("display change: %d %d\n", dpyinfo->width,
5325 dpyinfo->height));
5328 check_visibility = 1;
5329 break;
5331 default:
5332 /* Check for messages registered at runtime. */
5333 if (msg.msg.message == msh_mousewheel)
5335 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
5336 msg.msg.message = WM_MOUSEWHEEL;
5337 prepend_msg (&msg);
5339 break;
5342 if (inev.kind != NO_EVENT)
5344 kbd_buffer_store_event_hold (&inev, hold_quit);
5345 count++;
5348 if (do_help
5349 && !(hold_quit && hold_quit->kind != NO_EVENT))
5351 Lisp_Object frame;
5353 if (f)
5354 XSETFRAME (frame, f);
5355 else
5356 frame = Qnil;
5358 if (do_help > 0)
5360 if (NILP (help_echo_string))
5362 help_echo_object = help_echo_window = Qnil;
5363 help_echo_pos = -1;
5366 any_help_event_p = 1;
5367 gen_help_event (help_echo_string, frame, help_echo_window,
5368 help_echo_object, help_echo_pos);
5370 else
5372 help_echo_string = Qnil;
5373 gen_help_event (Qnil, frame, Qnil, Qnil, 0);
5375 count++;
5379 /* If the focus was just given to an autoraising frame,
5380 raise it now. */
5381 /* ??? This ought to be able to handle more than one such frame. */
5382 if (pending_autoraise_frame)
5384 x_raise_frame (pending_autoraise_frame);
5385 pending_autoraise_frame = 0;
5388 /* Check which frames are still visisble, if we have enqueued any user
5389 events or been notified of events that may affect visibility. We
5390 do this here because there doesn't seem to be any direct
5391 notification from Windows that the visibility of a window has
5392 changed (at least, not in all cases). */
5393 if (count > 0 || check_visibility)
5395 Lisp_Object tail, frame;
5397 FOR_EACH_FRAME (tail, frame)
5399 FRAME_PTR f = XFRAME (frame);
5400 /* The tooltip has been drawn already. Avoid the
5401 SET_FRAME_GARBAGED below. */
5402 if (EQ (frame, tip_frame))
5403 continue;
5405 /* Check "visible" frames and mark each as obscured or not.
5406 Note that async_visible is nonzero for unobscured and
5407 obscured frames, but zero for hidden and iconified frames. */
5408 if (FRAME_W32_P (f) && f->async_visible)
5410 RECT clipbox;
5411 HDC hdc;
5413 enter_crit ();
5414 /* Query clipping rectangle for the entire window area
5415 (GetWindowDC), not just the client portion (GetDC).
5416 Otherwise, the scrollbars and menubar aren't counted as
5417 part of the visible area of the frame, and we may think
5418 the frame is obscured when really a scrollbar is still
5419 visible and gets WM_PAINT messages above. */
5420 hdc = GetWindowDC (FRAME_W32_WINDOW (f));
5421 GetClipBox (hdc, &clipbox);
5422 ReleaseDC (FRAME_W32_WINDOW (f), hdc);
5423 leave_crit ();
5425 if (clipbox.right == clipbox.left
5426 || clipbox.bottom == clipbox.top)
5428 /* Frame has become completely obscured so mark as
5429 such (we do this by setting async_visible to 2 so
5430 that FRAME_VISIBLE_P is still true, but redisplay
5431 will skip it). */
5432 f->async_visible = 2;
5434 if (!FRAME_OBSCURED_P (f))
5436 DebPrint (("frame %p (%s) obscured\n", f,
5437 SDATA (f->name)));
5440 else
5442 /* Frame is not obscured, so mark it as such. */
5443 f->async_visible = 1;
5445 if (FRAME_OBSCURED_P (f))
5447 SET_FRAME_GARBAGED (f);
5448 DebPrint (("obscured frame %p (%s) found to be visible\n", f,
5449 SDATA (f->name)));
5451 /* Force a redisplay sooner or later. */
5452 record_asynch_buffer_change ();
5459 UNBLOCK_INPUT;
5460 return count;
5465 /***********************************************************************
5466 Text Cursor
5467 ***********************************************************************/
5469 /* Set clipping for output in glyph row ROW. W is the window in which
5470 we operate. GC is the graphics context to set clipping in.
5472 ROW may be a text row or, e.g., a mode line. Text rows must be
5473 clipped to the interior of the window dedicated to text display,
5474 mode lines must be clipped to the whole window. */
5476 static void
5477 w32_clip_to_row (w, row, area, hdc)
5478 struct window *w;
5479 struct glyph_row *row;
5480 int area;
5481 HDC hdc;
5483 struct frame *f = XFRAME (WINDOW_FRAME (w));
5484 RECT clip_rect;
5485 int window_x, window_y, window_width;
5487 window_box (w, area, &window_x, &window_y, &window_width, 0);
5489 clip_rect.left = window_x;
5490 clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y);
5491 clip_rect.top = max (clip_rect.top, window_y);
5492 clip_rect.right = clip_rect.left + window_width;
5493 clip_rect.bottom = clip_rect.top + row->visible_height;
5495 w32_set_clip_rectangle (hdc, &clip_rect);
5499 /* Draw a hollow box cursor on window W in glyph row ROW. */
5501 static void
5502 x_draw_hollow_cursor (w, row)
5503 struct window *w;
5504 struct glyph_row *row;
5506 struct frame *f = XFRAME (WINDOW_FRAME (w));
5507 HDC hdc;
5508 RECT rect;
5509 int left, top, h;
5510 struct glyph *cursor_glyph;
5511 HBRUSH hb = CreateSolidBrush (f->output_data.w32->cursor_pixel);
5513 /* Get the glyph the cursor is on. If we can't tell because
5514 the current matrix is invalid or such, give up. */
5515 cursor_glyph = get_phys_cursor_glyph (w);
5516 if (cursor_glyph == NULL)
5517 return;
5519 /* Compute frame-relative coordinates for phys cursor. */
5520 get_phys_cursor_geometry (w, row, cursor_glyph, &left, &top, &h);
5521 rect.left = left;
5522 rect.top = top;
5523 rect.bottom = rect.top + h;
5524 rect.right = rect.left + w->phys_cursor_width;
5526 hdc = get_frame_dc (f);
5527 /* Set clipping, draw the rectangle, and reset clipping again. */
5528 w32_clip_to_row (w, row, TEXT_AREA, hdc);
5529 FrameRect (hdc, &rect, hb);
5530 DeleteObject (hb);
5531 w32_set_clip_rectangle (hdc, NULL);
5532 release_frame_dc (f, hdc);
5536 /* Draw a bar cursor on window W in glyph row ROW.
5538 Implementation note: One would like to draw a bar cursor with an
5539 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5540 Unfortunately, I didn't find a font yet that has this property set.
5541 --gerd. */
5543 static void
5544 x_draw_bar_cursor (w, row, width, kind)
5545 struct window *w;
5546 struct glyph_row *row;
5547 int width;
5548 enum text_cursor_kinds kind;
5550 struct frame *f = XFRAME (w->frame);
5551 struct glyph *cursor_glyph;
5552 int x;
5553 HDC hdc;
5555 /* If cursor is out of bounds, don't draw garbage. This can happen
5556 in mini-buffer windows when switching between echo area glyphs
5557 and mini-buffer. */
5558 cursor_glyph = get_phys_cursor_glyph (w);
5559 if (cursor_glyph == NULL)
5560 return;
5562 /* If on an image, draw like a normal cursor. That's usually better
5563 visible than drawing a bar, esp. if the image is large so that
5564 the bar might not be in the window. */
5565 if (cursor_glyph->type == IMAGE_GLYPH)
5567 struct glyph_row *row;
5568 row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos);
5569 draw_phys_cursor_glyph (w, row, DRAW_CURSOR);
5571 else
5573 COLORREF cursor_color = f->output_data.w32->cursor_pixel;
5574 struct face *face = FACE_FROM_ID (f, cursor_glyph->face_id);
5576 /* If the glyph's background equals the color we normally draw
5577 the bar cursor in, the bar cursor in its normal color is
5578 invisible. Use the glyph's foreground color instead in this
5579 case, on the assumption that the glyph's colors are chosen so
5580 that the glyph is legible. */
5581 if (face->background == cursor_color)
5582 cursor_color = face->foreground;
5584 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
5586 if (width < 0)
5587 width = FRAME_CURSOR_WIDTH (f);
5588 width = min (cursor_glyph->pixel_width, width);
5590 w->phys_cursor_width = width;
5593 hdc = get_frame_dc (f);
5594 w32_clip_to_row (w, row, TEXT_AREA, hdc);
5596 if (kind == BAR_CURSOR)
5598 w32_fill_area (f, hdc, cursor_color, x,
5599 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
5600 width, row->height);
5602 else
5604 w32_fill_area (f, hdc, cursor_color, x,
5605 WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y +
5606 row->height - width),
5607 cursor_glyph->pixel_width, width);
5610 w32_set_clip_rectangle (hdc, NULL);
5611 release_frame_dc (f, hdc);
5616 /* RIF: Define cursor CURSOR on frame F. */
5618 static void
5619 w32_define_frame_cursor (f, cursor)
5620 struct frame *f;
5621 Cursor cursor;
5623 w32_define_cursor (FRAME_W32_WINDOW (f), cursor);
5627 /* RIF: Clear area on frame F. */
5629 static void
5630 w32_clear_frame_area (f, x, y, width, height)
5631 struct frame *f;
5632 int x, y, width, height;
5634 HDC hdc;
5636 hdc = get_frame_dc (f);
5637 w32_clear_area (f, hdc, x, y, width, height);
5638 release_frame_dc (f, hdc);
5641 /* RIF: Draw or clear cursor on window W. */
5643 static void
5644 w32_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, active_p)
5645 struct window *w;
5646 struct glyph_row *glyph_row;
5647 int x, y;
5648 int cursor_type, cursor_width;
5649 int on_p, active_p;
5651 if (on_p)
5653 /* If the user wants to use the system caret, make sure our own
5654 cursor remains invisible. */
5655 if (w32_use_visible_system_caret)
5657 /* Call to erase_phys_cursor here seems to use the
5658 wrong values of w->phys_cursor, as they have been
5659 overwritten before this function was called. */
5660 if (w->phys_cursor_type != NO_CURSOR)
5661 erase_phys_cursor (w);
5663 cursor_type = w->phys_cursor_type = NO_CURSOR;
5664 w->phys_cursor_width = -1;
5666 else
5668 w->phys_cursor_type = cursor_type;
5671 w->phys_cursor_on_p = 1;
5673 /* If this is the active cursor, we need to track it with the
5674 system caret, so third party software like screen magnifiers
5675 and speech synthesizers can follow the cursor. */
5676 if (active_p)
5678 struct frame *f = XFRAME (WINDOW_FRAME (w));
5679 HWND hwnd = FRAME_W32_WINDOW (f);
5681 w32_system_caret_x
5682 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
5683 w32_system_caret_y
5684 = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y)
5685 + glyph_row->ascent - w->phys_cursor_ascent);
5687 /* If the size of the active cursor changed, destroy the old
5688 system caret. */
5689 if (w32_system_caret_hwnd
5690 && (w32_system_caret_height != w->phys_cursor_height))
5691 PostMessage (hwnd, WM_EMACS_DESTROY_CARET, 0, 0);
5693 w32_system_caret_height = w->phys_cursor_height;
5695 /* Move the system caret. */
5696 PostMessage (hwnd, WM_EMACS_TRACK_CARET, 0, 0);
5699 if (glyph_row->exact_window_width_line_p
5700 && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])
5702 glyph_row->cursor_in_fringe_p = 1;
5703 draw_fringe_bitmap (w, glyph_row, 0);
5704 return;
5707 switch (cursor_type)
5709 case HOLLOW_BOX_CURSOR:
5710 x_draw_hollow_cursor (w, glyph_row);
5711 break;
5713 case FILLED_BOX_CURSOR:
5714 draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
5715 break;
5717 case BAR_CURSOR:
5718 x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
5719 break;
5721 case HBAR_CURSOR:
5722 x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
5723 break;
5725 case NO_CURSOR:
5726 w->phys_cursor_width = 0;
5727 break;
5729 default:
5730 abort ();
5737 /* Icons. */
5740 x_bitmap_icon (f, icon)
5741 struct frame *f;
5742 Lisp_Object icon;
5744 HANDLE main_icon;
5745 HANDLE small_icon = NULL;
5747 if (FRAME_W32_WINDOW (f) == 0)
5748 return 1;
5750 if (NILP (icon))
5751 main_icon = LoadIcon (hinst, EMACS_CLASS);
5752 else if (STRINGP (icon))
5754 /* Load the main icon from the named file. */
5755 main_icon = LoadImage (NULL, (LPCTSTR) SDATA (icon), IMAGE_ICON, 0, 0,
5756 LR_DEFAULTSIZE | LR_LOADFROMFILE);
5757 /* Try to load a small icon to go with it. */
5758 small_icon = LoadImage (NULL, (LPCSTR) SDATA (icon), IMAGE_ICON,
5759 GetSystemMetrics (SM_CXSMICON),
5760 GetSystemMetrics (SM_CYSMICON),
5761 LR_LOADFROMFILE);
5763 else if (SYMBOLP (icon))
5765 LPCTSTR name;
5767 if (EQ (icon, intern ("application")))
5768 name = (LPCTSTR) IDI_APPLICATION;
5769 else if (EQ (icon, intern ("hand")))
5770 name = (LPCTSTR) IDI_HAND;
5771 else if (EQ (icon, intern ("question")))
5772 name = (LPCTSTR) IDI_QUESTION;
5773 else if (EQ (icon, intern ("exclamation")))
5774 name = (LPCTSTR) IDI_EXCLAMATION;
5775 else if (EQ (icon, intern ("asterisk")))
5776 name = (LPCTSTR) IDI_ASTERISK;
5777 else if (EQ (icon, intern ("winlogo")))
5778 name = (LPCTSTR) IDI_WINLOGO;
5779 else
5780 return 1;
5782 main_icon = LoadIcon (NULL, name);
5784 else
5785 return 1;
5787 if (main_icon == NULL)
5788 return 1;
5790 PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_BIG,
5791 (LPARAM) main_icon);
5793 /* If there is a small icon that goes with it, set that too. */
5794 if (small_icon)
5795 PostMessage (FRAME_W32_WINDOW (f), WM_SETICON, (WPARAM) ICON_SMALL,
5796 (LPARAM) small_icon);
5798 return 0;
5802 /************************************************************************
5803 Handling X errors
5804 ************************************************************************/
5806 /* Display Error Handling functions not used on W32. Listing them here
5807 helps diff stay in step when comparing w32term.c with xterm.c.
5809 x_error_catcher (display, error)
5810 x_catch_errors (dpy)
5811 x_catch_errors_unwind (old_val)
5812 x_check_errors (dpy, format)
5813 x_fully_uncatch_errors ()
5814 x_catching_errors ()
5815 x_had_errors_p (dpy)
5816 x_clear_errors (dpy)
5817 x_uncatch_errors (dpy, count)
5818 x_trace_wire ()
5819 x_connection_signal (signalnum)
5820 x_connection_closed (dpy, error_message)
5821 x_error_quitter (display, error)
5822 x_error_handler (display, error)
5823 x_io_error_quitter (display)
5828 /* Changing the font of the frame. */
5830 /* Give frame F the font named FONTNAME as its default font, and
5831 return the full name of that font. FONTNAME may be a wildcard
5832 pattern; in that case, we choose some font that fits the pattern.
5833 The return value shows which font we chose. */
5835 Lisp_Object
5836 x_new_font (f, fontname)
5837 struct frame *f;
5838 register char *fontname;
5840 struct font_info *fontp
5841 = FS_LOAD_FONT (f, fontname);
5843 if (!fontp)
5844 return Qnil;
5846 if (FRAME_FONT (f) == (XFontStruct *) (fontp->font))
5847 /* This font is already set in frame F. There's nothing more to
5848 do. */
5849 return build_string (fontp->full_name);
5851 FRAME_FONT (f) = (XFontStruct *) (fontp->font);
5852 FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
5853 FRAME_FONTSET (f) = -1;
5855 FRAME_COLUMN_WIDTH (f) = fontp->average_width;
5856 FRAME_SPACE_WIDTH (f) = fontp->space_width;
5857 FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f));
5859 compute_fringe_widths (f, 1);
5861 /* Compute the scroll bar width in character columns. */
5862 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
5864 int wid = FRAME_COLUMN_WIDTH (f);
5865 FRAME_CONFIG_SCROLL_BAR_COLS (f)
5866 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid;
5868 else
5870 int wid = FRAME_COLUMN_WIDTH (f);
5871 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
5874 /* Now make the frame display the given font. */
5875 if (FRAME_W32_WINDOW (f) != 0)
5877 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
5878 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
5881 return build_string (fontp->full_name);
5884 /* Give frame F the fontset named FONTSETNAME as its default fontset,
5885 and return the full name of that fontset. FONTSETNAME may be a
5886 wildcard pattern; in that case, we choose some fontset that fits
5887 the pattern. FONTSETNAME may be a font name for ASCII characters;
5888 in that case, we create a fontset from that font name.
5890 The return value shows which fontset we chose.
5891 If FONTSETNAME specifies the default fontset, return Qt.
5892 If an ASCII font in the specified fontset can't be loaded, return
5893 Qnil. */
5895 Lisp_Object
5896 x_new_fontset (f, fontsetname)
5897 struct frame *f;
5898 Lisp_Object fontsetname;
5900 int fontset = fs_query_fontset (fontsetname, 0);
5901 Lisp_Object result;
5903 if (fontset > 0 && FRAME_FONTSET(f) == fontset)
5904 /* This fontset is already set in frame F. There's nothing more
5905 to do. */
5906 return fontset_name (fontset);
5907 else if (fontset == 0)
5908 /* The default fontset can't be the default font. */
5909 return Qt;
5911 if (fontset > 0)
5912 result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
5913 else
5914 result = x_new_font (f, SDATA (fontsetname));
5916 if (!STRINGP (result))
5917 /* Can't load ASCII font. */
5918 return Qnil;
5920 if (fontset < 0)
5921 fontset = new_fontset_from_font_name (result);
5923 /* Since x_new_font doesn't update any fontset information, do it now. */
5924 FRAME_FONTSET(f) = fontset;
5926 return fontset_name (fontset);
5929 #ifdef USE_FONT_BACKEND
5930 Lisp_Object
5931 x_new_fontset2 (f, fontset, font_object)
5932 struct frame *f;
5933 int fontset;
5934 Lisp_Object font_object;
5936 struct font *font = XSAVE_VALUE (font_object)->pointer;
5938 if (FRAME_FONT_OBJECT (f) == font)
5939 /* This font is already set in frame F. There's nothing more to
5940 do. */
5941 return fontset_name (fontset);
5943 BLOCK_INPUT;
5945 FRAME_FONT_OBJECT (f) = font;
5946 FRAME_FONT (f) = font->font.font;
5947 FRAME_BASELINE_OFFSET (f) = font->font.baseline_offset;
5948 FRAME_FONTSET (f) = fontset;
5950 FRAME_COLUMN_WIDTH (f) = font->font.average_width;
5951 FRAME_SPACE_WIDTH (f) = font->font.space_width;
5952 FRAME_LINE_HEIGHT (f) = font->font.height;
5954 compute_fringe_widths (f, 1);
5956 /* Compute the scroll bar width in character columns. */
5957 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
5959 int wid = FRAME_COLUMN_WIDTH (f);
5960 FRAME_CONFIG_SCROLL_BAR_COLS (f)
5961 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid - 1) / wid;
5963 else
5965 int wid = FRAME_COLUMN_WIDTH (f);
5966 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
5969 /* Now make the frame display the given font. */
5970 if (FRAME_X_WINDOW (f) != 0)
5972 /* Don't change the size of a tip frame; there's no point in
5973 doing it because it's done in Fx_show_tip, and it leads to
5974 problems because the tip frame has no widget. */
5975 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
5976 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
5979 #ifdef HAVE_X_I18N
5980 if (FRAME_XIC (f)
5981 && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
5982 xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
5983 #endif
5985 UNBLOCK_INPUT;
5987 return fontset_name (fontset);
5989 #endif /* USE_FONT_BACKEND */
5992 /***********************************************************************
5993 TODO: W32 Input Methods
5994 ***********************************************************************/
5995 /* Listing missing functions from xterm.c helps diff stay in step.
5997 xim_destroy_callback (xim, client_data, call_data)
5998 xim_open_dpy (dpyinfo, resource_name)
5999 struct xim_inst_t
6000 xim_instantiate_callback (display, client_data, call_data)
6001 xim_initialize (dpyinfo, resource_name)
6002 xim_close_dpy (dpyinfo)
6007 /* Calculate the absolute position in frame F
6008 from its current recorded position values and gravity. */
6010 void
6011 x_calc_absolute_position (f)
6012 struct frame *f;
6014 int flags = f->size_hint_flags;
6016 /* The sum of the widths of the frame's left and right borders, and
6017 the sum of the heights of the frame's top and bottom borders (in
6018 pixels) drawn by Windows. */
6019 unsigned int left_right_borders_width, top_bottom_borders_height;
6021 /* Try to get the actual values of these two variables. We compute
6022 the border width (height) by subtracting the width (height) of
6023 the frame's client area from the width (height) of the frame's
6024 entire window. */
6025 WINDOWPLACEMENT wp = { 0 };
6026 RECT client_rect = { 0 };
6028 if (GetWindowPlacement (FRAME_W32_WINDOW (f), &wp)
6029 && GetClientRect (FRAME_W32_WINDOW (f), &client_rect))
6031 left_right_borders_width =
6032 (wp.rcNormalPosition.right - wp.rcNormalPosition.left) -
6033 (client_rect.right - client_rect.left);
6035 top_bottom_borders_height =
6036 (wp.rcNormalPosition.bottom - wp.rcNormalPosition.top) -
6037 (client_rect.bottom - client_rect.top);
6039 else
6041 /* Use sensible default values. */
6042 left_right_borders_width = 8;
6043 top_bottom_borders_height = 32;
6046 /* Treat negative positions as relative to the rightmost bottommost
6047 position that fits on the screen. */
6048 if (flags & XNegative)
6049 f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
6050 - FRAME_PIXEL_WIDTH (f)
6051 + f->left_pos
6052 - (left_right_borders_width - 1));
6054 if (flags & YNegative)
6055 f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
6056 - FRAME_PIXEL_HEIGHT (f)
6057 + f->top_pos
6058 - (top_bottom_borders_height - 1));
6060 /* The left_pos and top_pos are now relative to the top and left
6061 screen edges, so the flags should correspond. */
6062 f->size_hint_flags &= ~ (XNegative | YNegative);
6065 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
6066 to really change the position, and 0 when calling from
6067 x_make_frame_visible (in that case, XOFF and YOFF are the current
6068 position values). It is -1 when calling from x_set_frame_parameters,
6069 which means, do adjust for borders but don't change the gravity. */
6071 void
6072 x_set_offset (f, xoff, yoff, change_gravity)
6073 struct frame *f;
6074 register int xoff, yoff;
6075 int change_gravity;
6077 int modified_top, modified_left;
6079 if (change_gravity > 0)
6081 f->top_pos = yoff;
6082 f->left_pos = xoff;
6083 f->size_hint_flags &= ~ (XNegative | YNegative);
6084 if (xoff < 0)
6085 f->size_hint_flags |= XNegative;
6086 if (yoff < 0)
6087 f->size_hint_flags |= YNegative;
6088 f->win_gravity = NorthWestGravity;
6090 x_calc_absolute_position (f);
6092 BLOCK_INPUT;
6093 x_wm_set_size_hint (f, (long) 0, 0);
6095 modified_left = f->left_pos;
6096 modified_top = f->top_pos;
6098 my_set_window_pos (FRAME_W32_WINDOW (f),
6099 NULL,
6100 modified_left, modified_top,
6101 0, 0,
6102 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
6103 UNBLOCK_INPUT;
6107 /* Check if we need to resize the frame due to a fullscreen request.
6108 If so needed, resize the frame. */
6109 static void
6110 x_check_fullscreen (f)
6111 struct frame *f;
6113 if (f->want_fullscreen & FULLSCREEN_BOTH)
6115 int width, height, ign;
6117 x_real_positions (f, &f->left_pos, &f->top_pos);
6119 x_fullscreen_adjust (f, &width, &height, &ign, &ign);
6121 /* We do not need to move the window, it shall be taken care of
6122 when setting WM manager hints. */
6123 if (FRAME_COLS (f) != width || FRAME_LINES (f) != height)
6125 change_frame_size (f, height, width, 0, 1, 0);
6126 SET_FRAME_GARBAGED (f);
6127 cancel_mouse_face (f);
6129 /* Wait for the change of frame size to occur */
6130 f->want_fullscreen |= FULLSCREEN_WAIT;
6135 /* Call this to change the size of frame F's x-window.
6136 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
6137 for this size change and subsequent size changes.
6138 Otherwise we leave the window gravity unchanged. */
6140 void
6141 x_set_window_size (f, change_gravity, cols, rows)
6142 struct frame *f;
6143 int change_gravity;
6144 int cols, rows;
6146 int pixelwidth, pixelheight;
6148 BLOCK_INPUT;
6150 check_frame_size (f, &rows, &cols);
6151 f->scroll_bar_actual_width
6152 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
6154 compute_fringe_widths (f, 0);
6156 pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols);
6157 pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
6159 f->win_gravity = NorthWestGravity;
6160 x_wm_set_size_hint (f, (long) 0, 0);
6163 RECT rect;
6165 rect.left = rect.top = 0;
6166 rect.right = pixelwidth;
6167 rect.bottom = pixelheight;
6169 AdjustWindowRect(&rect, f->output_data.w32->dwStyle,
6170 FRAME_EXTERNAL_MENU_BAR (f));
6172 my_set_window_pos (FRAME_W32_WINDOW (f),
6173 NULL,
6174 0, 0,
6175 rect.right - rect.left,
6176 rect.bottom - rect.top,
6177 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
6180 #if 0
6181 /* The following mirrors what is done in xterm.c. It appears to be
6182 for informing lisp of the new size immediately, while the actual
6183 resize will happen asynchronously. But on Windows, the menu bar
6184 automatically wraps when the frame is too narrow to contain it,
6185 and that causes any calculations made here to come out wrong. The
6186 end is some nasty buggy behaviour, including the potential loss
6187 of the minibuffer.
6189 Disabling this code is either not sufficient to fix the problems
6190 completely, or it causes fresh problems, but at least it removes
6191 the most problematic symptom of the minibuffer becoming unusable.
6193 -----------------------------------------------------------------
6195 Now, strictly speaking, we can't be sure that this is accurate,
6196 but the window manager will get around to dealing with the size
6197 change request eventually, and we'll hear how it went when the
6198 ConfigureNotify event gets here.
6200 We could just not bother storing any of this information here,
6201 and let the ConfigureNotify event set everything up, but that
6202 might be kind of confusing to the Lisp code, since size changes
6203 wouldn't be reported in the frame parameters until some random
6204 point in the future when the ConfigureNotify event arrives.
6206 We pass 1 for DELAY since we can't run Lisp code inside of
6207 a BLOCK_INPUT. */
6208 change_frame_size (f, rows, cols, 0, 1, 0);
6209 FRAME_PIXEL_WIDTH (f) = pixelwidth;
6210 FRAME_PIXEL_HEIGHT (f) = pixelheight;
6212 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
6213 receive in the ConfigureNotify event; if we get what we asked
6214 for, then the event won't cause the screen to become garbaged, so
6215 we have to make sure to do it here. */
6216 SET_FRAME_GARBAGED (f);
6218 /* If cursor was outside the new size, mark it as off. */
6219 mark_window_cursors_off (XWINDOW (f->root_window));
6221 /* Clear out any recollection of where the mouse highlighting was,
6222 since it might be in a place that's outside the new frame size.
6223 Actually checking whether it is outside is a pain in the neck,
6224 so don't try--just let the highlighting be done afresh with new size. */
6225 cancel_mouse_face (f);
6226 #endif
6228 UNBLOCK_INPUT;
6231 /* Mouse warping. */
6233 void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
6235 void
6236 x_set_mouse_position (f, x, y)
6237 struct frame *f;
6238 int x, y;
6240 int pix_x, pix_y;
6242 pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
6243 pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
6245 if (pix_x < 0) pix_x = 0;
6246 if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f);
6248 if (pix_y < 0) pix_y = 0;
6249 if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
6251 x_set_mouse_pixel_position (f, pix_x, pix_y);
6254 void
6255 x_set_mouse_pixel_position (f, pix_x, pix_y)
6256 struct frame *f;
6257 int pix_x, pix_y;
6259 RECT rect;
6260 POINT pt;
6262 BLOCK_INPUT;
6264 GetClientRect (FRAME_W32_WINDOW (f), &rect);
6265 pt.x = rect.left + pix_x;
6266 pt.y = rect.top + pix_y;
6267 ClientToScreen (FRAME_W32_WINDOW (f), &pt);
6269 SetCursorPos (pt.x, pt.y);
6271 UNBLOCK_INPUT;
6275 /* focus shifting, raising and lowering. */
6277 void
6278 x_focus_on_frame (f)
6279 struct frame *f;
6281 struct w32_display_info *dpyinfo = &one_w32_display_info;
6283 /* Give input focus to frame. */
6284 BLOCK_INPUT;
6285 #if 0
6286 /* Try not to change its Z-order if possible. */
6287 if (x_window_to_frame (dpyinfo, GetForegroundWindow ()))
6288 my_set_focus (f, FRAME_W32_WINDOW (f));
6289 else
6290 #endif
6291 my_set_foreground_window (FRAME_W32_WINDOW (f));
6292 UNBLOCK_INPUT;
6295 void
6296 x_unfocus_frame (f)
6297 struct frame *f;
6301 /* Raise frame F. */
6302 void
6303 x_raise_frame (f)
6304 struct frame *f;
6306 BLOCK_INPUT;
6308 /* Strictly speaking, raise-frame should only change the frame's Z
6309 order, leaving input focus unchanged. This is reasonable behaviour
6310 on X where the usual policy is point-to-focus. However, this
6311 behaviour would be very odd on Windows where the usual policy is
6312 click-to-focus.
6314 On X, if the mouse happens to be over the raised frame, it gets
6315 input focus anyway (so the window with focus will never be
6316 completely obscured) - if not, then just moving the mouse over it
6317 is sufficient to give it focus. On Windows, the user must actually
6318 click on the frame (preferrably the title bar so as not to move
6319 point), which is more awkward. Also, no other Windows program
6320 raises a window to the top but leaves another window (possibly now
6321 completely obscured) with input focus.
6323 Because there is a system setting on Windows that allows the user
6324 to choose the point to focus policy, we make the strict semantics
6325 optional, but by default we grab focus when raising. */
6327 if (NILP (Vw32_grab_focus_on_raise))
6329 /* The obvious call to my_set_window_pos doesn't work if Emacs is
6330 not already the foreground application: the frame is raised
6331 above all other frames belonging to us, but not above the
6332 current top window. To achieve that, we have to resort to this
6333 more cumbersome method. */
6335 HDWP handle = BeginDeferWindowPos (2);
6336 if (handle)
6338 DeferWindowPos (handle,
6339 FRAME_W32_WINDOW (f),
6340 HWND_TOP,
6341 0, 0, 0, 0,
6342 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6344 DeferWindowPos (handle,
6345 GetForegroundWindow (),
6346 FRAME_W32_WINDOW (f),
6347 0, 0, 0, 0,
6348 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6350 EndDeferWindowPos (handle);
6353 else
6355 my_set_foreground_window (FRAME_W32_WINDOW (f));
6358 UNBLOCK_INPUT;
6361 /* Lower frame F. */
6362 void
6363 x_lower_frame (f)
6364 struct frame *f;
6366 BLOCK_INPUT;
6367 my_set_window_pos (FRAME_W32_WINDOW (f),
6368 HWND_BOTTOM,
6369 0, 0, 0, 0,
6370 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
6371 UNBLOCK_INPUT;
6374 static void
6375 w32_frame_raise_lower (f, raise_flag)
6376 FRAME_PTR f;
6377 int raise_flag;
6379 if (! FRAME_W32_P (f))
6380 return;
6382 if (raise_flag)
6383 x_raise_frame (f);
6384 else
6385 x_lower_frame (f);
6388 /* Change of visibility. */
6390 /* This tries to wait until the frame is really visible.
6391 However, if the window manager asks the user where to position
6392 the frame, this will return before the user finishes doing that.
6393 The frame will not actually be visible at that time,
6394 but it will become visible later when the window manager
6395 finishes with it. */
6397 void
6398 x_make_frame_visible (f)
6399 struct frame *f;
6401 Lisp_Object type;
6403 BLOCK_INPUT;
6405 type = x_icon_type (f);
6406 if (!NILP (type))
6407 x_bitmap_icon (f, type);
6409 if (! FRAME_VISIBLE_P (f))
6411 /* We test FRAME_GARBAGED_P here to make sure we don't
6412 call x_set_offset a second time
6413 if we get to x_make_frame_visible a second time
6414 before the window gets really visible. */
6415 if (! FRAME_ICONIFIED_P (f)
6416 && ! f->output_data.w32->asked_for_visible)
6418 RECT workarea_rect;
6419 RECT window_rect;
6421 /* Adjust vertical window position in order to avoid being
6422 covered by a task bar placed at the bottom of the desktop. */
6423 SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea_rect, 0);
6424 GetWindowRect(FRAME_W32_WINDOW(f), &window_rect);
6425 if (window_rect.bottom > workarea_rect.bottom
6426 && window_rect.top > workarea_rect.top)
6427 f->top_pos = max (window_rect.top
6428 - window_rect.bottom + workarea_rect.bottom,
6429 workarea_rect.top);
6431 x_set_offset (f, f->left_pos, f->top_pos, 0);
6434 f->output_data.w32->asked_for_visible = 1;
6436 /* my_show_window (f, FRAME_W32_WINDOW (f), f->async_iconified ? SW_RESTORE : SW_SHOW); */
6437 my_show_window (f, FRAME_W32_WINDOW (f), SW_SHOWNORMAL);
6440 /* Synchronize to ensure Emacs knows the frame is visible
6441 before we do anything else. We do this loop with input not blocked
6442 so that incoming events are handled. */
6444 Lisp_Object frame;
6445 int count;
6447 /* This must come after we set COUNT. */
6448 UNBLOCK_INPUT;
6450 XSETFRAME (frame, f);
6452 /* Wait until the frame is visible. Process X events until a
6453 MapNotify event has been seen, or until we think we won't get a
6454 MapNotify at all.. */
6455 for (count = input_signal_count + 10;
6456 input_signal_count < count && !FRAME_VISIBLE_P (f);)
6458 /* Force processing of queued events. */
6459 /* TODO: x_sync equivalent? */
6461 /* Machines that do polling rather than SIGIO have been observed
6462 to go into a busy-wait here. So we'll fake an alarm signal
6463 to let the handler know that there's something to be read.
6464 We used to raise a real alarm, but it seems that the handler
6465 isn't always enabled here. This is probably a bug. */
6466 if (input_polling_used ())
6468 /* It could be confusing if a real alarm arrives while processing
6469 the fake one. Turn it off and let the handler reset it. */
6470 int old_poll_suppress_count = poll_suppress_count;
6471 poll_suppress_count = 1;
6472 poll_for_input_1 ();
6473 poll_suppress_count = old_poll_suppress_count;
6476 FRAME_SAMPLE_VISIBILITY (f);
6480 /* Change from mapped state to withdrawn state. */
6482 /* Make the frame visible (mapped and not iconified). */
6484 x_make_frame_invisible (f)
6485 struct frame *f;
6487 /* Don't keep the highlight on an invisible frame. */
6488 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f)
6489 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0;
6491 BLOCK_INPUT;
6493 my_show_window (f, FRAME_W32_WINDOW (f), SW_HIDE);
6495 /* We can't distinguish this from iconification
6496 just by the event that we get from the server.
6497 So we can't win using the usual strategy of letting
6498 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
6499 and synchronize with the server to make sure we agree. */
6500 f->visible = 0;
6501 FRAME_ICONIFIED_P (f) = 0;
6502 f->async_visible = 0;
6503 f->async_iconified = 0;
6505 UNBLOCK_INPUT;
6508 /* Change window state from mapped to iconified. */
6510 void
6511 x_iconify_frame (f)
6512 struct frame *f;
6514 Lisp_Object type;
6516 /* Don't keep the highlight on an invisible frame. */
6517 if (FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame == f)
6518 FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame = 0;
6520 if (f->async_iconified)
6521 return;
6523 BLOCK_INPUT;
6525 type = x_icon_type (f);
6526 if (!NILP (type))
6527 x_bitmap_icon (f, type);
6529 /* Simulate the user minimizing the frame. */
6530 SendMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0);
6532 UNBLOCK_INPUT;
6536 /* Free X resources of frame F. */
6538 void
6539 x_free_frame_resources (f)
6540 struct frame *f;
6542 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6544 BLOCK_INPUT;
6546 #ifdef USE_FONT_BACKEND
6547 /* We must free faces before destroying windows because some
6548 font-driver (e.g. xft) access a window while finishing a
6549 face. */
6550 if (enable_font_backend
6551 && FRAME_FACE_CACHE (f))
6552 free_frame_faces (f);
6553 #endif /* USE_FONT_BACKEND */
6555 if (FRAME_W32_WINDOW (f))
6556 my_destroy_window (f, FRAME_W32_WINDOW (f));
6558 free_frame_menubar (f);
6560 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
6561 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
6562 unload_color (f, f->output_data.w32->cursor_pixel);
6563 unload_color (f, f->output_data.w32->cursor_foreground_pixel);
6564 unload_color (f, f->output_data.w32->border_pixel);
6565 unload_color (f, f->output_data.w32->mouse_pixel);
6566 if (f->output_data.w32->white_relief.allocated_p)
6567 unload_color (f, f->output_data.w32->white_relief.pixel);
6568 if (f->output_data.w32->black_relief.allocated_p)
6569 unload_color (f, f->output_data.w32->black_relief.pixel);
6571 if (FRAME_FACE_CACHE (f))
6572 free_frame_faces (f);
6574 xfree (f->output_data.w32);
6575 f->output_data.w32 = NULL;
6577 if (f == dpyinfo->w32_focus_frame)
6578 dpyinfo->w32_focus_frame = 0;
6579 if (f == dpyinfo->w32_focus_event_frame)
6580 dpyinfo->w32_focus_event_frame = 0;
6581 if (f == dpyinfo->x_highlight_frame)
6582 dpyinfo->x_highlight_frame = 0;
6584 if (f == dpyinfo->mouse_face_mouse_frame)
6586 dpyinfo->mouse_face_beg_row
6587 = dpyinfo->mouse_face_beg_col = -1;
6588 dpyinfo->mouse_face_end_row
6589 = dpyinfo->mouse_face_end_col = -1;
6590 dpyinfo->mouse_face_window = Qnil;
6591 dpyinfo->mouse_face_deferred_gc = 0;
6592 dpyinfo->mouse_face_mouse_frame = 0;
6595 UNBLOCK_INPUT;
6599 /* Destroy the window of frame F. */
6600 void
6601 x_destroy_window (f)
6602 struct frame *f;
6604 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6606 x_free_frame_resources (f);
6607 dpyinfo->reference_count--;
6611 /* Setting window manager hints. */
6613 /* Set the normal size hints for the window manager, for frame F.
6614 FLAGS is the flags word to use--or 0 meaning preserve the flags
6615 that the window now has.
6616 If USER_POSITION is nonzero, we set the USPosition
6617 flag (this is useful when FLAGS is 0). */
6618 void
6619 x_wm_set_size_hint (f, flags, user_position)
6620 struct frame *f;
6621 long flags;
6622 int user_position;
6624 Window window = FRAME_W32_WINDOW (f);
6626 enter_crit ();
6628 SetWindowLong (window, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f));
6629 SetWindowLong (window, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f));
6630 SetWindowLong (window, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f));
6631 SetWindowLong (window, WND_SCROLLBAR_INDEX, f->scroll_bar_actual_width);
6633 leave_crit ();
6636 /* Window manager things */
6637 void
6638 x_wm_set_icon_position (f, icon_x, icon_y)
6639 struct frame *f;
6640 int icon_x, icon_y;
6642 #if 0
6643 Window window = FRAME_W32_WINDOW (f);
6645 f->display.x->wm_hints.flags |= IconPositionHint;
6646 f->display.x->wm_hints.icon_x = icon_x;
6647 f->display.x->wm_hints.icon_y = icon_y;
6649 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
6650 #endif
6654 /***********************************************************************
6655 Fonts
6656 ***********************************************************************/
6658 /* The following functions are listed here to help diff stay in step
6659 with xterm.c. See w32fns.c for definitions.
6661 x_get_font_info (f, font_idx)
6662 x_list_fonts (f, pattern, size, maxnames)
6666 #if GLYPH_DEBUG
6668 /* Check that FONT is valid on frame F. It is if it can be found in F's
6669 font table. */
6671 static void
6672 x_check_font (f, font)
6673 struct frame *f;
6674 XFontStruct *font;
6676 int i;
6677 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6679 xassert (font != NULL);
6681 for (i = 0; i < dpyinfo->n_fonts; i++)
6682 if (dpyinfo->font_table[i].name
6683 && font == dpyinfo->font_table[i].font)
6684 break;
6686 xassert (i < dpyinfo->n_fonts);
6689 #endif /* GLYPH_DEBUG != 0 */
6691 /* Set *W to the minimum width, *H to the minimum font height of FONT.
6692 Note: There are (broken) X fonts out there with invalid XFontStruct
6693 min_bounds contents. For example, handa@etl.go.jp reports that
6694 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
6695 have font->min_bounds.width == 0. */
6697 static INLINE void
6698 x_font_min_bounds (font, w, h)
6699 XFontStruct *font;
6700 int *w, *h;
6703 * TODO: Windows does not appear to offer min bound, only
6704 * average and maximum width, and maximum height.
6706 *h = FONT_HEIGHT (font);
6707 *w = FONT_AVG_WIDTH (font);
6711 /* Compute the smallest character width and smallest font height over
6712 all fonts available on frame F. Set the members smallest_char_width
6713 and smallest_font_height in F's x_display_info structure to
6714 the values computed. Value is non-zero if smallest_font_height or
6715 smallest_char_width become smaller than they were before. */
6718 x_compute_min_glyph_bounds (f)
6719 struct frame *f;
6721 int i;
6722 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
6723 XFontStruct *font;
6724 int old_width = dpyinfo->smallest_char_width;
6725 int old_height = dpyinfo->smallest_font_height;
6727 dpyinfo->smallest_font_height = 100000;
6728 dpyinfo->smallest_char_width = 100000;
6730 for (i = 0; i < dpyinfo->n_fonts; ++i)
6731 if (dpyinfo->font_table[i].name)
6733 struct font_info *fontp = dpyinfo->font_table + i;
6734 int w, h;
6736 font = (XFontStruct *) fontp->font;
6737 xassert (font != (XFontStruct *) ~0);
6738 x_font_min_bounds (font, &w, &h);
6740 dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h);
6741 dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w);
6744 xassert (dpyinfo->smallest_char_width > 0
6745 && dpyinfo->smallest_font_height > 0);
6747 return (dpyinfo->n_fonts == 1
6748 || dpyinfo->smallest_char_width < old_width
6749 || dpyinfo->smallest_font_height < old_height);
6752 /* The following functions are listed here to help diff stay in step
6753 with xterm.c. See w32fns.c for definitions.
6755 x_load_font (f, fontname, size)
6756 x_query_font (f, fontname)
6757 x_find_ccl_program (fontp)
6761 /***********************************************************************
6762 Initialization
6763 ***********************************************************************/
6765 static int w32_initialized = 0;
6767 void
6768 w32_initialize_display_info (display_name)
6769 Lisp_Object display_name;
6771 struct w32_display_info *dpyinfo = &one_w32_display_info;
6773 bzero (dpyinfo, sizeof (*dpyinfo));
6775 /* Put it on w32_display_name_list. */
6776 w32_display_name_list = Fcons (Fcons (display_name, Qnil),
6777 w32_display_name_list);
6778 dpyinfo->name_list_element = XCAR (w32_display_name_list);
6780 dpyinfo->w32_id_name
6781 = (char *) xmalloc (SCHARS (Vinvocation_name)
6782 + SCHARS (Vsystem_name)
6783 + 2);
6784 sprintf (dpyinfo->w32_id_name, "%s@%s",
6785 SDATA (Vinvocation_name), SDATA (Vsystem_name));
6787 /* Default Console mode values - overridden when running in GUI mode
6788 with values obtained from system metrics. */
6789 dpyinfo->resx = 1;
6790 dpyinfo->resy = 1;
6791 dpyinfo->height_in = 1;
6792 dpyinfo->width_in = 1;
6793 dpyinfo->n_planes = 1;
6794 dpyinfo->n_cbits = 4;
6795 dpyinfo->n_fonts = 0;
6796 dpyinfo->smallest_font_height = 1;
6797 dpyinfo->smallest_char_width = 1;
6799 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
6800 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
6801 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
6802 dpyinfo->mouse_face_window = Qnil;
6803 dpyinfo->mouse_face_overlay = Qnil;
6804 dpyinfo->mouse_face_hidden = 0;
6806 dpyinfo->vertical_scroll_bar_cursor = w32_load_cursor (IDC_ARROW);
6807 /* TODO: dpyinfo->gray */
6811 /* Create an xrdb-style database of resources to supercede registry settings.
6812 The database is just a concatenation of C strings, finished by an additional
6813 \0. The strings are submitted to some basic normalization, so
6815 [ *]option[ *]:[ *]value...
6817 becomes
6819 option:value...
6821 but any whitespace following value is not removed. */
6823 static char *
6824 w32_make_rdb (xrm_option)
6825 char *xrm_option;
6827 char *buffer = xmalloc (strlen (xrm_option) + 2);
6828 char *current = buffer;
6829 char ch;
6830 int in_option = 1;
6831 int before_value = 0;
6833 do {
6834 ch = *xrm_option++;
6836 if (ch == '\n')
6838 *current++ = '\0';
6839 in_option = 1;
6840 before_value = 0;
6842 else if (ch != ' ')
6844 *current++ = ch;
6845 if (in_option && (ch == ':'))
6847 in_option = 0;
6848 before_value = 1;
6850 else if (before_value)
6852 before_value = 0;
6855 else if (!(in_option || before_value))
6857 *current++ = ch;
6859 } while (ch);
6861 *current = '\0';
6863 return buffer;
6866 void
6867 x_flush (struct frame * f)
6868 { /* Nothing to do */ }
6871 extern frame_parm_handler w32_frame_parm_handlers[];
6873 static struct redisplay_interface w32_redisplay_interface =
6875 w32_frame_parm_handlers,
6876 x_produce_glyphs,
6877 x_write_glyphs,
6878 x_insert_glyphs,
6879 x_clear_end_of_line,
6880 x_scroll_run,
6881 x_after_update_window_line,
6882 x_update_window_begin,
6883 x_update_window_end,
6884 x_cursor_to,
6885 x_flush,
6886 0, /* flush_display_optional */
6887 x_clear_window_mouse_face,
6888 w32_get_glyph_overhangs,
6889 x_fix_overlapping_area,
6890 w32_draw_fringe_bitmap,
6891 w32_define_fringe_bitmap,
6892 w32_destroy_fringe_bitmap,
6893 w32_per_char_metric,
6894 w32_encode_char,
6895 NULL, /* w32_compute_glyph_string_overhangs */
6896 x_draw_glyph_string,
6897 w32_define_frame_cursor,
6898 w32_clear_frame_area,
6899 w32_draw_window_cursor,
6900 w32_draw_vertical_window_border,
6901 w32_shift_glyphs_for_insert
6904 static void x_delete_terminal (struct terminal *term);
6906 static struct terminal *
6907 w32_create_terminal (struct w32_display_info *dpyinfo)
6909 struct terminal *terminal;
6911 terminal = create_terminal ();
6913 terminal->type = output_w32;
6914 terminal->display_info.w32 = dpyinfo;
6915 dpyinfo->terminal = terminal;
6917 /* MSVC does not type K&R functions with no arguments correctly, and
6918 so we must explicitly cast them. */
6919 terminal->clear_frame_hook = x_clear_frame;
6920 terminal->ins_del_lines_hook = x_ins_del_lines;
6921 terminal->delete_glyphs_hook = x_delete_glyphs;
6922 terminal->ring_bell_hook = w32_ring_bell;
6923 terminal->reset_terminal_modes_hook = w32_reset_terminal_modes;
6924 terminal->set_terminal_modes_hook = w32_set_terminal_modes;
6925 terminal->update_begin_hook = x_update_begin;
6926 terminal->update_end_hook = x_update_end;
6927 terminal->set_terminal_window_hook = w32_set_terminal_window;
6928 terminal->read_socket_hook = w32_read_socket;
6929 terminal->frame_up_to_date_hook = w32_frame_up_to_date;
6930 terminal->mouse_position_hook = w32_mouse_position;
6931 terminal->frame_rehighlight_hook = w32_frame_rehighlight;
6932 terminal->frame_raise_lower_hook = w32_frame_raise_lower;
6933 // terminal->fullscreen_hook = XTfullscreen_hook;
6934 terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6935 terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6936 terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6937 terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
6939 terminal->delete_frame_hook = x_destroy_window;
6940 terminal->delete_terminal_hook = x_delete_terminal;
6942 terminal->rif = &w32_redisplay_interface;
6943 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
6944 terminal->char_ins_del_ok = 1;
6945 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
6946 terminal->fast_clear_end_of_line = 1; /* X does this well. */
6947 terminal->memory_below_frame = 0; /* We don't remember what scrolls
6948 off the bottom. */
6950 #ifdef MULTI_KBOARD
6951 /* We don't yet support separate terminals on W32, so don't try to share
6952 keyboards between virtual terminals that are on the same physical
6953 terminal like X does. */
6954 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
6955 init_kboard (terminal->kboard);
6956 terminal->kboard->Vwindow_system = intern ("w32");
6957 terminal->kboard->next_kboard = all_kboards;
6958 all_kboards = terminal->kboard;
6959 /* Don't let the initial kboard remain current longer than necessary.
6960 That would cause problems if a file loaded on startup tries to
6961 prompt in the mini-buffer. */
6962 if (current_kboard == initial_kboard)
6963 current_kboard = terminal->kboard;
6964 terminal->kboard->reference_count++;
6965 #endif
6967 return terminal;
6970 static void
6971 x_delete_terminal (struct terminal *terminal)
6973 struct w32_display_info *dpyinfo = terminal->display_info.w32;
6974 int i;
6976 /* Protect against recursive calls. Fdelete_frame in
6977 delete_terminal calls us back when it deletes our last frame. */
6978 if (!terminal->name)
6979 return;
6981 BLOCK_INPUT;
6982 /* Free the fonts in the font table. */
6983 for (i = 0; i < dpyinfo->n_fonts; i++)
6984 if (dpyinfo->font_table[i].name)
6986 DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont);
6989 x_delete_display (dpyinfo);
6990 UNBLOCK_INPUT;
6993 struct w32_display_info *
6994 w32_term_init (display_name, xrm_option, resource_name)
6995 Lisp_Object display_name;
6996 char *xrm_option;
6997 char *resource_name;
6999 struct w32_display_info *dpyinfo;
7000 struct terminal *terminal;
7001 HDC hdc;
7003 BLOCK_INPUT;
7005 if (!w32_initialized)
7007 w32_initialize ();
7008 w32_initialized = 1;
7011 w32_initialize_display_info (display_name);
7013 dpyinfo = &one_w32_display_info;
7014 terminal = w32_create_terminal (dpyinfo);
7016 /* Set the name of the terminal. */
7017 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
7018 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
7019 terminal->name[SBYTES (display_name)] = 0;
7021 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
7023 /* Put this display on the chain. */
7024 dpyinfo->next = x_display_list;
7025 x_display_list = dpyinfo;
7027 hdc = GetDC (GetDesktopWindow ());
7029 dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
7030 dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
7031 dpyinfo->root_window = GetDesktopWindow ();
7032 dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES);
7033 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
7034 dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX);
7035 dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
7036 dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
7037 dpyinfo->terminal->image_cache = make_image_cache ();
7038 dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
7039 dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
7040 ReleaseDC (GetDesktopWindow (), hdc);
7042 /* initialise palette with white and black */
7044 XColor color;
7045 w32_defined_color (0, "white", &color, 1);
7046 w32_defined_color (0, "black", &color, 1);
7049 /* Add the default keyboard. */
7050 add_keyboard_wait_descriptor (0);
7052 /* Create Fringe Bitmaps and store them for later use.
7054 On W32, bitmaps are all unsigned short, as Windows requires
7055 bitmap data to be Word aligned. For some reason they are
7056 horizontally reflected compared to how they appear on X, so we
7057 need to bitswap and convert to unsigned shorts before creating
7058 the bitmaps. */
7059 w32_init_fringe (terminal->rif);
7061 #ifdef F_SETOWN
7062 fcntl (connection, F_SETOWN, getpid ());
7063 #endif /* ! defined (F_SETOWN) */
7065 #ifdef SIGIO
7066 if (interrupt_input)
7067 init_sigio (connection);
7068 #endif /* ! defined (SIGIO) */
7070 UNBLOCK_INPUT;
7072 return dpyinfo;
7075 /* Get rid of display DPYINFO, assuming all frames are already gone. */
7076 void
7077 x_delete_display (dpyinfo)
7078 struct w32_display_info *dpyinfo;
7080 /* Discard this display from w32_display_name_list and w32_display_list.
7081 We can't use Fdelq because that can quit. */
7082 if (! NILP (w32_display_name_list)
7083 && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element))
7084 w32_display_name_list = XCDR (w32_display_name_list);
7085 else
7087 Lisp_Object tail;
7089 tail = w32_display_name_list;
7090 while (CONSP (tail) && CONSP (XCDR (tail)))
7092 if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element))
7094 XSETCDR (tail, XCDR (XCDR (tail)));
7095 break;
7097 tail = XCDR (tail);
7101 /* free palette table */
7103 struct w32_palette_entry * plist;
7105 plist = dpyinfo->color_list;
7106 while (plist)
7108 struct w32_palette_entry * pentry = plist;
7109 plist = plist->next;
7110 xfree (pentry);
7112 dpyinfo->color_list = NULL;
7113 if (dpyinfo->palette)
7114 DeleteObject(dpyinfo->palette);
7116 xfree (dpyinfo->font_table);
7117 xfree (dpyinfo->w32_id_name);
7119 w32_reset_fringes ();
7122 /* Set up use of W32. */
7124 DWORD WINAPI w32_msg_worker (void * arg);
7126 static void
7127 w32_initialize ()
7129 baud_rate = 19200;
7131 w32_system_caret_hwnd = NULL;
7132 w32_system_caret_height = 0;
7133 w32_system_caret_x = 0;
7134 w32_system_caret_y = 0;
7136 /* Initialize w32_use_visible_system_caret based on whether a screen
7137 reader is in use. */
7138 if (!SystemParametersInfo (SPI_GETSCREENREADER, 0,
7139 &w32_use_visible_system_caret, 0))
7140 w32_use_visible_system_caret = 0;
7142 last_tool_bar_item = -1;
7143 any_help_event_p = 0;
7145 /* Initialize input mode: interrupt_input off, no flow control, allow
7146 8 bit character input, standard quit char. */
7147 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
7149 /* Create the window thread - it will terminate itself or when the app terminates */
7151 init_crit ();
7153 dwMainThreadId = GetCurrentThreadId ();
7154 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
7155 GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS);
7157 /* Wait for thread to start */
7160 MSG msg;
7162 PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE);
7164 hWindowsThread = CreateThread (NULL, 0,
7165 w32_msg_worker,
7166 0, 0, &dwWindowsThreadId);
7168 GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
7171 /* It is desirable that mainThread should have the same notion of
7172 focus window and active window as windowsThread. Unfortunately, the
7173 following call to AttachThreadInput, which should do precisely what
7174 we need, causes major problems when Emacs is linked as a console
7175 program. Unfortunately, we have good reasons for doing that, so
7176 instead we need to send messages to windowsThread to make some API
7177 calls for us (ones that affect, or depend on, the active/focus
7178 window state. */
7179 #ifdef ATTACH_THREADS
7180 AttachThreadInput (dwMainThreadId, dwWindowsThreadId, TRUE);
7181 #endif
7183 /* Dynamically link to optional system components. */
7185 UINT smoothing_type;
7186 BOOL smoothing_enabled;
7188 HANDLE gdi_lib = LoadLibrary ("gdi32.dll");
7190 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
7192 LOAD_PROC (gdi_lib, GetFontUnicodeRanges);
7194 #undef LOAD_PROC
7196 FreeLibrary (gdi_lib);
7198 /* Ensure scrollbar handle is at least 5 pixels. */
7199 vertical_scroll_bar_min_handle = 5;
7201 /* For either kind of scroll bar, take account of the arrows; these
7202 effectively form the border of the main scroll bar range. */
7203 vertical_scroll_bar_top_border = vertical_scroll_bar_bottom_border
7204 = GetSystemMetrics (SM_CYVSCROLL);
7206 /* Constants that are not always defined by the system headers
7207 since they only exist on certain versions of Windows. */
7208 #ifndef SPI_GETFONTSMOOTHING
7209 #define SPI_GETFONTSMOOTHING 0x4A
7210 #endif
7211 #ifndef SPI_GETFONTSMOOTHINGTYPE
7212 #define SPI_GETFONTSMOOTHINGTYPE 0x0200A
7213 #endif
7214 #ifndef FE_FONTSMOOTHINGCLEARTYPE
7215 #define FE_FONTSMOOTHINGCLEARTYPE 0x2
7216 #endif
7218 /* Determine if Cleartype is in use. Used to enable a hack in
7219 the char metric calculations which adds extra pixels to
7220 compensate for the "sub-pixels" that are not counted by the
7221 system APIs. */
7222 cleartype_active =
7223 SystemParametersInfo (SPI_GETFONTSMOOTHING, 0, &smoothing_enabled, 0)
7224 && smoothing_enabled
7225 && SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type, 0)
7226 && smoothing_type == FE_FONTSMOOTHINGCLEARTYPE;
7230 void
7231 syms_of_w32term ()
7233 staticpro (&w32_display_name_list);
7234 w32_display_name_list = Qnil;
7236 staticpro (&last_mouse_scroll_bar);
7237 last_mouse_scroll_bar = Qnil;
7239 DEFSYM (Qvendor_specific_keysyms, "vendor-specific-keysyms");
7241 DEFVAR_INT ("w32-num-mouse-buttons",
7242 &w32_num_mouse_buttons,
7243 doc: /* Number of physical mouse buttons. */);
7244 w32_num_mouse_buttons = 2;
7246 DEFVAR_LISP ("w32-swap-mouse-buttons",
7247 &Vw32_swap_mouse_buttons,
7248 doc: /* Swap the mapping of middle and right mouse buttons.
7249 When nil, middle button is mouse-2 and right button is mouse-3. */);
7250 Vw32_swap_mouse_buttons = Qnil;
7252 DEFVAR_LISP ("w32-grab-focus-on-raise",
7253 &Vw32_grab_focus_on_raise,
7254 doc: /* Raised frame grabs input focus.
7255 When t, `raise-frame' grabs input focus as well. This fits well
7256 with the normal Windows click-to-focus policy, but might not be
7257 desirable when using a point-to-focus policy. */);
7258 Vw32_grab_focus_on_raise = Qt;
7260 DEFVAR_LISP ("w32-capslock-is-shiftlock",
7261 &Vw32_capslock_is_shiftlock,
7262 doc: /* Apply CapsLock state to non character input keys.
7263 When nil, CapsLock only affects normal character input keys. */);
7264 Vw32_capslock_is_shiftlock = Qnil;
7266 DEFVAR_LISP ("w32-recognize-altgr",
7267 &Vw32_recognize_altgr,
7268 doc: /* Recognize right-alt and left-ctrl as AltGr.
7269 When nil, the right-alt and left-ctrl key combination is
7270 interpreted normally. */);
7271 Vw32_recognize_altgr = Qt;
7273 DEFVAR_BOOL ("w32-enable-unicode-output",
7274 &w32_enable_unicode_output,
7275 doc: /* Enable the use of Unicode for text output if non-nil.
7276 Unicode output may prevent some third party applications for displaying
7277 Far-East Languages on Windows 95/98 from working properly.
7278 NT uses Unicode internally anyway, so this flag will probably have no
7279 effect on NT machines. */);
7280 w32_enable_unicode_output = 1;
7282 DEFVAR_BOOL ("w32-use-visible-system-caret",
7283 &w32_use_visible_system_caret,
7284 doc: /* Flag to make the system caret visible.
7285 When this is non-nil, Emacs will indicate the position of point by
7286 using the system caret instead of drawing its own cursor. Some screen
7287 reader software does not track the system cursor properly when it is
7288 invisible, and gets confused by Emacs drawing its own cursor, so this
7289 variable is initialized to t when Emacs detects that screen reader
7290 software is running as it starts up.
7292 When this variable is set, other variables affecting the appearance of
7293 the cursor have no effect. */);
7295 w32_use_visible_system_caret = 0;
7297 /* We don't yet support this, but defining this here avoids whining
7298 from cus-start.el and other places, like "M-x set-variable". */
7299 DEFVAR_BOOL ("x-use-underline-position-properties",
7300 &x_use_underline_position_properties,
7301 doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
7302 A value of nil means ignore them. If you encounter fonts with bogus
7303 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7304 to 4.1, set this to nil.
7306 NOTE: Not supported on MS-Windows yet. */);
7307 x_use_underline_position_properties = 0;
7309 DEFVAR_BOOL ("x-underline-at-descent-line",
7310 &x_underline_at_descent_line,
7311 doc: /* *Non-nil means to draw the underline at the same place as the descent line.
7312 A value of nil means to draw the underline according to the value of the
7313 variable `x-use-underline-position-properties', which is usually at the
7314 baseline level. The default value is nil. */);
7315 x_underline_at_descent_line = 0;
7317 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
7318 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
7319 Vx_toolkit_scroll_bars = Qt;
7321 staticpro (&last_mouse_motion_frame);
7322 last_mouse_motion_frame = Qnil;
7325 /* arch-tag: 5fa70624-ab86-499c-8a85-473958ee4646
7326 (do not change this comment) */