1 /* Graphical user interface functions for the Microsoft Windows API.
3 Copyright (C) 1989, 1992-2015 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/>. */
20 /* Added by Kevin Gallo */
38 #include "character.h"
40 #include "intervals.h"
41 #include "dispextern.h"
43 #include "blockinput.h"
50 #include "termhooks.h"
52 #include "w32common.h"
57 #endif /* WINDOWSNT */
65 #include "bitmaps/gray.xbm"
81 #ifndef FOF_NO_CONNECTED_ELEMENTS
82 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
85 void syms_of_w32fns (void);
86 void globals_of_w32fns (void);
88 extern void free_frame_menubar (struct frame
*);
89 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
90 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
91 extern void w32_free_menu_strings (HWND
);
92 extern const char *map_w32_filename (const char *, const char **);
93 extern char * w32_strerror (int error_no
);
96 #define IDC_HAND MAKEINTRESOURCE(32649)
99 /* Prefix for system colors. */
100 #define SYSTEM_COLOR_PREFIX "System"
101 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
103 /* State variables for emulating a three button mouse. */
108 static int button_state
= 0;
109 static W32Msg saved_mouse_button_msg
;
110 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
111 static W32Msg saved_mouse_move_msg
;
112 static unsigned mouse_move_timer
= 0;
114 /* Window that is tracking the mouse. */
115 static HWND track_mouse_window
;
117 /* Multi-monitor API definitions that are not pulled from the headers
118 since we are compiling for NT 4. */
119 #ifndef MONITOR_DEFAULT_TO_NEAREST
120 #define MONITOR_DEFAULT_TO_NEAREST 2
122 #ifndef MONITORINFOF_PRIMARY
123 #define MONITORINFOF_PRIMARY 1
125 #ifndef SM_XVIRTUALSCREEN
126 #define SM_XVIRTUALSCREEN 76
128 #ifndef SM_YVIRTUALSCREEN
129 #define SM_YVIRTUALSCREEN 77
131 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
132 To avoid a compile error on one or the other, redefine with a new name. */
141 #if _WIN32_WINDOWS >= 0x0410
142 #define C_CHILDREN_TITLEBAR CCHILDREN_TITLEBAR
143 typedef TITLEBARINFO TITLEBAR_INFO
;
145 #define C_CHILDREN_TITLEBAR 5
150 DWORD rgstate
[C_CHILDREN_TITLEBAR
+1];
151 } TITLEBAR_INFO
, *PTITLEBAR_INFO
;
154 #ifndef CCHDEVICENAME
155 #define CCHDEVICENAME 32
157 struct MONITOR_INFO_EX
163 char szDevice
[CCHDEVICENAME
];
166 /* Reportedly, MSVC does not have this in its headers. */
167 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
168 DECLARE_HANDLE(HMONITOR
);
171 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
172 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
173 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
174 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
175 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
176 typedef BOOL (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
177 typedef BOOL (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
178 IN COMPOSITIONFORM
*form
);
179 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
180 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
181 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
182 typedef HMONITOR (WINAPI
* MonitorFromWindow_Proc
)
183 (IN HWND hwnd
, IN DWORD dwFlags
);
184 typedef BOOL
CALLBACK (* MonitorEnum_Proc
)
185 (IN HMONITOR monitor
, IN HDC hdc
, IN RECT
*rcMonitor
, IN LPARAM dwData
);
186 typedef BOOL (WINAPI
* EnumDisplayMonitors_Proc
)
187 (IN HDC hdc
, IN RECT
*rcClip
, IN MonitorEnum_Proc fnEnum
, IN LPARAM dwData
);
188 typedef BOOL (WINAPI
* GetTitleBarInfo_Proc
)
189 (IN HWND hwnd
, OUT TITLEBAR_INFO
* info
);
191 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
192 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
193 ImmGetContext_Proc get_ime_context_fn
= NULL
;
194 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
195 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
196 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
197 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
198 MonitorFromWindow_Proc monitor_from_window_fn
= NULL
;
199 EnumDisplayMonitors_Proc enum_display_monitors_fn
= NULL
;
200 GetTitleBarInfo_Proc get_title_bar_info_fn
= NULL
;
203 #define unicode_append_menu AppendMenuW
204 #else /* !NTGUI_UNICODE */
205 extern AppendMenuW_Proc unicode_append_menu
;
206 #endif /* NTGUI_UNICODE */
208 /* Flag to selectively ignore WM_IME_CHAR messages. */
209 static int ignore_ime_char
= 0;
211 /* W95 mousewheel handler */
212 unsigned int msh_mousewheel
= 0;
215 #define MOUSE_BUTTON_ID 1
216 #define MOUSE_MOVE_ID 2
217 #define MENU_FREE_ID 3
218 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
220 #define MENU_FREE_DELAY 1000
221 static unsigned menu_free_timer
= 0;
224 static ptrdiff_t image_cache_refcount
;
225 static int dpyinfo_refcount
;
228 static HWND w32_visible_system_caret_hwnd
;
230 static int w32_unicode_gui
;
233 extern HMENU current_popup_menu
;
234 int menubar_in_use
= 0;
236 /* From w32uniscribe.c */
237 extern void syms_of_w32uniscribe (void);
238 extern int uniscribe_available
;
241 /* From w32inevt.c */
242 extern int faked_key
;
243 #endif /* WINDOWSNT */
245 /* This gives us the page size and the size of the allocation unit on NT. */
246 SYSTEM_INFO sysinfo_cache
;
248 /* This gives us version, build, and platform identification. */
249 OSVERSIONINFO osinfo_cache
;
251 DWORD_PTR syspage_mask
= 0;
253 /* The major and minor versions of NT. */
254 int w32_major_version
;
255 int w32_minor_version
;
256 int w32_build_number
;
258 /* Distinguish between Windows NT and Windows 95. */
262 HINSTANCE hinst
= NULL
;
265 static unsigned int sound_type
= 0xFFFFFFFF;
266 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
268 /* Let the user specify a display with a frame.
269 nil stands for the selected frame--or, if that is not a w32 frame,
270 the first display on the list. */
272 struct w32_display_info
*
273 check_x_display_info (Lisp_Object object
)
277 struct frame
*sf
= XFRAME (selected_frame
);
279 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
280 return FRAME_DISPLAY_INFO (sf
);
282 return &one_w32_display_info
;
284 else if (TERMINALP (object
))
286 struct terminal
*t
= decode_live_terminal (object
);
288 if (t
->type
!= output_w32
)
289 error ("Terminal %d is not a W32 display", t
->id
);
291 return t
->display_info
.w32
;
293 else if (STRINGP (object
))
294 return x_display_info_for_name (object
);
299 CHECK_LIVE_FRAME (object
);
301 if (! FRAME_W32_P (f
))
302 error ("Non-W32 frame used");
303 return FRAME_DISPLAY_INFO (f
);
307 /* Return the Emacs frame-object corresponding to an w32 window.
308 It could be the frame's main window or an icon window. */
311 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
313 Lisp_Object tail
, frame
;
316 FOR_EACH_FRAME (tail
, frame
)
319 if (!FRAME_W32_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
322 if (FRAME_W32_WINDOW (f
) == wdesc
)
329 static Lisp_Object
unwind_create_frame (Lisp_Object
);
330 static void unwind_create_tip_frame (Lisp_Object
);
331 static void my_create_window (struct frame
*);
332 static void my_create_tip_window (struct frame
*);
334 /* TODO: Native Input Method support; see x_create_im. */
335 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
336 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
337 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
338 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
339 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
340 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
341 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
342 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
343 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
344 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
345 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
346 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
347 void x_set_internal_border_width (struct frame
*f
, Lisp_Object
, Lisp_Object
);
350 /* Store the screen positions of frame F into XPTR and YPTR.
351 These are the positions of the containing window manager window,
352 not Emacs's own window. */
355 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
360 /* Get the bounds of the WM window. */
361 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
366 /* Convert (0, 0) in the client area to screen co-ordinates. */
367 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
373 /* Returns the window rectangle appropriate for the given fullscreen mode.
374 The normal rect parameter was the window's rectangle prior to entering
375 fullscreen mode. If multiple monitor support is available, the nearest
376 monitor to the window is chosen. */
379 w32_fullscreen_rect (HWND hwnd
, int fsmode
, RECT normal
, RECT
*rect
)
381 struct MONITOR_INFO mi
= { sizeof(mi
) };
382 if (monitor_from_window_fn
&& get_monitor_info_fn
)
385 monitor_from_window_fn (hwnd
, MONITOR_DEFAULT_TO_NEAREST
);
386 get_monitor_info_fn (monitor
, &mi
);
390 mi
.rcMonitor
.left
= 0;
391 mi
.rcMonitor
.top
= 0;
392 mi
.rcMonitor
.right
= GetSystemMetrics (SM_CXSCREEN
);
393 mi
.rcMonitor
.bottom
= GetSystemMetrics (SM_CYSCREEN
);
396 mi
.rcWork
.right
= GetSystemMetrics (SM_CXMAXIMIZED
);
397 mi
.rcWork
.bottom
= GetSystemMetrics (SM_CYMAXIMIZED
);
402 case FULLSCREEN_BOTH
:
403 rect
->left
= mi
.rcMonitor
.left
;
404 rect
->top
= mi
.rcMonitor
.top
;
405 rect
->right
= mi
.rcMonitor
.right
;
406 rect
->bottom
= mi
.rcMonitor
.bottom
;
408 case FULLSCREEN_WIDTH
:
409 rect
->left
= mi
.rcWork
.left
;
410 rect
->top
= normal
.top
;
411 rect
->right
= mi
.rcWork
.right
;
412 rect
->bottom
= normal
.bottom
;
414 case FULLSCREEN_HEIGHT
:
415 rect
->left
= normal
.left
;
416 rect
->top
= mi
.rcWork
.top
;
417 rect
->right
= normal
.right
;
418 rect
->bottom
= mi
.rcWork
.bottom
;
428 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
429 Sw32_define_rgb_color
, 4, 4, 0,
430 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
431 This adds or updates a named color to `w32-color-map', making it
432 available for use. The original entry's RGB ref is returned, or nil
433 if the entry is new. */)
434 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
437 Lisp_Object oldrgb
= Qnil
;
441 CHECK_NUMBER (green
);
445 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
449 /* replace existing entry in w32-color-map or add new entry. */
450 entry
= Fassoc (name
, Vw32_color_map
);
453 entry
= Fcons (name
, rgb
);
454 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
458 oldrgb
= Fcdr (entry
);
459 Fsetcdr (entry
, rgb
);
467 /* The default colors for the w32 color map */
468 typedef struct colormap_t
474 colormap_t w32_color_map
[] =
476 {"snow" , PALETTERGB (255,250,250)},
477 {"ghost white" , PALETTERGB (248,248,255)},
478 {"GhostWhite" , PALETTERGB (248,248,255)},
479 {"white smoke" , PALETTERGB (245,245,245)},
480 {"WhiteSmoke" , PALETTERGB (245,245,245)},
481 {"gainsboro" , PALETTERGB (220,220,220)},
482 {"floral white" , PALETTERGB (255,250,240)},
483 {"FloralWhite" , PALETTERGB (255,250,240)},
484 {"old lace" , PALETTERGB (253,245,230)},
485 {"OldLace" , PALETTERGB (253,245,230)},
486 {"linen" , PALETTERGB (250,240,230)},
487 {"antique white" , PALETTERGB (250,235,215)},
488 {"AntiqueWhite" , PALETTERGB (250,235,215)},
489 {"papaya whip" , PALETTERGB (255,239,213)},
490 {"PapayaWhip" , PALETTERGB (255,239,213)},
491 {"blanched almond" , PALETTERGB (255,235,205)},
492 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
493 {"bisque" , PALETTERGB (255,228,196)},
494 {"peach puff" , PALETTERGB (255,218,185)},
495 {"PeachPuff" , PALETTERGB (255,218,185)},
496 {"navajo white" , PALETTERGB (255,222,173)},
497 {"NavajoWhite" , PALETTERGB (255,222,173)},
498 {"moccasin" , PALETTERGB (255,228,181)},
499 {"cornsilk" , PALETTERGB (255,248,220)},
500 {"ivory" , PALETTERGB (255,255,240)},
501 {"lemon chiffon" , PALETTERGB (255,250,205)},
502 {"LemonChiffon" , PALETTERGB (255,250,205)},
503 {"seashell" , PALETTERGB (255,245,238)},
504 {"honeydew" , PALETTERGB (240,255,240)},
505 {"mint cream" , PALETTERGB (245,255,250)},
506 {"MintCream" , PALETTERGB (245,255,250)},
507 {"azure" , PALETTERGB (240,255,255)},
508 {"alice blue" , PALETTERGB (240,248,255)},
509 {"AliceBlue" , PALETTERGB (240,248,255)},
510 {"lavender" , PALETTERGB (230,230,250)},
511 {"lavender blush" , PALETTERGB (255,240,245)},
512 {"LavenderBlush" , PALETTERGB (255,240,245)},
513 {"misty rose" , PALETTERGB (255,228,225)},
514 {"MistyRose" , PALETTERGB (255,228,225)},
515 {"white" , PALETTERGB (255,255,255)},
516 {"black" , PALETTERGB ( 0, 0, 0)},
517 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
518 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
519 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
520 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
521 {"dim gray" , PALETTERGB (105,105,105)},
522 {"DimGray" , PALETTERGB (105,105,105)},
523 {"dim grey" , PALETTERGB (105,105,105)},
524 {"DimGrey" , PALETTERGB (105,105,105)},
525 {"slate gray" , PALETTERGB (112,128,144)},
526 {"SlateGray" , PALETTERGB (112,128,144)},
527 {"slate grey" , PALETTERGB (112,128,144)},
528 {"SlateGrey" , PALETTERGB (112,128,144)},
529 {"light slate gray" , PALETTERGB (119,136,153)},
530 {"LightSlateGray" , PALETTERGB (119,136,153)},
531 {"light slate grey" , PALETTERGB (119,136,153)},
532 {"LightSlateGrey" , PALETTERGB (119,136,153)},
533 {"gray" , PALETTERGB (190,190,190)},
534 {"grey" , PALETTERGB (190,190,190)},
535 {"light grey" , PALETTERGB (211,211,211)},
536 {"LightGrey" , PALETTERGB (211,211,211)},
537 {"light gray" , PALETTERGB (211,211,211)},
538 {"LightGray" , PALETTERGB (211,211,211)},
539 {"midnight blue" , PALETTERGB ( 25, 25,112)},
540 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
541 {"navy" , PALETTERGB ( 0, 0,128)},
542 {"navy blue" , PALETTERGB ( 0, 0,128)},
543 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
544 {"cornflower blue" , PALETTERGB (100,149,237)},
545 {"CornflowerBlue" , PALETTERGB (100,149,237)},
546 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
547 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
548 {"slate blue" , PALETTERGB (106, 90,205)},
549 {"SlateBlue" , PALETTERGB (106, 90,205)},
550 {"medium slate blue" , PALETTERGB (123,104,238)},
551 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
552 {"light slate blue" , PALETTERGB (132,112,255)},
553 {"LightSlateBlue" , PALETTERGB (132,112,255)},
554 {"medium blue" , PALETTERGB ( 0, 0,205)},
555 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
556 {"royal blue" , PALETTERGB ( 65,105,225)},
557 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
558 {"blue" , PALETTERGB ( 0, 0,255)},
559 {"dodger blue" , PALETTERGB ( 30,144,255)},
560 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
561 {"deep sky blue" , PALETTERGB ( 0,191,255)},
562 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
563 {"sky blue" , PALETTERGB (135,206,235)},
564 {"SkyBlue" , PALETTERGB (135,206,235)},
565 {"light sky blue" , PALETTERGB (135,206,250)},
566 {"LightSkyBlue" , PALETTERGB (135,206,250)},
567 {"steel blue" , PALETTERGB ( 70,130,180)},
568 {"SteelBlue" , PALETTERGB ( 70,130,180)},
569 {"light steel blue" , PALETTERGB (176,196,222)},
570 {"LightSteelBlue" , PALETTERGB (176,196,222)},
571 {"light blue" , PALETTERGB (173,216,230)},
572 {"LightBlue" , PALETTERGB (173,216,230)},
573 {"powder blue" , PALETTERGB (176,224,230)},
574 {"PowderBlue" , PALETTERGB (176,224,230)},
575 {"pale turquoise" , PALETTERGB (175,238,238)},
576 {"PaleTurquoise" , PALETTERGB (175,238,238)},
577 {"dark turquoise" , PALETTERGB ( 0,206,209)},
578 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
579 {"medium turquoise" , PALETTERGB ( 72,209,204)},
580 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
581 {"turquoise" , PALETTERGB ( 64,224,208)},
582 {"cyan" , PALETTERGB ( 0,255,255)},
583 {"light cyan" , PALETTERGB (224,255,255)},
584 {"LightCyan" , PALETTERGB (224,255,255)},
585 {"cadet blue" , PALETTERGB ( 95,158,160)},
586 {"CadetBlue" , PALETTERGB ( 95,158,160)},
587 {"medium aquamarine" , PALETTERGB (102,205,170)},
588 {"MediumAquamarine" , PALETTERGB (102,205,170)},
589 {"aquamarine" , PALETTERGB (127,255,212)},
590 {"dark green" , PALETTERGB ( 0,100, 0)},
591 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
592 {"dark olive green" , PALETTERGB ( 85,107, 47)},
593 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
594 {"dark sea green" , PALETTERGB (143,188,143)},
595 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
596 {"sea green" , PALETTERGB ( 46,139, 87)},
597 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
598 {"medium sea green" , PALETTERGB ( 60,179,113)},
599 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
600 {"light sea green" , PALETTERGB ( 32,178,170)},
601 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
602 {"pale green" , PALETTERGB (152,251,152)},
603 {"PaleGreen" , PALETTERGB (152,251,152)},
604 {"spring green" , PALETTERGB ( 0,255,127)},
605 {"SpringGreen" , PALETTERGB ( 0,255,127)},
606 {"lawn green" , PALETTERGB (124,252, 0)},
607 {"LawnGreen" , PALETTERGB (124,252, 0)},
608 {"green" , PALETTERGB ( 0,255, 0)},
609 {"chartreuse" , PALETTERGB (127,255, 0)},
610 {"medium spring green" , PALETTERGB ( 0,250,154)},
611 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
612 {"green yellow" , PALETTERGB (173,255, 47)},
613 {"GreenYellow" , PALETTERGB (173,255, 47)},
614 {"lime green" , PALETTERGB ( 50,205, 50)},
615 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
616 {"yellow green" , PALETTERGB (154,205, 50)},
617 {"YellowGreen" , PALETTERGB (154,205, 50)},
618 {"forest green" , PALETTERGB ( 34,139, 34)},
619 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
620 {"olive drab" , PALETTERGB (107,142, 35)},
621 {"OliveDrab" , PALETTERGB (107,142, 35)},
622 {"dark khaki" , PALETTERGB (189,183,107)},
623 {"DarkKhaki" , PALETTERGB (189,183,107)},
624 {"khaki" , PALETTERGB (240,230,140)},
625 {"pale goldenrod" , PALETTERGB (238,232,170)},
626 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
627 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
628 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
629 {"light yellow" , PALETTERGB (255,255,224)},
630 {"LightYellow" , PALETTERGB (255,255,224)},
631 {"yellow" , PALETTERGB (255,255, 0)},
632 {"gold" , PALETTERGB (255,215, 0)},
633 {"light goldenrod" , PALETTERGB (238,221,130)},
634 {"LightGoldenrod" , PALETTERGB (238,221,130)},
635 {"goldenrod" , PALETTERGB (218,165, 32)},
636 {"dark goldenrod" , PALETTERGB (184,134, 11)},
637 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
638 {"rosy brown" , PALETTERGB (188,143,143)},
639 {"RosyBrown" , PALETTERGB (188,143,143)},
640 {"indian red" , PALETTERGB (205, 92, 92)},
641 {"IndianRed" , PALETTERGB (205, 92, 92)},
642 {"saddle brown" , PALETTERGB (139, 69, 19)},
643 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
644 {"sienna" , PALETTERGB (160, 82, 45)},
645 {"peru" , PALETTERGB (205,133, 63)},
646 {"burlywood" , PALETTERGB (222,184,135)},
647 {"beige" , PALETTERGB (245,245,220)},
648 {"wheat" , PALETTERGB (245,222,179)},
649 {"sandy brown" , PALETTERGB (244,164, 96)},
650 {"SandyBrown" , PALETTERGB (244,164, 96)},
651 {"tan" , PALETTERGB (210,180,140)},
652 {"chocolate" , PALETTERGB (210,105, 30)},
653 {"firebrick" , PALETTERGB (178,34, 34)},
654 {"brown" , PALETTERGB (165,42, 42)},
655 {"dark salmon" , PALETTERGB (233,150,122)},
656 {"DarkSalmon" , PALETTERGB (233,150,122)},
657 {"salmon" , PALETTERGB (250,128,114)},
658 {"light salmon" , PALETTERGB (255,160,122)},
659 {"LightSalmon" , PALETTERGB (255,160,122)},
660 {"orange" , PALETTERGB (255,165, 0)},
661 {"dark orange" , PALETTERGB (255,140, 0)},
662 {"DarkOrange" , PALETTERGB (255,140, 0)},
663 {"coral" , PALETTERGB (255,127, 80)},
664 {"light coral" , PALETTERGB (240,128,128)},
665 {"LightCoral" , PALETTERGB (240,128,128)},
666 {"tomato" , PALETTERGB (255, 99, 71)},
667 {"orange red" , PALETTERGB (255, 69, 0)},
668 {"OrangeRed" , PALETTERGB (255, 69, 0)},
669 {"red" , PALETTERGB (255, 0, 0)},
670 {"hot pink" , PALETTERGB (255,105,180)},
671 {"HotPink" , PALETTERGB (255,105,180)},
672 {"deep pink" , PALETTERGB (255, 20,147)},
673 {"DeepPink" , PALETTERGB (255, 20,147)},
674 {"pink" , PALETTERGB (255,192,203)},
675 {"light pink" , PALETTERGB (255,182,193)},
676 {"LightPink" , PALETTERGB (255,182,193)},
677 {"pale violet red" , PALETTERGB (219,112,147)},
678 {"PaleVioletRed" , PALETTERGB (219,112,147)},
679 {"maroon" , PALETTERGB (176, 48, 96)},
680 {"medium violet red" , PALETTERGB (199, 21,133)},
681 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
682 {"violet red" , PALETTERGB (208, 32,144)},
683 {"VioletRed" , PALETTERGB (208, 32,144)},
684 {"magenta" , PALETTERGB (255, 0,255)},
685 {"violet" , PALETTERGB (238,130,238)},
686 {"plum" , PALETTERGB (221,160,221)},
687 {"orchid" , PALETTERGB (218,112,214)},
688 {"medium orchid" , PALETTERGB (186, 85,211)},
689 {"MediumOrchid" , PALETTERGB (186, 85,211)},
690 {"dark orchid" , PALETTERGB (153, 50,204)},
691 {"DarkOrchid" , PALETTERGB (153, 50,204)},
692 {"dark violet" , PALETTERGB (148, 0,211)},
693 {"DarkViolet" , PALETTERGB (148, 0,211)},
694 {"blue violet" , PALETTERGB (138, 43,226)},
695 {"BlueViolet" , PALETTERGB (138, 43,226)},
696 {"purple" , PALETTERGB (160, 32,240)},
697 {"medium purple" , PALETTERGB (147,112,219)},
698 {"MediumPurple" , PALETTERGB (147,112,219)},
699 {"thistle" , PALETTERGB (216,191,216)},
700 {"gray0" , PALETTERGB ( 0, 0, 0)},
701 {"grey0" , PALETTERGB ( 0, 0, 0)},
702 {"dark grey" , PALETTERGB (169,169,169)},
703 {"DarkGrey" , PALETTERGB (169,169,169)},
704 {"dark gray" , PALETTERGB (169,169,169)},
705 {"DarkGray" , PALETTERGB (169,169,169)},
706 {"dark blue" , PALETTERGB ( 0, 0,139)},
707 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
708 {"dark cyan" , PALETTERGB ( 0,139,139)},
709 {"DarkCyan" , PALETTERGB ( 0,139,139)},
710 {"dark magenta" , PALETTERGB (139, 0,139)},
711 {"DarkMagenta" , PALETTERGB (139, 0,139)},
712 {"dark red" , PALETTERGB (139, 0, 0)},
713 {"DarkRed" , PALETTERGB (139, 0, 0)},
714 {"light green" , PALETTERGB (144,238,144)},
715 {"LightGreen" , PALETTERGB (144,238,144)},
719 w32_default_color_map (void)
722 colormap_t
*pc
= w32_color_map
;
729 for (i
= 0; i
< ARRAYELTS (w32_color_map
); pc
++, i
++)
730 cmap
= Fcons (Fcons (build_string (pc
->name
),
731 make_number (pc
->colorref
)),
739 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
740 0, 0, 0, doc
: /* Return the default color map. */)
743 return w32_default_color_map ();
747 w32_color_map_lookup (const char *colorname
)
749 Lisp_Object tail
, ret
= Qnil
;
753 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
755 register Lisp_Object elt
, tem
;
758 if (!CONSP (elt
)) continue;
762 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
778 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
782 /* Other registry operations are done with input blocked. */
785 /* Look for "Control Panel/Colors" under User and Machine registry
787 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
788 KEY_READ
, &colors_key
) == ERROR_SUCCESS
789 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
790 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
793 char color_buffer
[64];
794 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
796 DWORD name_size
, color_size
;
797 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
799 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
800 color_size
= sizeof (color_buffer
);
802 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
804 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
805 NULL
, NULL
, color_buffer
, &color_size
)
809 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
810 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
811 make_number (RGB (r
, g
, b
))),
814 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
815 color_size
= sizeof (color_buffer
);
818 RegCloseKey (colors_key
);
826 x_to_w32_color (const char * colorname
)
828 register Lisp_Object ret
= Qnil
;
832 if (colorname
[0] == '#')
834 /* Could be an old-style RGB Device specification. */
835 int size
= strlen (colorname
+ 1);
836 char *color
= alloca (size
+ 1);
838 strcpy (color
, colorname
+ 1);
839 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
847 for (i
= 0; i
< 3; i
++)
853 /* The check for 'x' in the following conditional takes into
854 account the fact that strtol allows a "0x" in front of
855 our numbers, and we don't. */
856 if (!isxdigit (color
[0]) || color
[1] == 'x')
860 value
= strtoul (color
, &end
, 16);
862 if (errno
== ERANGE
|| end
- color
!= size
)
867 value
= value
* 0x10;
878 colorval
|= (value
<< pos
);
883 XSETINT (ret
, colorval
);
890 else if (strnicmp (colorname
, "rgb:", 4) == 0)
898 color
= colorname
+ 4;
899 for (i
= 0; i
< 3; i
++)
904 /* The check for 'x' in the following conditional takes into
905 account the fact that strtol allows a "0x" in front of
906 our numbers, and we don't. */
907 if (!isxdigit (color
[0]) || color
[1] == 'x')
909 value
= strtoul (color
, &end
, 16);
915 value
= value
* 0x10 + value
;
928 if (value
== ULONG_MAX
)
930 colorval
|= (value
<< pos
);
937 XSETINT (ret
, colorval
);
945 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
947 /* This is an RGB Intensity specification. */
954 color
= colorname
+ 5;
955 for (i
= 0; i
< 3; i
++)
961 value
= strtod (color
, &end
);
964 if (value
< 0.0 || value
> 1.0)
966 val
= (UINT
)(0x100 * value
);
967 /* We used 0x100 instead of 0xFF to give a continuous
968 range between 0.0 and 1.0 inclusive. The next statement
969 fixes the 1.0 case. */
972 colorval
|= (val
<< pos
);
979 XSETINT (ret
, colorval
);
987 /* I am not going to attempt to handle any of the CIE color schemes
988 or TekHVC, since I don't know the algorithms for conversion to
991 /* If we fail to lookup the color name in w32_color_map, then check the
992 colorname to see if it can be crudely approximated: If the X color
993 ends in a number (e.g., "darkseagreen2"), strip the number and
994 return the result of looking up the base color name. */
995 ret
= w32_color_map_lookup (colorname
);
998 int len
= strlen (colorname
);
1000 if (isdigit (colorname
[len
- 1]))
1002 char *ptr
, *approx
= alloca (len
+ 1);
1004 strcpy (approx
, colorname
);
1005 ptr
= &approx
[len
- 1];
1006 while (ptr
> approx
&& isdigit (*ptr
))
1009 ret
= w32_color_map_lookup (approx
);
1018 w32_regenerate_palette (struct frame
*f
)
1020 struct w32_palette_entry
* list
;
1021 LOGPALETTE
* log_palette
;
1022 HPALETTE new_palette
;
1025 /* don't bother trying to create palette if not supported */
1026 if (! FRAME_DISPLAY_INFO (f
)->has_palette
)
1029 log_palette
= (LOGPALETTE
*)
1030 alloca (sizeof (LOGPALETTE
) +
1031 FRAME_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1032 log_palette
->palVersion
= 0x300;
1033 log_palette
->palNumEntries
= FRAME_DISPLAY_INFO (f
)->num_colors
;
1035 list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1037 i
< FRAME_DISPLAY_INFO (f
)->num_colors
;
1038 i
++, list
= list
->next
)
1039 log_palette
->palPalEntry
[i
] = list
->entry
;
1041 new_palette
= CreatePalette (log_palette
);
1045 if (FRAME_DISPLAY_INFO (f
)->palette
)
1046 DeleteObject (FRAME_DISPLAY_INFO (f
)->palette
);
1047 FRAME_DISPLAY_INFO (f
)->palette
= new_palette
;
1049 /* Realize display palette and garbage all frames. */
1050 release_frame_dc (f
, get_frame_dc (f
));
1055 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1056 #define SET_W32_COLOR(pe, color) \
1059 pe.peRed = GetRValue (color); \
1060 pe.peGreen = GetGValue (color); \
1061 pe.peBlue = GetBValue (color); \
1066 /* Keep these around in case we ever want to track color usage. */
1068 w32_map_color (struct frame
*f
, COLORREF color
)
1070 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1072 if (NILP (Vw32_enable_palette
))
1075 /* check if color is already mapped */
1078 if (W32_COLOR (list
->entry
) == color
)
1086 /* not already mapped, so add to list and recreate Windows palette */
1087 list
= xmalloc (sizeof (struct w32_palette_entry
));
1088 SET_W32_COLOR (list
->entry
, color
);
1090 list
->next
= FRAME_DISPLAY_INFO (f
)->color_list
;
1091 FRAME_DISPLAY_INFO (f
)->color_list
= list
;
1092 FRAME_DISPLAY_INFO (f
)->num_colors
++;
1094 /* set flag that palette must be regenerated */
1095 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1099 w32_unmap_color (struct frame
*f
, COLORREF color
)
1101 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1102 struct w32_palette_entry
**prev
= &FRAME_DISPLAY_INFO (f
)->color_list
;
1104 if (NILP (Vw32_enable_palette
))
1107 /* check if color is already mapped */
1110 if (W32_COLOR (list
->entry
) == color
)
1112 if (--list
->refcount
== 0)
1116 FRAME_DISPLAY_INFO (f
)->num_colors
--;
1126 /* set flag that palette must be regenerated */
1127 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1132 /* Gamma-correct COLOR on frame F. */
1135 gamma_correct (struct frame
*f
, COLORREF
*color
)
1139 *color
= PALETTERGB (
1140 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1141 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1142 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1147 /* Decide if color named COLOR is valid for the display associated with
1148 the selected frame; if so, return the rgb values in COLOR_DEF.
1149 If ALLOC is nonzero, allocate a new colormap cell. */
1152 w32_defined_color (struct frame
*f
, const char *color
, XColor
*color_def
,
1155 register Lisp_Object tem
;
1156 COLORREF w32_color_ref
;
1158 tem
= x_to_w32_color (color
);
1164 /* Apply gamma correction. */
1165 w32_color_ref
= XUINT (tem
);
1166 gamma_correct (f
, &w32_color_ref
);
1167 XSETINT (tem
, w32_color_ref
);
1170 /* Map this color to the palette if it is enabled. */
1171 if (!NILP (Vw32_enable_palette
))
1173 struct w32_palette_entry
* entry
=
1174 one_w32_display_info
.color_list
;
1175 struct w32_palette_entry
** prev
=
1176 &one_w32_display_info
.color_list
;
1178 /* check if color is already mapped */
1181 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1183 prev
= &entry
->next
;
1184 entry
= entry
->next
;
1187 if (entry
== NULL
&& alloc_p
)
1189 /* not already mapped, so add to list */
1190 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1191 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1194 one_w32_display_info
.num_colors
++;
1196 /* set flag that palette must be regenerated */
1197 one_w32_display_info
.regen_palette
= TRUE
;
1200 /* Ensure COLORREF value is snapped to nearest color in (default)
1201 palette by simulating the PALETTERGB macro. This works whether
1202 or not the display device has a palette. */
1203 w32_color_ref
= XUINT (tem
) | 0x2000000;
1205 color_def
->pixel
= w32_color_ref
;
1206 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1207 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1208 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1218 /* Given a string ARG naming a color, compute a pixel value from it
1219 suitable for screen F.
1220 If F is not a color screen, return DEF (default) regardless of what
1224 x_decode_color (struct frame
*f
, Lisp_Object arg
, int def
)
1230 if (strcmp (SDATA (arg
), "black") == 0)
1231 return BLACK_PIX_DEFAULT (f
);
1232 else if (strcmp (SDATA (arg
), "white") == 0)
1233 return WHITE_PIX_DEFAULT (f
);
1235 if ((FRAME_DISPLAY_INFO (f
)->n_planes
* FRAME_DISPLAY_INFO (f
)->n_cbits
) == 1)
1238 /* w32_defined_color is responsible for coping with failures
1239 by looking for a near-miss. */
1240 if (w32_defined_color (f
, SDATA (arg
), &cdef
, true))
1243 /* defined_color failed; return an ultimate default. */
1249 /* Functions called only from `x_set_frame_param'
1250 to set individual parameters.
1252 If FRAME_W32_WINDOW (f) is 0,
1253 the frame is being created and its window does not exist yet.
1254 In that case, just record the parameter's new value
1255 in the standard place; do not attempt to change the window. */
1258 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1260 struct w32_output
*x
= f
->output_data
.w32
;
1261 PIX_TYPE fg
, old_fg
;
1263 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1264 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1265 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1267 if (FRAME_W32_WINDOW (f
) != 0)
1269 if (x
->cursor_pixel
== old_fg
)
1271 x
->cursor_pixel
= fg
;
1272 x
->cursor_gc
->background
= fg
;
1275 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1276 if (FRAME_VISIBLE_P (f
))
1282 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1284 FRAME_BACKGROUND_PIXEL (f
)
1285 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1287 if (FRAME_W32_WINDOW (f
) != 0)
1289 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1290 FRAME_BACKGROUND_PIXEL (f
));
1292 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1294 if (FRAME_VISIBLE_P (f
))
1300 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1303 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1308 if (!EQ (Qnil
, arg
))
1309 f
->output_data
.w32
->mouse_pixel
1310 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1311 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1313 /* Don't let pointers be invisible. */
1314 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1315 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1316 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1318 #if 0 /* TODO : Mouse cursor customization. */
1321 /* It's not okay to crash if the user selects a screwy cursor. */
1322 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1324 if (!EQ (Qnil
, Vx_pointer_shape
))
1326 CHECK_NUMBER (Vx_pointer_shape
);
1327 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1330 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1331 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1333 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1335 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1336 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1337 XINT (Vx_nontext_pointer_shape
));
1340 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1341 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1343 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1345 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1346 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1347 XINT (Vx_hourglass_pointer_shape
));
1350 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1351 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1353 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1354 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1356 CHECK_NUMBER (Vx_mode_pointer_shape
);
1357 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1358 XINT (Vx_mode_pointer_shape
));
1361 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1362 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1364 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1366 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1368 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1369 XINT (Vx_sensitive_text_pointer_shape
));
1372 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1374 if (!NILP (Vx_window_horizontal_drag_shape
))
1376 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1377 horizontal_drag_cursor
1378 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1379 XINT (Vx_window_horizontal_drag_shape
));
1382 horizontal_drag_cursor
1383 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_h_double_arrow
);
1385 if (!NILP (Vx_window_vertical_drag_shape
))
1387 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
1388 vertical_drag_cursor
1389 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1390 XINT (Vx_window_vertical_drag_shape
));
1393 vertical_drag_cursor
1394 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_v_double_arrow
);
1396 /* Check and report errors with the above calls. */
1397 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1398 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1401 XColor fore_color
, back_color
;
1403 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1404 back_color
.pixel
= mask_color
;
1405 XQueryColor (FRAME_W32_DISPLAY (f
),
1406 DefaultColormap (FRAME_W32_DISPLAY (f
),
1407 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1409 XQueryColor (FRAME_W32_DISPLAY (f
),
1410 DefaultColormap (FRAME_W32_DISPLAY (f
),
1411 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1413 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1414 &fore_color
, &back_color
);
1415 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1416 &fore_color
, &back_color
);
1417 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1418 &fore_color
, &back_color
);
1419 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1420 &fore_color
, &back_color
);
1421 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1422 &fore_color
, &back_color
);
1425 if (FRAME_W32_WINDOW (f
) != 0)
1426 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1428 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1429 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1430 f
->output_data
.w32
->text_cursor
= cursor
;
1432 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1433 && f
->output_data
.w32
->nontext_cursor
!= 0)
1434 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1435 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1437 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1438 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1439 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1440 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1442 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1443 && f
->output_data
.w32
->modeline_cursor
!= 0)
1444 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1445 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1447 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1448 && f
->output_data
.w32
->hand_cursor
!= 0)
1449 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1450 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1452 XFlush (FRAME_W32_DISPLAY (f
));
1455 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1460 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1462 unsigned long fore_pixel
, pixel
;
1464 if (!NILP (Vx_cursor_fore_pixel
))
1465 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1466 WHITE_PIX_DEFAULT (f
));
1468 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1470 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1472 /* Make sure that the cursor color differs from the background color. */
1473 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1475 pixel
= f
->output_data
.w32
->mouse_pixel
;
1476 if (pixel
== fore_pixel
)
1477 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1480 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1481 f
->output_data
.w32
->cursor_pixel
= pixel
;
1483 if (FRAME_W32_WINDOW (f
) != 0)
1486 /* Update frame's cursor_gc. */
1487 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1488 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1492 if (FRAME_VISIBLE_P (f
))
1494 x_update_cursor (f
, 0);
1495 x_update_cursor (f
, 1);
1499 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1502 /* Set the border-color of frame F to pixel value PIX.
1503 Note that this does not fully take effect if done before
1507 x_set_border_pixel (struct frame
*f
, int pix
)
1510 f
->output_data
.w32
->border_pixel
= pix
;
1512 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1514 if (FRAME_VISIBLE_P (f
))
1519 /* Set the border-color of frame F to value described by ARG.
1520 ARG can be a string naming a color.
1521 The border-color is used for the border that is drawn by the server.
1522 Note that this does not fully take effect if done before
1523 F has a window; it must be redone when the window is created. */
1526 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1531 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1532 x_set_border_pixel (f
, pix
);
1533 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1538 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1540 set_frame_cursor_types (f
, arg
);
1544 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1548 if (NILP (arg
) && NILP (oldval
))
1551 if (STRINGP (arg
) && STRINGP (oldval
)
1552 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1555 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1560 result
= x_bitmap_icon (f
, arg
);
1564 error ("No icon window available");
1571 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1575 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1578 else if (!NILP (arg
) || NILP (oldval
))
1581 fset_icon_name (f
, arg
);
1584 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1589 result
= x_text_icon (f
,
1590 SSDATA ((!NILP (f
->icon_name
)
1599 error ("No icon window available");
1602 /* If the window was unmapped (and its icon was mapped),
1603 the new icon is not mapped, so map the window in its stead. */
1604 if (FRAME_VISIBLE_P (f
))
1606 #ifdef USE_X_TOOLKIT
1607 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1609 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1612 XFlush (FRAME_W32_DISPLAY (f
));
1618 x_clear_under_internal_border (struct frame
*f
)
1620 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1622 /* Clear border if it's larger than before. */
1625 HDC hdc
= get_frame_dc (f
);
1626 int width
= FRAME_PIXEL_WIDTH (f
);
1627 int height
= FRAME_PIXEL_HEIGHT (f
);
1630 w32_clear_area (f
, hdc
, 0, FRAME_TOP_MARGIN_HEIGHT (f
), width
, border
);
1631 w32_clear_area (f
, hdc
, 0, 0, border
, height
);
1632 w32_clear_area (f
, hdc
, width
- border
, 0, border
, height
);
1633 w32_clear_area (f
, hdc
, 0, height
- border
, width
, border
);
1634 release_frame_dc (f
, hdc
);
1641 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1645 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1646 border
= max (XINT (arg
), 0);
1648 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1650 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1652 if (FRAME_X_WINDOW (f
) != 0)
1654 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1656 if (FRAME_VISIBLE_P (f
))
1657 x_clear_under_internal_border (f
);
1664 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1668 /* Right now, menu bars don't work properly in minibuf-only frames;
1669 most of the commands try to apply themselves to the minibuffer
1670 frame itself, and get an error because you can't switch buffers
1671 in or split the minibuffer window. */
1672 if (FRAME_MINIBUF_ONLY_P (f
))
1675 if (INTEGERP (value
))
1676 nlines
= XINT (value
);
1680 FRAME_MENU_BAR_LINES (f
) = 0;
1681 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1684 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1685 windows_or_buffers_changed
= 23;
1689 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1690 free_frame_menubar (f
);
1691 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1693 /* Adjust the frame size so that the client (text) dimensions
1694 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1695 set correctly. Note that we resize twice: The first time upon
1696 a request from the window manager who wants to keep the height
1697 of the outer rectangle (including decorations) unchanged, and a
1698 second time because we want to keep the height of the inner
1699 rectangle (without the decorations unchanged). */
1700 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1702 /* Not sure whether this is needed. */
1703 x_clear_under_internal_border (f
);
1708 /* Set the number of lines used for the tool bar of frame F to VALUE.
1709 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL is
1710 the old number of tool bar lines (and is unused). This function may
1711 change the height of all windows on frame F to match the new tool bar
1712 height. By design, the frame's height doesn't change (but maybe it
1713 should if we don't get enough space otherwise). */
1716 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1720 /* Treat tool bars like menu bars. */
1721 if (FRAME_MINIBUF_ONLY_P (f
))
1724 /* Use VALUE only if an integer >= 0. */
1725 if (INTEGERP (value
) && XINT (value
) >= 0)
1726 nlines
= XFASTINT (value
);
1730 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1734 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1736 x_change_tool_bar_height (struct frame
*f
, int height
)
1738 int unit
= FRAME_LINE_HEIGHT (f
);
1739 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1740 int lines
= (height
+ unit
- 1) / unit
;
1741 Lisp_Object fullscreen
;
1743 /* Make sure we redisplay all windows in this frame. */
1744 windows_or_buffers_changed
= 23;
1746 /* Recalculate tool bar and frame text sizes. */
1747 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1748 FRAME_TOOL_BAR_LINES (f
) = lines
;
1749 /* Store `tool-bar-lines' and `height' frame parameters. */
1750 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1751 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1753 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1756 clear_current_matrices (f
);
1759 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1760 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1762 /* Recalculate toolbar height. */
1763 f
->n_tool_bar_rows
= 0;
1765 && (!f
->after_make_frame
1766 || NILP (frame_inhibit_implied_resize
)
1767 || (CONSP (frame_inhibit_implied_resize
)
1768 && NILP (Fmemq (Qtool_bar_lines
, frame_inhibit_implied_resize
)))))
1769 f
->tool_bar_redisplayed
= f
->tool_bar_resized
= false;
1771 adjust_frame_size (f
, -1, -1,
1772 ((!f
->tool_bar_resized
1773 && (NILP (fullscreen
=
1774 get_frame_param (f
, Qfullscreen
))
1775 || EQ (fullscreen
, Qfullwidth
))) ? 1
1776 : (old_height
== 0 || height
== 0) ? 2
1778 false, Qtool_bar_lines
);
1780 f
->tool_bar_resized
= f
->tool_bar_redisplayed
;
1782 /* adjust_frame_size might not have done anything, garbage frame
1784 adjust_frame_glyphs (f
);
1785 SET_FRAME_GARBAGED (f
);
1786 if (FRAME_X_WINDOW (f
))
1787 x_clear_under_internal_border (f
);
1791 w32_set_title_bar_text (struct frame
*f
, Lisp_Object name
)
1793 if (FRAME_W32_WINDOW (f
))
1797 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1798 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1800 /* The frame's title many times shows the name of the file
1801 visited in the selected window's buffer, so it makes sense to
1802 support non-ASCII characters outside of the current system
1803 codepage in the title. */
1804 if (w32_unicode_filenames
)
1806 Lisp_Object encoded_title
= ENCODE_UTF_8 (name
);
1808 int tlen
= pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
),
1813 /* Windows truncates the title text beyond what fits on
1814 a single line, so we can limit the length to some
1815 reasonably large value, and use alloca. */
1818 title_w
= alloca ((tlen
+ 1) * sizeof (wchar_t));
1819 pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
), -1,
1821 title_w
[tlen
] = L
'\0';
1822 SetWindowTextW (FRAME_W32_WINDOW (f
), title_w
);
1824 else /* Conversion to UTF-16 failed, so we punt. */
1825 SetWindowTextA (FRAME_W32_WINDOW (f
),
1826 SSDATA (ENCODE_SYSTEM (name
)));
1829 SetWindowTextA (FRAME_W32_WINDOW (f
), SSDATA (ENCODE_SYSTEM (name
)));
1835 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1838 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1839 name; if NAME is a string, set F's name to NAME and set
1840 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1842 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1843 suggesting a new name, which lisp code should override; if
1844 F->explicit_name is set, ignore the new name; otherwise, set it. */
1847 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1849 /* Make sure that requests from lisp code override requests from
1850 Emacs redisplay code. */
1853 /* If we're switching from explicit to implicit, we had better
1854 update the mode lines and thereby update the title. */
1855 if (f
->explicit_name
&& NILP (name
))
1856 update_mode_lines
= 25;
1858 f
->explicit_name
= ! NILP (name
);
1860 else if (f
->explicit_name
)
1863 /* If NAME is nil, set the name to the w32_id_name. */
1866 /* Check for no change needed in this very common case
1867 before we do any consing. */
1868 if (!strcmp (FRAME_DISPLAY_INFO (f
)->w32_id_name
,
1871 name
= build_string (FRAME_DISPLAY_INFO (f
)->w32_id_name
);
1874 CHECK_STRING (name
);
1876 /* Don't change the name if it's already NAME. */
1877 if (! NILP (Fstring_equal (name
, f
->name
)))
1880 fset_name (f
, name
);
1882 /* For setting the frame title, the title parameter should override
1883 the name parameter. */
1884 if (! NILP (f
->title
))
1887 w32_set_title_bar_text (f
, name
);
1890 /* This function should be called when the user's lisp code has
1891 specified a name for the frame; the name will override any set by the
1894 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1896 x_set_name (f
, arg
, true);
1899 /* This function should be called by Emacs redisplay code to set the
1900 name; names set this way will never override names set by the user's
1903 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1905 x_set_name (f
, arg
, false);
1908 /* Change the title of frame F to NAME.
1909 If NAME is nil, use the frame name as the title. */
1912 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1914 /* Don't change the title if it's already NAME. */
1915 if (EQ (name
, f
->title
))
1918 update_mode_lines
= 26;
1920 fset_title (f
, name
);
1925 w32_set_title_bar_text (f
, name
);
1929 x_set_scroll_bar_default_width (struct frame
*f
)
1931 int unit
= FRAME_COLUMN_WIDTH (f
);
1933 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1934 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
1935 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
1940 x_set_scroll_bar_default_height (struct frame
*f
)
1942 int unit
= FRAME_LINE_HEIGHT (f
);
1944 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
1945 FRAME_CONFIG_SCROLL_BAR_LINES (f
)
1946 = (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) + unit
- 1) / unit
;
1949 /* Subroutines for creating a frame. */
1952 w32_load_cursor (LPCTSTR name
)
1954 /* Try first to load cursor from application resource. */
1955 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1956 name
, IMAGE_CURSOR
, 0, 0,
1957 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1960 /* Then try to load a shared predefined cursor. */
1961 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1962 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1967 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1969 #define INIT_WINDOW_CLASS(WC) \
1970 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1971 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1972 (WC).cbClsExtra = 0; \
1973 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1974 (WC).hInstance = hinst; \
1975 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1976 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1977 (WC).hbrBackground = NULL; \
1978 (WC).lpszMenuName = NULL; \
1981 w32_init_class (HINSTANCE hinst
)
1983 if (w32_unicode_gui
)
1986 INIT_WINDOW_CLASS(uwc
);
1987 uwc
.lpszClassName
= L
"Emacs";
1989 return RegisterClassW (&uwc
);
1994 INIT_WINDOW_CLASS(wc
);
1995 wc
.lpszClassName
= EMACS_CLASS
;
1997 return RegisterClassA (&wc
);
2002 w32_createvscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
2004 return CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
2005 /* Position and size of scroll bar. */
2006 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
2007 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
2011 w32_createhscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
2013 return CreateWindow ("SCROLLBAR", "", SBS_HORZ
| WS_CHILD
| WS_VISIBLE
,
2014 /* Position and size of scroll bar. */
2015 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
2016 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
2020 w32_createwindow (struct frame
*f
, int *coords
)
2027 rect
.left
= rect
.top
= 0;
2028 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2029 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2031 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2032 FRAME_EXTERNAL_MENU_BAR (f
));
2034 /* Do first time app init */
2036 w32_init_class (hinst
);
2038 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2049 FRAME_W32_WINDOW (f
) = hwnd
2050 = CreateWindow (EMACS_CLASS
,
2052 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2054 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2062 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2063 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2064 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2065 SetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
2066 SetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_HEIGHT (f
));
2067 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2069 /* Enable drag-n-drop. */
2070 DragAcceptFiles (hwnd
, TRUE
);
2072 /* Do this to discard the default setting specified by our parent. */
2073 ShowWindow (hwnd
, SW_HIDE
);
2075 /* Update frame positions. */
2076 GetWindowRect (hwnd
, &rect
);
2077 f
->left_pos
= rect
.left
;
2078 f
->top_pos
= rect
.top
;
2083 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2085 wmsg
->msg
.hwnd
= hwnd
;
2086 wmsg
->msg
.message
= msg
;
2087 wmsg
->msg
.wParam
= wParam
;
2088 wmsg
->msg
.lParam
= lParam
;
2089 wmsg
->msg
.time
= GetMessageTime ();
2094 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2095 between left and right keys as advertised. We test for this
2096 support dynamically, and set a flag when the support is absent. If
2097 absent, we keep track of the left and right control and alt keys
2098 ourselves. This is particularly necessary on keyboards that rely
2099 upon the AltGr key, which is represented as having the left control
2100 and right alt keys pressed. For these keyboards, we need to know
2101 when the left alt key has been pressed in addition to the AltGr key
2102 so that we can properly support M-AltGr-key sequences (such as M-@
2103 on Swedish keyboards). */
2105 #define EMACS_LCONTROL 0
2106 #define EMACS_RCONTROL 1
2107 #define EMACS_LMENU 2
2108 #define EMACS_RMENU 3
2110 static int modifiers
[4];
2111 static int modifiers_recorded
;
2112 static int modifier_key_support_tested
;
2115 test_modifier_support (unsigned int wparam
)
2119 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2121 if (wparam
== VK_CONTROL
)
2131 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2132 modifiers_recorded
= 1;
2134 modifiers_recorded
= 0;
2135 modifier_key_support_tested
= 1;
2139 record_keydown (unsigned int wparam
, unsigned int lparam
)
2143 if (!modifier_key_support_tested
)
2144 test_modifier_support (wparam
);
2146 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2149 if (wparam
== VK_CONTROL
)
2150 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2152 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2158 record_keyup (unsigned int wparam
, unsigned int lparam
)
2162 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2165 if (wparam
== VK_CONTROL
)
2166 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2168 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2173 /* Emacs can lose focus while a modifier key has been pressed. When
2174 it regains focus, be conservative and clear all modifiers since
2175 we cannot reconstruct the left and right modifier state. */
2177 reset_modifiers (void)
2181 if (GetFocus () == NULL
)
2182 /* Emacs doesn't have keyboard focus. Do nothing. */
2185 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2186 alt
= GetAsyncKeyState (VK_MENU
);
2188 if (!(ctrl
& 0x08000))
2189 /* Clear any recorded control modifier state. */
2190 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2192 if (!(alt
& 0x08000))
2193 /* Clear any recorded alt modifier state. */
2194 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2196 /* Update the state of all modifier keys, because modifiers used in
2197 hot-key combinations can get stuck on if Emacs loses focus as a
2198 result of a hot-key being pressed. */
2202 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2204 memset (keystate
, 0, sizeof (keystate
));
2205 GetKeyboardState (keystate
);
2206 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2207 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2208 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2209 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2210 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2211 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2212 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2213 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2214 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2215 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2216 SetKeyboardState (keystate
);
2220 /* Synchronize modifier state with what is reported with the current
2221 keystroke. Even if we cannot distinguish between left and right
2222 modifier keys, we know that, if no modifiers are set, then neither
2223 the left or right modifier should be set. */
2225 sync_modifiers (void)
2227 if (!modifiers_recorded
)
2230 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2231 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2233 if (!(GetKeyState (VK_MENU
) & 0x8000))
2234 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2238 modifier_set (int vkey
)
2240 /* Warning: The fact that VK_NUMLOCK is not treated as the other 2
2241 toggle keys is not an omission! If you want to add it, you will
2242 have to make changes in the default sub-case of the WM_KEYDOWN
2243 switch, because if the NUMLOCK modifier is set, the code there
2244 will directly convert any key that looks like an ASCII letter,
2245 and also downcase those that look like upper-case ASCII. */
2246 if (vkey
== VK_CAPITAL
)
2248 if (NILP (Vw32_enable_caps_lock
))
2251 return (GetKeyState (vkey
) & 0x1);
2253 if (vkey
== VK_SCROLL
)
2255 if (NILP (Vw32_scroll_lock_modifier
)
2256 /* w32-scroll-lock-modifier can be any non-nil value that is
2257 not one of the modifiers, in which case it shall be ignored. */
2258 || !( EQ (Vw32_scroll_lock_modifier
, Qhyper
)
2259 || EQ (Vw32_scroll_lock_modifier
, Qsuper
)
2260 || EQ (Vw32_scroll_lock_modifier
, Qmeta
)
2261 || EQ (Vw32_scroll_lock_modifier
, Qalt
)
2262 || EQ (Vw32_scroll_lock_modifier
, Qcontrol
)
2263 || EQ (Vw32_scroll_lock_modifier
, Qshift
)))
2266 return (GetKeyState (vkey
) & 0x1);
2269 if (!modifiers_recorded
)
2270 return (GetKeyState (vkey
) & 0x8000);
2275 return modifiers
[EMACS_LCONTROL
];
2277 return modifiers
[EMACS_RCONTROL
];
2279 return modifiers
[EMACS_LMENU
];
2281 return modifiers
[EMACS_RMENU
];
2283 return (GetKeyState (vkey
) & 0x8000);
2286 /* Convert between the modifier bits W32 uses and the modifier bits
2290 w32_key_to_modifier (int key
)
2292 Lisp_Object key_mapping
;
2297 key_mapping
= Vw32_lwindow_modifier
;
2300 key_mapping
= Vw32_rwindow_modifier
;
2303 key_mapping
= Vw32_apps_modifier
;
2306 key_mapping
= Vw32_scroll_lock_modifier
;
2312 /* NB. This code runs in the input thread, asynchronously to the lisp
2313 thread, so we must be careful to ensure access to lisp data is
2314 thread-safe. The following code is safe because the modifier
2315 variable values are updated atomically from lisp and symbols are
2316 not relocated by GC. Also, we don't have to worry about seeing GC
2318 if (EQ (key_mapping
, Qhyper
))
2319 return hyper_modifier
;
2320 if (EQ (key_mapping
, Qsuper
))
2321 return super_modifier
;
2322 if (EQ (key_mapping
, Qmeta
))
2323 return meta_modifier
;
2324 if (EQ (key_mapping
, Qalt
))
2325 return alt_modifier
;
2326 if (EQ (key_mapping
, Qctrl
))
2327 return ctrl_modifier
;
2328 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2329 return ctrl_modifier
;
2330 if (EQ (key_mapping
, Qshift
))
2331 return shift_modifier
;
2333 /* Don't generate any modifier if not explicitly requested. */
2338 w32_get_modifiers (void)
2340 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2341 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2342 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2343 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2344 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2345 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2346 (modifier_set (VK_MENU
) ?
2347 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2350 /* We map the VK_* modifiers into console modifier constants
2351 so that we can use the same routines to handle both console
2352 and window input. */
2355 construct_console_modifiers (void)
2360 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2361 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2362 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2363 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2364 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2365 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2366 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2367 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2368 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2369 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2370 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2376 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2380 /* Convert to emacs modifiers. */
2381 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2387 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2389 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2392 if (virt_key
== VK_RETURN
)
2393 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2395 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2396 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2398 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2399 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2401 if (virt_key
== VK_CLEAR
)
2402 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2407 /* List of special key combinations which w32 would normally capture,
2408 but Emacs should grab instead. Not directly visible to lisp, to
2409 simplify synchronization. Each item is an integer encoding a virtual
2410 key code and modifier combination to capture. */
2411 static Lisp_Object w32_grabbed_keys
;
2413 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2414 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2415 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2416 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2418 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2419 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2420 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2422 /* Register hot-keys for reserved key combinations when Emacs has
2423 keyboard focus, since this is the only way Emacs can receive key
2424 combinations like Alt-Tab which are used by the system. */
2427 register_hot_keys (HWND hwnd
)
2429 Lisp_Object keylist
;
2431 /* Use CONSP, since we are called asynchronously. */
2432 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2434 Lisp_Object key
= XCAR (keylist
);
2436 /* Deleted entries get set to nil. */
2437 if (!INTEGERP (key
))
2440 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2441 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2446 unregister_hot_keys (HWND hwnd
)
2448 Lisp_Object keylist
;
2450 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2452 Lisp_Object key
= XCAR (keylist
);
2454 if (!INTEGERP (key
))
2457 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2463 w32_name_of_message (UINT msg
)
2466 static char buf
[64];
2467 static const struct {
2471 #define M(msg) { msg, # msg }
2479 M (WM_EMACS_CREATEWINDOW
),
2481 M (WM_EMACS_CREATEVSCROLLBAR
),
2482 M (WM_EMACS_CREATEHSCROLLBAR
),
2483 M (WM_EMACS_SHOWWINDOW
),
2484 M (WM_EMACS_SETWINDOWPOS
),
2485 M (WM_EMACS_DESTROYWINDOW
),
2486 M (WM_EMACS_TRACKPOPUPMENU
),
2487 M (WM_EMACS_SETFOCUS
),
2488 M (WM_EMACS_SETFOREGROUND
),
2489 M (WM_EMACS_SETLOCALE
),
2490 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2491 M (WM_EMACS_REGISTER_HOT_KEY
),
2492 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2493 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2494 M (WM_EMACS_TRACK_CARET
),
2495 M (WM_EMACS_DESTROY_CARET
),
2496 M (WM_EMACS_SHOW_CARET
),
2497 M (WM_EMACS_HIDE_CARET
),
2498 M (WM_EMACS_SETCURSOR
),
2499 M (WM_EMACS_SHOWCURSOR
),
2506 for (i
= 0; msgnames
[i
].name
; ++i
)
2507 if (msgnames
[i
].msg
== msg
)
2508 return msgnames
[i
].name
;
2510 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2513 #endif /* EMACSDEBUG */
2515 /* Here's an overview of how Emacs input works in GUI sessions on
2516 MS-Windows. (For description of non-GUI input, see the commentary
2517 before w32_console_read_socket in w32inevt.c.)
2519 System messages are read and processed by w32_msg_pump below. This
2520 function runs in a separate thread. It handles a small number of
2521 custom WM_EMACS_* messages (posted by the main thread, look for
2522 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2523 is the main window procedure for the entire Emacs application.
2525 w32_wnd_proc also runs in the same separate input thread. It
2526 handles some messages, mostly those that need GDI calls, by itself.
2527 For the others, it calls my_post_msg, which inserts the messages
2528 into the input queue serviced by w32_read_socket.
2530 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2531 called synchronously from keyboard.c when it is known or suspected
2532 that some input is available. w32_read_socket either handles
2533 messages immediately, or converts them into Emacs input events and
2534 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2535 them and process them when read_char and its callers require
2538 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2539 select(2) takes the place of w32_read_socket.
2543 /* Main message dispatch loop. */
2546 w32_msg_pump (deferred_msg
* msg_buf
)
2552 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2554 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2557 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2558 /* w32_name_of_message (msg.message), msg.time)); */
2560 if (msg
.hwnd
== NULL
)
2562 switch (msg
.message
)
2565 /* Produced by complete_deferred_msg; just ignore. */
2567 case WM_EMACS_CREATEWINDOW
:
2568 /* Initialize COM for this window. Even though we don't use it,
2569 some third party shell extensions can cause it to be used in
2570 system dialogs, which causes a crash if it is not initialized.
2571 This is a known bug in Windows, which was fixed long ago, but
2572 the patch for XP is not publicly available until XP SP3,
2573 and older versions will never be patched. */
2574 CoInitialize (NULL
);
2575 w32_createwindow ((struct frame
*) msg
.wParam
,
2576 (int *) msg
.lParam
);
2577 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2580 case WM_EMACS_SETLOCALE
:
2581 SetThreadLocale (msg
.wParam
);
2582 /* Reply is not expected. */
2584 case WM_EMACS_SETKEYBOARDLAYOUT
:
2585 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2586 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2590 case WM_EMACS_REGISTER_HOT_KEY
:
2591 focus_window
= GetFocus ();
2592 if (focus_window
!= NULL
)
2593 RegisterHotKey (focus_window
,
2594 RAW_HOTKEY_ID (msg
.wParam
),
2595 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2596 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2597 /* Reply is not expected. */
2599 case WM_EMACS_UNREGISTER_HOT_KEY
:
2600 focus_window
= GetFocus ();
2601 if (focus_window
!= NULL
)
2602 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2603 /* Mark item as erased. NB: this code must be
2604 thread-safe. The next line is okay because the cons
2605 cell is never made into garbage and is not relocated by
2607 XSETCAR (make_lisp_ptr ((void *)msg
.lParam
, Lisp_Cons
), Qnil
);
2608 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2611 case WM_EMACS_TOGGLE_LOCK_KEY
:
2613 int vk_code
= (int) msg
.wParam
;
2614 int cur_state
= (GetKeyState (vk_code
) & 1);
2615 int new_state
= msg
.lParam
;
2618 || ((new_state
& 1) != cur_state
))
2620 one_w32_display_info
.faked_key
= vk_code
;
2622 keybd_event ((BYTE
) vk_code
,
2623 (BYTE
) MapVirtualKey (vk_code
, 0),
2624 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2625 keybd_event ((BYTE
) vk_code
,
2626 (BYTE
) MapVirtualKey (vk_code
, 0),
2627 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2628 keybd_event ((BYTE
) vk_code
,
2629 (BYTE
) MapVirtualKey (vk_code
, 0),
2630 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2631 cur_state
= !cur_state
;
2633 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2639 /* Broadcast messages make it here, so you need to be looking
2640 for something in particular for this to be useful. */
2642 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2648 if (w32_unicode_gui
)
2649 DispatchMessageW (&msg
);
2651 DispatchMessageA (&msg
);
2654 /* Exit nested loop when our deferred message has completed. */
2655 if (msg_buf
->completed
)
2660 deferred_msg
* deferred_msg_head
;
2662 static deferred_msg
*
2663 find_deferred_msg (HWND hwnd
, UINT msg
)
2665 deferred_msg
* item
;
2667 /* Don't actually need synchronization for read access, since
2668 modification of single pointer is always atomic. */
2669 /* enter_crit (); */
2671 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2672 if (item
->w32msg
.msg
.hwnd
== hwnd
2673 && item
->w32msg
.msg
.message
== msg
)
2676 /* leave_crit (); */
2682 send_deferred_msg (deferred_msg
* msg_buf
,
2688 /* Only input thread can send deferred messages. */
2689 if (GetCurrentThreadId () != dwWindowsThreadId
)
2692 /* It is an error to send a message that is already deferred. */
2693 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2696 /* Enforced synchronization is not needed because this is the only
2697 function that alters deferred_msg_head, and the following critical
2698 section is guaranteed to only be serially reentered (since only the
2699 input thread can call us). */
2701 /* enter_crit (); */
2703 msg_buf
->completed
= 0;
2704 msg_buf
->next
= deferred_msg_head
;
2705 deferred_msg_head
= msg_buf
;
2706 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2708 /* leave_crit (); */
2710 /* Start a new nested message loop to process other messages until
2711 this one is completed. */
2712 w32_msg_pump (msg_buf
);
2714 deferred_msg_head
= msg_buf
->next
;
2716 return msg_buf
->result
;
2720 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2722 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2724 if (msg_buf
== NULL
)
2725 /* Message may have been canceled, so don't abort. */
2728 msg_buf
->result
= result
;
2729 msg_buf
->completed
= 1;
2731 /* Ensure input thread is woken so it notices the completion. */
2732 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2736 cancel_all_deferred_msgs (void)
2738 deferred_msg
* item
;
2740 /* Don't actually need synchronization for read access, since
2741 modification of single pointer is always atomic. */
2742 /* enter_crit (); */
2744 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2747 item
->completed
= 1;
2750 /* leave_crit (); */
2752 /* Ensure input thread is woken so it notices the completion. */
2753 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2757 w32_msg_worker (void *arg
)
2760 deferred_msg dummy_buf
;
2762 /* Ensure our message queue is created */
2764 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2766 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2769 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2770 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2771 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2773 /* This is the initial message loop which should only exit when the
2774 application quits. */
2775 w32_msg_pump (&dummy_buf
);
2781 signal_user_input (void)
2783 /* Interrupt any lisp that wants to be interrupted by input. */
2784 if (!NILP (Vthrow_on_input
))
2786 Vquit_flag
= Vthrow_on_input
;
2787 /* Doing a QUIT from this thread is a bad idea, since this
2788 unwinds the stack of the Lisp thread, and the Windows runtime
2789 rightfully barfs. Disabled. */
2791 /* If we're inside a function that wants immediate quits,
2793 if (immediate_quit
&& NILP (Vinhibit_quit
))
2804 post_character_message (HWND hwnd
, UINT msg
,
2805 WPARAM wParam
, LPARAM lParam
,
2810 wmsg
.dwModifiers
= modifiers
;
2812 /* Detect quit_char and set quit-flag directly. Note that we
2813 still need to post a message to ensure the main thread will be
2814 woken up if blocked in sys_select, but we do NOT want to post
2815 the quit_char message itself (because it will usually be as if
2816 the user had typed quit_char twice). Instead, we post a dummy
2817 message that has no particular effect. */
2820 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2821 c
= make_ctrl_char (c
) & 0377;
2823 || (wmsg
.dwModifiers
== 0
2824 && w32_quit_key
&& wParam
== w32_quit_key
))
2828 /* The choice of message is somewhat arbitrary, as long as
2829 the main thread handler just ignores it. */
2832 /* Interrupt any blocking system calls. */
2835 /* As a safety precaution, forcibly complete any deferred
2836 messages. This is a kludge, but I don't see any particularly
2837 clean way to handle the situation where a deferred message is
2838 "dropped" in the lisp thread, and will thus never be
2839 completed, eg. by the user trying to activate the menubar
2840 when the lisp thread is busy, and then typing C-g when the
2841 menubar doesn't open promptly (with the result that the
2842 menubar never responds at all because the deferred
2843 WM_INITMENU message is never completed). Another problem
2844 situation is when the lisp thread calls SendMessage (to send
2845 a window manager command) when a message has been deferred;
2846 the lisp thread gets blocked indefinitely waiting for the
2847 deferred message to be completed, which itself is waiting for
2848 the lisp thread to respond.
2850 Note that we don't want to block the input thread waiting for
2851 a response from the lisp thread (although that would at least
2852 solve the deadlock problem above), because we want to be able
2853 to receive C-g to interrupt the lisp thread. */
2854 cancel_all_deferred_msgs ();
2857 signal_user_input ();
2860 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2864 get_wm_chars (HWND aWnd
, int *buf
, int buflen
, int ignore_ctrl
, int ctrl
,
2865 int *ctrl_cnt
, int *is_dead
, int vk
, int exp
)
2868 /* If doubled is at the end, ignore it. */
2869 int i
= buflen
, doubled
= 0, code_unit
;
2875 eassert (w32_unicode_gui
);
2877 /* Should be called only when w32_unicode_gui: */
2878 && PeekMessageW (&msg
, aWnd
, WM_KEYFIRST
, WM_KEYLAST
,
2879 PM_NOREMOVE
| PM_NOYIELD
)
2880 && (msg
.message
== WM_CHAR
|| msg
.message
== WM_SYSCHAR
2881 || msg
.message
== WM_DEADCHAR
|| msg
.message
== WM_SYSDEADCHAR
2882 || msg
.message
== WM_UNICHAR
))
2884 /* We extract character payload, but in this call we handle only the
2885 characters which come BEFORE the next keyup/keydown message. */
2888 GetMessageW (&msg
, aWnd
, msg
.message
, msg
.message
);
2889 dead
= (msg
.message
== WM_DEADCHAR
|| msg
.message
== WM_SYSDEADCHAR
);
2891 *is_dead
= (dead
? msg
.wParam
: -1);
2894 code_unit
= msg
.wParam
;
2897 /* Had surrogate. */
2898 if (msg
.message
== WM_UNICHAR
2899 || code_unit
< 0xDC00 || code_unit
> 0xDFFF)
2900 { /* Mismatched first surrogate.
2901 Pass both code units as if they were two characters. */
2904 return i
; /* Drop the 2nd char if at the end of the buffer. */
2906 else /* see https://en.wikipedia.org/wiki/UTF-16 */
2907 code_unit
= (doubled
<< 10) + code_unit
- 0x35FDC00;
2910 else if (code_unit
>= 0xD800 && code_unit
<= 0xDBFF)
2912 /* Handle mismatched 2nd surrogate the same as a normal character. */
2913 doubled
= code_unit
;
2917 /* The only "fake" characters delivered by ToUnicode() or
2918 TranslateMessage() are:
2919 0x01 .. 0x1a for Ctrl-letter, Enter, Tab, Ctrl-Break, Esc, Backspace
2920 0x00 and 0x1b .. 0x1f for Control- []\@^_
2921 0x7f for Control-BackSpace
2922 0x20 for Control-Space */
2924 && (code_unit
< 0x20 || code_unit
== 0x7f
2925 || (code_unit
== 0x20 && ctrl
)))
2927 /* Non-character payload in a WM_CHAR
2928 (Ctrl-something pressed, see above). Ignore, and report. */
2933 /* Traditionally, Emacs would ignore the character payload of VK_NUMPAD*
2934 keys, and would treat them later via `function-key-map'. In addition
2935 to usual 102-key NUMPAD keys, this map also treats `kp-'-variants of
2936 space, tab, enter, separator, equal. TAB and EQUAL, apparently,
2937 cannot be generated on Win-GUI branch. ENTER is already handled
2938 by the code above. According to `lispy_function_keys', kp_space is
2939 generated by not-extended VK_CLEAR. (kp-tab != VK_OEM_NEC_EQUAL!).
2941 We do similarly for backward-compatibility, but ignore only the
2942 characters restorable later by `function-key-map'. */
2943 if (code_unit
< 0x7f
2944 && ((vk
>= VK_NUMPAD0
&& vk
<= VK_DIVIDE
)
2945 || (exp
&& ((vk
>= VK_PRIOR
&& vk
<= VK_DOWN
) ||
2946 vk
== VK_INSERT
|| vk
== VK_DELETE
|| vk
== VK_CLEAR
)))
2947 && strchr ("0123456789/*-+.,", code_unit
))
2956 # define FPRINTF_WM_CHARS(ARG) fprintf ARG
2958 # define FPRINTF_WM_CHARS(ARG) 0
2961 /* This is a heuristic only. This is supposed to track the state of the
2962 finite automaton in the language environment of Windows.
2964 However, separate windows (if with the same different language
2965 environments!) should have different values. Moreover, switching to a
2966 non-Emacs window with the same language environment, and using (dead)keys
2967 there would change the value stored in the kernel, but not this value. */
2968 /* A layout may emit deadkey=0. It looks like this would reset the state
2969 of the kernel's finite automaton (equivalent to emiting 0-length string,
2970 which is otherwise impossible in the dead-key map of a layout).
2971 Be ready to treat the case when this delivers WM_(SYS)DEADCHAR. */
2972 static int after_deadkey
= -1;
2975 deliver_wm_chars (int do_translate
, HWND hwnd
, UINT msg
, UINT wParam
,
2976 UINT lParam
, int legacy_alt_meta
)
2978 /* An "old style" keyboard description may assign up to 125 UTF-16 code
2979 points to a keypress.
2980 (However, the "old style" TranslateMessage() would deliver at most 16 of
2981 them.) Be on a safe side, and prepare to treat many more. */
2982 int ctrl_cnt
, buf
[1024], count
, is_dead
, after_dead
= (after_deadkey
> 0);
2984 /* Since the keypress processing logic of Windows has a lot of state, it
2985 is important to call TranslateMessage() for every keyup/keydown, AND
2986 do it exactly once. (The actual change of state is done by
2987 ToUnicode[Ex](), which is called by TranslateMessage(). So one can
2988 call ToUnicode[Ex]() instead.)
2990 The "usual" message pump calls TranslateMessage() for EVERY event.
2991 Emacs calls TranslateMessage() very selectively (is it needed for doing
2992 some tricky stuff with Win95??? With newer Windows, selectiveness is,
2993 most probably, not needed -- and harms a lot).
2995 So, with the usual message pump, the following call to TranslateMessage()
2996 is not needed (and is going to be VERY harmful). With Emacs' message
2997 pump, the call is needed. */
3000 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3002 windows_msg
.time
= GetMessageTime ();
3003 TranslateMessage (&windows_msg
);
3005 count
= get_wm_chars (hwnd
, buf
, sizeof (buf
)/sizeof (*buf
), 1,
3006 /* The message may have been synthesized by
3007 who knows what; be conservative. */
3008 modifier_set (VK_LCONTROL
)
3009 || modifier_set (VK_RCONTROL
)
3010 || modifier_set (VK_CONTROL
),
3011 &ctrl_cnt
, &is_dead
, wParam
,
3012 (lParam
& 0x1000000L
) != 0);
3016 DWORD console_modifiers
= construct_console_modifiers ();
3017 int *b
= buf
, strip_ExtraMods
= 1, hairy
= 0;
3018 char *type_CtrlAlt
= NULL
;
3020 /* XXXX In fact, there may be another case when we need to do the same:
3021 What happens if the string defined in the LIGATURES has length
3022 0? Probably, we will get count==0, but the state of the finite
3023 automaton would reset to 0??? */
3026 /* wParam is checked when converting CapsLock to Shift; this is a clone
3027 of w32_get_key_modifiers (). */
3028 wmsg
.dwModifiers
= w32_kbd_mods_to_emacs (console_modifiers
, wParam
);
3030 /* What follows is just heuristics; the correct treatement requires
3031 non-destructive ToUnicode():
3032 http://search.cpan.org/~ilyaz/UI-KeyboardLayout/lib/UI/KeyboardLayout.pm#Can_an_application_on_Windows_accept_keyboard_events?_Part_IV:_application-specific_modifiers
3034 What one needs to find is:
3035 * which of the present modifiers AFFECT the resulting char(s)
3036 (so should be stripped, since their EFFECT is "already
3037 taken into account" in the string in buf), and
3038 * which modifiers are not affecting buf, so should be reported to
3039 the application for further treatment.
3041 Example: assume that we know:
3042 (A) lCtrl+rCtrl+rAlt modifiers with VK_A key produce a Latin "f"
3043 ("may be logical" in JCUKEN-flavored Russian keyboard flavors);
3044 (B) removing any of lCtrl, rCtrl, rAlt changes the produced char;
3045 (C) Win-modifier is not affecting the produced character
3046 (this is the common case: happens with all "standard" layouts).
3048 Suppose the user presses Win+lCtrl+rCtrl+rAlt modifiers with VK_A.
3049 What is the intent of the user? We need to guess the intent to decide
3050 which event to deliver to the application.
3052 This looks like a reasonable logic: since Win- modifier doesn't affect
3053 the output string, the user was pressing Win for SOME OTHER purpose.
3054 So the user wanted to generate Win-SOMETHING event. Now, what is
3055 something? If one takes the mantra that "character payload is more
3056 important than the combination of keypresses which resulted in this
3057 payload", then one should ignore lCtrl+rCtrl+rAlt, ignore VK_A, and
3058 assume that the user wanted to generate Win-f.
3060 Unfortunately, without non-destructive ToUnicode(), checking (B),(C)
3061 is out of question. So we use heuristics (hopefully, covering
3062 99.9999% of cases). */
3064 /* Another thing to watch for is a possibility to use AltGr-* and
3065 Ctrl-Alt-* with different semantic.
3067 Background: the layout defining the KLLF_ALTGR bit are treated
3068 specially by the kernel: when VK_RMENU (=rightAlt, =AltGr) is pressed
3069 (released), a press (release) of VK_LCONTROL is emulated (unless Ctrl
3070 is already down). As a result, any press/release of AltGr is seen
3071 by applications as a press/release of lCtrl AND rAlt. This is
3072 applicable, in particular, to ToUnicode[Ex](). (Keyrepeat is covered
3075 NOTE: it IS possible to see bare rAlt even with KLLF_ALTGR; but this
3076 requires a good finger coordination: doing (physically)
3077 Down-lCtrl Down-rAlt Up-lCtrl Down-a
3078 (doing quick enough, so that key repeat of rAlt [which would
3079 generate new "fake" Down-lCtrl events] does not happens before 'a'
3080 is down) results in no "fake" events, so the application will see
3081 only rAlt down when 'a' is pressed. (However, fake Up-lCtrl WILL
3082 be generated when rAlt goes UP.)
3084 In fact, note also that KLLF_ALTGR does not prohibit construction of
3085 rCtrl-rAlt (just press them in this order!).
3087 Moreover: "traditional" layouts do not define distinct modifier-masks
3088 for VK_LMENU and VK_RMENU (same for VK_L/RCONTROL). Instead, they
3089 rely on the KLLF_ALTGR bit to make the behavior of VK_LMENU and
3090 VK_RMENU distinct. As a corollary, for such layouts, the produced
3091 character is the same for AltGr-* (=rAlt-*) and Ctrl-Alt-* (in any
3092 combination of handedness). For description of masks, see
3094 http://search.cpan.org/~ilyaz/UI-KeyboardLayout/lib/UI/KeyboardLayout.pm#Keyboard_input_on_Windows,_Part_I:_what_is_the_kernel_doing?
3096 By default, Emacs was using these coincidences via the following
3097 heuristics: it was treating:
3098 (*) keypresses with lCtrl-rAlt modifiers as if they are carrying
3099 ONLY the character payload (no matter what the actual keyboard
3100 was defining: if lCtrl-lAlt-b was delivering U+05df=beta, then
3101 Emacs saw [beta]; if lCtrl-lAlt-b was undefined in the layout,
3102 the keypress was completely ignored), and
3103 (*) keypresses with the other combinations of handedness of Ctrl-Alt
3104 modifiers (e.g., lCtrl-lAlt) as if they NEVER carry a character
3105 payload (so they were reported "raw": if lCtrl-lAlt-b was
3106 delivering beta, then Emacs saw event [C-A-b], and not [beta]).
3107 This worked good for "traditional" layouts: users could type both
3108 AltGr-x and Ctrl-Alt-x, and one was a character, another a bindable
3111 However, for layouts which deliver different characters for AltGr-x
3112 and lCtrl-lAlt-x, this scheme makes the latter character unaccessible
3113 in Emacs. While it is easy to access functionality of [C-M-x] in
3114 Emacs by other means (for example, by the `controlify' prefix, or
3115 using lCtrl-rCtrl-x, or rCtrl-rAlt-x [in this order]), missing
3116 characters cannot be reconstructed without a tedious manual work. */
3118 /* These two cases are often going to be distinguishable, since at most
3119 one of these character is defined with KBDCTRL | KBDMENU modifier
3120 bitmap. (This heuristic breaks if both lCtrl-lAlt- AND lCtrl-rAlt-
3121 are translated to modifier bitmaps distinct from KBDCTRL | KBDMENU,
3122 or in the cases when lCtrl-lAlt-* and lCtrl-rAlt-* are generally
3123 different, but lCtrl-lAlt-x and lCtrl-rAlt-x happen to deliver the
3126 So we have 2 chunks of info:
3127 (A) is it lCtrl-rAlt-, or lCtrl-lAlt, or some other combination?
3128 (B) is the delivered character defined with KBDCTRL | KBDMENU bits?
3129 Basing on (A) and (B), we should decide whether to ignore the
3130 delivered character. (Before, Emacs was completely ignoring (B), and
3131 was treating the 3-state of (A) as a bit.) This means that we have 6
3132 bits of customization.
3134 Additionally, a presence of two Ctrl down may be AltGr-rCtrl-. */
3136 /* Strip all non-Shift modifiers if:
3137 - more than one UTF-16 code point delivered (can't call VkKeyScanW ())
3138 - or the character is a result of combining with a prefix key. */
3139 if (!after_dead
&& count
== 1 && *b
< 0x10000)
3141 if (console_modifiers
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
)
3142 && console_modifiers
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
3144 type_CtrlAlt
= "bB"; /* generic bindable Ctrl-Alt- modifiers */
3145 if (console_modifiers
& (LEFT_CTRL_PRESSED
| RIGHT_CTRL_PRESSED
)
3146 == (LEFT_CTRL_PRESSED
| RIGHT_CTRL_PRESSED
))
3148 e.g. AltGr-rCtrl on some layouts (in this order!) */
3149 type_CtrlAlt
= "dD";
3150 else if (console_modifiers
3151 & (LEFT_CTRL_PRESSED
| LEFT_ALT_PRESSED
)
3152 == (LEFT_CTRL_PRESSED
| LEFT_ALT_PRESSED
))
3153 type_CtrlAlt
= "lL"; /* Ctrl-Alt- modifiers on the left */
3154 else if (!NILP (Vw32_recognize_altgr
)
3155 && (console_modifiers
3156 & (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
3157 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
3158 type_CtrlAlt
= "gG"; /* modifiers as in AltGr */
3160 else if (wmsg
.dwModifiers
& (alt_modifier
| meta_modifier
)
3161 || (console_modifiers
3162 & (LEFT_WIN_PRESSED
| RIGHT_WIN_PRESSED
3163 | APPS_PRESSED
| SCROLLLOCK_ON
)))
3165 /* Pure Alt (or combination of Alt, Win, APPS, scrolllock. */
3166 type_CtrlAlt
= "aA";
3170 /* Out of bound bitmap: */
3171 SHORT r
= VkKeyScanW (*b
), bitmap
= 0x1FF;
3173 FPRINTF_WM_CHARS((stderr
, "VkKeyScanW %#06x %#04x\n", (int)r
,
3175 if ((r
& 0xFF) == wParam
)
3176 bitmap
= r
>>8; /* *b is reachable via simple interface */
3177 if (*type_CtrlAlt
== 'a') /* Simple Alt seen */
3179 if ((bitmap
& ~1) == 0) /* 1: KBDSHIFT */
3181 /* In "traditional" layouts, Alt without Ctrl does not
3182 change the delivered character. This detects this
3183 situation; it is safe to report this as Alt-something
3184 -- as opposed to delivering the reported character
3185 without modifiers. */
3187 && *b
> 0x7f && ('A' <= wParam
&& wParam
<= 'Z'))
3188 /* For backward-compatibility with older Emacsen, let
3189 this be processed by another branch below (which
3190 would convert it to Alt-Latin char via wParam). */
3196 /* Check whether the delivered character(s) is accessible via
3197 KBDCTRL | KBDALT ( | KBDSHIFT ) modifier mask (which is 7). */
3198 else if ((bitmap
& ~1) != 6)
3200 /* The character is not accessible via plain Ctrl-Alt(-Shift)
3201 (which is, probably, same as AltGr) modifiers.
3202 Either it was after a prefix key, or is combined with
3203 modifier keys which we don't see, or there is an asymmetry
3204 between left-hand and right-hand modifiers, or other hairy
3208 /* The best solution is to delegate these tough (but rarely
3209 needed) choices to the user. Temporarily (???), it is
3210 implemented as C macros.
3212 Essentially, there are 3 things to do: return 0 (handle to the
3213 legacy processing code [ignoring the character payload]; keep
3214 some modifiers (so that they will be processed by the binding
3215 system [on top of the character payload]; strip modifiers [so
3216 that `self-insert' is going to be triggered with the character
3219 The default below should cover 99.9999% of cases:
3220 (a) strip Alt- in the hairy case only;
3221 (stripping = not ignoring)
3222 (l) for lAlt-lCtrl, ignore the char in simple cases only;
3223 (g) for what looks like AltGr, ignore the modifiers;
3224 (d) for what looks like lCtrl-rCtrl-Alt (probably
3225 AltGr-rCtrl), ignore the character in simple cases only;
3226 (b) for other cases of Ctrl-Alt, ignore the character in
3229 Essentially, in all hairy cases, and in looks-like-AltGr case,
3230 we keep the character, ignoring the modifiers. In all the
3231 other cases, we ignore the delivered character. */
3232 #define S_TYPES_TO_IGNORE_CHARACTER_PAYLOAD "aldb"
3233 #define S_TYPES_TO_REPORT_CHARACTER_PAYLOAD_WITH_MODIFIERS ""
3234 if (strchr (S_TYPES_TO_IGNORE_CHARACTER_PAYLOAD
,
3235 type_CtrlAlt
[hairy
]))
3237 /* If in neither list, report all the modifiers we see COMBINED
3238 WITH the reported character. */
3239 if (strchr (S_TYPES_TO_REPORT_CHARACTER_PAYLOAD_WITH_MODIFIERS
,
3240 type_CtrlAlt
[hairy
]))
3241 strip_ExtraMods
= 0;
3244 if (strip_ExtraMods
)
3245 wmsg
.dwModifiers
= wmsg
.dwModifiers
& shift_modifier
;
3247 signal_user_input ();
3250 FPRINTF_WM_CHARS((stderr
, "unichar %#06x\n", *b
));
3251 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, *b
++, lParam
);
3253 if (!ctrl_cnt
) /* Process ALSO as ctrl */
3256 FPRINTF_WM_CHARS((stderr
, "extra ctrl char\n"));
3259 else if (is_dead
>= 0)
3261 FPRINTF_WM_CHARS((stderr
, "dead %#06x\n", is_dead
));
3262 after_deadkey
= is_dead
;
3268 /* Main window procedure */
3270 static LRESULT CALLBACK
3271 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3274 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
3276 int windows_translate
;
3279 /* Note that it is okay to call x_window_to_frame, even though we are
3280 not running in the main lisp thread, because frame deletion
3281 requires the lisp thread to synchronize with this thread. Thus, if
3282 a frame struct is returned, it can be used without concern that the
3283 lisp thread might make it disappear while we are using it.
3285 NB. Walking the frame list in this thread is safe (as long as
3286 writes of Lisp_Object slots are atomic, which they are on Windows).
3287 Although delete-frame can destructively modify the frame list while
3288 we are walking it, a garbage collection cannot occur until after
3289 delete-frame has synchronized with this thread.
3291 It is also safe to use functions that make GDI calls, such as
3292 w32_clear_rect, because these functions must obtain a DC handle
3293 from the frame struct using get_frame_dc which is thread-aware. */
3298 f
= x_window_to_frame (dpyinfo
, hwnd
);
3301 HDC hdc
= get_frame_dc (f
);
3302 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
3303 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
3304 release_frame_dc (f
, hdc
);
3306 #if defined (W32_DEBUG_DISPLAY)
3307 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
3309 wmsg
.rect
.left
, wmsg
.rect
.top
,
3310 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
3311 #endif /* W32_DEBUG_DISPLAY */
3314 case WM_PALETTECHANGED
:
3315 /* ignore our own changes */
3316 if ((HWND
)wParam
!= hwnd
)
3318 f
= x_window_to_frame (dpyinfo
, hwnd
);
3320 /* get_frame_dc will realize our palette and force all
3321 frames to be redrawn if needed. */
3322 release_frame_dc (f
, get_frame_dc (f
));
3327 PAINTSTRUCT paintStruct
;
3329 memset (&update_rect
, 0, sizeof (update_rect
));
3331 f
= x_window_to_frame (dpyinfo
, hwnd
);
3334 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
3338 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
3339 fails. Apparently this can happen under some
3341 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
3344 BeginPaint (hwnd
, &paintStruct
);
3346 /* The rectangles returned by GetUpdateRect and BeginPaint
3347 do not always match. Play it safe by assuming both areas
3349 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
3351 #if defined (W32_DEBUG_DISPLAY)
3352 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
3354 wmsg
.rect
.left
, wmsg
.rect
.top
,
3355 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
3356 DebPrint ((" [update region is %d,%d-%d,%d]\n",
3357 update_rect
.left
, update_rect
.top
,
3358 update_rect
.right
, update_rect
.bottom
));
3360 EndPaint (hwnd
, &paintStruct
);
3363 /* Change the message type to prevent Windows from
3364 combining WM_PAINT messages in the Lisp thread's queue,
3365 since Windows assumes that each message queue is
3366 dedicated to one frame and does not bother checking
3367 that hwnd matches before combining them. */
3368 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
3373 /* If GetUpdateRect returns 0 (meaning there is no update
3374 region), assume the whole window needs to be repainted. */
3375 GetClientRect (hwnd
, &wmsg
.rect
);
3376 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3380 case WM_INPUTLANGCHANGE
:
3381 /* Inform lisp thread of keyboard layout changes. */
3382 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3384 /* The state of the finite automaton is separate per every input
3385 language environment (so it does not change when one switches
3386 to a different window with the same environment). Moreover,
3387 the experiments show that the state is not remembered when
3388 one switches back to the pre-previous environment. */
3391 /* XXXX??? What follows is a COMPLETE misunderstanding of Windows! */
3393 /* Clear dead keys in the keyboard state; for simplicity only
3394 preserve modifier key states. */
3399 GetKeyboardState (keystate
);
3400 for (i
= 0; i
< 256; i
++)
3417 SetKeyboardState (keystate
);
3422 /* Synchronize hot keys with normal input. */
3423 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
3428 record_keyup (wParam
, lParam
);
3433 /* Ignore keystrokes we fake ourself; see below. */
3434 if (dpyinfo
->faked_key
== wParam
)
3436 dpyinfo
->faked_key
= 0;
3437 /* Make sure TranslateMessage sees them though (as long as
3438 they don't produce WM_CHAR messages). This ensures that
3439 indicator lights are toggled promptly on Windows 9x, for
3441 if (wParam
< 256 && lispy_function_keys
[wParam
])
3443 windows_translate
= 1;
3449 /* Synchronize modifiers with current keystroke. */
3451 record_keydown (wParam
, lParam
);
3452 if (w32_use_fallback_wm_chars_method
)
3453 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
3455 windows_translate
= 0;
3460 if (NILP (Vw32_pass_lwindow_to_system
))
3462 /* Prevent system from acting on keyup (which opens the
3463 Start menu if no other key was pressed) by simulating a
3464 press of Space which we will ignore. */
3465 if (GetAsyncKeyState (wParam
) & 1)
3467 if (NUMBERP (Vw32_phantom_key_code
))
3468 key
= XUINT (Vw32_phantom_key_code
) & 255;
3471 dpyinfo
->faked_key
= key
;
3472 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3475 if (!NILP (Vw32_lwindow_modifier
))
3479 if (NILP (Vw32_pass_rwindow_to_system
))
3481 if (GetAsyncKeyState (wParam
) & 1)
3483 if (NUMBERP (Vw32_phantom_key_code
))
3484 key
= XUINT (Vw32_phantom_key_code
) & 255;
3487 dpyinfo
->faked_key
= key
;
3488 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3491 if (!NILP (Vw32_rwindow_modifier
))
3495 if (!NILP (Vw32_apps_modifier
))
3499 if (NILP (Vw32_pass_alt_to_system
))
3500 /* Prevent DefWindowProc from activating the menu bar if an
3501 Alt key is pressed and released by itself. */
3503 windows_translate
= 1;
3506 /* Decide whether to treat as modifier or function key. */
3507 if (NILP (Vw32_enable_caps_lock
))
3508 goto disable_lock_key
;
3509 windows_translate
= 1;
3512 /* Decide whether to treat as modifier or function key. */
3513 if (NILP (Vw32_enable_num_lock
))
3514 goto disable_lock_key
;
3515 windows_translate
= 1;
3518 /* Decide whether to treat as modifier or function key. */
3519 if (NILP (Vw32_scroll_lock_modifier
))
3520 goto disable_lock_key
;
3521 windows_translate
= 1;
3524 /* Ensure the appropriate lock key state (and indicator light)
3525 remains in the same state. We do this by faking another
3526 press of the relevant key. Apparently, this really is the
3527 only way to toggle the state of the indicator lights. */
3528 dpyinfo
->faked_key
= wParam
;
3529 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3530 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3531 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3532 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3533 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3534 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3535 /* Ensure indicator lights are updated promptly on Windows 9x
3536 (TranslateMessage apparently does this), after forwarding
3538 post_character_message (hwnd
, msg
, wParam
, lParam
,
3539 w32_get_key_modifiers (wParam
, lParam
));
3540 windows_translate
= 1;
3544 case VK_PROCESSKEY
: /* Generated by IME. */
3545 windows_translate
= 1;
3548 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3549 which is confusing for purposes of key binding; convert
3550 VK_CANCEL events into VK_PAUSE events. */
3554 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3555 for purposes of key binding; convert these back into
3556 VK_NUMLOCK events, at least when we want to see NumLock key
3557 presses. (Note that there is never any possibility that
3558 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3559 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3560 wParam
= VK_NUMLOCK
;
3563 if (w32_unicode_gui
&& !w32_use_fallback_wm_chars_method
)
3565 /* If this event generates characters or deadkeys, do
3566 not interpret it as a "raw combination of modifiers
3567 and keysym". Hide deadkeys, and use the generated
3568 character(s) instead of the keysym. (Backward
3569 compatibility: exceptions for numpad keys generating
3570 0-9 . , / * - +, and for extra-Alt combined with a
3573 Try to not report modifiers which have effect on
3574 which character or deadkey is generated.
3576 Example (contrived): if rightAlt-? generates f (on a
3577 Cyrillic keyboard layout), and Ctrl, leftAlt do not
3578 affect the generated character, one wants to report
3579 Ctrl-leftAlt-f if the user presses
3580 Ctrl-leftAlt-rightAlt-?. */
3583 /* Some of WM_CHAR may be fed to us directly, some are
3584 results of TranslateMessage(). Using 0 as the first
3585 argument (in a separate call) might help us
3586 distinguish these two cases.
3588 However, the keypress feeders would most probably
3589 expect the "standard" message pump, when
3590 TranslateMessage() is called on EVERY KeyDown/KeyUp
3591 event. So they may feed us Down-Ctrl Down-FAKE
3592 Char-o and expect us to recognize it as Ctrl-o.
3593 Using 0 as the first argument would interfere with
3595 deliver_wm_chars (0, hwnd
, msg
, wParam
, lParam
, 1);
3597 /* Processing the generated WM_CHAR messages *WHILE* we
3598 handle KEYDOWN/UP event is the best choice, since
3599 without any fuss, we know all 3 of: scancode, virtual
3600 keycode, and expansion. (Additionally, one knows
3601 boundaries of expansion of different keypresses.) */
3602 res
= deliver_wm_chars (1, hwnd
, msg
, wParam
, lParam
, 1);
3603 windows_translate
= -(res
!= 0);
3604 if (res
> 0) /* Bound to character(s) or a deadkey */
3606 /* deliver_wm_chars may make some branches after this vestigal. */
3608 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
3609 /* If not defined as a function key, change it to a WM_CHAR message. */
3610 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3612 DWORD modifiers
= construct_console_modifiers ();
3614 if (!NILP (Vw32_recognize_altgr
)
3615 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3617 /* Always let TranslateMessage handle AltGr key chords;
3618 for some reason, ToAscii doesn't always process AltGr
3619 chords correctly. */
3620 windows_translate
= 1;
3622 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3624 /* Handle key chords including any modifiers other
3625 than shift directly, in order to preserve as much
3626 modifier information as possible. */
3627 if ('A' <= wParam
&& wParam
<= 'Z')
3629 /* Don't translate modified alphabetic keystrokes,
3630 so the user doesn't need to constantly switch
3631 layout to type control or meta keystrokes when
3632 the normal layout translates alphabetic
3633 characters to non-ascii characters. */
3634 if (!modifier_set (VK_SHIFT
))
3635 wParam
+= ('a' - 'A');
3640 /* Try to handle other keystrokes by determining the
3641 base character (ie. translating the base key plus
3644 KEY_EVENT_RECORD key
;
3646 key
.bKeyDown
= TRUE
;
3647 key
.wRepeatCount
= 1;
3648 key
.wVirtualKeyCode
= wParam
;
3649 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3650 key
.uChar
.AsciiChar
= 0;
3651 key
.dwControlKeyState
= modifiers
;
3653 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3654 /* 0 means an unrecognized keycode, negative means
3655 dead key. Ignore both. */
3658 /* Forward asciified character sequence. */
3659 post_character_message
3661 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3662 w32_get_key_modifiers (wParam
, lParam
));
3663 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3670 /* Let TranslateMessage handle everything else. */
3671 windows_translate
= 1;
3676 if (windows_translate
== -1)
3679 if (windows_translate
)
3681 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3682 windows_msg
.time
= GetMessageTime ();
3683 TranslateMessage (&windows_msg
);
3695 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3696 signal_user_input ();
3697 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3701 post_character_message (hwnd
, msg
, wParam
, lParam
,
3702 w32_get_key_modifiers (wParam
, lParam
));
3706 /* WM_UNICHAR looks promising from the docs, but the exact
3707 circumstances in which TranslateMessage sends it is one of those
3708 Microsoft secret API things that EU and US courts are supposed
3709 to have put a stop to already. Spy++ shows it being sent to Notepad
3710 and other MS apps, but never to Emacs.
3712 Some third party IMEs send it in accordance with the official
3713 documentation though, so handle it here.
3715 UNICODE_NOCHAR is used to test for support for this message.
3716 TRUE indicates that the message is supported. */
3717 if (wParam
== UNICODE_NOCHAR
)
3722 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3723 signal_user_input ();
3724 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3729 /* If we can't get the IME result as Unicode, use default processing,
3730 which will at least allow characters decodable in the system locale
3732 if (!get_composition_string_fn
)
3735 else if (!ignore_ime_char
)
3740 HIMC context
= get_ime_context_fn (hwnd
);
3741 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3742 /* Get buffer size. */
3743 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3744 buffer
= alloca (size
);
3745 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3747 release_ime_context_fn (hwnd
, context
);
3749 signal_user_input ();
3750 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3752 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3755 /* Ignore the messages for the rest of the
3756 characters in the string that was output above. */
3757 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3764 case WM_IME_STARTCOMPOSITION
:
3765 if (!set_ime_composition_window_fn
)
3769 COMPOSITIONFORM form
;
3773 /* Implementation note: The code below does something that
3774 one shouldn't do: it accesses the window object from a
3775 separate thread, while the main (a.k.a. "Lisp") thread
3776 runs and can legitimately delete and even GC it. That is
3777 why we are extra careful not to futz with a window that
3778 is different from the one recorded when the system caret
3779 coordinates were last modified. That is also why we are
3780 careful not to move the IME window if the window
3781 described by W was deleted, as indicated by its buffer
3782 field being reset to nil. */
3783 f
= x_window_to_frame (dpyinfo
, hwnd
);
3784 if (!(f
&& FRAME_LIVE_P (f
)))
3786 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3787 /* Punt if someone changed the frame's selected window
3789 if (w
!= w32_system_caret_window
)
3792 form
.dwStyle
= CFS_RECT
;
3793 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3794 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3796 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3797 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3798 + w32_system_caret_hdr_height
);
3799 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3800 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3801 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3802 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3803 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
3804 - w32_system_caret_mode_height
);
3806 /* Punt if the window was deleted behind our back. */
3807 if (!BUFFERP (w
->contents
))
3810 context
= get_ime_context_fn (hwnd
);
3815 set_ime_composition_window_fn (context
, &form
);
3816 release_ime_context_fn (hwnd
, context
);
3818 /* We should "goto dflt" here to pass WM_IME_STARTCOMPOSITION to
3819 DefWindowProc, so that the composition window will actually
3820 be displayed. But doing so causes trouble with displaying
3821 dialog boxes, such as the file selection dialog or font
3822 selection dialog. So something else is needed to fix the
3823 former without breaking the latter. See bug#11732. */
3826 case WM_IME_ENDCOMPOSITION
:
3827 ignore_ime_char
= 0;
3830 /* Simulate middle mouse button events when left and right buttons
3831 are used together, but only if user has two button mouse. */
3832 case WM_LBUTTONDOWN
:
3833 case WM_RBUTTONDOWN
:
3834 if (w32_num_mouse_buttons
> 2)
3835 goto handle_plain_button
;
3838 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3839 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3841 if (button_state
& this)
3844 if (button_state
== 0)
3847 button_state
|= this;
3849 if (button_state
& other
)
3851 if (mouse_button_timer
)
3853 KillTimer (hwnd
, mouse_button_timer
);
3854 mouse_button_timer
= 0;
3856 /* Generate middle mouse event instead. */
3857 msg
= WM_MBUTTONDOWN
;
3858 button_state
|= MMOUSE
;
3860 else if (button_state
& MMOUSE
)
3862 /* Ignore button event if we've already generated a
3863 middle mouse down event. This happens if the
3864 user releases and press one of the two buttons
3865 after we've faked a middle mouse event. */
3870 /* Flush out saved message. */
3871 post_msg (&saved_mouse_button_msg
);
3873 wmsg
.dwModifiers
= w32_get_modifiers ();
3874 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3875 signal_user_input ();
3877 /* Clear message buffer. */
3878 saved_mouse_button_msg
.msg
.hwnd
= 0;
3882 /* Hold onto message for now. */
3883 mouse_button_timer
=
3884 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3885 w32_mouse_button_tolerance
, NULL
);
3886 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3887 saved_mouse_button_msg
.msg
.message
= msg
;
3888 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3889 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3890 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3891 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3898 if (w32_num_mouse_buttons
> 2)
3899 goto handle_plain_button
;
3902 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3903 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3905 if ((button_state
& this) == 0)
3908 button_state
&= ~this;
3910 if (button_state
& MMOUSE
)
3912 /* Only generate event when second button is released. */
3913 if ((button_state
& other
) == 0)
3916 button_state
&= ~MMOUSE
;
3918 if (button_state
) emacs_abort ();
3925 /* Flush out saved message if necessary. */
3926 if (saved_mouse_button_msg
.msg
.hwnd
)
3928 post_msg (&saved_mouse_button_msg
);
3931 wmsg
.dwModifiers
= w32_get_modifiers ();
3932 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3933 signal_user_input ();
3935 /* Always clear message buffer and cancel timer. */
3936 saved_mouse_button_msg
.msg
.hwnd
= 0;
3937 KillTimer (hwnd
, mouse_button_timer
);
3938 mouse_button_timer
= 0;
3940 if (button_state
== 0)
3945 case WM_XBUTTONDOWN
:
3947 if (w32_pass_extra_mouse_buttons_to_system
)
3949 /* else fall through and process them. */
3950 case WM_MBUTTONDOWN
:
3952 handle_plain_button
:
3957 /* Ignore middle and extra buttons as long as the menu is active. */
3958 f
= x_window_to_frame (dpyinfo
, hwnd
);
3959 if (f
&& f
->output_data
.w32
->menubar_active
)
3962 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3964 if (up
) ReleaseCapture ();
3965 else SetCapture (hwnd
);
3966 button
= (button
== 0) ? LMOUSE
:
3967 ((button
== 1) ? MMOUSE
: RMOUSE
);
3969 button_state
&= ~button
;
3971 button_state
|= button
;
3975 wmsg
.dwModifiers
= w32_get_modifiers ();
3976 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3977 signal_user_input ();
3979 /* Need to return true for XBUTTON messages, false for others,
3980 to indicate that we processed the message. */
3981 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3984 f
= x_window_to_frame (dpyinfo
, hwnd
);
3987 /* Ignore mouse movements as long as the menu is active.
3988 These movements are processed by the window manager
3989 anyway, and it's wrong to handle them as if they happened
3990 on the underlying frame. */
3991 if (f
->output_data
.w32
->menubar_active
)
3994 /* If the mouse moved, and the mouse pointer is invisible,
3995 make it visible again. We do this here so as to be able
3996 to show the mouse pointer even when the main
3997 (a.k.a. "Lisp") thread is busy doing something. */
3998 static int last_x
, last_y
;
3999 int x
= GET_X_LPARAM (lParam
);
4000 int y
= GET_Y_LPARAM (lParam
);
4002 if (f
->pointer_invisible
4003 && (x
!= last_x
|| y
!= last_y
))
4004 f
->pointer_invisible
= false;
4010 /* If the mouse has just moved into the frame, start tracking
4011 it, so we will be notified when it leaves the frame. Mouse
4012 tracking only works under W98 and NT4 and later. On earlier
4013 versions, there is no way of telling when the mouse leaves the
4014 frame, so we just have to put up with help-echo and mouse
4015 highlighting remaining while the frame is not active. */
4016 if (track_mouse_event_fn
&& !track_mouse_window
4017 /* If the menu bar is active, turning on tracking of mouse
4018 movement events might send these events to the tooltip
4019 frame, if the user happens to move the mouse pointer over
4020 the tooltip. But since we don't process events for
4021 tooltip frames, this causes Windows to present a
4022 hourglass cursor, which is ugly and unexpected. So don't
4023 enable tracking mouse events in this case; they will be
4024 restarted when the menu pops down. (Confusingly, the
4025 menubar_active member of f->output_data.w32, tested
4026 above, is only set when a menu was popped up _not_ from
4027 the frame's menu bar, but via x-popup-menu.) */
4030 TRACKMOUSEEVENT tme
;
4031 tme
.cbSize
= sizeof (tme
);
4032 tme
.dwFlags
= TME_LEAVE
;
4033 tme
.hwndTrack
= hwnd
;
4034 tme
.dwHoverTime
= HOVER_DEFAULT
;
4036 track_mouse_event_fn (&tme
);
4037 track_mouse_window
= hwnd
;
4041 if (w32_mouse_move_interval
<= 0
4042 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4044 wmsg
.dwModifiers
= w32_get_modifiers ();
4045 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4049 /* Hang onto mouse move and scroll messages for a bit, to avoid
4050 sending such events to Emacs faster than it can process them.
4051 If we get more events before the timer from the first message
4052 expires, we just replace the first message. */
4054 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4056 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4057 w32_mouse_move_interval
, NULL
);
4059 /* Hold onto message for now. */
4060 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4061 saved_mouse_move_msg
.msg
.message
= msg
;
4062 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4063 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4064 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4065 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4071 wmsg
.dwModifiers
= w32_get_modifiers ();
4072 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4073 signal_user_input ();
4077 if (w32_pass_multimedia_buttons_to_system
)
4079 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
4080 case WM_MOUSEHWHEEL
:
4081 wmsg
.dwModifiers
= w32_get_modifiers ();
4082 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4083 signal_user_input ();
4084 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
4085 handled, to prevent the system trying to handle it by faking
4086 scroll bar events. */
4090 /* Flush out saved messages if necessary. */
4091 if (wParam
== mouse_button_timer
)
4093 if (saved_mouse_button_msg
.msg
.hwnd
)
4095 post_msg (&saved_mouse_button_msg
);
4096 signal_user_input ();
4097 saved_mouse_button_msg
.msg
.hwnd
= 0;
4099 KillTimer (hwnd
, mouse_button_timer
);
4100 mouse_button_timer
= 0;
4102 else if (wParam
== mouse_move_timer
)
4104 if (saved_mouse_move_msg
.msg
.hwnd
)
4106 post_msg (&saved_mouse_move_msg
);
4107 saved_mouse_move_msg
.msg
.hwnd
= 0;
4109 KillTimer (hwnd
, mouse_move_timer
);
4110 mouse_move_timer
= 0;
4112 else if (wParam
== menu_free_timer
)
4114 KillTimer (hwnd
, menu_free_timer
);
4115 menu_free_timer
= 0;
4116 f
= x_window_to_frame (dpyinfo
, hwnd
);
4117 /* If a popup menu is active, don't wipe its strings. */
4119 && current_popup_menu
== NULL
)
4121 /* Free memory used by owner-drawn and help-echo strings. */
4122 w32_free_menu_strings (hwnd
);
4124 f
->output_data
.w32
->menubar_active
= 0;
4131 /* Windows doesn't send us focus messages when putting up and
4132 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4133 The only indication we get that something happened is receiving
4134 this message afterwards. So this is a good time to reset our
4135 keyboard modifiers' state. */
4142 /* We must ensure menu bar is fully constructed and up to date
4143 before allowing user interaction with it. To achieve this
4144 we send this message to the lisp thread and wait for a
4145 reply (whose value is not actually needed) to indicate that
4146 the menu bar is now ready for use, so we can now return.
4148 To remain responsive in the meantime, we enter a nested message
4149 loop that can process all other messages.
4151 However, we skip all this if the message results from calling
4152 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4153 thread a message because it is blocked on us at this point. We
4154 set menubar_active before calling TrackPopupMenu to indicate
4155 this (there is no possibility of confusion with real menubar
4158 f
= x_window_to_frame (dpyinfo
, hwnd
);
4160 && (f
->output_data
.w32
->menubar_active
4161 /* We can receive this message even in the absence of a
4162 menubar (ie. when the system menu is activated) - in this
4163 case we do NOT want to forward the message, otherwise it
4164 will cause the menubar to suddenly appear when the user
4165 had requested it to be turned off! */
4166 || f
->output_data
.w32
->menubar_widget
== NULL
))
4170 deferred_msg msg_buf
;
4172 /* Detect if message has already been deferred; in this case
4173 we cannot return any sensible value to ignore this. */
4174 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4179 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4182 case WM_EXITMENULOOP
:
4183 f
= x_window_to_frame (dpyinfo
, hwnd
);
4185 /* If a menu is still active, check again after a short delay,
4186 since Windows often (always?) sends the WM_EXITMENULOOP
4187 before the corresponding WM_COMMAND message.
4188 Don't do this if a popup menu is active, since it is only
4189 menubar menus that require cleaning up in this way.
4191 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
4192 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
4194 /* If hourglass cursor should be displayed, display it now. */
4195 if (f
&& f
->output_data
.w32
->hourglass_p
)
4196 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
4201 /* Direct handling of help_echo in menus. Should be safe now
4202 that we generate the help_echo by placing a help event in the
4205 HMENU menu
= (HMENU
) lParam
;
4206 UINT menu_item
= (UINT
) LOWORD (wParam
);
4207 UINT flags
= (UINT
) HIWORD (wParam
);
4209 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
4213 case WM_MEASUREITEM
:
4214 f
= x_window_to_frame (dpyinfo
, hwnd
);
4217 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4219 if (pMis
->CtlType
== ODT_MENU
)
4221 /* Work out dimensions for popup menu titles. */
4222 char * title
= (char *) pMis
->itemData
;
4223 HDC hdc
= GetDC (hwnd
);
4224 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4225 LOGFONT menu_logfont
;
4229 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4230 menu_logfont
.lfWeight
= FW_BOLD
;
4231 menu_font
= CreateFontIndirect (&menu_logfont
);
4232 old_font
= SelectObject (hdc
, menu_font
);
4234 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4237 if (unicode_append_menu
)
4238 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
4239 wcslen ((WCHAR
*) title
),
4242 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4244 pMis
->itemWidth
= size
.cx
;
4245 if (pMis
->itemHeight
< size
.cy
)
4246 pMis
->itemHeight
= size
.cy
;
4249 pMis
->itemWidth
= 0;
4251 SelectObject (hdc
, old_font
);
4252 DeleteObject (menu_font
);
4253 ReleaseDC (hwnd
, hdc
);
4260 f
= x_window_to_frame (dpyinfo
, hwnd
);
4263 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4265 if (pDis
->CtlType
== ODT_MENU
)
4267 /* Draw popup menu title. */
4268 char * title
= (char *) pDis
->itemData
;
4271 HDC hdc
= pDis
->hDC
;
4272 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4273 LOGFONT menu_logfont
;
4276 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4277 menu_logfont
.lfWeight
= FW_BOLD
;
4278 menu_font
= CreateFontIndirect (&menu_logfont
);
4279 old_font
= SelectObject (hdc
, menu_font
);
4281 /* Always draw title as if not selected. */
4282 if (unicode_append_menu
)
4285 + GetSystemMetrics (SM_CXMENUCHECK
),
4287 ETO_OPAQUE
, &pDis
->rcItem
,
4289 wcslen ((WCHAR
*) title
), NULL
);
4293 + GetSystemMetrics (SM_CXMENUCHECK
),
4295 ETO_OPAQUE
, &pDis
->rcItem
,
4296 title
, strlen (title
), NULL
);
4298 SelectObject (hdc
, old_font
);
4299 DeleteObject (menu_font
);
4307 /* Still not right - can't distinguish between clicks in the
4308 client area of the frame from clicks forwarded from the scroll
4309 bars - may have to hook WM_NCHITTEST to remember the mouse
4310 position and then check if it is in the client area ourselves. */
4311 case WM_MOUSEACTIVATE
:
4312 /* Discard the mouse click that activates a frame, allowing the
4313 user to click anywhere without changing point (or worse!).
4314 Don't eat mouse clicks on scrollbars though!! */
4315 if (LOWORD (lParam
) == HTCLIENT
)
4316 return MA_ACTIVATEANDEAT
;
4321 /* No longer tracking mouse. */
4322 track_mouse_window
= NULL
;
4324 case WM_ACTIVATEAPP
:
4326 case WM_WINDOWPOSCHANGED
:
4328 /* Inform lisp thread that a frame might have just been obscured
4329 or exposed, so should recheck visibility of all frames. */
4330 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4334 dpyinfo
->faked_key
= 0;
4336 register_hot_keys (hwnd
);
4339 unregister_hot_keys (hwnd
);
4342 /* Relinquish the system caret. */
4343 if (w32_system_caret_hwnd
)
4345 w32_visible_system_caret_hwnd
= NULL
;
4346 w32_system_caret_hwnd
= NULL
;
4352 f
= x_window_to_frame (dpyinfo
, hwnd
);
4353 if (f
&& HIWORD (wParam
) == 0)
4355 if (menu_free_timer
)
4357 KillTimer (hwnd
, menu_free_timer
);
4358 menu_free_timer
= 0;
4364 wmsg
.dwModifiers
= w32_get_modifiers ();
4365 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4373 wmsg
.dwModifiers
= w32_get_modifiers ();
4374 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4377 case WM_WINDOWPOSCHANGING
:
4378 /* Don't restrict the sizing of any kind of frames. If the window
4379 manager doesn't, there's no reason to do it ourselves. */
4382 case WM_GETMINMAXINFO
:
4383 /* Hack to allow resizing the Emacs frame above the screen size.
4384 Note that Windows 9x limits coordinates to 16-bits. */
4385 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
4386 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
4390 if (LOWORD (lParam
) == HTCLIENT
)
4392 f
= x_window_to_frame (dpyinfo
, hwnd
);
4395 if (f
->output_data
.w32
->hourglass_p
4396 && !menubar_in_use
&& !current_popup_menu
)
4397 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
4398 else if (f
->pointer_invisible
)
4401 SetCursor (f
->output_data
.w32
->current_cursor
);
4408 case WM_EMACS_SETCURSOR
:
4410 Cursor cursor
= (Cursor
) wParam
;
4411 f
= x_window_to_frame (dpyinfo
, hwnd
);
4414 f
->output_data
.w32
->current_cursor
= cursor
;
4415 /* Don't change the cursor while menu-bar menu is in use. */
4416 if (!f
->output_data
.w32
->menubar_active
4417 && !f
->output_data
.w32
->hourglass_p
)
4419 if (f
->pointer_invisible
)
4428 case WM_EMACS_SHOWCURSOR
:
4430 ShowCursor ((BOOL
) wParam
);
4435 case WM_EMACS_CREATEVSCROLLBAR
:
4436 return (LRESULT
) w32_createvscrollbar ((struct frame
*) wParam
,
4437 (struct scroll_bar
*) lParam
);
4439 case WM_EMACS_CREATEHSCROLLBAR
:
4440 return (LRESULT
) w32_createhscrollbar ((struct frame
*) wParam
,
4441 (struct scroll_bar
*) lParam
);
4443 case WM_EMACS_SHOWWINDOW
:
4444 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4446 case WM_EMACS_BRINGTOTOP
:
4447 case WM_EMACS_SETFOREGROUND
:
4449 HWND foreground_window
;
4450 DWORD foreground_thread
, retval
;
4452 /* On NT 5.0, and apparently Windows 98, it is necessary to
4453 attach to the thread that currently has focus in order to
4454 pull the focus away from it. */
4455 foreground_window
= GetForegroundWindow ();
4456 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4457 if (!foreground_window
4458 || foreground_thread
== GetCurrentThreadId ()
4459 || !AttachThreadInput (GetCurrentThreadId (),
4460 foreground_thread
, TRUE
))
4461 foreground_thread
= 0;
4463 retval
= SetForegroundWindow ((HWND
) wParam
);
4464 if (msg
== WM_EMACS_BRINGTOTOP
)
4465 retval
= BringWindowToTop ((HWND
) wParam
);
4467 /* Detach from the previous foreground thread. */
4468 if (foreground_thread
)
4469 AttachThreadInput (GetCurrentThreadId (),
4470 foreground_thread
, FALSE
);
4475 case WM_EMACS_SETWINDOWPOS
:
4477 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4478 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4479 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4482 case WM_EMACS_DESTROYWINDOW
:
4483 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4484 return DestroyWindow ((HWND
) wParam
);
4486 case WM_EMACS_HIDE_CARET
:
4487 return HideCaret (hwnd
);
4489 case WM_EMACS_SHOW_CARET
:
4490 return ShowCaret (hwnd
);
4492 case WM_EMACS_DESTROY_CARET
:
4493 w32_system_caret_hwnd
= NULL
;
4494 w32_visible_system_caret_hwnd
= NULL
;
4495 return DestroyCaret ();
4497 case WM_EMACS_TRACK_CARET
:
4498 /* If there is currently no system caret, create one. */
4499 if (w32_system_caret_hwnd
== NULL
)
4501 /* Use the default caret width, and avoid changing it
4502 unnecessarily, as it confuses screen reader software. */
4503 w32_system_caret_hwnd
= hwnd
;
4504 CreateCaret (hwnd
, NULL
, 0,
4505 w32_system_caret_height
);
4508 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
4510 /* Ensure visible caret gets turned on when requested. */
4511 else if (w32_use_visible_system_caret
4512 && w32_visible_system_caret_hwnd
!= hwnd
)
4514 w32_visible_system_caret_hwnd
= hwnd
;
4515 return ShowCaret (hwnd
);
4517 /* Ensure visible caret gets turned off when requested. */
4518 else if (!w32_use_visible_system_caret
4519 && w32_visible_system_caret_hwnd
)
4521 w32_visible_system_caret_hwnd
= NULL
;
4522 return HideCaret (hwnd
);
4527 case WM_EMACS_TRACKPOPUPMENU
:
4532 pos
= (POINT
*)lParam
;
4533 flags
= TPM_CENTERALIGN
;
4534 if (button_state
& LMOUSE
)
4535 flags
|= TPM_LEFTBUTTON
;
4536 else if (button_state
& RMOUSE
)
4537 flags
|= TPM_RIGHTBUTTON
;
4539 /* Remember we did a SetCapture on the initial mouse down event,
4540 so for safety, we make sure the capture is canceled now. */
4544 /* Use menubar_active to indicate that WM_INITMENU is from
4545 TrackPopupMenu below, and should be ignored. */
4546 f
= x_window_to_frame (dpyinfo
, hwnd
);
4548 f
->output_data
.w32
->menubar_active
= 1;
4550 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4554 /* Eat any mouse messages during popupmenu */
4555 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4557 /* Get the menu selection, if any */
4558 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4560 retval
= LOWORD (amsg
.wParam
);
4574 case WM_EMACS_FILENOTIFY
:
4575 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4579 /* Check for messages registered at runtime. */
4580 if (msg
== msh_mousewheel
)
4582 wmsg
.dwModifiers
= w32_get_modifiers ();
4583 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4584 signal_user_input ();
4589 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
4592 /* The most common default return code for handled messages is 0. */
4597 my_create_window (struct frame
* f
)
4600 static int coords
[2];
4601 Lisp_Object left
, top
;
4602 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4604 /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
4605 anything that is not a number and is not Qunbound. */
4606 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
4607 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
4608 if (EQ (left
, Qunbound
))
4609 coords
[0] = CW_USEDEFAULT
;
4611 coords
[0] = XINT (left
);
4612 if (EQ (top
, Qunbound
))
4613 coords
[1] = CW_USEDEFAULT
;
4615 coords
[1] = XINT (top
);
4617 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
,
4618 (WPARAM
)f
, (LPARAM
)coords
))
4620 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4624 /* Create a tooltip window. Unlike my_create_window, we do not do this
4625 indirectly via the Window thread, as we do not need to process Window
4626 messages for the tooltip. Creating tooltips indirectly also creates
4627 deadlocks when tooltips are created for menu items. */
4629 my_create_tip_window (struct frame
*f
)
4633 rect
.left
= rect
.top
= 0;
4634 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4635 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4637 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4638 FRAME_EXTERNAL_MENU_BAR (f
));
4640 tip_window
= FRAME_W32_WINDOW (f
)
4641 = CreateWindow (EMACS_CLASS
,
4643 f
->output_data
.w32
->dwStyle
,
4646 rect
.right
- rect
.left
,
4647 rect
.bottom
- rect
.top
,
4648 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4655 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4656 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4657 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4658 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4660 /* Tip frames have no scrollbars. */
4661 SetWindowLong (tip_window
, WND_VSCROLLBAR_INDEX
, 0);
4662 SetWindowLong (tip_window
, WND_HSCROLLBAR_INDEX
, 0);
4664 /* Do this to discard the default setting specified by our parent. */
4665 ShowWindow (tip_window
, SW_HIDE
);
4670 /* Create and set up the w32 window for frame F. */
4673 w32_window (struct frame
*f
, long window_prompting
, bool minibuffer_only
)
4677 /* Use the resource name as the top-level window name
4678 for looking up resources. Make a non-Lisp copy
4679 for the window manager, so GC relocation won't bother it.
4681 Elsewhere we specify the window name for the window manager. */
4682 f
->namebuf
= xlispstrdup (Vx_resource_name
);
4684 my_create_window (f
);
4686 validate_x_resource_name ();
4688 /* x_set_name normally ignores requests to set the name if the
4689 requested name is the same as the current name. This is the one
4690 place where that assumption isn't correct; f->name is set, but
4691 the server hasn't been told. */
4694 int explicit = f
->explicit_name
;
4696 f
->explicit_name
= 0;
4698 fset_name (f
, Qnil
);
4699 x_set_name (f
, name
, explicit);
4704 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4705 initialize_frame_menubar (f
);
4707 if (FRAME_W32_WINDOW (f
) == 0)
4708 error ("Unable to create window");
4711 /* Handle the icon stuff for this window. Perhaps later we might
4712 want an x_set_icon_position which can be called interactively as
4716 x_icon (struct frame
*f
, Lisp_Object parms
)
4718 Lisp_Object icon_x
, icon_y
;
4719 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4721 /* Set the position of the icon. Note that Windows 95 groups all
4722 icons in the tray. */
4723 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4724 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4725 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4727 CHECK_NUMBER (icon_x
);
4728 CHECK_NUMBER (icon_y
);
4730 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4731 error ("Both left and top icon corners of icon must be specified");
4736 /* Start up iconic or window? */
4737 x_wm_set_window_state
4738 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4742 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4752 x_make_gc (struct frame
*f
)
4754 XGCValues gc_values
;
4758 /* Create the GC's of this frame.
4759 Note that many default values are used. */
4762 gc_values
.font
= FRAME_FONT (f
);
4764 /* Cursor has cursor-color background, background-color foreground. */
4765 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4766 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4767 f
->output_data
.w32
->cursor_gc
4768 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4769 (GCFont
| GCForeground
| GCBackground
),
4773 f
->output_data
.w32
->white_relief
.gc
= 0;
4774 f
->output_data
.w32
->black_relief
.gc
= 0;
4780 /* Handler for signals raised during x_create_frame and
4781 x_create_tip_frame. FRAME is the frame which is partially
4785 unwind_create_frame (Lisp_Object frame
)
4787 struct frame
*f
= XFRAME (frame
);
4789 /* If frame is ``official'', nothing to do. */
4790 if (NILP (Fmemq (frame
, Vframe_list
)))
4793 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4795 /* If the frame's image cache refcount is still the same as our
4796 private shadow variable, it means we are unwinding a frame
4797 for which we didn't yet call init_frame_faces, where the
4798 refcount is incremented. Therefore, we increment it here, so
4799 that free_frame_faces, called in x_free_frame_resources
4800 below, will not mistakenly decrement the counter that was not
4801 incremented yet to account for this new frame. */
4802 if (FRAME_IMAGE_CACHE (f
) != NULL
4803 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
4804 FRAME_IMAGE_CACHE (f
)->refcount
++;
4807 x_free_frame_resources (f
);
4811 /* Check that reference counts are indeed correct. */
4812 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4813 eassert ((dpyinfo
->terminal
->image_cache
== NULL
4814 && image_cache_refcount
== 0)
4815 || (dpyinfo
->terminal
->image_cache
!= NULL
4816 && dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
));
4825 do_unwind_create_frame (Lisp_Object frame
)
4827 unwind_create_frame (frame
);
4831 unwind_create_frame_1 (Lisp_Object val
)
4833 inhibit_lisp_code
= val
;
4837 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4839 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4840 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4843 if (EQ (font_param
, Qunbound
))
4845 font
= !NILP (font_param
) ? font_param
4846 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4848 if (!STRINGP (font
))
4851 static char *names
[]
4852 = { "Courier New-10",
4853 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4854 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4858 for (i
= 0; names
[i
]; i
++)
4860 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4865 error ("No suitable font was found");
4867 else if (!NILP (font_param
))
4869 /* Remember the explicit font parameter, so we can re-apply it after
4870 we've applied the `default' face settings. */
4871 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4873 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4876 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4878 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4879 Return an Emacs frame object.
4880 PARAMETERS is an alist of frame parameters.
4881 If the parameters specify that the frame should not have a minibuffer,
4882 and do not specify a specific minibuffer window to use,
4883 then `default-minibuffer-frame' must be a frame whose minibuffer can
4884 be shared by the new frame.
4886 This function is an internal primitive--use `make-frame' instead. */)
4887 (Lisp_Object parameters
)
4890 Lisp_Object frame
, tem
;
4892 bool minibuffer_only
= false;
4893 long window_prompting
= 0;
4894 ptrdiff_t count
= SPECPDL_INDEX ();
4895 Lisp_Object display
;
4896 struct w32_display_info
*dpyinfo
= NULL
;
4899 int x_width
= 0, x_height
= 0;
4901 if (!FRAME_W32_P (SELECTED_FRAME ())
4902 && !FRAME_INITIAL_P (SELECTED_FRAME ()))
4903 error ("Cannot create a GUI frame in a -nw session");
4905 /* Make copy of frame parameters because the original is in pure
4907 parameters
= Fcopy_alist (parameters
);
4909 /* Use this general default value to start with
4910 until we know if this frame has a specified name. */
4911 Vx_resource_name
= Vinvocation_name
;
4913 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4914 if (EQ (display
, Qunbound
))
4915 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4916 if (EQ (display
, Qunbound
))
4918 dpyinfo
= check_x_display_info (display
);
4919 kb
= dpyinfo
->terminal
->kboard
;
4921 if (!dpyinfo
->terminal
->name
)
4922 error ("Terminal is not live, can't create new frames on it");
4924 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4926 && ! EQ (name
, Qunbound
)
4928 error ("Invalid frame name--not a string or nil");
4931 Vx_resource_name
= name
;
4933 /* See if parent window is specified. */
4934 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4935 if (EQ (parent
, Qunbound
))
4937 if (! NILP (parent
))
4938 CHECK_NUMBER (parent
);
4940 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4941 /* No need to protect DISPLAY because that's not used after passing
4942 it to make_frame_without_minibuffer. */
4944 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4946 if (EQ (tem
, Qnone
) || NILP (tem
))
4947 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4948 else if (EQ (tem
, Qonly
))
4950 f
= make_minibuffer_frame ();
4951 minibuffer_only
= true;
4953 else if (WINDOWP (tem
))
4954 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4956 f
= make_frame (true);
4958 XSETFRAME (frame
, f
);
4960 /* By default, make scrollbars the system standard width and height. */
4961 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4962 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
4964 f
->terminal
= dpyinfo
->terminal
;
4966 f
->output_method
= output_w32
;
4967 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4968 FRAME_FONTSET (f
) = -1;
4971 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4973 if (! STRINGP (f
->icon_name
))
4974 fset_icon_name (f
, Qnil
);
4976 /* FRAME_DISPLAY_INFO (f) = dpyinfo; */
4978 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
4979 record_unwind_protect (do_unwind_create_frame
, frame
);
4982 image_cache_refcount
=
4983 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4984 dpyinfo_refcount
= dpyinfo
->reference_count
;
4985 #endif /* GLYPH_DEBUG */
4987 /* Specify the parent under which to make this window. */
4990 /* Cast to UINT_PTR shuts up compiler warnings about cast to
4991 pointer from integer of different size. */
4992 f
->output_data
.w32
->parent_desc
= (Window
) (UINT_PTR
) XFASTINT (parent
);
4993 f
->output_data
.w32
->explicit_parent
= true;
4997 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4998 f
->output_data
.w32
->explicit_parent
= false;
5001 /* Set the name; the functions to which we pass f expect the name to
5003 if (EQ (name
, Qunbound
) || NILP (name
))
5005 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5006 f
->explicit_name
= false;
5010 fset_name (f
, name
);
5011 f
->explicit_name
= true;
5012 /* Use the frame's title when getting resources for this frame. */
5013 specbind (Qx_resource_name
, name
);
5016 if (uniscribe_available
)
5017 register_font_driver (&uniscribe_font_driver
, f
);
5018 register_font_driver (&w32font_driver
, f
);
5020 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
5021 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5023 /* Extract the window parameters from the supplied values
5024 that are needed to determine window geometry. */
5025 x_default_font_parameter (f
, parameters
);
5027 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
5028 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5030 /* We recognize either internalBorderWidth or internalBorder
5031 (which is what xterm calls it). */
5032 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
5036 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
5037 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5038 if (! EQ (value
, Qunbound
))
5039 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
5042 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5043 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
5044 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5045 x_default_parameter (f
, parameters
, Qright_divider_width
, make_number (0),
5046 NULL
, NULL
, RES_TYPE_NUMBER
);
5047 x_default_parameter (f
, parameters
, Qbottom_divider_width
, make_number (0),
5048 NULL
, NULL
, RES_TYPE_NUMBER
);
5049 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
5050 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5051 x_default_parameter (f
, parameters
, Qhorizontal_scroll_bars
, Qnil
,
5052 "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5054 /* Also do the stuff which must be set before the window exists. */
5055 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
5056 "foreground", "Foreground", RES_TYPE_STRING
);
5057 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
5058 "background", "Background", RES_TYPE_STRING
);
5059 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
5060 "pointerColor", "Foreground", RES_TYPE_STRING
);
5061 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
5062 "borderColor", "BorderColor", RES_TYPE_STRING
);
5063 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
5064 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5065 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
5066 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5067 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
5068 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
5069 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
5070 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
5071 /* Process alpha here (Bug#16619). */
5072 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
5073 "alpha", "Alpha", RES_TYPE_NUMBER
);
5075 /* Init faces first since we need the frame's column width/line
5076 height in various occasions. */
5077 init_frame_faces (f
);
5079 /* The following call of change_frame_size is needed since otherwise
5080 x_set_tool_bar_lines will already work with the character sizes
5081 installed by init_frame_faces while the frame's pixel size is
5082 still calculated from a character size of 1 and we subsequently
5083 hit the (height >= 0) assertion in window_box_height.
5085 The non-pixelwise code apparently worked around this because it
5086 had one frame line vs one toolbar line which left us with a zero
5087 root window height which was obviously wrong as well ... */
5088 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
5089 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
5092 /* The X resources controlling the menu-bar and tool-bar are
5093 processed specially at startup, and reflected in the mode
5094 variables; ignore them here. */
5095 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
5096 NILP (Vmenu_bar_mode
)
5097 ? make_number (0) : make_number (1),
5098 NULL
, NULL
, RES_TYPE_NUMBER
);
5099 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
5100 NILP (Vtool_bar_mode
)
5101 ? make_number (0) : make_number (1),
5102 NULL
, NULL
, RES_TYPE_NUMBER
);
5104 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
5105 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5106 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
5107 "title", "Title", RES_TYPE_STRING
);
5109 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5110 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5112 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
5113 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
5114 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
5115 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
5116 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
5117 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
5118 f
->output_data
.w32
->vertical_drag_cursor
= w32_load_cursor (IDC_SIZENS
);
5120 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
5122 window_prompting
= x_figure_window_size (f
, parameters
, true, &x_width
, &x_height
);
5124 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5125 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5127 w32_window (f
, window_prompting
, minibuffer_only
);
5128 x_icon (f
, parameters
);
5132 /* Now consider the frame official. */
5133 f
->terminal
->reference_count
++;
5134 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5135 Vframe_list
= Fcons (frame
, Vframe_list
);
5137 /* We need to do this after creating the window, so that the
5138 icon-creation functions can say whose icon they're describing. */
5139 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
5140 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5142 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
5143 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5144 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
5145 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5146 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
5147 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5148 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
5149 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5150 x_default_parameter (f
, parameters
, Qscroll_bar_height
, Qnil
,
5151 "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER
);
5153 /* Allow x_set_window_size, now. */
5154 f
->can_x_set_window_size
= true;
5157 SET_FRAME_WIDTH (f
, x_width
);
5159 SET_FRAME_HEIGHT (f
, x_height
);
5161 /* Tell the server what size and position, etc, we want, and how
5162 badly we want them. This should be done after we have the menu
5163 bar so that its size can be taken into account. */
5165 x_wm_set_size_hint (f
, window_prompting
, false);
5168 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
5171 /* Process fullscreen parameter here in the hope that normalizing a
5172 fullheight/fullwidth frame will produce the size set by the last
5173 adjust_frame_size call. */
5174 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
5175 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
5177 /* Make the window appear on the frame and enable display, unless
5178 the caller says not to. However, with explicit parent, Emacs
5179 cannot control visibility, so don't try. */
5180 if (! f
->output_data
.w32
->explicit_parent
)
5182 Lisp_Object visibility
;
5184 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5185 if (EQ (visibility
, Qunbound
))
5188 if (EQ (visibility
, Qicon
))
5189 x_iconify_frame (f
);
5190 else if (! NILP (visibility
))
5191 x_make_frame_visible (f
);
5193 /* Must have been Qnil. */
5197 /* Initialize `default-minibuffer-frame' in case this is the first
5198 frame on this terminal. */
5199 if (FRAME_HAS_MINIBUF_P (f
)
5200 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
5201 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
5202 kset_default_minibuffer_frame (kb
, frame
);
5204 /* All remaining specified parameters, which have not been "used"
5205 by x_get_arg and friends, now go in the misc. alist of the frame. */
5206 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
5207 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
5208 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
5210 /* Make sure windows on this frame appear in calls to next-window
5211 and similar functions. */
5212 Vwindow_list
= Qnil
;
5214 return unbind_to (count
, frame
);
5217 /* FRAME is used only to get a handle on the X display. We don't pass the
5218 display info directly because we're called from frame.c, which doesn't
5219 know about that structure. */
5221 x_get_focus_frame (struct frame
*frame
)
5223 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
5225 if (! dpyinfo
->w32_focus_frame
)
5228 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5232 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
5233 doc
: /* Internal function called by `color-defined-p', which see.
5234 (Note that the Nextstep version of this function ignores FRAME.) */)
5235 (Lisp_Object color
, Lisp_Object frame
)
5238 struct frame
*f
= decode_window_system_frame (frame
);
5240 CHECK_STRING (color
);
5242 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
5248 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
5249 doc
: /* Internal function called by `color-values', which see. */)
5250 (Lisp_Object color
, Lisp_Object frame
)
5253 struct frame
*f
= decode_window_system_frame (frame
);
5255 CHECK_STRING (color
);
5257 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
5258 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
5259 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
5260 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
5265 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
5266 doc
: /* Internal function called by `display-color-p', which see. */)
5267 (Lisp_Object display
)
5269 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5271 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
5277 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
5278 Sx_display_grayscale_p
, 0, 1, 0,
5279 doc
: /* Return t if DISPLAY supports shades of gray.
5280 Note that color displays do support shades of gray.
5281 The optional argument DISPLAY specifies which display to ask about.
5282 DISPLAY should be either a frame or a display name (a string).
5283 If omitted or nil, that stands for the selected frame's display. */)
5284 (Lisp_Object display
)
5286 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5288 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
5294 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
5295 Sx_display_pixel_width
, 0, 1, 0,
5296 doc
: /* Return the width in pixels of DISPLAY.
5297 The optional argument DISPLAY specifies which display to ask about.
5298 DISPLAY should be either a frame or a display name (a string).
5299 If omitted or nil, that stands for the selected frame's display.
5301 On \"multi-monitor\" setups this refers to the pixel width for all
5302 physical monitors associated with DISPLAY. To get information for
5303 each physical monitor, use `display-monitor-attributes-list'. */)
5304 (Lisp_Object display
)
5306 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5308 return make_number (x_display_pixel_width (dpyinfo
));
5311 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
5312 Sx_display_pixel_height
, 0, 1, 0,
5313 doc
: /* Return the height in pixels of DISPLAY.
5314 The optional argument DISPLAY specifies which display to ask about.
5315 DISPLAY should be either a frame or a display name (a string).
5316 If omitted or nil, that stands for the selected frame's display.
5318 On \"multi-monitor\" setups this refers to the pixel height for all
5319 physical monitors associated with DISPLAY. To get information for
5320 each physical monitor, use `display-monitor-attributes-list'. */)
5321 (Lisp_Object display
)
5323 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5325 return make_number (x_display_pixel_height (dpyinfo
));
5328 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
5330 doc
: /* Return the number of bitplanes of DISPLAY.
5331 The optional argument DISPLAY specifies which display to ask about.
5332 DISPLAY should be either a frame or a display name (a string).
5333 If omitted or nil, that stands for the selected frame's display. */)
5334 (Lisp_Object display
)
5336 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5338 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
5341 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
5343 doc
: /* Return the number of color cells of DISPLAY.
5344 The optional argument DISPLAY specifies which display to ask about.
5345 DISPLAY should be either a frame or a display name (a string).
5346 If omitted or nil, that stands for the selected frame's display. */)
5347 (Lisp_Object display
)
5349 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5352 /* Don't use NCOLORS: it returns incorrect results under remote
5353 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
5354 * overflow and because probably is more meaningful on Windows
5357 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
5358 return make_number (cap
);
5361 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
5362 Sx_server_max_request_size
,
5364 doc
: /* Return the maximum request size of the server of DISPLAY.
5365 The optional argument DISPLAY specifies which display to ask about.
5366 DISPLAY should be either a frame or a display name (a string).
5367 If omitted or nil, that stands for the selected frame's display. */)
5368 (Lisp_Object display
)
5370 return make_number (1);
5373 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
5374 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
5376 (Labeling every distributor as a "vendor" embodies the false assumption
5377 that operating systems cannot be developed and distributed noncommercially.)
5379 For GNU and Unix systems, this queries the X server software; for
5380 MS-Windows, this queries the OS.
5382 The optional argument TERMINAL specifies which display to ask about.
5383 TERMINAL should be a terminal object, a frame or a display name (a string).
5384 If omitted or nil, that stands for the selected frame's display. */)
5385 (Lisp_Object terminal
)
5387 return build_string ("Microsoft Corp.");
5390 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
5391 doc
: /* Return the version numbers of the GUI software on TERMINAL.
5392 The value is a list of three integers specifying the version of the GUI
5395 For GNU and Unix system, the first 2 numbers are the version of the X
5396 Protocol used on TERMINAL and the 3rd number is the distributor-specific
5397 release number. For MS-Windows, the 3 numbers report the version and
5398 the build number of the OS.
5400 See also the function `x-server-vendor'.
5402 The optional argument TERMINAL specifies which display to ask about.
5403 TERMINAL should be a terminal object, a frame or a display name (a string).
5404 If omitted or nil, that stands for the selected frame's display. */)
5405 (Lisp_Object terminal
)
5407 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
5410 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
5411 doc
: /* Return the number of screens on the server of DISPLAY.
5412 The optional argument DISPLAY specifies which display to ask about.
5413 DISPLAY should be either a frame or a display name (a string).
5414 If omitted or nil, that stands for the selected frame's display. */)
5415 (Lisp_Object display
)
5417 return make_number (1);
5420 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
5421 Sx_display_mm_height
, 0, 1, 0,
5422 doc
: /* Return the height in millimeters of DISPLAY.
5423 The optional argument DISPLAY specifies which display to ask about.
5424 DISPLAY should be either a frame or a display name (a string).
5425 If omitted or nil, that stands for the selected frame's display.
5427 On \"multi-monitor\" setups this refers to the height in millimeters for
5428 all physical monitors associated with DISPLAY. To get information
5429 for each physical monitor, use `display-monitor-attributes-list'. */)
5430 (Lisp_Object display
)
5432 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5434 double mm_per_pixel
;
5437 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5438 / GetDeviceCaps (hdc
, VERTRES
));
5439 ReleaseDC (NULL
, hdc
);
5441 return make_number (x_display_pixel_height (dpyinfo
) * mm_per_pixel
+ 0.5);
5444 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
5445 doc
: /* Return the width in millimeters of DISPLAY.
5446 The optional argument DISPLAY specifies which display to ask about.
5447 DISPLAY should be either a frame or a display name (a string).
5448 If omitted or nil, that stands for the selected frame's display.
5450 On \"multi-monitor\" setups this refers to the width in millimeters for
5451 all physical monitors associated with TERMINAL. To get information
5452 for each physical monitor, use `display-monitor-attributes-list'. */)
5453 (Lisp_Object display
)
5455 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5457 double mm_per_pixel
;
5460 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5461 / GetDeviceCaps (hdc
, HORZRES
));
5462 ReleaseDC (NULL
, hdc
);
5464 return make_number (x_display_pixel_width (dpyinfo
) * mm_per_pixel
+ 0.5);
5467 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
5468 Sx_display_backing_store
, 0, 1, 0,
5469 doc
: /* Return an indication of whether DISPLAY does backing store.
5470 The value may be `always', `when-mapped', or `not-useful'.
5471 The optional argument DISPLAY specifies which display to ask about.
5472 DISPLAY should be either a frame or a display name (a string).
5473 If omitted or nil, that stands for the selected frame's display. */)
5474 (Lisp_Object display
)
5476 return intern ("not-useful");
5479 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
5480 Sx_display_visual_class
, 0, 1, 0,
5481 doc
: /* Return the visual class of DISPLAY.
5482 The value is one of the symbols `static-gray', `gray-scale',
5483 `static-color', `pseudo-color', `true-color', or `direct-color'.
5485 The optional argument DISPLAY specifies which display to ask about.
5486 DISPLAY should be either a frame or a display name (a string).
5487 If omitted or nil, that stands for the selected frame's display. */)
5488 (Lisp_Object display
)
5490 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5491 Lisp_Object result
= Qnil
;
5493 if (dpyinfo
->has_palette
)
5494 result
= intern ("pseudo-color");
5495 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
5496 result
= intern ("static-grey");
5497 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
5498 result
= intern ("static-color");
5499 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
5500 result
= intern ("true-color");
5505 DEFUN ("x-display-save-under", Fx_display_save_under
,
5506 Sx_display_save_under
, 0, 1, 0,
5507 doc
: /* Return t if DISPLAY supports the save-under feature.
5508 The optional argument DISPLAY specifies which display to ask about.
5509 DISPLAY should be either a frame or a display name (a string).
5510 If omitted or nil, that stands for the selected frame's display. */)
5511 (Lisp_Object display
)
5516 static BOOL CALLBACK ALIGN_STACK
5517 w32_monitor_enum (HMONITOR monitor
, HDC hdc
, RECT
*rcMonitor
, LPARAM dwData
)
5519 Lisp_Object
*monitor_list
= (Lisp_Object
*) dwData
;
5521 *monitor_list
= Fcons (make_save_ptr (monitor
), *monitor_list
);
5527 w32_display_monitor_attributes_list (void)
5529 Lisp_Object attributes_list
= Qnil
, primary_monitor_attributes
= Qnil
;
5530 Lisp_Object monitor_list
= Qnil
, monitor_frames
, rest
, frame
;
5534 if (!(enum_display_monitors_fn
&& get_monitor_info_fn
5535 && monitor_from_window_fn
))
5538 if (!enum_display_monitors_fn (NULL
, NULL
, w32_monitor_enum
,
5539 (LPARAM
) &monitor_list
)
5540 || NILP (monitor_list
))
5544 for (rest
= monitor_list
; CONSP (rest
); rest
= XCDR (rest
))
5547 monitors
= xmalloc (n_monitors
* sizeof (*monitors
));
5548 for (i
= 0; i
< n_monitors
; i
++)
5550 monitors
[i
] = XSAVE_POINTER (XCAR (monitor_list
), 0);
5551 monitor_list
= XCDR (monitor_list
);
5554 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
5555 FOR_EACH_FRAME (rest
, frame
)
5557 struct frame
*f
= XFRAME (frame
);
5559 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5562 monitor_from_window_fn (FRAME_W32_WINDOW (f
),
5563 MONITOR_DEFAULT_TO_NEAREST
);
5565 for (i
= 0; i
< n_monitors
; i
++)
5566 if (monitors
[i
] == monitor
)
5570 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
5574 for (i
= 0; i
< n_monitors
; i
++)
5576 Lisp_Object geometry
, workarea
, name
, attributes
= Qnil
;
5578 int width_mm
, height_mm
;
5579 struct MONITOR_INFO_EX mi
;
5581 mi
.cbSize
= sizeof (mi
);
5582 if (!get_monitor_info_fn (monitors
[i
], (struct MONITOR_INFO
*) &mi
))
5585 hdc
= CreateDCA ("DISPLAY", mi
.szDevice
, NULL
, NULL
);
5588 width_mm
= GetDeviceCaps (hdc
, HORZSIZE
);
5589 height_mm
= GetDeviceCaps (hdc
, VERTSIZE
);
5592 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
5595 name
= DECODE_SYSTEM (build_unibyte_string (mi
.szDevice
));
5597 attributes
= Fcons (Fcons (Qname
, name
), attributes
);
5599 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5602 workarea
= list4i (mi
.rcWork
.left
, mi
.rcWork
.top
,
5603 mi
.rcWork
.right
- mi
.rcWork
.left
,
5604 mi
.rcWork
.bottom
- mi
.rcWork
.top
);
5605 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5607 geometry
= list4i (mi
.rcMonitor
.left
, mi
.rcMonitor
.top
,
5608 mi
.rcMonitor
.right
- mi
.rcMonitor
.left
,
5609 mi
.rcMonitor
.bottom
- mi
.rcMonitor
.top
);
5610 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5612 if (mi
.dwFlags
& MONITORINFOF_PRIMARY
)
5613 primary_monitor_attributes
= attributes
;
5615 attributes_list
= Fcons (attributes
, attributes_list
);
5618 if (!NILP (primary_monitor_attributes
))
5619 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
5623 return attributes_list
;
5627 w32_display_monitor_attributes_list_fallback (struct w32_display_info
*dpyinfo
)
5629 Lisp_Object geometry
, workarea
, frames
, rest
, frame
, attributes
= Qnil
;
5631 double mm_per_pixel
;
5632 int pixel_width
, pixel_height
, width_mm
, height_mm
;
5635 /* Fallback: treat (possibly) multiple physical monitors as if they
5636 formed a single monitor as a whole. This should provide a
5637 consistent result at least on single monitor environments. */
5638 attributes
= Fcons (Fcons (Qname
, build_string ("combined screen")),
5642 FOR_EACH_FRAME (rest
, frame
)
5644 struct frame
*f
= XFRAME (frame
);
5646 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5647 frames
= Fcons (frame
, frames
);
5649 attributes
= Fcons (Fcons (Qframes
, frames
), attributes
);
5651 pixel_width
= x_display_pixel_width (dpyinfo
);
5652 pixel_height
= x_display_pixel_height (dpyinfo
);
5655 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5656 / GetDeviceCaps (hdc
, HORZRES
));
5657 width_mm
= pixel_width
* mm_per_pixel
+ 0.5;
5658 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5659 / GetDeviceCaps (hdc
, VERTRES
));
5660 height_mm
= pixel_height
* mm_per_pixel
+ 0.5;
5661 ReleaseDC (NULL
, hdc
);
5662 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5665 /* GetSystemMetrics below may return 0 for Windows 95 or NT 4.0, but
5667 geometry
= list4i (GetSystemMetrics (SM_XVIRTUALSCREEN
),
5668 GetSystemMetrics (SM_YVIRTUALSCREEN
),
5669 pixel_width
, pixel_height
);
5670 if (SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0))
5671 workarea
= list4i (workarea_rect
.left
, workarea_rect
.top
,
5672 workarea_rect
.right
- workarea_rect
.left
,
5673 workarea_rect
.bottom
- workarea_rect
.top
);
5675 workarea
= geometry
;
5676 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5678 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5680 return list1 (attributes
);
5683 DEFUN ("w32-display-monitor-attributes-list", Fw32_display_monitor_attributes_list
,
5684 Sw32_display_monitor_attributes_list
,
5686 doc
: /* Return a list of physical monitor attributes on the W32 display DISPLAY.
5688 The optional argument DISPLAY specifies which display to ask about.
5689 DISPLAY should be either a frame or a display name (a string).
5690 If omitted or nil, that stands for the selected frame's display.
5692 Internal use only, use `display-monitor-attributes-list' instead. */)
5693 (Lisp_Object display
)
5695 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5696 Lisp_Object attributes_list
;
5699 attributes_list
= w32_display_monitor_attributes_list ();
5700 if (NILP (attributes_list
))
5701 attributes_list
= w32_display_monitor_attributes_list_fallback (dpyinfo
);
5704 return attributes_list
;
5707 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
5708 doc
: /* Set the sound generated when the bell is rung.
5709 SOUND is `asterisk', `exclamation', `hand', `question', `ok', or `silent'
5710 to use the corresponding system sound for the bell. The `silent' sound
5711 prevents Emacs from making any sound at all.
5712 SOUND is nil to use the normal beep. */)
5715 CHECK_SYMBOL (sound
);
5718 sound_type
= 0xFFFFFFFF;
5719 else if (EQ (sound
, intern ("asterisk")))
5720 sound_type
= MB_ICONASTERISK
;
5721 else if (EQ (sound
, intern ("exclamation")))
5722 sound_type
= MB_ICONEXCLAMATION
;
5723 else if (EQ (sound
, intern ("hand")))
5724 sound_type
= MB_ICONHAND
;
5725 else if (EQ (sound
, intern ("question")))
5726 sound_type
= MB_ICONQUESTION
;
5727 else if (EQ (sound
, intern ("ok")))
5729 else if (EQ (sound
, intern ("silent")))
5730 sound_type
= MB_EMACS_SILENT
;
5732 sound_type
= 0xFFFFFFFF;
5738 x_screen_planes (register struct frame
*f
)
5740 return FRAME_DISPLAY_INFO (f
)->n_planes
;
5743 /* Return the display structure for the display named NAME.
5744 Open a new connection if necessary. */
5746 struct w32_display_info
*
5747 x_display_info_for_name (Lisp_Object name
)
5749 struct w32_display_info
*dpyinfo
;
5751 CHECK_STRING (name
);
5753 for (dpyinfo
= &one_w32_display_info
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
5754 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
5757 /* Use this general default value to start with. */
5758 Vx_resource_name
= Vinvocation_name
;
5760 validate_x_resource_name ();
5762 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
5763 SSDATA (Vx_resource_name
));
5766 error ("Cannot connect to server %s", SDATA (name
));
5768 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5773 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5774 1, 3, 0, doc
: /* Open a connection to a display server.
5775 DISPLAY is the name of the display to connect to.
5776 Optional second arg XRM-STRING is a string of resources in xrdb format.
5777 If the optional third arg MUST-SUCCEED is non-nil,
5778 terminate Emacs if we can't open the connection.
5779 (In the Nextstep version, the last two arguments are currently ignored.) */)
5780 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
5782 unsigned char *xrm_option
;
5783 struct w32_display_info
*dpyinfo
;
5785 CHECK_STRING (display
);
5787 /* Signal an error in order to encourage correct use from callers.
5788 * If we ever support multiple window systems in the same Emacs,
5789 * we'll need callers to be precise about what window system they
5792 if (strcmp (SSDATA (display
), "w32") != 0)
5793 error ("The name of the display in this Emacs must be \"w32\"");
5795 /* If initialization has already been done, return now to avoid
5796 overwriting critical parts of one_w32_display_info. */
5797 if (window_system_available (NULL
))
5800 if (! NILP (xrm_string
))
5801 CHECK_STRING (xrm_string
);
5803 /* Allow color mapping to be defined externally; first look in user's
5804 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5806 Lisp_Object color_file
;
5808 color_file
= build_string ("~/rgb.txt");
5810 if (NILP (Ffile_readable_p (color_file
)))
5812 Fexpand_file_name (build_string ("rgb.txt"),
5813 Fsymbol_value (intern ("data-directory")));
5815 Vw32_color_map
= Fx_load_color_file (color_file
);
5817 if (NILP (Vw32_color_map
))
5818 Vw32_color_map
= w32_default_color_map ();
5820 /* Merge in system logical colors. */
5821 add_system_logical_colors_to_map (&Vw32_color_map
);
5823 if (! NILP (xrm_string
))
5824 xrm_option
= SDATA (xrm_string
);
5826 xrm_option
= (unsigned char *) 0;
5828 /* Use this general default value to start with. */
5829 /* First remove .exe suffix from invocation-name - it looks ugly. */
5831 char basename
[ MAX_PATH
], *str
;
5833 lispstpcpy (basename
, Vinvocation_name
);
5834 str
= strrchr (basename
, '.');
5836 Vinvocation_name
= build_string (basename
);
5838 Vx_resource_name
= Vinvocation_name
;
5840 validate_x_resource_name ();
5842 /* This is what opens the connection and sets x_current_display.
5843 This also initializes many symbols, such as those used for input. */
5844 dpyinfo
= w32_term_init (display
, xrm_option
,
5845 SSDATA (Vx_resource_name
));
5849 if (!NILP (must_succeed
))
5850 fatal ("Cannot connect to server %s.\n",
5853 error ("Cannot connect to server %s", SDATA (display
));
5856 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5860 DEFUN ("x-close-connection", Fx_close_connection
,
5861 Sx_close_connection
, 1, 1, 0,
5862 doc
: /* Close the connection to DISPLAY's server.
5863 For DISPLAY, specify either a frame or a display name (a string).
5864 If DISPLAY is nil, that stands for the selected frame's display. */)
5865 (Lisp_Object display
)
5867 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5869 if (dpyinfo
->reference_count
> 0)
5870 error ("Display still has frames on it");
5873 x_destroy_all_bitmaps (dpyinfo
);
5875 x_delete_display (dpyinfo
);
5881 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5882 doc
: /* Return the list of display names that Emacs has connections to. */)
5885 Lisp_Object result
= Qnil
;
5886 struct w32_display_info
*wdi
;
5888 for (wdi
= x_display_list
; wdi
; wdi
= wdi
->next
)
5889 result
= Fcons (XCAR (wdi
->name_list_element
), result
);
5894 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5895 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5896 This function only has an effect on X Windows. With MS Windows, it is
5897 defined but does nothing.
5899 If ON is nil, allow buffering of requests.
5900 Turning on synchronization prohibits the Xlib routines from buffering
5901 requests and seriously degrades performance, but makes debugging much
5903 The optional second argument TERMINAL specifies which display to act on.
5904 TERMINAL should be a terminal object, a frame or a display name (a string).
5905 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5906 (Lisp_Object on
, Lisp_Object display
)
5913 /***********************************************************************
5915 ***********************************************************************/
5917 #if 0 /* TODO : port window properties to W32 */
5919 DEFUN ("x-change-window-property", Fx_change_window_property
,
5920 Sx_change_window_property
, 2, 6, 0,
5921 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5922 PROP must be a string. VALUE may be a string or a list of conses,
5923 numbers and/or strings. If an element in the list is a string, it is
5924 converted to an atom and the value of the Atom is used. If an element
5925 is a cons, it is converted to a 32 bit number where the car is the 16
5926 top bits and the cdr is the lower 16 bits.
5928 FRAME nil or omitted means use the selected frame.
5929 If TYPE is given and non-nil, it is the name of the type of VALUE.
5930 If TYPE is not given or nil, the type is STRING.
5931 FORMAT gives the size in bits of each element if VALUE is a list.
5932 It must be one of 8, 16 or 32.
5933 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5934 If OUTER-P is non-nil, the property is changed for the outer X window of
5935 FRAME. Default is to change on the edit X window. */)
5936 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5937 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5939 struct frame
*f
= decode_window_system_frame (frame
);
5942 CHECK_STRING (prop
);
5943 CHECK_STRING (value
);
5946 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5947 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5948 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5949 SDATA (value
), SCHARS (value
));
5951 /* Make sure the property is set when we return. */
5952 XFlush (FRAME_W32_DISPLAY (f
));
5959 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5960 Sx_delete_window_property
, 1, 2, 0,
5961 doc
: /* Remove window property PROP from X window of FRAME.
5962 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5963 (Lisp_Object prop
, Lisp_Object frame
)
5965 struct frame
*f
= decode_window_system_frame (frame
);
5968 CHECK_STRING (prop
);
5970 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5971 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5973 /* Make sure the property is removed when we return. */
5974 XFlush (FRAME_W32_DISPLAY (f
));
5981 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5983 doc
: /* Value is the value of window property PROP on FRAME.
5984 If FRAME is nil or omitted, use the selected frame.
5986 On X Windows, the following optional arguments are also accepted:
5987 If TYPE is nil or omitted, get the property as a string.
5988 Otherwise TYPE is the name of the atom that denotes the type expected.
5989 If SOURCE is non-nil, get the property on that window instead of from
5990 FRAME. The number 0 denotes the root window.
5991 If DELETE-P is non-nil, delete the property after retrieving it.
5992 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5994 On MS Windows, this function accepts but ignores those optional arguments.
5996 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5997 no value of TYPE (always string in the MS Windows case). */)
5998 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5999 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
6001 struct frame
*f
= decode_window_system_frame (frame
);
6004 Lisp_Object prop_value
= Qnil
;
6005 char *tmp_data
= NULL
;
6008 unsigned long actual_size
, bytes_remaining
;
6010 CHECK_STRING (prop
);
6012 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
6013 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6014 prop_atom
, 0, 0, False
, XA_STRING
,
6015 &actual_type
, &actual_format
, &actual_size
,
6016 &bytes_remaining
, (unsigned char **) &tmp_data
);
6019 int size
= bytes_remaining
;
6024 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
6025 prop_atom
, 0, bytes_remaining
,
6027 &actual_type
, &actual_format
,
6028 &actual_size
, &bytes_remaining
,
6029 (unsigned char **) &tmp_data
);
6031 prop_value
= make_string (tmp_data
, size
);
6045 /***********************************************************************
6047 ***********************************************************************/
6049 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
6050 Lisp_Object
, Lisp_Object
);
6051 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
6052 Lisp_Object
, int, int, int *, int *);
6054 /* The frame of a currently visible tooltip. */
6056 Lisp_Object tip_frame
;
6058 /* If non-nil, a timer started that hides the last tooltip when it
6061 Lisp_Object tip_timer
;
6064 /* If non-nil, a vector of 3 elements containing the last args
6065 with which x-show-tip was called. See there. */
6067 Lisp_Object last_show_tip_args
;
6071 unwind_create_tip_frame (Lisp_Object frame
)
6073 Lisp_Object deleted
;
6075 deleted
= unwind_create_frame (frame
);
6076 if (EQ (deleted
, Qt
))
6084 /* Create a frame for a tooltip on the display described by DPYINFO.
6085 PARMS is a list of frame parameters. TEXT is the string to
6086 display in the tip frame. Value is the frame.
6088 Note that functions called here, esp. x_default_parameter can
6089 signal errors, for instance when a specified color name is
6090 undefined. We have to make sure that we're in a consistent state
6091 when this happens. */
6094 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
6095 Lisp_Object parms
, Lisp_Object text
)
6100 long window_prompting
= 0;
6102 ptrdiff_t count
= SPECPDL_INDEX ();
6104 bool face_change_before
= face_change
;
6106 struct buffer
*old_buffer
;
6107 int x_width
= 0, x_height
= 0;
6109 /* Use this general default value to start with until we know if
6110 this frame has a specified name. */
6111 Vx_resource_name
= Vinvocation_name
;
6113 kb
= dpyinfo
->terminal
->kboard
;
6115 /* The calls to x_get_arg remove elements from PARMS, so copy it to
6116 avoid destructive changes behind our caller's back. */
6117 parms
= Fcopy_alist (parms
);
6119 /* Get the name of the frame to use for resource lookup. */
6120 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
6122 && !EQ (name
, Qunbound
)
6124 error ("Invalid frame name--not a string or nil");
6125 Vx_resource_name
= name
;
6128 /* Make a frame without minibuffer nor mode-line. */
6129 f
= make_frame (false);
6130 f
->wants_modeline
= 0;
6131 XSETFRAME (frame
, f
);
6133 AUTO_STRING (tip
, " *tip*");
6134 buffer
= Fget_buffer_create (tip
);
6135 /* Use set_window_buffer instead of Fset_window_buffer (see
6136 discussion of bug#11984, bug#12025, bug#12026). */
6137 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
6138 old_buffer
= current_buffer
;
6139 set_buffer_internal_1 (XBUFFER (buffer
));
6140 bset_truncate_lines (current_buffer
, Qnil
);
6141 specbind (Qinhibit_read_only
, Qt
);
6142 specbind (Qinhibit_modification_hooks
, Qt
);
6145 set_buffer_internal_1 (old_buffer
);
6147 record_unwind_protect (unwind_create_tip_frame
, frame
);
6149 /* By setting the output method, we're essentially saying that
6150 the frame is live, as per FRAME_LIVE_P. If we get a signal
6151 from this point on, x_destroy_window might screw up reference
6153 f
->terminal
= dpyinfo
->terminal
;
6154 f
->output_method
= output_w32
;
6155 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
6157 FRAME_FONTSET (f
) = -1;
6158 fset_icon_name (f
, Qnil
);
6161 image_cache_refcount
=
6162 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
6163 dpyinfo_refcount
= dpyinfo
->reference_count
;
6164 #endif /* GLYPH_DEBUG */
6165 FRAME_KBOARD (f
) = kb
;
6166 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
6167 f
->output_data
.w32
->explicit_parent
= false;
6169 /* Set the name; the functions to which we pass f expect the name to
6171 if (EQ (name
, Qunbound
) || NILP (name
))
6173 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
6174 f
->explicit_name
= false;
6178 fset_name (f
, name
);
6179 f
->explicit_name
= true;
6180 /* use the frame's title when getting resources for this frame. */
6181 specbind (Qx_resource_name
, name
);
6184 if (uniscribe_available
)
6185 register_font_driver (&uniscribe_font_driver
, f
);
6186 register_font_driver (&w32font_driver
, f
);
6188 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
6189 "fontBackend", "FontBackend", RES_TYPE_STRING
);
6191 /* Extract the window parameters from the supplied values
6192 that are needed to determine window geometry. */
6193 x_default_font_parameter (f
, parms
);
6195 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
6196 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
6197 /* This defaults to 2 in order to match xterm. We recognize either
6198 internalBorderWidth or internalBorder (which is what xterm calls
6200 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6204 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
6205 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
6206 if (! EQ (value
, Qunbound
))
6207 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
6210 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
6211 "internalBorderWidth", "internalBorderWidth",
6213 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
6214 NULL
, NULL
, RES_TYPE_NUMBER
);
6215 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
6216 NULL
, NULL
, RES_TYPE_NUMBER
);
6218 /* Also do the stuff which must be set before the window exists. */
6219 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
6220 "foreground", "Foreground", RES_TYPE_STRING
);
6221 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
6222 "background", "Background", RES_TYPE_STRING
);
6223 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
6224 "pointerColor", "Foreground", RES_TYPE_STRING
);
6225 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
6226 "cursorColor", "Foreground", RES_TYPE_STRING
);
6227 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
6228 "borderColor", "BorderColor", RES_TYPE_STRING
);
6230 /* Init faces before x_default_parameter is called for the
6231 scroll-bar-width parameter because otherwise we end up in
6232 init_iterator with a null face cache, which should not happen. */
6233 init_frame_faces (f
);
6235 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
6236 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
6238 window_prompting
= x_figure_window_size (f
, parms
, true, &x_width
, &x_height
);
6240 /* No fringes on tip frame. */
6242 f
->left_fringe_width
= 0;
6243 f
->right_fringe_width
= 0;
6246 my_create_tip_window (f
);
6251 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
6252 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
6253 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
6254 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
6255 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
6256 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
6257 /* Process alpha here (Bug#17344). */
6258 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
6259 "alpha", "Alpha", RES_TYPE_NUMBER
);
6261 /* Dimensions, especially FRAME_LINES (f), must be done via
6262 change_frame_size. Change will not be effected unless different
6263 from the current FRAME_LINES (f). */
6264 width
= FRAME_COLS (f
);
6265 height
= FRAME_LINES (f
);
6266 SET_FRAME_COLS (f
, 0);
6267 SET_FRAME_LINES (f
, 0);
6268 adjust_frame_size (f
, width
* FRAME_COLUMN_WIDTH (f
),
6269 height
* FRAME_LINE_HEIGHT (f
), 0, true, Qtip_frame
);
6271 /* Add `tooltip' frame parameter's default value. */
6272 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
6273 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
6275 /* Set up faces after all frame parameters are known. This call
6276 also merges in face attributes specified for new frames.
6278 Frame parameters may be changed if .Xdefaults contains
6279 specifications for the default font. For example, if there is an
6280 `Emacs.default.attributeBackground: pink', the `background-color'
6281 attribute of the frame get's set, which let's the internal border
6282 of the tooltip frame appear in pink. Prevent this. */
6284 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
6285 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
6286 Lisp_Object colors
= Qnil
;
6288 /* Set tip_frame here, so that */
6290 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
6292 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
6293 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
6294 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
6295 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
6298 Fmodify_frame_parameters (frame
, colors
);
6303 /* Now that the frame is official, it counts as a reference to
6305 FRAME_DISPLAY_INFO (f
)->reference_count
++;
6306 f
->terminal
->reference_count
++;
6308 /* It is now ok to make the frame official even if we get an error
6309 below. And the frame needs to be on Vframe_list or making it
6310 visible won't work. */
6311 Vframe_list
= Fcons (frame
, Vframe_list
);
6312 f
->can_x_set_window_size
= true;
6314 /* Setting attributes of faces of the tooltip frame from resources
6315 and similar will set face_change, which leads to the
6316 clearing of all current matrices. Since this isn't necessary
6317 here, avoid it by resetting face_change to the value it
6318 had before we created the tip frame. */
6319 face_change
= face_change_before
;
6321 /* Discard the unwind_protect. */
6322 return unbind_to (count
, frame
);
6326 /* Compute where to display tip frame F. PARMS is the list of frame
6327 parameters for F. DX and DY are specified offsets from the current
6328 location of the mouse. WIDTH and HEIGHT are the width and height
6329 of the tooltip. Return coordinates relative to the root window of
6330 the display in *ROOT_X and *ROOT_Y. */
6333 compute_tip_xy (struct frame
*f
,
6334 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
6335 int width
, int height
, int *root_x
, int *root_y
)
6337 Lisp_Object left
, top
, right
, bottom
;
6338 int min_x
, min_y
, max_x
, max_y
;
6340 /* User-specified position? */
6341 left
= Fcdr (Fassq (Qleft
, parms
));
6342 top
= Fcdr (Fassq (Qtop
, parms
));
6343 right
= Fcdr (Fassq (Qright
, parms
));
6344 bottom
= Fcdr (Fassq (Qbottom
, parms
));
6346 /* Move the tooltip window where the mouse pointer is. Resize and
6348 if ((!INTEGERP (left
) && !INTEGERP (right
))
6349 || (!INTEGERP (top
) && !INTEGERP (bottom
)))
6353 /* Default min and max values. */
6356 max_x
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
));
6357 max_y
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
));
6365 /* If multiple monitor support is available, constrain the tip onto
6366 the current monitor. This improves the above by allowing negative
6367 co-ordinates if monitor positions are such that they are valid, and
6368 snaps a tooltip onto a single monitor if we are close to the edge
6369 where it would otherwise flow onto the other monitor (or into
6370 nothingness if there is a gap in the overlap). */
6371 if (monitor_from_point_fn
&& get_monitor_info_fn
)
6373 struct MONITOR_INFO info
;
6375 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
6376 info
.cbSize
= sizeof (info
);
6378 if (get_monitor_info_fn (monitor
, &info
))
6380 min_x
= info
.rcWork
.left
;
6381 min_y
= info
.rcWork
.top
;
6382 max_x
= info
.rcWork
.right
;
6383 max_y
= info
.rcWork
.bottom
;
6389 *root_y
= XINT (top
);
6390 else if (INTEGERP (bottom
))
6391 *root_y
= XINT (bottom
) - height
;
6392 else if (*root_y
+ XINT (dy
) <= min_y
)
6393 *root_y
= min_y
; /* Can happen for negative dy */
6394 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
6395 /* It fits below the pointer */
6396 *root_y
+= XINT (dy
);
6397 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
6398 /* It fits above the pointer. */
6399 *root_y
-= height
+ XINT (dy
);
6401 /* Put it on the top. */
6404 if (INTEGERP (left
))
6405 *root_x
= XINT (left
);
6406 else if (INTEGERP (right
))
6407 *root_y
= XINT (right
) - width
;
6408 else if (*root_x
+ XINT (dx
) <= min_x
)
6409 *root_x
= 0; /* Can happen for negative dx */
6410 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
6411 /* It fits to the right of the pointer. */
6412 *root_x
+= XINT (dx
);
6413 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
6414 /* It fits to the left of the pointer. */
6415 *root_x
-= width
+ XINT (dx
);
6417 /* Put it left justified on the screen -- it ought to fit that way. */
6422 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
6423 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
6424 A tooltip window is a small window displaying a string.
6426 This is an internal function; Lisp code should call `tooltip-show'.
6428 FRAME nil or omitted means use the selected frame.
6430 PARMS is an optional list of frame parameters which can be
6431 used to change the tooltip's appearance.
6433 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
6434 means use the default timeout of 5 seconds.
6436 If the list of frame parameters PARMS contains a `left' parameter,
6437 display the tooltip at that x-position. If the list of frame parameters
6438 PARMS contains no `left' but a `right' parameter, display the tooltip
6439 right-adjusted at that x-position. Otherwise display it at the
6440 x-position of the mouse, with offset DX added (default is 5 if DX isn't
6443 Likewise for the y-position: If a `top' frame parameter is specified, it
6444 determines the position of the upper edge of the tooltip window. If a
6445 `bottom' parameter but no `top' frame parameter is specified, it
6446 determines the position of the lower edge of the tooltip window.
6447 Otherwise display the tooltip window at the y-position of the mouse,
6448 with offset DY added (default is -10).
6450 A tooltip's maximum size is specified by `x-max-tooltip-size'.
6451 Text larger than the specified size is clipped. */)
6452 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
6457 struct buffer
*old_buffer
;
6458 struct text_pos pos
;
6459 int i
, width
, height
;
6460 bool seen_reversed_p
;
6461 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6462 ptrdiff_t count
= SPECPDL_INDEX ();
6464 specbind (Qinhibit_redisplay
, Qt
);
6466 CHECK_STRING (string
);
6467 f
= decode_window_system_frame (frame
);
6469 timeout
= make_number (5);
6471 CHECK_NATNUM (timeout
);
6474 dx
= make_number (5);
6479 dy
= make_number (-10);
6483 if (NILP (last_show_tip_args
))
6484 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
6486 if (!NILP (tip_frame
))
6488 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
6489 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
6490 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
6492 if (EQ (frame
, last_frame
)
6493 && !NILP (Fequal (last_string
, string
))
6494 && !NILP (Fequal (last_parms
, parms
)))
6496 struct frame
*f
= XFRAME (tip_frame
);
6498 /* Only DX and DY have changed. */
6499 if (!NILP (tip_timer
))
6501 Lisp_Object timer
= tip_timer
;
6503 call1 (Qcancel_timer
, timer
);
6507 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
6508 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
6510 /* Put tooltip in topmost group and in position. */
6511 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6512 root_x
, root_y
, 0, 0,
6513 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6515 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6516 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6518 SWP_NOMOVE
| SWP_NOSIZE
6519 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6526 /* Hide a previous tip, if any. */
6529 ASET (last_show_tip_args
, 0, string
);
6530 ASET (last_show_tip_args
, 1, frame
);
6531 ASET (last_show_tip_args
, 2, parms
);
6533 /* Add default values to frame parameters. */
6534 if (NILP (Fassq (Qname
, parms
)))
6535 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
6536 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6537 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
6538 if (NILP (Fassq (Qright_divider_width
, parms
)))
6539 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
6540 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
6541 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
6542 if (NILP (Fassq (Qborder_width
, parms
)))
6543 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
6544 if (NILP (Fassq (Qborder_color
, parms
)))
6545 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
6546 if (NILP (Fassq (Qbackground_color
, parms
)))
6547 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
6550 /* Block input until the tip has been fully drawn, to avoid crashes
6551 when drawing tips in menus. */
6554 /* Create a frame for the tooltip, and record it in the global
6555 variable tip_frame. */
6556 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
6559 /* Set up the frame's root window. */
6560 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6566 if (CONSP (Vx_max_tooltip_size
)
6567 && INTEGERP (XCAR (Vx_max_tooltip_size
))
6568 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
6569 && INTEGERP (XCDR (Vx_max_tooltip_size
))
6570 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
6572 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
6573 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
6578 w
->total_lines
= 40;
6581 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
6582 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
6584 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
6585 adjust_frame_glyphs (f
);
6586 w
->pseudo_window_p
= true;
6588 /* Display the tooltip text in a temporary buffer. */
6589 old_buffer
= current_buffer
;
6590 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
6591 bset_truncate_lines (current_buffer
, Qnil
);
6592 clear_glyph_matrix (w
->desired_matrix
);
6593 clear_glyph_matrix (w
->current_matrix
);
6594 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
6595 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6597 /* Compute width and height of the tooltip. */
6599 seen_reversed_p
= false;
6600 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6602 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6606 /* Stop at the first empty row at the end. */
6607 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6610 /* Let the row go over the full width of the frame. */
6611 row
->full_width_p
= true;
6613 row_width
= row
->pixel_width
;
6614 if (row
->used
[TEXT_AREA
])
6616 if (!row
->reversed_p
)
6618 /* There's a glyph at the end of rows that is used to
6619 place the cursor there. Don't include the width of
6621 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6622 if (NILP (last
->object
))
6623 row_width
-= last
->pixel_width
;
6627 /* There could be a stretch glyph at the beginning of R2L
6628 rows that is produced by extend_face_to_end_of_line.
6629 Don't count that glyph. */
6630 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
6632 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
6634 row_width
-= g
->pixel_width
;
6635 seen_reversed_p
= true;
6640 height
+= row
->height
;
6641 width
= max (width
, row_width
);
6644 /* If we've seen partial-length R2L rows, we need to re-adjust the
6645 tool-tip frame width and redisplay it again, to avoid over-wide
6646 tips due to the stretch glyph that extends R2L lines to full
6647 width of the frame. */
6648 if (seen_reversed_p
)
6650 /* PXW: Why do we do the pixel-to-cols conversion only if
6651 seen_reversed_p holds? Don't we have to set other fields of
6652 the window/frame structure?
6654 w->total_cols and FRAME_TOTAL_COLS want the width in columns,
6656 w
->pixel_width
= width
;
6657 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
6658 w
->total_cols
= width
;
6659 FRAME_TOTAL_COLS (f
) = width
;
6660 SET_FRAME_WIDTH (f
, width
);
6661 adjust_frame_glyphs (f
);
6662 w
->pseudo_window_p
= 1;
6663 clear_glyph_matrix (w
->desired_matrix
);
6664 clear_glyph_matrix (w
->current_matrix
);
6665 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6667 /* Recompute width and height of the tooltip. */
6668 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6670 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6674 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6676 row
->full_width_p
= true;
6677 row_width
= row
->pixel_width
;
6678 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
6680 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6681 if (NILP (last
->object
))
6682 row_width
-= last
->pixel_width
;
6685 height
+= row
->height
;
6686 width
= max (width
, row_width
);
6690 /* Add the frame's internal border to the width and height the w32
6691 window should have. */
6692 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6693 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6695 /* Move the tooltip window where the mouse pointer is. Resize and
6698 PXW: This should use the frame's pixel coordinates. */
6699 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
6702 /* Adjust Window size to take border into account. */
6704 rect
.left
= rect
.top
= 0;
6706 rect
.bottom
= height
;
6707 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6708 FRAME_EXTERNAL_MENU_BAR (f
));
6710 /* Position and size tooltip, and put it in the topmost group.
6711 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
6712 peculiarity of w32 display: without it, some fonts cause the
6713 last character of the tip to be truncated or wrapped around to
6715 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6717 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
6718 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6720 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6721 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6723 SWP_NOMOVE
| SWP_NOSIZE
6724 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6726 /* Let redisplay know that we have made the frame visible already. */
6727 SET_FRAME_VISIBLE (f
, 1);
6729 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
6732 /* Draw into the window. */
6733 w
->must_be_updated_p
= true;
6734 update_single_window (w
);
6738 /* Restore original current buffer. */
6739 set_buffer_internal_1 (old_buffer
);
6740 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6743 /* Let the tip disappear after timeout seconds. */
6744 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
6745 intern ("x-hide-tip"));
6747 return unbind_to (count
, Qnil
);
6751 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
6752 doc
: /* Hide the current tooltip window, if there is any.
6753 Value is t if tooltip was open, nil otherwise. */)
6757 Lisp_Object deleted
, frame
, timer
;
6759 /* Return quickly if nothing to do. */
6760 if (NILP (tip_timer
) && NILP (tip_frame
))
6765 tip_frame
= tip_timer
= deleted
= Qnil
;
6767 count
= SPECPDL_INDEX ();
6768 specbind (Qinhibit_redisplay
, Qt
);
6769 specbind (Qinhibit_quit
, Qt
);
6772 call1 (Qcancel_timer
, timer
);
6776 delete_frame (frame
, Qnil
);
6780 return unbind_to (count
, deleted
);
6783 /***********************************************************************
6784 File selection dialog
6785 ***********************************************************************/
6787 #define FILE_NAME_TEXT_FIELD edt1
6788 #define FILE_NAME_COMBO_BOX cmb13
6789 #define FILE_NAME_LIST lst1
6791 /* Callback for altering the behavior of the Open File dialog.
6792 Makes the Filename text field contain "Current Directory" and be
6793 read-only when "Directories" is selected in the filter. This
6794 allows us to work around the fact that the standard Open File
6795 dialog does not support directories. */
6796 static UINT_PTR CALLBACK
6797 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6799 if (msg
== WM_NOTIFY
)
6801 OFNOTIFYW
* notify_w
= (OFNOTIFYW
*)lParam
;
6802 OFNOTIFYA
* notify_a
= (OFNOTIFYA
*)lParam
;
6803 int dropdown_changed
;
6805 #ifdef NTGUI_UNICODE
6806 const int use_unicode
= 1;
6807 #else /* !NTGUI_UNICODE */
6808 int use_unicode
= w32_unicode_filenames
;
6809 #endif /* NTGUI_UNICODE */
6811 /* Detect when the Filter dropdown is changed. */
6814 notify_w
->hdr
.code
== CDN_TYPECHANGE
6815 || notify_w
->hdr
.code
== CDN_INITDONE
;
6818 notify_a
->hdr
.code
== CDN_TYPECHANGE
6819 || notify_a
->hdr
.code
== CDN_INITDONE
;
6820 if (dropdown_changed
)
6822 HWND dialog
= GetParent (hwnd
);
6823 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6824 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6827 /* At least on Windows 7, the above attempt to get the window handle
6828 to the File Name Text Field fails. The following code does the
6829 job though. Note that this code is based on my examination of the
6830 window hierarchy using Microsoft Spy++. bk */
6831 if (edit_control
== NULL
)
6833 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6836 tmp
= GetWindow (tmp
, GW_CHILD
);
6838 edit_control
= GetWindow (tmp
, GW_CHILD
);
6842 /* Directories is in index 2. */
6845 dir_index
= notify_w
->lpOFN
->nFilterIndex
;
6846 hdr_code
= notify_w
->hdr
.code
;
6850 dir_index
= notify_a
->lpOFN
->nFilterIndex
;
6851 hdr_code
= notify_a
->hdr
.code
;
6856 SendMessageW (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6857 (LPARAM
)L
"Current Directory");
6859 SendMessageA (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6860 (LPARAM
)"Current Directory");
6861 EnableWindow (edit_control
, FALSE
);
6862 /* Note that at least on Windows 7, the above call to EnableWindow
6863 disables the window that would ordinarily have focus. If we
6864 do not set focus to some other window here, focus will land in
6865 no man's land and the user will be unable to tab through the
6866 dialog box (pressing tab will only result in a beep).
6867 Avoid that problem by setting focus to the list here. */
6868 if (hdr_code
== CDN_INITDONE
)
6873 /* Don't override default filename on init done. */
6874 if (hdr_code
== CDN_TYPECHANGE
)
6877 SendMessageW (dialog
, CDM_SETCONTROLTEXT
,
6878 FILE_NAME_TEXT_FIELD
, (LPARAM
)L
"");
6880 SendMessageA (dialog
, CDM_SETCONTROLTEXT
,
6881 FILE_NAME_TEXT_FIELD
, (LPARAM
)"");
6883 EnableWindow (edit_control
, TRUE
);
6890 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6891 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6892 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6893 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6894 or directory must exist.
6896 This function is only defined on NS, MS Windows, and X Windows with the
6897 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6898 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6899 On Windows 7 and later, the file selection dialog "remembers" the last
6900 directory where the user selected a file, and will open that directory
6901 instead of DIR on subsequent invocations of this function with the same
6902 value of DIR as in previous invocations; this is standard Windows behavior. */)
6903 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6905 /* Filter index: 1: All Files, 2: Directories only */
6906 static const wchar_t filter_w
[] = L
"All Files (*.*)\0*.*\0Directories\0*|*\0";
6907 static const char filter_a
[] = "All Files (*.*)\0*.*\0Directories\0*|*\0";
6909 Lisp_Object filename
= default_filename
;
6910 struct frame
*f
= SELECTED_FRAME ();
6911 BOOL file_opened
= FALSE
;
6912 Lisp_Object orig_dir
= dir
;
6913 Lisp_Object orig_prompt
= prompt
;
6915 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6916 compatibility) we end up with the old file dialogs. Define a big
6917 enough struct for the new dialog to trick GetOpenFileName into
6918 giving us the new dialogs on newer versions of Windows. */
6920 OPENFILENAMEW details
;
6921 #if _WIN32_WINNT < 0x500 /* < win2k */
6925 #endif /* < win2k */
6926 } new_file_details_w
;
6928 #ifdef NTGUI_UNICODE
6929 wchar_t filename_buf_w
[32*1024 + 1]; // NT kernel maximum
6930 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6931 const int use_unicode
= 1;
6932 #else /* not NTGUI_UNICODE */
6934 OPENFILENAMEA details
;
6935 #if _WIN32_WINNT < 0x500 /* < win2k */
6939 #endif /* < win2k */
6940 } new_file_details_a
;
6941 wchar_t filename_buf_w
[MAX_PATH
+ 1], dir_w
[MAX_PATH
];
6942 char filename_buf_a
[MAX_PATH
+ 1], dir_a
[MAX_PATH
];
6943 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6944 OPENFILENAMEA
* file_details_a
= &new_file_details_a
.details
;
6945 int use_unicode
= w32_unicode_filenames
;
6949 char fname_ret
[MAX_UTF8_PATH
];
6950 #endif /* NTGUI_UNICODE */
6953 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6954 system file encoding expected by the platform APIs (e.g. Cygwin's
6955 POSIX implementation) may not be the same as the encoding expected
6956 by the Windows "ANSI" APIs! */
6958 CHECK_STRING (prompt
);
6961 dir
= Fexpand_file_name (dir
, Qnil
);
6963 if (STRINGP (filename
))
6964 filename
= Ffile_name_nondirectory (filename
);
6966 filename
= empty_unibyte_string
;
6969 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6970 if (SCHARS (filename
) > 0)
6971 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6975 CHECK_STRING (filename
);
6977 /* The code in file_dialog_callback that attempts to set the text
6978 of the file name edit window when handling the CDN_INITDONE
6979 WM_NOTIFY message does not work. Setting filename to "Current
6980 Directory" in the only_dir_p case here does work however. */
6981 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6982 filename
= build_string ("Current Directory");
6984 /* Convert the values we've computed so far to system form. */
6985 #ifdef NTGUI_UNICODE
6986 to_unicode (prompt
, &prompt
);
6987 to_unicode (dir
, &dir
);
6988 to_unicode (filename
, &filename
);
6989 if (SBYTES (filename
) + 1 > sizeof (filename_buf_w
))
6990 report_file_error ("filename too long", default_filename
);
6992 memcpy (filename_buf_w
, SDATA (filename
), SBYTES (filename
) + 1);
6993 #else /* !NTGUI_UNICODE */
6994 prompt
= ENCODE_FILE (prompt
);
6995 dir
= ENCODE_FILE (dir
);
6996 filename
= ENCODE_FILE (filename
);
6998 /* We modify these in-place, so make copies for safety. */
6999 dir
= Fcopy_sequence (dir
);
7000 unixtodos_filename (SDATA (dir
));
7001 filename
= Fcopy_sequence (filename
);
7002 unixtodos_filename (SDATA (filename
));
7003 if (SBYTES (filename
) >= MAX_UTF8_PATH
)
7004 report_file_error ("filename too long", default_filename
);
7005 if (w32_unicode_filenames
)
7007 filename_to_utf16 (SSDATA (dir
), dir_w
);
7008 if (filename_to_utf16 (SSDATA (filename
), filename_buf_w
) != 0)
7010 /* filename_to_utf16 sets errno to ENOENT when the file
7011 name is too long or cannot be converted to UTF-16. */
7012 if (errno
== ENOENT
&& filename_buf_w
[MAX_PATH
- 1] != 0)
7013 report_file_error ("filename too long", default_filename
);
7015 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7016 SSDATA (prompt
), -1, NULL
, 0);
7019 prompt_w
= alloca (len
* sizeof (wchar_t));
7020 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7021 SSDATA (prompt
), -1, prompt_w
, len
);
7025 filename_to_ansi (SSDATA (dir
), dir_a
);
7026 if (filename_to_ansi (SSDATA (filename
), filename_buf_a
) != '\0')
7028 /* filename_to_ansi sets errno to ENOENT when the file
7029 name is too long or cannot be converted to UTF-16. */
7030 if (errno
== ENOENT
&& filename_buf_a
[MAX_PATH
- 1] != 0)
7031 report_file_error ("filename too long", default_filename
);
7033 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7034 SSDATA (prompt
), -1, NULL
, 0);
7037 prompt_w
= alloca (len
* sizeof (wchar_t));
7038 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7039 SSDATA (prompt
), -1, prompt_w
, len
);
7040 len
= pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, NULL
, 0, NULL
, NULL
);
7043 prompt_a
= alloca (len
);
7044 pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, prompt_a
, len
, NULL
, NULL
);
7046 #endif /* NTGUI_UNICODE */
7048 /* Fill in the structure for the call to GetOpenFileName below.
7049 For NTGUI_UNICODE builds (which run only on NT), we just use
7050 the actual size of the structure. For non-NTGUI_UNICODE
7051 builds, we tell the OS we're using an old version of the
7052 structure if the OS isn't new enough to support the newer
7056 memset (&new_file_details_w
, 0, sizeof (new_file_details_w
));
7057 if (w32_major_version
> 4 && w32_major_version
< 95)
7058 file_details_w
->lStructSize
= sizeof (new_file_details_w
);
7060 file_details_w
->lStructSize
= sizeof (*file_details_w
);
7061 /* Set up the inout parameter for the selected file name. */
7062 file_details_w
->lpstrFile
= filename_buf_w
;
7063 file_details_w
->nMaxFile
=
7064 sizeof (filename_buf_w
) / sizeof (*filename_buf_w
);
7065 file_details_w
->hwndOwner
= FRAME_W32_WINDOW (f
);
7066 /* Undocumented Bug in Common File Dialog:
7067 If a filter is not specified, shell links are not resolved. */
7068 file_details_w
->lpstrFilter
= filter_w
;
7069 #ifdef NTGUI_UNICODE
7070 file_details_w
->lpstrInitialDir
= (wchar_t*) SDATA (dir
);
7071 file_details_w
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
7073 file_details_w
->lpstrInitialDir
= dir_w
;
7074 file_details_w
->lpstrTitle
= prompt_w
;
7076 file_details_w
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
7077 file_details_w
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7078 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7079 if (!NILP (mustmatch
))
7081 /* Require that the path to the parent directory exists. */
7082 file_details_w
->Flags
|= OFN_PATHMUSTEXIST
;
7083 /* If we are looking for a file, require that it exists. */
7084 if (NILP (only_dir_p
))
7085 file_details_w
->Flags
|= OFN_FILEMUSTEXIST
;
7088 #ifndef NTGUI_UNICODE
7091 memset (&new_file_details_a
, 0, sizeof (new_file_details_a
));
7092 if (w32_major_version
> 4 && w32_major_version
< 95)
7093 file_details_a
->lStructSize
= sizeof (new_file_details_a
);
7095 file_details_a
->lStructSize
= sizeof (*file_details_a
);
7096 file_details_a
->lpstrFile
= filename_buf_a
;
7097 file_details_a
->nMaxFile
=
7098 sizeof (filename_buf_a
) / sizeof (*filename_buf_a
);
7099 file_details_a
->hwndOwner
= FRAME_W32_WINDOW (f
);
7100 file_details_a
->lpstrFilter
= filter_a
;
7101 file_details_a
->lpstrInitialDir
= dir_a
;
7102 file_details_a
->lpstrTitle
= prompt_a
;
7103 file_details_a
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
7104 file_details_a
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
7105 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
7106 if (!NILP (mustmatch
))
7108 /* Require that the path to the parent directory exists. */
7109 file_details_a
->Flags
|= OFN_PATHMUSTEXIST
;
7110 /* If we are looking for a file, require that it exists. */
7111 if (NILP (only_dir_p
))
7112 file_details_a
->Flags
|= OFN_FILEMUSTEXIST
;
7115 #endif /* !NTGUI_UNICODE */
7118 int count
= SPECPDL_INDEX ();
7119 /* Prevent redisplay. */
7120 specbind (Qinhibit_redisplay
, Qt
);
7124 file_details_w
->lpfnHook
= file_dialog_callback
;
7126 file_opened
= GetOpenFileNameW (file_details_w
);
7128 #ifndef NTGUI_UNICODE
7131 file_details_a
->lpfnHook
= file_dialog_callback
;
7133 file_opened
= GetOpenFileNameA (file_details_a
);
7135 #endif /* !NTGUI_UNICODE */
7137 unbind_to (count
, Qnil
);
7142 /* Get an Emacs string from the value Windows gave us. */
7143 #ifdef NTGUI_UNICODE
7144 filename
= from_unicode_buffer (filename_buf_w
);
7145 #else /* !NTGUI_UNICODE */
7147 filename_from_utf16 (filename_buf_w
, fname_ret
);
7149 filename_from_ansi (filename_buf_a
, fname_ret
);
7150 dostounix_filename (fname_ret
);
7151 filename
= DECODE_FILE (build_unibyte_string (fname_ret
));
7152 #endif /* NTGUI_UNICODE */
7155 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
7158 /* Strip the dummy filename off the end of the string if we
7159 added it to select a directory. */
7160 if ((use_unicode
&& file_details_w
->nFilterIndex
== 2)
7161 #ifndef NTGUI_UNICODE
7162 || (!use_unicode
&& file_details_a
->nFilterIndex
== 2)
7165 filename
= Ffile_name_directory (filename
);
7167 /* User canceled the dialog without making a selection. */
7168 else if (!CommDlgExtendedError ())
7170 /* An error occurred, fallback on reading from the mini-buffer. */
7172 filename
= Fcompleting_read (
7174 intern ("read-file-name-internal"),
7183 /* Make "Cancel" equivalent to C-g. */
7184 if (NILP (filename
))
7185 Fsignal (Qquit
, Qnil
);
7192 /* Moving files to the system recycle bin.
7193 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
7194 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
7195 Ssystem_move_file_to_trash
, 1, 1, 0,
7196 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
7197 (Lisp_Object filename
)
7199 Lisp_Object handler
;
7200 Lisp_Object encoded_file
;
7201 Lisp_Object operation
;
7203 operation
= Qdelete_file
;
7204 if (!NILP (Ffile_directory_p (filename
))
7205 && NILP (Ffile_symlink_p (filename
)))
7207 operation
= intern ("delete-directory");
7208 filename
= Fdirectory_file_name (filename
);
7211 /* Must have fully qualified file names for moving files to Recycle
7213 filename
= Fexpand_file_name (filename
, Qnil
);
7215 handler
= Ffind_file_name_handler (filename
, operation
);
7216 if (!NILP (handler
))
7217 return call2 (handler
, operation
, filename
);
7223 encoded_file
= ENCODE_FILE (filename
);
7225 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
7227 /* The Unicode version of SHFileOperation is not supported on
7229 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7231 SHFILEOPSTRUCTW file_op_w
;
7232 /* We need one more element beyond MAX_PATH because this is
7233 a list of file names, with the last element double-null
7235 wchar_t tmp_path_w
[MAX_PATH
+ 1];
7237 memset (tmp_path_w
, 0, sizeof (tmp_path_w
));
7238 filename_to_utf16 (path
, tmp_path_w
);
7240 /* On Windows, write permission is required to delete/move files. */
7241 _wchmod (tmp_path_w
, 0666);
7243 memset (&file_op_w
, 0, sizeof (file_op_w
));
7244 file_op_w
.hwnd
= HWND_DESKTOP
;
7245 file_op_w
.wFunc
= FO_DELETE
;
7246 file_op_w
.pFrom
= tmp_path_w
;
7247 file_op_w
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
7248 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
7249 file_op_w
.fAnyOperationsAborted
= FALSE
;
7251 result
= SHFileOperationW (&file_op_w
);
7255 SHFILEOPSTRUCTA file_op_a
;
7256 char tmp_path_a
[MAX_PATH
+ 1];
7258 memset (tmp_path_a
, 0, sizeof (tmp_path_a
));
7259 filename_to_ansi (path
, tmp_path_a
);
7261 /* If a file cannot be represented in ANSI codepage, don't
7262 let them inadvertently delete other files because some
7263 characters are interpreted as a wildcards. */
7264 if (_mbspbrk (tmp_path_a
, "?*"))
7265 result
= ERROR_FILE_NOT_FOUND
;
7268 _chmod (tmp_path_a
, 0666);
7270 memset (&file_op_a
, 0, sizeof (file_op_a
));
7271 file_op_a
.hwnd
= HWND_DESKTOP
;
7272 file_op_a
.wFunc
= FO_DELETE
;
7273 file_op_a
.pFrom
= tmp_path_a
;
7274 file_op_a
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
7275 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
7276 file_op_a
.fAnyOperationsAborted
= FALSE
;
7278 result
= SHFileOperationA (&file_op_a
);
7282 report_file_error ("Removing old name", list1 (filename
));
7287 #endif /* WINDOWSNT */
7290 /***********************************************************************
7291 w32 specialized functions
7292 ***********************************************************************/
7294 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
7295 Sw32_send_sys_command
, 1, 2, 0,
7296 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
7297 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
7298 to minimize), #xf120 to restore frame to original size, and #xf100
7299 to activate the menubar for keyboard access. #xf140 activates the
7300 screen saver if defined.
7302 If optional parameter FRAME is not specified, use selected frame. */)
7303 (Lisp_Object command
, Lisp_Object frame
)
7305 struct frame
*f
= decode_window_system_frame (frame
);
7307 CHECK_NUMBER (command
);
7309 if (FRAME_W32_P (f
))
7310 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
7315 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
7316 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
7317 This is a wrapper around the ShellExecute system function, which
7318 invokes the application registered to handle OPERATION for DOCUMENT.
7320 OPERATION is either nil or a string that names a supported operation.
7321 What operations can be used depends on the particular DOCUMENT and its
7322 handler application, but typically it is one of the following common
7325 \"open\" - open DOCUMENT, which could be a file, a directory, or an
7326 executable program (application). If it is an application,
7327 that application is launched in the current buffer's default
7328 directory. Otherwise, the application associated with
7329 DOCUMENT is launched in the buffer's default directory.
7330 \"opennew\" - like \"open\", but instruct the application to open
7331 DOCUMENT in a new window.
7332 \"openas\" - open the \"Open With\" dialog for DOCUMENT.
7333 \"print\" - print DOCUMENT, which must be a file.
7334 \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
7335 The printer should be provided in PARAMETERS, see below.
7336 \"explore\" - start the Windows Explorer on DOCUMENT.
7337 \"edit\" - launch an editor and open DOCUMENT for editing; which
7338 editor is launched depends on the association for the
7340 \"find\" - initiate search starting from DOCUMENT, which must specify
7342 \"delete\" - move DOCUMENT, a file or a directory, to Recycle Bin.
7343 \"copy\" - copy DOCUMENT, which must be a file or a directory, into
7345 \"cut\" - move DOCUMENT, a file or a directory, into the clipboard.
7346 \"paste\" - paste the file whose name is in the clipboard into DOCUMENT,
7347 which must be a directory.
7349 - create a shortcut in DOCUMENT (which must be a directory)
7350 the file or directory whose name is in the clipboard.
7351 \"runas\" - run DOCUMENT, which must be an excutable file, with
7352 elevated privileges (a.k.a. \"as Administrator\").
7354 - open the property sheet dialog for DOCUMENT.
7355 nil - invoke the default OPERATION, or \"open\" if default is
7356 not defined or unavailable.
7358 DOCUMENT is typically the name of a document file or a URL, but can
7359 also be an executable program to run, or a directory to open in the
7360 Windows Explorer. If it is a file or a directory, it must be a local
7361 one; this function does not support remote file names.
7363 If DOCUMENT is an executable program, the optional third arg PARAMETERS
7364 can be a string containing command line parameters, separated by blanks,
7365 that will be passed to the program. Some values of OPERATION also require
7366 parameters (e.g., \"printto\" requires the printer address). Otherwise,
7367 PARAMETERS should be nil or unspecified. Note that double quote characters
7368 in PARAMETERS must each be enclosed in 2 additional quotes, as in \"\"\".
7370 Optional fourth argument SHOW-FLAG can be used to control how the
7371 application will be displayed when it is invoked. If SHOW-FLAG is nil
7372 or unspecified, the application is displayed as if SHOW-FLAG of 10 was
7373 specified, otherwise it is an integer between 0 and 11 representing
7377 1 - start as normal-size window
7378 3 - start in a maximized window
7379 6 - start in a minimized window
7380 10 - start as the application itself specifies; this is the default. */)
7381 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
7384 Lisp_Object current_dir
= BVAR (current_buffer
, directory
);;
7385 wchar_t *doc_w
= NULL
, *params_w
= NULL
, *ops_w
= NULL
;
7389 int use_unicode
= w32_unicode_filenames
;
7390 char *doc_a
= NULL
, *params_a
= NULL
, *ops_a
= NULL
;
7391 Lisp_Object absdoc
, handler
;
7395 CHECK_STRING (document
);
7398 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
7399 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
7401 /* Encode filename, current directory and parameters. */
7402 current_dir
= GUI_ENCODE_FILE (current_dir
);
7403 document
= GUI_ENCODE_FILE (document
);
7404 doc_w
= GUI_SDATA (document
);
7405 if (STRINGP (parameters
))
7407 parameters
= GUI_ENCODE_SYSTEM (parameters
);
7408 params_w
= GUI_SDATA (parameters
);
7410 if (STRINGP (operation
))
7412 operation
= GUI_ENCODE_SYSTEM (operation
);
7413 ops_w
= GUI_SDATA (operation
);
7415 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
7416 GUI_SDATA (current_dir
),
7417 (INTEGERP (show_flag
)
7418 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
7425 case SE_ERR_ACCESSDENIED
:
7426 errstr
= w32_strerror (ERROR_ACCESS_DENIED
);
7428 case SE_ERR_ASSOCINCOMPLETE
:
7429 case SE_ERR_NOASSOC
:
7430 errstr
= w32_strerror (ERROR_NO_ASSOCIATION
);
7432 case SE_ERR_DDEBUSY
:
7433 case SE_ERR_DDEFAIL
:
7434 errstr
= w32_strerror (ERROR_DDE_FAIL
);
7436 case SE_ERR_DDETIMEOUT
:
7437 errstr
= w32_strerror (ERROR_TIMEOUT
);
7439 case SE_ERR_DLLNOTFOUND
:
7440 errstr
= w32_strerror (ERROR_DLL_NOT_FOUND
);
7443 errstr
= w32_strerror (ERROR_FILE_NOT_FOUND
);
7446 errstr
= w32_strerror (ERROR_NOT_ENOUGH_MEMORY
);
7449 errstr
= w32_strerror (ERROR_PATH_NOT_FOUND
);
7452 errstr
= w32_strerror (ERROR_SHARING_VIOLATION
);
7455 errstr
= w32_strerror (0);
7461 const char file_url_str
[] = "file:///";
7462 const int file_url_len
= sizeof (file_url_str
) - 1;
7465 if (strncmp (SSDATA (document
), file_url_str
, file_url_len
) == 0)
7467 /* Passing "file:///" URLs to ShellExecute causes shlwapi.dll to
7468 start a thread in some rare system configurations, for
7469 unknown reasons. That thread is started in the context of
7470 the Emacs process, but out of control of our code, and seems
7471 to never exit afterwards. Each such thread reserves 8MB of
7472 stack space (because that's the value recorded in the Emacs
7473 executable at link time: Emacs needs a large stack). So a
7474 large enough number of invocations of w32-shell-execute can
7475 potentially cause the Emacs process to run out of available
7476 address space, which is nasty. To work around this, we
7477 convert such URLs to local file names, which seems to prevent
7478 those threads from starting. See bug #20220. */
7479 char *p
= SSDATA (document
) + file_url_len
;
7481 if (c_isalpha (*p
) && p
[1] == ':' && IS_DIRECTORY_SEP (p
[2]))
7482 document
= Fsubstring_no_properties (document
,
7483 make_number (file_url_len
), Qnil
);
7485 /* We have a situation here. If DOCUMENT is a relative file name,
7486 but its name includes leading directories, i.e. it lives not in
7487 CURRENT_DIR, but in its subdirectory, then ShellExecute below
7488 will fail to find it. So we need to make the file name is
7489 absolute. But DOCUMENT does not have to be a file, it can be a
7490 URL, for example. So we make it absolute only if it is an
7491 existing file; if it is a file that does not exist, tough. */
7492 absdoc
= Fexpand_file_name (document
, Qnil
);
7493 /* Don't call file handlers for file-exists-p, since they might
7494 attempt to access the file, which could fail or produce undesired
7495 consequences, see bug#16558 for an example. */
7496 handler
= Ffind_file_name_handler (absdoc
, Qfile_exists_p
);
7499 Lisp_Object absdoc_encoded
= ENCODE_FILE (absdoc
);
7501 if (faccessat (AT_FDCWD
, SSDATA (absdoc_encoded
), F_OK
, AT_EACCESS
) == 0)
7503 /* ShellExecute fails if DOCUMENT is a UNC with forward
7504 slashes (expand-file-name above converts all backslashes
7505 to forward slashes). Now that we know DOCUMENT is a
7506 file, we can mirror all forward slashes into backslashes. */
7507 unixtodos_filename (SSDATA (absdoc_encoded
));
7508 document
= absdoc_encoded
;
7511 document
= ENCODE_FILE (document
);
7514 document
= ENCODE_FILE (document
);
7516 current_dir
= ENCODE_FILE (current_dir
);
7517 /* Cannot use filename_to_utf16/ansi with DOCUMENT, since it could
7518 be a URL that is not limited to MAX_PATH chararcters. */
7519 doclen
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7520 SSDATA (document
), -1, NULL
, 0);
7521 doc_w
= xmalloc (doclen
* sizeof (wchar_t));
7522 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
7523 SSDATA (document
), -1, doc_w
, doclen
);
7526 wchar_t current_dir_w
[MAX_PATH
];
7527 SHELLEXECUTEINFOW shexinfo_w
;
7529 /* Encode the current directory and parameters, and convert
7530 operation to UTF-16. */
7531 filename_to_utf16 (SSDATA (current_dir
), current_dir_w
);
7532 if (STRINGP (parameters
))
7536 parameters
= ENCODE_SYSTEM (parameters
);
7537 len
= pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7538 SSDATA (parameters
), -1, NULL
, 0);
7541 params_w
= alloca (len
* sizeof (wchar_t));
7542 pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7543 SSDATA (parameters
), -1, params_w
, len
);
7544 params_w
[len
- 1] = 0;
7546 if (STRINGP (operation
))
7548 /* Assume OPERATION is pure ASCII. */
7549 const char *s
= SSDATA (operation
);
7551 int len
= SBYTES (operation
) + 1;
7555 d
= ops_w
= alloca (len
* sizeof (wchar_t));
7556 while (d
< ops_w
+ len
- 1)
7561 /* Using ShellExecuteEx and setting the SEE_MASK_INVOKEIDLIST
7562 flag succeeds with more OPERATIONs (a.k.a. "verbs"), as it is
7563 able to invoke verbs from shortcut menu extensions, not just
7564 static verbs listed in the Registry. */
7565 memset (&shexinfo_w
, 0, sizeof (shexinfo_w
));
7566 shexinfo_w
.cbSize
= sizeof (shexinfo_w
);
7568 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7569 shexinfo_w
.hwnd
= NULL
;
7570 shexinfo_w
.lpVerb
= ops_w
;
7571 shexinfo_w
.lpFile
= doc_w
;
7572 shexinfo_w
.lpParameters
= params_w
;
7573 shexinfo_w
.lpDirectory
= current_dir_w
;
7575 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7576 success
= ShellExecuteExW (&shexinfo_w
);
7581 char current_dir_a
[MAX_PATH
];
7582 SHELLEXECUTEINFOA shexinfo_a
;
7583 int codepage
= codepage_for_filenames (NULL
);
7584 int ldoc_a
= pWideCharToMultiByte (codepage
, 0, doc_w
, -1, NULL
, 0,
7587 doc_a
= xmalloc (ldoc_a
);
7588 pWideCharToMultiByte (codepage
, 0, doc_w
, -1, doc_a
, ldoc_a
, NULL
, NULL
);
7589 filename_to_ansi (SSDATA (current_dir
), current_dir_a
);
7590 if (STRINGP (parameters
))
7592 parameters
= ENCODE_SYSTEM (parameters
);
7593 params_a
= SSDATA (parameters
);
7595 if (STRINGP (operation
))
7597 /* Assume OPERATION is pure ASCII. */
7598 ops_a
= SSDATA (operation
);
7600 memset (&shexinfo_a
, 0, sizeof (shexinfo_a
));
7601 shexinfo_a
.cbSize
= sizeof (shexinfo_a
);
7603 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7604 shexinfo_a
.hwnd
= NULL
;
7605 shexinfo_a
.lpVerb
= ops_a
;
7606 shexinfo_a
.lpFile
= doc_a
;
7607 shexinfo_a
.lpParameters
= params_a
;
7608 shexinfo_a
.lpDirectory
= current_dir_a
;
7610 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7611 success
= ShellExecuteExA (&shexinfo_a
);
7619 errstr
= w32_strerror (0);
7621 #endif /* !CYGWIN */
7623 /* The error string might be encoded in the locale's encoding. */
7624 if (!NILP (Vlocale_coding_system
))
7626 Lisp_Object decoded
=
7627 code_convert_string_norecord (build_unibyte_string (errstr
),
7628 Vlocale_coding_system
, 0);
7629 errstr
= SSDATA (decoded
);
7631 error ("ShellExecute failed: %s", errstr
);
7634 /* Lookup virtual keycode from string representing the name of a
7635 non-ascii keystroke into the corresponding virtual key, using
7636 lispy_function_keys. */
7638 lookup_vk_code (char *key
)
7642 for (i
= 0; i
< 256; i
++)
7643 if (lispy_function_keys
[i
]
7644 && strcmp (lispy_function_keys
[i
], key
) == 0)
7650 /* Convert a one-element vector style key sequence to a hot key
7653 w32_parse_hot_key (Lisp_Object key
)
7655 /* Copied from Fdefine_key and store_in_keymap. */
7656 register Lisp_Object c
;
7663 if (ASIZE (key
) != 1)
7668 if (CONSP (c
) && lucid_event_type_list_p (c
))
7669 c
= Fevent_convert_list (c
);
7671 if (! INTEGERP (c
) && ! SYMBOLP (c
))
7672 error ("Key definition is invalid");
7674 /* Work out the base key and the modifiers. */
7677 c
= parse_modifiers (c
);
7678 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
7682 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
7684 else if (INTEGERP (c
))
7686 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
7687 /* Many ascii characters are their own virtual key code. */
7688 vk_code
= XINT (c
) & CHARACTERBITS
;
7691 if (vk_code
< 0 || vk_code
> 255)
7694 if ((lisp_modifiers
& meta_modifier
) != 0
7695 && !NILP (Vw32_alt_is_meta
))
7696 lisp_modifiers
|= alt_modifier
;
7698 /* Supply defs missing from mingw32. */
7700 #define MOD_ALT 0x0001
7701 #define MOD_CONTROL 0x0002
7702 #define MOD_SHIFT 0x0004
7703 #define MOD_WIN 0x0008
7706 /* Convert lisp modifiers to Windows hot-key form. */
7707 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
7708 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
7709 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
7710 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
7712 return HOTKEY (vk_code
, w32_modifiers
);
7715 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
7716 Sw32_register_hot_key
, 1, 1, 0,
7717 doc
: /* Register KEY as a hot-key combination.
7718 Certain key combinations like Alt-Tab are reserved for system use on
7719 Windows, and therefore are normally intercepted by the system. However,
7720 most of these key combinations can be received by registering them as
7721 hot-keys, overriding their special meaning.
7723 KEY must be a one element key definition in vector form that would be
7724 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
7725 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
7726 is always interpreted as the Windows modifier keys.
7728 The return value is the hotkey-id if registered, otherwise nil. */)
7731 key
= w32_parse_hot_key (key
);
7733 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
7735 /* Reuse an empty slot if possible. */
7736 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
7738 /* Safe to add new key to list, even if we have focus. */
7740 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
7742 XSETCAR (item
, key
);
7744 /* Notify input thread about new hot-key definition, so that it
7745 takes effect without needing to switch focus. */
7746 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
7747 (WPARAM
) XINT (key
), 0);
7753 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
7754 Sw32_unregister_hot_key
, 1, 1, 0,
7755 doc
: /* Unregister KEY as a hot-key combination. */)
7760 if (!INTEGERP (key
))
7761 key
= w32_parse_hot_key (key
);
7763 item
= Fmemq (key
, w32_grabbed_keys
);
7769 eassert (CONSP (item
));
7770 /* Pass the tail of the list as a pointer to a Lisp_Cons cell,
7771 so that it works in a --with-wide-int build as well. */
7772 lparam
= (LPARAM
) XUNTAG (item
, Lisp_Cons
);
7774 /* Notify input thread about hot-key definition being removed, so
7775 that it takes effect without needing focus switch. */
7776 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
7777 (WPARAM
) XINT (XCAR (item
)), lparam
))
7780 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7787 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
7788 Sw32_registered_hot_keys
, 0, 0, 0,
7789 doc
: /* Return list of registered hot-key IDs. */)
7792 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
7795 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
7796 Sw32_reconstruct_hot_key
, 1, 1, 0,
7797 doc
: /* Convert hot-key ID to a lisp key combination.
7798 usage: (w32-reconstruct-hot-key ID) */)
7799 (Lisp_Object hotkeyid
)
7801 int vk_code
, w32_modifiers
;
7804 CHECK_NUMBER (hotkeyid
);
7806 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
7807 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
7809 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
7810 key
= intern (lispy_function_keys
[vk_code
]);
7812 key
= make_number (vk_code
);
7814 key
= Fcons (key
, Qnil
);
7815 if (w32_modifiers
& MOD_SHIFT
)
7816 key
= Fcons (Qshift
, key
);
7817 if (w32_modifiers
& MOD_CONTROL
)
7818 key
= Fcons (Qctrl
, key
);
7819 if (w32_modifiers
& MOD_ALT
)
7820 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
7821 if (w32_modifiers
& MOD_WIN
)
7822 key
= Fcons (Qhyper
, key
);
7827 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
7828 Sw32_toggle_lock_key
, 1, 2, 0,
7829 doc
: /* Toggle the state of the lock key KEY.
7830 KEY can be `capslock', `kp-numlock', or `scroll'.
7831 If the optional parameter NEW-STATE is a number, then the state of KEY
7832 is set to off if the low bit of NEW-STATE is zero, otherwise on.
7833 If NEW-STATE is omitted or nil, the function toggles the state,
7835 Value is the new state of the key, or nil if the function failed
7836 to change the state. */)
7837 (Lisp_Object key
, Lisp_Object new_state
)
7842 if (EQ (key
, intern ("capslock")))
7843 vk_code
= VK_CAPITAL
;
7844 else if (EQ (key
, intern ("kp-numlock")))
7845 vk_code
= VK_NUMLOCK
;
7846 else if (EQ (key
, intern ("scroll")))
7847 vk_code
= VK_SCROLL
;
7851 if (!dwWindowsThreadId
)
7852 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
7854 if (NILP (new_state
))
7857 lparam
= (XUINT (new_state
)) & 1;
7858 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
7859 (WPARAM
) vk_code
, lparam
))
7862 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7863 return make_number (msg
.wParam
);
7868 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
7870 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
7872 This is a direct interface to the Windows API FindWindow function. */)
7873 (Lisp_Object
class, Lisp_Object name
)
7878 CHECK_STRING (class);
7880 CHECK_STRING (name
);
7882 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
7883 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
7889 DEFUN ("w32-frame-geometry", Fw32_frame_geometry
, Sw32_frame_geometry
, 0, 1, 0,
7890 doc
: /* Return geometric attributes of FRAME.
7891 FRAME must be a live frame and defaults to the selected one. The return
7892 value is an association list of the attributes listed below. All height
7893 and width values are in pixels.
7895 `outer-position' is a cons of the outer left and top edges of FRAME
7896 relative to the origin - the position (0, 0) - of FRAME's display.
7898 `outer-size' is a cons of the outer width and height of FRAME. The
7899 outer size includes the title bar and the external borders as well as
7900 any menu and/or tool bar of frame.
7902 `external-border-size' is a cons of the horizontal and vertical width of
7903 FRAME's external borders as supplied by the window manager.
7905 `title-bar-size' is a cons of the width and height of the title bar of
7906 FRAME as supplied by the window manager. If both of them are zero,
7907 FRAME has no title bar. If only the width is zero, Emacs was not
7908 able to retrieve the width information.
7910 `menu-bar-external', if non-nil, means the menu bar is external (never
7911 included in the inner edges of FRAME).
7913 `menu-bar-size' is a cons of the width and height of the menu bar of
7916 `tool-bar-external', if non-nil, means the tool bar is external (never
7917 included in the inner edges of FRAME).
7919 `tool-bar-position' tells on which side the tool bar on FRAME is and can
7920 be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
7923 `tool-bar-size' is a cons of the width and height of the tool bar of
7926 `internal-border-width' is the width of the internal border of
7930 struct frame
*f
= decode_live_frame (frame
);
7932 MENUBARINFO menu_bar
;
7934 int left
, top
, right
, bottom
;
7935 unsigned int external_border_width
, external_border_height
;
7936 int title_bar_width
= 0, title_bar_height
= 0;
7937 int single_menu_bar_height
, wrapped_menu_bar_height
, menu_bar_height
;
7938 int tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
7939 int internal_border_width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
7941 if (FRAME_INITIAL_P (f
) || !FRAME_W32_P (f
))
7945 /* Outer rectangle and borders. */
7946 window
.cbSize
= sizeof (window
);
7947 GetWindowInfo (FRAME_W32_WINDOW (f
), &window
);
7948 external_border_width
= window
.cxWindowBorders
;
7949 external_border_height
= window
.cyWindowBorders
;
7951 if (get_title_bar_info_fn
)
7953 TITLEBAR_INFO title_bar
;
7955 title_bar
.cbSize
= sizeof (title_bar
);
7956 title_bar
.rcTitleBar
.left
= title_bar
.rcTitleBar
.right
= 0;
7957 title_bar
.rcTitleBar
.top
= title_bar
.rcTitleBar
.bottom
= 0;
7958 for (int i
= 0; i
< 6; i
++)
7959 title_bar
.rgstate
[i
] = 0;
7960 if (get_title_bar_info_fn (FRAME_W32_WINDOW (f
), &title_bar
)
7961 && !(title_bar
.rgstate
[0] & 0x00008001))
7964 = title_bar
.rcTitleBar
.right
- title_bar
.rcTitleBar
.left
;
7966 = title_bar
.rcTitleBar
.bottom
- title_bar
.rcTitleBar
.top
;
7969 else if ((window
.dwStyle
& WS_CAPTION
) == WS_CAPTION
)
7970 title_bar_height
= GetSystemMetrics (SM_CYCAPTION
);
7972 menu_bar
.cbSize
= sizeof (menu_bar
);
7973 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7974 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7975 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7976 single_menu_bar_height
= GetSystemMetrics (SM_CYMENU
);
7977 wrapped_menu_bar_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7980 left
= window
.rcWindow
.left
;
7981 top
= window
.rcWindow
.top
;
7982 right
= window
.rcWindow
.right
;
7983 bottom
= window
.rcWindow
.bottom
;
7986 menu_bar_height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7987 /* Fix menu bar height reported by GetMenuBarInfo. */
7988 if (menu_bar_height
> single_menu_bar_height
)
7989 /* A wrapped menu bar. */
7990 menu_bar_height
+= single_menu_bar_height
- wrapped_menu_bar_height
;
7991 else if (menu_bar_height
> 0)
7992 /* A single line menu bar. */
7993 menu_bar_height
= single_menu_bar_height
;
7995 return listn (CONSTYPE_HEAP
, 10,
7996 Fcons (Qouter_position
,
7997 Fcons (make_number (left
), make_number (top
))),
7999 Fcons (make_number (right
- left
),
8000 make_number (bottom
- top
))),
8001 Fcons (Qexternal_border_size
,
8002 Fcons (make_number (external_border_width
),
8003 make_number (external_border_height
))),
8004 Fcons (Qtitle_bar_size
,
8005 Fcons (make_number (title_bar_width
),
8006 make_number (title_bar_height
))),
8007 Fcons (Qmenu_bar_external
, Qt
),
8008 Fcons (Qmenu_bar_size
,
8010 (menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
),
8011 make_number (menu_bar_height
))),
8012 Fcons (Qtool_bar_external
, Qnil
),
8013 Fcons (Qtool_bar_position
, tool_bar_height
? Qtop
: Qnil
),
8014 Fcons (Qtool_bar_size
,
8017 ? right
- left
- 2 * internal_border_width
8019 make_number (tool_bar_height
))),
8020 Fcons (Qinternal_border_width
,
8021 make_number (internal_border_width
)));
8024 DEFUN ("w32-frame-edges", Fw32_frame_edges
, Sw32_frame_edges
, 0, 2, 0,
8025 doc
: /* Return edge coordinates of FRAME.
8026 FRAME must be a live frame and defaults to the selected one. The return
8027 value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are
8028 in pixels relative to the origin - the position (0, 0) - of FRAME's
8031 If optional argument TYPE is the symbol `outer-edges', return the outer
8032 edges of FRAME. The outer edges comprise the decorations of the window
8033 manager (like the title bar or external borders) as well as any external
8034 menu or tool bar of FRAME. If optional argument TYPE is the symbol
8035 `native-edges' or nil, return the native edges of FRAME. The native
8036 edges exclude the decorations of the window manager and any external
8037 menu or tool bar of FRAME. If TYPE is the symbol `inner-edges', return
8038 the inner edges of FRAME. These edges exclude title bar, any borders,
8039 menu bar or tool bar of FRAME. */)
8040 (Lisp_Object frame
, Lisp_Object type
)
8042 struct frame
*f
= decode_live_frame (frame
);
8044 if (FRAME_INITIAL_P (f
) || !FRAME_W32_P (f
))
8047 if (EQ (type
, Qouter_edges
))
8052 /* Outer frame rectangle, including outer borders and title bar. */
8053 GetWindowRect (FRAME_W32_WINDOW (f
), &rectangle
);
8056 return list4 (make_number (rectangle
.left
),
8057 make_number (rectangle
.top
),
8058 make_number (rectangle
.right
),
8059 make_number (rectangle
.bottom
));
8065 int left
, top
, right
, bottom
;
8068 /* Inner frame rectangle, excluding borders and title bar. */
8069 GetClientRect (FRAME_W32_WINDOW (f
), &rectangle
);
8070 /* Get top-left corner of native rectangle in screen
8074 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
8079 right
= left
+ rectangle
.right
;
8080 bottom
= top
+ rectangle
.bottom
;
8082 if (EQ (type
, Qinner_edges
))
8084 int internal_border_width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
8086 return list4 (make_number (left
+ internal_border_width
),
8088 + FRAME_TOOL_BAR_HEIGHT (f
)
8089 + internal_border_width
),
8090 make_number (right
- internal_border_width
),
8091 make_number (bottom
- internal_border_width
));
8094 return list4 (make_number (left
), make_number (top
),
8095 make_number (right
), make_number (bottom
));
8099 DEFUN ("w32-mouse-absolute-pixel-position", Fw32_mouse_absolute_pixel_position
,
8100 Sw32_mouse_absolute_pixel_position
, 0, 0, 0,
8101 doc
: /* Return absolute position of mouse cursor in pixels.
8102 The position is returned as a cons cell (X . Y) of the coordinates of
8103 the mouse cursor position in pixels relative to a position (0, 0) of the
8104 selected frame's display. */)
8113 return Fcons (make_number (pt
.x
), make_number (pt
.y
));
8116 DEFUN ("w32-set-mouse-absolute-pixel-position", Fw32_set_mouse_absolute_pixel_position
,
8117 Sw32_set_mouse_absolute_pixel_position
, 2, 2, 0,
8118 doc
: /* Move mouse pointer to absolute pixel position (X, Y).
8119 The coordinates X and Y are interpreted in pixels relative to a position
8120 (0, 0) of the selected frame's display. */)
8121 (Lisp_Object x
, Lisp_Object y
)
8123 CHECK_TYPE_RANGED_INTEGER (int, x
);
8124 CHECK_TYPE_RANGED_INTEGER (int, y
);
8127 SetCursorPos (XINT (x
), XINT (y
));
8133 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
8134 doc
: /* Get power status information from Windows system.
8136 The following %-sequences are provided:
8137 %L AC line status (verbose)
8138 %B Battery status (verbose)
8139 %b Battery status, empty means high, `-' means low,
8140 `!' means critical, and `+' means charging
8141 %p Battery load percentage
8142 %s Remaining time (to charge or discharge) in seconds
8143 %m Remaining time (to charge or discharge) in minutes
8144 %h Remaining time (to charge or discharge) in hours
8145 %t Remaining time (to charge or discharge) in the form `h:min' */)
8148 Lisp_Object status
= Qnil
;
8150 SYSTEM_POWER_STATUS system_status
;
8151 if (GetSystemPowerStatus (&system_status
))
8153 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
8154 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
8156 long seconds_left
= (long) system_status
.BatteryLifeTime
;
8158 if (system_status
.ACLineStatus
== 0)
8159 line_status
= build_string ("off-line");
8160 else if (system_status
.ACLineStatus
== 1)
8161 line_status
= build_string ("on-line");
8163 line_status
= build_string ("N/A");
8165 if (system_status
.BatteryFlag
& 128)
8167 battery_status
= build_string ("N/A");
8168 battery_status_symbol
= empty_unibyte_string
;
8170 else if (system_status
.BatteryFlag
& 8)
8172 battery_status
= build_string ("charging");
8173 battery_status_symbol
= build_string ("+");
8174 if (system_status
.BatteryFullLifeTime
!= -1L)
8175 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
8177 else if (system_status
.BatteryFlag
& 4)
8179 battery_status
= build_string ("critical");
8180 battery_status_symbol
= build_string ("!");
8182 else if (system_status
.BatteryFlag
& 2)
8184 battery_status
= build_string ("low");
8185 battery_status_symbol
= build_string ("-");
8187 else if (system_status
.BatteryFlag
& 1)
8189 battery_status
= build_string ("high");
8190 battery_status_symbol
= empty_unibyte_string
;
8194 battery_status
= build_string ("medium");
8195 battery_status_symbol
= empty_unibyte_string
;
8198 if (system_status
.BatteryLifePercent
> 100)
8199 load_percentage
= build_string ("N/A");
8203 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
8204 load_percentage
= build_string (buffer
);
8207 if (seconds_left
< 0)
8208 seconds
= minutes
= hours
= remain
= build_string ("N/A");
8214 snprintf (buffer
, 16, "%ld", seconds_left
);
8215 seconds
= build_string (buffer
);
8217 m
= seconds_left
/ 60;
8218 snprintf (buffer
, 16, "%ld", m
);
8219 minutes
= build_string (buffer
);
8221 h
= seconds_left
/ 3600.0;
8222 snprintf (buffer
, 16, "%3.1f", h
);
8223 hours
= build_string (buffer
);
8225 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
8226 remain
= build_string (buffer
);
8229 status
= listn (CONSTYPE_HEAP
, 8,
8230 Fcons (make_number ('L'), line_status
),
8231 Fcons (make_number ('B'), battery_status
),
8232 Fcons (make_number ('b'), battery_status_symbol
),
8233 Fcons (make_number ('p'), load_percentage
),
8234 Fcons (make_number ('s'), seconds
),
8235 Fcons (make_number ('m'), minutes
),
8236 Fcons (make_number ('h'), hours
),
8237 Fcons (make_number ('t'), remain
));
8244 typedef BOOL (WINAPI
*GetDiskFreeSpaceExW_Proc
)
8245 (LPCWSTR
, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
);
8246 typedef BOOL (WINAPI
*GetDiskFreeSpaceExA_Proc
)
8247 (LPCSTR
, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
);
8249 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
8250 doc
: /* Return storage information about the file system FILENAME is on.
8251 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
8252 storage of the file system, FREE is the free storage, and AVAIL is the
8253 storage available to a non-superuser. All 3 numbers are in bytes.
8254 If the underlying system call fails, value is nil. */)
8255 (Lisp_Object filename
)
8257 Lisp_Object encoded
, value
;
8259 CHECK_STRING (filename
);
8260 filename
= Fexpand_file_name (filename
, Qnil
);
8261 encoded
= ENCODE_FILE (filename
);
8265 /* Determining the required information on Windows turns out, sadly,
8266 to be more involved than one would hope. The original Windows API
8267 call for this will return bogus information on some systems, but we
8268 must dynamically probe for the replacement api, since that was
8269 added rather late on. */
8271 HMODULE hKernel
= GetModuleHandle ("kernel32");
8272 GetDiskFreeSpaceExW_Proc pfn_GetDiskFreeSpaceExW
=
8273 (GetDiskFreeSpaceExW_Proc
) GetProcAddress (hKernel
, "GetDiskFreeSpaceExW");
8274 GetDiskFreeSpaceExA_Proc pfn_GetDiskFreeSpaceExA
=
8275 (GetDiskFreeSpaceExA_Proc
) GetProcAddress (hKernel
, "GetDiskFreeSpaceExA");
8276 bool have_pfn_GetDiskFreeSpaceEx
=
8277 ((w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExW
)
8278 || (!w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExA
));
8280 /* On Windows, we may need to specify the root directory of the
8281 volume holding FILENAME. */
8282 char rootname
[MAX_UTF8_PATH
];
8283 wchar_t rootname_w
[MAX_PATH
];
8284 char rootname_a
[MAX_PATH
];
8285 char *name
= SDATA (encoded
);
8288 /* find the root name of the volume if given */
8289 if (isalpha (name
[0]) && name
[1] == ':')
8291 rootname
[0] = name
[0];
8292 rootname
[1] = name
[1];
8296 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
8298 char *str
= rootname
;
8302 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
8312 if (w32_unicode_filenames
)
8313 filename_to_utf16 (rootname
, rootname_w
);
8315 filename_to_ansi (rootname
, rootname_a
);
8317 if (have_pfn_GetDiskFreeSpaceEx
)
8319 /* Unsigned large integers cannot be cast to double, so
8320 use signed ones instead. */
8321 LARGE_INTEGER availbytes
;
8322 LARGE_INTEGER freebytes
;
8323 LARGE_INTEGER totalbytes
;
8325 if (w32_unicode_filenames
)
8326 result
= pfn_GetDiskFreeSpaceExW (rootname_w
,
8327 (ULARGE_INTEGER
*)&availbytes
,
8328 (ULARGE_INTEGER
*)&totalbytes
,
8329 (ULARGE_INTEGER
*)&freebytes
);
8331 result
= pfn_GetDiskFreeSpaceExA (rootname_a
,
8332 (ULARGE_INTEGER
*)&availbytes
,
8333 (ULARGE_INTEGER
*)&totalbytes
,
8334 (ULARGE_INTEGER
*)&freebytes
);
8336 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
8337 make_float ((double) freebytes
.QuadPart
),
8338 make_float ((double) availbytes
.QuadPart
));
8342 DWORD sectors_per_cluster
;
8343 DWORD bytes_per_sector
;
8344 DWORD free_clusters
;
8345 DWORD total_clusters
;
8347 if (w32_unicode_filenames
)
8348 result
= GetDiskFreeSpaceW (rootname_w
,
8349 §ors_per_cluster
,
8354 result
= GetDiskFreeSpaceA (rootname_a
,
8355 §ors_per_cluster
,
8360 value
= list3 (make_float ((double) total_clusters
8361 * sectors_per_cluster
* bytes_per_sector
),
8362 make_float ((double) free_clusters
8363 * sectors_per_cluster
* bytes_per_sector
),
8364 make_float ((double) free_clusters
8365 * sectors_per_cluster
* bytes_per_sector
));
8371 #endif /* WINDOWSNT */
8375 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
8376 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
8379 static char pname_buf
[256];
8382 PRINTER_INFO_2W
*ppi2w
= NULL
;
8383 PRINTER_INFO_2A
*ppi2a
= NULL
;
8384 DWORD dwNeeded
= 0, dwReturned
= 0;
8385 char server_name
[MAX_UTF8_PATH
], share_name
[MAX_UTF8_PATH
];
8386 char port_name
[MAX_UTF8_PATH
];
8388 /* Retrieve the default string from Win.ini (the registry).
8389 * String will be in form "printername,drivername,portname".
8390 * This is the most portable way to get the default printer. */
8391 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
8393 /* printername precedes first "," character */
8394 strtok (pname_buf
, ",");
8395 /* We want to know more than the printer name */
8396 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
8398 /* GetPrinterW is not supported by unicows.dll. */
8399 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
8400 GetPrinterW (hPrn
, 2, NULL
, 0, &dwNeeded
);
8402 GetPrinterA (hPrn
, 2, NULL
, 0, &dwNeeded
);
8405 ClosePrinter (hPrn
);
8408 /* Call GetPrinter again with big enough memory block. */
8409 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
8411 /* Allocate memory for the PRINTER_INFO_2 struct. */
8412 ppi2w
= xmalloc (dwNeeded
);
8413 err
= GetPrinterW (hPrn
, 2, (LPBYTE
)ppi2w
, dwNeeded
, &dwReturned
);
8414 ClosePrinter (hPrn
);
8421 if ((ppi2w
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
8422 && ppi2w
->pServerName
)
8424 filename_from_utf16 (ppi2w
->pServerName
, server_name
);
8425 filename_from_utf16 (ppi2w
->pShareName
, share_name
);
8429 server_name
[0] = '\0';
8430 filename_from_utf16 (ppi2w
->pPortName
, port_name
);
8435 ppi2a
= xmalloc (dwNeeded
);
8436 err
= GetPrinterA (hPrn
, 2, (LPBYTE
)ppi2a
, dwNeeded
, &dwReturned
);
8437 ClosePrinter (hPrn
);
8444 if ((ppi2a
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
8445 && ppi2a
->pServerName
)
8447 filename_from_ansi (ppi2a
->pServerName
, server_name
);
8448 filename_from_ansi (ppi2a
->pShareName
, share_name
);
8452 server_name
[0] = '\0';
8453 filename_from_ansi (ppi2a
->pPortName
, port_name
);
8459 /* a remote printer */
8460 if (server_name
[0] == '\\')
8461 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", server_name
,
8464 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", server_name
,
8466 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8470 /* a local printer */
8471 strncpy (pname_buf
, port_name
, sizeof (pname_buf
));
8472 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8473 /* `pPortName' can include several ports, delimited by ','.
8474 * we only use the first one. */
8475 strtok (pname_buf
, ",");
8478 return DECODE_FILE (build_unibyte_string (pname_buf
));
8480 #endif /* WINDOWSNT */
8483 /* Equivalent of strerror for W32 error codes. */
8485 w32_strerror (int error_no
)
8487 static char buf
[500];
8491 error_no
= GetLastError ();
8493 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
8494 FORMAT_MESSAGE_IGNORE_INSERTS
,
8497 0, /* choose most suitable language */
8498 buf
, sizeof (buf
), NULL
);
8500 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
8501 buf
[ret
- 1] == '\r' ))
8505 sprintf (buf
, "w32 error %u", error_no
);
8510 /* For convenience when debugging. (You cannot call GetLastError
8511 directly from GDB: it will crash, because it uses the __stdcall
8512 calling convention, not the _cdecl convention assumed by GDB.) */
8514 w32_last_error (void)
8516 return GetLastError ();
8519 /* Cache information describing the NT system for later use. */
8521 cache_system_info (void)
8534 /* Cache the module handle of Emacs itself. */
8535 hinst
= GetModuleHandle (NULL
);
8537 /* Cache the version of the operating system. */
8538 version
.data
= GetVersion ();
8539 w32_major_version
= version
.info
.major
;
8540 w32_minor_version
= version
.info
.minor
;
8542 if (version
.info
.platform
& 0x8000)
8547 /* Cache page size, allocation unit, processor type, etc. */
8548 GetSystemInfo (&sysinfo_cache
);
8549 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
8551 /* Cache os info. */
8552 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
8553 GetVersionEx (&osinfo_cache
);
8555 w32_build_number
= osinfo_cache
.dwBuildNumber
;
8556 if (os_subtype
== OS_9X
)
8557 w32_build_number
&= 0xffff;
8559 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
8564 _DebPrint (const char *fmt
, ...)
8569 va_start (args
, fmt
);
8570 vsprintf (buf
, fmt
, args
);
8573 fprintf (stderr
, "%s", buf
);
8575 OutputDebugString (buf
);
8580 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
8582 int cur_state
= (GetKeyState (vk_code
) & 1);
8584 if (NILP (new_state
)
8585 || (NUMBERP (new_state
)
8586 && ((XUINT (new_state
)) & 1) != cur_state
))
8589 faked_key
= vk_code
;
8590 #endif /* WINDOWSNT */
8592 keybd_event ((BYTE
) vk_code
,
8593 (BYTE
) MapVirtualKey (vk_code
, 0),
8594 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8595 keybd_event ((BYTE
) vk_code
,
8596 (BYTE
) MapVirtualKey (vk_code
, 0),
8597 KEYEVENTF_EXTENDEDKEY
| 0, 0);
8598 keybd_event ((BYTE
) vk_code
,
8599 (BYTE
) MapVirtualKey (vk_code
, 0),
8600 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8601 cur_state
= !cur_state
;
8607 /* Translate console modifiers to emacs modifiers.
8608 German keyboard support (Kai Morgan Zeise 2/18/95). */
8610 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
8614 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
8615 pressed, first remove those modifiers. */
8616 if (!NILP (Vw32_recognize_altgr
)
8617 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8618 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8619 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
8621 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
8622 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
8624 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8626 retval
|= ctrl_modifier
;
8627 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8628 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8629 retval
|= meta_modifier
;
8632 if (mods
& LEFT_WIN_PRESSED
)
8633 retval
|= w32_key_to_modifier (VK_LWIN
);
8634 if (mods
& RIGHT_WIN_PRESSED
)
8635 retval
|= w32_key_to_modifier (VK_RWIN
);
8636 if (mods
& APPS_PRESSED
)
8637 retval
|= w32_key_to_modifier (VK_APPS
);
8638 if (mods
& SCROLLLOCK_ON
)
8639 retval
|= w32_key_to_modifier (VK_SCROLL
);
8641 /* Just in case someone wanted the original behavior, make it
8642 optional by setting w32-capslock-is-shiftlock to t. */
8643 if (NILP (Vw32_capslock_is_shiftlock
)
8644 /* Keys that should _not_ be affected by CapsLock. */
8645 && ( (key
== VK_BACK
)
8647 || (key
== VK_CLEAR
)
8648 || (key
== VK_RETURN
)
8649 || (key
== VK_ESCAPE
)
8650 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
8651 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
8652 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
8655 /* Only consider shift state. */
8656 if ((mods
& SHIFT_PRESSED
) != 0)
8657 retval
|= shift_modifier
;
8661 /* Ignore CapsLock state if not enabled. */
8662 if (NILP (Vw32_enable_caps_lock
))
8663 mods
&= ~CAPSLOCK_ON
;
8664 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
8665 retval
|= shift_modifier
;
8671 /* The return code indicates key code size. cpID is the codepage to
8672 use for translation to Unicode; -1 means use the current console
8675 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
8677 unsigned int key_code
= event
->wVirtualKeyCode
;
8678 unsigned int mods
= event
->dwControlKeyState
;
8680 static BYTE ansi_code
[4];
8681 static int isdead
= 0;
8685 event
->uChar
.AsciiChar
= ansi_code
[2];
8689 if (event
->uChar
.AsciiChar
!= 0)
8692 memset (keystate
, 0, sizeof (keystate
));
8693 keystate
[key_code
] = 0x80;
8694 if (mods
& SHIFT_PRESSED
)
8695 keystate
[VK_SHIFT
] = 0x80;
8696 if (mods
& CAPSLOCK_ON
)
8697 keystate
[VK_CAPITAL
] = 1;
8698 /* If we recognize right-alt and left-ctrl as AltGr, set the key
8699 states accordingly before invoking ToAscii. */
8700 if (!NILP (Vw32_recognize_altgr
)
8701 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
8703 keystate
[VK_CONTROL
] = 0x80;
8704 keystate
[VK_LCONTROL
] = 0x80;
8705 keystate
[VK_MENU
] = 0x80;
8706 keystate
[VK_RMENU
] = 0x80;
8710 /* Because of an OS bug, ToAscii corrupts the stack when called to
8711 convert a dead key in console mode on NT4. Unfortunately, trying
8712 to check for dead keys using MapVirtualKey doesn't work either -
8713 these functions apparently use internal information about keyboard
8714 layout which doesn't get properly updated in console programs when
8715 changing layout (though apparently it gets partly updated,
8716 otherwise ToAscii wouldn't crash). */
8717 if (is_dead_key (event
->wVirtualKeyCode
))
8721 /* On NT, call ToUnicode instead and then convert to the current
8722 console input codepage. */
8723 if (os_subtype
== OS_NT
)
8727 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8728 keystate
, buf
, 128, 0);
8731 /* When we are called from the GUI message processing code,
8732 we are passed the current keyboard codepage, a positive
8733 number, to use below. */
8735 cpId
= GetConsoleCP ();
8737 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
8738 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
8739 ansi_code
, 4, NULL
, NULL
);
8746 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8747 keystate
, (LPWORD
) ansi_code
, 0);
8752 event
->uChar
.AsciiChar
= ansi_code
[0];
8758 w32_sys_ring_bell (struct frame
*f
)
8760 if (sound_type
== 0xFFFFFFFF)
8764 else if (sound_type
== MB_EMACS_SILENT
)
8769 MessageBeep (sound_type
);
8772 DEFUN ("w32--menu-bar-in-use", Fw32__menu_bar_in_use
, Sw32__menu_bar_in_use
,
8774 doc
: /* Return non-nil when a menu-bar menu is being used.
8775 Internal use only. */)
8778 return menubar_in_use
? Qt
: Qnil
;
8782 /***********************************************************************
8784 ***********************************************************************/
8786 /* Keep this list in the same order as frame_parms in frame.c.
8787 Use 0 for unsupported frame parameters. */
8789 frame_parm_handler w32_frame_parm_handlers
[] =
8793 x_set_background_color
,
8799 x_set_foreground_color
,
8802 x_set_internal_border_width
,
8803 x_set_right_divider_width
,
8804 x_set_bottom_divider_width
,
8805 x_set_menu_bar_lines
,
8807 x_explicitly_set_name
,
8808 x_set_scroll_bar_width
,
8809 x_set_scroll_bar_height
,
8812 x_set_vertical_scroll_bars
,
8813 x_set_horizontal_scroll_bars
,
8815 x_set_tool_bar_lines
,
8816 0, /* x_set_scroll_bar_foreground, */
8817 0, /* x_set_scroll_bar_background, */
8822 0, /* x_set_wait_for_wm, */
8826 0, /* x_set_sticky */
8827 0, /* x_set_tool_bar_position */
8831 syms_of_w32fns (void)
8833 globals_of_w32fns ();
8834 track_mouse_window
= NULL
;
8836 w32_visible_system_caret_hwnd
= NULL
;
8838 DEFSYM (Qundefined_color
, "undefined-color");
8839 DEFSYM (Qcancel_timer
, "cancel-timer");
8840 DEFSYM (Qhyper
, "hyper");
8841 DEFSYM (Qsuper
, "super");
8842 DEFSYM (Qmeta
, "meta");
8843 DEFSYM (Qalt
, "alt");
8844 DEFSYM (Qctrl
, "ctrl");
8845 DEFSYM (Qcontrol
, "control");
8846 DEFSYM (Qshift
, "shift");
8847 DEFSYM (Qfont_param
, "font-parameter");
8848 DEFSYM (Qgeometry
, "geometry");
8849 DEFSYM (Qworkarea
, "workarea");
8850 DEFSYM (Qmm_size
, "mm-size");
8851 DEFSYM (Qframes
, "frames");
8852 DEFSYM (Qtip_frame
, "tip-frame");
8853 DEFSYM (Qunicode_sip
, "unicode-sip");
8855 /* Symbols used elsewhere, but only in MS-Windows-specific code. */
8856 DEFSYM (Qgnutls_dll
, "gnutls");
8857 DEFSYM (Qlibxml2_dll
, "libxml2");
8858 DEFSYM (Qserif
, "serif");
8859 DEFSYM (Qzlib_dll
, "zlib");
8861 Fput (Qundefined_color
, Qerror_conditions
,
8862 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
8863 Fput (Qundefined_color
, Qerror_message
,
8864 build_pure_c_string ("Undefined color"));
8866 staticpro (&w32_grabbed_keys
);
8867 w32_grabbed_keys
= Qnil
;
8869 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
8870 doc
: /* An array of color name mappings for Windows. */);
8871 Vw32_color_map
= Qnil
;
8873 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
8874 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8875 When non-nil, for example, Alt pressed and released and then space will
8876 open the System menu. When nil, Emacs processes the Alt key events, and
8877 then silently swallows them. */);
8878 Vw32_pass_alt_to_system
= Qnil
;
8880 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
8881 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8882 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8883 Vw32_alt_is_meta
= Qt
;
8885 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
8886 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8889 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8890 Vw32_pass_lwindow_to_system
,
8891 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8893 When non-nil, the Start menu is opened by tapping the key.
8894 If you set this to nil, the left \"Windows\" key is processed by Emacs
8895 according to the value of `w32-lwindow-modifier', which see.
8897 Note that some combinations of the left \"Windows\" key with other keys are
8898 caught by Windows at low level, and so binding them in Emacs will have no
8899 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8900 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8901 the doc string of `w32-phantom-key-code'. */);
8902 Vw32_pass_lwindow_to_system
= Qt
;
8904 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8905 Vw32_pass_rwindow_to_system
,
8906 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8908 When non-nil, the Start menu is opened by tapping the key.
8909 If you set this to nil, the right \"Windows\" key is processed by Emacs
8910 according to the value of `w32-rwindow-modifier', which see.
8912 Note that some combinations of the right \"Windows\" key with other keys are
8913 caught by Windows at low level, and so binding them in Emacs will have no
8914 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8915 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8916 the doc string of `w32-phantom-key-code'. */);
8917 Vw32_pass_rwindow_to_system
= Qt
;
8919 DEFVAR_LISP ("w32-phantom-key-code",
8920 Vw32_phantom_key_code
,
8921 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8922 Value is a number between 0 and 255.
8924 Phantom key presses are generated in order to stop the system from
8925 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8926 `w32-pass-rwindow-to-system' is nil. */);
8927 /* Although 255 is technically not a valid key code, it works and
8928 means that this hack won't interfere with any real key code. */
8929 XSETINT (Vw32_phantom_key_code
, 255);
8931 DEFVAR_LISP ("w32-enable-num-lock",
8932 Vw32_enable_num_lock
,
8933 doc
: /* If non-nil, the Num Lock key acts normally.
8934 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8935 Vw32_enable_num_lock
= Qt
;
8937 DEFVAR_LISP ("w32-enable-caps-lock",
8938 Vw32_enable_caps_lock
,
8939 doc
: /* If non-nil, the Caps Lock key acts normally.
8940 Set to nil to handle Caps Lock as the `capslock' key. */);
8941 Vw32_enable_caps_lock
= Qt
;
8943 DEFVAR_LISP ("w32-scroll-lock-modifier",
8944 Vw32_scroll_lock_modifier
,
8945 doc
: /* Modifier to use for the Scroll Lock ON state.
8946 The value can be hyper, super, meta, alt, control or shift for the
8947 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8948 Any other value will cause the Scroll Lock key to be ignored. */);
8949 Vw32_scroll_lock_modifier
= Qnil
;
8951 DEFVAR_LISP ("w32-lwindow-modifier",
8952 Vw32_lwindow_modifier
,
8953 doc
: /* Modifier to use for the left \"Windows\" key.
8954 The value can be hyper, super, meta, alt, control or shift for the
8955 respective modifier, or nil to appear as the `lwindow' key.
8956 Any other value will cause the key to be ignored. */);
8957 Vw32_lwindow_modifier
= Qnil
;
8959 DEFVAR_LISP ("w32-rwindow-modifier",
8960 Vw32_rwindow_modifier
,
8961 doc
: /* Modifier to use for the right \"Windows\" key.
8962 The value can be hyper, super, meta, alt, control or shift for the
8963 respective modifier, or nil to appear as the `rwindow' key.
8964 Any other value will cause the key to be ignored. */);
8965 Vw32_rwindow_modifier
= Qnil
;
8967 DEFVAR_LISP ("w32-apps-modifier",
8969 doc
: /* Modifier to use for the \"Apps\" key.
8970 The value can be hyper, super, meta, alt, control or shift for the
8971 respective modifier, or nil to appear as the `apps' key.
8972 Any other value will cause the key to be ignored. */);
8973 Vw32_apps_modifier
= Qnil
;
8975 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
8976 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8977 w32_enable_synthesized_fonts
= 0;
8979 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
8980 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8981 Vw32_enable_palette
= Qt
;
8983 DEFVAR_INT ("w32-mouse-button-tolerance",
8984 w32_mouse_button_tolerance
,
8985 doc
: /* Analogue of double click interval for faking middle mouse events.
8986 The value is the minimum time in milliseconds that must elapse between
8987 left and right button down events before they are considered distinct events.
8988 If both mouse buttons are depressed within this interval, a middle mouse
8989 button down event is generated instead. */);
8990 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8992 DEFVAR_INT ("w32-mouse-move-interval",
8993 w32_mouse_move_interval
,
8994 doc
: /* Minimum interval between mouse move events.
8995 The value is the minimum time in milliseconds that must elapse between
8996 successive mouse move (or scroll bar drag) events before they are
8997 reported as lisp events. */);
8998 w32_mouse_move_interval
= 0;
9000 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
9001 w32_pass_extra_mouse_buttons_to_system
,
9002 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
9003 Recent versions of Windows support mice with up to five buttons.
9004 Since most applications don't support these extra buttons, most mouse
9005 drivers will allow you to map them to functions at the system level.
9006 If this variable is non-nil, Emacs will pass them on, allowing the
9007 system to handle them. */);
9008 w32_pass_extra_mouse_buttons_to_system
= 0;
9010 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
9011 w32_pass_multimedia_buttons_to_system
,
9012 doc
: /* If non-nil, media buttons are passed to Windows.
9013 Some modern keyboards contain buttons for controlling media players, web
9014 browsers and other applications. Generally these buttons are handled on a
9015 system wide basis, but by setting this to nil they are made available
9016 to Emacs for binding. Depending on your keyboard, additional keys that
9017 may be available are:
9019 browser-back, browser-forward, browser-refresh, browser-stop,
9020 browser-search, browser-favorites, browser-home,
9021 mail, mail-reply, mail-forward, mail-send,
9023 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
9024 spell-check, correction-list, toggle-dictate-command,
9025 media-next, media-previous, media-stop, media-play-pause, media-select,
9026 media-play, media-pause, media-record, media-fast-forward, media-rewind,
9027 media-channel-up, media-channel-down,
9028 volume-mute, volume-up, volume-down,
9029 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
9030 bass-down, bass-boost, bass-up, treble-down, treble-up */);
9031 w32_pass_multimedia_buttons_to_system
= 1;
9033 #if 0 /* TODO: Mouse cursor customization. */
9034 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
9035 doc
: /* The shape of the pointer when over text.
9036 Changing the value does not affect existing frames
9037 unless you set the mouse color. */);
9038 Vx_pointer_shape
= Qnil
;
9040 Vx_nontext_pointer_shape
= Qnil
;
9042 Vx_mode_pointer_shape
= Qnil
;
9044 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
9045 doc
: /* The shape of the pointer when Emacs is busy.
9046 This variable takes effect when you create a new frame
9047 or when you set the mouse color. */);
9048 Vx_hourglass_pointer_shape
= Qnil
;
9050 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
9051 Vx_sensitive_text_pointer_shape
,
9052 doc
: /* The shape of the pointer when over mouse-sensitive text.
9053 This variable takes effect when you create a new frame
9054 or when you set the mouse color. */);
9055 Vx_sensitive_text_pointer_shape
= Qnil
;
9057 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
9058 Vx_window_horizontal_drag_shape
,
9059 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
9060 This variable takes effect when you create a new frame
9061 or when you set the mouse color. */);
9062 Vx_window_horizontal_drag_shape
= Qnil
;
9064 DEFVAR_LISP ("x-window-vertical-drag-cursor",
9065 Vx_window_vertical_drag_shape
,
9066 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
9067 This variable takes effect when you create a new frame
9068 or when you set the mouse color. */);
9069 Vx_window_vertical_drag_shape
= Qnil
;
9072 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
9073 doc
: /* A string indicating the foreground color of the cursor box. */);
9074 Vx_cursor_fore_pixel
= Qnil
;
9076 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
9077 doc
: /* Maximum size for tooltips.
9078 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
9079 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
9081 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
9082 doc
: /* Non-nil if no window manager is in use.
9083 Emacs doesn't try to figure this out; this is always nil
9084 unless you set it to something else. */);
9085 /* We don't have any way to find this out, so set it to nil
9086 and maybe the user would like to set it to t. */
9087 Vx_no_window_manager
= Qnil
;
9089 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
9090 Vx_pixel_size_width_font_regexp
,
9091 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
9093 Since Emacs gets width of a font matching with this regexp from
9094 PIXEL_SIZE field of the name, font finding mechanism gets faster for
9095 such a font. This is especially effective for such large fonts as
9096 Chinese, Japanese, and Korean. */);
9097 Vx_pixel_size_width_font_regexp
= Qnil
;
9099 DEFVAR_LISP ("w32-bdf-filename-alist",
9100 Vw32_bdf_filename_alist
,
9101 doc
: /* List of bdf fonts and their corresponding filenames. */);
9102 Vw32_bdf_filename_alist
= Qnil
;
9104 DEFVAR_BOOL ("w32-strict-fontnames",
9105 w32_strict_fontnames
,
9106 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
9107 Default is nil, which allows old fontnames that are not XLFD compliant,
9108 and allows third-party CJK display to work by specifying false charset
9109 fields to trick Emacs into translating to Big5, SJIS etc.
9110 Setting this to t will prevent wrong fonts being selected when
9111 fontsets are automatically created. */);
9112 w32_strict_fontnames
= 0;
9114 DEFVAR_BOOL ("w32-strict-painting",
9115 w32_strict_painting
,
9116 doc
: /* Non-nil means use strict rules for repainting frames.
9117 Set this to nil to get the old behavior for repainting; this should
9118 only be necessary if the default setting causes problems. */);
9119 w32_strict_painting
= 1;
9121 DEFVAR_BOOL ("w32-use-fallback-wm-chars-method",
9122 w32_use_fallback_wm_chars_method
,
9123 doc
: /* Non-nil means use old method of processing character keys.
9124 This is intended only for debugging of the new processing method.
9127 This variable has effect only on NT family of systems, not on Windows 9X. */);
9128 w32_use_fallback_wm_chars_method
= 0;
9130 DEFVAR_BOOL ("w32-disable-new-uniscribe-apis",
9131 w32_disable_new_uniscribe_apis
,
9132 doc
: /* Non-nil means don't use new Uniscribe APIs.
9133 The new APIs are used to access OTF features supported by fonts.
9134 This is intended only for debugging of the new Uniscribe-related code.
9137 This variable has effect only on Windows Vista and later. */);
9138 w32_disable_new_uniscribe_apis
= 0;
9140 #if 0 /* TODO: Port to W32 */
9141 defsubr (&Sx_change_window_property
);
9142 defsubr (&Sx_delete_window_property
);
9143 defsubr (&Sx_window_property
);
9145 defsubr (&Sxw_display_color_p
);
9146 defsubr (&Sx_display_grayscale_p
);
9147 defsubr (&Sxw_color_defined_p
);
9148 defsubr (&Sxw_color_values
);
9149 defsubr (&Sx_server_max_request_size
);
9150 defsubr (&Sx_server_vendor
);
9151 defsubr (&Sx_server_version
);
9152 defsubr (&Sx_display_pixel_width
);
9153 defsubr (&Sx_display_pixel_height
);
9154 defsubr (&Sx_display_mm_width
);
9155 defsubr (&Sx_display_mm_height
);
9156 defsubr (&Sx_display_screens
);
9157 defsubr (&Sx_display_planes
);
9158 defsubr (&Sx_display_color_cells
);
9159 defsubr (&Sx_display_visual_class
);
9160 defsubr (&Sx_display_backing_store
);
9161 defsubr (&Sx_display_save_under
);
9162 defsubr (&Sx_create_frame
);
9163 defsubr (&Sx_open_connection
);
9164 defsubr (&Sx_close_connection
);
9165 defsubr (&Sx_display_list
);
9166 defsubr (&Sw32_frame_geometry
);
9167 defsubr (&Sw32_frame_edges
);
9168 defsubr (&Sw32_mouse_absolute_pixel_position
);
9169 defsubr (&Sw32_set_mouse_absolute_pixel_position
);
9170 defsubr (&Sx_synchronize
);
9172 /* W32 specific functions */
9174 defsubr (&Sw32_define_rgb_color
);
9175 defsubr (&Sw32_default_color_map
);
9176 defsubr (&Sw32_display_monitor_attributes_list
);
9177 defsubr (&Sw32_send_sys_command
);
9178 defsubr (&Sw32_shell_execute
);
9179 defsubr (&Sw32_register_hot_key
);
9180 defsubr (&Sw32_unregister_hot_key
);
9181 defsubr (&Sw32_registered_hot_keys
);
9182 defsubr (&Sw32_reconstruct_hot_key
);
9183 defsubr (&Sw32_toggle_lock_key
);
9184 defsubr (&Sw32_window_exists_p
);
9185 defsubr (&Sw32_battery_status
);
9186 defsubr (&Sw32__menu_bar_in_use
);
9189 defsubr (&Sfile_system_info
);
9190 defsubr (&Sdefault_printer_name
);
9193 defsubr (&Sset_message_beep
);
9194 defsubr (&Sx_show_tip
);
9195 defsubr (&Sx_hide_tip
);
9197 staticpro (&tip_timer
);
9199 staticpro (&tip_frame
);
9201 last_show_tip_args
= Qnil
;
9202 staticpro (&last_show_tip_args
);
9204 defsubr (&Sx_file_dialog
);
9206 defsubr (&Ssystem_move_file_to_trash
);
9212 /* Crashing and reporting backtrace. */
9215 static LONG CALLBACK
my_exception_handler (EXCEPTION_POINTERS
*);
9216 static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_handler
;
9218 static DWORD except_code
;
9219 static PVOID except_addr
;
9223 /* Stack overflow recovery. */
9225 /* Re-establish the guard page at stack limit. This is needed because
9226 when a stack overflow is detected, Windows removes the guard bit
9227 from the guard page, so if we don't re-establish that protection,
9228 the next stack overflow will cause a crash. */
9230 w32_reset_stack_overflow_guard (void)
9232 /* MinGW headers don't declare this (should be in malloc.h). */
9233 _CRTIMP
int __cdecl
_resetstkoflw (void);
9235 /* We ignore the return value. If _resetstkoflw fails, the next
9236 stack overflow will crash the program. */
9237 (void)_resetstkoflw ();
9241 stack_overflow_handler (void)
9243 /* Hard GC error may lead to stack overflow caused by
9244 too nested calls to mark_object. No way to survive. */
9246 terminate_due_to_signal (SIGSEGV
, 40);
9248 /* See ms-w32.h: MinGW64's longjmp crashes if invoked in this context. */
9249 __builtin_longjmp (return_to_command_loop
, 1);
9251 sys_longjmp (return_to_command_loop
, 1);
9255 /* This handler records the exception code and the address where it
9256 was triggered so that this info could be included in the backtrace.
9257 Without that, the backtrace in some cases has no information
9258 whatsoever about the offending code, and looks as if the top-level
9259 exception handler in the MinGW startup code was the one that
9260 crashed. We also recover from stack overflow, by calling our stack
9261 overflow handler that jumps back to top level. */
9262 static LONG CALLBACK
9263 my_exception_handler (EXCEPTION_POINTERS
* exception_data
)
9265 except_code
= exception_data
->ExceptionRecord
->ExceptionCode
;
9266 except_addr
= exception_data
->ExceptionRecord
->ExceptionAddress
;
9268 /* If this is a stack overflow exception, attempt to recover. */
9269 if (exception_data
->ExceptionRecord
->ExceptionCode
== EXCEPTION_STACK_OVERFLOW
9270 && exception_data
->ExceptionRecord
->NumberParameters
== 2
9271 /* We can only longjmp to top level from the main thread. */
9272 && GetCurrentThreadId () == dwMainThreadId
)
9274 /* Call stack_overflow_handler (). */
9276 exception_data
->ContextRecord
->Rip
= (DWORD_PTR
) &stack_overflow_handler
;
9278 exception_data
->ContextRecord
->Eip
= (DWORD_PTR
) &stack_overflow_handler
;
9280 /* Zero this out, so the stale address of the stack overflow
9281 exception we handled is not displayed in some future
9284 return EXCEPTION_CONTINUE_EXECUTION
;
9287 if (prev_exception_handler
)
9288 return prev_exception_handler (exception_data
);
9289 return EXCEPTION_EXECUTE_HANDLER
;
9293 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
9296 #define BACKTRACE_LIMIT_MAX 62
9299 w32_backtrace (void **buffer
, int limit
)
9301 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
9302 HMODULE hm_kernel32
= NULL
;
9304 if (!s_pfn_CaptureStackBackTrace
)
9306 hm_kernel32
= LoadLibrary ("Kernel32.dll");
9307 s_pfn_CaptureStackBackTrace
=
9308 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
9309 "RtlCaptureStackBackTrace");
9311 if (s_pfn_CaptureStackBackTrace
)
9312 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
9321 button
= MessageBox (NULL
,
9322 "A fatal error has occurred!\n\n"
9323 "Would you like to attach a debugger?\n\n"
9325 "YES -- to debug Emacs, or\n"
9326 "NO -- to abort Emacs and produce a backtrace\n"
9327 " (emacs_backtrace.txt in current directory)."
9329 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
9330 "\"continue\" inside GDB before clicking YES.)"
9332 , "Emacs Abort Dialog",
9333 MB_ICONEXCLAMATION
| MB_TASKMODAL
9334 | MB_SETFOREGROUND
| MB_YESNO
);
9339 exit (2); /* tell the compiler we will never return */
9343 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
9344 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
9348 int errfile_fd
= -1;
9350 char buf
[sizeof ("\r\nException at this address:\r\n\r\n")
9351 /* The type below should really be 'void *', but
9352 INT_BUFSIZE_BOUND cannot handle that without
9353 triggering compiler warnings (under certain
9354 pedantic warning switches), it wants an
9356 + 2 * INT_BUFSIZE_BOUND (intptr_t)];
9360 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
9363 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
9364 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
9367 /* We use %p, not 0x%p, as %p produces a leading "0x" on XP,
9368 but not on Windows 7. addr2line doesn't mind a missing
9369 "0x", but will be confused by an extra one. */
9371 sprintf (buf
, "\r\nException 0x%lx at this address:\r\n%p\r\n",
9372 except_code
, except_addr
);
9376 write (stderr_fd
, buf
, strlen (buf
));
9377 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
9382 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
9383 if (errfile_fd
>= 0)
9385 lseek (errfile_fd
, 0L, SEEK_END
);
9387 write (errfile_fd
, buf
, strlen (buf
));
9388 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
9391 for (j
= 0; j
< i
; j
++)
9393 /* stack[] gives the return addresses, whereas we want
9394 the address of the call, so decrease each address
9395 by approximate size of 1 CALL instruction. */
9396 sprintf (buf
, "%p\r\n", (char *)stack
[j
] - sizeof(void *));
9398 write (stderr_fd
, buf
, strlen (buf
));
9399 if (errfile_fd
>= 0)
9400 write (errfile_fd
, buf
, strlen (buf
));
9402 if (i
== BACKTRACE_LIMIT_MAX
)
9405 write (stderr_fd
, "...\r\n", 5);
9406 if (errfile_fd
>= 0)
9407 write (errfile_fd
, "...\r\n", 5);
9409 if (errfile_fd
>= 0)
9420 /* Initialization. */
9423 globals_of_w32fns is used to initialize those global variables that
9424 must always be initialized on startup even when the global variable
9425 initialized is non zero (see the function main in emacs.c).
9426 globals_of_w32fns is called from syms_of_w32fns when the global
9427 variable initialized is 0 and directly from main when initialized
9431 globals_of_w32fns (void)
9433 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
9435 TrackMouseEvent not available in all versions of Windows, so must load
9436 it dynamically. Do it once, here, instead of every time it is used.
9438 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
9439 GetProcAddress (user32_lib
, "TrackMouseEvent");
9441 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
9442 GetProcAddress (user32_lib
, "MonitorFromPoint");
9443 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
9444 GetProcAddress (user32_lib
, "GetMonitorInfoA");
9445 monitor_from_window_fn
= (MonitorFromWindow_Proc
)
9446 GetProcAddress (user32_lib
, "MonitorFromWindow");
9447 enum_display_monitors_fn
= (EnumDisplayMonitors_Proc
)
9448 GetProcAddress (user32_lib
, "EnumDisplayMonitors");
9449 get_title_bar_info_fn
= (GetTitleBarInfo_Proc
)
9450 GetProcAddress (user32_lib
, "GetTitleBarInfo");
9453 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
9454 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
9455 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
9456 get_ime_context_fn
= (ImmGetContext_Proc
)
9457 GetProcAddress (imm32_lib
, "ImmGetContext");
9458 release_ime_context_fn
= (ImmReleaseContext_Proc
)
9459 GetProcAddress (imm32_lib
, "ImmReleaseContext");
9460 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
9461 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
9467 prev_exception_handler
= SetUnhandledExceptionFilter (my_exception_handler
);
9470 DEFVAR_INT ("w32-ansi-code-page",
9472 doc
: /* The ANSI code page used by the system. */);
9473 w32_ansi_code_page
= GetACP ();
9475 if (os_subtype
== OS_NT
)
9476 w32_unicode_gui
= 1;
9478 w32_unicode_gui
= 0;
9482 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
9483 InitCommonControls ();
9485 syms_of_w32uniscribe ();
9487 /* Needed for recovery from C stack overflows in batch mode. */
9489 dwMainThreadId
= GetCurrentThreadId ();
9492 #ifdef NTGUI_UNICODE
9495 ntgui_encode_system (Lisp_Object str
)
9497 Lisp_Object encoded
;
9498 to_unicode (str
, &encoded
);
9502 #endif /* NTGUI_UNICODE */