1 /* Implementation of GUI terminal on the Microsoft Windows API.
3 Copyright (C) 1989, 1993-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24 #include "blockinput.h"
36 #include "character.h"
40 #include "dispextern.h"
42 #include "termhooks.h"
49 #include "intervals.h"
56 #include "w32.h" /* for filename_from_utf16, filename_from_ansi */
61 #include <io.h> /* for get_osfhandle */
71 static int max_fringe_bmp
= 0;
72 static HBITMAP
*fringe_bmp
= 0;
74 /* Temporary variables for w32_read_socket. */
76 static int last_mousemove_x
= 0;
77 static int last_mousemove_y
= 0;
79 /* Define GET_WHEEL_DELTA_WPARAM macro if system headers don't. */
80 #ifndef GET_WHEEL_DELTA_WPARAM
81 #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
84 /* Non-zero means that a HELP_EVENT has been generated since Emacs
87 static int any_help_event_p
;
89 extern unsigned int msh_mousewheel
;
91 extern void free_frame_menubar (struct frame
*);
93 extern int w32_codepage_for_font (char *fontname
);
94 extern Cursor
w32_load_cursor (LPCTSTR name
);
96 #define x_any_window_to_frame x_window_to_frame
97 #define x_top_window_to_frame x_window_to_frame
100 /* This is display since w32 does not support multiple ones. */
101 struct w32_display_info one_w32_display_info
;
102 struct w32_display_info
*x_display_list
;
104 #if _WIN32_WINNT < 0x0500 && !defined(_W64)
105 /* Pre Windows 2000, this was not available, but define it here so
106 that Emacs compiled on such a platform will run on newer versions.
107 MinGW64 (_W64) defines these unconditionally, so avoid redefining. */
109 typedef struct tagWCRANGE
115 typedef struct tagGLYPHSET
119 DWORD cGlyphsSupported
;
124 #endif /* compiling for pre-Win2k */
126 /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */
127 BOOL (WINAPI
*pfnSetLayeredWindowAttributes
) (HWND
, COLORREF
, BYTE
, DWORD
);
130 #define LWA_ALPHA 0x02
132 /* WS_EX_LAYERED is defined unconditionally by MingW, but only for W2K and
133 later targets by MSVC headers. */
134 #ifndef WS_EX_LAYERED
135 #define WS_EX_LAYERED 0x80000
138 /* SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not defined on 95 and
140 #ifndef SM_CXVIRTUALSCREEN
141 #define SM_CXVIRTUALSCREEN 78
143 #ifndef SM_CYVIRTUALSCREEN
144 #define SM_CYVIRTUALSCREEN 79
147 /* The handle of the frame that currently owns the system caret. */
148 HWND w32_system_caret_hwnd
;
149 int w32_system_caret_height
;
150 int w32_system_caret_x
;
151 int w32_system_caret_y
;
152 struct window
*w32_system_caret_window
;
153 int w32_system_caret_hdr_height
;
154 int w32_system_caret_mode_height
;
155 DWORD dwWindowsThreadId
= 0;
156 HANDLE hWindowsThread
= NULL
;
157 DWORD dwMainThreadId
= 0;
158 HANDLE hMainThread
= NULL
;
160 int vertical_scroll_bar_min_handle
;
161 int horizontal_scroll_bar_min_handle
;
162 int vertical_scroll_bar_top_border
;
163 int vertical_scroll_bar_bottom_border
;
164 int horizontal_scroll_bar_left_border
;
165 int horizontal_scroll_bar_right_border
;
167 int last_scroll_bar_drag_pos
;
169 /* Keyboard code page - may be changed by language-change events. */
170 int w32_keyboard_codepage
;
172 /* Incremented by w32_read_socket whenever it really tries to read
174 static int volatile input_signal_count
;
177 int w32_message_fd
= -1;
180 static void w32_handle_tool_bar_click (struct frame
*,
181 struct input_event
*);
182 static void w32_define_cursor (Window
, Cursor
);
184 void x_lower_frame (struct frame
*);
185 void x_scroll_bar_clear (struct frame
*);
186 void x_wm_set_size_hint (struct frame
*, long, bool);
187 void x_raise_frame (struct frame
*);
188 void x_set_window_size (struct frame
*, int, int, int, bool);
189 void x_wm_set_window_state (struct frame
*, int);
190 void x_wm_set_icon_pixmap (struct frame
*, int);
191 static void w32_initialize (void);
192 static void x_update_end (struct frame
*);
193 static void w32_frame_up_to_date (struct frame
*);
194 static void x_clear_frame (struct frame
*);
195 static void frame_highlight (struct frame
*);
196 static void frame_unhighlight (struct frame
*);
197 static void x_new_focus_frame (struct w32_display_info
*,
199 static void x_focus_changed (int, int, struct w32_display_info
*,
200 struct frame
*, struct input_event
*);
201 static void w32_detect_focus_change (struct w32_display_info
*,
202 W32Msg
*, struct input_event
*);
203 static void w32_frame_rehighlight (struct frame
*);
204 static void x_frame_rehighlight (struct w32_display_info
*);
205 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
206 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
207 enum text_cursor_kinds
);
208 static void w32_clip_to_row (struct window
*, struct glyph_row
*,
209 enum glyph_row_area
, HDC
);
210 static BOOL
my_show_window (struct frame
*, HWND
, int);
211 static void my_set_window_pos (HWND
, HWND
, int, int, int, int, UINT
);
213 static void my_set_focus (struct frame
*, HWND
);
215 static void my_set_foreground_window (HWND
);
216 static void my_destroy_window (struct frame
*, HWND
);
217 static void w32fullscreen_hook (struct frame
*);
220 static void x_check_font (struct frame
*, struct font
*);
223 static Lisp_Object Qvendor_specific_keysyms
;
224 static Lisp_Object Qadded
, Qremoved
, Qmodified
;
225 static Lisp_Object Qrenamed_from
, Qrenamed_to
;
228 /***********************************************************************
230 ***********************************************************************/
234 /* This is a function useful for recording debugging information about
235 the sequence of occurrences in this file. */
243 struct record event_record
[100];
245 int event_record_index
;
247 record_event (char *locus
, int type
)
249 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
250 event_record_index
= 0;
252 event_record
[event_record_index
].locus
= locus
;
253 event_record
[event_record_index
].type
= type
;
254 event_record_index
++;
261 XChangeGC (void *ignore
, XGCValues
*gc
, unsigned long mask
,
264 if (mask
& GCForeground
)
265 gc
->foreground
= xgcv
->foreground
;
266 if (mask
& GCBackground
)
267 gc
->background
= xgcv
->background
;
269 gc
->font
= xgcv
->font
;
273 XCreateGC (void *ignore
, Window window
, unsigned long mask
, XGCValues
*xgcv
)
275 XGCValues
*gc
= xzalloc (sizeof (XGCValues
));
277 XChangeGC (ignore
, gc
, mask
, xgcv
);
283 XGetGCValues (void *ignore
, XGCValues
*gc
,
284 unsigned long mask
, XGCValues
*xgcv
)
286 XChangeGC (ignore
, xgcv
, mask
, gc
);
290 w32_set_clip_rectangle (HDC hdc
, RECT
*rect
)
294 HRGN clip_region
= CreateRectRgnIndirect (rect
);
295 SelectClipRgn (hdc
, clip_region
);
296 DeleteObject (clip_region
);
299 SelectClipRgn (hdc
, NULL
);
302 /* Restore clipping rectangle in S */
304 w32_restore_glyph_string_clip (struct glyph_string
*s
)
307 int n
= s
->num_clips
;
310 w32_set_clip_rectangle (s
->hdc
, r
);
313 HRGN clip1
= CreateRectRgnIndirect (r
);
314 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
315 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
316 SelectClipRgn (s
->hdc
, clip1
);
317 DeleteObject (clip1
);
318 DeleteObject (clip2
);
323 Draw a wavy line under S. The wave fills wave_height pixels from y0.
329 wave_height = 3 | * * * *
334 w32_draw_underwave (struct glyph_string
*s
, COLORREF color
)
336 int wave_height
= 3, wave_length
= 2;
337 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
338 XRectangle wave_clip
, string_clip
, final_clip
;
339 RECT w32_final_clip
, w32_string_clip
;
343 dy
= wave_height
- 1;
345 y0
= s
->ybase
- wave_height
+ 3;
349 /* Find and set clipping rectangle */
353 wave_clip
.width
= width
;
354 wave_clip
.height
= wave_height
;
356 get_glyph_string_clip_rect (s
, &w32_string_clip
);
357 CONVERT_TO_XRECT (string_clip
, w32_string_clip
);
359 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
362 hp
= CreatePen (PS_SOLID
, 0, color
);
363 oldhp
= SelectObject (s
->hdc
, hp
);
364 CONVERT_FROM_XRECT (final_clip
, w32_final_clip
);
365 w32_set_clip_rectangle (s
->hdc
, &w32_final_clip
);
379 MoveToEx (s
->hdc
, x1
, y1
, NULL
);
383 LineTo (s
->hdc
, x2
, y2
);
385 x2
+= dx
, y2
= y0
+ odd
*dy
;
389 /* Restore previous pen and clipping rectangle(s) */
390 w32_restore_glyph_string_clip (s
);
391 SelectObject (s
->hdc
, oldhp
);
395 /* Draw a hollow rectangle at the specified position. */
397 w32_draw_rectangle (HDC hdc
, XGCValues
*gc
, int x
, int y
,
398 int width
, int height
)
403 hb
= CreateSolidBrush (gc
->background
);
404 hp
= CreatePen (PS_SOLID
, 0, gc
->foreground
);
405 oldhb
= SelectObject (hdc
, hb
);
406 oldhp
= SelectObject (hdc
, hp
);
408 Rectangle (hdc
, x
, y
, x
+ width
, y
+ height
);
410 SelectObject (hdc
, oldhb
);
411 SelectObject (hdc
, oldhp
);
416 /* Draw a filled rectangle at the specified position. */
418 w32_fill_rect (struct frame
*f
, HDC hdc
, COLORREF pix
, RECT
*lprect
)
422 hb
= CreateSolidBrush (pix
);
423 FillRect (hdc
, lprect
, hb
);
428 w32_clear_window (struct frame
*f
)
431 HDC hdc
= get_frame_dc (f
);
433 /* Under certain conditions, this can be called at startup with
434 a console frame pointer before the GUI frame is created. An HDC
435 of 0 indicates this. */
438 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
439 w32_clear_rect (f
, hdc
, &rect
);
442 release_frame_dc (f
, hdc
);
445 #define OPAQUE_FRAME 255
448 x_set_frame_alpha (struct frame
*f
)
450 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
452 double alpha_min
= 1.0;
455 HWND window
= FRAME_W32_WINDOW (f
);
457 /* Older versions of Windows do not support transparency. */
458 if (!pfnSetLayeredWindowAttributes
)
461 if (dpyinfo
->w32_focus_frame
== f
)
466 if (FLOATP (Vframe_alpha_lower_limit
))
467 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
468 else if (INTEGERP (Vframe_alpha_lower_limit
))
469 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
473 else if (alpha
> 1.0)
475 else if (alpha
< alpha_min
&& alpha_min
<= 1.0)
478 opac
= alpha
* OPAQUE_FRAME
;
480 ex_style
= GetWindowLong (window
, GWL_EXSTYLE
);
482 if (opac
== OPAQUE_FRAME
)
483 ex_style
&= ~WS_EX_LAYERED
;
485 ex_style
|= WS_EX_LAYERED
;
487 SetWindowLong (window
, GWL_EXSTYLE
, ex_style
);
489 if (opac
!= OPAQUE_FRAME
)
490 pfnSetLayeredWindowAttributes (window
, 0, opac
, LWA_ALPHA
);
494 x_display_pixel_height (struct w32_display_info
*dpyinfo
)
496 int pixels
= GetSystemMetrics (SM_CYVIRTUALSCREEN
);
499 /* Fallback for Windows 95 or NT 4.0. */
500 pixels
= GetSystemMetrics (SM_CYSCREEN
);
506 x_display_pixel_width (struct w32_display_info
*dpyinfo
)
508 int pixels
= GetSystemMetrics (SM_CXVIRTUALSCREEN
);
511 /* Fallback for Windows 95 or NT 4.0. */
512 pixels
= GetSystemMetrics (SM_CXSCREEN
);
518 /***********************************************************************
519 Starting and ending an update
520 ***********************************************************************/
522 /* Start an update of frame F. This function is installed as a hook
523 for update_begin, i.e. it is called when update_begin is called.
524 This function is called prior to calls to x_update_window_begin for
525 each window being updated. */
528 x_update_begin (struct frame
*f
)
530 struct w32_display_info
*display_info
= FRAME_DISPLAY_INFO (f
);
532 if (! FRAME_W32_P (f
))
535 /* Regenerate display palette before drawing if list of requested
536 colors has changed. */
537 if (display_info
->regen_palette
)
539 w32_regenerate_palette (f
);
540 display_info
->regen_palette
= FALSE
;
545 /* Start update of window W. */
548 x_update_window_begin (struct window
*w
)
550 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
551 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
553 /* Hide the system caret during an update. */
554 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
556 SendMessage (w32_system_caret_hwnd
, WM_EMACS_HIDE_CARET
, 0, 0);
559 w
->output_cursor
= w
->cursor
;
563 if (f
== hlinfo
->mouse_face_mouse_frame
)
565 /* Don't do highlighting for mouse motion during the update. */
566 hlinfo
->mouse_face_defer
= 1;
568 /* If F needs to be redrawn, simply forget about any prior mouse
570 if (FRAME_GARBAGED_P (f
))
571 hlinfo
->mouse_face_window
= Qnil
;
573 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
574 their mouse_face_p flag set, which means that they are always
575 unequal to rows in a desired matrix which never have that
576 flag set. So, rows containing mouse-face glyphs are never
577 scrolled, and we don't have to switch the mouse highlight off
578 here to prevent it from being scrolled. */
580 /* Can we tell that this update does not affect the window
581 where the mouse highlight is? If so, no need to turn off.
582 Likewise, don't do anything if the frame is garbaged;
583 in that case, the frame's current matrix that we would use
584 is all wrong, and we will redisplay that line anyway. */
585 if (!NILP (hlinfo
->mouse_face_window
)
586 && w
== XWINDOW (hlinfo
->mouse_face_window
))
590 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
591 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
594 if (i
< w
->desired_matrix
->nrows
)
595 clear_mouse_face (hlinfo
);
603 /* Draw a vertical window border from (x,y0) to (x,y1) */
606 w32_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
608 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
618 hdc
= get_frame_dc (f
);
619 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
621 w32_fill_rect (f
, hdc
, face
->foreground
, &r
);
623 w32_fill_rect (f
, hdc
, FRAME_FOREGROUND_PIXEL (f
), &r
);
625 release_frame_dc (f
, hdc
);
629 /* Draw a window divider from (x0, y0) to (x1, y1) */
632 w32_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
634 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
635 HDC hdc
= get_frame_dc (f
);
636 struct face
*face
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FACE_ID
);
637 struct face
*face_first
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
638 struct face
*face_last
= FACE_FROM_ID (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
639 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
640 unsigned long color_first
= (face_first
641 ? face_first
->foreground
642 : FRAME_FOREGROUND_PIXEL (f
));
643 unsigned long color_last
= (face_last
644 ? face_last
->foreground
645 : FRAME_FOREGROUND_PIXEL (f
));
647 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
650 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x0
+ 1, y1
);
651 w32_fill_area_abs (f
, hdc
, color
, x0
+ 1, y0
, x1
- 1, y1
);
652 w32_fill_area_abs (f
, hdc
, color_last
, x1
- 1, y0
, x1
, y1
);
654 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
657 w32_fill_area_abs (f
, hdc
, color_first
, x0
, y0
, x1
, y0
+ 1);
658 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
+ 1, x1
, y1
- 1);
659 w32_fill_area_abs (f
, hdc
, color_last
, x0
, y1
- 1, x1
, y1
);
662 w32_fill_area_abs (f
, hdc
, color
, x0
, y0
, x1
, y1
);
664 release_frame_dc (f
, hdc
);
667 /* End update of window W.
669 Draw vertical borders between horizontally adjacent windows, and
670 display W's cursor if CURSOR_ON_P is non-zero.
672 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
673 glyphs in mouse-face were overwritten. In that case we have to
674 make sure that the mouse-highlight is properly redrawn.
676 W may be a menu bar pseudo-window in case we don't have X toolkit
677 support. Such windows don't have a cursor, so don't display it
681 x_update_window_end (struct window
*w
, bool cursor_on_p
,
682 bool mouse_face_overwritten_p
)
684 if (!w
->pseudo_window_p
)
689 display_and_set_cursor (w
, 1,
690 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
691 w
->output_cursor
.x
, w
->output_cursor
.y
);
693 if (draw_window_fringes (w
, 1))
695 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
696 x_draw_right_divider (w
);
698 x_draw_vertical_border (w
);
704 /* If a row with mouse-face was overwritten, arrange for
705 XTframe_up_to_date to redisplay the mouse highlight. */
706 if (mouse_face_overwritten_p
)
708 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
710 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
711 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
712 hlinfo
->mouse_face_window
= Qnil
;
715 /* Unhide the caret. This won't actually show the cursor, unless it
716 was visible before the corresponding call to HideCaret in
717 x_update_window_begin. */
718 if (w32_use_visible_system_caret
&& w32_system_caret_hwnd
)
720 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
725 /* End update of frame F. This function is installed as a hook in
729 x_update_end (struct frame
*f
)
731 if (! FRAME_W32_P (f
))
734 /* Mouse highlight may be displayed again. */
735 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
739 /* This function is called from various places in xdisp.c
740 whenever a complete update has been performed. */
743 w32_frame_up_to_date (struct frame
*f
)
746 FRAME_MOUSE_UPDATE (f
);
750 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
751 arrow bitmaps, or clear the fringes if no bitmaps are required
752 before DESIRED_ROW is made current. This function is called from
753 update_window_line only if it is known that there are differences
754 between bitmaps to be drawn between current row and DESIRED_ROW. */
757 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
764 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
765 desired_row
->redraw_fringe_bitmaps_p
= 1;
767 /* When a window has disappeared, make sure that no rest of
768 full-width rows stays visible in the internal border. Could
769 check here if updated window is the leftmost/rightmost window,
770 but I guess it's not worth doing since vertically split windows
771 are almost never used, internal border is rarely set, and the
772 overhead is very small. */
773 if (windows_or_buffers_changed
774 && desired_row
->full_width_p
775 && (f
= XFRAME (w
->frame
),
776 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
778 && (height
= desired_row
->visible_height
,
781 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
785 HDC hdc
= get_frame_dc (f
);
786 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
787 w32_clear_area (f
, hdc
, FRAME_PIXEL_WIDTH (f
) - width
,
789 release_frame_dc (f
, hdc
);
796 /* Draw the bitmap WHICH in one of the left or right fringes of
797 window W. ROW is the glyph row for which to display the bitmap; it
798 determines the vertical position at which the bitmap has to be
802 w32_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
,
803 struct draw_fringe_bitmap_params
*p
)
805 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
807 struct face
*face
= p
->face
;
809 hdc
= get_frame_dc (f
);
811 /* Must clip because of partially visible lines. */
812 w32_clip_to_row (w
, row
, ANY_AREA
, hdc
);
814 if (p
->bx
>= 0 && !p
->overlay_p
)
815 w32_fill_area (f
, hdc
, face
->background
,
816 p
->bx
, p
->by
, p
->nx
, p
->ny
);
818 if (p
->which
&& p
->which
< max_fringe_bmp
)
820 HBITMAP pixmap
= fringe_bmp
[p
->which
];
824 compat_hdc
= CreateCompatibleDC (hdc
);
828 horig_obj
= SelectObject (compat_hdc
, pixmap
);
830 /* Paint overlays transparently. */
833 HBRUSH h_brush
, h_orig_brush
;
835 SetTextColor (hdc
, BLACK_PIX_DEFAULT (f
));
836 SetBkColor (hdc
, WHITE_PIX_DEFAULT (f
));
837 h_brush
= CreateSolidBrush (face
->foreground
);
838 h_orig_brush
= SelectObject (hdc
, h_brush
);
840 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
841 compat_hdc
, 0, p
->dh
,
843 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
844 compat_hdc
, 0, p
->dh
,
846 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
847 compat_hdc
, 0, p
->dh
,
850 SelectObject (hdc
, h_orig_brush
);
851 DeleteObject (h_brush
);
855 SetTextColor (hdc
, face
->background
);
856 SetBkColor (hdc
, (p
->cursor_p
857 ? f
->output_data
.w32
->cursor_pixel
858 : face
->foreground
));
860 BitBlt (hdc
, p
->x
, p
->y
, p
->wd
, p
->h
,
861 compat_hdc
, 0, p
->dh
,
865 SelectObject (compat_hdc
, horig_obj
);
866 DeleteDC (compat_hdc
);
870 w32_set_clip_rectangle (hdc
, NULL
);
872 release_frame_dc (f
, hdc
);
876 w32_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
878 if (which
>= max_fringe_bmp
)
880 int i
= max_fringe_bmp
;
881 max_fringe_bmp
= which
+ 20;
882 fringe_bmp
= (HBITMAP
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (HBITMAP
));
883 while (i
< max_fringe_bmp
)
887 fringe_bmp
[which
] = CreateBitmap (wd
, h
, 1, 1, bits
);
891 w32_destroy_fringe_bitmap (int which
)
893 if (which
>= max_fringe_bmp
)
896 if (fringe_bmp
[which
])
897 DeleteObject (fringe_bmp
[which
]);
898 fringe_bmp
[which
] = 0;
901 /***********************************************************************
903 ***********************************************************************/
905 /* Function prototypes of this page. */
907 static void x_set_glyph_string_clipping (struct glyph_string
*);
908 static void x_set_glyph_string_gc (struct glyph_string
*);
909 static void x_draw_glyph_string_background (struct glyph_string
*,
911 static void x_draw_glyph_string_foreground (struct glyph_string
*);
912 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
913 static void x_draw_glyph_string_box (struct glyph_string
*);
914 static void x_draw_glyph_string (struct glyph_string
*);
915 static void x_set_cursor_gc (struct glyph_string
*);
916 static void x_set_mode_line_face_gc (struct glyph_string
*);
917 static void x_set_mouse_face_gc (struct glyph_string
*);
918 static int w32_alloc_lighter_color (struct frame
*, COLORREF
*, double, int);
919 static void w32_setup_relief_color (struct frame
*, struct relief
*,
920 double, int, COLORREF
);
921 static void x_setup_relief_colors (struct glyph_string
*);
922 static void x_draw_image_glyph_string (struct glyph_string
*);
923 static void x_draw_image_relief (struct glyph_string
*);
924 static void x_draw_image_foreground (struct glyph_string
*);
925 static void w32_draw_image_foreground_1 (struct glyph_string
*, HBITMAP
);
926 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
928 static void w32_draw_relief_rect (struct frame
*, int, int, int, int,
929 int, int, int, int, int, int,
931 static void w32_draw_box_rect (struct glyph_string
*, int, int, int, int,
932 int, int, int, RECT
*);
935 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
939 x_set_cursor_gc (struct glyph_string
*s
)
941 if (s
->font
== FRAME_FONT (s
->f
)
942 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
943 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
945 s
->gc
= s
->f
->output_data
.w32
->cursor_gc
;
948 /* Cursor on non-default face: must merge. */
952 xgcv
.background
= s
->f
->output_data
.w32
->cursor_pixel
;
953 xgcv
.foreground
= s
->face
->background
;
955 /* If the glyph would be invisible, try a different foreground. */
956 if (xgcv
.foreground
== xgcv
.background
)
957 xgcv
.foreground
= s
->face
->foreground
;
958 if (xgcv
.foreground
== xgcv
.background
)
959 xgcv
.foreground
= s
->f
->output_data
.w32
->cursor_foreground_pixel
;
960 if (xgcv
.foreground
== xgcv
.background
)
961 xgcv
.foreground
= s
->face
->foreground
;
963 /* Make sure the cursor is distinct from text in this face. */
964 if (xgcv
.background
== s
->face
->background
965 && xgcv
.foreground
== s
->face
->foreground
)
967 xgcv
.background
= s
->face
->foreground
;
968 xgcv
.foreground
= s
->face
->background
;
971 IF_DEBUG (x_check_font (s
->f
, s
->font
));
973 mask
= GCForeground
| GCBackground
| GCFont
;
975 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
976 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
979 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
980 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
982 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
987 /* Set up S->gc of glyph string S for drawing text in mouse face. */
990 x_set_mouse_face_gc (struct glyph_string
*s
)
995 /* What face has to be used last for the mouse face? */
996 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
997 face
= FACE_FROM_ID (s
->f
, face_id
);
999 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1001 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1002 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1004 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1005 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1006 prepare_face_for_display (s
->f
, s
->face
);
1008 /* If font in this face is same as S->font, use it. */
1009 if (s
->font
== s
->face
->font
)
1010 s
->gc
= s
->face
->gc
;
1013 /* Otherwise construct scratch_cursor_gc with values from FACE
1018 xgcv
.background
= s
->face
->background
;
1019 xgcv
.foreground
= s
->face
->foreground
;
1020 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1021 xgcv
.font
= s
->font
;
1022 mask
= GCForeground
| GCBackground
| GCFont
;
1024 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1025 XChangeGC (NULL
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1028 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1029 = XCreateGC (NULL
, s
->window
, mask
, &xgcv
);
1031 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1034 eassert (s
->gc
!= 0);
1038 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1039 Faces to use in the mode line have already been computed when the
1040 matrix was built, so there isn't much to do, here. */
1043 x_set_mode_line_face_gc (struct glyph_string
*s
)
1045 s
->gc
= s
->face
->gc
;
1049 /* Set S->gc of glyph string S for drawing that glyph string. Set
1050 S->stippled_p to a non-zero value if the face of S has a stipple
1054 x_set_glyph_string_gc (struct glyph_string
*s
)
1056 prepare_face_for_display (s
->f
, s
->face
);
1058 if (s
->hl
== DRAW_NORMAL_TEXT
)
1060 s
->gc
= s
->face
->gc
;
1061 s
->stippled_p
= s
->face
->stipple
!= 0;
1063 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1065 x_set_mode_line_face_gc (s
);
1066 s
->stippled_p
= s
->face
->stipple
!= 0;
1068 else if (s
->hl
== DRAW_CURSOR
)
1070 x_set_cursor_gc (s
);
1073 else if (s
->hl
== DRAW_MOUSE_FACE
)
1075 x_set_mouse_face_gc (s
);
1076 s
->stippled_p
= s
->face
->stipple
!= 0;
1078 else if (s
->hl
== DRAW_IMAGE_RAISED
1079 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1081 s
->gc
= s
->face
->gc
;
1082 s
->stippled_p
= s
->face
->stipple
!= 0;
1087 /* GC must have been set. */
1088 eassert (s
->gc
!= 0);
1092 /* Set clipping for output of glyph string S. S may be part of a mode
1093 line or menu if we don't have X toolkit support. */
1096 x_set_glyph_string_clipping (struct glyph_string
*s
)
1099 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1102 w32_set_clip_rectangle (s
->hdc
, r
);
1105 HRGN clip1
= CreateRectRgnIndirect (r
);
1106 HRGN clip2
= CreateRectRgnIndirect (r
+ 1);
1107 if (CombineRgn (clip1
, clip1
, clip2
, RGN_OR
) != ERROR
)
1108 SelectClipRgn (s
->hdc
, clip1
);
1109 DeleteObject (clip1
);
1110 DeleteObject (clip2
);
1115 /* Set SRC's clipping for output of glyph string DST. This is called
1116 when we are drawing DST's left_overhang or right_overhang only in
1120 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
,
1121 struct glyph_string
*dst
)
1126 r
.right
= r
.left
+ src
->width
;
1128 r
.bottom
= r
.top
+ src
->height
;
1131 w32_set_clip_rectangle (dst
->hdc
, &r
);
1135 Compute left and right overhang of glyph string S. */
1138 w32_compute_glyph_string_overhangs (struct glyph_string
*s
)
1141 && s
->first_glyph
->type
== CHAR_GLYPH
1142 && !s
->font_not_found_p
)
1144 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1145 struct font
*font
= s
->font
;
1146 struct font_metrics metrics
;
1149 for (i
= 0; i
< s
->nchars
; i
++)
1150 code
[i
] = s
->char2b
[i
];
1151 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1152 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1153 ? metrics
.rbearing
- metrics
.width
: 0);
1154 s
->left_overhang
= metrics
.lbearing
< 0 ? -metrics
.lbearing
: 0;
1158 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1159 s
->left_overhang
= -s
->cmp
->lbearing
;
1163 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1166 x_clear_glyph_string_rect (struct glyph_string
*s
,
1167 int x
, int y
, int w
, int h
)
1174 /* Take clipping into account. */
1175 if (s
->gc
->clip_mask
== Rect
)
1177 real_x
= max (real_x
, s
->gc
->clip_rectangle
.left
);
1178 real_y
= max (real_y
, s
->gc
->clip_rectangle
.top
);
1179 real_w
= min (real_w
, s
->gc
->clip_rectangle
.right
1180 - s
->gc
->clip_rectangle
.left
);
1181 real_h
= min (real_h
, s
->gc
->clip_rectangle
.bottom
1182 - s
->gc
->clip_rectangle
.top
);
1185 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->background
, real_x
, real_y
,
1190 /* Draw the background of glyph_string S. If S->background_filled_p
1191 is non-zero don't draw it. FORCE_P non-zero means draw the
1192 background even if it wouldn't be drawn normally. This is used
1193 when a string preceding S draws into the background of S, or S
1194 contains the first component of a composition. */
1197 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1199 /* Nothing to do if background has already been drawn or if it
1200 shouldn't be drawn in the first place. */
1201 if (!s
->background_filled_p
)
1203 int box_line_width
= max (s
->face
->box_line_width
, 0);
1205 #if 0 /* TODO: stipple */
1208 /* Fill background with a stipple pattern. */
1209 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1210 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1211 s
->y
+ box_line_width
,
1212 s
->background_width
,
1213 s
->height
- 2 * box_line_width
);
1214 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1215 s
->background_filled_p
= 1;
1219 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1220 || s
->font_not_found_p
1221 || s
->extends_to_end_of_line_p
1224 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1225 s
->background_width
,
1226 s
->height
- 2 * box_line_width
);
1227 s
->background_filled_p
= 1;
1233 /* Draw the foreground of glyph string S. */
1236 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1240 /* If first glyph of S has a left box line, start drawing the text
1241 of S to the right of that box line. */
1242 if (s
->face
->box
!= FACE_NO_BOX
1243 && s
->first_glyph
->left_box_line_p
)
1244 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1248 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1249 SetBkColor (s
->hdc
, s
->gc
->background
);
1250 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1252 /* Draw characters of S as rectangles if S's font could not be
1254 if (s
->font_not_found_p
)
1256 for (i
= 0; i
< s
->nchars
; ++i
)
1258 struct glyph
*g
= s
->first_glyph
+ i
;
1260 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1262 x
+= g
->pixel_width
;
1267 struct font
*font
= s
->font
;
1268 int boff
= font
->baseline_offset
;
1272 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1274 if (font
->vertical_centering
)
1275 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1277 y
= s
->ybase
- boff
;
1279 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1280 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1282 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1283 if (s
->face
->overstrike
)
1284 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1286 SelectObject (s
->hdc
, old_font
);
1290 /* Draw the foreground of composite glyph string S. */
1293 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1296 struct font
*font
= s
->font
;
1298 /* If first glyph of S has a left box line, start drawing the text
1299 of S to the right of that box line. */
1300 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1301 && s
->first_glyph
->left_box_line_p
)
1302 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1306 /* S is a glyph string for a composition. S->cmp_from is the index
1307 of the first character drawn for glyphs of this composition.
1308 S->cmp_from == 0 means we are drawing the very first character of
1309 this composition. */
1311 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1312 SetBkColor (s
->hdc
, s
->gc
->background
);
1313 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1315 /* Draw a rectangle for the composition if the font for the very
1316 first character of the composition could not be loaded. */
1317 if (s
->font_not_found_p
)
1319 if (s
->cmp_from
== 0)
1320 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, s
->y
, s
->width
- 1,
1323 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1328 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1330 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1331 /* TAB in a composition means display glyphs with padding
1332 space on the left or right. */
1333 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1335 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1336 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1338 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1339 if (s
->face
->overstrike
)
1340 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1342 SelectObject (s
->hdc
, old_font
);
1346 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1352 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1354 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1356 glyph
= LGSTRING_GLYPH (gstring
, i
);
1357 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1358 width
+= LGLYPH_WIDTH (glyph
);
1361 int xoff
, yoff
, wadjust
;
1365 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1368 xoff
= LGLYPH_XOFF (glyph
);
1369 yoff
= LGLYPH_YOFF (glyph
);
1370 wadjust
= LGLYPH_WADJUST (glyph
);
1371 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1378 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1380 SelectObject (s
->hdc
, old_font
);
1385 /* Draw the foreground of glyph string S for glyphless characters. */
1388 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1390 struct glyph
*glyph
= s
->first_glyph
;
1393 int with_background
;
1395 /* If first glyph of S has a left box line, start drawing the text
1396 of S to the right of that box line. */
1397 if (s
->face
->box
!= FACE_NO_BOX
1398 && s
->first_glyph
->left_box_line_p
)
1399 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1403 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1404 SetBkColor (s
->hdc
, s
->gc
->background
);
1405 SetTextAlign (s
->hdc
, TA_BASELINE
| TA_LEFT
);
1408 with_background
= ! (s
->for_overlaps
1409 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
));
1410 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1412 char buf
[7], *str
= NULL
;
1413 int len
= glyph
->u
.glyphless
.len
;
1415 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1418 && CHAR_TABLE_P (Vglyphless_char_display
)
1419 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1423 = (! glyph
->u
.glyphless
.for_no_font
1424 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1425 glyph
->u
.glyphless
.ch
)
1426 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1427 if (STRINGP (acronym
))
1428 str
= SSDATA (acronym
);
1431 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1433 sprintf ((char *) buf
, "%0*X",
1434 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1435 glyph
->u
.glyphless
.ch
);
1439 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1440 w32_draw_rectangle (s
->hdc
, s
->gc
,
1441 x
, s
->ybase
- glyph
->ascent
,
1442 glyph
->pixel_width
- 1,
1443 glyph
->ascent
+ glyph
->descent
- 1);
1446 struct font
*font
= s
->font
;
1447 int upper_len
= (len
+ 1) / 2;
1451 old_font
= SelectObject (s
->hdc
, FONT_HANDLE (font
));
1452 /* It is certain that all LEN characters in STR are ASCII. */
1453 for (j
= 0; j
< len
; j
++)
1455 code
= font
->driver
->encode_char (font
, str
[j
]);
1456 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1458 font
->driver
->draw (s
, 0, upper_len
,
1459 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1460 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1462 font
->driver
->draw (s
, upper_len
, len
,
1463 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1464 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1466 SelectObject (s
->hdc
, old_font
);
1468 x
+= glyph
->pixel_width
;
1473 /* Brightness beyond which a color won't have its highlight brightness
1476 Nominally, highlight colors for `3d' faces are calculated by
1477 brightening an object's color by a constant scale factor, but this
1478 doesn't yield good results for dark colors, so for colors whose
1479 brightness is less than this value (on a scale of 0-255) have to
1480 use an additional additive factor.
1482 The value here is set so that the default menu-bar/mode-line color
1483 (grey75) will not have its highlights changed at all. */
1484 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
1487 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
1488 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1489 If this produces the same color as COLOR, try a color where all RGB
1490 values have DELTA added. Return the allocated color in *COLOR.
1491 DISPLAY is the X display, CMAP is the colormap to operate on.
1492 Value is non-zero if successful. */
1495 w32_alloc_lighter_color (struct frame
*f
, COLORREF
*color
,
1496 double factor
, int delta
)
1501 /* On Windows, RGB values are 0-255, not 0-65535, so scale delta. */
1504 /* Change RGB values by specified FACTOR. Avoid overflow! */
1505 eassert (factor
>= 0);
1506 new = PALETTERGB (min (0xff, factor
* GetRValue (*color
)),
1507 min (0xff, factor
* GetGValue (*color
)),
1508 min (0xff, factor
* GetBValue (*color
)));
1510 /* Calculate brightness of COLOR. */
1511 bright
= (2 * GetRValue (*color
) + 3 * GetGValue (*color
)
1512 + GetBValue (*color
)) / 6;
1514 /* We only boost colors that are darker than
1515 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1516 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1517 /* Make an additive adjustment to NEW, because it's dark enough so
1518 that scaling by FACTOR alone isn't enough. */
1520 /* How far below the limit this color is (0 - 1, 1 being darker). */
1521 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1522 /* The additive adjustment. */
1523 int min_delta
= delta
* dimness
* factor
/ 2;
1526 new = PALETTERGB (max (0, min (0xff, min_delta
- GetRValue (*color
))),
1527 max (0, min (0xff, min_delta
- GetGValue (*color
))),
1528 max (0, min (0xff, min_delta
- GetBValue (*color
))));
1530 new = PALETTERGB (max (0, min (0xff, min_delta
+ GetRValue (*color
))),
1531 max (0, min (0xff, min_delta
+ GetGValue (*color
))),
1532 max (0, min (0xff, min_delta
+ GetBValue (*color
))));
1536 new = PALETTERGB (max (0, min (0xff, delta
+ GetRValue (*color
))),
1537 max (0, min (0xff, delta
+ GetGValue (*color
))),
1538 max (0, min (0xff, delta
+ GetBValue (*color
))));
1540 /* TODO: Map to palette and retry with delta if same? */
1541 /* TODO: Free colors (if using palette)? */
1551 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1552 colors in COLORS. On W32, we no longer try to map colors to
1555 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1559 for (i
= 0; i
< ncolors
; i
++)
1561 DWORD pixel
= colors
[i
].pixel
;
1562 /* Convert to a 16 bit value in range 0 - 0xffff. */
1563 colors
[i
].red
= GetRValue (pixel
) * 257;
1564 colors
[i
].green
= GetGValue (pixel
) * 257;
1565 colors
[i
].blue
= GetBValue (pixel
) * 257;
1570 x_query_color (struct frame
*f
, XColor
*color
)
1572 x_query_colors (f
, color
, 1);
1576 /* Set up the foreground color for drawing relief lines of glyph
1577 string S. RELIEF is a pointer to a struct relief containing the GC
1578 with which lines will be drawn. Use a color that is FACTOR or
1579 DELTA lighter or darker than the relief's background which is found
1580 in S->f->output_data.x->relief_background. If such a color cannot
1581 be allocated, use DEFAULT_PIXEL, instead. */
1584 w32_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
1585 int delta
, COLORREF default_pixel
)
1588 struct w32_output
*di
= f
->output_data
.w32
;
1589 unsigned long mask
= GCForeground
;
1591 COLORREF background
= di
->relief_background
;
1592 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1594 /* TODO: Free colors (if using palette)? */
1596 /* Allocate new color. */
1597 xgcv
.foreground
= default_pixel
;
1599 if (w32_alloc_lighter_color (f
, &pixel
, factor
, delta
))
1600 xgcv
.foreground
= relief
->pixel
= pixel
;
1602 if (relief
->gc
== 0)
1604 #if 0 /* TODO: stipple */
1605 xgcv
.stipple
= dpyinfo
->gray
;
1608 relief
->gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, &xgcv
);
1611 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
1615 /* Set up colors for the relief lines around glyph string S. */
1618 x_setup_relief_colors (struct glyph_string
*s
)
1620 struct w32_output
*di
= s
->f
->output_data
.w32
;
1623 if (s
->face
->use_box_color_for_shadows_p
)
1624 color
= s
->face
->box_color
;
1625 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1627 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1628 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1630 color
= s
->gc
->background
;
1632 if (di
->white_relief
.gc
== 0
1633 || color
!= di
->relief_background
)
1635 di
->relief_background
= color
;
1636 w32_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1637 WHITE_PIX_DEFAULT (s
->f
));
1638 w32_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1639 BLACK_PIX_DEFAULT (s
->f
));
1644 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1645 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1646 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1647 relief. LEFT_P non-zero means draw a relief on the left side of
1648 the rectangle. RIGHT_P non-zero means draw a relief on the right
1649 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1653 w32_draw_relief_rect (struct frame
*f
,
1654 int left_x
, int top_y
, int right_x
, int bottom_y
,
1655 int width
, int raised_p
,
1656 int top_p
, int bot_p
, int left_p
, int right_p
,
1661 HDC hdc
= get_frame_dc (f
);
1664 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1666 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1668 w32_set_clip_rectangle (hdc
, clip_rect
);
1672 for (i
= 0; i
< width
; ++i
)
1673 w32_fill_area (f
, hdc
, gc
.foreground
,
1674 left_x
+ i
* left_p
, top_y
+ i
,
1675 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1679 for (i
= 0; i
< width
; ++i
)
1680 w32_fill_area (f
, hdc
, gc
.foreground
,
1681 left_x
+ i
, top_y
+ (i
+ 1) * top_p
, 1,
1682 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1685 gc
.foreground
= f
->output_data
.w32
->black_relief
.gc
->foreground
;
1687 gc
.foreground
= f
->output_data
.w32
->white_relief
.gc
->foreground
;
1691 for (i
= 0; i
< width
; ++i
)
1692 w32_fill_area (f
, hdc
, gc
.foreground
,
1693 left_x
+ i
* left_p
, bottom_y
- i
,
1694 right_x
- left_x
- i
* (left_p
+ right_p
) + 1, 1);
1698 for (i
= 0; i
< width
; ++i
)
1699 w32_fill_area (f
, hdc
, gc
.foreground
,
1700 right_x
- i
, top_y
+ (i
+ 1) * top_p
, 1,
1701 bottom_y
- top_y
- (i
+ 1) * (bot_p
+ top_p
) + 1);
1703 w32_set_clip_rectangle (hdc
, NULL
);
1705 release_frame_dc (f
, hdc
);
1709 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1710 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1711 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1712 left side of the rectangle. RIGHT_P non-zero means draw a line
1713 on the right side of the rectangle. CLIP_RECT is the clipping
1714 rectangle to use when drawing. */
1717 w32_draw_box_rect (struct glyph_string
*s
,
1718 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1719 int left_p
, int right_p
, RECT
*clip_rect
)
1721 w32_set_clip_rectangle (s
->hdc
, clip_rect
);
1724 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1725 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1730 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1731 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1735 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1736 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1741 w32_fill_area (s
->f
, s
->hdc
, s
->face
->box_color
,
1742 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1745 w32_set_clip_rectangle (s
->hdc
, NULL
);
1749 /* Draw a box around glyph string S. */
1752 x_draw_glyph_string_box (struct glyph_string
*s
)
1754 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
1755 int left_p
, right_p
;
1756 struct glyph
*last_glyph
;
1759 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1760 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1761 : window_box_right (s
->w
, s
->area
));
1763 /* The glyph that may have a right box line. */
1764 last_glyph
= (s
->cmp
|| s
->img
1766 : s
->first_glyph
+ s
->nchars
- 1);
1768 width
= eabs (s
->face
->box_line_width
);
1769 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
1771 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
1773 : min (last_x
, s
->x
+ s
->background_width
) - 1));
1775 bottom_y
= top_y
+ s
->height
- 1;
1777 left_p
= (s
->first_glyph
->left_box_line_p
1778 || (s
->hl
== DRAW_MOUSE_FACE
1780 || s
->prev
->hl
!= s
->hl
)));
1781 right_p
= (last_glyph
->right_box_line_p
1782 || (s
->hl
== DRAW_MOUSE_FACE
1784 || s
->next
->hl
!= s
->hl
)));
1786 get_glyph_string_clip_rect (s
, &clip_rect
);
1788 if (s
->face
->box
== FACE_SIMPLE_BOX
)
1789 w32_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
1790 left_p
, right_p
, &clip_rect
);
1793 x_setup_relief_colors (s
);
1794 w32_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
1795 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
1800 /* Draw foreground of image glyph string S. */
1803 x_draw_image_foreground (struct glyph_string
*s
)
1806 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1808 /* If first glyph of S has a left box line, start drawing it to the
1809 right of that line. */
1810 if (s
->face
->box
!= FACE_NO_BOX
1811 && s
->first_glyph
->left_box_line_p
1813 x
+= eabs (s
->face
->box_line_width
);
1815 /* If there is a margin around the image, adjust x- and y-position
1817 if (s
->slice
.x
== 0)
1818 x
+= s
->img
->hmargin
;
1819 if (s
->slice
.y
== 0)
1820 y
+= s
->img
->vmargin
;
1826 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
1827 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1828 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
1829 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1830 SetBkColor (compat_hdc
, RGB (255, 255, 255));
1831 SetTextColor (s
->hdc
, RGB (0, 0, 0));
1832 x_set_glyph_string_clipping (s
);
1836 HDC mask_dc
= CreateCompatibleDC (s
->hdc
);
1837 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1839 SetTextColor (s
->hdc
, RGB (255, 255, 255));
1840 SetBkColor (s
->hdc
, RGB (0, 0, 0));
1842 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1843 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1844 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1845 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
1846 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1847 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
1849 SelectObject (mask_dc
, mask_orig_obj
);
1854 SetTextColor (s
->hdc
, s
->gc
->foreground
);
1855 SetBkColor (s
->hdc
, s
->gc
->background
);
1857 BitBlt (s
->hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
1858 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
1860 /* When the image has a mask, we can expect that at
1861 least part of a mouse highlight or a block cursor will
1862 be visible. If the image doesn't have a mask, make
1863 a block cursor visible by drawing a rectangle around
1864 the image. I believe it's looking better if we do
1865 nothing here for mouse-face. */
1866 if (s
->hl
== DRAW_CURSOR
)
1868 int r
= s
->img
->relief
;
1870 w32_draw_rectangle (s
->hdc
, s
->gc
, x
- r
, y
- r
,
1871 s
->slice
.width
+ r
*2 - 1,
1872 s
->slice
.height
+ r
*2 - 1);
1876 w32_set_clip_rectangle (s
->hdc
, NULL
);
1877 SelectObject (s
->hdc
, orig_brush
);
1878 DeleteObject (fg_brush
);
1879 SelectObject (compat_hdc
, orig_obj
);
1880 DeleteDC (compat_hdc
);
1883 w32_draw_rectangle (s
->hdc
, s
->gc
, x
, y
,
1884 s
->slice
.width
- 1, s
->slice
.height
- 1);
1886 RestoreDC (s
->hdc
,-1);
1890 /* Draw a relief around the image glyph string S. */
1893 x_draw_image_relief (struct glyph_string
*s
)
1895 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
1896 int extra_x
, extra_y
;
1899 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1901 /* If first glyph of S has a left box line, start drawing it to the
1902 right of that line. */
1903 if (s
->face
->box
!= FACE_NO_BOX
1904 && s
->first_glyph
->left_box_line_p
1906 x
+= eabs (s
->face
->box_line_width
);
1908 /* If there is a margin around the image, adjust x- and y-position
1910 if (s
->slice
.x
== 0)
1911 x
+= s
->img
->hmargin
;
1912 if (s
->slice
.y
== 0)
1913 y
+= s
->img
->vmargin
;
1915 if (s
->hl
== DRAW_IMAGE_SUNKEN
1916 || s
->hl
== DRAW_IMAGE_RAISED
)
1918 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
1919 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
1920 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
1924 thick
= eabs (s
->img
->relief
);
1925 raised_p
= s
->img
->relief
> 0;
1928 x1
= x
+ s
->slice
.width
- 1;
1929 y1
= y
+ s
->slice
.height
- 1;
1931 extra_x
= extra_y
= 0;
1932 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
1934 if (CONSP (Vtool_bar_button_margin
)
1935 && INTEGERP (XCAR (Vtool_bar_button_margin
))
1936 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
1938 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
1939 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
1941 else if (INTEGERP (Vtool_bar_button_margin
))
1942 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
1945 top_p
= bot_p
= left_p
= right_p
= 0;
1947 if (s
->slice
.x
== 0)
1948 x
-= thick
+ extra_x
, left_p
= 1;
1949 if (s
->slice
.y
== 0)
1950 y
-= thick
+ extra_y
, top_p
= 1;
1951 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
1952 x1
+= thick
+ extra_x
, right_p
= 1;
1953 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
1954 y1
+= thick
+ extra_y
, bot_p
= 1;
1956 x_setup_relief_colors (s
);
1957 get_glyph_string_clip_rect (s
, &r
);
1958 w32_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
1959 top_p
, bot_p
, left_p
, right_p
, &r
);
1963 /* Draw the foreground of image glyph string S to PIXMAP. */
1966 w32_draw_image_foreground_1 (struct glyph_string
*s
, HBITMAP pixmap
)
1968 HDC hdc
= CreateCompatibleDC (s
->hdc
);
1969 HGDIOBJ orig_hdc_obj
= SelectObject (hdc
, pixmap
);
1971 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
1973 /* If first glyph of S has a left box line, start drawing it to the
1974 right of that line. */
1975 if (s
->face
->box
!= FACE_NO_BOX
1976 && s
->first_glyph
->left_box_line_p
1978 x
+= eabs (s
->face
->box_line_width
);
1980 /* If there is a margin around the image, adjust x- and y-position
1982 if (s
->slice
.x
== 0)
1983 x
+= s
->img
->hmargin
;
1984 if (s
->slice
.y
== 0)
1985 y
+= s
->img
->vmargin
;
1989 HDC compat_hdc
= CreateCompatibleDC (hdc
);
1990 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
1991 HBRUSH orig_brush
= SelectObject (hdc
, fg_brush
);
1992 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, s
->img
->pixmap
);
1996 HDC mask_dc
= CreateCompatibleDC (hdc
);
1997 HGDIOBJ mask_orig_obj
= SelectObject (mask_dc
, s
->img
->mask
);
1999 SetTextColor (hdc
, RGB (0, 0, 0));
2000 SetBkColor (hdc
, RGB (255, 255, 255));
2001 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2002 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2003 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2004 mask_dc
, s
->slice
.x
, s
->slice
.y
, SRCAND
);
2005 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2006 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCINVERT
);
2008 SelectObject (mask_dc
, mask_orig_obj
);
2013 SetTextColor (hdc
, s
->gc
->foreground
);
2014 SetBkColor (hdc
, s
->gc
->background
);
2016 BitBlt (hdc
, x
, y
, s
->slice
.width
, s
->slice
.height
,
2017 compat_hdc
, s
->slice
.x
, s
->slice
.y
, SRCCOPY
);
2019 /* When the image has a mask, we can expect that at
2020 least part of a mouse highlight or a block cursor will
2021 be visible. If the image doesn't have a mask, make
2022 a block cursor visible by drawing a rectangle around
2023 the image. I believe it's looking better if we do
2024 nothing here for mouse-face. */
2025 if (s
->hl
== DRAW_CURSOR
)
2027 int r
= s
->img
->relief
;
2029 w32_draw_rectangle (hdc
, s
->gc
, x
- r
, y
- r
,
2030 s
->slice
.width
+ r
*2 - 1,
2031 s
->slice
.height
+ r
*2 - 1);
2035 SelectObject (hdc
, orig_brush
);
2036 DeleteObject (fg_brush
);
2037 SelectObject (compat_hdc
, orig_obj
);
2038 DeleteDC (compat_hdc
);
2041 w32_draw_rectangle (hdc
, s
->gc
, x
, y
,
2042 s
->slice
.width
- 1, s
->slice
.height
- 1);
2044 SelectObject (hdc
, orig_hdc_obj
);
2049 /* Draw part of the background of glyph string S. X, Y, W, and H
2050 give the rectangle to draw. */
2053 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2055 #if 0 /* TODO: stipple */
2058 /* Fill background with a stipple pattern. */
2059 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2060 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2061 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2065 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2069 /* Draw image glyph string S.
2072 s->x +-------------------------
2075 | +-------------------------
2078 | | +-------------------
2084 x_draw_image_glyph_string (struct glyph_string
*s
)
2087 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2088 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2093 if (s
->slice
.y
== 0)
2094 height
-= box_line_vwidth
;
2095 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2096 height
-= box_line_vwidth
;
2098 /* Fill background with face under the image. Do it only if row is
2099 taller than image or if image has a clip mask to reduce
2101 s
->stippled_p
= s
->face
->stipple
!= 0;
2102 if (height
> s
->slice
.height
2106 || s
->img
->pixmap
== 0
2107 || s
->width
!= s
->background_width
)
2109 width
= s
->background_width
;
2111 if (s
->first_glyph
->left_box_line_p
2114 x
+= box_line_hwidth
;
2115 width
-= box_line_hwidth
;
2119 if (s
->slice
.y
== 0)
2120 y
+= box_line_vwidth
;
2122 #if 0 /* TODO: figure out if we need to do this on Windows. */
2125 /* Create a pixmap as large as the glyph string. Fill it
2126 with the background color. Copy the image to it, using
2127 its mask. Copy the temporary pixmap to the display. */
2128 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2129 int depth
= DefaultDepthOfScreen (screen
);
2131 /* Create a pixmap as large as the glyph string. */
2132 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2133 s
->background_width
,
2136 /* Don't clip in the following because we're working on the
2138 XSetClipMask (s
->display
, s
->gc
, None
);
2140 /* Fill the pixmap with the background color/stipple. */
2143 /* Fill background with a stipple pattern. */
2144 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2145 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2146 0, 0, s
->background_width
, s
->height
);
2147 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2152 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2154 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2155 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2156 0, 0, s
->background_width
, s
->height
);
2157 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2162 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
2164 s
->background_filled_p
= 1;
2167 /* Draw the foreground. */
2170 w32_draw_image_foreground_1 (s
, pixmap
);
2171 x_set_glyph_string_clipping (s
);
2173 HDC compat_hdc
= CreateCompatibleDC (s
->hdc
);
2174 HBRUSH fg_brush
= CreateSolidBrush (s
->gc
->foreground
);
2175 HBRUSH orig_brush
= SelectObject (s
->hdc
, fg_brush
);
2176 HGDIOBJ orig_obj
= SelectObject (compat_hdc
, pixmap
);
2178 SetTextColor (s
->hdc
, s
->gc
->foreground
);
2179 SetBkColor (s
->hdc
, s
->gc
->background
);
2180 BitBlt (s
->hdc
, s
->x
, s
->y
, s
->background_width
, s
->height
,
2181 compat_hdc
, 0, 0, SRCCOPY
);
2183 SelectObject (s
->hdc
, orig_brush
);
2184 DeleteObject (fg_brush
);
2185 SelectObject (compat_hdc
, orig_obj
);
2186 DeleteDC (compat_hdc
);
2188 DeleteObject (pixmap
);
2192 x_draw_image_foreground (s
);
2194 /* If we must draw a relief around the image, do it. */
2196 || s
->hl
== DRAW_IMAGE_RAISED
2197 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2198 x_draw_image_relief (s
);
2202 /* Draw stretch glyph string S. */
2205 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2207 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2209 if (s
->hl
== DRAW_CURSOR
2210 && !x_stretch_cursor_p
)
2212 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2213 wide as the stretch glyph. */
2214 int width
, background_width
= s
->background_width
;
2217 if (!s
->row
->reversed_p
)
2219 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2223 background_width
-= left_x
- x
;
2229 /* In R2L rows, draw the cursor on the right edge of the
2231 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2233 if (x
+ background_width
> right_x
)
2234 background_width
-= x
- right_x
;
2235 x
+= background_width
;
2237 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2238 if (s
->row
->reversed_p
)
2242 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2244 /* Clear rest using the GC of the original non-cursor face. */
2245 if (width
< background_width
)
2247 XGCValues
*gc
= s
->face
->gc
;
2249 int w
= background_width
- width
, h
= s
->height
;
2253 if (!s
->row
->reversed_p
)
2257 if (s
->row
->mouse_face_p
2258 && cursor_in_mouse_face_p (s
->w
))
2260 x_set_mouse_face_gc (s
);
2266 get_glyph_string_clip_rect (s
, &r
);
2267 w32_set_clip_rectangle (hdc
, &r
);
2269 #if 0 /* TODO: stipple */
2270 if (s
->face
->stipple
)
2272 /* Fill background with a stipple pattern. */
2273 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2274 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2275 XSetFillStyle (s
->display
, gc
, FillSolid
);
2280 w32_fill_area (s
->f
, s
->hdc
, gc
->background
, x
, y
, w
, h
);
2284 else if (!s
->background_filled_p
)
2286 int background_width
= s
->background_width
;
2287 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2289 /* Don't draw into left margin, fringe or scrollbar area
2290 except for header line and mode line. */
2291 if (x
< left_x
&& !s
->row
->mode_line_p
)
2293 background_width
-= left_x
- x
;
2296 if (background_width
> 0)
2297 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2300 s
->background_filled_p
= 1;
2304 /* Draw glyph string S. */
2307 x_draw_glyph_string (struct glyph_string
*s
)
2309 bool relief_drawn_p
= 0;
2311 /* If S draws into the background of its successor, draw the
2312 background of the successor first so that S can draw into it.
2313 This makes S->next use XDrawString instead of XDrawImageString. */
2314 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2317 struct glyph_string
*next
;
2318 for (width
= 0, next
= s
->next
;
2319 next
&& width
< s
->right_overhang
;
2320 width
+= next
->width
, next
= next
->next
)
2321 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2323 x_set_glyph_string_gc (next
);
2324 x_set_glyph_string_clipping (next
);
2325 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2326 x_draw_stretch_glyph_string (next
);
2328 x_draw_glyph_string_background (next
, 1);
2329 next
->num_clips
= 0;
2333 /* Set up S->gc, set clipping and draw S. */
2334 x_set_glyph_string_gc (s
);
2336 /* Draw relief (if any) in advance for char/composition so that the
2337 glyph string can be drawn over it. */
2338 if (!s
->for_overlaps
2339 && s
->face
->box
!= FACE_NO_BOX
2340 && (s
->first_glyph
->type
== CHAR_GLYPH
2341 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2344 x_set_glyph_string_clipping (s
);
2345 x_draw_glyph_string_background (s
, 1);
2346 x_draw_glyph_string_box (s
);
2347 x_set_glyph_string_clipping (s
);
2350 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2352 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2353 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2354 /* We must clip just this glyph. left_overhang part has already
2355 drawn when s->prev was drawn, and right_overhang part will be
2356 drawn later when s->next is drawn. */
2357 x_set_glyph_string_clipping_exactly (s
, s
);
2359 x_set_glyph_string_clipping (s
);
2361 switch (s
->first_glyph
->type
)
2364 x_draw_image_glyph_string (s
);
2368 x_draw_stretch_glyph_string (s
);
2372 if (s
->for_overlaps
)
2373 s
->background_filled_p
= 1;
2375 x_draw_glyph_string_background (s
, 0);
2376 x_draw_glyph_string_foreground (s
);
2379 case COMPOSITE_GLYPH
:
2380 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2381 && ! s
->first_glyph
->u
.cmp
.automatic
))
2382 s
->background_filled_p
= 1;
2384 x_draw_glyph_string_background (s
, 1);
2385 x_draw_composite_glyph_string_foreground (s
);
2388 case GLYPHLESS_GLYPH
:
2389 if (s
->for_overlaps
)
2390 s
->background_filled_p
= 1;
2392 x_draw_glyph_string_background (s
, 0);
2393 x_draw_glyphless_glyph_string_foreground (s
);
2400 if (!s
->for_overlaps
)
2402 /* Draw underline. */
2403 if (s
->face
->underline_p
)
2405 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2409 if (s
->face
->underline_defaulted_p
)
2410 color
= s
->gc
->foreground
;
2412 color
= s
->face
->underline_color
;
2414 w32_draw_underwave (s
, color
);
2416 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2418 unsigned long thickness
, position
;
2421 if (s
->prev
&& s
->prev
->face
->underline_p
2422 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2424 /* We use the same underline style as the previous one. */
2425 thickness
= s
->prev
->underline_thickness
;
2426 position
= s
->prev
->underline_position
;
2430 /* Get the underline thickness. Default is 1 pixel. */
2431 if (s
->font
&& s
->font
->underline_thickness
> 0)
2432 thickness
= s
->font
->underline_thickness
;
2435 if (x_underline_at_descent_line
)
2436 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2439 /* Get the underline position. This is the recommended
2440 vertical offset in pixels from the baseline to the top of
2441 the underline. This is a signed value according to the
2442 specs, and its default is
2444 ROUND ((maximum_descent) / 2), with
2445 ROUND (x) = floor (x + 0.5) */
2447 if (x_use_underline_position_properties
2448 && s
->font
&& s
->font
->underline_position
>= 0)
2449 position
= s
->font
->underline_position
;
2451 position
= (s
->font
->descent
+ 1) / 2;
2453 position
= max (position
, underline_minimum_offset
);
2455 /* Check the sanity of thickness and position. We should
2456 avoid drawing underline out of the current line area. */
2457 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2458 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2459 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2460 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2461 s
->underline_thickness
= thickness
;
2462 s
->underline_position
=position
;
2463 y
= s
->ybase
+ position
;
2464 if (s
->face
->underline_defaulted_p
)
2466 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2471 w32_fill_area (s
->f
, s
->hdc
, s
->face
->underline_color
, s
->x
,
2476 /* Draw overline. */
2477 if (s
->face
->overline_p
)
2479 unsigned long dy
= 0, h
= 1;
2481 if (s
->face
->overline_color_defaulted_p
)
2483 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
,
2484 s
->y
+ dy
, s
->width
, h
);
2488 w32_fill_area (s
->f
, s
->hdc
, s
->face
->overline_color
, s
->x
,
2489 s
->y
+ dy
, s
->width
, h
);
2493 /* Draw strike-through. */
2494 if (s
->face
->strike_through_p
2495 && !FONT_TEXTMETRIC (s
->font
).tmStruckOut
)
2497 unsigned long h
= 1;
2498 unsigned long dy
= (s
->height
- h
) / 2;
2500 if (s
->face
->strike_through_color_defaulted_p
)
2502 w32_fill_area (s
->f
, s
->hdc
, s
->gc
->foreground
, s
->x
, s
->y
+ dy
,
2507 w32_fill_area (s
->f
, s
->hdc
, s
->face
->strike_through_color
, s
->x
,
2508 s
->y
+ dy
, s
->width
, h
);
2512 /* Draw relief if not yet drawn. */
2513 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2514 x_draw_glyph_string_box (s
);
2518 struct glyph_string
*prev
;
2520 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2521 if (prev
->hl
!= s
->hl
2522 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2524 /* As prev was drawn while clipped to its own area, we
2525 must draw the right_overhang part using s->hl now. */
2526 enum draw_glyphs_face save
= prev
->hl
;
2529 x_set_glyph_string_gc (prev
);
2530 x_set_glyph_string_clipping_exactly (s
, prev
);
2531 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2532 x_draw_glyph_string_foreground (prev
);
2534 x_draw_composite_glyph_string_foreground (prev
);
2535 w32_set_clip_rectangle (prev
->hdc
, NULL
);
2537 prev
->num_clips
= 0;
2543 struct glyph_string
*next
;
2545 for (next
= s
->next
; next
; next
= next
->next
)
2546 if (next
->hl
!= s
->hl
2547 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2549 /* As next will be drawn while clipped to its own area,
2550 we must draw the left_overhang part using s->hl now. */
2551 enum draw_glyphs_face save
= next
->hl
;
2554 x_set_glyph_string_gc (next
);
2555 x_set_glyph_string_clipping_exactly (s
, next
);
2556 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2557 x_draw_glyph_string_foreground (next
);
2559 x_draw_composite_glyph_string_foreground (next
);
2560 w32_set_clip_rectangle (next
->hdc
, NULL
);
2562 next
->num_clips
= 0;
2563 next
->clip_head
= s
->next
;
2568 /* Reset clipping. */
2569 w32_set_clip_rectangle (s
->hdc
, NULL
);
2574 /* Shift display to make room for inserted glyphs. */
2577 w32_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
,
2578 int width
, int height
, int shift_by
)
2582 hdc
= get_frame_dc (f
);
2583 BitBlt (hdc
, x
+ shift_by
, y
, width
, height
,
2584 hdc
, x
, y
, SRCCOPY
);
2586 release_frame_dc (f
, hdc
);
2590 /* Delete N glyphs at the nominal cursor position. Not implemented
2594 x_delete_glyphs (struct frame
*f
, register int n
)
2596 if (! FRAME_W32_P (f
))
2603 /* Clear entire frame. */
2606 x_clear_frame (struct frame
*f
)
2608 if (! FRAME_W32_P (f
))
2611 /* Clearing the frame will erase any cursor, so mark them all as no
2613 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2617 w32_clear_window (f
);
2619 /* We have to clear the scroll bars, too. If we have changed
2620 colors or something like that, then they should be notified. */
2621 x_scroll_bar_clear (f
);
2627 /* Make audible bell. */
2630 w32_ring_bell (struct frame
*f
)
2634 if (FRAME_W32_P (f
) && visible_bell
)
2637 HWND hwnd
= FRAME_W32_WINDOW (f
);
2639 for (i
= 0; i
< 5; i
++)
2641 FlashWindow (hwnd
, TRUE
);
2644 FlashWindow (hwnd
, FALSE
);
2647 w32_sys_ring_bell (f
);
2652 /***********************************************************************
2654 ***********************************************************************/
2656 /* Perform an insert-lines or delete-lines operation, inserting N
2657 lines or deleting -N lines at vertical position VPOS. */
2660 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
2662 if (! FRAME_W32_P (f
))
2669 /* Scroll part of the display as described by RUN. */
2672 x_scroll_run (struct window
*w
, struct run
*run
)
2674 struct frame
*f
= XFRAME (w
->frame
);
2675 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2676 HWND hwnd
= FRAME_W32_WINDOW (f
);
2679 /* Get frame-relative bounding box of the text display area of W,
2680 without mode lines. Include in this box the left and right
2682 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
2684 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
2685 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
2686 bottom_y
= y
+ height
;
2690 /* Scrolling up. Make sure we don't copy part of the mode
2691 line at the bottom. */
2692 if (from_y
+ run
->height
> bottom_y
)
2693 height
= bottom_y
- from_y
;
2695 height
= run
->height
;
2696 expect_dirty
= CreateRectRgn (x
, y
+ height
, x
+ width
, bottom_y
);
2700 /* Scrolling down. Make sure we don't copy over the mode line.
2702 if (to_y
+ run
->height
> bottom_y
)
2703 height
= bottom_y
- to_y
;
2705 height
= run
->height
;
2706 expect_dirty
= CreateRectRgn (x
, y
, x
+ width
, to_y
);
2711 /* Cursor off. Will be switched on again in x_update_window_end. */
2717 HRGN dirty
= CreateRectRgn (0, 0, 0, 0);
2718 HRGN combined
= CreateRectRgn (0, 0, 0, 0);
2720 from
.left
= to
.left
= x
;
2721 from
.right
= to
.right
= x
+ width
;
2723 from
.bottom
= from_y
+ height
;
2725 to
.bottom
= bottom_y
;
2727 ScrollWindowEx (hwnd
, 0, to_y
- from_y
, &from
, &to
, dirty
,
2728 NULL
, SW_INVALIDATE
);
2730 /* Combine this with what we expect to be dirty. This covers the
2731 case where not all of the region we expect is actually dirty. */
2732 CombineRgn (combined
, dirty
, expect_dirty
, RGN_OR
);
2734 /* If the dirty region is not what we expected, redraw the entire frame. */
2735 if (!EqualRgn (combined
, expect_dirty
))
2736 SET_FRAME_GARBAGED (f
);
2738 DeleteObject (dirty
);
2739 DeleteObject (combined
);
2743 DeleteObject (expect_dirty
);
2748 /***********************************************************************
2750 ***********************************************************************/
2753 frame_highlight (struct frame
*f
)
2755 x_update_cursor (f
, 1);
2756 x_set_frame_alpha (f
);
2760 frame_unhighlight (struct frame
*f
)
2762 x_update_cursor (f
, 1);
2763 x_set_frame_alpha (f
);
2766 /* The focus has changed. Update the frames as necessary to reflect
2767 the new situation. Note that we can't change the selected frame
2768 here, because the Lisp code we are interrupting might become confused.
2769 Each event gets marked with the frame in which it occurred, so the
2770 Lisp code can tell when the switch took place by examining the events. */
2773 x_new_focus_frame (struct w32_display_info
*dpyinfo
, struct frame
*frame
)
2775 struct frame
*old_focus
= dpyinfo
->w32_focus_frame
;
2777 if (frame
!= dpyinfo
->w32_focus_frame
)
2779 /* Set this before calling other routines, so that they see
2780 the correct value of w32_focus_frame. */
2781 dpyinfo
->w32_focus_frame
= frame
;
2783 if (old_focus
&& old_focus
->auto_lower
)
2784 x_lower_frame (old_focus
);
2786 if (dpyinfo
->w32_focus_frame
&& dpyinfo
->w32_focus_frame
->auto_raise
)
2787 dpyinfo
->w32_pending_autoraise_frame
= dpyinfo
->w32_focus_frame
;
2789 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
2792 x_frame_rehighlight (dpyinfo
);
2796 /* Handle FocusIn and FocusOut state changes for FRAME.
2797 If FRAME has focus and there exists more than one frame, puts
2798 a FOCUS_IN_EVENT into *BUFP. */
2801 x_focus_changed (int type
, int state
, struct w32_display_info
*dpyinfo
,
2802 struct frame
*frame
, struct input_event
*bufp
)
2804 if (type
== WM_SETFOCUS
)
2806 if (dpyinfo
->w32_focus_event_frame
!= frame
)
2808 x_new_focus_frame (dpyinfo
, frame
);
2809 dpyinfo
->w32_focus_event_frame
= frame
;
2811 /* Don't stop displaying the initial startup message
2812 for a switch-frame event we don't need. */
2813 if (NILP (Vterminal_frame
)
2814 && CONSP (Vframe_list
)
2815 && !NILP (XCDR (Vframe_list
)))
2824 bufp
->kind
= FOCUS_IN_EVENT
;
2825 XSETFRAME (bufp
->frame_or_window
, frame
);
2828 frame
->output_data
.x
->focus_state
|= state
;
2830 /* TODO: IME focus? */
2832 else if (type
== WM_KILLFOCUS
)
2834 frame
->output_data
.x
->focus_state
&= ~state
;
2836 if (dpyinfo
->w32_focus_event_frame
== frame
)
2838 dpyinfo
->w32_focus_event_frame
= 0;
2839 x_new_focus_frame (dpyinfo
, 0);
2841 bufp
->kind
= FOCUS_OUT_EVENT
;
2842 XSETFRAME (bufp
->frame_or_window
, frame
);
2845 /* TODO: IME focus? */
2850 /* The focus may have changed. Figure out if it is a real focus change,
2851 by checking both FocusIn/Out and Enter/LeaveNotify events.
2853 Returns FOCUS_IN_EVENT event in *BUFP. */
2856 w32_detect_focus_change (struct w32_display_info
*dpyinfo
, W32Msg
*event
,
2857 struct input_event
*bufp
)
2859 struct frame
*frame
;
2861 frame
= x_any_window_to_frame (dpyinfo
, event
->msg
.hwnd
);
2865 /* On w32, this is only called from focus events, so no switch needed. */
2866 x_focus_changed (event
->msg
.message
,
2867 (event
->msg
.message
== WM_KILLFOCUS
?
2868 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
2869 dpyinfo
, frame
, bufp
);
2873 /* Handle an event saying the mouse has moved out of an Emacs frame. */
2876 x_mouse_leave (struct w32_display_info
*dpyinfo
)
2878 x_new_focus_frame (dpyinfo
, dpyinfo
->w32_focus_event_frame
);
2881 /* The focus has changed, or we have redirected a frame's focus to
2882 another frame (this happens when a frame uses a surrogate
2883 mini-buffer frame). Shift the highlight as appropriate.
2885 The FRAME argument doesn't necessarily have anything to do with which
2886 frame is being highlighted or un-highlighted; we only use it to find
2887 the appropriate X display info. */
2890 w32_frame_rehighlight (struct frame
*frame
)
2892 if (! FRAME_W32_P (frame
))
2894 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
2898 x_frame_rehighlight (struct w32_display_info
*dpyinfo
)
2900 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
2902 if (dpyinfo
->w32_focus_frame
)
2904 dpyinfo
->x_highlight_frame
2905 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
)))
2906 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->w32_focus_frame
))
2907 : dpyinfo
->w32_focus_frame
);
2908 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
2910 fset_focus_frame (dpyinfo
->w32_focus_frame
, Qnil
);
2911 dpyinfo
->x_highlight_frame
= dpyinfo
->w32_focus_frame
;
2915 dpyinfo
->x_highlight_frame
= 0;
2917 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
2920 frame_unhighlight (old_highlight
);
2921 if (dpyinfo
->x_highlight_frame
)
2922 frame_highlight (dpyinfo
->x_highlight_frame
);
2926 /* Keyboard processing - modifier keys, etc. */
2928 /* Convert a keysym to its name. */
2931 x_get_keysym_name (int keysym
)
2933 /* Make static so we can always return it */
2934 static char value
[100];
2937 GetKeyNameText (keysym
, value
, 100);
2944 codepage_for_locale (LCID locale
)
2948 if (GetLocaleInfo (locale
, LOCALE_IDEFAULTANSICODEPAGE
, cp
, 20) > 0)
2955 /* Mouse clicks and mouse movement. Rah. */
2957 /* Parse a button MESSAGE. The button index is returned in PBUTTON, and
2958 the state in PUP. XBUTTON provides extra information for extended mouse
2959 button messages. Returns FALSE if unable to parse the message. */
2961 parse_button (int message
, int xbutton
, int * pbutton
, int * pup
)
2968 case WM_LBUTTONDOWN
:
2976 case WM_MBUTTONDOWN
:
2977 if (NILP (Vw32_swap_mouse_buttons
))
2984 if (NILP (Vw32_swap_mouse_buttons
))
2990 case WM_RBUTTONDOWN
:
2991 if (NILP (Vw32_swap_mouse_buttons
))
2998 if (NILP (Vw32_swap_mouse_buttons
))
3004 case WM_XBUTTONDOWN
:
3005 button
= xbutton
+ 2;
3009 button
= xbutton
+ 2;
3017 if (pbutton
) *pbutton
= button
;
3023 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3025 If the event is a button press, then note that we have grabbed
3029 construct_mouse_click (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3034 parse_button (msg
->msg
.message
, HIWORD (msg
->msg
.wParam
),
3037 /* Make the event type NO_EVENT; we'll change that when we decide
3039 result
->kind
= MOUSE_CLICK_EVENT
;
3040 result
->code
= button
;
3041 result
->timestamp
= msg
->msg
.time
;
3042 result
->modifiers
= (msg
->dwModifiers
3047 XSETINT (result
->x
, LOWORD (msg
->msg
.lParam
));
3048 XSETINT (result
->y
, HIWORD (msg
->msg
.lParam
));
3049 XSETFRAME (result
->frame_or_window
, f
);
3055 construct_mouse_wheel (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3060 result
->kind
= msg
->msg
.message
== WM_MOUSEHWHEEL
? HORIZ_WHEEL_EVENT
3063 result
->timestamp
= msg
->msg
.time
;
3065 /* A WHEEL_DELTA positive value indicates that the wheel was rotated
3066 forward, away from the user (up); a negative value indicates that
3067 the wheel was rotated backward, toward the user (down). */
3068 delta
= GET_WHEEL_DELTA_WPARAM (msg
->msg
.wParam
);
3070 /* The up and down modifiers indicate if the wheel was rotated up or
3071 down based on WHEEL_DELTA value. */
3072 result
->modifiers
= (msg
->dwModifiers
3073 | ((delta
< 0 ) ? down_modifier
: up_modifier
));
3075 /* With multiple monitors, we can legitimately get negative
3076 coordinates, so cast to short to interpret them correctly. */
3077 p
.x
= (short) LOWORD (msg
->msg
.lParam
);
3078 p
.y
= (short) HIWORD (msg
->msg
.lParam
);
3079 ScreenToClient (msg
->msg
.hwnd
, &p
);
3080 XSETINT (result
->x
, p
.x
);
3081 XSETINT (result
->y
, p
.y
);
3082 XSETFRAME (result
->frame_or_window
, f
);
3088 construct_drag_n_drop (struct input_event
*result
, W32Msg
*msg
, struct frame
*f
)
3095 wchar_t name_w
[MAX_PATH
];
3096 #ifdef NTGUI_UNICODE
3097 const int use_unicode
= 1;
3099 int use_unicode
= w32_unicode_filenames
;
3100 char name_a
[MAX_PATH
];
3101 char file
[MAX_UTF8_PATH
];
3105 result
->kind
= DRAG_N_DROP_EVENT
;
3107 result
->timestamp
= msg
->msg
.time
;
3108 result
->modifiers
= msg
->dwModifiers
;
3110 hdrop
= (HDROP
) msg
->msg
.wParam
;
3111 DragQueryPoint (hdrop
, &p
);
3114 p
.x
= LOWORD (msg
->msg
.lParam
);
3115 p
.y
= HIWORD (msg
->msg
.lParam
);
3116 ScreenToClient (msg
->msg
.hwnd
, &p
);
3119 XSETINT (result
->x
, p
.x
);
3120 XSETINT (result
->y
, p
.y
);
3122 num_files
= DragQueryFile (hdrop
, 0xFFFFFFFF, NULL
, 0);
3125 for (i
= 0; i
< num_files
; i
++)
3129 eassert (DragQueryFileW (hdrop
, i
, NULL
, 0) < MAX_PATH
);
3130 /* If DragQueryFile returns zero, it failed to fetch a file
3132 if (DragQueryFileW (hdrop
, i
, name_w
, MAX_PATH
) == 0)
3134 #ifdef NTGUI_UNICODE
3135 files
= Fcons (from_unicode_buffer (name_w
), files
);
3137 filename_from_utf16 (name_w
, file
);
3138 files
= Fcons (DECODE_FILE (build_unibyte_string (file
)), files
);
3139 #endif /* NTGUI_UNICODE */
3141 #ifndef NTGUI_UNICODE
3144 eassert (DragQueryFileA (hdrop
, i
, NULL
, 0) < MAX_PATH
);
3145 if (DragQueryFileA (hdrop
, i
, name_a
, MAX_PATH
) == 0)
3147 filename_from_ansi (name_a
, file
);
3148 files
= Fcons (DECODE_FILE (build_unibyte_string (file
)), files
);
3155 XSETFRAME (frame
, f
);
3156 result
->frame_or_window
= frame
;
3157 result
->arg
= files
;
3164 /* File event notifications (see w32notify.c). */
3167 lispy_file_action (DWORD action
)
3169 static char unknown_fmt
[] = "unknown-action(%d)";
3174 case FILE_ACTION_ADDED
:
3177 case FILE_ACTION_REMOVED
:
3180 case FILE_ACTION_MODIFIED
:
3183 case FILE_ACTION_RENAMED_OLD_NAME
:
3184 retval
= Qrenamed_from
;
3186 case FILE_ACTION_RENAMED_NEW_NAME
:
3187 retval
= Qrenamed_to
;
3191 char buf
[sizeof(unknown_fmt
) - 1 + INT_STRLEN_BOUND (DWORD
)];
3193 sprintf (buf
, unknown_fmt
, action
);
3194 retval
= intern (buf
);
3203 /* Put file notifications into the Emacs input event queue. This
3204 function runs when the WM_EMACS_FILENOTIFY message arrives from a
3207 queue_notifications (struct input_event
*event
, W32Msg
*msg
, struct frame
*f
,
3210 BYTE
*p
= file_notifications
;
3211 FILE_NOTIFY_INFORMATION
*fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3212 const DWORD min_size
3213 = offsetof (FILE_NOTIFY_INFORMATION
, FileName
) + sizeof(wchar_t);
3216 /* We cannot process notification before Emacs is fully initialized,
3217 since we need the UTF-16LE coding-system to be set up. */
3220 notification_buffer_in_use
= 0;
3224 XSETFRAME (frame
, f
);
3227 if (notification_buffer_in_use
)
3229 DWORD info_size
= notifications_size
;
3230 Lisp_Object cs
= intern ("utf-16le");
3231 Lisp_Object obj
= w32_get_watch_object (notifications_desc
);
3233 /* notifications_size could be zero when the buffer of
3234 notifications overflowed on the OS level, or when the
3235 directory being watched was itself deleted. Do nothing in
3238 && !NILP (obj
) && CONSP (obj
))
3240 Lisp_Object callback
= XCDR (obj
);
3242 while (info_size
>= min_size
)
3244 Lisp_Object utf_16_fn
3245 = make_unibyte_string ((char *)fni
->FileName
,
3246 fni
->FileNameLength
);
3247 /* Note: mule-conf is preloaded, so utf-16le must
3248 already be defined at this point. */
3250 = code_convert_string_norecord (utf_16_fn
, cs
, 0);
3251 Lisp_Object action
= lispy_file_action (fni
->Action
);
3253 event
->kind
= FILE_NOTIFY_EVENT
;
3255 = (ptrdiff_t)XINT (XIL ((EMACS_INT
)notifications_desc
));
3256 event
->timestamp
= msg
->msg
.time
;
3257 event
->modifiers
= 0;
3258 event
->frame_or_window
= callback
;
3259 event
->arg
= Fcons (action
, fname
);
3260 kbd_buffer_store_event (event
);
3263 if (!fni
->NextEntryOffset
)
3265 p
+= fni
->NextEntryOffset
;
3266 fni
= (PFILE_NOTIFY_INFORMATION
)p
;
3267 info_size
-= fni
->NextEntryOffset
;
3270 notification_buffer_in_use
= 0;
3273 DebPrint (("We were promised notifications, but in-use flag is zero!\n"));
3276 /* We've stuffed all the events ourselves, so w32_read_socket shouldn't. */
3277 event
->kind
= NO_EVENT
;
3279 #endif /* WINDOWSNT */
3280 #endif /* HAVE_W32NOTIFY */
3283 /* Function to report a mouse movement to the mainstream Emacs code.
3284 The input handler calls this.
3286 We have received a mouse movement event, which is given in *event.
3287 If the mouse is over a different glyph than it was last time, tell
3288 the mainstream emacs code by setting mouse_moved. If not, ask for
3289 another motion event, so we can check again the next time it moves. */
3292 note_mouse_movement (struct frame
*frame
, MSG
*msg
)
3294 struct w32_display_info
*dpyinfo
;
3295 int mouse_x
= LOWORD (msg
->lParam
);
3296 int mouse_y
= HIWORD (msg
->lParam
);
3299 if (!FRAME_X_OUTPUT (frame
))
3302 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3303 dpyinfo
->last_mouse_movement_time
= msg
->time
;
3304 dpyinfo
->last_mouse_motion_frame
= frame
;
3305 dpyinfo
->last_mouse_motion_x
= mouse_x
;
3306 dpyinfo
->last_mouse_motion_y
= mouse_y
;
3308 if (msg
->hwnd
!= FRAME_W32_WINDOW (frame
))
3310 frame
->mouse_moved
= 1;
3311 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3312 note_mouse_highlight (frame
, -1, -1);
3313 dpyinfo
->last_mouse_glyph_frame
= NULL
;
3317 /* Has the mouse moved off the glyph it was on at the last sighting? */
3318 r
= &dpyinfo
->last_mouse_glyph
;
3319 if (frame
!= dpyinfo
->last_mouse_glyph_frame
3320 || mouse_x
< r
->left
|| mouse_x
>= r
->right
3321 || mouse_y
< r
->top
|| mouse_y
>= r
->bottom
)
3323 frame
->mouse_moved
= 1;
3324 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3325 note_mouse_highlight (frame
, mouse_x
, mouse_y
);
3326 /* Remember the mouse position here, as w32_mouse_position only
3327 gets called when mouse tracking is enabled but we also need
3328 to keep track of the mouse for help_echo and highlighting at
3330 remember_mouse_glyph (frame
, mouse_x
, mouse_y
, r
);
3331 dpyinfo
->last_mouse_glyph_frame
= frame
;
3339 /************************************************************************
3341 ************************************************************************/
3343 static struct scroll_bar
*x_window_to_scroll_bar (Window
, int);
3344 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
3345 enum scroll_bar_part
*,
3346 Lisp_Object
*, Lisp_Object
*,
3348 static void x_horizontal_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
3349 enum scroll_bar_part
*,
3350 Lisp_Object
*, Lisp_Object
*,
3352 static void x_check_fullscreen (struct frame
*);
3355 w32_define_cursor (Window window
, Cursor cursor
)
3357 PostMessage (window
, WM_EMACS_SETCURSOR
, (WPARAM
) cursor
, 0);
3360 /* Return the current position of the mouse.
3361 *fp should be a frame which indicates which display to ask about.
3363 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3364 and *part to the frame, window, and scroll bar part that the mouse
3365 is over. Set *x and *y to the portion and whole of the mouse's
3366 position on the scroll bar.
3368 If the mouse movement started elsewhere, set *fp to the frame the
3369 mouse is on, *bar_window to nil, and *x and *y to the character cell
3372 Set *time to the server time-stamp for the time at which the mouse
3373 was at this position.
3375 Don't store anything if we don't have a valid set of values to report.
3377 This clears the mouse_moved flag, so we can wait for the next mouse
3381 w32_mouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3382 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3383 unsigned long *time
)
3386 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
3390 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
3392 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
3394 if (bar
->horizontal
)
3395 x_horizontal_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3397 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3403 Lisp_Object frame
, tail
;
3405 /* Clear the mouse-moved flag for every frame on this display. */
3406 FOR_EACH_FRAME (tail
, frame
)
3407 XFRAME (frame
)->mouse_moved
= 0;
3409 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3413 /* Now we have a position on the root; find the innermost window
3414 containing the pointer. */
3416 /* If mouse was grabbed on a frame, give coords for that
3417 frame even if the mouse is now outside it. Otherwise
3418 check for window under mouse on one of our frames. */
3419 f1
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
3420 : x_any_window_to_frame (dpyinfo
, WindowFromPoint (pt
)));
3422 /* If not, is it one of our scroll bars? */
3425 struct scroll_bar
*bar
3426 = x_window_to_scroll_bar (WindowFromPoint (pt
), 2);
3429 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3432 if (f1
== 0 && insist
> 0)
3433 f1
= SELECTED_FRAME ();
3437 /* Ok, we found a frame. Store all the values.
3438 last_mouse_glyph is a rectangle used to reduce the
3439 generation of mouse events. To not miss any motion
3440 events, we must divide the frame into rectangles of the
3441 size of the smallest character that could be displayed
3442 on it, i.e. into the same rectangles that matrices on
3443 the frame are divided into. */
3445 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
3446 ScreenToClient (FRAME_W32_WINDOW (f1
), &pt
);
3447 remember_mouse_glyph (f1
, pt
.x
, pt
.y
, &dpyinfo
->last_mouse_glyph
);
3448 dpyinfo
->last_mouse_glyph_frame
= f1
;
3455 *time
= dpyinfo
->last_mouse_movement_time
;
3464 /***********************************************************************
3466 ***********************************************************************/
3468 /* Handle mouse button event on the tool-bar of frame F, at
3469 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
3470 or ButtonRelease. */
3473 w32_handle_tool_bar_click (struct frame
*f
, struct input_event
*button_event
)
3475 int x
= XFASTINT (button_event
->x
);
3476 int y
= XFASTINT (button_event
->y
);
3478 if (button_event
->modifiers
& down_modifier
)
3479 handle_tool_bar_click (f
, x
, y
, 1, 0);
3481 handle_tool_bar_click (f
, x
, y
, 0,
3482 button_event
->modifiers
& ~up_modifier
);
3487 /***********************************************************************
3489 ***********************************************************************/
3491 /* Scroll bar support. */
3493 /* Given a window ID, find the struct scroll_bar which manages it
3494 vertically. This can be called in GC, so we have to make sure to
3495 strip off mark bits. */
3497 static struct scroll_bar
*
3498 x_window_to_scroll_bar (Window window_id
, int type
)
3500 Lisp_Object tail
, frame
;
3502 FOR_EACH_FRAME (tail
, frame
)
3504 Lisp_Object bar
, condemned
;
3506 /* Scan this frame's scroll bar list for a scroll bar with the
3508 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3509 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3510 /* This trick allows us to search both the ordinary and
3511 condemned scroll bar lists with one loop. */
3512 ! NILP (bar
) || (bar
= condemned
,
3515 bar
= XSCROLL_BAR (bar
)->next
)
3516 if (SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
)) == window_id
3518 || (type
== 1 && XSCROLL_BAR (bar
)->horizontal
)
3519 || (type
== 0 && !XSCROLL_BAR (bar
)->horizontal
)))
3520 return XSCROLL_BAR (bar
);
3528 /* Set the thumb size and position of vertical scroll bar BAR. We are currently
3529 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3532 w32_set_scroll_bar_thumb (struct scroll_bar
*bar
,
3533 int portion
, int position
, int whole
)
3535 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3536 /* We use the whole scroll-bar height in the calculations below, to
3537 avoid strange effects like scrolling backwards when just clicking
3538 on the handle (without moving it). */
3539 double range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
)
3540 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3541 int sb_page
, sb_pos
;
3542 BOOL draggingp
= bar
->dragging
? TRUE
: FALSE
;
3545 /* We used to change the nPage setting while dragging the handle,
3546 but that had very strange effects (such as scrolling backwards
3547 while dragging downwards).
3549 Now, we don't change the nPage setting while dragging unless we
3550 get near to the end of the buffer, in which case we often have to
3551 resize the handle to "go all the way". */
3557 si
.cbSize
= sizeof (si
);
3558 si
.fMask
= SIF_POS
| SIF_PAGE
;
3559 GetScrollInfo (w
, SB_CTL
, &si
);
3560 near_bottom_p
= si
.nPos
+ si
.nPage
>= range
;
3568 /* Position scroll bar at rock bottom if the bottom of the
3569 buffer is visible. This avoids shrinking the thumb away
3570 to nothing if it is held at the bottom of the buffer. */
3571 if (position
+ portion
>= whole
&& !draggingp
)
3573 sb_page
= range
* (whole
- position
) / whole
;
3578 sb_pos
= position
* range
/ whole
;
3579 sb_page
= (min (portion
, (whole
- position
)) * range
) / whole
;
3588 sb_page
= max (sb_page
, VERTICAL_SCROLL_BAR_MIN_HANDLE
);
3592 si
.cbSize
= sizeof (si
);
3593 si
.fMask
= SIF_PAGE
| SIF_POS
;
3597 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3602 /* Set the thumb size and position of horizontal scroll bar BAR. We are currently
3603 displaying PORTION out of a whole WHOLE, and our position POSITION. */
3606 w32_set_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
,
3607 int portion
, int position
, int whole
)
3609 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
3614 si
.cbSize
= sizeof (si
);
3615 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
;
3618 /* Allow nPage to be one larger than nPos so we don't allow to scroll
3619 an already fully visible buffer. */
3620 si
.nPage
= min (portion
, si
.nMax
) + 1;
3621 si
.nPos
= min (position
, si
.nMax
);
3622 SetScrollInfo (w
, SB_CTL
, &si
, TRUE
);
3628 /************************************************************************
3629 Scroll bars, general
3630 ************************************************************************/
3633 my_create_vscrollbar (struct frame
* f
, struct scroll_bar
* bar
)
3635 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3636 WM_EMACS_CREATEVSCROLLBAR
, (WPARAM
) f
,
3641 my_create_hscrollbar (struct frame
* f
, struct scroll_bar
* bar
)
3643 return (HWND
) SendMessage (FRAME_W32_WINDOW (f
),
3644 WM_EMACS_CREATEHSCROLLBAR
, (WPARAM
) f
,
3648 /*#define ATTACH_THREADS*/
3651 my_show_window (struct frame
*f
, HWND hwnd
, int how
)
3653 #ifndef ATTACH_THREADS
3654 return SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SHOWWINDOW
,
3655 (WPARAM
) hwnd
, (LPARAM
) how
);
3657 return ShowWindow (hwnd
, how
);
3662 my_set_window_pos (HWND hwnd
, HWND hwndAfter
,
3663 int x
, int y
, int cx
, int cy
, UINT flags
)
3665 #ifndef ATTACH_THREADS
3667 pos
.hwndInsertAfter
= hwndAfter
;
3673 SendMessage (hwnd
, WM_EMACS_SETWINDOWPOS
, (WPARAM
) &pos
, 0);
3675 SetWindowPos (hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
3681 my_set_focus (struct frame
* f
, HWND hwnd
)
3683 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_SETFOCUS
,
3689 my_set_foreground_window (HWND hwnd
)
3691 SendMessage (hwnd
, WM_EMACS_SETFOREGROUND
, (WPARAM
) hwnd
, 0);
3696 my_destroy_window (struct frame
* f
, HWND hwnd
)
3698 SendMessage (FRAME_W32_WINDOW (f
), WM_EMACS_DESTROYWINDOW
,
3703 my_bring_window_to_top (HWND hwnd
)
3705 SendMessage (hwnd
, WM_EMACS_BRINGTOTOP
, (WPARAM
) hwnd
, 0);
3708 /* Create a scroll bar and return the scroll bar vector for it. W is
3709 the Emacs window on which to create the scroll bar. TOP, LEFT,
3710 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
3713 static struct scroll_bar
*
3714 x_scroll_bar_create (struct window
*w
, int left
, int top
, int width
, int height
, bool horizontal
)
3716 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3719 struct scroll_bar
*bar
3720 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, top
, PVEC_OTHER
);
3725 XSETWINDOW (bar
->window
, w
);
3729 bar
->height
= height
;
3733 bar
->horizontal
= horizontal
;
3735 /* Requires geometry to be set before call to create the real window */
3738 hwnd
= my_create_hscrollbar (f
, bar
);
3740 hwnd
= my_create_vscrollbar (f
, bar
);
3742 si
.cbSize
= sizeof (si
);
3746 si
.nMax
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, width
)
3747 + HORIZONTAL_SCROLL_BAR_MIN_HANDLE
;
3749 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3750 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3754 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3756 SET_SCROLL_BAR_W32_WINDOW (bar
, hwnd
);
3758 /* Add bar to its frame's list of scroll bars. */
3759 bar
->next
= FRAME_SCROLL_BARS (f
);
3761 XSETVECTOR (barobj
, bar
);
3762 fset_scroll_bars (f
, barobj
);
3763 if (! NILP (bar
->next
))
3764 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3772 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
3776 x_scroll_bar_remove (struct scroll_bar
*bar
)
3778 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3782 /* Destroy the window. */
3783 my_destroy_window (f
, SCROLL_BAR_W32_WINDOW (bar
));
3785 /* Dissociate this scroll bar from its window. */
3786 if (bar
->horizontal
)
3787 wset_horizontal_scroll_bar (XWINDOW (bar
->window
), Qnil
);
3789 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
3794 /* Set the handle of the vertical scroll bar for WINDOW to indicate that
3795 we are displaying PORTION characters out of a total of WHOLE
3796 characters, starting at POSITION. If WINDOW has no vertical scroll
3799 w32_set_vertical_scroll_bar (struct window
*w
,
3800 int portion
, int whole
, int position
)
3802 struct frame
*f
= XFRAME (w
->frame
);
3804 struct scroll_bar
*bar
;
3805 int top
, height
, left
, width
;
3806 int window_y
, window_height
;
3808 /* Get window dimensions. */
3809 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
3811 height
= window_height
;
3813 /* Compute the left edge and the width of the scroll bar area. */
3814 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
3815 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
3817 /* Does the scroll bar exist yet? */
3818 if (NILP (w
->vertical_scroll_bar
))
3822 if (width
> 0 && height
> 0)
3824 hdc
= get_frame_dc (f
);
3825 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3826 release_frame_dc (f
, hdc
);
3830 bar
= x_scroll_bar_create (w
, left
, top
, width
, height
, 0);
3834 /* It may just need to be moved and resized. */
3837 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
3838 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3840 /* If already correctly positioned, do nothing. */
3841 if (bar
->left
== left
3843 && bar
->width
== width
3844 && bar
->height
== height
)
3846 /* Redraw after clear_frame. */
3847 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3848 InvalidateRect (hwnd
, NULL
, FALSE
);
3856 if (width
&& height
)
3858 hdc
= get_frame_dc (f
);
3859 /* Since Windows scroll bars are smaller than the space reserved
3860 for them on the frame, we have to clear "under" them. */
3861 w32_clear_area (f
, hdc
, left
, top
, width
, height
);
3862 release_frame_dc (f
, hdc
);
3864 /* Make sure scroll bar is "visible" before moving, to ensure the
3865 area of the parent window now exposed will be refreshed. */
3866 my_show_window (f
, hwnd
, SW_HIDE
);
3867 MoveWindow (hwnd
, left
, top
, width
, max (height
, 1), TRUE
);
3869 si
.cbSize
= sizeof (si
);
3870 si
.fMask
= SIF_RANGE
;
3872 si
.nMax
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
)
3873 + VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3875 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3877 my_show_window (f
, hwnd
, SW_NORMAL
);
3878 /* InvalidateRect (w, NULL, FALSE); */
3880 /* Remember new settings. */
3884 bar
->height
= height
;
3889 w32_set_scroll_bar_thumb (bar
, portion
, position
, whole
);
3890 XSETVECTOR (barobj
, bar
);
3891 wset_vertical_scroll_bar (w
, barobj
);
3894 /* Set the handle of the horizontal scroll bar for WINDOW to indicate
3895 that we are displaying PORTION characters out of a total of WHOLE
3896 characters, starting at POSITION. If WINDOW has no horizontal scroll
3899 w32_set_horizontal_scroll_bar (struct window
*w
,
3900 int portion
, int whole
, int position
)
3902 struct frame
*f
= XFRAME (w
->frame
);
3904 struct scroll_bar
*bar
;
3905 int top
, height
, left
, width
;
3906 int window_x
, window_width
;
3907 int clear_left
= WINDOW_LEFT_EDGE_X (w
);
3908 int clear_width
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
3910 /* Get window dimensions. */
3911 window_box (w
, ANY_AREA
, &window_x
, 0, &window_width
, 0);
3913 height
= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
3914 width
= window_width
;
3915 top
= WINDOW_SCROLL_BAR_AREA_Y (w
);
3917 /* Does the scroll bar exist yet? */
3918 if (NILP (w
->horizontal_scroll_bar
))
3922 if (width
> 0 && height
> 0)
3924 hdc
= get_frame_dc (f
);
3925 w32_clear_area (f
, hdc
, clear_left
, top
, clear_width
, height
);
3926 release_frame_dc (f
, hdc
);
3930 bar
= x_scroll_bar_create (w
, left
, top
, width
, height
, 1);
3934 /* It may just need to be moved and resized. */
3937 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
3938 hwnd
= SCROLL_BAR_W32_WINDOW (bar
);
3940 /* If already correctly positioned, do nothing. */
3941 if (bar
->left
== left
&& bar
->top
== top
3942 && bar
->width
== width
&& bar
->height
== height
)
3944 /* Redraw after clear_frame. */
3945 if (!my_show_window (f
, hwnd
, SW_NORMAL
))
3946 InvalidateRect (hwnd
, NULL
, FALSE
);
3954 if (width
&& height
)
3956 hdc
= get_frame_dc (f
);
3957 /* Since Windows scroll bars are smaller than the space reserved
3958 for them on the frame, we have to clear "under" them. */
3959 w32_clear_area (f
, hdc
, clear_left
, top
, clear_width
, height
);
3960 release_frame_dc (f
, hdc
);
3962 /* Make sure scroll bar is "visible" before moving, to ensure the
3963 area of the parent window now exposed will be refreshed. */
3964 my_show_window (f
, hwnd
, SW_HIDE
);
3965 MoveWindow (hwnd
, left
, top
, width
, max (height
, 1), TRUE
);
3967 /* +++ SetScrollInfo +++ */
3968 si
.cbSize
= sizeof (si
);
3969 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
;
3972 si
.nPage
= min (portion
, si
.nMax
) + 1;
3973 si
.nPos
= min (position
, si
.nMax
);
3974 SetScrollInfo (hwnd
, SB_CTL
, &si
, FALSE
);
3976 my_show_window (f
, hwnd
, SW_NORMAL
);
3977 /* InvalidateRect (w, NULL, FALSE); */
3979 /* Remember new settings. */
3983 bar
->height
= height
;
3989 w32_set_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
3990 XSETVECTOR (barobj
, bar
);
3991 wset_horizontal_scroll_bar (w
, barobj
);
3995 /* The following three hooks are used when we're doing a thorough
3996 redisplay of the frame. We don't explicitly know which scroll bars
3997 are going to be deleted, because keeping track of when windows go
3998 away is a real pain - "Can you say set-window-configuration, boys
3999 and girls?" Instead, we just assert at the beginning of redisplay
4000 that *all* scroll bars are to be removed, and then save a scroll bar
4001 from the fiery pit when we actually redisplay its window. */
4003 /* Arrange for all scroll bars on FRAME to be removed at the next call
4004 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4005 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4008 w32_condemn_scroll_bars (struct frame
*frame
)
4010 if (!NILP (FRAME_SCROLL_BARS (frame
)))
4012 if (!NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
4014 /* Prepend scrollbars to already condemned ones. */
4015 Lisp_Object last
= FRAME_SCROLL_BARS (frame
);
4017 while (!NILP (XSCROLL_BAR (last
)->next
))
4018 last
= XSCROLL_BAR (last
)->next
;
4020 XSCROLL_BAR (last
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
4021 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= last
;
4024 fset_condemned_scroll_bars (frame
, FRAME_SCROLL_BARS (frame
));
4025 fset_scroll_bars (frame
, Qnil
);
4030 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4031 Note that WINDOW isn't necessarily condemned at all. */
4034 w32_redeem_scroll_bar (struct window
*w
)
4036 struct scroll_bar
*bar
;
4040 /* We can't redeem this window's scroll bar if it doesn't have one. */
4041 if (NILP (w
->vertical_scroll_bar
) && NILP (w
->horizontal_scroll_bar
))
4044 if (!NILP (w
->vertical_scroll_bar
) && WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4046 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4047 /* Unlink it from the condemned list. */
4048 f
= XFRAME (WINDOW_FRAME (w
));
4049 if (NILP (bar
->prev
))
4051 /* If the prev pointer is nil, it must be the first in one of
4053 if (EQ (FRAME_SCROLL_BARS (f
), w
->vertical_scroll_bar
))
4054 /* It's not condemned. Everything's fine. */
4056 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4057 w
->vertical_scroll_bar
))
4058 fset_condemned_scroll_bars (f
, bar
->next
);
4060 /* If its prev pointer is nil, it must be at the front of
4061 one or the other! */
4065 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4067 if (! NILP (bar
->next
))
4068 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4070 bar
->next
= FRAME_SCROLL_BARS (f
);
4072 XSETVECTOR (barobj
, bar
);
4073 fset_scroll_bars (f
, barobj
);
4074 if (! NILP (bar
->next
))
4075 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4079 if (!NILP (w
->horizontal_scroll_bar
) && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
4081 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
4082 /* Unlink it from the condemned list. */
4083 f
= XFRAME (WINDOW_FRAME (w
));
4084 if (NILP (bar
->prev
))
4086 /* If the prev pointer is nil, it must be the first in one of
4088 if (EQ (FRAME_SCROLL_BARS (f
), w
->horizontal_scroll_bar
))
4089 /* It's not condemned. Everything's fine. */
4091 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4092 w
->horizontal_scroll_bar
))
4093 fset_condemned_scroll_bars (f
, bar
->next
);
4095 /* If its prev pointer is nil, it must be at the front of
4096 one or the other! */
4100 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4102 if (! NILP (bar
->next
))
4103 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4105 bar
->next
= FRAME_SCROLL_BARS (f
);
4107 XSETVECTOR (barobj
, bar
);
4108 fset_scroll_bars (f
, barobj
);
4109 if (! NILP (bar
->next
))
4110 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4114 /* Remove all scroll bars on FRAME that haven't been saved since the
4115 last call to `*condemn_scroll_bars_hook'. */
4118 w32_judge_scroll_bars (struct frame
*f
)
4120 Lisp_Object bar
, next
;
4122 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
4124 /* Clear out the condemned list now so we won't try to process any
4125 more events on the hapless scroll bars. */
4126 fset_condemned_scroll_bars (f
, Qnil
);
4128 for (; ! NILP (bar
); bar
= next
)
4130 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
4132 x_scroll_bar_remove (b
);
4135 b
->next
= b
->prev
= Qnil
;
4138 /* Now there should be no references to the condemned scroll bars,
4139 and they should get garbage-collected. */
4142 /* Handle a mouse click on the vertical scroll bar BAR. If
4143 *EMACS_EVENT's kind is set to something other than NO_EVENT, it is
4146 This may be called from a signal handler, so we have to ignore GC
4150 w32_scroll_bar_handle_click (struct scroll_bar
*bar
, W32Msg
*msg
,
4151 struct input_event
*emacs_event
)
4153 if (! WINDOWP (bar
->window
))
4156 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
4157 emacs_event
->code
= 0;
4158 /* not really meaningful to distinguish up/down */
4159 emacs_event
->modifiers
= msg
->dwModifiers
;
4160 emacs_event
->frame_or_window
= bar
->window
;
4161 emacs_event
->arg
= Qnil
;
4162 emacs_event
->timestamp
= msg
->msg
.time
;
4165 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4167 int dragging
= bar
->dragging
;
4170 si
.cbSize
= sizeof (si
);
4173 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
4177 FRAME_DISPLAY_INFO (f
)->last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
4179 switch (LOWORD (msg
->msg
.wParam
))
4182 emacs_event
->part
= scroll_bar_down_arrow
;
4185 emacs_event
->part
= scroll_bar_up_arrow
;
4188 emacs_event
->part
= scroll_bar_above_handle
;
4191 emacs_event
->part
= scroll_bar_below_handle
;
4194 emacs_event
->part
= scroll_bar_handle
;
4198 emacs_event
->part
= scroll_bar_handle
;
4202 case SB_THUMBPOSITION
:
4203 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
) <= 0xffff)
4204 y
= HIWORD (msg
->msg
.wParam
);
4205 bar
->dragging
= 1; /* ??????? */
4206 emacs_event
->part
= scroll_bar_handle
;
4208 /* "Silently" update current position. */
4212 si
.cbSize
= sizeof (si
);
4215 /* Remember apparent position (we actually lag behind the real
4216 position, so don't set that directly). */
4217 last_scroll_bar_drag_pos
= y
;
4219 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
4223 /* If this is the end of a drag sequence, then reset the scroll
4224 handle size to normal and do a final redraw. Otherwise do
4229 int start
= bar
->start
;
4232 si
.cbSize
= sizeof (si
);
4233 si
.fMask
= SIF_PAGE
| SIF_POS
;
4234 si
.nPage
= end
- start
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4235 si
.nPos
= last_scroll_bar_drag_pos
;
4236 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
4240 emacs_event
->kind
= NO_EVENT
;
4244 XSETINT (emacs_event
->x
, y
);
4245 XSETINT (emacs_event
->y
, top_range
);
4251 /* Handle a mouse click on the horizontal scroll bar BAR. If
4252 *EMACS_EVENT's kind is set to something other than NO_EVENT, it is
4255 This may be called from a signal handler, so we have to ignore GC
4259 w32_horizontal_scroll_bar_handle_click (struct scroll_bar
*bar
, W32Msg
*msg
,
4260 struct input_event
*emacs_event
)
4262 if (! WINDOWP (bar
->window
))
4265 emacs_event
->kind
= HORIZONTAL_SCROLL_BAR_CLICK_EVENT
;
4266 emacs_event
->code
= 0;
4267 /* not really meaningful to distinguish left/right */
4268 emacs_event
->modifiers
= msg
->dwModifiers
;
4269 emacs_event
->frame_or_window
= bar
->window
;
4270 emacs_event
->arg
= Qnil
;
4271 emacs_event
->timestamp
= msg
->msg
.time
;
4274 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
4276 int dragging
= bar
->dragging
;
4279 si
.cbSize
= sizeof (si
);
4280 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4281 GetScrollInfo ((HWND
) msg
->msg
.lParam
, SB_CTL
, &si
);
4283 y
= si
.nMax
- si
.nPos
- si
.nPage
;
4286 FRAME_DISPLAY_INFO (f
)->last_mouse_scroll_bar_pos
= msg
->msg
.wParam
;
4288 switch (LOWORD (msg
->msg
.wParam
))
4291 emacs_event
->part
= scroll_bar_left_arrow
;
4294 emacs_event
->part
= scroll_bar_right_arrow
;
4297 emacs_event
->part
= scroll_bar_before_handle
;
4300 emacs_event
->part
= scroll_bar_after_handle
;
4303 emacs_event
->part
= scroll_bar_horizontal_handle
;
4307 emacs_event
->part
= scroll_bar_horizontal_handle
;
4311 case SB_THUMBPOSITION
:
4312 if (HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
) <= 0xffff)
4314 x
= HIWORD (msg
->msg
.wParam
);
4315 y
= si
.nMax
- x
- si
.nPage
;
4318 emacs_event
->part
= scroll_bar_horizontal_handle
;
4320 /* "Silently" update current position. */
4324 si
.cbSize
= sizeof (si
);
4326 si
.nPos
= min (x
, XWINDOW (bar
->window
)->hscroll_whole
- 1);
4327 /* Remember apparent position (we actually lag behind the real
4328 position, so don't set that directly). */
4329 last_scroll_bar_drag_pos
= x
;
4331 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, FALSE
);
4335 /* If this is the end of a drag sequence, then reset the scroll
4336 handle size to normal and do a final redraw. Otherwise do
4341 int start
= bar
->start
;
4344 si
.cbSize
= sizeof (si
);
4345 /** si.fMask = SIF_PAGE | SIF_POS; **/
4347 /** si.nPage = end - start + HORIZONTAL_SCROLL_BAR_MIN_HANDLE; **/
4348 si
.nPos
= min (last_scroll_bar_drag_pos
,
4349 XWINDOW (bar
->window
)->hscroll_whole
- 1);
4350 /** si.nPos = last_scroll_bar_drag_pos; **/
4351 SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar
), SB_CTL
, &si
, TRUE
);
4355 emacs_event
->kind
= NO_EVENT
;
4359 XSETINT (emacs_event
->x
, x
);
4360 XSETINT (emacs_event
->y
, y
);
4366 /* Return information to the user about the current position of the mouse
4367 on the vertical scroll bar. */
4369 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
4370 enum scroll_bar_part
*part
,
4371 Lisp_Object
*x
, Lisp_Object
*y
,
4372 unsigned long *time
)
4374 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4375 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4376 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
4377 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4379 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4385 *bar_window
= bar
->window
;
4387 si
.cbSize
= sizeof (si
);
4388 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4390 GetScrollInfo (w
, SB_CTL
, &si
);
4392 top_range
= si
.nMax
- si
.nPage
+ 1;
4394 switch (LOWORD (dpyinfo
->last_mouse_scroll_bar_pos
))
4396 case SB_THUMBPOSITION
:
4398 *part
= scroll_bar_handle
;
4399 if (VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
) <= 0xffff)
4400 pos
= HIWORD (dpyinfo
->last_mouse_scroll_bar_pos
);
4403 *part
= scroll_bar_handle
;
4407 *part
= scroll_bar_handle
;
4412 XSETINT (*y
, top_range
);
4415 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4417 *time
= dpyinfo
->last_mouse_movement_time
;
4422 /* Return information to the user about the current position of the mouse
4423 on the horizontal scroll bar. */
4425 x_horizontal_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
4426 enum scroll_bar_part
*part
,
4427 Lisp_Object
*x
, Lisp_Object
*y
,
4428 unsigned long *time
)
4430 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4431 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4432 Window w
= SCROLL_BAR_W32_WINDOW (bar
);
4433 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4435 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
4441 *bar_window
= bar
->window
;
4443 si
.cbSize
= sizeof (si
);
4444 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
;
4446 GetScrollInfo (w
, SB_CTL
, &si
);
4448 left_range
= si
.nMax
- si
.nPage
+ 1;
4450 switch (LOWORD (dpyinfo
->last_mouse_scroll_bar_pos
))
4452 case SB_THUMBPOSITION
:
4454 *part
= scroll_bar_handle
;
4455 if (HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
) <= 0xffff)
4456 pos
= HIWORD (dpyinfo
->last_mouse_scroll_bar_pos
);
4459 *part
= scroll_bar_handle
;
4463 *part
= scroll_bar_handle
;
4468 XSETINT (*x
, left_range
);
4471 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4473 *time
= dpyinfo
->last_mouse_movement_time
;
4479 /* The screen has been cleared so we may have changed foreground or
4480 background colors, and the scroll bars may need to be redrawn.
4481 Clear out the scroll bars, and ask for expose events, so we can
4485 x_scroll_bar_clear (struct frame
*f
)
4489 /* We can have scroll bars even if this is 0,
4490 if we just turned off scroll bar mode.
4491 But in that case we should not clear them. */
4492 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4493 || FRAME_HAS_HORIZONTAL_SCROLL_BARS (f
))
4494 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
4495 bar
= XSCROLL_BAR (bar
)->next
)
4497 HWND window
= SCROLL_BAR_W32_WINDOW (XSCROLL_BAR (bar
));
4498 HDC hdc
= GetDC (window
);
4501 /* Hide scroll bar until ready to repaint. x_scroll_bar_move
4502 arranges to refresh the scroll bar if hidden. */
4503 my_show_window (f
, window
, SW_HIDE
);
4505 GetClientRect (window
, &rect
);
4506 select_palette (f
, hdc
);
4507 w32_clear_rect (f
, hdc
, &rect
);
4508 deselect_palette (f
, hdc
);
4510 ReleaseDC (window
, hdc
);
4515 set_frame_param (struct frame
*f
, Lisp_Object prop
, Lisp_Object val
)
4517 register Lisp_Object old_alist_elt
;
4519 old_alist_elt
= Fassq (prop
, f
->param_alist
);
4520 if (EQ (old_alist_elt
, Qnil
))
4521 fset_param_alist (f
, Fcons (Fcons (prop
, val
), f
->param_alist
));
4523 Fsetcdr (old_alist_elt
, val
);
4526 /* The main W32 event-reading loop - w32_read_socket. */
4528 /* Record the last 100 characters stored
4529 to help debug the loss-of-chars-during-GC problem. */
4531 static int temp_index
;
4532 static short temp_buffer
[100];
4534 /* Temporarily store lead byte of DBCS input sequences. */
4535 static char dbcs_lead
= 0;
4537 /* Read events coming from the W32 shell.
4538 This routine is called by the SIGIO handler.
4539 We return as soon as there are no more events to be read.
4541 For an overview of how Emacs input works on MS-Windows, see the
4542 commentary before w32_msg_pump in w32fns.c.
4544 We return the number of characters stored into the buffer,
4545 thus pretending to be `read'.
4547 Some of these messages are reposted back to the message queue since the
4548 system calls the windows proc directly in a context where we cannot return
4549 the data nor can we guarantee the state we are in. So if we dispatch them
4550 we will get into an infinite loop. To prevent this from ever happening we
4551 will set a variable to indicate we are in the read_socket call and indicate
4552 which message we are processing since the windows proc gets called
4553 recursively with different messages by the system.
4557 w32_read_socket (struct terminal
*terminal
,
4558 struct input_event
*hold_quit
)
4561 int check_visibility
= 0;
4564 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4565 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
4569 /* So people can tell when we have read the available input. */
4570 input_signal_count
++;
4572 /* Process any incoming thread messages. */
4573 drain_message_queue ();
4575 /* TODO: ghostscript integration. */
4576 while (get_next_msg (&msg
, FALSE
))
4578 struct input_event inev
;
4581 /* DebPrint (("w32_read_socket: %s time:%u\n", */
4582 /* w32_name_of_message (msg.msg.message), */
4583 /* msg.msg.time)); */
4586 inev
.kind
= NO_EVENT
;
4589 switch (msg
.msg
.message
)
4591 case WM_EMACS_PAINT
:
4592 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4596 if (msg
.rect
.right
== msg
.rect
.left
||
4597 msg
.rect
.bottom
== msg
.rect
.top
)
4599 /* We may get paint messages even though the client
4600 area is clipped - these are not expose events. */
4601 DebPrint (("clipped frame %p (%s) got WM_PAINT - ignored\n", f
,
4604 else if (FRAME_VISIBLE_P (f
) != 1)
4606 bool iconified
= FRAME_ICONIFIED_P (f
);
4608 /* Definitely not obscured, so mark as visible. */
4609 SET_FRAME_VISIBLE (f
, 1);
4610 SET_FRAME_ICONIFIED (f
, 0);
4611 SET_FRAME_GARBAGED (f
);
4612 if (!f
->output_data
.w32
->asked_for_visible
)
4613 DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f
,
4616 /* WM_PAINT serves as MapNotify as well, so report
4617 visibility changes properly. */
4620 inev
.kind
= DEICONIFY_EVENT
;
4621 XSETFRAME (inev
.frame_or_window
, f
);
4623 else if (!NILP (Vframe_list
) && !NILP (XCDR (Vframe_list
)))
4624 /* Force a redisplay sooner or later to update the
4625 frame titles in case this is the second frame. */
4626 record_asynch_buffer_change ();
4630 HDC hdc
= get_frame_dc (f
);
4632 /* Erase background again for safety. */
4633 w32_clear_rect (f
, hdc
, &msg
.rect
);
4634 release_frame_dc (f
, hdc
);
4638 msg
.rect
.right
- msg
.rect
.left
,
4639 msg
.rect
.bottom
- msg
.rect
.top
);
4644 case WM_INPUTLANGCHANGE
:
4645 /* Generate a language change event. */
4646 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4648 /* lParam contains the input language ID in its low 16 bits.
4649 Use it to update our record of the keyboard codepage. */
4650 w32_keyboard_codepage
= codepage_for_locale ((LCID
)(msg
.msg
.lParam
4655 inev
.kind
= LANGUAGE_CHANGE_EVENT
;
4656 XSETFRAME (inev
.frame_or_window
, f
);
4657 inev
.code
= w32_keyboard_codepage
;
4658 inev
.modifiers
= msg
.msg
.lParam
& 0xffff;
4664 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4666 if (f
&& !FRAME_ICONIFIED_P (f
))
4668 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4669 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4671 clear_mouse_face (hlinfo
);
4672 hlinfo
->mouse_face_hidden
= 1;
4675 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4677 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4678 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
4679 inev
.code
= msg
.msg
.wParam
;
4680 inev
.modifiers
= msg
.dwModifiers
;
4681 XSETFRAME (inev
.frame_or_window
, f
);
4682 inev
.timestamp
= msg
.msg
.time
;
4689 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4691 if (f
&& !FRAME_ICONIFIED_P (f
))
4693 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4694 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4696 clear_mouse_face (hlinfo
);
4697 hlinfo
->mouse_face_hidden
= 1;
4700 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4702 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4704 inev
.modifiers
= msg
.dwModifiers
;
4705 XSETFRAME (inev
.frame_or_window
, f
);
4706 inev
.timestamp
= msg
.msg
.time
;
4708 if (msg
.msg
.message
== WM_UNICHAR
)
4710 inev
.code
= msg
.msg
.wParam
;
4712 else if (msg
.msg
.wParam
< 256)
4717 dbcs
[1] = (char) msg
.msg
.wParam
;
4721 dbcs
[0] = dbcs_lead
;
4723 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4727 DebPrint (("Invalid DBCS sequence: %d %d\n",
4729 inev
.kind
= NO_EVENT
;
4733 else if (IsDBCSLeadByteEx (w32_keyboard_codepage
,
4734 (BYTE
) msg
.msg
.wParam
))
4736 dbcs_lead
= (char) msg
.msg
.wParam
;
4737 inev
.kind
= NO_EVENT
;
4742 if (!MultiByteToWideChar (w32_keyboard_codepage
, 0,
4743 &dbcs
[1], 1, &code
, 1))
4745 /* What to do with garbage? */
4746 DebPrint (("Invalid character: %d\n", dbcs
[1]));
4747 inev
.kind
= NO_EVENT
;
4755 /* Windows shouldn't generate WM_CHAR events above 0xFF
4756 in non-Unicode message handlers. */
4757 DebPrint (("Non-byte WM_CHAR: %d\n", msg
.msg
.wParam
));
4758 inev
.kind
= NO_EVENT
;
4761 inev
.kind
= inev
.code
< 128 ? ASCII_KEYSTROKE_EVENT
4762 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
4767 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4769 if (f
&& !FRAME_ICONIFIED_P (f
))
4771 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
4772 && !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
4774 clear_mouse_face (hlinfo
);
4775 hlinfo
->mouse_face_hidden
= 1;
4778 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4780 temp_buffer
[temp_index
++] = msg
.msg
.wParam
;
4781 inev
.kind
= MULTIMEDIA_KEY_EVENT
;
4782 inev
.code
= GET_APPCOMMAND_LPARAM (msg
.msg
.lParam
);
4783 inev
.modifiers
= msg
.dwModifiers
;
4784 XSETFRAME (inev
.frame_or_window
, f
);
4785 inev
.timestamp
= msg
.msg
.time
;
4790 /* Ignore non-movement. */
4792 int x
= LOWORD (msg
.msg
.lParam
);
4793 int y
= HIWORD (msg
.msg
.lParam
);
4794 if (x
== last_mousemove_x
&& y
== last_mousemove_y
)
4796 last_mousemove_x
= x
;
4797 last_mousemove_y
= y
;
4800 previous_help_echo_string
= help_echo_string
;
4801 help_echo_string
= Qnil
;
4803 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4804 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4806 if (hlinfo
->mouse_face_hidden
)
4808 hlinfo
->mouse_face_hidden
= 0;
4809 clear_mouse_face (hlinfo
);
4814 /* Generate SELECT_WINDOW_EVENTs when needed. */
4815 if (!NILP (Vmouse_autoselect_window
))
4817 static Lisp_Object last_mouse_window
;
4818 Lisp_Object window
= window_from_coordinates
4819 (f
, LOWORD (msg
.msg
.lParam
), HIWORD (msg
.msg
.lParam
), 0, 0);
4821 /* Window will be selected only when it is not
4822 selected now and last mouse movement event was
4823 not in it. Minibuffer window will be selected
4824 only when it is active. */
4825 if (WINDOWP (window
)
4826 && !EQ (window
, last_mouse_window
)
4827 && !EQ (window
, selected_window
)
4828 /* For click-to-focus window managers
4829 create event iff we don't leave the
4831 && (focus_follows_mouse
4832 || (EQ (XWINDOW (window
)->frame
,
4833 XWINDOW (selected_window
)->frame
))))
4835 inev
.kind
= SELECT_WINDOW_EVENT
;
4836 inev
.frame_or_window
= window
;
4838 /* Remember the last window where we saw the mouse. */
4839 last_mouse_window
= window
;
4841 if (!note_mouse_movement (f
, &msg
.msg
))
4842 help_echo_string
= previous_help_echo_string
;
4846 /* If we move outside the frame, then we're
4847 certainly no longer on any text in the frame. */
4848 clear_mouse_face (hlinfo
);
4851 /* If the contents of the global variable help_echo_string
4852 has changed, generate a HELP_EVENT. */
4853 #if 0 /* The below is an invalid comparison when CHECK_LISP_OBJECT_TYPE.
4854 But it was originally changed to this to fix a bug, so I have
4855 not removed it completely in case the bug is still there. */
4856 if (help_echo_string
!= previous_help_echo_string
||
4857 (!NILP (help_echo_string
) && !STRINGP (help_echo_string
) && f
->mouse_moved
))
4858 #else /* This is what xterm.c does. */
4859 if (!NILP (help_echo_string
)
4860 || !NILP (previous_help_echo_string
))
4865 case WM_LBUTTONDOWN
:
4867 case WM_MBUTTONDOWN
:
4869 case WM_RBUTTONDOWN
:
4871 case WM_XBUTTONDOWN
:
4874 /* If we decide we want to generate an event to be seen
4875 by the rest of Emacs, we put it here. */
4876 bool tool_bar_p
= 0;
4880 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4881 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4885 construct_mouse_click (&inev
, &msg
, f
);
4887 /* Is this in the tool-bar? */
4888 if (WINDOWP (f
->tool_bar_window
)
4889 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
4892 int x
= XFASTINT (inev
.x
);
4893 int y
= XFASTINT (inev
.y
);
4895 window
= window_from_coordinates (f
, x
, y
, 0, 1);
4897 if (EQ (window
, f
->tool_bar_window
))
4899 w32_handle_tool_bar_click (f
, &inev
);
4905 || (dpyinfo
->w32_focus_frame
4906 && f
!= dpyinfo
->w32_focus_frame
))
4907 inev
.kind
= NO_EVENT
;
4910 parse_button (msg
.msg
.message
, HIWORD (msg
.msg
.wParam
),
4915 dpyinfo
->grabbed
&= ~ (1 << button
);
4919 dpyinfo
->grabbed
|= (1 << button
);
4920 dpyinfo
->last_mouse_frame
= f
;
4921 /* Ignore any mouse motion that happened
4922 before this event; any subsequent mouse-movement
4923 Emacs events should reflect only motion after
4929 f
->last_tool_bar_item
= -1;
4936 case WM_MOUSEHWHEEL
:
4938 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
4939 : x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
));
4944 if (!dpyinfo
->w32_focus_frame
4945 || f
== dpyinfo
->w32_focus_frame
)
4947 /* Emit an Emacs wheel-up/down event. */
4948 construct_mouse_wheel (&inev
, &msg
, f
);
4950 /* Ignore any mouse motion that happened before this
4951 event; any subsequent mouse-movement Emacs events
4952 should reflect only motion after the
4955 f
->last_tool_bar_item
= -1;
4957 dpyinfo
->last_mouse_frame
= f
;
4962 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4965 construct_drag_n_drop (&inev
, &msg
, f
);
4970 struct scroll_bar
*bar
=
4971 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
, 1);
4974 w32_horizontal_scroll_bar_handle_click (bar
, &msg
, &inev
);
4980 struct scroll_bar
*bar
=
4981 x_window_to_scroll_bar ((HWND
)msg
.msg
.lParam
, 0);
4984 w32_scroll_bar_handle_click (bar
, &msg
, &inev
);
4988 case WM_WINDOWPOSCHANGED
:
4990 case WM_ACTIVATEAPP
:
4991 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
4994 /* Run the full-screen hook function also when we are
4995 being activated, to actually install the required
4996 size in effect, if the WAIT flag is set. This is
4997 because when the hook is run from x_set_fullscreen,
4998 the frame might not yet be visible, if that call is a
4999 result of make-frame, and in that case the hook just
5000 sets the WAIT flag. */
5001 if ((msg
.msg
.message
== WM_WINDOWPOSCHANGED
|| msg
.msg
.wParam
)
5002 && (f
->want_fullscreen
& FULLSCREEN_WAIT
))
5003 w32fullscreen_hook (f
);
5004 x_check_fullscreen (f
);
5006 check_visibility
= 1;
5010 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5012 if (f
&& !FRAME_ICONIFIED_P (f
))
5013 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5015 check_visibility
= 1;
5019 /* wParam non-zero means Window is about to be shown, 0 means
5020 about to be hidden. */
5021 /* Redo the mouse-highlight after the tooltip has gone. */
5022 if (!msg
.msg
.wParam
&& msg
.msg
.hwnd
== tip_window
)
5025 x_redo_mouse_highlight (dpyinfo
);
5028 /* If window has been obscured or exposed by another window
5029 being maximized or minimized/restored, then recheck
5030 visibility of all frames. Direct changes to our own
5031 windows get handled by WM_SIZE. */
5033 if (msg
.msg
.lParam
!= 0)
5034 check_visibility
= 1;
5037 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5038 f
->async_visible
= msg
.msg
.wParam
;
5042 check_visibility
= 1;
5046 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5048 /* Inform lisp of whether frame has been iconified etc. */
5051 switch (msg
.msg
.wParam
)
5053 case SIZE_MINIMIZED
:
5054 SET_FRAME_VISIBLE (f
, 0);
5055 SET_FRAME_ICONIFIED (f
, 1);
5057 inev
.kind
= ICONIFY_EVENT
;
5058 XSETFRAME (inev
.frame_or_window
, f
);
5061 case SIZE_MAXIMIZED
:
5063 bool iconified
= FRAME_ICONIFIED_P (f
);
5065 SET_FRAME_VISIBLE (f
, 1);
5066 SET_FRAME_ICONIFIED (f
, 0);
5068 /* wait_reading_process_output will notice this
5069 and update the frame's display structures. */
5070 SET_FRAME_GARBAGED (f
);
5076 /* Reset top and left positions of the Window
5077 here since Windows sends a WM_MOVE message
5078 BEFORE telling us the Window is minimized
5079 when the Window is iconified, with 3000,3000
5081 x_real_positions (f
, &x
, &y
);
5085 inev
.kind
= DEICONIFY_EVENT
;
5086 XSETFRAME (inev
.frame_or_window
, f
);
5088 else if (! NILP (Vframe_list
)
5089 && ! NILP (XCDR (Vframe_list
)))
5090 /* Force a redisplay sooner or later
5091 to update the frame titles
5092 in case this is the second frame. */
5093 record_asynch_buffer_change ();
5096 if (EQ (get_frame_param (f
, Qfullscreen
), Qnil
))
5097 set_frame_param (f
, Qfullscreen
, Qmaximized
);
5098 else if (! EQ (get_frame_param (f
, Qfullscreen
), Qmaximized
))
5099 set_frame_param (f
, Qmaximized
, Qmaximized
);
5105 bool iconified
= FRAME_ICONIFIED_P (f
);
5107 /* The following was made unconditional in a
5108 pathetic attempt to fix bug#16967 in revision
5109 116716 but, considered counterproductive was made
5110 conditional again in revision 116727. martin */
5112 SET_FRAME_VISIBLE (f
, 1);
5113 SET_FRAME_ICONIFIED (f
, 0);
5115 /* wait_reading_process_output will notice this
5116 and update the frame's display structures. */
5117 SET_FRAME_GARBAGED (f
);
5121 /* Reset top and left positions of the Window
5122 here since Windows sends a WM_MOVE message
5123 BEFORE telling us the Window is minimized
5124 when the Window is iconified, with 3000,3000
5126 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5128 inev
.kind
= DEICONIFY_EVENT
;
5129 XSETFRAME (inev
.frame_or_window
, f
);
5131 else if (! NILP (Vframe_list
)
5132 && ! NILP (XCDR (Vframe_list
)))
5133 /* Force a redisplay sooner or later
5134 to update the frame titles
5135 in case this is the second frame. */
5136 record_asynch_buffer_change ();
5139 if (EQ (get_frame_param (f
, Qfullscreen
), Qmaximized
))
5140 set_frame_param (f
, Qfullscreen
, Qnil
);
5141 else if (! EQ (get_frame_param (f
, Qmaximized
), Qnil
))
5142 set_frame_param (f
, Qmaximized
, Qnil
);
5148 if (f
&& !FRAME_ICONIFIED_P (f
) && msg
.msg
.wParam
!= SIZE_MINIMIZED
)
5151 int rows
, columns
, width
, height
, text_width
, text_height
;
5153 GetClientRect (msg
.msg
.hwnd
, &rect
);
5155 height
= rect
.bottom
- rect
.top
;
5156 width
= rect
.right
- rect
.left
;
5157 text_width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, width
);
5158 text_height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, height
);
5159 /* rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); */
5160 /* columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); */
5162 /* TODO: Clip size to the screen dimensions. */
5164 /* Even if the number of character rows and columns has
5165 not changed, the font size may have changed, so we need
5166 to check the pixel dimensions as well. */
5168 if (width
!= FRAME_PIXEL_WIDTH (f
)
5169 || height
!= FRAME_PIXEL_HEIGHT (f
)
5170 || text_width
!= FRAME_TEXT_WIDTH (f
)
5171 || text_height
!= FRAME_TEXT_HEIGHT (f
))
5173 change_frame_size (f
, text_width
, text_height
, 0, 1, 0, 1);
5174 SET_FRAME_GARBAGED (f
);
5175 cancel_mouse_face (f
);
5176 f
->win_gravity
= NorthWestGravity
;
5180 check_visibility
= 1;
5184 f
= x_any_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5187 if (f
== hlinfo
->mouse_face_mouse_frame
)
5189 /* If we move outside the frame, then we're
5190 certainly no longer on any text in the frame. */
5191 clear_mouse_face (hlinfo
);
5192 hlinfo
->mouse_face_mouse_frame
= 0;
5195 /* Generate a nil HELP_EVENT to cancel a help-echo.
5196 Do it only if there's something to cancel.
5197 Otherwise, the startup message is cleared when
5198 the mouse leaves the frame. */
5199 if (any_help_event_p
)
5205 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
5207 dpyinfo
->grabbed
= 0;
5208 check_visibility
= 1;
5212 w32_detect_focus_change (dpyinfo
, &msg
, &inev
);
5213 f
= x_top_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5217 if (f
== hlinfo
->mouse_face_mouse_frame
)
5219 /* If we move outside the frame, then we're
5220 certainly no longer on any text in the frame. */
5221 clear_mouse_face (hlinfo
);
5222 hlinfo
->mouse_face_mouse_frame
= 0;
5225 /* Generate a nil HELP_EVENT to cancel a help-echo.
5226 Do it only if there's something to cancel.
5227 Otherwise, the startup message is cleared when
5228 the mouse leaves the frame. */
5229 if (any_help_event_p
)
5233 dpyinfo
->grabbed
= 0;
5234 check_visibility
= 1;
5238 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5242 inev
.kind
= DELETE_WINDOW_EVENT
;
5243 XSETFRAME (inev
.frame_or_window
, f
);
5248 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5252 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
5253 XSETFRAME (inev
.frame_or_window
, f
);
5258 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5262 extern void menubar_selection_callback
5263 (struct frame
*f
, void * client_data
);
5264 menubar_selection_callback (f
, (void *)msg
.msg
.wParam
);
5267 check_visibility
= 1;
5270 case WM_DISPLAYCHANGE
:
5271 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5275 dpyinfo
->n_cbits
= msg
.msg
.wParam
;
5276 /* The new display could have a different resolution, in
5277 which case we must reconsider what fullscreen
5279 x_check_fullscreen (f
);
5280 DebPrint (("display change: %d %d\n",
5281 (short) LOWORD (msg
.msg
.lParam
),
5282 (short) HIWORD (msg
.msg
.lParam
)));
5285 check_visibility
= 1;
5289 case WM_EMACS_FILENOTIFY
:
5290 f
= x_window_to_frame (dpyinfo
, msg
.msg
.hwnd
);
5292 queue_notifications (&inev
, &msg
, f
, &count
);
5297 /* Check for messages registered at runtime. */
5298 if (msg
.msg
.message
== msh_mousewheel
)
5300 /* Forward MSH_MOUSEWHEEL as WM_MOUSEWHEEL. */
5301 msg
.msg
.message
= WM_MOUSEWHEEL
;
5307 if (inev
.kind
!= NO_EVENT
)
5309 kbd_buffer_store_event_hold (&inev
, hold_quit
);
5314 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
5319 XSETFRAME (frame
, f
);
5325 if (NILP (help_echo_string
))
5327 help_echo_object
= help_echo_window
= Qnil
;
5331 any_help_event_p
= 1;
5332 gen_help_event (help_echo_string
, frame
, help_echo_window
,
5333 help_echo_object
, help_echo_pos
);
5337 help_echo_string
= Qnil
;
5338 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
5344 /* If the focus was just given to an autoraising frame,
5345 raise it now. FIXME: handle more than one such frame. */
5346 if (dpyinfo
->w32_pending_autoraise_frame
)
5348 x_raise_frame (dpyinfo
->w32_pending_autoraise_frame
);
5349 dpyinfo
->w32_pending_autoraise_frame
= NULL
;
5352 /* Check which frames are still visible, if we have enqueued any user
5353 events or been notified of events that may affect visibility. We
5354 do this here because there doesn't seem to be any direct
5355 notification from Windows that the visibility of a window has
5356 changed (at least, not in all cases). */
5357 if (count
> 0 || check_visibility
)
5359 Lisp_Object tail
, frame
;
5361 FOR_EACH_FRAME (tail
, frame
)
5363 struct frame
*f
= XFRAME (frame
);
5364 /* The tooltip has been drawn already. Avoid the
5365 SET_FRAME_GARBAGED below. */
5366 if (EQ (frame
, tip_frame
))
5369 /* Check "visible" frames and mark each as obscured or not.
5370 Note that visible is nonzero for unobscured and obscured
5371 frames, but zero for hidden and iconified frames. */
5372 if (FRAME_W32_P (f
) && FRAME_VISIBLE_P (f
))
5379 /* Query clipping rectangle for the entire window area
5380 (GetWindowDC), not just the client portion (GetDC).
5381 Otherwise, the scrollbars and menubar aren't counted as
5382 part of the visible area of the frame, and we may think
5383 the frame is obscured when really a scrollbar is still
5384 visible and gets WM_PAINT messages above. */
5385 hdc
= GetWindowDC (FRAME_W32_WINDOW (f
));
5386 GetClipBox (hdc
, &clipbox
);
5387 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
5390 obscured
= FRAME_OBSCURED_P (f
);
5392 if (clipbox
.right
== clipbox
.left
|| clipbox
.bottom
== clipbox
.top
)
5394 /* Frame has become completely obscured so mark as such (we
5395 do this by setting visible to 2 so that FRAME_VISIBLE_P
5396 is still true, but redisplay will skip it). */
5397 SET_FRAME_VISIBLE (f
, 2);
5400 DebPrint (("frame %p (%s) obscured\n", f
, SDATA (f
->name
)));
5404 /* Frame is not obscured, so mark it as such. */
5405 SET_FRAME_VISIBLE (f
, 1);
5409 SET_FRAME_GARBAGED (f
);
5410 DebPrint (("obscured frame %p (%s) found to be visible\n",
5411 f
, SDATA (f
->name
)));
5413 /* Force a redisplay sooner or later. */
5414 record_asynch_buffer_change ();
5427 /***********************************************************************
5429 ***********************************************************************/
5431 /* Set clipping for output in glyph row ROW. W is the window in which
5432 we operate. GC is the graphics context to set clipping in.
5434 ROW may be a text row or, e.g., a mode line. Text rows must be
5435 clipped to the interior of the window dedicated to text display,
5436 mode lines must be clipped to the whole window. */
5439 w32_clip_to_row (struct window
*w
, struct glyph_row
*row
,
5440 enum glyph_row_area area
, HDC hdc
)
5443 int window_x
, window_y
, window_width
;
5445 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5447 clip_rect
.left
= window_x
;
5448 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5449 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5450 clip_rect
.right
= clip_rect
.left
+ window_width
;
5451 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5453 w32_set_clip_rectangle (hdc
, &clip_rect
);
5457 /* Draw a hollow box cursor on window W in glyph row ROW. */
5460 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
5462 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5466 struct glyph
*cursor_glyph
;
5467 HBRUSH hb
= CreateSolidBrush (f
->output_data
.w32
->cursor_pixel
);
5469 /* Get the glyph the cursor is on. If we can't tell because
5470 the current matrix is invalid or such, give up. */
5471 cursor_glyph
= get_phys_cursor_glyph (w
);
5472 if (cursor_glyph
== NULL
)
5478 /* Compute frame-relative coordinates for phys cursor. */
5479 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &left
, &top
, &h
);
5482 rect
.bottom
= rect
.top
+ h
;
5483 rect
.right
= rect
.left
+ w
->phys_cursor_width
;
5485 hdc
= get_frame_dc (f
);
5486 /* Set clipping, draw the rectangle, and reset clipping again. */
5487 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5488 FrameRect (hdc
, &rect
, hb
);
5490 w32_set_clip_rectangle (hdc
, NULL
);
5491 release_frame_dc (f
, hdc
);
5495 /* Draw a bar cursor on window W in glyph row ROW.
5497 Implementation note: One would like to draw a bar cursor with an
5498 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5499 Unfortunately, I didn't find a font yet that has this property set.
5503 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
,
5504 int width
, enum text_cursor_kinds kind
)
5506 struct frame
*f
= XFRAME (w
->frame
);
5507 struct glyph
*cursor_glyph
;
5509 /* If cursor is out of bounds, don't draw garbage. This can happen
5510 in mini-buffer windows when switching between echo area glyphs
5512 cursor_glyph
= get_phys_cursor_glyph (w
);
5513 if (cursor_glyph
== NULL
)
5516 /* If on an image, draw like a normal cursor. That's usually better
5517 visible than drawing a bar, esp. if the image is large so that
5518 the bar might not be in the window. */
5519 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5521 struct glyph_row
*row
;
5522 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5523 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5527 COLORREF cursor_color
= f
->output_data
.w32
->cursor_pixel
;
5528 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5532 /* If the glyph's background equals the color we normally draw
5533 the bar cursor in, the bar cursor in its normal color is
5534 invisible. Use the glyph's foreground color instead in this
5535 case, on the assumption that the glyph's colors are chosen so
5536 that the glyph is legible. */
5537 if (face
->background
== cursor_color
)
5538 cursor_color
= face
->foreground
;
5540 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5542 hdc
= get_frame_dc (f
);
5543 w32_clip_to_row (w
, row
, TEXT_AREA
, hdc
);
5545 if (kind
== BAR_CURSOR
)
5548 width
= FRAME_CURSOR_WIDTH (f
);
5549 width
= min (cursor_glyph
->pixel_width
, width
);
5551 w
->phys_cursor_width
= width
;
5553 /* If the character under cursor is R2L, draw the bar cursor
5554 on the right of its glyph, rather than on the left. */
5555 if ((cursor_glyph
->resolved_level
& 1) != 0)
5556 x
+= cursor_glyph
->pixel_width
- width
;
5558 w32_fill_area (f
, hdc
, cursor_color
, x
,
5559 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5560 width
, row
->height
);
5564 int dummy_x
, dummy_y
, dummy_h
;
5567 width
= row
->height
;
5569 width
= min (row
->height
, width
);
5571 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
5572 &dummy_y
, &dummy_h
);
5573 w32_fill_area (f
, hdc
, cursor_color
, x
,
5574 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5575 row
->height
- width
),
5576 w
->phys_cursor_width
, width
);
5579 w32_set_clip_rectangle (hdc
, NULL
);
5580 release_frame_dc (f
, hdc
);
5585 /* RIF: Define cursor CURSOR on frame F. */
5588 w32_define_frame_cursor (struct frame
*f
, Cursor cursor
)
5590 w32_define_cursor (FRAME_W32_WINDOW (f
), cursor
);
5594 /* RIF: Clear area on frame F. */
5597 w32_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
5601 hdc
= get_frame_dc (f
);
5602 w32_clear_area (f
, hdc
, x
, y
, width
, height
);
5603 release_frame_dc (f
, hdc
);
5606 /* RIF: Draw or clear cursor on window W. */
5609 w32_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
,
5610 int x
, int y
, enum text_cursor_kinds cursor_type
,
5611 int cursor_width
, bool on_p
, bool active_p
)
5615 /* If the user wants to use the system caret, make sure our own
5616 cursor remains invisible. */
5617 if (w32_use_visible_system_caret
)
5619 /* Call to erase_phys_cursor here seems to use the
5620 wrong values of w->phys_cursor, as they have been
5621 overwritten before this function was called. */
5622 if (w
->phys_cursor_type
!= NO_CURSOR
)
5623 erase_phys_cursor (w
);
5625 cursor_type
= w
->phys_cursor_type
= NO_CURSOR
;
5626 w
->phys_cursor_width
= -1;
5630 w
->phys_cursor_type
= cursor_type
;
5633 w
->phys_cursor_on_p
= 1;
5635 /* If this is the active cursor, we need to track it with the
5636 system caret, so third party software like screen magnifiers
5637 and speech synthesizers can follow the cursor. */
5640 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5641 HWND hwnd
= FRAME_W32_WINDOW (f
);
5644 = WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5646 = (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
5647 + glyph_row
->ascent
- w
->phys_cursor_ascent
);
5648 w32_system_caret_window
= w
;
5649 w32_system_caret_hdr_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
5650 w32_system_caret_mode_height
= WINDOW_MODE_LINE_HEIGHT (w
);
5652 PostMessage (hwnd
, WM_IME_STARTCOMPOSITION
, 0, 0);
5654 /* If the size of the active cursor changed, destroy the old
5656 if (w32_system_caret_hwnd
5657 && (w32_system_caret_height
!= w
->phys_cursor_height
))
5658 PostMessage (hwnd
, WM_EMACS_DESTROY_CARET
, 0, 0);
5660 w32_system_caret_height
= w
->phys_cursor_height
;
5662 /* Move the system caret. */
5663 PostMessage (hwnd
, WM_EMACS_TRACK_CARET
, 0, 0);
5666 if (glyph_row
->exact_window_width_line_p
5667 && (glyph_row
->reversed_p
5668 ? (w
->phys_cursor
.hpos
< 0)
5669 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
5671 glyph_row
->cursor_in_fringe_p
= 1;
5672 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
5676 switch (cursor_type
)
5678 case HOLLOW_BOX_CURSOR
:
5679 x_draw_hollow_cursor (w
, glyph_row
);
5682 case FILLED_BOX_CURSOR
:
5683 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5687 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5691 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5695 w
->phys_cursor_width
= 0;
5709 x_bitmap_icon (struct frame
*f
, Lisp_Object icon
)
5712 HANDLE small_icon
= NULL
;
5714 if (FRAME_W32_WINDOW (f
) == 0)
5718 main_icon
= LoadIcon (hinst
, EMACS_CLASS
);
5719 else if (STRINGP (icon
))
5721 /* Load the main icon from the named file. */
5722 main_icon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5723 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5724 /* Try to load a small icon to go with it. */
5725 small_icon
= LoadImage (NULL
, (LPCSTR
) SDATA (icon
), IMAGE_ICON
,
5726 GetSystemMetrics (SM_CXSMICON
),
5727 GetSystemMetrics (SM_CYSMICON
),
5730 else if (SYMBOLP (icon
))
5734 if (EQ (icon
, intern ("application")))
5735 name
= (LPCTSTR
) IDI_APPLICATION
;
5736 else if (EQ (icon
, intern ("hand")))
5737 name
= (LPCTSTR
) IDI_HAND
;
5738 else if (EQ (icon
, intern ("question")))
5739 name
= (LPCTSTR
) IDI_QUESTION
;
5740 else if (EQ (icon
, intern ("exclamation")))
5741 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5742 else if (EQ (icon
, intern ("asterisk")))
5743 name
= (LPCTSTR
) IDI_ASTERISK
;
5744 else if (EQ (icon
, intern ("winlogo")))
5745 name
= (LPCTSTR
) IDI_WINLOGO
;
5749 main_icon
= LoadIcon (NULL
, name
);
5754 if (main_icon
== NULL
)
5757 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5758 (LPARAM
) main_icon
);
5760 /* If there is a small icon that goes with it, set that too. */
5762 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_SMALL
,
5763 (LPARAM
) small_icon
);
5769 /************************************************************************
5771 ************************************************************************/
5773 /* Display Error Handling functions not used on W32. Listing them here
5774 helps diff stay in step when comparing w32term.c with xterm.c.
5776 x_error_catcher (display, error)
5777 x_catch_errors (dpy)
5778 x_catch_errors_unwind (old_val)
5779 x_check_errors (dpy, format)
5780 x_fully_uncatch_errors ()
5781 x_had_errors_p (dpy)
5782 x_clear_errors (dpy)
5783 x_uncatch_errors (dpy, count)
5785 x_connection_signal (signalnum)
5786 x_connection_closed (dpy, error_message)
5787 x_error_quitter (display, error)
5788 x_error_handler (display, error)
5789 x_io_error_quitter (display)
5794 /* Changing the font of the frame. */
5797 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
5799 struct font
*font
= XFONT_OBJECT (font_object
);
5803 fontset
= fontset_from_font (font_object
);
5804 FRAME_FONTSET (f
) = fontset
;
5805 if (FRAME_FONT (f
) == font
)
5806 /* This font is already set in frame F. There's nothing more to
5810 FRAME_FONT (f
) = font
;
5811 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
5812 FRAME_COLUMN_WIDTH (f
) = unit
= font
->average_width
;
5813 FRAME_LINE_HEIGHT (f
) = font
->height
;
5815 /* Compute number of scrollbar columns. */
5816 unit
= FRAME_COLUMN_WIDTH (f
);
5817 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5818 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5819 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
5822 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
5823 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) =
5824 FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
5827 /* Now make the frame display the given font. */
5828 if (FRAME_X_WINDOW (f
) != 0)
5830 /* Don't change the size of a tip frame; there's no point in
5831 doing it because it's done in Fx_show_tip, and it leads to
5832 problems because the tip frame has no widget. */
5833 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5834 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
5835 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 3, 0);
5838 /* X version sets font of input methods here also. */
5844 /***********************************************************************
5845 TODO: W32 Input Methods
5846 ***********************************************************************/
5847 /* Listing missing functions from xterm.c helps diff stay in step.
5849 xim_destroy_callback (xim, client_data, call_data)
5850 xim_open_dpy (dpyinfo, resource_name)
5852 xim_instantiate_callback (display, client_data, call_data)
5853 xim_initialize (dpyinfo, resource_name)
5854 xim_close_dpy (dpyinfo)
5859 /* Calculate the absolute position in frame F
5860 from its current recorded position values and gravity. */
5863 x_calc_absolute_position (struct frame
*f
)
5865 int flags
= f
->size_hint_flags
;
5867 /* The sum of the widths of the frame's left and right borders, and
5868 the sum of the heights of the frame's top and bottom borders (in
5869 pixels) drawn by Windows. */
5870 unsigned int left_right_borders_width
, top_bottom_borders_height
;
5872 /* Try to get the actual values of these two variables. We compute
5873 the border width (height) by subtracting the width (height) of
5874 the frame's client area from the width (height) of the frame's
5876 WINDOWPLACEMENT wp
= { 0 };
5877 RECT client_rect
= { 0 };
5879 if (GetWindowPlacement (FRAME_W32_WINDOW (f
), &wp
)
5880 && GetClientRect (FRAME_W32_WINDOW (f
), &client_rect
))
5882 left_right_borders_width
=
5883 (wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
) -
5884 (client_rect
.right
- client_rect
.left
);
5886 top_bottom_borders_height
=
5887 (wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
) -
5888 (client_rect
.bottom
- client_rect
.top
);
5892 /* Use sensible default values. */
5893 left_right_borders_width
= 8;
5894 top_bottom_borders_height
= 32;
5897 /* Treat negative positions as relative to the rightmost bottommost
5898 position that fits on the screen. */
5899 if (flags
& XNegative
)
5900 f
->left_pos
= (x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
5901 - FRAME_PIXEL_WIDTH (f
)
5903 - (left_right_borders_width
- 1));
5905 if (flags
& YNegative
)
5906 f
->top_pos
= (x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
5907 - FRAME_PIXEL_HEIGHT (f
)
5909 - (top_bottom_borders_height
- 1));
5911 /* The left_pos and top_pos are now relative to the top and left
5912 screen edges, so the flags should correspond. */
5913 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5916 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5917 to really change the position, and 0 when calling from
5918 x_make_frame_visible (in that case, XOFF and YOFF are the current
5919 position values). It is -1 when calling from x_set_frame_parameters,
5920 which means, do adjust for borders but don't change the gravity. */
5923 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
,
5926 int modified_top
, modified_left
;
5928 if (change_gravity
> 0)
5932 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5934 f
->size_hint_flags
|= XNegative
;
5936 f
->size_hint_flags
|= YNegative
;
5937 f
->win_gravity
= NorthWestGravity
;
5939 x_calc_absolute_position (f
);
5942 x_wm_set_size_hint (f
, (long) 0, 0);
5944 modified_left
= f
->left_pos
;
5945 modified_top
= f
->top_pos
;
5947 my_set_window_pos (FRAME_W32_WINDOW (f
),
5949 modified_left
, modified_top
,
5951 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
5955 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
5956 wanted positions of the WM window (not Emacs window).
5957 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
5958 window (FRAME_X_WINDOW).
5962 x_fullscreen_adjust (struct frame
*f
, int *width
, int *height
, int *top_pos
, int *left_pos
)
5964 int newwidth
= FRAME_COLS (f
);
5965 int newheight
= FRAME_LINES (f
);
5966 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
5968 *top_pos
= f
->top_pos
;
5969 *left_pos
= f
->left_pos
;
5971 if (f
->want_fullscreen
& FULLSCREEN_HEIGHT
)
5975 ph
= x_display_pixel_height (dpyinfo
);
5976 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
5977 ph
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, newheight
) - f
->y_pixels_diff
;
5978 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
5982 if (f
->want_fullscreen
& FULLSCREEN_WIDTH
)
5986 pw
= x_display_pixel_width (dpyinfo
);
5987 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
5988 pw
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, newwidth
) - f
->x_pixels_diff
;
5989 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
5994 *height
= newheight
;
5997 /* Check if we need to resize the frame due to a fullscreen request.
5998 If so needed, resize the frame. */
6000 x_check_fullscreen (struct frame
*f
)
6002 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
6004 int width
, height
, ign
;
6006 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6008 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
6010 /* We do not need to move the window, it shall be taken care of
6011 when setting WM manager hints. */
6012 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
6014 change_frame_size (f
, width
, height
, 0, 1, 0, 0);
6015 SET_FRAME_GARBAGED (f
);
6016 cancel_mouse_face (f
);
6018 /* Wait for the change of frame size to occur. */
6019 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
6025 w32fullscreen_hook (struct frame
*f
)
6027 if (FRAME_VISIBLE_P (f
))
6029 HWND hwnd
= FRAME_W32_WINDOW(f
);
6030 DWORD dwStyle
= GetWindowLong (hwnd
, GWL_STYLE
);
6032 enum fullscreen_type prev_fsmode
= FRAME_PREV_FSMODE (f
);
6035 f
->want_fullscreen
&= ~FULLSCREEN_WAIT
;
6037 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_NONE
)
6038 GetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6040 if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_BOTH
)
6042 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
| WS_OVERLAPPEDWINDOW
);
6043 SetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6045 else if (FRAME_PREV_FSMODE (f
) == FULLSCREEN_HEIGHT
6046 || FRAME_PREV_FSMODE (f
) == FULLSCREEN_WIDTH
)
6047 SetWindowPlacement (hwnd
, &FRAME_NORMAL_PLACEMENT (f
));
6049 FRAME_PREV_FSMODE (f
) = f
->want_fullscreen
;
6051 if (f
->want_fullscreen
== FULLSCREEN_NONE
)
6052 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6053 else if (f
->want_fullscreen
== FULLSCREEN_MAXIMIZED
)
6055 if (prev_fsmode
== FULLSCREEN_BOTH
|| prev_fsmode
== FULLSCREEN_WIDTH
6056 || prev_fsmode
== FULLSCREEN_HEIGHT
)
6057 /* Make window normal since otherwise the subsequent
6058 maximization might fail in some cases. */
6059 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6060 ShowWindow (hwnd
, SW_MAXIMIZE
);
6062 else if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
6064 w32_fullscreen_rect (hwnd
, f
->want_fullscreen
,
6065 FRAME_NORMAL_PLACEMENT (f
).rcNormalPosition
, &rect
);
6066 SetWindowLong (hwnd
, GWL_STYLE
, dwStyle
& ~WS_OVERLAPPEDWINDOW
);
6067 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
6068 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
6069 SWP_NOOWNERZORDER
| SWP_FRAMECHANGED
);
6073 ShowWindow (hwnd
, SW_SHOWNORMAL
);
6074 w32_fullscreen_rect (hwnd
, f
->want_fullscreen
,
6075 FRAME_NORMAL_PLACEMENT (f
).rcNormalPosition
, &rect
);
6076 SetWindowPos (hwnd
, HWND_TOP
, rect
.left
, rect
.top
,
6077 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 0);
6080 f
->want_fullscreen
= FULLSCREEN_NONE
;
6084 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
6087 /* Call this to change the size of frame F's x-window.
6088 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
6089 for this size change and subsequent size changes.
6090 Otherwise we leave the window gravity unchanged. */
6093 x_set_window_size (struct frame
*f
, int change_gravity
, int width
, int height
, bool pixelwise
)
6095 int pixelwidth
, pixelheight
;
6102 pixelwidth
= FRAME_TEXT_TO_PIXEL_WIDTH (f
, width
);
6103 pixelheight
= FRAME_TEXT_TO_PIXEL_HEIGHT (f
, height
);
6107 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, width
);
6108 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, height
);
6111 f
->win_gravity
= NorthWestGravity
;
6112 x_wm_set_size_hint (f
, (long) 0, 0);
6114 f
->want_fullscreen
= FULLSCREEN_NONE
;
6115 w32fullscreen_hook (f
);
6117 rect
.left
= rect
.top
= 0;
6118 rect
.right
= pixelwidth
;
6119 rect
.bottom
= pixelheight
;
6121 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6122 FRAME_EXTERNAL_MENU_BAR (f
));
6124 my_set_window_pos (FRAME_W32_WINDOW (f
),
6127 rect
.right
- rect
.left
,
6128 rect
.bottom
- rect
.top
,
6129 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6131 /* If w32_enable_frame_resize_hack is non-nil, immediately apply the
6132 new pixel sizes to the frame and its subwindows.
6134 Jason Rumney earlier refused to call change_frame_size right here
6135 with the following argument:
6137 The following mirrors what is done in xterm.c. It appears to be for
6138 informing lisp of the new size immediately, while the actual resize
6139 will happen asynchronously. But on Windows, the menu bar
6140 automatically wraps when the frame is too narrow to contain it, and
6141 that causes any calculations made here to come out wrong. The end
6142 is some nasty buggy behavior, including the potential loss of the
6145 Disabling this code is either not sufficient to fix the problems
6146 completely, or it causes fresh problems, but at least it removes
6147 the most problematic symptom of the minibuffer becoming unusable.
6149 However, as the discussion about how to handle frame size
6150 parameters on Windows (Bug#1348, Bug#16028) shows, that cure seems
6151 worse than the disease. In particular, menu bar wrapping looks
6152 like a non-issue - maybe so because Windows eventually gets back to
6153 us with the correct client rectangle anyway. But we have to avoid
6154 calling change_frame_size with a delta of less than one canoncial
6155 character size when frame_resize_pixelwise is nil, as explained in
6156 the comment above. */
6158 if (w32_enable_frame_resize_hack
)
6161 change_frame_size (f
, FRAME_PIXEL_TO_TEXT_WIDTH (f
, pixelwidth
),
6162 FRAME_PIXEL_TO_TEXT_HEIGHT (f
, pixelheight
),
6164 SET_FRAME_GARBAGED (f
);
6166 /* If cursor was outside the new size, mark it as off. */
6167 mark_window_cursors_off (XWINDOW (f
->root_window
));
6169 /* Clear out any recollection of where the mouse highlighting was,
6170 since it might be in a place that's outside the new frame size.
6171 Actually checking whether it is outside is a pain in the neck,
6172 so don't try--just let the highlighting be done afresh with new
6174 cancel_mouse_face (f
);
6179 do_pending_window_change (0);
6182 /* Mouse warping. */
6185 frame_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
6192 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
6193 pt
.x
= rect
.left
+ pix_x
;
6194 pt
.y
= rect
.top
+ pix_y
;
6195 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
6197 SetCursorPos (pt
.x
, pt
.y
);
6203 /* focus shifting, raising and lowering. */
6206 x_focus_frame (struct frame
*f
)
6209 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6212 /* Give input focus to frame. */
6215 /* Try not to change its Z-order if possible. */
6216 if (x_window_to_frame (dpyinfo
, GetForegroundWindow ()))
6217 my_set_focus (f
, FRAME_W32_WINDOW (f
));
6220 my_set_foreground_window (FRAME_W32_WINDOW (f
));
6224 /* Raise frame F. */
6226 x_raise_frame (struct frame
*f
)
6230 /* Strictly speaking, raise-frame should only change the frame's Z
6231 order, leaving input focus unchanged. This is reasonable behavior
6232 on X where the usual policy is point-to-focus. However, this
6233 behavior would be very odd on Windows where the usual policy is
6236 On X, if the mouse happens to be over the raised frame, it gets
6237 input focus anyway (so the window with focus will never be
6238 completely obscured) - if not, then just moving the mouse over it
6239 is sufficient to give it focus. On Windows, the user must actually
6240 click on the frame (preferably the title bar so as not to move
6241 point), which is more awkward. Also, no other Windows program
6242 raises a window to the top but leaves another window (possibly now
6243 completely obscured) with input focus.
6245 Because there is a system setting on Windows that allows the user
6246 to choose the point to focus policy, we make the strict semantics
6247 optional, but by default we grab focus when raising. */
6249 if (NILP (Vw32_grab_focus_on_raise
))
6251 /* The obvious call to my_set_window_pos doesn't work if Emacs is
6252 not already the foreground application: the frame is raised
6253 above all other frames belonging to us, but not above the
6254 current top window. To achieve that, we have to resort to this
6255 more cumbersome method. */
6257 HDWP handle
= BeginDeferWindowPos (2);
6260 handle
= DeferWindowPos (handle
,
6261 FRAME_W32_WINDOW (f
),
6264 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6267 handle
= DeferWindowPos (handle
,
6268 GetForegroundWindow (),
6269 FRAME_W32_WINDOW (f
),
6271 SWP_NOSIZE
| SWP_NOMOVE
|
6274 EndDeferWindowPos (handle
);
6280 my_bring_window_to_top (FRAME_W32_WINDOW (f
));
6286 /* Lower frame F. */
6288 x_lower_frame (struct frame
*f
)
6291 my_set_window_pos (FRAME_W32_WINDOW (f
),
6294 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
6299 w32_frame_raise_lower (struct frame
*f
, int raise_flag
)
6301 if (! FRAME_W32_P (f
))
6310 /* Change of visibility. */
6312 /* This tries to wait until the frame is really visible.
6313 However, if the window manager asks the user where to position
6314 the frame, this will return before the user finishes doing that.
6315 The frame will not actually be visible at that time,
6316 but it will become visible later when the window manager
6317 finishes with it. */
6320 x_make_frame_visible (struct frame
*f
)
6324 x_set_bitmap_icon (f
);
6326 if (! FRAME_VISIBLE_P (f
))
6328 /* We test FRAME_GARBAGED_P here to make sure we don't
6329 call x_set_offset a second time
6330 if we get to x_make_frame_visible a second time
6331 before the window gets really visible. */
6332 if (! FRAME_ICONIFIED_P (f
)
6333 && ! f
->output_data
.w32
->asked_for_visible
)
6338 /* Adjust vertical window position in order to avoid being
6339 covered by a task bar placed at the bottom of the desktop. */
6340 SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0);
6341 GetWindowRect (FRAME_W32_WINDOW (f
), &window_rect
);
6342 if (window_rect
.bottom
> workarea_rect
.bottom
6343 && window_rect
.top
> workarea_rect
.top
)
6344 f
->top_pos
= max (window_rect
.top
6345 - window_rect
.bottom
+ workarea_rect
.bottom
,
6348 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
6351 f
->output_data
.w32
->asked_for_visible
= 1;
6353 /* According to a report in emacs-devel 2008-06-03, SW_SHOWNORMAL
6354 causes unexpected behavior when unminimizing frames that were
6355 previously maximized. But only SW_SHOWNORMAL works properly for
6356 frames that were truely hidden (using make-frame-invisible), so
6357 we need it to avoid Bug#5482. It seems that iconified is only
6358 set for minimized windows that are still visible, so use that to
6359 determine the appropriate flag to pass ShowWindow. */
6360 my_show_window (f
, FRAME_W32_WINDOW (f
),
6361 FRAME_ICONIFIED_P (f
) ? SW_RESTORE
: SW_SHOWNORMAL
);
6364 /* Synchronize to ensure Emacs knows the frame is visible
6365 before we do anything else. We do this loop with input not blocked
6366 so that incoming events are handled. */
6371 /* This must come after we set COUNT. */
6374 XSETFRAME (frame
, f
);
6376 /* Wait until the frame is visible. Process X events until a
6377 MapNotify event has been seen, or until we think we won't get a
6378 MapNotify at all.. */
6379 for (count
= input_signal_count
+ 10;
6380 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
6382 /* Force processing of queued events. */
6383 /* TODO: x_sync equivalent? */
6385 /* Machines that do polling rather than SIGIO have been observed
6386 to go into a busy-wait here. So we'll fake an alarm signal
6387 to let the handler know that there's something to be read.
6388 We used to raise a real alarm, but it seems that the handler
6389 isn't always enabled here. This is probably a bug. */
6390 if (input_polling_used ())
6392 /* It could be confusing if a real alarm arrives while processing
6393 the fake one. Turn it off and let the handler reset it. */
6394 int old_poll_suppress_count
= poll_suppress_count
;
6395 poll_suppress_count
= 1;
6396 poll_for_input_1 ();
6397 poll_suppress_count
= old_poll_suppress_count
;
6403 /* Change from mapped state to withdrawn state. */
6405 /* Make the frame visible (mapped and not iconified). */
6408 x_make_frame_invisible (struct frame
*f
)
6410 /* Don't keep the highlight on an invisible frame. */
6411 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6412 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6416 my_show_window (f
, FRAME_W32_WINDOW (f
), SW_HIDE
);
6418 /* We can't distinguish this from iconification
6419 just by the event that we get from the server.
6420 So we can't win using the usual strategy of letting
6421 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
6422 and synchronize with the server to make sure we agree. */
6423 SET_FRAME_VISIBLE (f
, 0);
6424 SET_FRAME_ICONIFIED (f
, 0);
6429 /* Change window state from mapped to iconified. */
6432 x_iconify_frame (struct frame
*f
)
6434 /* Don't keep the highlight on an invisible frame. */
6435 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6436 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6438 if (FRAME_ICONIFIED_P (f
))
6443 x_set_bitmap_icon (f
);
6445 /* Simulate the user minimizing the frame. */
6446 SendMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
6448 SET_FRAME_VISIBLE (f
, 0);
6449 SET_FRAME_ICONIFIED (f
, 1);
6455 /* Free X resources of frame F. */
6458 x_free_frame_resources (struct frame
*f
)
6460 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6461 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
6465 /* We must free faces before destroying windows because some
6466 font-driver (e.g. xft) access a window while finishing a
6468 free_frame_faces (f
);
6470 if (FRAME_W32_WINDOW (f
))
6471 my_destroy_window (f
, FRAME_W32_WINDOW (f
));
6473 free_frame_menubar (f
);
6475 xfree (f
->output_data
.w32
);
6476 f
->output_data
.w32
= NULL
;
6478 if (f
== dpyinfo
->w32_focus_frame
)
6479 dpyinfo
->w32_focus_frame
= 0;
6480 if (f
== dpyinfo
->w32_focus_event_frame
)
6481 dpyinfo
->w32_focus_event_frame
= 0;
6482 if (f
== dpyinfo
->x_highlight_frame
)
6483 dpyinfo
->x_highlight_frame
= 0;
6484 if (f
== hlinfo
->mouse_face_mouse_frame
)
6485 reset_mouse_highlight (hlinfo
);
6491 /* Destroy the window of frame F. */
6493 x_destroy_window (struct frame
*f
)
6495 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6497 x_free_frame_resources (f
);
6498 dpyinfo
->reference_count
--;
6502 /* Setting window manager hints. */
6504 /* Set the normal size hints for the window manager, for frame F.
6505 FLAGS is the flags word to use--or 0 meaning preserve the flags
6506 that the window now has.
6507 If USER_POSITION, set the USPosition
6508 flag (this is useful when FLAGS is 0). */
6510 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
6512 Window window
= FRAME_W32_WINDOW (f
);
6516 SetWindowLong (window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
6517 SetWindowLong (window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
6518 SetWindowLong (window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
6519 SetWindowLong (window
, WND_VSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
6520 SetWindowLong (window
, WND_HSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_HEIGHT (f
));
6525 /***********************************************************************
6527 ***********************************************************************/
6531 /* Check that FONT is valid on frame F. It is if it can be found in F's
6535 x_check_font (struct frame
*f
, struct font
*font
)
6537 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
6538 if (font
->driver
->check
)
6539 eassert (font
->driver
->check (f
, font
) == 0);
6542 #endif /* GLYPH_DEBUG */
6544 /* Show hourglass cursor on frame F. */
6547 w32_show_hourglass (struct frame
*f
)
6549 if (!menubar_in_use
&& !current_popup_menu
)
6551 struct w32_output
*w32
= FRAME_X_OUTPUT (f
);
6553 w32
->hourglass_p
= 1;
6554 SetCursor (w32
->hourglass_cursor
);
6558 /* Hide hourglass cursor on frame F. */
6561 w32_hide_hourglass (struct frame
*f
)
6563 struct w32_output
*w32
= FRAME_X_OUTPUT (f
);
6565 w32
->hourglass_p
= 0;
6566 SetCursor (w32
->current_cursor
);
6569 /* FIXME: old code did that, but I don't know why. Anyway,
6570 this is used for non-GUI frames (see cancel_hourglass). */
6573 w32_arrow_cursor (void)
6575 SetCursor (w32_load_cursor (IDC_ARROW
));
6578 /***********************************************************************
6580 ***********************************************************************/
6582 static int w32_initialized
= 0;
6585 w32_initialize_display_info (Lisp_Object display_name
)
6587 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6589 memset (dpyinfo
, 0, sizeof (*dpyinfo
));
6591 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
6592 dpyinfo
->w32_id_name
= xmalloc (SCHARS (Vinvocation_name
)
6593 + SCHARS (Vsystem_name
) + 2);
6594 sprintf (dpyinfo
->w32_id_name
, "%s@%s",
6595 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
6597 /* Default Console mode values - overridden when running in GUI mode
6598 with values obtained from system metrics. */
6601 dpyinfo
->n_planes
= 1;
6602 dpyinfo
->n_cbits
= 4;
6603 dpyinfo
->n_fonts
= 0;
6604 dpyinfo
->smallest_font_height
= 1;
6605 dpyinfo
->smallest_char_width
= 1;
6606 dpyinfo
->vertical_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
6607 dpyinfo
->horizontal_scroll_bar_cursor
= w32_load_cursor (IDC_ARROW
);
6608 /* TODO: dpyinfo->gray */
6610 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
6613 /* Create an xrdb-style database of resources to supersede registry settings.
6614 The database is just a concatenation of C strings, finished by an additional
6615 \0. The strings are submitted to some basic normalization, so
6617 [ *]option[ *]:[ *]value...
6623 but any whitespace following value is not removed. */
6626 w32_make_rdb (char *xrm_option
)
6628 char *buffer
= xmalloc (strlen (xrm_option
) + 2);
6629 char *current
= buffer
;
6632 int before_value
= 0;
6646 if (in_option
&& (ch
== ':'))
6651 else if (before_value
)
6656 else if (!(in_option
|| before_value
))
6667 extern frame_parm_handler w32_frame_parm_handlers
[];
6669 static struct redisplay_interface w32_redisplay_interface
=
6671 w32_frame_parm_handlers
,
6675 x_clear_end_of_line
,
6677 x_after_update_window_line
,
6678 x_update_window_begin
,
6679 x_update_window_end
,
6680 0, /* flush_display */
6681 x_clear_window_mouse_face
,
6682 x_get_glyph_overhangs
,
6683 x_fix_overlapping_area
,
6684 w32_draw_fringe_bitmap
,
6685 w32_define_fringe_bitmap
,
6686 w32_destroy_fringe_bitmap
,
6687 w32_compute_glyph_string_overhangs
,
6688 x_draw_glyph_string
,
6689 w32_define_frame_cursor
,
6690 w32_clear_frame_area
,
6691 w32_draw_window_cursor
,
6692 w32_draw_vertical_window_border
,
6693 w32_draw_window_divider
,
6694 w32_shift_glyphs_for_insert
,
6699 static void x_delete_terminal (struct terminal
*term
);
6701 static struct terminal
*
6702 w32_create_terminal (struct w32_display_info
*dpyinfo
)
6704 struct terminal
*terminal
;
6706 terminal
= create_terminal (output_w32
, &w32_redisplay_interface
);
6708 terminal
->display_info
.w32
= dpyinfo
;
6709 dpyinfo
->terminal
= terminal
;
6711 /* MSVC does not type K&R functions with no arguments correctly, and
6712 so we must explicitly cast them. */
6713 terminal
->clear_frame_hook
= x_clear_frame
;
6714 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
6715 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
6716 terminal
->ring_bell_hook
= w32_ring_bell
;
6717 terminal
->update_begin_hook
= x_update_begin
;
6718 terminal
->update_end_hook
= x_update_end
;
6719 terminal
->read_socket_hook
= w32_read_socket
;
6720 terminal
->frame_up_to_date_hook
= w32_frame_up_to_date
;
6721 terminal
->mouse_position_hook
= w32_mouse_position
;
6722 terminal
->frame_rehighlight_hook
= w32_frame_rehighlight
;
6723 terminal
->frame_raise_lower_hook
= w32_frame_raise_lower
;
6724 terminal
->fullscreen_hook
= w32fullscreen_hook
;
6725 terminal
->menu_show_hook
= w32_menu_show
;
6726 terminal
->popup_dialog_hook
= w32_popup_dialog
;
6727 terminal
->set_vertical_scroll_bar_hook
= w32_set_vertical_scroll_bar
;
6728 terminal
->set_horizontal_scroll_bar_hook
= w32_set_horizontal_scroll_bar
;
6729 terminal
->condemn_scroll_bars_hook
= w32_condemn_scroll_bars
;
6730 terminal
->redeem_scroll_bar_hook
= w32_redeem_scroll_bar
;
6731 terminal
->judge_scroll_bars_hook
= w32_judge_scroll_bars
;
6732 terminal
->delete_frame_hook
= x_destroy_window
;
6733 terminal
->delete_terminal_hook
= x_delete_terminal
;
6734 /* Other hooks are NULL by default. */
6736 /* We don't yet support separate terminals on W32, so don't try to share
6737 keyboards between virtual terminals that are on the same physical
6738 terminal like X does. */
6739 terminal
->kboard
= allocate_kboard (Qw32
);
6740 /* Don't let the initial kboard remain current longer than necessary.
6741 That would cause problems if a file loaded on startup tries to
6742 prompt in the mini-buffer. */
6743 if (current_kboard
== initial_kboard
)
6744 current_kboard
= terminal
->kboard
;
6745 terminal
->kboard
->reference_count
++;
6751 x_delete_terminal (struct terminal
*terminal
)
6753 struct w32_display_info
*dpyinfo
= terminal
->display_info
.w32
;
6755 /* Protect against recursive calls. delete_frame in
6756 delete_terminal calls us back when it deletes our last frame. */
6757 if (!terminal
->name
)
6762 x_delete_display (dpyinfo
);
6766 struct w32_display_info
*
6767 w32_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
6769 struct w32_display_info
*dpyinfo
;
6770 struct terminal
*terminal
;
6775 if (!w32_initialized
)
6778 w32_initialized
= 1;
6781 w32_initialize_display_info (display_name
);
6783 dpyinfo
= &one_w32_display_info
;
6784 terminal
= w32_create_terminal (dpyinfo
);
6786 /* Set the name of the terminal. */
6787 terminal
->name
= xlispstrdup (display_name
);
6789 dpyinfo
->xrdb
= xrm_option
? w32_make_rdb (xrm_option
) : NULL
;
6791 /* Put this display on the chain. */
6792 dpyinfo
->next
= x_display_list
;
6793 x_display_list
= dpyinfo
;
6797 dpyinfo
->root_window
= GetDesktopWindow ();
6798 dpyinfo
->n_planes
= GetDeviceCaps (hdc
, PLANES
);
6799 dpyinfo
->n_cbits
= GetDeviceCaps (hdc
, BITSPIXEL
);
6800 dpyinfo
->resx
= GetDeviceCaps (hdc
, LOGPIXELSX
);
6801 dpyinfo
->resy
= GetDeviceCaps (hdc
, LOGPIXELSY
);
6802 dpyinfo
->has_palette
= GetDeviceCaps (hdc
, RASTERCAPS
) & RC_PALETTE
;
6803 ReleaseDC (NULL
, hdc
);
6805 /* initialize palette with white and black */
6808 w32_defined_color (0, "white", &color
, 1);
6809 w32_defined_color (0, "black", &color
, 1);
6813 /* Add the default keyboard. When !WINDOWSNT, we're using the
6814 standard Emacs console handling machinery and don't need an
6815 explicit FD here. */
6816 add_keyboard_wait_descriptor (0);
6818 /* /dev/windows wakes us up when we have a thread message pending. */
6819 add_keyboard_wait_descriptor (w32_message_fd
);
6822 /* Create Fringe Bitmaps and store them for later use.
6824 On W32, bitmaps are all unsigned short, as Windows requires
6825 bitmap data to be Word aligned. For some reason they are
6826 horizontally reflected compared to how they appear on X, so we
6827 need to bitswap and convert to unsigned shorts before creating
6829 w32_init_fringe (terminal
->rif
);
6836 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6838 x_delete_display (struct w32_display_info
*dpyinfo
)
6840 /* FIXME: the only display info apparently can't be deleted. */
6841 /* free palette table */
6843 struct w32_palette_entry
* plist
;
6845 plist
= dpyinfo
->color_list
;
6848 struct w32_palette_entry
* pentry
= plist
;
6849 plist
= plist
->next
;
6852 dpyinfo
->color_list
= NULL
;
6853 if (dpyinfo
->palette
)
6854 DeleteObject (dpyinfo
->palette
);
6856 w32_reset_fringes ();
6860 /* Set up use of W32. */
6862 DWORD WINAPI
w32_msg_worker (void * arg
);
6865 w32_initialize (void)
6868 HRESULT (WINAPI
* set_user_model
) (const wchar_t * id
);
6872 w32_system_caret_hwnd
= NULL
;
6873 w32_system_caret_height
= 0;
6874 w32_system_caret_x
= 0;
6875 w32_system_caret_y
= 0;
6877 /* On Windows 7 and later, we need to set the user model ID
6878 to associate emacsclient launched files with Emacs frames
6880 shell
= GetModuleHandle ("shell32.dll");
6884 = (void *) GetProcAddress (shell
,
6885 "SetCurrentProcessExplicitAppUserModelID");
6887 /* If the function is defined, then we are running on Windows 7
6888 or newer, and the UI uses this to group related windows
6889 together. Since emacs, runemacs, emacsclient are related, we
6890 want them grouped even though the executables are different,
6891 so we need to set a consistent ID between them. */
6893 set_user_model (L
"GNU.Emacs");
6897 if ((w32_message_fd
= emacs_open ("/dev/windows", O_RDWR
, 0)) == -1)
6898 fatal ("opening /dev/windows: %s", strerror (errno
));
6901 /* Initialize w32_use_visible_system_caret based on whether a screen
6902 reader is in use. */
6903 if (!SystemParametersInfo (SPI_GETSCREENREADER
, 0,
6904 &w32_use_visible_system_caret
, 0))
6905 w32_use_visible_system_caret
= 0;
6907 any_help_event_p
= 0;
6909 /* Initialize input mode: interrupt_input off, no flow control, allow
6910 8 bit character input, standard quit char. */
6911 Fset_input_mode (Qnil
, Qnil
, make_number (2), Qnil
);
6914 LCID input_locale_id
= LOWORD (GetKeyboardLayout (0));
6915 w32_keyboard_codepage
= codepage_for_locale (input_locale_id
);
6918 /* Create the window thread - it will terminate itself when the app
6922 dwMainThreadId
= GetCurrentThreadId ();
6923 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
6924 GetCurrentProcess (), &hMainThread
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
6926 /* Wait for thread to start */
6930 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
6932 hWindowsThread
= CreateThread (NULL
, 0,
6934 0, 0, &dwWindowsThreadId
);
6936 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
6939 /* It is desirable that mainThread should have the same notion of
6940 focus window and active window as windowsThread. Unfortunately, the
6941 following call to AttachThreadInput, which should do precisely what
6942 we need, causes major problems when Emacs is linked as a console
6943 program. Unfortunately, we have good reasons for doing that, so
6944 instead we need to send messages to windowsThread to make some API
6945 calls for us (ones that affect, or depend on, the active/focus
6947 #ifdef ATTACH_THREADS
6948 AttachThreadInput (dwMainThreadId
, dwWindowsThreadId
, TRUE
);
6951 /* Dynamically link to optional system components. */
6953 HMODULE user_lib
= GetModuleHandle ("user32.dll");
6955 #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn)
6957 LOAD_PROC (user_lib
, SetLayeredWindowAttributes
);
6961 /* Ensure scrollbar handles are at least 5 pixels. */
6962 vertical_scroll_bar_min_handle
= 5;
6963 horizontal_scroll_bar_min_handle
= 5;
6965 /* For either kind of scroll bar, take account of the arrows; these
6966 effectively form the border of the main scroll bar range. */
6967 vertical_scroll_bar_top_border
= vertical_scroll_bar_bottom_border
6968 = GetSystemMetrics (SM_CYVSCROLL
);
6969 horizontal_scroll_bar_left_border
= horizontal_scroll_bar_right_border
6970 = GetSystemMetrics (SM_CYHSCROLL
);
6975 syms_of_w32term (void)
6977 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
6979 DEFSYM (Qadded
, "added");
6980 DEFSYM (Qremoved
, "removed");
6981 DEFSYM (Qmodified
, "modified");
6982 DEFSYM (Qrenamed_from
, "renamed-from");
6983 DEFSYM (Qrenamed_to
, "renamed-to");
6985 DEFVAR_INT ("w32-num-mouse-buttons",
6986 w32_num_mouse_buttons
,
6987 doc
: /* Number of physical mouse buttons. */);
6988 w32_num_mouse_buttons
= 2;
6990 DEFVAR_LISP ("w32-swap-mouse-buttons",
6991 Vw32_swap_mouse_buttons
,
6992 doc
: /* Swap the mapping of middle and right mouse buttons.
6993 When nil, middle button is mouse-2 and right button is mouse-3. */);
6994 Vw32_swap_mouse_buttons
= Qnil
;
6996 DEFVAR_LISP ("w32-grab-focus-on-raise",
6997 Vw32_grab_focus_on_raise
,
6998 doc
: /* Raised frame grabs input focus.
6999 When t, `raise-frame' grabs input focus as well. This fits well
7000 with the normal Windows click-to-focus policy, but might not be
7001 desirable when using a point-to-focus policy. */);
7002 Vw32_grab_focus_on_raise
= Qt
;
7004 DEFVAR_LISP ("w32-capslock-is-shiftlock",
7005 Vw32_capslock_is_shiftlock
,
7006 doc
: /* Apply CapsLock state to non character input keys.
7007 When nil, CapsLock only affects normal character input keys. */);
7008 Vw32_capslock_is_shiftlock
= Qnil
;
7010 DEFVAR_LISP ("w32-recognize-altgr",
7011 Vw32_recognize_altgr
,
7012 doc
: /* Recognize right-alt and left-ctrl as AltGr.
7013 When nil, the right-alt and left-ctrl key combination is
7014 interpreted normally. */);
7015 Vw32_recognize_altgr
= Qt
;
7017 DEFVAR_BOOL ("w32-use-visible-system-caret",
7018 w32_use_visible_system_caret
,
7019 doc
: /* Flag to make the system caret visible.
7020 When this is non-nil, Emacs will indicate the position of point by
7021 using the system caret instead of drawing its own cursor. Some screen
7022 reader software does not track the system cursor properly when it is
7023 invisible, and gets confused by Emacs drawing its own cursor, so this
7024 variable is initialized to t when Emacs detects that screen reader
7025 software is running as it starts up.
7027 When this variable is set, other variables affecting the appearance of
7028 the cursor have no effect. */);
7030 w32_use_visible_system_caret
= 0;
7032 /* We don't yet support this, but defining this here avoids whining
7033 from cus-start.el and other places, like "M-x set-variable". */
7034 DEFVAR_BOOL ("x-use-underline-position-properties",
7035 x_use_underline_position_properties
,
7036 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
7037 A value of nil means ignore them. If you encounter fonts with bogus
7038 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7039 to 4.1, set this to nil. You can also use `underline-minimum-offset'
7040 to override the font's UNDERLINE_POSITION for small font display
7042 x_use_underline_position_properties
= 0;
7044 DEFVAR_BOOL ("x-underline-at-descent-line",
7045 x_underline_at_descent_line
,
7046 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
7047 A value of nil means to draw the underline according to the value of the
7048 variable `x-use-underline-position-properties', which is usually at the
7049 baseline level. The default value is nil. */);
7050 x_underline_at_descent_line
= 0;
7052 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
7053 doc
: /* Which toolkit scroll bars Emacs uses, if any.
7054 A value of nil means Emacs doesn't use toolkit scroll bars.
7055 With the X Window system, the value is a symbol describing the
7056 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
7057 With MS Windows or Nextstep, the value is t. */);
7058 Vx_toolkit_scroll_bars
= Qt
;
7060 DEFVAR_BOOL ("w32-unicode-filenames",
7061 w32_unicode_filenames
,
7062 doc
: /* Non-nil means use Unicode APIs when passing file names to the OS.
7063 A value of nil means file names passed to the OS APIs and returned
7064 from those APIs are encoded/decoded using the ANSI codepage
7065 specified by `file-name-coding-system'.
7067 This variable is set to non-nil by default when Emacs runs on Windows
7068 systems of the NT family, including W2K, XP, Vista, Windows 7 and
7069 Windows 8. It is set to nil on Windows 9X. */);
7070 w32_unicode_filenames
= 0;
7072 DEFVAR_BOOL ("w32-enable-frame-resize-hack",
7073 w32_enable_frame_resize_hack
,
7074 doc
: /* Non-nil means enable hack for frame resizing on Windows.
7075 A value of nil means to resize frames by sending a corresponding request
7076 to the Windows API and changing the pixel sizes of the frame and its
7077 windows after the latter calls back. If this is non-nil, Emacs changes
7078 the pixel sizes of the frame and its windows at the time it sends the
7079 resize request to the API. */);
7080 w32_enable_frame_resize_hack
= 1;
7082 /* Tell Emacs about this window system. */
7083 Fprovide (Qw32
, Qnil
);