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 #ifndef CCHDEVICENAME
142 #define CCHDEVICENAME 32
144 struct MONITOR_INFO_EX
150 char szDevice
[CCHDEVICENAME
];
153 /* Reportedly, MSVC does not have this in its headers. */
154 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
155 DECLARE_HANDLE(HMONITOR
);
158 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
159 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
160 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
161 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
162 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
163 typedef BOOL (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
164 typedef BOOL (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
165 IN COMPOSITIONFORM
*form
);
166 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
167 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
168 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
169 typedef HMONITOR (WINAPI
* MonitorFromWindow_Proc
)
170 (IN HWND hwnd
, IN DWORD dwFlags
);
171 typedef BOOL
CALLBACK (* MonitorEnum_Proc
)
172 (IN HMONITOR monitor
, IN HDC hdc
, IN RECT
*rcMonitor
, IN LPARAM dwData
);
173 typedef BOOL (WINAPI
* EnumDisplayMonitors_Proc
)
174 (IN HDC hdc
, IN RECT
*rcClip
, IN MonitorEnum_Proc fnEnum
, IN LPARAM dwData
);
176 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
177 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
178 ImmGetContext_Proc get_ime_context_fn
= NULL
;
179 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
180 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
181 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
182 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
183 MonitorFromWindow_Proc monitor_from_window_fn
= NULL
;
184 EnumDisplayMonitors_Proc enum_display_monitors_fn
= NULL
;
187 #define unicode_append_menu AppendMenuW
188 #else /* !NTGUI_UNICODE */
189 extern AppendMenuW_Proc unicode_append_menu
;
190 #endif /* NTGUI_UNICODE */
192 /* Flag to selectively ignore WM_IME_CHAR messages. */
193 static int ignore_ime_char
= 0;
195 /* W95 mousewheel handler */
196 unsigned int msh_mousewheel
= 0;
199 #define MOUSE_BUTTON_ID 1
200 #define MOUSE_MOVE_ID 2
201 #define MENU_FREE_ID 3
202 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
204 #define MENU_FREE_DELAY 1000
205 static unsigned menu_free_timer
= 0;
208 static ptrdiff_t image_cache_refcount
;
209 static int dpyinfo_refcount
;
212 static HWND w32_visible_system_caret_hwnd
;
214 static int w32_unicode_gui
;
217 extern HMENU current_popup_menu
;
218 int menubar_in_use
= 0;
220 /* From w32uniscribe.c */
221 extern void syms_of_w32uniscribe (void);
222 extern int uniscribe_available
;
225 /* From w32inevt.c */
226 extern int faked_key
;
227 #endif /* WINDOWSNT */
229 /* This gives us the page size and the size of the allocation unit on NT. */
230 SYSTEM_INFO sysinfo_cache
;
232 /* This gives us version, build, and platform identification. */
233 OSVERSIONINFO osinfo_cache
;
235 DWORD_PTR syspage_mask
= 0;
237 /* The major and minor versions of NT. */
238 int w32_major_version
;
239 int w32_minor_version
;
240 int w32_build_number
;
242 /* Distinguish between Windows NT and Windows 95. */
246 HINSTANCE hinst
= NULL
;
249 static unsigned int sound_type
= 0xFFFFFFFF;
250 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
252 /* Let the user specify a display with a frame.
253 nil stands for the selected frame--or, if that is not a w32 frame,
254 the first display on the list. */
256 struct w32_display_info
*
257 check_x_display_info (Lisp_Object object
)
261 struct frame
*sf
= XFRAME (selected_frame
);
263 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
264 return FRAME_DISPLAY_INFO (sf
);
266 return &one_w32_display_info
;
268 else if (TERMINALP (object
))
270 struct terminal
*t
= decode_live_terminal (object
);
272 if (t
->type
!= output_w32
)
273 error ("Terminal %d is not a W32 display", t
->id
);
275 return t
->display_info
.w32
;
277 else if (STRINGP (object
))
278 return x_display_info_for_name (object
);
283 CHECK_LIVE_FRAME (object
);
285 if (! FRAME_W32_P (f
))
286 error ("Non-W32 frame used");
287 return FRAME_DISPLAY_INFO (f
);
291 /* Return the Emacs frame-object corresponding to an w32 window.
292 It could be the frame's main window or an icon window. */
295 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
297 Lisp_Object tail
, frame
;
300 FOR_EACH_FRAME (tail
, frame
)
303 if (!FRAME_W32_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
306 if (FRAME_W32_WINDOW (f
) == wdesc
)
313 static Lisp_Object
unwind_create_frame (Lisp_Object
);
314 static void unwind_create_tip_frame (Lisp_Object
);
315 static void my_create_window (struct frame
*);
316 static void my_create_tip_window (struct frame
*);
318 /* TODO: Native Input Method support; see x_create_im. */
319 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
320 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
321 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
322 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
323 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
324 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
325 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
326 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
327 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
328 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
329 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
330 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
331 void x_set_internal_border_width (struct frame
*f
, Lisp_Object
, Lisp_Object
);
334 /* Store the screen positions of frame F into XPTR and YPTR.
335 These are the positions of the containing window manager window,
336 not Emacs's own window. */
339 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
344 /* Get the bounds of the WM window. */
345 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
350 /* Convert (0, 0) in the client area to screen co-ordinates. */
351 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
357 /* Returns the window rectangle appropriate for the given fullscreen mode.
358 The normal rect parameter was the window's rectangle prior to entering
359 fullscreen mode. If multiple monitor support is available, the nearest
360 monitor to the window is chosen. */
363 w32_fullscreen_rect (HWND hwnd
, int fsmode
, RECT normal
, RECT
*rect
)
365 struct MONITOR_INFO mi
= { sizeof(mi
) };
366 if (monitor_from_window_fn
&& get_monitor_info_fn
)
369 monitor_from_window_fn (hwnd
, MONITOR_DEFAULT_TO_NEAREST
);
370 get_monitor_info_fn (monitor
, &mi
);
374 mi
.rcMonitor
.left
= 0;
375 mi
.rcMonitor
.top
= 0;
376 mi
.rcMonitor
.right
= GetSystemMetrics (SM_CXSCREEN
);
377 mi
.rcMonitor
.bottom
= GetSystemMetrics (SM_CYSCREEN
);
380 mi
.rcWork
.right
= GetSystemMetrics (SM_CXMAXIMIZED
);
381 mi
.rcWork
.bottom
= GetSystemMetrics (SM_CYMAXIMIZED
);
386 case FULLSCREEN_BOTH
:
387 rect
->left
= mi
.rcMonitor
.left
;
388 rect
->top
= mi
.rcMonitor
.top
;
389 rect
->right
= mi
.rcMonitor
.right
;
390 rect
->bottom
= mi
.rcMonitor
.bottom
;
392 case FULLSCREEN_WIDTH
:
393 rect
->left
= mi
.rcWork
.left
;
394 rect
->top
= normal
.top
;
395 rect
->right
= mi
.rcWork
.right
;
396 rect
->bottom
= normal
.bottom
;
398 case FULLSCREEN_HEIGHT
:
399 rect
->left
= normal
.left
;
400 rect
->top
= mi
.rcWork
.top
;
401 rect
->right
= normal
.right
;
402 rect
->bottom
= mi
.rcWork
.bottom
;
412 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
413 Sw32_define_rgb_color
, 4, 4, 0,
414 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
415 This adds or updates a named color to `w32-color-map', making it
416 available for use. The original entry's RGB ref is returned, or nil
417 if the entry is new. */)
418 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
421 Lisp_Object oldrgb
= Qnil
;
425 CHECK_NUMBER (green
);
429 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
433 /* replace existing entry in w32-color-map or add new entry. */
434 entry
= Fassoc (name
, Vw32_color_map
);
437 entry
= Fcons (name
, rgb
);
438 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
442 oldrgb
= Fcdr (entry
);
443 Fsetcdr (entry
, rgb
);
451 /* The default colors for the w32 color map */
452 typedef struct colormap_t
458 colormap_t w32_color_map
[] =
460 {"snow" , PALETTERGB (255,250,250)},
461 {"ghost white" , PALETTERGB (248,248,255)},
462 {"GhostWhite" , PALETTERGB (248,248,255)},
463 {"white smoke" , PALETTERGB (245,245,245)},
464 {"WhiteSmoke" , PALETTERGB (245,245,245)},
465 {"gainsboro" , PALETTERGB (220,220,220)},
466 {"floral white" , PALETTERGB (255,250,240)},
467 {"FloralWhite" , PALETTERGB (255,250,240)},
468 {"old lace" , PALETTERGB (253,245,230)},
469 {"OldLace" , PALETTERGB (253,245,230)},
470 {"linen" , PALETTERGB (250,240,230)},
471 {"antique white" , PALETTERGB (250,235,215)},
472 {"AntiqueWhite" , PALETTERGB (250,235,215)},
473 {"papaya whip" , PALETTERGB (255,239,213)},
474 {"PapayaWhip" , PALETTERGB (255,239,213)},
475 {"blanched almond" , PALETTERGB (255,235,205)},
476 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
477 {"bisque" , PALETTERGB (255,228,196)},
478 {"peach puff" , PALETTERGB (255,218,185)},
479 {"PeachPuff" , PALETTERGB (255,218,185)},
480 {"navajo white" , PALETTERGB (255,222,173)},
481 {"NavajoWhite" , PALETTERGB (255,222,173)},
482 {"moccasin" , PALETTERGB (255,228,181)},
483 {"cornsilk" , PALETTERGB (255,248,220)},
484 {"ivory" , PALETTERGB (255,255,240)},
485 {"lemon chiffon" , PALETTERGB (255,250,205)},
486 {"LemonChiffon" , PALETTERGB (255,250,205)},
487 {"seashell" , PALETTERGB (255,245,238)},
488 {"honeydew" , PALETTERGB (240,255,240)},
489 {"mint cream" , PALETTERGB (245,255,250)},
490 {"MintCream" , PALETTERGB (245,255,250)},
491 {"azure" , PALETTERGB (240,255,255)},
492 {"alice blue" , PALETTERGB (240,248,255)},
493 {"AliceBlue" , PALETTERGB (240,248,255)},
494 {"lavender" , PALETTERGB (230,230,250)},
495 {"lavender blush" , PALETTERGB (255,240,245)},
496 {"LavenderBlush" , PALETTERGB (255,240,245)},
497 {"misty rose" , PALETTERGB (255,228,225)},
498 {"MistyRose" , PALETTERGB (255,228,225)},
499 {"white" , PALETTERGB (255,255,255)},
500 {"black" , PALETTERGB ( 0, 0, 0)},
501 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
502 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
503 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
504 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
505 {"dim gray" , PALETTERGB (105,105,105)},
506 {"DimGray" , PALETTERGB (105,105,105)},
507 {"dim grey" , PALETTERGB (105,105,105)},
508 {"DimGrey" , PALETTERGB (105,105,105)},
509 {"slate gray" , PALETTERGB (112,128,144)},
510 {"SlateGray" , PALETTERGB (112,128,144)},
511 {"slate grey" , PALETTERGB (112,128,144)},
512 {"SlateGrey" , PALETTERGB (112,128,144)},
513 {"light slate gray" , PALETTERGB (119,136,153)},
514 {"LightSlateGray" , PALETTERGB (119,136,153)},
515 {"light slate grey" , PALETTERGB (119,136,153)},
516 {"LightSlateGrey" , PALETTERGB (119,136,153)},
517 {"gray" , PALETTERGB (190,190,190)},
518 {"grey" , PALETTERGB (190,190,190)},
519 {"light grey" , PALETTERGB (211,211,211)},
520 {"LightGrey" , PALETTERGB (211,211,211)},
521 {"light gray" , PALETTERGB (211,211,211)},
522 {"LightGray" , PALETTERGB (211,211,211)},
523 {"midnight blue" , PALETTERGB ( 25, 25,112)},
524 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
525 {"navy" , PALETTERGB ( 0, 0,128)},
526 {"navy blue" , PALETTERGB ( 0, 0,128)},
527 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
528 {"cornflower blue" , PALETTERGB (100,149,237)},
529 {"CornflowerBlue" , PALETTERGB (100,149,237)},
530 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
531 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
532 {"slate blue" , PALETTERGB (106, 90,205)},
533 {"SlateBlue" , PALETTERGB (106, 90,205)},
534 {"medium slate blue" , PALETTERGB (123,104,238)},
535 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
536 {"light slate blue" , PALETTERGB (132,112,255)},
537 {"LightSlateBlue" , PALETTERGB (132,112,255)},
538 {"medium blue" , PALETTERGB ( 0, 0,205)},
539 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
540 {"royal blue" , PALETTERGB ( 65,105,225)},
541 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
542 {"blue" , PALETTERGB ( 0, 0,255)},
543 {"dodger blue" , PALETTERGB ( 30,144,255)},
544 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
545 {"deep sky blue" , PALETTERGB ( 0,191,255)},
546 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
547 {"sky blue" , PALETTERGB (135,206,235)},
548 {"SkyBlue" , PALETTERGB (135,206,235)},
549 {"light sky blue" , PALETTERGB (135,206,250)},
550 {"LightSkyBlue" , PALETTERGB (135,206,250)},
551 {"steel blue" , PALETTERGB ( 70,130,180)},
552 {"SteelBlue" , PALETTERGB ( 70,130,180)},
553 {"light steel blue" , PALETTERGB (176,196,222)},
554 {"LightSteelBlue" , PALETTERGB (176,196,222)},
555 {"light blue" , PALETTERGB (173,216,230)},
556 {"LightBlue" , PALETTERGB (173,216,230)},
557 {"powder blue" , PALETTERGB (176,224,230)},
558 {"PowderBlue" , PALETTERGB (176,224,230)},
559 {"pale turquoise" , PALETTERGB (175,238,238)},
560 {"PaleTurquoise" , PALETTERGB (175,238,238)},
561 {"dark turquoise" , PALETTERGB ( 0,206,209)},
562 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
563 {"medium turquoise" , PALETTERGB ( 72,209,204)},
564 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
565 {"turquoise" , PALETTERGB ( 64,224,208)},
566 {"cyan" , PALETTERGB ( 0,255,255)},
567 {"light cyan" , PALETTERGB (224,255,255)},
568 {"LightCyan" , PALETTERGB (224,255,255)},
569 {"cadet blue" , PALETTERGB ( 95,158,160)},
570 {"CadetBlue" , PALETTERGB ( 95,158,160)},
571 {"medium aquamarine" , PALETTERGB (102,205,170)},
572 {"MediumAquamarine" , PALETTERGB (102,205,170)},
573 {"aquamarine" , PALETTERGB (127,255,212)},
574 {"dark green" , PALETTERGB ( 0,100, 0)},
575 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
576 {"dark olive green" , PALETTERGB ( 85,107, 47)},
577 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
578 {"dark sea green" , PALETTERGB (143,188,143)},
579 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
580 {"sea green" , PALETTERGB ( 46,139, 87)},
581 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
582 {"medium sea green" , PALETTERGB ( 60,179,113)},
583 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
584 {"light sea green" , PALETTERGB ( 32,178,170)},
585 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
586 {"pale green" , PALETTERGB (152,251,152)},
587 {"PaleGreen" , PALETTERGB (152,251,152)},
588 {"spring green" , PALETTERGB ( 0,255,127)},
589 {"SpringGreen" , PALETTERGB ( 0,255,127)},
590 {"lawn green" , PALETTERGB (124,252, 0)},
591 {"LawnGreen" , PALETTERGB (124,252, 0)},
592 {"green" , PALETTERGB ( 0,255, 0)},
593 {"chartreuse" , PALETTERGB (127,255, 0)},
594 {"medium spring green" , PALETTERGB ( 0,250,154)},
595 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
596 {"green yellow" , PALETTERGB (173,255, 47)},
597 {"GreenYellow" , PALETTERGB (173,255, 47)},
598 {"lime green" , PALETTERGB ( 50,205, 50)},
599 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
600 {"yellow green" , PALETTERGB (154,205, 50)},
601 {"YellowGreen" , PALETTERGB (154,205, 50)},
602 {"forest green" , PALETTERGB ( 34,139, 34)},
603 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
604 {"olive drab" , PALETTERGB (107,142, 35)},
605 {"OliveDrab" , PALETTERGB (107,142, 35)},
606 {"dark khaki" , PALETTERGB (189,183,107)},
607 {"DarkKhaki" , PALETTERGB (189,183,107)},
608 {"khaki" , PALETTERGB (240,230,140)},
609 {"pale goldenrod" , PALETTERGB (238,232,170)},
610 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
611 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
612 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
613 {"light yellow" , PALETTERGB (255,255,224)},
614 {"LightYellow" , PALETTERGB (255,255,224)},
615 {"yellow" , PALETTERGB (255,255, 0)},
616 {"gold" , PALETTERGB (255,215, 0)},
617 {"light goldenrod" , PALETTERGB (238,221,130)},
618 {"LightGoldenrod" , PALETTERGB (238,221,130)},
619 {"goldenrod" , PALETTERGB (218,165, 32)},
620 {"dark goldenrod" , PALETTERGB (184,134, 11)},
621 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
622 {"rosy brown" , PALETTERGB (188,143,143)},
623 {"RosyBrown" , PALETTERGB (188,143,143)},
624 {"indian red" , PALETTERGB (205, 92, 92)},
625 {"IndianRed" , PALETTERGB (205, 92, 92)},
626 {"saddle brown" , PALETTERGB (139, 69, 19)},
627 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
628 {"sienna" , PALETTERGB (160, 82, 45)},
629 {"peru" , PALETTERGB (205,133, 63)},
630 {"burlywood" , PALETTERGB (222,184,135)},
631 {"beige" , PALETTERGB (245,245,220)},
632 {"wheat" , PALETTERGB (245,222,179)},
633 {"sandy brown" , PALETTERGB (244,164, 96)},
634 {"SandyBrown" , PALETTERGB (244,164, 96)},
635 {"tan" , PALETTERGB (210,180,140)},
636 {"chocolate" , PALETTERGB (210,105, 30)},
637 {"firebrick" , PALETTERGB (178,34, 34)},
638 {"brown" , PALETTERGB (165,42, 42)},
639 {"dark salmon" , PALETTERGB (233,150,122)},
640 {"DarkSalmon" , PALETTERGB (233,150,122)},
641 {"salmon" , PALETTERGB (250,128,114)},
642 {"light salmon" , PALETTERGB (255,160,122)},
643 {"LightSalmon" , PALETTERGB (255,160,122)},
644 {"orange" , PALETTERGB (255,165, 0)},
645 {"dark orange" , PALETTERGB (255,140, 0)},
646 {"DarkOrange" , PALETTERGB (255,140, 0)},
647 {"coral" , PALETTERGB (255,127, 80)},
648 {"light coral" , PALETTERGB (240,128,128)},
649 {"LightCoral" , PALETTERGB (240,128,128)},
650 {"tomato" , PALETTERGB (255, 99, 71)},
651 {"orange red" , PALETTERGB (255, 69, 0)},
652 {"OrangeRed" , PALETTERGB (255, 69, 0)},
653 {"red" , PALETTERGB (255, 0, 0)},
654 {"hot pink" , PALETTERGB (255,105,180)},
655 {"HotPink" , PALETTERGB (255,105,180)},
656 {"deep pink" , PALETTERGB (255, 20,147)},
657 {"DeepPink" , PALETTERGB (255, 20,147)},
658 {"pink" , PALETTERGB (255,192,203)},
659 {"light pink" , PALETTERGB (255,182,193)},
660 {"LightPink" , PALETTERGB (255,182,193)},
661 {"pale violet red" , PALETTERGB (219,112,147)},
662 {"PaleVioletRed" , PALETTERGB (219,112,147)},
663 {"maroon" , PALETTERGB (176, 48, 96)},
664 {"medium violet red" , PALETTERGB (199, 21,133)},
665 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
666 {"violet red" , PALETTERGB (208, 32,144)},
667 {"VioletRed" , PALETTERGB (208, 32,144)},
668 {"magenta" , PALETTERGB (255, 0,255)},
669 {"violet" , PALETTERGB (238,130,238)},
670 {"plum" , PALETTERGB (221,160,221)},
671 {"orchid" , PALETTERGB (218,112,214)},
672 {"medium orchid" , PALETTERGB (186, 85,211)},
673 {"MediumOrchid" , PALETTERGB (186, 85,211)},
674 {"dark orchid" , PALETTERGB (153, 50,204)},
675 {"DarkOrchid" , PALETTERGB (153, 50,204)},
676 {"dark violet" , PALETTERGB (148, 0,211)},
677 {"DarkViolet" , PALETTERGB (148, 0,211)},
678 {"blue violet" , PALETTERGB (138, 43,226)},
679 {"BlueViolet" , PALETTERGB (138, 43,226)},
680 {"purple" , PALETTERGB (160, 32,240)},
681 {"medium purple" , PALETTERGB (147,112,219)},
682 {"MediumPurple" , PALETTERGB (147,112,219)},
683 {"thistle" , PALETTERGB (216,191,216)},
684 {"gray0" , PALETTERGB ( 0, 0, 0)},
685 {"grey0" , PALETTERGB ( 0, 0, 0)},
686 {"dark grey" , PALETTERGB (169,169,169)},
687 {"DarkGrey" , PALETTERGB (169,169,169)},
688 {"dark gray" , PALETTERGB (169,169,169)},
689 {"DarkGray" , PALETTERGB (169,169,169)},
690 {"dark blue" , PALETTERGB ( 0, 0,139)},
691 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
692 {"dark cyan" , PALETTERGB ( 0,139,139)},
693 {"DarkCyan" , PALETTERGB ( 0,139,139)},
694 {"dark magenta" , PALETTERGB (139, 0,139)},
695 {"DarkMagenta" , PALETTERGB (139, 0,139)},
696 {"dark red" , PALETTERGB (139, 0, 0)},
697 {"DarkRed" , PALETTERGB (139, 0, 0)},
698 {"light green" , PALETTERGB (144,238,144)},
699 {"LightGreen" , PALETTERGB (144,238,144)},
703 w32_default_color_map (void)
706 colormap_t
*pc
= w32_color_map
;
713 for (i
= 0; i
< ARRAYELTS (w32_color_map
); pc
++, i
++)
714 cmap
= Fcons (Fcons (build_string (pc
->name
),
715 make_number (pc
->colorref
)),
723 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
724 0, 0, 0, doc
: /* Return the default color map. */)
727 return w32_default_color_map ();
731 w32_color_map_lookup (const char *colorname
)
733 Lisp_Object tail
, ret
= Qnil
;
737 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
739 register Lisp_Object elt
, tem
;
742 if (!CONSP (elt
)) continue;
746 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
762 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
766 /* Other registry operations are done with input blocked. */
769 /* Look for "Control Panel/Colors" under User and Machine registry
771 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
772 KEY_READ
, &colors_key
) == ERROR_SUCCESS
773 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
774 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
777 char color_buffer
[64];
778 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
780 DWORD name_size
, color_size
;
781 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
783 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
784 color_size
= sizeof (color_buffer
);
786 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
788 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
789 NULL
, NULL
, color_buffer
, &color_size
)
793 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
794 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
795 make_number (RGB (r
, g
, b
))),
798 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
799 color_size
= sizeof (color_buffer
);
802 RegCloseKey (colors_key
);
810 x_to_w32_color (const char * colorname
)
812 register Lisp_Object ret
= Qnil
;
816 if (colorname
[0] == '#')
818 /* Could be an old-style RGB Device specification. */
819 int size
= strlen (colorname
+ 1);
820 char *color
= alloca (size
+ 1);
822 strcpy (color
, colorname
+ 1);
823 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
831 for (i
= 0; i
< 3; i
++)
837 /* The check for 'x' in the following conditional takes into
838 account the fact that strtol allows a "0x" in front of
839 our numbers, and we don't. */
840 if (!isxdigit (color
[0]) || color
[1] == 'x')
844 value
= strtoul (color
, &end
, 16);
846 if (errno
== ERANGE
|| end
- color
!= size
)
851 value
= value
* 0x10;
862 colorval
|= (value
<< pos
);
867 XSETINT (ret
, colorval
);
874 else if (strnicmp (colorname
, "rgb:", 4) == 0)
882 color
= colorname
+ 4;
883 for (i
= 0; i
< 3; i
++)
888 /* The check for 'x' in the following conditional takes into
889 account the fact that strtol allows a "0x" in front of
890 our numbers, and we don't. */
891 if (!isxdigit (color
[0]) || color
[1] == 'x')
893 value
= strtoul (color
, &end
, 16);
899 value
= value
* 0x10 + value
;
912 if (value
== ULONG_MAX
)
914 colorval
|= (value
<< pos
);
921 XSETINT (ret
, colorval
);
929 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
931 /* This is an RGB Intensity specification. */
938 color
= colorname
+ 5;
939 for (i
= 0; i
< 3; i
++)
945 value
= strtod (color
, &end
);
948 if (value
< 0.0 || value
> 1.0)
950 val
= (UINT
)(0x100 * value
);
951 /* We used 0x100 instead of 0xFF to give a continuous
952 range between 0.0 and 1.0 inclusive. The next statement
953 fixes the 1.0 case. */
956 colorval
|= (val
<< pos
);
963 XSETINT (ret
, colorval
);
971 /* I am not going to attempt to handle any of the CIE color schemes
972 or TekHVC, since I don't know the algorithms for conversion to
975 /* If we fail to lookup the color name in w32_color_map, then check the
976 colorname to see if it can be crudely approximated: If the X color
977 ends in a number (e.g., "darkseagreen2"), strip the number and
978 return the result of looking up the base color name. */
979 ret
= w32_color_map_lookup (colorname
);
982 int len
= strlen (colorname
);
984 if (isdigit (colorname
[len
- 1]))
986 char *ptr
, *approx
= alloca (len
+ 1);
988 strcpy (approx
, colorname
);
989 ptr
= &approx
[len
- 1];
990 while (ptr
> approx
&& isdigit (*ptr
))
993 ret
= w32_color_map_lookup (approx
);
1002 w32_regenerate_palette (struct frame
*f
)
1004 struct w32_palette_entry
* list
;
1005 LOGPALETTE
* log_palette
;
1006 HPALETTE new_palette
;
1009 /* don't bother trying to create palette if not supported */
1010 if (! FRAME_DISPLAY_INFO (f
)->has_palette
)
1013 log_palette
= (LOGPALETTE
*)
1014 alloca (sizeof (LOGPALETTE
) +
1015 FRAME_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1016 log_palette
->palVersion
= 0x300;
1017 log_palette
->palNumEntries
= FRAME_DISPLAY_INFO (f
)->num_colors
;
1019 list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1021 i
< FRAME_DISPLAY_INFO (f
)->num_colors
;
1022 i
++, list
= list
->next
)
1023 log_palette
->palPalEntry
[i
] = list
->entry
;
1025 new_palette
= CreatePalette (log_palette
);
1029 if (FRAME_DISPLAY_INFO (f
)->palette
)
1030 DeleteObject (FRAME_DISPLAY_INFO (f
)->palette
);
1031 FRAME_DISPLAY_INFO (f
)->palette
= new_palette
;
1033 /* Realize display palette and garbage all frames. */
1034 release_frame_dc (f
, get_frame_dc (f
));
1039 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1040 #define SET_W32_COLOR(pe, color) \
1043 pe.peRed = GetRValue (color); \
1044 pe.peGreen = GetGValue (color); \
1045 pe.peBlue = GetBValue (color); \
1050 /* Keep these around in case we ever want to track color usage. */
1052 w32_map_color (struct frame
*f
, COLORREF color
)
1054 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1056 if (NILP (Vw32_enable_palette
))
1059 /* check if color is already mapped */
1062 if (W32_COLOR (list
->entry
) == color
)
1070 /* not already mapped, so add to list and recreate Windows palette */
1071 list
= xmalloc (sizeof (struct w32_palette_entry
));
1072 SET_W32_COLOR (list
->entry
, color
);
1074 list
->next
= FRAME_DISPLAY_INFO (f
)->color_list
;
1075 FRAME_DISPLAY_INFO (f
)->color_list
= list
;
1076 FRAME_DISPLAY_INFO (f
)->num_colors
++;
1078 /* set flag that palette must be regenerated */
1079 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1083 w32_unmap_color (struct frame
*f
, COLORREF color
)
1085 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1086 struct w32_palette_entry
**prev
= &FRAME_DISPLAY_INFO (f
)->color_list
;
1088 if (NILP (Vw32_enable_palette
))
1091 /* check if color is already mapped */
1094 if (W32_COLOR (list
->entry
) == color
)
1096 if (--list
->refcount
== 0)
1100 FRAME_DISPLAY_INFO (f
)->num_colors
--;
1110 /* set flag that palette must be regenerated */
1111 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1116 /* Gamma-correct COLOR on frame F. */
1119 gamma_correct (struct frame
*f
, COLORREF
*color
)
1123 *color
= PALETTERGB (
1124 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1125 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1126 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1131 /* Decide if color named COLOR is valid for the display associated with
1132 the selected frame; if so, return the rgb values in COLOR_DEF.
1133 If ALLOC is nonzero, allocate a new colormap cell. */
1136 w32_defined_color (struct frame
*f
, const char *color
, XColor
*color_def
,
1139 register Lisp_Object tem
;
1140 COLORREF w32_color_ref
;
1142 tem
= x_to_w32_color (color
);
1148 /* Apply gamma correction. */
1149 w32_color_ref
= XUINT (tem
);
1150 gamma_correct (f
, &w32_color_ref
);
1151 XSETINT (tem
, w32_color_ref
);
1154 /* Map this color to the palette if it is enabled. */
1155 if (!NILP (Vw32_enable_palette
))
1157 struct w32_palette_entry
* entry
=
1158 one_w32_display_info
.color_list
;
1159 struct w32_palette_entry
** prev
=
1160 &one_w32_display_info
.color_list
;
1162 /* check if color is already mapped */
1165 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1167 prev
= &entry
->next
;
1168 entry
= entry
->next
;
1171 if (entry
== NULL
&& alloc_p
)
1173 /* not already mapped, so add to list */
1174 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1175 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1178 one_w32_display_info
.num_colors
++;
1180 /* set flag that palette must be regenerated */
1181 one_w32_display_info
.regen_palette
= TRUE
;
1184 /* Ensure COLORREF value is snapped to nearest color in (default)
1185 palette by simulating the PALETTERGB macro. This works whether
1186 or not the display device has a palette. */
1187 w32_color_ref
= XUINT (tem
) | 0x2000000;
1189 color_def
->pixel
= w32_color_ref
;
1190 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1191 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1192 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1202 /* Given a string ARG naming a color, compute a pixel value from it
1203 suitable for screen F.
1204 If F is not a color screen, return DEF (default) regardless of what
1208 x_decode_color (struct frame
*f
, Lisp_Object arg
, int def
)
1214 if (strcmp (SDATA (arg
), "black") == 0)
1215 return BLACK_PIX_DEFAULT (f
);
1216 else if (strcmp (SDATA (arg
), "white") == 0)
1217 return WHITE_PIX_DEFAULT (f
);
1219 if ((FRAME_DISPLAY_INFO (f
)->n_planes
* FRAME_DISPLAY_INFO (f
)->n_cbits
) == 1)
1222 /* w32_defined_color is responsible for coping with failures
1223 by looking for a near-miss. */
1224 if (w32_defined_color (f
, SDATA (arg
), &cdef
, true))
1227 /* defined_color failed; return an ultimate default. */
1233 /* Functions called only from `x_set_frame_param'
1234 to set individual parameters.
1236 If FRAME_W32_WINDOW (f) is 0,
1237 the frame is being created and its window does not exist yet.
1238 In that case, just record the parameter's new value
1239 in the standard place; do not attempt to change the window. */
1242 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1244 struct w32_output
*x
= f
->output_data
.w32
;
1245 PIX_TYPE fg
, old_fg
;
1247 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1248 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1249 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1251 if (FRAME_W32_WINDOW (f
) != 0)
1253 if (x
->cursor_pixel
== old_fg
)
1255 x
->cursor_pixel
= fg
;
1256 x
->cursor_gc
->background
= fg
;
1259 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1260 if (FRAME_VISIBLE_P (f
))
1266 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1268 FRAME_BACKGROUND_PIXEL (f
)
1269 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1271 if (FRAME_W32_WINDOW (f
) != 0)
1273 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1274 FRAME_BACKGROUND_PIXEL (f
));
1276 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1278 if (FRAME_VISIBLE_P (f
))
1284 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1286 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1290 if (!EQ (Qnil
, arg
))
1291 f
->output_data
.w32
->mouse_pixel
1292 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1293 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1295 /* Don't let pointers be invisible. */
1296 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1297 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1298 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1300 #if 0 /* TODO : Mouse cursor customization. */
1303 /* It's not okay to crash if the user selects a screwy cursor. */
1304 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1306 if (!EQ (Qnil
, Vx_pointer_shape
))
1308 CHECK_NUMBER (Vx_pointer_shape
);
1309 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1312 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1313 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1315 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1317 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1318 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1319 XINT (Vx_nontext_pointer_shape
));
1322 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1323 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1325 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1327 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1328 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1329 XINT (Vx_hourglass_pointer_shape
));
1332 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1333 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1335 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1336 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1338 CHECK_NUMBER (Vx_mode_pointer_shape
);
1339 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1340 XINT (Vx_mode_pointer_shape
));
1343 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1344 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1346 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1348 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1350 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1351 XINT (Vx_sensitive_text_pointer_shape
));
1354 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1356 if (!NILP (Vx_window_horizontal_drag_shape
))
1358 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1359 horizontal_drag_cursor
1360 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1361 XINT (Vx_window_horizontal_drag_shape
));
1364 horizontal_drag_cursor
1365 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_h_double_arrow
);
1367 if (!NILP (Vx_window_vertical_drag_shape
))
1369 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
1370 vertical_drag_cursor
1371 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1372 XINT (Vx_window_vertical_drag_shape
));
1375 vertical_drag_cursor
1376 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_v_double_arrow
);
1378 /* Check and report errors with the above calls. */
1379 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1380 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1383 XColor fore_color
, back_color
;
1385 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1386 back_color
.pixel
= mask_color
;
1387 XQueryColor (FRAME_W32_DISPLAY (f
),
1388 DefaultColormap (FRAME_W32_DISPLAY (f
),
1389 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1391 XQueryColor (FRAME_W32_DISPLAY (f
),
1392 DefaultColormap (FRAME_W32_DISPLAY (f
),
1393 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1395 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1396 &fore_color
, &back_color
);
1397 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1398 &fore_color
, &back_color
);
1399 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1400 &fore_color
, &back_color
);
1401 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1402 &fore_color
, &back_color
);
1403 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1404 &fore_color
, &back_color
);
1407 if (FRAME_W32_WINDOW (f
) != 0)
1408 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1410 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1411 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1412 f
->output_data
.w32
->text_cursor
= cursor
;
1414 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1415 && f
->output_data
.w32
->nontext_cursor
!= 0)
1416 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1417 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1419 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1420 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1421 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1422 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1424 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1425 && f
->output_data
.w32
->modeline_cursor
!= 0)
1426 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1427 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1429 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1430 && f
->output_data
.w32
->hand_cursor
!= 0)
1431 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1432 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1434 XFlush (FRAME_W32_DISPLAY (f
));
1437 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1442 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1444 unsigned long fore_pixel
, pixel
;
1446 if (!NILP (Vx_cursor_fore_pixel
))
1447 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1448 WHITE_PIX_DEFAULT (f
));
1450 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1452 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1454 /* Make sure that the cursor color differs from the background color. */
1455 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1457 pixel
= f
->output_data
.w32
->mouse_pixel
;
1458 if (pixel
== fore_pixel
)
1459 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1462 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1463 f
->output_data
.w32
->cursor_pixel
= pixel
;
1465 if (FRAME_W32_WINDOW (f
) != 0)
1468 /* Update frame's cursor_gc. */
1469 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1470 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1474 if (FRAME_VISIBLE_P (f
))
1476 x_update_cursor (f
, 0);
1477 x_update_cursor (f
, 1);
1481 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1484 /* Set the border-color of frame F to pixel value PIX.
1485 Note that this does not fully take effect if done before
1489 x_set_border_pixel (struct frame
*f
, int pix
)
1492 f
->output_data
.w32
->border_pixel
= pix
;
1494 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1496 if (FRAME_VISIBLE_P (f
))
1501 /* Set the border-color of frame F to value described by ARG.
1502 ARG can be a string naming a color.
1503 The border-color is used for the border that is drawn by the server.
1504 Note that this does not fully take effect if done before
1505 F has a window; it must be redone when the window is created. */
1508 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1513 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1514 x_set_border_pixel (f
, pix
);
1515 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1520 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1522 set_frame_cursor_types (f
, arg
);
1526 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1530 if (NILP (arg
) && NILP (oldval
))
1533 if (STRINGP (arg
) && STRINGP (oldval
)
1534 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1537 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1542 result
= x_bitmap_icon (f
, arg
);
1546 error ("No icon window available");
1553 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1557 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1560 else if (!NILP (arg
) || NILP (oldval
))
1563 fset_icon_name (f
, arg
);
1566 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1571 result
= x_text_icon (f
,
1572 SSDATA ((!NILP (f
->icon_name
)
1581 error ("No icon window available");
1584 /* If the window was unmapped (and its icon was mapped),
1585 the new icon is not mapped, so map the window in its stead. */
1586 if (FRAME_VISIBLE_P (f
))
1588 #ifdef USE_X_TOOLKIT
1589 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1591 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1594 XFlush (FRAME_W32_DISPLAY (f
));
1600 x_clear_under_internal_border (struct frame
*f
)
1602 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1604 /* Clear border if it's larger than before. */
1607 HDC hdc
= get_frame_dc (f
);
1608 int width
= FRAME_PIXEL_WIDTH (f
);
1609 int height
= FRAME_PIXEL_HEIGHT (f
);
1612 w32_clear_area (f
, hdc
, 0, FRAME_TOP_MARGIN_HEIGHT (f
), width
, border
);
1613 w32_clear_area (f
, hdc
, 0, 0, border
, height
);
1614 w32_clear_area (f
, hdc
, width
- border
, 0, border
, height
);
1615 w32_clear_area (f
, hdc
, 0, height
- border
, width
, border
);
1616 release_frame_dc (f
, hdc
);
1623 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1627 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1628 border
= max (XINT (arg
), 0);
1630 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1632 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1634 if (FRAME_X_WINDOW (f
) != 0)
1636 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1638 if (FRAME_VISIBLE_P (f
))
1639 x_clear_under_internal_border (f
);
1646 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1650 /* Right now, menu bars don't work properly in minibuf-only frames;
1651 most of the commands try to apply themselves to the minibuffer
1652 frame itself, and get an error because you can't switch buffers
1653 in or split the minibuffer window. */
1654 if (FRAME_MINIBUF_ONLY_P (f
))
1657 if (INTEGERP (value
))
1658 nlines
= XINT (value
);
1662 FRAME_MENU_BAR_LINES (f
) = 0;
1663 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1666 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1667 windows_or_buffers_changed
= 23;
1671 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1672 free_frame_menubar (f
);
1673 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1675 /* Adjust the frame size so that the client (text) dimensions
1676 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1677 set correctly. Note that we resize twice: The first time upon
1678 a request from the window manager who wants to keep the height
1679 of the outer rectangle (including decorations) unchanged, and a
1680 second time because we want to keep the height of the inner
1681 rectangle (without the decorations unchanged). */
1682 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1684 /* Not sure whether this is needed. */
1685 x_clear_under_internal_border (f
);
1690 /* Set the number of lines used for the tool bar of frame F to VALUE.
1691 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL is
1692 the old number of tool bar lines (and is unused). This function may
1693 change the height of all windows on frame F to match the new tool bar
1694 height. By design, the frame's height doesn't change (but maybe it
1695 should if we don't get enough space otherwise). */
1698 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1702 /* Treat tool bars like menu bars. */
1703 if (FRAME_MINIBUF_ONLY_P (f
))
1706 /* Use VALUE only if an integer >= 0. */
1707 if (INTEGERP (value
) && XINT (value
) >= 0)
1708 nlines
= XFASTINT (value
);
1712 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1716 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1718 x_change_tool_bar_height (struct frame
*f
, int height
)
1721 int unit
= FRAME_LINE_HEIGHT (f
);
1722 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1723 int lines
= (height
+ unit
- 1) / unit
;
1724 int old_text_height
= FRAME_TEXT_HEIGHT (f
);
1725 Lisp_Object fullscreen
;
1727 /* Make sure we redisplay all windows in this frame. */
1728 windows_or_buffers_changed
= 23;
1730 /* Recalculate tool bar and frame text sizes. */
1731 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1732 FRAME_TOOL_BAR_LINES (f
) = lines
;
1733 /* Store `tool-bar-lines' and `height' frame parameters. */
1734 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1735 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1737 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1740 clear_current_matrices (f
);
1743 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1744 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1746 /* Recalculate toolbar height. */
1747 f
->n_tool_bar_rows
= 0;
1749 adjust_frame_size (f
, -1, -1,
1750 ((!f
->tool_bar_redisplayed_once
1751 && (NILP (fullscreen
=
1752 get_frame_param (f
, Qfullscreen
))
1753 || EQ (fullscreen
, Qfullwidth
))) ? 1
1754 : (old_height
== 0 || height
== 0) ? 2
1756 false, Qtool_bar_lines
);
1758 /* adjust_frame_size might not have done anything, garbage frame
1760 adjust_frame_glyphs (f
);
1761 SET_FRAME_GARBAGED (f
);
1762 if (FRAME_X_WINDOW (f
))
1763 x_clear_under_internal_border (f
);
1767 w32_set_title_bar_text (struct frame
*f
, Lisp_Object name
)
1769 if (FRAME_W32_WINDOW (f
))
1773 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1774 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1776 /* The frame's title many times shows the name of the file
1777 visited in the selected window's buffer, so it makes sense to
1778 support non-ASCII characters outside of the current system
1779 codepage in the title. */
1780 if (w32_unicode_filenames
)
1782 Lisp_Object encoded_title
= ENCODE_UTF_8 (name
);
1784 int tlen
= pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
),
1789 /* Windows truncates the title text beyond what fits on
1790 a single line, so we can limit the length to some
1791 reasonably large value, and use alloca. */
1794 title_w
= alloca ((tlen
+ 1) * sizeof (wchar_t));
1795 pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
), -1,
1797 title_w
[tlen
] = L
'\0';
1798 SetWindowTextW (FRAME_W32_WINDOW (f
), title_w
);
1800 else /* Conversion to UTF-16 failed, so we punt. */
1801 SetWindowTextA (FRAME_W32_WINDOW (f
),
1802 SSDATA (ENCODE_SYSTEM (name
)));
1805 SetWindowTextA (FRAME_W32_WINDOW (f
), SSDATA (ENCODE_SYSTEM (name
)));
1811 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1814 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1815 name; if NAME is a string, set F's name to NAME and set
1816 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1818 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1819 suggesting a new name, which lisp code should override; if
1820 F->explicit_name is set, ignore the new name; otherwise, set it. */
1823 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1825 /* Make sure that requests from lisp code override requests from
1826 Emacs redisplay code. */
1829 /* If we're switching from explicit to implicit, we had better
1830 update the mode lines and thereby update the title. */
1831 if (f
->explicit_name
&& NILP (name
))
1832 update_mode_lines
= 25;
1834 f
->explicit_name
= ! NILP (name
);
1836 else if (f
->explicit_name
)
1839 /* If NAME is nil, set the name to the w32_id_name. */
1842 /* Check for no change needed in this very common case
1843 before we do any consing. */
1844 if (!strcmp (FRAME_DISPLAY_INFO (f
)->w32_id_name
,
1847 name
= build_string (FRAME_DISPLAY_INFO (f
)->w32_id_name
);
1850 CHECK_STRING (name
);
1852 /* Don't change the name if it's already NAME. */
1853 if (! NILP (Fstring_equal (name
, f
->name
)))
1856 fset_name (f
, name
);
1858 /* For setting the frame title, the title parameter should override
1859 the name parameter. */
1860 if (! NILP (f
->title
))
1863 w32_set_title_bar_text (f
, name
);
1866 /* This function should be called when the user's lisp code has
1867 specified a name for the frame; the name will override any set by the
1870 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1872 x_set_name (f
, arg
, true);
1875 /* This function should be called by Emacs redisplay code to set the
1876 name; names set this way will never override names set by the user's
1879 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1881 x_set_name (f
, arg
, false);
1884 /* Change the title of frame F to NAME.
1885 If NAME is nil, use the frame name as the title. */
1888 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1890 /* Don't change the title if it's already NAME. */
1891 if (EQ (name
, f
->title
))
1894 update_mode_lines
= 26;
1896 fset_title (f
, name
);
1901 w32_set_title_bar_text (f
, name
);
1905 x_set_scroll_bar_default_width (struct frame
*f
)
1907 int unit
= FRAME_COLUMN_WIDTH (f
);
1909 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1910 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
1911 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
1916 x_set_scroll_bar_default_height (struct frame
*f
)
1918 int unit
= FRAME_LINE_HEIGHT (f
);
1920 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
1921 FRAME_CONFIG_SCROLL_BAR_LINES (f
)
1922 = (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) + unit
- 1) / unit
;
1925 /* Subroutines for creating a frame. */
1928 w32_load_cursor (LPCTSTR name
)
1930 /* Try first to load cursor from application resource. */
1931 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1932 name
, IMAGE_CURSOR
, 0, 0,
1933 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1936 /* Then try to load a shared predefined cursor. */
1937 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1938 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1943 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1945 #define INIT_WINDOW_CLASS(WC) \
1946 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1947 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1948 (WC).cbClsExtra = 0; \
1949 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1950 (WC).hInstance = hinst; \
1951 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1952 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1953 (WC).hbrBackground = NULL; \
1954 (WC).lpszMenuName = NULL; \
1957 w32_init_class (HINSTANCE hinst
)
1959 if (w32_unicode_gui
)
1962 INIT_WINDOW_CLASS(uwc
);
1963 uwc
.lpszClassName
= L
"Emacs";
1965 return RegisterClassW (&uwc
);
1970 INIT_WINDOW_CLASS(wc
);
1971 wc
.lpszClassName
= EMACS_CLASS
;
1973 return RegisterClassA (&wc
);
1978 w32_createvscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1980 return CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1981 /* Position and size of scroll bar. */
1982 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
1983 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
1987 w32_createhscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1989 return CreateWindow ("SCROLLBAR", "", SBS_HORZ
| WS_CHILD
| WS_VISIBLE
,
1990 /* Position and size of scroll bar. */
1991 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
1992 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
1996 w32_createwindow (struct frame
*f
, int *coords
)
2003 rect
.left
= rect
.top
= 0;
2004 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2005 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2007 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2008 FRAME_EXTERNAL_MENU_BAR (f
));
2010 /* Do first time app init */
2012 w32_init_class (hinst
);
2014 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2025 FRAME_W32_WINDOW (f
) = hwnd
2026 = CreateWindow (EMACS_CLASS
,
2028 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2030 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2038 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2039 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2040 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2041 SetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
2042 SetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_HEIGHT (f
));
2043 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2045 /* Enable drag-n-drop. */
2046 DragAcceptFiles (hwnd
, TRUE
);
2048 /* Do this to discard the default setting specified by our parent. */
2049 ShowWindow (hwnd
, SW_HIDE
);
2051 /* Update frame positions. */
2052 GetWindowRect (hwnd
, &rect
);
2053 f
->left_pos
= rect
.left
;
2054 f
->top_pos
= rect
.top
;
2059 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2061 wmsg
->msg
.hwnd
= hwnd
;
2062 wmsg
->msg
.message
= msg
;
2063 wmsg
->msg
.wParam
= wParam
;
2064 wmsg
->msg
.lParam
= lParam
;
2065 wmsg
->msg
.time
= GetMessageTime ();
2070 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2071 between left and right keys as advertised. We test for this
2072 support dynamically, and set a flag when the support is absent. If
2073 absent, we keep track of the left and right control and alt keys
2074 ourselves. This is particularly necessary on keyboards that rely
2075 upon the AltGr key, which is represented as having the left control
2076 and right alt keys pressed. For these keyboards, we need to know
2077 when the left alt key has been pressed in addition to the AltGr key
2078 so that we can properly support M-AltGr-key sequences (such as M-@
2079 on Swedish keyboards). */
2081 #define EMACS_LCONTROL 0
2082 #define EMACS_RCONTROL 1
2083 #define EMACS_LMENU 2
2084 #define EMACS_RMENU 3
2086 static int modifiers
[4];
2087 static int modifiers_recorded
;
2088 static int modifier_key_support_tested
;
2091 test_modifier_support (unsigned int wparam
)
2095 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2097 if (wparam
== VK_CONTROL
)
2107 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2108 modifiers_recorded
= 1;
2110 modifiers_recorded
= 0;
2111 modifier_key_support_tested
= 1;
2115 record_keydown (unsigned int wparam
, unsigned int lparam
)
2119 if (!modifier_key_support_tested
)
2120 test_modifier_support (wparam
);
2122 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2125 if (wparam
== VK_CONTROL
)
2126 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2128 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2134 record_keyup (unsigned int wparam
, unsigned int lparam
)
2138 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2141 if (wparam
== VK_CONTROL
)
2142 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2144 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2149 /* Emacs can lose focus while a modifier key has been pressed. When
2150 it regains focus, be conservative and clear all modifiers since
2151 we cannot reconstruct the left and right modifier state. */
2153 reset_modifiers (void)
2157 if (GetFocus () == NULL
)
2158 /* Emacs doesn't have keyboard focus. Do nothing. */
2161 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2162 alt
= GetAsyncKeyState (VK_MENU
);
2164 if (!(ctrl
& 0x08000))
2165 /* Clear any recorded control modifier state. */
2166 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2168 if (!(alt
& 0x08000))
2169 /* Clear any recorded alt modifier state. */
2170 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2172 /* Update the state of all modifier keys, because modifiers used in
2173 hot-key combinations can get stuck on if Emacs loses focus as a
2174 result of a hot-key being pressed. */
2178 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2180 memset (keystate
, 0, sizeof (keystate
));
2181 GetKeyboardState (keystate
);
2182 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2183 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2184 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2185 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2186 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2187 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2188 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2189 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2190 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2191 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2192 SetKeyboardState (keystate
);
2196 /* Synchronize modifier state with what is reported with the current
2197 keystroke. Even if we cannot distinguish between left and right
2198 modifier keys, we know that, if no modifiers are set, then neither
2199 the left or right modifier should be set. */
2201 sync_modifiers (void)
2203 if (!modifiers_recorded
)
2206 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2207 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2209 if (!(GetKeyState (VK_MENU
) & 0x8000))
2210 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2214 modifier_set (int vkey
)
2216 /* Warning: The fact that VK_NUMLOCK is not treated as the other 2
2217 toggle keys is not an omission! If you want to add it, you will
2218 have to make changes in the default sub-case of the WM_KEYDOWN
2219 switch, because if the NUMLOCK modifier is set, the code there
2220 will directly convert any key that looks like an ASCII letter,
2221 and also downcase those that look like upper-case ASCII. */
2222 if (vkey
== VK_CAPITAL
)
2224 if (NILP (Vw32_enable_caps_lock
))
2227 return (GetKeyState (vkey
) & 0x1);
2229 if (vkey
== VK_SCROLL
)
2231 if (NILP (Vw32_scroll_lock_modifier
)
2232 /* w32-scroll-lock-modifier can be any non-nil value that is
2233 not one of the modifiers, in which case it shall be ignored. */
2234 || !( EQ (Vw32_scroll_lock_modifier
, Qhyper
)
2235 || EQ (Vw32_scroll_lock_modifier
, Qsuper
)
2236 || EQ (Vw32_scroll_lock_modifier
, Qmeta
)
2237 || EQ (Vw32_scroll_lock_modifier
, Qalt
)
2238 || EQ (Vw32_scroll_lock_modifier
, Qcontrol
)
2239 || EQ (Vw32_scroll_lock_modifier
, Qshift
)))
2242 return (GetKeyState (vkey
) & 0x1);
2245 if (!modifiers_recorded
)
2246 return (GetKeyState (vkey
) & 0x8000);
2251 return modifiers
[EMACS_LCONTROL
];
2253 return modifiers
[EMACS_RCONTROL
];
2255 return modifiers
[EMACS_LMENU
];
2257 return modifiers
[EMACS_RMENU
];
2259 return (GetKeyState (vkey
) & 0x8000);
2262 /* Convert between the modifier bits W32 uses and the modifier bits
2266 w32_key_to_modifier (int key
)
2268 Lisp_Object key_mapping
;
2273 key_mapping
= Vw32_lwindow_modifier
;
2276 key_mapping
= Vw32_rwindow_modifier
;
2279 key_mapping
= Vw32_apps_modifier
;
2282 key_mapping
= Vw32_scroll_lock_modifier
;
2288 /* NB. This code runs in the input thread, asynchronously to the lisp
2289 thread, so we must be careful to ensure access to lisp data is
2290 thread-safe. The following code is safe because the modifier
2291 variable values are updated atomically from lisp and symbols are
2292 not relocated by GC. Also, we don't have to worry about seeing GC
2294 if (EQ (key_mapping
, Qhyper
))
2295 return hyper_modifier
;
2296 if (EQ (key_mapping
, Qsuper
))
2297 return super_modifier
;
2298 if (EQ (key_mapping
, Qmeta
))
2299 return meta_modifier
;
2300 if (EQ (key_mapping
, Qalt
))
2301 return alt_modifier
;
2302 if (EQ (key_mapping
, Qctrl
))
2303 return ctrl_modifier
;
2304 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2305 return ctrl_modifier
;
2306 if (EQ (key_mapping
, Qshift
))
2307 return shift_modifier
;
2309 /* Don't generate any modifier if not explicitly requested. */
2314 w32_get_modifiers (void)
2316 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2317 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2318 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2319 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2320 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2321 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2322 (modifier_set (VK_MENU
) ?
2323 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2326 /* We map the VK_* modifiers into console modifier constants
2327 so that we can use the same routines to handle both console
2328 and window input. */
2331 construct_console_modifiers (void)
2336 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2337 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2338 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2339 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2340 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2341 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2342 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2343 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2344 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2345 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2346 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2352 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2356 /* Convert to emacs modifiers. */
2357 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2363 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2365 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2368 if (virt_key
== VK_RETURN
)
2369 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2371 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2372 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2374 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2375 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2377 if (virt_key
== VK_CLEAR
)
2378 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2383 /* List of special key combinations which w32 would normally capture,
2384 but Emacs should grab instead. Not directly visible to lisp, to
2385 simplify synchronization. Each item is an integer encoding a virtual
2386 key code and modifier combination to capture. */
2387 static Lisp_Object w32_grabbed_keys
;
2389 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2390 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2391 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2392 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2394 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2395 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2396 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2398 /* Register hot-keys for reserved key combinations when Emacs has
2399 keyboard focus, since this is the only way Emacs can receive key
2400 combinations like Alt-Tab which are used by the system. */
2403 register_hot_keys (HWND hwnd
)
2405 Lisp_Object keylist
;
2407 /* Use CONSP, since we are called asynchronously. */
2408 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2410 Lisp_Object key
= XCAR (keylist
);
2412 /* Deleted entries get set to nil. */
2413 if (!INTEGERP (key
))
2416 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2417 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2422 unregister_hot_keys (HWND hwnd
)
2424 Lisp_Object keylist
;
2426 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2428 Lisp_Object key
= XCAR (keylist
);
2430 if (!INTEGERP (key
))
2433 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2439 w32_name_of_message (UINT msg
)
2442 static char buf
[64];
2443 static const struct {
2447 #define M(msg) { msg, # msg }
2455 M (WM_EMACS_CREATEWINDOW
),
2457 M (WM_EMACS_CREATEVSCROLLBAR
),
2458 M (WM_EMACS_CREATEHSCROLLBAR
),
2459 M (WM_EMACS_SHOWWINDOW
),
2460 M (WM_EMACS_SETWINDOWPOS
),
2461 M (WM_EMACS_DESTROYWINDOW
),
2462 M (WM_EMACS_TRACKPOPUPMENU
),
2463 M (WM_EMACS_SETFOCUS
),
2464 M (WM_EMACS_SETFOREGROUND
),
2465 M (WM_EMACS_SETLOCALE
),
2466 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2467 M (WM_EMACS_REGISTER_HOT_KEY
),
2468 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2469 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2470 M (WM_EMACS_TRACK_CARET
),
2471 M (WM_EMACS_DESTROY_CARET
),
2472 M (WM_EMACS_SHOW_CARET
),
2473 M (WM_EMACS_HIDE_CARET
),
2474 M (WM_EMACS_SETCURSOR
),
2475 M (WM_EMACS_SHOWCURSOR
),
2482 for (i
= 0; msgnames
[i
].name
; ++i
)
2483 if (msgnames
[i
].msg
== msg
)
2484 return msgnames
[i
].name
;
2486 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2489 #endif /* EMACSDEBUG */
2491 /* Here's an overview of how Emacs input works in GUI sessions on
2492 MS-Windows. (For description of non-GUI input, see the commentary
2493 before w32_console_read_socket in w32inevt.c.)
2495 System messages are read and processed by w32_msg_pump below. This
2496 function runs in a separate thread. It handles a small number of
2497 custom WM_EMACS_* messages (posted by the main thread, look for
2498 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2499 is the main window procedure for the entire Emacs application.
2501 w32_wnd_proc also runs in the same separate input thread. It
2502 handles some messages, mostly those that need GDI calls, by itself.
2503 For the others, it calls my_post_msg, which inserts the messages
2504 into the input queue serviced by w32_read_socket.
2506 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2507 called synchronously from keyboard.c when it is known or suspected
2508 that some input is available. w32_read_socket either handles
2509 messages immediately, or converts them into Emacs input events and
2510 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2511 them and process them when read_char and its callers require
2514 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2515 select(2) takes the place of w32_read_socket.
2519 /* Main message dispatch loop. */
2522 w32_msg_pump (deferred_msg
* msg_buf
)
2528 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2530 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2533 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2534 /* w32_name_of_message (msg.message), msg.time)); */
2536 if (msg
.hwnd
== NULL
)
2538 switch (msg
.message
)
2541 /* Produced by complete_deferred_msg; just ignore. */
2543 case WM_EMACS_CREATEWINDOW
:
2544 /* Initialize COM for this window. Even though we don't use it,
2545 some third party shell extensions can cause it to be used in
2546 system dialogs, which causes a crash if it is not initialized.
2547 This is a known bug in Windows, which was fixed long ago, but
2548 the patch for XP is not publicly available until XP SP3,
2549 and older versions will never be patched. */
2550 CoInitialize (NULL
);
2551 w32_createwindow ((struct frame
*) msg
.wParam
,
2552 (int *) msg
.lParam
);
2553 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2556 case WM_EMACS_SETLOCALE
:
2557 SetThreadLocale (msg
.wParam
);
2558 /* Reply is not expected. */
2560 case WM_EMACS_SETKEYBOARDLAYOUT
:
2561 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2562 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2566 case WM_EMACS_REGISTER_HOT_KEY
:
2567 focus_window
= GetFocus ();
2568 if (focus_window
!= NULL
)
2569 RegisterHotKey (focus_window
,
2570 RAW_HOTKEY_ID (msg
.wParam
),
2571 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2572 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2573 /* Reply is not expected. */
2575 case WM_EMACS_UNREGISTER_HOT_KEY
:
2576 focus_window
= GetFocus ();
2577 if (focus_window
!= NULL
)
2578 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2579 /* Mark item as erased. NB: this code must be
2580 thread-safe. The next line is okay because the cons
2581 cell is never made into garbage and is not relocated by
2583 XSETCAR (make_lisp_ptr ((void *)msg
.lParam
, Lisp_Cons
), Qnil
);
2584 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2587 case WM_EMACS_TOGGLE_LOCK_KEY
:
2589 int vk_code
= (int) msg
.wParam
;
2590 int cur_state
= (GetKeyState (vk_code
) & 1);
2591 int new_state
= msg
.lParam
;
2594 || ((new_state
& 1) != cur_state
))
2596 one_w32_display_info
.faked_key
= vk_code
;
2598 keybd_event ((BYTE
) vk_code
,
2599 (BYTE
) MapVirtualKey (vk_code
, 0),
2600 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2601 keybd_event ((BYTE
) vk_code
,
2602 (BYTE
) MapVirtualKey (vk_code
, 0),
2603 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2604 keybd_event ((BYTE
) vk_code
,
2605 (BYTE
) MapVirtualKey (vk_code
, 0),
2606 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2607 cur_state
= !cur_state
;
2609 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2615 /* Broadcast messages make it here, so you need to be looking
2616 for something in particular for this to be useful. */
2618 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2624 if (w32_unicode_gui
)
2625 DispatchMessageW (&msg
);
2627 DispatchMessageA (&msg
);
2630 /* Exit nested loop when our deferred message has completed. */
2631 if (msg_buf
->completed
)
2636 deferred_msg
* deferred_msg_head
;
2638 static deferred_msg
*
2639 find_deferred_msg (HWND hwnd
, UINT msg
)
2641 deferred_msg
* item
;
2643 /* Don't actually need synchronization for read access, since
2644 modification of single pointer is always atomic. */
2645 /* enter_crit (); */
2647 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2648 if (item
->w32msg
.msg
.hwnd
== hwnd
2649 && item
->w32msg
.msg
.message
== msg
)
2652 /* leave_crit (); */
2658 send_deferred_msg (deferred_msg
* msg_buf
,
2664 /* Only input thread can send deferred messages. */
2665 if (GetCurrentThreadId () != dwWindowsThreadId
)
2668 /* It is an error to send a message that is already deferred. */
2669 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2672 /* Enforced synchronization is not needed because this is the only
2673 function that alters deferred_msg_head, and the following critical
2674 section is guaranteed to only be serially reentered (since only the
2675 input thread can call us). */
2677 /* enter_crit (); */
2679 msg_buf
->completed
= 0;
2680 msg_buf
->next
= deferred_msg_head
;
2681 deferred_msg_head
= msg_buf
;
2682 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2684 /* leave_crit (); */
2686 /* Start a new nested message loop to process other messages until
2687 this one is completed. */
2688 w32_msg_pump (msg_buf
);
2690 deferred_msg_head
= msg_buf
->next
;
2692 return msg_buf
->result
;
2696 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2698 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2700 if (msg_buf
== NULL
)
2701 /* Message may have been canceled, so don't abort. */
2704 msg_buf
->result
= result
;
2705 msg_buf
->completed
= 1;
2707 /* Ensure input thread is woken so it notices the completion. */
2708 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2712 cancel_all_deferred_msgs (void)
2714 deferred_msg
* item
;
2716 /* Don't actually need synchronization for read access, since
2717 modification of single pointer is always atomic. */
2718 /* enter_crit (); */
2720 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2723 item
->completed
= 1;
2726 /* leave_crit (); */
2728 /* Ensure input thread is woken so it notices the completion. */
2729 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2733 w32_msg_worker (void *arg
)
2736 deferred_msg dummy_buf
;
2738 /* Ensure our message queue is created */
2740 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2742 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2745 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2746 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2747 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2749 /* This is the initial message loop which should only exit when the
2750 application quits. */
2751 w32_msg_pump (&dummy_buf
);
2757 signal_user_input (void)
2759 /* Interrupt any lisp that wants to be interrupted by input. */
2760 if (!NILP (Vthrow_on_input
))
2762 Vquit_flag
= Vthrow_on_input
;
2763 /* Doing a QUIT from this thread is a bad idea, since this
2764 unwinds the stack of the Lisp thread, and the Windows runtime
2765 rightfully barfs. Disabled. */
2767 /* If we're inside a function that wants immediate quits,
2769 if (immediate_quit
&& NILP (Vinhibit_quit
))
2780 post_character_message (HWND hwnd
, UINT msg
,
2781 WPARAM wParam
, LPARAM lParam
,
2786 wmsg
.dwModifiers
= modifiers
;
2788 /* Detect quit_char and set quit-flag directly. Note that we
2789 still need to post a message to ensure the main thread will be
2790 woken up if blocked in sys_select, but we do NOT want to post
2791 the quit_char message itself (because it will usually be as if
2792 the user had typed quit_char twice). Instead, we post a dummy
2793 message that has no particular effect. */
2796 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2797 c
= make_ctrl_char (c
) & 0377;
2799 || (wmsg
.dwModifiers
== 0
2800 && w32_quit_key
&& wParam
== w32_quit_key
))
2804 /* The choice of message is somewhat arbitrary, as long as
2805 the main thread handler just ignores it. */
2808 /* Interrupt any blocking system calls. */
2811 /* As a safety precaution, forcibly complete any deferred
2812 messages. This is a kludge, but I don't see any particularly
2813 clean way to handle the situation where a deferred message is
2814 "dropped" in the lisp thread, and will thus never be
2815 completed, eg. by the user trying to activate the menubar
2816 when the lisp thread is busy, and then typing C-g when the
2817 menubar doesn't open promptly (with the result that the
2818 menubar never responds at all because the deferred
2819 WM_INITMENU message is never completed). Another problem
2820 situation is when the lisp thread calls SendMessage (to send
2821 a window manager command) when a message has been deferred;
2822 the lisp thread gets blocked indefinitely waiting for the
2823 deferred message to be completed, which itself is waiting for
2824 the lisp thread to respond.
2826 Note that we don't want to block the input thread waiting for
2827 a response from the lisp thread (although that would at least
2828 solve the deadlock problem above), because we want to be able
2829 to receive C-g to interrupt the lisp thread. */
2830 cancel_all_deferred_msgs ();
2833 signal_user_input ();
2836 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2839 /* Main window procedure */
2841 static LRESULT CALLBACK
2842 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2845 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2847 int windows_translate
;
2850 /* Note that it is okay to call x_window_to_frame, even though we are
2851 not running in the main lisp thread, because frame deletion
2852 requires the lisp thread to synchronize with this thread. Thus, if
2853 a frame struct is returned, it can be used without concern that the
2854 lisp thread might make it disappear while we are using it.
2856 NB. Walking the frame list in this thread is safe (as long as
2857 writes of Lisp_Object slots are atomic, which they are on Windows).
2858 Although delete-frame can destructively modify the frame list while
2859 we are walking it, a garbage collection cannot occur until after
2860 delete-frame has synchronized with this thread.
2862 It is also safe to use functions that make GDI calls, such as
2863 w32_clear_rect, because these functions must obtain a DC handle
2864 from the frame struct using get_frame_dc which is thread-aware. */
2869 f
= x_window_to_frame (dpyinfo
, hwnd
);
2872 HDC hdc
= get_frame_dc (f
);
2873 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2874 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2875 release_frame_dc (f
, hdc
);
2877 #if defined (W32_DEBUG_DISPLAY)
2878 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2880 wmsg
.rect
.left
, wmsg
.rect
.top
,
2881 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2882 #endif /* W32_DEBUG_DISPLAY */
2885 case WM_PALETTECHANGED
:
2886 /* ignore our own changes */
2887 if ((HWND
)wParam
!= hwnd
)
2889 f
= x_window_to_frame (dpyinfo
, hwnd
);
2891 /* get_frame_dc will realize our palette and force all
2892 frames to be redrawn if needed. */
2893 release_frame_dc (f
, get_frame_dc (f
));
2898 PAINTSTRUCT paintStruct
;
2900 memset (&update_rect
, 0, sizeof (update_rect
));
2902 f
= x_window_to_frame (dpyinfo
, hwnd
);
2905 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2909 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2910 fails. Apparently this can happen under some
2912 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2915 BeginPaint (hwnd
, &paintStruct
);
2917 /* The rectangles returned by GetUpdateRect and BeginPaint
2918 do not always match. Play it safe by assuming both areas
2920 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2922 #if defined (W32_DEBUG_DISPLAY)
2923 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2925 wmsg
.rect
.left
, wmsg
.rect
.top
,
2926 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2927 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2928 update_rect
.left
, update_rect
.top
,
2929 update_rect
.right
, update_rect
.bottom
));
2931 EndPaint (hwnd
, &paintStruct
);
2934 /* Change the message type to prevent Windows from
2935 combining WM_PAINT messages in the Lisp thread's queue,
2936 since Windows assumes that each message queue is
2937 dedicated to one frame and does not bother checking
2938 that hwnd matches before combining them. */
2939 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2944 /* If GetUpdateRect returns 0 (meaning there is no update
2945 region), assume the whole window needs to be repainted. */
2946 GetClientRect (hwnd
, &wmsg
.rect
);
2947 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2951 case WM_INPUTLANGCHANGE
:
2952 /* Inform lisp thread of keyboard layout changes. */
2953 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2955 /* Clear dead keys in the keyboard state; for simplicity only
2956 preserve modifier key states. */
2961 GetKeyboardState (keystate
);
2962 for (i
= 0; i
< 256; i
++)
2979 SetKeyboardState (keystate
);
2984 /* Synchronize hot keys with normal input. */
2985 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2990 record_keyup (wParam
, lParam
);
2995 /* Ignore keystrokes we fake ourself; see below. */
2996 if (dpyinfo
->faked_key
== wParam
)
2998 dpyinfo
->faked_key
= 0;
2999 /* Make sure TranslateMessage sees them though (as long as
3000 they don't produce WM_CHAR messages). This ensures that
3001 indicator lights are toggled promptly on Windows 9x, for
3003 if (wParam
< 256 && lispy_function_keys
[wParam
])
3005 windows_translate
= 1;
3011 /* Synchronize modifiers with current keystroke. */
3013 record_keydown (wParam
, lParam
);
3014 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
3016 windows_translate
= 0;
3021 if (NILP (Vw32_pass_lwindow_to_system
))
3023 /* Prevent system from acting on keyup (which opens the
3024 Start menu if no other key was pressed) by simulating a
3025 press of Space which we will ignore. */
3026 if (GetAsyncKeyState (wParam
) & 1)
3028 if (NUMBERP (Vw32_phantom_key_code
))
3029 key
= XUINT (Vw32_phantom_key_code
) & 255;
3032 dpyinfo
->faked_key
= key
;
3033 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3036 if (!NILP (Vw32_lwindow_modifier
))
3040 if (NILP (Vw32_pass_rwindow_to_system
))
3042 if (GetAsyncKeyState (wParam
) & 1)
3044 if (NUMBERP (Vw32_phantom_key_code
))
3045 key
= XUINT (Vw32_phantom_key_code
) & 255;
3048 dpyinfo
->faked_key
= key
;
3049 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3052 if (!NILP (Vw32_rwindow_modifier
))
3056 if (!NILP (Vw32_apps_modifier
))
3060 if (NILP (Vw32_pass_alt_to_system
))
3061 /* Prevent DefWindowProc from activating the menu bar if an
3062 Alt key is pressed and released by itself. */
3064 windows_translate
= 1;
3067 /* Decide whether to treat as modifier or function key. */
3068 if (NILP (Vw32_enable_caps_lock
))
3069 goto disable_lock_key
;
3070 windows_translate
= 1;
3073 /* Decide whether to treat as modifier or function key. */
3074 if (NILP (Vw32_enable_num_lock
))
3075 goto disable_lock_key
;
3076 windows_translate
= 1;
3079 /* Decide whether to treat as modifier or function key. */
3080 if (NILP (Vw32_scroll_lock_modifier
))
3081 goto disable_lock_key
;
3082 windows_translate
= 1;
3085 /* Ensure the appropriate lock key state (and indicator light)
3086 remains in the same state. We do this by faking another
3087 press of the relevant key. Apparently, this really is the
3088 only way to toggle the state of the indicator lights. */
3089 dpyinfo
->faked_key
= wParam
;
3090 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3091 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3092 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3093 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3094 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3095 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3096 /* Ensure indicator lights are updated promptly on Windows 9x
3097 (TranslateMessage apparently does this), after forwarding
3099 post_character_message (hwnd
, msg
, wParam
, lParam
,
3100 w32_get_key_modifiers (wParam
, lParam
));
3101 windows_translate
= 1;
3105 case VK_PROCESSKEY
: /* Generated by IME. */
3106 windows_translate
= 1;
3109 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3110 which is confusing for purposes of key binding; convert
3111 VK_CANCEL events into VK_PAUSE events. */
3115 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3116 for purposes of key binding; convert these back into
3117 VK_NUMLOCK events, at least when we want to see NumLock key
3118 presses. (Note that there is never any possibility that
3119 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3120 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3121 wParam
= VK_NUMLOCK
;
3124 /* If not defined as a function key, change it to a WM_CHAR message. */
3125 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3127 DWORD modifiers
= construct_console_modifiers ();
3129 if (!NILP (Vw32_recognize_altgr
)
3130 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3132 /* Always let TranslateMessage handle AltGr key chords;
3133 for some reason, ToAscii doesn't always process AltGr
3134 chords correctly. */
3135 windows_translate
= 1;
3137 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3139 /* Handle key chords including any modifiers other
3140 than shift directly, in order to preserve as much
3141 modifier information as possible. */
3142 if ('A' <= wParam
&& wParam
<= 'Z')
3144 /* Don't translate modified alphabetic keystrokes,
3145 so the user doesn't need to constantly switch
3146 layout to type control or meta keystrokes when
3147 the normal layout translates alphabetic
3148 characters to non-ascii characters. */
3149 if (!modifier_set (VK_SHIFT
))
3150 wParam
+= ('a' - 'A');
3155 /* Try to handle other keystrokes by determining the
3156 base character (ie. translating the base key plus
3159 KEY_EVENT_RECORD key
;
3161 key
.bKeyDown
= TRUE
;
3162 key
.wRepeatCount
= 1;
3163 key
.wVirtualKeyCode
= wParam
;
3164 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3165 key
.uChar
.AsciiChar
= 0;
3166 key
.dwControlKeyState
= modifiers
;
3168 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3169 /* 0 means an unrecognized keycode, negative means
3170 dead key. Ignore both. */
3173 /* Forward asciified character sequence. */
3174 post_character_message
3176 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3177 w32_get_key_modifiers (wParam
, lParam
));
3178 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3185 /* Let TranslateMessage handle everything else. */
3186 windows_translate
= 1;
3192 if (windows_translate
)
3194 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3195 windows_msg
.time
= GetMessageTime ();
3196 TranslateMessage (&windows_msg
);
3208 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3209 signal_user_input ();
3210 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3214 post_character_message (hwnd
, msg
, wParam
, lParam
,
3215 w32_get_key_modifiers (wParam
, lParam
));
3219 /* WM_UNICHAR looks promising from the docs, but the exact
3220 circumstances in which TranslateMessage sends it is one of those
3221 Microsoft secret API things that EU and US courts are supposed
3222 to have put a stop to already. Spy++ shows it being sent to Notepad
3223 and other MS apps, but never to Emacs.
3225 Some third party IMEs send it in accordance with the official
3226 documentation though, so handle it here.
3228 UNICODE_NOCHAR is used to test for support for this message.
3229 TRUE indicates that the message is supported. */
3230 if (wParam
== UNICODE_NOCHAR
)
3235 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3236 signal_user_input ();
3237 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3242 /* If we can't get the IME result as Unicode, use default processing,
3243 which will at least allow characters decodable in the system locale
3245 if (!get_composition_string_fn
)
3248 else if (!ignore_ime_char
)
3253 HIMC context
= get_ime_context_fn (hwnd
);
3254 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3255 /* Get buffer size. */
3256 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3257 buffer
= alloca (size
);
3258 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3260 release_ime_context_fn (hwnd
, context
);
3262 signal_user_input ();
3263 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3265 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3268 /* Ignore the messages for the rest of the
3269 characters in the string that was output above. */
3270 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3277 case WM_IME_STARTCOMPOSITION
:
3278 if (!set_ime_composition_window_fn
)
3282 COMPOSITIONFORM form
;
3286 /* Implementation note: The code below does something that
3287 one shouldn't do: it accesses the window object from a
3288 separate thread, while the main (a.k.a. "Lisp") thread
3289 runs and can legitimately delete and even GC it. That is
3290 why we are extra careful not to futz with a window that
3291 is different from the one recorded when the system caret
3292 coordinates were last modified. That is also why we are
3293 careful not to move the IME window if the window
3294 described by W was deleted, as indicated by its buffer
3295 field being reset to nil. */
3296 f
= x_window_to_frame (dpyinfo
, hwnd
);
3297 if (!(f
&& FRAME_LIVE_P (f
)))
3299 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3300 /* Punt if someone changed the frame's selected window
3302 if (w
!= w32_system_caret_window
)
3305 form
.dwStyle
= CFS_RECT
;
3306 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3307 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3309 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3310 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3311 + w32_system_caret_hdr_height
);
3312 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3313 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3314 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3315 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3316 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
3317 - w32_system_caret_mode_height
);
3319 /* Punt if the window was deleted behind our back. */
3320 if (!BUFFERP (w
->contents
))
3323 context
= get_ime_context_fn (hwnd
);
3328 set_ime_composition_window_fn (context
, &form
);
3329 release_ime_context_fn (hwnd
, context
);
3331 /* We should "goto dflt" here to pass WM_IME_STARTCOMPOSITION to
3332 DefWindowProc, so that the composition window will actually
3333 be displayed. But doing so causes trouble with displaying
3334 dialog boxes, such as the file selection dialog or font
3335 selection dialog. So something else is needed to fix the
3336 former without breaking the latter. See bug#11732. */
3339 case WM_IME_ENDCOMPOSITION
:
3340 ignore_ime_char
= 0;
3343 /* Simulate middle mouse button events when left and right buttons
3344 are used together, but only if user has two button mouse. */
3345 case WM_LBUTTONDOWN
:
3346 case WM_RBUTTONDOWN
:
3347 if (w32_num_mouse_buttons
> 2)
3348 goto handle_plain_button
;
3351 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3352 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3354 if (button_state
& this)
3357 if (button_state
== 0)
3360 button_state
|= this;
3362 if (button_state
& other
)
3364 if (mouse_button_timer
)
3366 KillTimer (hwnd
, mouse_button_timer
);
3367 mouse_button_timer
= 0;
3369 /* Generate middle mouse event instead. */
3370 msg
= WM_MBUTTONDOWN
;
3371 button_state
|= MMOUSE
;
3373 else if (button_state
& MMOUSE
)
3375 /* Ignore button event if we've already generated a
3376 middle mouse down event. This happens if the
3377 user releases and press one of the two buttons
3378 after we've faked a middle mouse event. */
3383 /* Flush out saved message. */
3384 post_msg (&saved_mouse_button_msg
);
3386 wmsg
.dwModifiers
= w32_get_modifiers ();
3387 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3388 signal_user_input ();
3390 /* Clear message buffer. */
3391 saved_mouse_button_msg
.msg
.hwnd
= 0;
3395 /* Hold onto message for now. */
3396 mouse_button_timer
=
3397 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3398 w32_mouse_button_tolerance
, NULL
);
3399 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3400 saved_mouse_button_msg
.msg
.message
= msg
;
3401 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3402 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3403 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3404 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3411 if (w32_num_mouse_buttons
> 2)
3412 goto handle_plain_button
;
3415 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3416 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3418 if ((button_state
& this) == 0)
3421 button_state
&= ~this;
3423 if (button_state
& MMOUSE
)
3425 /* Only generate event when second button is released. */
3426 if ((button_state
& other
) == 0)
3429 button_state
&= ~MMOUSE
;
3431 if (button_state
) emacs_abort ();
3438 /* Flush out saved message if necessary. */
3439 if (saved_mouse_button_msg
.msg
.hwnd
)
3441 post_msg (&saved_mouse_button_msg
);
3444 wmsg
.dwModifiers
= w32_get_modifiers ();
3445 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3446 signal_user_input ();
3448 /* Always clear message buffer and cancel timer. */
3449 saved_mouse_button_msg
.msg
.hwnd
= 0;
3450 KillTimer (hwnd
, mouse_button_timer
);
3451 mouse_button_timer
= 0;
3453 if (button_state
== 0)
3458 case WM_XBUTTONDOWN
:
3460 if (w32_pass_extra_mouse_buttons_to_system
)
3462 /* else fall through and process them. */
3463 case WM_MBUTTONDOWN
:
3465 handle_plain_button
:
3470 /* Ignore middle and extra buttons as long as the menu is active. */
3471 f
= x_window_to_frame (dpyinfo
, hwnd
);
3472 if (f
&& f
->output_data
.w32
->menubar_active
)
3475 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3477 if (up
) ReleaseCapture ();
3478 else SetCapture (hwnd
);
3479 button
= (button
== 0) ? LMOUSE
:
3480 ((button
== 1) ? MMOUSE
: RMOUSE
);
3482 button_state
&= ~button
;
3484 button_state
|= button
;
3488 wmsg
.dwModifiers
= w32_get_modifiers ();
3489 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3490 signal_user_input ();
3492 /* Need to return true for XBUTTON messages, false for others,
3493 to indicate that we processed the message. */
3494 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3497 f
= x_window_to_frame (dpyinfo
, hwnd
);
3500 /* Ignore mouse movements as long as the menu is active.
3501 These movements are processed by the window manager
3502 anyway, and it's wrong to handle them as if they happened
3503 on the underlying frame. */
3504 if (f
->output_data
.w32
->menubar_active
)
3507 /* If the mouse moved, and the mouse pointer is invisible,
3508 make it visible again. We do this here so as to be able
3509 to show the mouse pointer even when the main
3510 (a.k.a. "Lisp") thread is busy doing something. */
3511 static int last_x
, last_y
;
3512 int x
= GET_X_LPARAM (lParam
);
3513 int y
= GET_Y_LPARAM (lParam
);
3515 if (f
->pointer_invisible
3516 && (x
!= last_x
|| y
!= last_y
))
3517 f
->pointer_invisible
= false;
3523 /* If the mouse has just moved into the frame, start tracking
3524 it, so we will be notified when it leaves the frame. Mouse
3525 tracking only works under W98 and NT4 and later. On earlier
3526 versions, there is no way of telling when the mouse leaves the
3527 frame, so we just have to put up with help-echo and mouse
3528 highlighting remaining while the frame is not active. */
3529 if (track_mouse_event_fn
&& !track_mouse_window
3530 /* If the menu bar is active, turning on tracking of mouse
3531 movement events might send these events to the tooltip
3532 frame, if the user happens to move the mouse pointer over
3533 the tooltip. But since we don't process events for
3534 tooltip frames, this causes Windows to present a
3535 hourglass cursor, which is ugly and unexpected. So don't
3536 enable tracking mouse events in this case; they will be
3537 restarted when the menu pops down. (Confusingly, the
3538 menubar_active member of f->output_data.w32, tested
3539 above, is only set when a menu was popped up _not_ from
3540 the frame's menu bar, but via x-popup-menu.) */
3543 TRACKMOUSEEVENT tme
;
3544 tme
.cbSize
= sizeof (tme
);
3545 tme
.dwFlags
= TME_LEAVE
;
3546 tme
.hwndTrack
= hwnd
;
3547 tme
.dwHoverTime
= HOVER_DEFAULT
;
3549 track_mouse_event_fn (&tme
);
3550 track_mouse_window
= hwnd
;
3554 if (w32_mouse_move_interval
<= 0
3555 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3557 wmsg
.dwModifiers
= w32_get_modifiers ();
3558 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3562 /* Hang onto mouse move and scroll messages for a bit, to avoid
3563 sending such events to Emacs faster than it can process them.
3564 If we get more events before the timer from the first message
3565 expires, we just replace the first message. */
3567 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3569 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3570 w32_mouse_move_interval
, NULL
);
3572 /* Hold onto message for now. */
3573 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3574 saved_mouse_move_msg
.msg
.message
= msg
;
3575 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3576 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3577 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3578 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3584 wmsg
.dwModifiers
= w32_get_modifiers ();
3585 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3586 signal_user_input ();
3590 if (w32_pass_multimedia_buttons_to_system
)
3592 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3593 case WM_MOUSEHWHEEL
:
3594 wmsg
.dwModifiers
= w32_get_modifiers ();
3595 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3596 signal_user_input ();
3597 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3598 handled, to prevent the system trying to handle it by faking
3599 scroll bar events. */
3603 /* Flush out saved messages if necessary. */
3604 if (wParam
== mouse_button_timer
)
3606 if (saved_mouse_button_msg
.msg
.hwnd
)
3608 post_msg (&saved_mouse_button_msg
);
3609 signal_user_input ();
3610 saved_mouse_button_msg
.msg
.hwnd
= 0;
3612 KillTimer (hwnd
, mouse_button_timer
);
3613 mouse_button_timer
= 0;
3615 else if (wParam
== mouse_move_timer
)
3617 if (saved_mouse_move_msg
.msg
.hwnd
)
3619 post_msg (&saved_mouse_move_msg
);
3620 saved_mouse_move_msg
.msg
.hwnd
= 0;
3622 KillTimer (hwnd
, mouse_move_timer
);
3623 mouse_move_timer
= 0;
3625 else if (wParam
== menu_free_timer
)
3627 KillTimer (hwnd
, menu_free_timer
);
3628 menu_free_timer
= 0;
3629 f
= x_window_to_frame (dpyinfo
, hwnd
);
3630 /* If a popup menu is active, don't wipe its strings. */
3632 && current_popup_menu
== NULL
)
3634 /* Free memory used by owner-drawn and help-echo strings. */
3635 w32_free_menu_strings (hwnd
);
3637 f
->output_data
.w32
->menubar_active
= 0;
3644 /* Windows doesn't send us focus messages when putting up and
3645 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3646 The only indication we get that something happened is receiving
3647 this message afterwards. So this is a good time to reset our
3648 keyboard modifiers' state. */
3655 /* We must ensure menu bar is fully constructed and up to date
3656 before allowing user interaction with it. To achieve this
3657 we send this message to the lisp thread and wait for a
3658 reply (whose value is not actually needed) to indicate that
3659 the menu bar is now ready for use, so we can now return.
3661 To remain responsive in the meantime, we enter a nested message
3662 loop that can process all other messages.
3664 However, we skip all this if the message results from calling
3665 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3666 thread a message because it is blocked on us at this point. We
3667 set menubar_active before calling TrackPopupMenu to indicate
3668 this (there is no possibility of confusion with real menubar
3671 f
= x_window_to_frame (dpyinfo
, hwnd
);
3673 && (f
->output_data
.w32
->menubar_active
3674 /* We can receive this message even in the absence of a
3675 menubar (ie. when the system menu is activated) - in this
3676 case we do NOT want to forward the message, otherwise it
3677 will cause the menubar to suddenly appear when the user
3678 had requested it to be turned off! */
3679 || f
->output_data
.w32
->menubar_widget
== NULL
))
3683 deferred_msg msg_buf
;
3685 /* Detect if message has already been deferred; in this case
3686 we cannot return any sensible value to ignore this. */
3687 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3692 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3695 case WM_EXITMENULOOP
:
3696 f
= x_window_to_frame (dpyinfo
, hwnd
);
3698 /* If a menu is still active, check again after a short delay,
3699 since Windows often (always?) sends the WM_EXITMENULOOP
3700 before the corresponding WM_COMMAND message.
3701 Don't do this if a popup menu is active, since it is only
3702 menubar menus that require cleaning up in this way.
3704 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3705 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3707 /* If hourglass cursor should be displayed, display it now. */
3708 if (f
&& f
->output_data
.w32
->hourglass_p
)
3709 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3714 /* Direct handling of help_echo in menus. Should be safe now
3715 that we generate the help_echo by placing a help event in the
3718 HMENU menu
= (HMENU
) lParam
;
3719 UINT menu_item
= (UINT
) LOWORD (wParam
);
3720 UINT flags
= (UINT
) HIWORD (wParam
);
3722 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3726 case WM_MEASUREITEM
:
3727 f
= x_window_to_frame (dpyinfo
, hwnd
);
3730 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3732 if (pMis
->CtlType
== ODT_MENU
)
3734 /* Work out dimensions for popup menu titles. */
3735 char * title
= (char *) pMis
->itemData
;
3736 HDC hdc
= GetDC (hwnd
);
3737 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3738 LOGFONT menu_logfont
;
3742 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3743 menu_logfont
.lfWeight
= FW_BOLD
;
3744 menu_font
= CreateFontIndirect (&menu_logfont
);
3745 old_font
= SelectObject (hdc
, menu_font
);
3747 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3750 if (unicode_append_menu
)
3751 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3752 wcslen ((WCHAR
*) title
),
3755 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3757 pMis
->itemWidth
= size
.cx
;
3758 if (pMis
->itemHeight
< size
.cy
)
3759 pMis
->itemHeight
= size
.cy
;
3762 pMis
->itemWidth
= 0;
3764 SelectObject (hdc
, old_font
);
3765 DeleteObject (menu_font
);
3766 ReleaseDC (hwnd
, hdc
);
3773 f
= x_window_to_frame (dpyinfo
, hwnd
);
3776 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3778 if (pDis
->CtlType
== ODT_MENU
)
3780 /* Draw popup menu title. */
3781 char * title
= (char *) pDis
->itemData
;
3784 HDC hdc
= pDis
->hDC
;
3785 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3786 LOGFONT menu_logfont
;
3789 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3790 menu_logfont
.lfWeight
= FW_BOLD
;
3791 menu_font
= CreateFontIndirect (&menu_logfont
);
3792 old_font
= SelectObject (hdc
, menu_font
);
3794 /* Always draw title as if not selected. */
3795 if (unicode_append_menu
)
3798 + GetSystemMetrics (SM_CXMENUCHECK
),
3800 ETO_OPAQUE
, &pDis
->rcItem
,
3802 wcslen ((WCHAR
*) title
), NULL
);
3806 + GetSystemMetrics (SM_CXMENUCHECK
),
3808 ETO_OPAQUE
, &pDis
->rcItem
,
3809 title
, strlen (title
), NULL
);
3811 SelectObject (hdc
, old_font
);
3812 DeleteObject (menu_font
);
3820 /* Still not right - can't distinguish between clicks in the
3821 client area of the frame from clicks forwarded from the scroll
3822 bars - may have to hook WM_NCHITTEST to remember the mouse
3823 position and then check if it is in the client area ourselves. */
3824 case WM_MOUSEACTIVATE
:
3825 /* Discard the mouse click that activates a frame, allowing the
3826 user to click anywhere without changing point (or worse!).
3827 Don't eat mouse clicks on scrollbars though!! */
3828 if (LOWORD (lParam
) == HTCLIENT
)
3829 return MA_ACTIVATEANDEAT
;
3834 /* No longer tracking mouse. */
3835 track_mouse_window
= NULL
;
3837 case WM_ACTIVATEAPP
:
3839 case WM_WINDOWPOSCHANGED
:
3841 /* Inform lisp thread that a frame might have just been obscured
3842 or exposed, so should recheck visibility of all frames. */
3843 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3847 dpyinfo
->faked_key
= 0;
3849 register_hot_keys (hwnd
);
3852 unregister_hot_keys (hwnd
);
3855 /* Relinquish the system caret. */
3856 if (w32_system_caret_hwnd
)
3858 w32_visible_system_caret_hwnd
= NULL
;
3859 w32_system_caret_hwnd
= NULL
;
3865 f
= x_window_to_frame (dpyinfo
, hwnd
);
3866 if (f
&& HIWORD (wParam
) == 0)
3868 if (menu_free_timer
)
3870 KillTimer (hwnd
, menu_free_timer
);
3871 menu_free_timer
= 0;
3877 wmsg
.dwModifiers
= w32_get_modifiers ();
3878 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3886 wmsg
.dwModifiers
= w32_get_modifiers ();
3887 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3890 case WM_WINDOWPOSCHANGING
:
3891 /* Don't restrict the sizing of any kind of frames. If the window
3892 manager doesn't, there's no reason to do it ourselves. */
3894 if (frame_resize_pixelwise
|| hwnd
== tip_window
)
3899 /* Don't restrict the sizing of fullscreened frames, allowing them to be
3900 flush with the sides of the screen. */
3901 f
= x_window_to_frame (dpyinfo
, hwnd
);
3902 if (f
&& FRAME_PREV_FSMODE (f
) != FULLSCREEN_NONE
)
3907 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3909 wp
.length
= sizeof (WINDOWPLACEMENT
);
3910 GetWindowPlacement (hwnd
, &wp
);
3912 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
&& wp
.showCmd
!= SW_SHOWMINIMIZED
3913 && (lppos
->flags
& SWP_NOSIZE
) == 0)
3920 DWORD internal_border
;
3921 DWORD vscrollbar_extra
;
3922 DWORD hscrollbar_extra
;
3925 wp
.length
= sizeof (wp
);
3926 GetWindowRect (hwnd
, &wr
);
3930 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3931 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3932 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3933 vscrollbar_extra
= GetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
);
3934 hscrollbar_extra
= GetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
);
3938 memset (&rect
, 0, sizeof (rect
));
3939 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3940 GetMenu (hwnd
) != NULL
);
3942 /* Force width and height of client area to be exact
3943 multiples of the character cell dimensions. */
3944 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3945 - 2 * internal_border
- vscrollbar_extra
)
3947 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3948 - 2 * internal_border
- hscrollbar_extra
)
3953 /* For right/bottom sizing we can just fix the sizes.
3954 However for top/left sizing we will need to fix the X
3955 and Y positions as well. */
3957 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3958 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3960 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3961 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3963 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3964 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3966 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3973 lppos
->flags
|= SWP_NOMOVE
;
3985 case WM_GETMINMAXINFO
:
3986 /* Hack to allow resizing the Emacs frame above the screen size.
3987 Note that Windows 9x limits coordinates to 16-bits. */
3988 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3989 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3993 if (LOWORD (lParam
) == HTCLIENT
)
3995 f
= x_window_to_frame (dpyinfo
, hwnd
);
3998 if (f
->output_data
.w32
->hourglass_p
3999 && !menubar_in_use
&& !current_popup_menu
)
4000 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
4001 else if (f
->pointer_invisible
)
4004 SetCursor (f
->output_data
.w32
->current_cursor
);
4011 case WM_EMACS_SETCURSOR
:
4013 Cursor cursor
= (Cursor
) wParam
;
4014 f
= x_window_to_frame (dpyinfo
, hwnd
);
4017 f
->output_data
.w32
->current_cursor
= cursor
;
4018 if (!f
->output_data
.w32
->hourglass_p
)
4020 if (f
->pointer_invisible
)
4029 case WM_EMACS_SHOWCURSOR
:
4031 ShowCursor ((BOOL
) wParam
);
4036 case WM_EMACS_CREATEVSCROLLBAR
:
4037 return (LRESULT
) w32_createvscrollbar ((struct frame
*) wParam
,
4038 (struct scroll_bar
*) lParam
);
4040 case WM_EMACS_CREATEHSCROLLBAR
:
4041 return (LRESULT
) w32_createhscrollbar ((struct frame
*) wParam
,
4042 (struct scroll_bar
*) lParam
);
4044 case WM_EMACS_SHOWWINDOW
:
4045 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4047 case WM_EMACS_BRINGTOTOP
:
4048 case WM_EMACS_SETFOREGROUND
:
4050 HWND foreground_window
;
4051 DWORD foreground_thread
, retval
;
4053 /* On NT 5.0, and apparently Windows 98, it is necessary to
4054 attach to the thread that currently has focus in order to
4055 pull the focus away from it. */
4056 foreground_window
= GetForegroundWindow ();
4057 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4058 if (!foreground_window
4059 || foreground_thread
== GetCurrentThreadId ()
4060 || !AttachThreadInput (GetCurrentThreadId (),
4061 foreground_thread
, TRUE
))
4062 foreground_thread
= 0;
4064 retval
= SetForegroundWindow ((HWND
) wParam
);
4065 if (msg
== WM_EMACS_BRINGTOTOP
)
4066 retval
= BringWindowToTop ((HWND
) wParam
);
4068 /* Detach from the previous foreground thread. */
4069 if (foreground_thread
)
4070 AttachThreadInput (GetCurrentThreadId (),
4071 foreground_thread
, FALSE
);
4076 case WM_EMACS_SETWINDOWPOS
:
4078 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4079 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4080 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4083 case WM_EMACS_DESTROYWINDOW
:
4084 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4085 return DestroyWindow ((HWND
) wParam
);
4087 case WM_EMACS_HIDE_CARET
:
4088 return HideCaret (hwnd
);
4090 case WM_EMACS_SHOW_CARET
:
4091 return ShowCaret (hwnd
);
4093 case WM_EMACS_DESTROY_CARET
:
4094 w32_system_caret_hwnd
= NULL
;
4095 w32_visible_system_caret_hwnd
= NULL
;
4096 return DestroyCaret ();
4098 case WM_EMACS_TRACK_CARET
:
4099 /* If there is currently no system caret, create one. */
4100 if (w32_system_caret_hwnd
== NULL
)
4102 /* Use the default caret width, and avoid changing it
4103 unnecessarily, as it confuses screen reader software. */
4104 w32_system_caret_hwnd
= hwnd
;
4105 CreateCaret (hwnd
, NULL
, 0,
4106 w32_system_caret_height
);
4109 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
4111 /* Ensure visible caret gets turned on when requested. */
4112 else if (w32_use_visible_system_caret
4113 && w32_visible_system_caret_hwnd
!= hwnd
)
4115 w32_visible_system_caret_hwnd
= hwnd
;
4116 return ShowCaret (hwnd
);
4118 /* Ensure visible caret gets turned off when requested. */
4119 else if (!w32_use_visible_system_caret
4120 && w32_visible_system_caret_hwnd
)
4122 w32_visible_system_caret_hwnd
= NULL
;
4123 return HideCaret (hwnd
);
4128 case WM_EMACS_TRACKPOPUPMENU
:
4133 pos
= (POINT
*)lParam
;
4134 flags
= TPM_CENTERALIGN
;
4135 if (button_state
& LMOUSE
)
4136 flags
|= TPM_LEFTBUTTON
;
4137 else if (button_state
& RMOUSE
)
4138 flags
|= TPM_RIGHTBUTTON
;
4140 /* Remember we did a SetCapture on the initial mouse down event,
4141 so for safety, we make sure the capture is canceled now. */
4145 /* Use menubar_active to indicate that WM_INITMENU is from
4146 TrackPopupMenu below, and should be ignored. */
4147 f
= x_window_to_frame (dpyinfo
, hwnd
);
4149 f
->output_data
.w32
->menubar_active
= 1;
4151 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4155 /* Eat any mouse messages during popupmenu */
4156 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4158 /* Get the menu selection, if any */
4159 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4161 retval
= LOWORD (amsg
.wParam
);
4175 case WM_EMACS_FILENOTIFY
:
4176 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4180 /* Check for messages registered at runtime. */
4181 if (msg
== msh_mousewheel
)
4183 wmsg
.dwModifiers
= w32_get_modifiers ();
4184 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4185 signal_user_input ();
4190 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
4193 /* The most common default return code for handled messages is 0. */
4198 my_create_window (struct frame
* f
)
4201 static int coords
[2];
4202 Lisp_Object left
, top
;
4203 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4205 /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
4206 anything that is not a number and is not Qunbound. */
4207 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
4208 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
4209 if (EQ (left
, Qunbound
))
4210 coords
[0] = CW_USEDEFAULT
;
4212 coords
[0] = XINT (left
);
4213 if (EQ (top
, Qunbound
))
4214 coords
[1] = CW_USEDEFAULT
;
4216 coords
[1] = XINT (top
);
4218 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
,
4219 (WPARAM
)f
, (LPARAM
)coords
))
4221 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4225 /* Create a tooltip window. Unlike my_create_window, we do not do this
4226 indirectly via the Window thread, as we do not need to process Window
4227 messages for the tooltip. Creating tooltips indirectly also creates
4228 deadlocks when tooltips are created for menu items. */
4230 my_create_tip_window (struct frame
*f
)
4234 rect
.left
= rect
.top
= 0;
4235 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4236 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4238 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4239 FRAME_EXTERNAL_MENU_BAR (f
));
4241 tip_window
= FRAME_W32_WINDOW (f
)
4242 = CreateWindow (EMACS_CLASS
,
4244 f
->output_data
.w32
->dwStyle
,
4247 rect
.right
- rect
.left
,
4248 rect
.bottom
- rect
.top
,
4249 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4256 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4257 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4258 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4259 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4261 /* Tip frames have no scrollbars. */
4262 SetWindowLong (tip_window
, WND_VSCROLLBAR_INDEX
, 0);
4263 SetWindowLong (tip_window
, WND_HSCROLLBAR_INDEX
, 0);
4265 /* Do this to discard the default setting specified by our parent. */
4266 ShowWindow (tip_window
, SW_HIDE
);
4271 /* Create and set up the w32 window for frame F. */
4274 w32_window (struct frame
*f
, long window_prompting
, bool minibuffer_only
)
4278 /* Use the resource name as the top-level window name
4279 for looking up resources. Make a non-Lisp copy
4280 for the window manager, so GC relocation won't bother it.
4282 Elsewhere we specify the window name for the window manager. */
4283 f
->namebuf
= xlispstrdup (Vx_resource_name
);
4285 my_create_window (f
);
4287 validate_x_resource_name ();
4289 /* x_set_name normally ignores requests to set the name if the
4290 requested name is the same as the current name. This is the one
4291 place where that assumption isn't correct; f->name is set, but
4292 the server hasn't been told. */
4295 int explicit = f
->explicit_name
;
4297 f
->explicit_name
= 0;
4299 fset_name (f
, Qnil
);
4300 x_set_name (f
, name
, explicit);
4305 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4306 initialize_frame_menubar (f
);
4308 if (FRAME_W32_WINDOW (f
) == 0)
4309 error ("Unable to create window");
4312 /* Handle the icon stuff for this window. Perhaps later we might
4313 want an x_set_icon_position which can be called interactively as
4317 x_icon (struct frame
*f
, Lisp_Object parms
)
4319 Lisp_Object icon_x
, icon_y
;
4320 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4322 /* Set the position of the icon. Note that Windows 95 groups all
4323 icons in the tray. */
4324 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4325 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4326 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4328 CHECK_NUMBER (icon_x
);
4329 CHECK_NUMBER (icon_y
);
4331 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4332 error ("Both left and top icon corners of icon must be specified");
4337 /* Start up iconic or window? */
4338 x_wm_set_window_state
4339 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4343 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4353 x_make_gc (struct frame
*f
)
4355 XGCValues gc_values
;
4359 /* Create the GC's of this frame.
4360 Note that many default values are used. */
4363 gc_values
.font
= FRAME_FONT (f
);
4365 /* Cursor has cursor-color background, background-color foreground. */
4366 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4367 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4368 f
->output_data
.w32
->cursor_gc
4369 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4370 (GCFont
| GCForeground
| GCBackground
),
4374 f
->output_data
.w32
->white_relief
.gc
= 0;
4375 f
->output_data
.w32
->black_relief
.gc
= 0;
4381 /* Handler for signals raised during x_create_frame and
4382 x_create_tip_frame. FRAME is the frame which is partially
4386 unwind_create_frame (Lisp_Object frame
)
4388 struct frame
*f
= XFRAME (frame
);
4390 /* If frame is ``official'', nothing to do. */
4391 if (NILP (Fmemq (frame
, Vframe_list
)))
4394 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4396 /* If the frame's image cache refcount is still the same as our
4397 private shadow variable, it means we are unwinding a frame
4398 for which we didn't yet call init_frame_faces, where the
4399 refcount is incremented. Therefore, we increment it here, so
4400 that free_frame_faces, called in x_free_frame_resources
4401 below, will not mistakenly decrement the counter that was not
4402 incremented yet to account for this new frame. */
4403 if (FRAME_IMAGE_CACHE (f
) != NULL
4404 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
4405 FRAME_IMAGE_CACHE (f
)->refcount
++;
4408 x_free_frame_resources (f
);
4412 /* Check that reference counts are indeed correct. */
4413 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4414 eassert ((dpyinfo
->terminal
->image_cache
== NULL
4415 && image_cache_refcount
== 0)
4416 || (dpyinfo
->terminal
->image_cache
!= NULL
4417 && dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
));
4426 do_unwind_create_frame (Lisp_Object frame
)
4428 unwind_create_frame (frame
);
4432 unwind_create_frame_1 (Lisp_Object val
)
4434 inhibit_lisp_code
= val
;
4438 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4440 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4441 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4444 if (EQ (font_param
, Qunbound
))
4446 font
= !NILP (font_param
) ? font_param
4447 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4449 if (!STRINGP (font
))
4452 static char *names
[]
4453 = { "Courier New-10",
4454 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4455 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4459 for (i
= 0; names
[i
]; i
++)
4461 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4466 error ("No suitable font was found");
4468 else if (!NILP (font_param
))
4470 /* Remember the explicit font parameter, so we can re-apply it after
4471 we've applied the `default' face settings. */
4472 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4474 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4477 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4479 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4480 Return an Emacs frame object.
4481 PARAMETERS is an alist of frame parameters.
4482 If the parameters specify that the frame should not have a minibuffer,
4483 and do not specify a specific minibuffer window to use,
4484 then `default-minibuffer-frame' must be a frame whose minibuffer can
4485 be shared by the new frame.
4487 This function is an internal primitive--use `make-frame' instead. */)
4488 (Lisp_Object parameters
)
4491 Lisp_Object frame
, tem
;
4493 bool minibuffer_only
= false;
4494 long window_prompting
= 0;
4495 ptrdiff_t count
= SPECPDL_INDEX ();
4496 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4497 Lisp_Object display
;
4498 struct w32_display_info
*dpyinfo
= NULL
;
4502 if (!FRAME_W32_P (SELECTED_FRAME ())
4503 && !FRAME_INITIAL_P (SELECTED_FRAME ()))
4504 error ("Cannot create a GUI frame in a -nw session");
4506 /* Make copy of frame parameters because the original is in pure
4508 parameters
= Fcopy_alist (parameters
);
4510 /* Use this general default value to start with
4511 until we know if this frame has a specified name. */
4512 Vx_resource_name
= Vinvocation_name
;
4514 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4515 if (EQ (display
, Qunbound
))
4516 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4517 if (EQ (display
, Qunbound
))
4519 dpyinfo
= check_x_display_info (display
);
4520 kb
= dpyinfo
->terminal
->kboard
;
4522 if (!dpyinfo
->terminal
->name
)
4523 error ("Terminal is not live, can't create new frames on it");
4525 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4527 && ! EQ (name
, Qunbound
)
4529 error ("Invalid frame name--not a string or nil");
4532 Vx_resource_name
= name
;
4534 /* See if parent window is specified. */
4535 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4536 if (EQ (parent
, Qunbound
))
4538 if (! NILP (parent
))
4539 CHECK_NUMBER (parent
);
4541 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4542 /* No need to protect DISPLAY because that's not used after passing
4543 it to make_frame_without_minibuffer. */
4545 GCPRO4 (parameters
, parent
, name
, frame
);
4546 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4548 if (EQ (tem
, Qnone
) || NILP (tem
))
4549 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4550 else if (EQ (tem
, Qonly
))
4552 f
= make_minibuffer_frame ();
4553 minibuffer_only
= true;
4555 else if (WINDOWP (tem
))
4556 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4558 f
= make_frame (true);
4560 XSETFRAME (frame
, f
);
4562 /* By default, make scrollbars the system standard width and height. */
4563 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4564 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
4566 f
->terminal
= dpyinfo
->terminal
;
4568 f
->output_method
= output_w32
;
4569 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4570 FRAME_FONTSET (f
) = -1;
4573 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4575 if (! STRINGP (f
->icon_name
))
4576 fset_icon_name (f
, Qnil
);
4578 /* FRAME_DISPLAY_INFO (f) = dpyinfo; */
4580 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
4581 record_unwind_protect (do_unwind_create_frame
, frame
);
4584 image_cache_refcount
=
4585 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4586 dpyinfo_refcount
= dpyinfo
->reference_count
;
4587 #endif /* GLYPH_DEBUG */
4589 /* Specify the parent under which to make this window. */
4592 /* Cast to UINT_PTR shuts up compiler warnings about cast to
4593 pointer from integer of different size. */
4594 f
->output_data
.w32
->parent_desc
= (Window
) (UINT_PTR
) XFASTINT (parent
);
4595 f
->output_data
.w32
->explicit_parent
= true;
4599 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4600 f
->output_data
.w32
->explicit_parent
= false;
4603 /* Set the name; the functions to which we pass f expect the name to
4605 if (EQ (name
, Qunbound
) || NILP (name
))
4607 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4608 f
->explicit_name
= false;
4612 fset_name (f
, name
);
4613 f
->explicit_name
= true;
4614 /* Use the frame's title when getting resources for this frame. */
4615 specbind (Qx_resource_name
, name
);
4618 if (uniscribe_available
)
4619 register_font_driver (&uniscribe_font_driver
, f
);
4620 register_font_driver (&w32font_driver
, f
);
4622 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4623 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4625 /* Extract the window parameters from the supplied values
4626 that are needed to determine window geometry. */
4627 x_default_font_parameter (f
, parameters
);
4629 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4630 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4632 /* We recognize either internalBorderWidth or internalBorder
4633 (which is what xterm calls it). */
4634 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4638 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4639 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4640 if (! EQ (value
, Qunbound
))
4641 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4644 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4645 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4646 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4647 x_default_parameter (f
, parameters
, Qright_divider_width
, make_number (0),
4648 NULL
, NULL
, RES_TYPE_NUMBER
);
4649 x_default_parameter (f
, parameters
, Qbottom_divider_width
, make_number (0),
4650 NULL
, NULL
, RES_TYPE_NUMBER
);
4651 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4652 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4653 x_default_parameter (f
, parameters
, Qhorizontal_scroll_bars
, Qnil
,
4654 "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4656 /* Also do the stuff which must be set before the window exists. */
4657 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4658 "foreground", "Foreground", RES_TYPE_STRING
);
4659 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4660 "background", "Background", RES_TYPE_STRING
);
4661 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4662 "pointerColor", "Foreground", RES_TYPE_STRING
);
4663 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4664 "borderColor", "BorderColor", RES_TYPE_STRING
);
4665 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4666 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4667 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4668 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4669 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4670 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4671 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4672 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4673 /* Process alpha here (Bug#16619). */
4674 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4675 "alpha", "Alpha", RES_TYPE_NUMBER
);
4677 /* Init faces first since we need the frame's column width/line
4678 height in various occasions. */
4679 init_frame_faces (f
);
4681 /* The following call of change_frame_size is needed since otherwise
4682 x_set_tool_bar_lines will already work with the character sizes
4683 installed by init_frame_faces while the frame's pixel size is
4684 still calculated from a character size of 1 and we subsequently
4685 hit the (height >= 0) assertion in window_box_height.
4687 The non-pixelwise code apparently worked around this because it
4688 had one frame line vs one toolbar line which left us with a zero
4689 root window height which was obviously wrong as well ... */
4690 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
4691 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
4694 /* The X resources controlling the menu-bar and tool-bar are
4695 processed specially at startup, and reflected in the mode
4696 variables; ignore them here. */
4697 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4698 NILP (Vmenu_bar_mode
)
4699 ? make_number (0) : make_number (1),
4700 NULL
, NULL
, RES_TYPE_NUMBER
);
4701 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4702 NILP (Vtool_bar_mode
)
4703 ? make_number (0) : make_number (1),
4704 NULL
, NULL
, RES_TYPE_NUMBER
);
4706 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4707 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4708 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4709 "title", "Title", RES_TYPE_STRING
);
4711 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4712 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4714 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4715 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4716 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4717 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4718 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4719 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4720 f
->output_data
.w32
->vertical_drag_cursor
= w32_load_cursor (IDC_SIZENS
);
4722 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4724 window_prompting
= x_figure_window_size (f
, parameters
, true);
4726 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4727 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4729 w32_window (f
, window_prompting
, minibuffer_only
);
4730 x_icon (f
, parameters
);
4734 /* Now consider the frame official. */
4735 f
->terminal
->reference_count
++;
4736 FRAME_DISPLAY_INFO (f
)->reference_count
++;
4737 Vframe_list
= Fcons (frame
, Vframe_list
);
4739 /* We need to do this after creating the window, so that the
4740 icon-creation functions can say whose icon they're describing. */
4741 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4742 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4744 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4745 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4746 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4747 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4748 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4749 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4750 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4751 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4752 x_default_parameter (f
, parameters
, Qscroll_bar_height
, Qnil
,
4753 "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER
);
4755 /* Allow x_set_window_size, now. */
4756 f
->can_x_set_window_size
= true;
4758 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
4761 /* Tell the server what size and position, etc, we want, and how
4762 badly we want them. This should be done after we have the menu
4763 bar so that its size can be taken into account. */
4765 x_wm_set_size_hint (f
, window_prompting
, false);
4768 /* Process fullscreen parameter here in the hope that normalizing a
4769 fullheight/fullwidth frame will produce the size set by the last
4770 adjust_frame_size call. */
4771 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4772 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4774 /* Make the window appear on the frame and enable display, unless
4775 the caller says not to. However, with explicit parent, Emacs
4776 cannot control visibility, so don't try. */
4777 if (! f
->output_data
.w32
->explicit_parent
)
4779 Lisp_Object visibility
;
4781 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4782 if (EQ (visibility
, Qunbound
))
4785 if (EQ (visibility
, Qicon
))
4786 x_iconify_frame (f
);
4787 else if (! NILP (visibility
))
4788 x_make_frame_visible (f
);
4790 /* Must have been Qnil. */
4794 /* Initialize `default-minibuffer-frame' in case this is the first
4795 frame on this terminal. */
4796 if (FRAME_HAS_MINIBUF_P (f
)
4797 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4798 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4799 kset_default_minibuffer_frame (kb
, frame
);
4801 /* All remaining specified parameters, which have not been "used"
4802 by x_get_arg and friends, now go in the misc. alist of the frame. */
4803 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4804 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4805 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4809 /* Make sure windows on this frame appear in calls to next-window
4810 and similar functions. */
4811 Vwindow_list
= Qnil
;
4813 return unbind_to (count
, frame
);
4816 /* FRAME is used only to get a handle on the X display. We don't pass the
4817 display info directly because we're called from frame.c, which doesn't
4818 know about that structure. */
4820 x_get_focus_frame (struct frame
*frame
)
4822 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4824 if (! dpyinfo
->w32_focus_frame
)
4827 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4831 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4832 doc
: /* Internal function called by `color-defined-p', which see.
4833 \(Note that the Nextstep version of this function ignores FRAME.) */)
4834 (Lisp_Object color
, Lisp_Object frame
)
4837 struct frame
*f
= decode_window_system_frame (frame
);
4839 CHECK_STRING (color
);
4841 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4847 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4848 doc
: /* Internal function called by `color-values', which see. */)
4849 (Lisp_Object color
, Lisp_Object frame
)
4852 struct frame
*f
= decode_window_system_frame (frame
);
4854 CHECK_STRING (color
);
4856 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4857 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
4858 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
4859 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
4864 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4865 doc
: /* Internal function called by `display-color-p', which see. */)
4866 (Lisp_Object display
)
4868 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4870 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4876 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4877 Sx_display_grayscale_p
, 0, 1, 0,
4878 doc
: /* Return t if DISPLAY supports shades of gray.
4879 Note that color displays do support shades of gray.
4880 The optional argument DISPLAY specifies which display to ask about.
4881 DISPLAY should be either a frame or a display name (a string).
4882 If omitted or nil, that stands for the selected frame's display. */)
4883 (Lisp_Object display
)
4885 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4887 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4893 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4894 Sx_display_pixel_width
, 0, 1, 0,
4895 doc
: /* Return the width in pixels of DISPLAY.
4896 The optional argument DISPLAY specifies which display to ask about.
4897 DISPLAY should be either a frame or a display name (a string).
4898 If omitted or nil, that stands for the selected frame's display.
4900 On \"multi-monitor\" setups this refers to the pixel width for all
4901 physical monitors associated with DISPLAY. To get information for
4902 each physical monitor, use `display-monitor-attributes-list'. */)
4903 (Lisp_Object display
)
4905 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4907 return make_number (x_display_pixel_width (dpyinfo
));
4910 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4911 Sx_display_pixel_height
, 0, 1, 0,
4912 doc
: /* Return the height in pixels of DISPLAY.
4913 The optional argument DISPLAY specifies which display to ask about.
4914 DISPLAY should be either a frame or a display name (a string).
4915 If omitted or nil, that stands for the selected frame's display.
4917 On \"multi-monitor\" setups this refers to the pixel height for all
4918 physical monitors associated with DISPLAY. To get information for
4919 each physical monitor, use `display-monitor-attributes-list'. */)
4920 (Lisp_Object display
)
4922 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4924 return make_number (x_display_pixel_height (dpyinfo
));
4927 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4929 doc
: /* Return the number of bitplanes of DISPLAY.
4930 The optional argument DISPLAY specifies which display to ask about.
4931 DISPLAY should be either a frame or a display name (a string).
4932 If omitted or nil, that stands for the selected frame's display. */)
4933 (Lisp_Object display
)
4935 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4937 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4940 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4942 doc
: /* Return the number of color cells of DISPLAY.
4943 The optional argument DISPLAY specifies which display to ask about.
4944 DISPLAY should be either a frame or a display name (a string).
4945 If omitted or nil, that stands for the selected frame's display. */)
4946 (Lisp_Object display
)
4948 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4951 /* Don't use NCOLORS: it returns incorrect results under remote
4952 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4953 * overflow and because probably is more meaningful on Windows
4956 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4957 return make_number (cap
);
4960 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4961 Sx_server_max_request_size
,
4963 doc
: /* Return the maximum request size of the server of DISPLAY.
4964 The optional argument DISPLAY specifies which display to ask about.
4965 DISPLAY should be either a frame or a display name (a string).
4966 If omitted or nil, that stands for the selected frame's display. */)
4967 (Lisp_Object display
)
4969 return make_number (1);
4972 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4973 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
4975 \(Labeling every distributor as a "vendor" embodies the false assumption
4976 that operating systems cannot be developed and distributed noncommercially.)
4978 For GNU and Unix systems, this queries the X server software; for
4979 MS-Windows, this queries the OS.
4981 The optional argument TERMINAL specifies which display to ask about.
4982 TERMINAL should be a terminal object, a frame or a display name (a string).
4983 If omitted or nil, that stands for the selected frame's display. */)
4984 (Lisp_Object terminal
)
4986 return build_string ("Microsoft Corp.");
4989 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4990 doc
: /* Return the version numbers of the GUI software on TERMINAL.
4991 The value is a list of three integers specifying the version of the GUI
4994 For GNU and Unix system, the first 2 numbers are the version of the X
4995 Protocol used on TERMINAL and the 3rd number is the distributor-specific
4996 release number. For MS-Windows, the 3 numbers report the version and
4997 the build number of the OS.
4999 See also the function `x-server-vendor'.
5001 The optional argument TERMINAL specifies which display to ask about.
5002 TERMINAL should be a terminal object, a frame or a display name (a string).
5003 If omitted or nil, that stands for the selected frame's display. */)
5004 (Lisp_Object terminal
)
5006 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
5009 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
5010 doc
: /* Return the number of screens on the server of DISPLAY.
5011 The optional argument DISPLAY specifies which display to ask about.
5012 DISPLAY should be either a frame or a display name (a string).
5013 If omitted or nil, that stands for the selected frame's display. */)
5014 (Lisp_Object display
)
5016 return make_number (1);
5019 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
5020 Sx_display_mm_height
, 0, 1, 0,
5021 doc
: /* Return the height in millimeters of DISPLAY.
5022 The optional argument DISPLAY specifies which display to ask about.
5023 DISPLAY should be either a frame or a display name (a string).
5024 If omitted or nil, that stands for the selected frame's display.
5026 On \"multi-monitor\" setups this refers to the height in millimeters for
5027 all physical monitors associated with DISPLAY. To get information
5028 for each physical monitor, use `display-monitor-attributes-list'. */)
5029 (Lisp_Object display
)
5031 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5033 double mm_per_pixel
;
5036 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5037 / GetDeviceCaps (hdc
, VERTRES
));
5038 ReleaseDC (NULL
, hdc
);
5040 return make_number (x_display_pixel_height (dpyinfo
) * mm_per_pixel
+ 0.5);
5043 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
5044 doc
: /* Return the width in millimeters of DISPLAY.
5045 The optional argument DISPLAY specifies which display to ask about.
5046 DISPLAY should be either a frame or a display name (a string).
5047 If omitted or nil, that stands for the selected frame's display.
5049 On \"multi-monitor\" setups this refers to the width in millimeters for
5050 all physical monitors associated with TERMINAL. To get information
5051 for each physical monitor, use `display-monitor-attributes-list'. */)
5052 (Lisp_Object display
)
5054 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5056 double mm_per_pixel
;
5059 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5060 / GetDeviceCaps (hdc
, HORZRES
));
5061 ReleaseDC (NULL
, hdc
);
5063 return make_number (x_display_pixel_width (dpyinfo
) * mm_per_pixel
+ 0.5);
5066 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
5067 Sx_display_backing_store
, 0, 1, 0,
5068 doc
: /* Return an indication of whether DISPLAY does backing store.
5069 The value may be `always', `when-mapped', or `not-useful'.
5070 The optional argument DISPLAY specifies which display to ask about.
5071 DISPLAY should be either a frame or a display name (a string).
5072 If omitted or nil, that stands for the selected frame's display. */)
5073 (Lisp_Object display
)
5075 return intern ("not-useful");
5078 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
5079 Sx_display_visual_class
, 0, 1, 0,
5080 doc
: /* Return the visual class of DISPLAY.
5081 The value is one of the symbols `static-gray', `gray-scale',
5082 `static-color', `pseudo-color', `true-color', or `direct-color'.
5084 The optional argument DISPLAY specifies which display to ask about.
5085 DISPLAY should be either a frame or a display name (a string).
5086 If omitted or nil, that stands for the selected frame's display. */)
5087 (Lisp_Object display
)
5089 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5090 Lisp_Object result
= Qnil
;
5092 if (dpyinfo
->has_palette
)
5093 result
= intern ("pseudo-color");
5094 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
5095 result
= intern ("static-grey");
5096 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
5097 result
= intern ("static-color");
5098 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
5099 result
= intern ("true-color");
5104 DEFUN ("x-display-save-under", Fx_display_save_under
,
5105 Sx_display_save_under
, 0, 1, 0,
5106 doc
: /* Return t if DISPLAY supports the save-under feature.
5107 The optional argument DISPLAY specifies which display to ask about.
5108 DISPLAY should be either a frame or a display name (a string).
5109 If omitted or nil, that stands for the selected frame's display. */)
5110 (Lisp_Object display
)
5115 static BOOL CALLBACK ALIGN_STACK
5116 w32_monitor_enum (HMONITOR monitor
, HDC hdc
, RECT
*rcMonitor
, LPARAM dwData
)
5118 Lisp_Object
*monitor_list
= (Lisp_Object
*) dwData
;
5120 *monitor_list
= Fcons (make_save_ptr (monitor
), *monitor_list
);
5126 w32_display_monitor_attributes_list (void)
5128 Lisp_Object attributes_list
= Qnil
, primary_monitor_attributes
= Qnil
;
5129 Lisp_Object monitor_list
= Qnil
, monitor_frames
, rest
, frame
;
5132 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5134 if (!(enum_display_monitors_fn
&& get_monitor_info_fn
5135 && monitor_from_window_fn
))
5138 if (!enum_display_monitors_fn (NULL
, NULL
, w32_monitor_enum
,
5139 (LPARAM
) &monitor_list
)
5140 || NILP (monitor_list
))
5144 for (rest
= monitor_list
; CONSP (rest
); rest
= XCDR (rest
))
5147 monitors
= xmalloc (n_monitors
* sizeof (*monitors
));
5148 for (i
= 0; i
< n_monitors
; i
++)
5150 monitors
[i
] = XSAVE_POINTER (XCAR (monitor_list
), 0);
5151 monitor_list
= XCDR (monitor_list
);
5154 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
5155 FOR_EACH_FRAME (rest
, frame
)
5157 struct frame
*f
= XFRAME (frame
);
5159 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5162 monitor_from_window_fn (FRAME_W32_WINDOW (f
),
5163 MONITOR_DEFAULT_TO_NEAREST
);
5165 for (i
= 0; i
< n_monitors
; i
++)
5166 if (monitors
[i
] == monitor
)
5170 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
5174 GCPRO3 (attributes_list
, primary_monitor_attributes
, monitor_frames
);
5176 for (i
= 0; i
< n_monitors
; i
++)
5178 Lisp_Object geometry
, workarea
, name
, attributes
= Qnil
;
5180 int width_mm
, height_mm
;
5181 struct MONITOR_INFO_EX mi
;
5183 mi
.cbSize
= sizeof (mi
);
5184 if (!get_monitor_info_fn (monitors
[i
], (struct MONITOR_INFO
*) &mi
))
5187 hdc
= CreateDCA ("DISPLAY", mi
.szDevice
, NULL
, NULL
);
5190 width_mm
= GetDeviceCaps (hdc
, HORZSIZE
);
5191 height_mm
= GetDeviceCaps (hdc
, VERTSIZE
);
5194 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
5197 name
= DECODE_SYSTEM (build_unibyte_string (mi
.szDevice
));
5199 attributes
= Fcons (Fcons (Qname
, name
), attributes
);
5201 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5204 workarea
= list4i (mi
.rcWork
.left
, mi
.rcWork
.top
,
5205 mi
.rcWork
.right
- mi
.rcWork
.left
,
5206 mi
.rcWork
.bottom
- mi
.rcWork
.top
);
5207 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5209 geometry
= list4i (mi
.rcMonitor
.left
, mi
.rcMonitor
.top
,
5210 mi
.rcMonitor
.right
- mi
.rcMonitor
.left
,
5211 mi
.rcMonitor
.bottom
- mi
.rcMonitor
.top
);
5212 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5214 if (mi
.dwFlags
& MONITORINFOF_PRIMARY
)
5215 primary_monitor_attributes
= attributes
;
5217 attributes_list
= Fcons (attributes
, attributes_list
);
5220 if (!NILP (primary_monitor_attributes
))
5221 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
5227 return attributes_list
;
5231 w32_display_monitor_attributes_list_fallback (struct w32_display_info
*dpyinfo
)
5233 Lisp_Object geometry
, workarea
, frames
, rest
, frame
, attributes
= Qnil
;
5235 double mm_per_pixel
;
5236 int pixel_width
, pixel_height
, width_mm
, height_mm
;
5239 /* Fallback: treat (possibly) multiple physical monitors as if they
5240 formed a single monitor as a whole. This should provide a
5241 consistent result at least on single monitor environments. */
5242 attributes
= Fcons (Fcons (Qname
, build_string ("combined screen")),
5246 FOR_EACH_FRAME (rest
, frame
)
5248 struct frame
*f
= XFRAME (frame
);
5250 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5251 frames
= Fcons (frame
, frames
);
5253 attributes
= Fcons (Fcons (Qframes
, frames
), attributes
);
5255 pixel_width
= x_display_pixel_width (dpyinfo
);
5256 pixel_height
= x_display_pixel_height (dpyinfo
);
5259 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5260 / GetDeviceCaps (hdc
, HORZRES
));
5261 width_mm
= pixel_width
* mm_per_pixel
+ 0.5;
5262 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5263 / GetDeviceCaps (hdc
, VERTRES
));
5264 height_mm
= pixel_height
* mm_per_pixel
+ 0.5;
5265 ReleaseDC (NULL
, hdc
);
5266 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5269 /* GetSystemMetrics below may return 0 for Windows 95 or NT 4.0, but
5271 geometry
= list4i (GetSystemMetrics (SM_XVIRTUALSCREEN
),
5272 GetSystemMetrics (SM_YVIRTUALSCREEN
),
5273 pixel_width
, pixel_height
);
5274 if (SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0))
5275 workarea
= list4i (workarea_rect
.left
, workarea_rect
.top
,
5276 workarea_rect
.right
- workarea_rect
.left
,
5277 workarea_rect
.bottom
- workarea_rect
.top
);
5279 workarea
= geometry
;
5280 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5282 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5284 return list1 (attributes
);
5287 DEFUN ("w32-display-monitor-attributes-list", Fw32_display_monitor_attributes_list
,
5288 Sw32_display_monitor_attributes_list
,
5290 doc
: /* Return a list of physical monitor attributes on the W32 display DISPLAY.
5292 The optional argument DISPLAY specifies which display to ask about.
5293 DISPLAY should be either a frame or a display name (a string).
5294 If omitted or nil, that stands for the selected frame's display.
5296 Internal use only, use `display-monitor-attributes-list' instead. */)
5297 (Lisp_Object display
)
5299 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5300 Lisp_Object attributes_list
;
5303 attributes_list
= w32_display_monitor_attributes_list ();
5304 if (NILP (attributes_list
))
5305 attributes_list
= w32_display_monitor_attributes_list_fallback (dpyinfo
);
5308 return attributes_list
;
5311 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
5312 doc
: /* Set the sound generated when the bell is rung.
5313 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
5314 to use the corresponding system sound for the bell. The 'silent sound
5315 prevents Emacs from making any sound at all.
5316 SOUND is nil to use the normal beep. */)
5319 CHECK_SYMBOL (sound
);
5322 sound_type
= 0xFFFFFFFF;
5323 else if (EQ (sound
, intern ("asterisk")))
5324 sound_type
= MB_ICONASTERISK
;
5325 else if (EQ (sound
, intern ("exclamation")))
5326 sound_type
= MB_ICONEXCLAMATION
;
5327 else if (EQ (sound
, intern ("hand")))
5328 sound_type
= MB_ICONHAND
;
5329 else if (EQ (sound
, intern ("question")))
5330 sound_type
= MB_ICONQUESTION
;
5331 else if (EQ (sound
, intern ("ok")))
5333 else if (EQ (sound
, intern ("silent")))
5334 sound_type
= MB_EMACS_SILENT
;
5336 sound_type
= 0xFFFFFFFF;
5342 x_screen_planes (register struct frame
*f
)
5344 return FRAME_DISPLAY_INFO (f
)->n_planes
;
5347 /* Return the display structure for the display named NAME.
5348 Open a new connection if necessary. */
5350 struct w32_display_info
*
5351 x_display_info_for_name (Lisp_Object name
)
5353 struct w32_display_info
*dpyinfo
;
5355 CHECK_STRING (name
);
5357 for (dpyinfo
= &one_w32_display_info
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
5358 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
5361 /* Use this general default value to start with. */
5362 Vx_resource_name
= Vinvocation_name
;
5364 validate_x_resource_name ();
5366 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
5367 SSDATA (Vx_resource_name
));
5370 error ("Cannot connect to server %s", SDATA (name
));
5372 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5377 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5378 1, 3, 0, doc
: /* Open a connection to a display server.
5379 DISPLAY is the name of the display to connect to.
5380 Optional second arg XRM-STRING is a string of resources in xrdb format.
5381 If the optional third arg MUST-SUCCEED is non-nil,
5382 terminate Emacs if we can't open the connection.
5383 \(In the Nextstep version, the last two arguments are currently ignored.) */)
5384 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
5386 unsigned char *xrm_option
;
5387 struct w32_display_info
*dpyinfo
;
5389 CHECK_STRING (display
);
5391 /* Signal an error in order to encourage correct use from callers.
5392 * If we ever support multiple window systems in the same Emacs,
5393 * we'll need callers to be precise about what window system they
5396 if (strcmp (SSDATA (display
), "w32") != 0)
5397 error ("The name of the display in this Emacs must be \"w32\"");
5399 /* If initialization has already been done, return now to avoid
5400 overwriting critical parts of one_w32_display_info. */
5401 if (window_system_available (NULL
))
5404 if (! NILP (xrm_string
))
5405 CHECK_STRING (xrm_string
);
5407 /* Allow color mapping to be defined externally; first look in user's
5408 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5410 Lisp_Object color_file
;
5411 struct gcpro gcpro1
;
5413 color_file
= build_string ("~/rgb.txt");
5415 GCPRO1 (color_file
);
5417 if (NILP (Ffile_readable_p (color_file
)))
5419 Fexpand_file_name (build_string ("rgb.txt"),
5420 Fsymbol_value (intern ("data-directory")));
5422 Vw32_color_map
= Fx_load_color_file (color_file
);
5426 if (NILP (Vw32_color_map
))
5427 Vw32_color_map
= w32_default_color_map ();
5429 /* Merge in system logical colors. */
5430 add_system_logical_colors_to_map (&Vw32_color_map
);
5432 if (! NILP (xrm_string
))
5433 xrm_option
= SDATA (xrm_string
);
5435 xrm_option
= (unsigned char *) 0;
5437 /* Use this general default value to start with. */
5438 /* First remove .exe suffix from invocation-name - it looks ugly. */
5440 char basename
[ MAX_PATH
], *str
;
5442 lispstpcpy (basename
, Vinvocation_name
);
5443 str
= strrchr (basename
, '.');
5445 Vinvocation_name
= build_string (basename
);
5447 Vx_resource_name
= Vinvocation_name
;
5449 validate_x_resource_name ();
5451 /* This is what opens the connection and sets x_current_display.
5452 This also initializes many symbols, such as those used for input. */
5453 dpyinfo
= w32_term_init (display
, xrm_option
,
5454 SSDATA (Vx_resource_name
));
5458 if (!NILP (must_succeed
))
5459 fatal ("Cannot connect to server %s.\n",
5462 error ("Cannot connect to server %s", SDATA (display
));
5465 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5469 DEFUN ("x-close-connection", Fx_close_connection
,
5470 Sx_close_connection
, 1, 1, 0,
5471 doc
: /* Close the connection to DISPLAY's server.
5472 For DISPLAY, specify either a frame or a display name (a string).
5473 If DISPLAY is nil, that stands for the selected frame's display. */)
5474 (Lisp_Object display
)
5476 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5478 if (dpyinfo
->reference_count
> 0)
5479 error ("Display still has frames on it");
5482 x_destroy_all_bitmaps (dpyinfo
);
5484 x_delete_display (dpyinfo
);
5490 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5491 doc
: /* Return the list of display names that Emacs has connections to. */)
5494 Lisp_Object result
= Qnil
;
5495 struct w32_display_info
*wdi
;
5497 for (wdi
= x_display_list
; wdi
; wdi
= wdi
->next
)
5498 result
= Fcons (XCAR (wdi
->name_list_element
), result
);
5503 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5504 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5505 This function only has an effect on X Windows. With MS Windows, it is
5506 defined but does nothing.
5508 If ON is nil, allow buffering of requests.
5509 Turning on synchronization prohibits the Xlib routines from buffering
5510 requests and seriously degrades performance, but makes debugging much
5512 The optional second argument TERMINAL specifies which display to act on.
5513 TERMINAL should be a terminal object, a frame or a display name (a string).
5514 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5515 (Lisp_Object on
, Lisp_Object display
)
5522 /***********************************************************************
5524 ***********************************************************************/
5526 #if 0 /* TODO : port window properties to W32 */
5528 DEFUN ("x-change-window-property", Fx_change_window_property
,
5529 Sx_change_window_property
, 2, 6, 0,
5530 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5531 PROP must be a string. VALUE may be a string or a list of conses,
5532 numbers and/or strings. If an element in the list is a string, it is
5533 converted to an atom and the value of the Atom is used. If an element
5534 is a cons, it is converted to a 32 bit number where the car is the 16
5535 top bits and the cdr is the lower 16 bits.
5537 FRAME nil or omitted means use the selected frame.
5538 If TYPE is given and non-nil, it is the name of the type of VALUE.
5539 If TYPE is not given or nil, the type is STRING.
5540 FORMAT gives the size in bits of each element if VALUE is a list.
5541 It must be one of 8, 16 or 32.
5542 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5543 If OUTER-P is non-nil, the property is changed for the outer X window of
5544 FRAME. Default is to change on the edit X window. */)
5545 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5546 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5548 struct frame
*f
= decode_window_system_frame (frame
);
5551 CHECK_STRING (prop
);
5552 CHECK_STRING (value
);
5555 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5556 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5557 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5558 SDATA (value
), SCHARS (value
));
5560 /* Make sure the property is set when we return. */
5561 XFlush (FRAME_W32_DISPLAY (f
));
5568 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5569 Sx_delete_window_property
, 1, 2, 0,
5570 doc
: /* Remove window property PROP from X window of FRAME.
5571 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5572 (Lisp_Object prop
, Lisp_Object frame
)
5574 struct frame
*f
= decode_window_system_frame (frame
);
5577 CHECK_STRING (prop
);
5579 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5580 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5582 /* Make sure the property is removed when we return. */
5583 XFlush (FRAME_W32_DISPLAY (f
));
5590 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5592 doc
: /* Value is the value of window property PROP on FRAME.
5593 If FRAME is nil or omitted, use the selected frame.
5595 On X Windows, the following optional arguments are also accepted:
5596 If TYPE is nil or omitted, get the property as a string.
5597 Otherwise TYPE is the name of the atom that denotes the type expected.
5598 If SOURCE is non-nil, get the property on that window instead of from
5599 FRAME. The number 0 denotes the root window.
5600 If DELETE-P is non-nil, delete the property after retrieving it.
5601 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5603 On MS Windows, this function accepts but ignores those optional arguments.
5605 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5606 no value of TYPE (always string in the MS Windows case). */)
5607 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5608 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5610 struct frame
*f
= decode_window_system_frame (frame
);
5613 Lisp_Object prop_value
= Qnil
;
5614 char *tmp_data
= NULL
;
5617 unsigned long actual_size
, bytes_remaining
;
5619 CHECK_STRING (prop
);
5621 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5622 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5623 prop_atom
, 0, 0, False
, XA_STRING
,
5624 &actual_type
, &actual_format
, &actual_size
,
5625 &bytes_remaining
, (unsigned char **) &tmp_data
);
5628 int size
= bytes_remaining
;
5633 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5634 prop_atom
, 0, bytes_remaining
,
5636 &actual_type
, &actual_format
,
5637 &actual_size
, &bytes_remaining
,
5638 (unsigned char **) &tmp_data
);
5640 prop_value
= make_string (tmp_data
, size
);
5654 /***********************************************************************
5656 ***********************************************************************/
5658 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5659 Lisp_Object
, Lisp_Object
);
5660 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5661 Lisp_Object
, int, int, int *, int *);
5663 /* The frame of a currently visible tooltip. */
5665 Lisp_Object tip_frame
;
5667 /* If non-nil, a timer started that hides the last tooltip when it
5670 Lisp_Object tip_timer
;
5673 /* If non-nil, a vector of 3 elements containing the last args
5674 with which x-show-tip was called. See there. */
5676 Lisp_Object last_show_tip_args
;
5680 unwind_create_tip_frame (Lisp_Object frame
)
5682 Lisp_Object deleted
;
5684 deleted
= unwind_create_frame (frame
);
5685 if (EQ (deleted
, Qt
))
5693 /* Create a frame for a tooltip on the display described by DPYINFO.
5694 PARMS is a list of frame parameters. TEXT is the string to
5695 display in the tip frame. Value is the frame.
5697 Note that functions called here, esp. x_default_parameter can
5698 signal errors, for instance when a specified color name is
5699 undefined. We have to make sure that we're in a consistent state
5700 when this happens. */
5703 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5704 Lisp_Object parms
, Lisp_Object text
)
5709 long window_prompting
= 0;
5711 ptrdiff_t count
= SPECPDL_INDEX ();
5712 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5714 bool face_change_before
= face_change
;
5716 struct buffer
*old_buffer
;
5718 /* Use this general default value to start with until we know if
5719 this frame has a specified name. */
5720 Vx_resource_name
= Vinvocation_name
;
5722 kb
= dpyinfo
->terminal
->kboard
;
5724 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5725 avoid destructive changes behind our caller's back. */
5726 parms
= Fcopy_alist (parms
);
5728 /* Get the name of the frame to use for resource lookup. */
5729 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5731 && !EQ (name
, Qunbound
)
5733 error ("Invalid frame name--not a string or nil");
5734 Vx_resource_name
= name
;
5737 GCPRO3 (parms
, name
, frame
);
5738 /* Make a frame without minibuffer nor mode-line. */
5739 f
= make_frame (false);
5740 f
->wants_modeline
= 0;
5741 XSETFRAME (frame
, f
);
5743 AUTO_STRING (tip
, " *tip*");
5744 buffer
= Fget_buffer_create (tip
);
5745 /* Use set_window_buffer instead of Fset_window_buffer (see
5746 discussion of bug#11984, bug#12025, bug#12026). */
5747 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5748 old_buffer
= current_buffer
;
5749 set_buffer_internal_1 (XBUFFER (buffer
));
5750 bset_truncate_lines (current_buffer
, Qnil
);
5751 specbind (Qinhibit_read_only
, Qt
);
5752 specbind (Qinhibit_modification_hooks
, Qt
);
5755 set_buffer_internal_1 (old_buffer
);
5757 record_unwind_protect (unwind_create_tip_frame
, frame
);
5759 /* By setting the output method, we're essentially saying that
5760 the frame is live, as per FRAME_LIVE_P. If we get a signal
5761 from this point on, x_destroy_window might screw up reference
5763 f
->terminal
= dpyinfo
->terminal
;
5764 f
->output_method
= output_w32
;
5765 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5767 FRAME_FONTSET (f
) = -1;
5768 fset_icon_name (f
, Qnil
);
5771 image_cache_refcount
=
5772 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5773 dpyinfo_refcount
= dpyinfo
->reference_count
;
5774 #endif /* GLYPH_DEBUG */
5775 FRAME_KBOARD (f
) = kb
;
5776 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5777 f
->output_data
.w32
->explicit_parent
= false;
5779 /* Set the name; the functions to which we pass f expect the name to
5781 if (EQ (name
, Qunbound
) || NILP (name
))
5783 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5784 f
->explicit_name
= false;
5788 fset_name (f
, name
);
5789 f
->explicit_name
= true;
5790 /* use the frame's title when getting resources for this frame. */
5791 specbind (Qx_resource_name
, name
);
5794 if (uniscribe_available
)
5795 register_font_driver (&uniscribe_font_driver
, f
);
5796 register_font_driver (&w32font_driver
, f
);
5798 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5799 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5801 /* Extract the window parameters from the supplied values
5802 that are needed to determine window geometry. */
5803 x_default_font_parameter (f
, parms
);
5805 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5806 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5807 /* This defaults to 2 in order to match xterm. We recognize either
5808 internalBorderWidth or internalBorder (which is what xterm calls
5810 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5814 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5815 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5816 if (! EQ (value
, Qunbound
))
5817 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5820 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5821 "internalBorderWidth", "internalBorderWidth",
5823 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5824 NULL
, NULL
, RES_TYPE_NUMBER
);
5825 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5826 NULL
, NULL
, RES_TYPE_NUMBER
);
5828 /* Also do the stuff which must be set before the window exists. */
5829 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5830 "foreground", "Foreground", RES_TYPE_STRING
);
5831 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5832 "background", "Background", RES_TYPE_STRING
);
5833 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5834 "pointerColor", "Foreground", RES_TYPE_STRING
);
5835 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5836 "cursorColor", "Foreground", RES_TYPE_STRING
);
5837 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5838 "borderColor", "BorderColor", RES_TYPE_STRING
);
5839 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
5840 "alpha", "Alpha", RES_TYPE_NUMBER
);
5842 /* Init faces before x_default_parameter is called for the
5843 scroll-bar-width parameter because otherwise we end up in
5844 init_iterator with a null face cache, which should not happen. */
5845 init_frame_faces (f
);
5847 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5848 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5850 window_prompting
= x_figure_window_size (f
, parms
, false);
5852 /* No fringes on tip frame. */
5854 f
->left_fringe_width
= 0;
5855 f
->right_fringe_width
= 0;
5858 my_create_tip_window (f
);
5863 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5864 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5865 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5866 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5867 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5868 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5870 /* Dimensions, especially FRAME_LINES (f), must be done via
5871 change_frame_size. Change will not be effected unless different
5872 from the current FRAME_LINES (f). */
5873 width
= FRAME_COLS (f
);
5874 height
= FRAME_LINES (f
);
5875 SET_FRAME_COLS (f
, 0);
5876 SET_FRAME_LINES (f
, 0);
5877 adjust_frame_size (f
, width
* FRAME_COLUMN_WIDTH (f
),
5878 height
* FRAME_LINE_HEIGHT (f
), 0, true, Qtip_frame
);
5880 /* Add `tooltip' frame parameter's default value. */
5881 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5882 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5884 /* Set up faces after all frame parameters are known. This call
5885 also merges in face attributes specified for new frames.
5887 Frame parameters may be changed if .Xdefaults contains
5888 specifications for the default font. For example, if there is an
5889 `Emacs.default.attributeBackground: pink', the `background-color'
5890 attribute of the frame get's set, which let's the internal border
5891 of the tooltip frame appear in pink. Prevent this. */
5893 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5894 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5895 Lisp_Object colors
= Qnil
;
5897 /* Set tip_frame here, so that */
5899 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5901 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5902 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5903 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5904 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5907 Fmodify_frame_parameters (frame
, colors
);
5914 /* Now that the frame is official, it counts as a reference to
5916 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5917 f
->terminal
->reference_count
++;
5919 /* It is now ok to make the frame official even if we get an error
5920 below. And the frame needs to be on Vframe_list or making it
5921 visible won't work. */
5922 Vframe_list
= Fcons (frame
, Vframe_list
);
5923 f
->can_x_set_window_size
= true;
5925 /* Setting attributes of faces of the tooltip frame from resources
5926 and similar will set face_change, which leads to the
5927 clearing of all current matrices. Since this isn't necessary
5928 here, avoid it by resetting face_change to the value it
5929 had before we created the tip frame. */
5930 face_change
= face_change_before
;
5932 /* Discard the unwind_protect. */
5933 return unbind_to (count
, frame
);
5937 /* Compute where to display tip frame F. PARMS is the list of frame
5938 parameters for F. DX and DY are specified offsets from the current
5939 location of the mouse. WIDTH and HEIGHT are the width and height
5940 of the tooltip. Return coordinates relative to the root window of
5941 the display in *ROOT_X, and *ROOT_Y. */
5944 compute_tip_xy (struct frame
*f
,
5945 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5946 int width
, int height
, int *root_x
, int *root_y
)
5948 Lisp_Object left
, top
;
5949 int min_x
, min_y
, max_x
, max_y
;
5951 /* User-specified position? */
5952 left
= Fcdr (Fassq (Qleft
, parms
));
5953 top
= Fcdr (Fassq (Qtop
, parms
));
5955 /* Move the tooltip window where the mouse pointer is. Resize and
5957 if (!INTEGERP (left
) || !INTEGERP (top
))
5961 /* Default min and max values. */
5964 max_x
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
));
5965 max_y
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
));
5973 /* If multiple monitor support is available, constrain the tip onto
5974 the current monitor. This improves the above by allowing negative
5975 co-ordinates if monitor positions are such that they are valid, and
5976 snaps a tooltip onto a single monitor if we are close to the edge
5977 where it would otherwise flow onto the other monitor (or into
5978 nothingness if there is a gap in the overlap). */
5979 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5981 struct MONITOR_INFO info
;
5983 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5984 info
.cbSize
= sizeof (info
);
5986 if (get_monitor_info_fn (monitor
, &info
))
5988 min_x
= info
.rcWork
.left
;
5989 min_y
= info
.rcWork
.top
;
5990 max_x
= info
.rcWork
.right
;
5991 max_y
= info
.rcWork
.bottom
;
5997 *root_y
= XINT (top
);
5998 else if (*root_y
+ XINT (dy
) <= min_y
)
5999 *root_y
= min_y
; /* Can happen for negative dy */
6000 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
6001 /* It fits below the pointer */
6002 *root_y
+= XINT (dy
);
6003 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
6004 /* It fits above the pointer. */
6005 *root_y
-= height
+ XINT (dy
);
6007 /* Put it on the top. */
6010 if (INTEGERP (left
))
6011 *root_x
= XINT (left
);
6012 else if (*root_x
+ XINT (dx
) <= min_x
)
6013 *root_x
= 0; /* Can happen for negative dx */
6014 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
6015 /* It fits to the right of the pointer. */
6016 *root_x
+= XINT (dx
);
6017 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
6018 /* It fits to the left of the pointer. */
6019 *root_x
-= width
+ XINT (dx
);
6021 /* Put it left justified on the screen -- it ought to fit that way. */
6026 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
6027 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
6028 A tooltip window is a small window displaying a string.
6030 This is an internal function; Lisp code should call `tooltip-show'.
6032 FRAME nil or omitted means use the selected frame.
6034 PARMS is an optional list of frame parameters which can be
6035 used to change the tooltip's appearance.
6037 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
6038 means use the default timeout of 5 seconds.
6040 If the list of frame parameters PARMS contains a `left' parameter,
6041 the tooltip is displayed at that x-position. Otherwise it is
6042 displayed at the mouse position, with offset DX added (default is 5 if
6043 DX isn't specified). Likewise for the y-position; if a `top' frame
6044 parameter is specified, it determines the y-position of the tooltip
6045 window, otherwise it is displayed at the mouse position, with offset
6046 DY added (default is -10).
6048 A tooltip's maximum size is specified by `x-max-tooltip-size'.
6049 Text larger than the specified size is clipped. */)
6050 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
6055 struct buffer
*old_buffer
;
6056 struct text_pos pos
;
6057 int i
, width
, height
;
6058 bool seen_reversed_p
;
6059 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6060 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6061 ptrdiff_t count
= SPECPDL_INDEX ();
6063 specbind (Qinhibit_redisplay
, Qt
);
6065 GCPRO4 (string
, parms
, frame
, timeout
);
6067 CHECK_STRING (string
);
6068 f
= decode_window_system_frame (frame
);
6070 timeout
= make_number (5);
6072 CHECK_NATNUM (timeout
);
6075 dx
= make_number (5);
6080 dy
= make_number (-10);
6084 if (NILP (last_show_tip_args
))
6085 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
6087 if (!NILP (tip_frame
))
6089 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
6090 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
6091 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
6093 if (EQ (frame
, last_frame
)
6094 && !NILP (Fequal (last_string
, string
))
6095 && !NILP (Fequal (last_parms
, parms
)))
6097 struct frame
*f
= XFRAME (tip_frame
);
6099 /* Only DX and DY have changed. */
6100 if (!NILP (tip_timer
))
6102 Lisp_Object timer
= tip_timer
;
6104 call1 (Qcancel_timer
, timer
);
6108 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
6109 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
6111 /* Put tooltip in topmost group and in position. */
6112 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6113 root_x
, root_y
, 0, 0,
6114 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6116 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6117 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6119 SWP_NOMOVE
| SWP_NOSIZE
6120 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6127 /* Hide a previous tip, if any. */
6130 ASET (last_show_tip_args
, 0, string
);
6131 ASET (last_show_tip_args
, 1, frame
);
6132 ASET (last_show_tip_args
, 2, parms
);
6134 /* Add default values to frame parameters. */
6135 if (NILP (Fassq (Qname
, parms
)))
6136 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
6137 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6138 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
6139 if (NILP (Fassq (Qright_divider_width
, parms
)))
6140 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
6141 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
6142 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
6143 if (NILP (Fassq (Qborder_width
, parms
)))
6144 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
6145 if (NILP (Fassq (Qborder_color
, parms
)))
6146 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
6147 if (NILP (Fassq (Qbackground_color
, parms
)))
6148 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
6151 /* Block input until the tip has been fully drawn, to avoid crashes
6152 when drawing tips in menus. */
6155 /* Create a frame for the tooltip, and record it in the global
6156 variable tip_frame. */
6157 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
6160 /* Set up the frame's root window. */
6161 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6167 if (CONSP (Vx_max_tooltip_size
)
6168 && INTEGERP (XCAR (Vx_max_tooltip_size
))
6169 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
6170 && INTEGERP (XCDR (Vx_max_tooltip_size
))
6171 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
6173 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
6174 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
6179 w
->total_lines
= 40;
6182 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
6183 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
6185 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
6186 adjust_frame_glyphs (f
);
6187 w
->pseudo_window_p
= true;
6189 /* Display the tooltip text in a temporary buffer. */
6190 old_buffer
= current_buffer
;
6191 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
6192 bset_truncate_lines (current_buffer
, Qnil
);
6193 clear_glyph_matrix (w
->desired_matrix
);
6194 clear_glyph_matrix (w
->current_matrix
);
6195 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
6196 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6198 /* Compute width and height of the tooltip. */
6200 seen_reversed_p
= false;
6201 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6203 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6207 /* Stop at the first empty row at the end. */
6208 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6211 /* Let the row go over the full width of the frame. */
6212 row
->full_width_p
= true;
6214 row_width
= row
->pixel_width
;
6215 if (row
->used
[TEXT_AREA
])
6217 if (!row
->reversed_p
)
6219 /* There's a glyph at the end of rows that is used to
6220 place the cursor there. Don't include the width of
6222 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6223 if (NILP (last
->object
))
6224 row_width
-= last
->pixel_width
;
6228 /* There could be a stretch glyph at the beginning of R2L
6229 rows that is produced by extend_face_to_end_of_line.
6230 Don't count that glyph. */
6231 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
6233 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
6235 row_width
-= g
->pixel_width
;
6236 seen_reversed_p
= true;
6241 height
+= row
->height
;
6242 width
= max (width
, row_width
);
6245 /* If we've seen partial-length R2L rows, we need to re-adjust the
6246 tool-tip frame width and redisplay it again, to avoid over-wide
6247 tips due to the stretch glyph that extends R2L lines to full
6248 width of the frame. */
6249 if (seen_reversed_p
)
6251 /* PXW: Why do we do the pixel-to-cols conversion only if
6252 seen_reversed_p holds? Don't we have to set other fields of
6253 the window/frame structure?
6255 w->total_cols and FRAME_TOTAL_COLS want the width in columns,
6257 w
->pixel_width
= width
;
6258 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
6259 w
->total_cols
= width
;
6260 FRAME_TOTAL_COLS (f
) = width
;
6261 SET_FRAME_WIDTH (f
, width
);
6262 adjust_frame_glyphs (f
);
6263 w
->pseudo_window_p
= 1;
6264 clear_glyph_matrix (w
->desired_matrix
);
6265 clear_glyph_matrix (w
->current_matrix
);
6266 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6268 /* Recompute width and height of the tooltip. */
6269 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6271 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6275 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6277 row
->full_width_p
= true;
6278 row_width
= row
->pixel_width
;
6279 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
6281 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6282 if (NILP (last
->object
))
6283 row_width
-= last
->pixel_width
;
6286 height
+= row
->height
;
6287 width
= max (width
, row_width
);
6291 /* Add the frame's internal border to the width and height the w32
6292 window should have. */
6293 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6294 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6296 /* Move the tooltip window where the mouse pointer is. Resize and
6299 PXW: This should use the frame's pixel coordinates. */
6300 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
6303 /* Adjust Window size to take border into account. */
6305 rect
.left
= rect
.top
= 0;
6307 rect
.bottom
= height
;
6308 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6309 FRAME_EXTERNAL_MENU_BAR (f
));
6311 /* Position and size tooltip, and put it in the topmost group.
6312 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
6313 peculiarity of w32 display: without it, some fonts cause the
6314 last character of the tip to be truncated or wrapped around to
6316 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6318 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
6319 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6321 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6322 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6324 SWP_NOMOVE
| SWP_NOSIZE
6325 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6327 /* Let redisplay know that we have made the frame visible already. */
6328 SET_FRAME_VISIBLE (f
, 1);
6330 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
6333 /* Draw into the window. */
6334 w
->must_be_updated_p
= true;
6335 update_single_window (w
);
6339 /* Restore original current buffer. */
6340 set_buffer_internal_1 (old_buffer
);
6341 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6344 /* Let the tip disappear after timeout seconds. */
6345 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
6346 intern ("x-hide-tip"));
6349 return unbind_to (count
, Qnil
);
6353 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
6354 doc
: /* Hide the current tooltip window, if there is any.
6355 Value is t if tooltip was open, nil otherwise. */)
6359 Lisp_Object deleted
, frame
, timer
;
6360 struct gcpro gcpro1
, gcpro2
;
6362 /* Return quickly if nothing to do. */
6363 if (NILP (tip_timer
) && NILP (tip_frame
))
6368 GCPRO2 (frame
, timer
);
6369 tip_frame
= tip_timer
= deleted
= Qnil
;
6371 count
= SPECPDL_INDEX ();
6372 specbind (Qinhibit_redisplay
, Qt
);
6373 specbind (Qinhibit_quit
, Qt
);
6376 call1 (Qcancel_timer
, timer
);
6380 delete_frame (frame
, Qnil
);
6385 return unbind_to (count
, deleted
);
6388 /***********************************************************************
6389 File selection dialog
6390 ***********************************************************************/
6392 #define FILE_NAME_TEXT_FIELD edt1
6393 #define FILE_NAME_COMBO_BOX cmb13
6394 #define FILE_NAME_LIST lst1
6396 /* Callback for altering the behavior of the Open File dialog.
6397 Makes the Filename text field contain "Current Directory" and be
6398 read-only when "Directories" is selected in the filter. This
6399 allows us to work around the fact that the standard Open File
6400 dialog does not support directories. */
6401 static UINT_PTR CALLBACK
6402 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6404 if (msg
== WM_NOTIFY
)
6406 OFNOTIFYW
* notify_w
= (OFNOTIFYW
*)lParam
;
6407 OFNOTIFYA
* notify_a
= (OFNOTIFYA
*)lParam
;
6408 int dropdown_changed
;
6410 #ifdef NTGUI_UNICODE
6411 const int use_unicode
= 1;
6412 #else /* !NTGUI_UNICODE */
6413 int use_unicode
= w32_unicode_filenames
;
6414 #endif /* NTGUI_UNICODE */
6416 /* Detect when the Filter dropdown is changed. */
6419 notify_w
->hdr
.code
== CDN_TYPECHANGE
6420 || notify_w
->hdr
.code
== CDN_INITDONE
;
6423 notify_a
->hdr
.code
== CDN_TYPECHANGE
6424 || notify_a
->hdr
.code
== CDN_INITDONE
;
6425 if (dropdown_changed
)
6427 HWND dialog
= GetParent (hwnd
);
6428 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6429 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6432 /* At least on Windows 7, the above attempt to get the window handle
6433 to the File Name Text Field fails. The following code does the
6434 job though. Note that this code is based on my examination of the
6435 window hierarchy using Microsoft Spy++. bk */
6436 if (edit_control
== NULL
)
6438 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6441 tmp
= GetWindow (tmp
, GW_CHILD
);
6443 edit_control
= GetWindow (tmp
, GW_CHILD
);
6447 /* Directories is in index 2. */
6450 dir_index
= notify_w
->lpOFN
->nFilterIndex
;
6451 hdr_code
= notify_w
->hdr
.code
;
6455 dir_index
= notify_a
->lpOFN
->nFilterIndex
;
6456 hdr_code
= notify_a
->hdr
.code
;
6461 SendMessageW (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6462 (LPARAM
)L
"Current Directory");
6464 SendMessageA (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6465 (LPARAM
)"Current Directory");
6466 EnableWindow (edit_control
, FALSE
);
6467 /* Note that at least on Windows 7, the above call to EnableWindow
6468 disables the window that would ordinarily have focus. If we
6469 do not set focus to some other window here, focus will land in
6470 no man's land and the user will be unable to tab through the
6471 dialog box (pressing tab will only result in a beep).
6472 Avoid that problem by setting focus to the list here. */
6473 if (hdr_code
== CDN_INITDONE
)
6478 /* Don't override default filename on init done. */
6479 if (hdr_code
== CDN_TYPECHANGE
)
6482 SendMessageW (dialog
, CDM_SETCONTROLTEXT
,
6483 FILE_NAME_TEXT_FIELD
, (LPARAM
)L
"");
6485 SendMessageA (dialog
, CDM_SETCONTROLTEXT
,
6486 FILE_NAME_TEXT_FIELD
, (LPARAM
)"");
6488 EnableWindow (edit_control
, TRUE
);
6495 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6496 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6497 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6498 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6499 or directory must exist.
6501 This function is only defined on NS, MS Windows, and X Windows with the
6502 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6503 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6504 On Windows 7 and later, the file selection dialog "remembers" the last
6505 directory where the user selected a file, and will open that directory
6506 instead of DIR on subsequent invocations of this function with the same
6507 value of DIR as in previous invocations; this is standard Windows behavior. */)
6508 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6510 /* Filter index: 1: All Files, 2: Directories only */
6511 static const wchar_t filter_w
[] = L
"All Files (*.*)\0*.*\0Directories\0*|*\0";
6512 static const char filter_a
[] = "All Files (*.*)\0*.*\0Directories\0*|*\0";
6514 Lisp_Object filename
= default_filename
;
6515 struct frame
*f
= SELECTED_FRAME ();
6516 BOOL file_opened
= FALSE
;
6517 Lisp_Object orig_dir
= dir
;
6518 Lisp_Object orig_prompt
= prompt
;
6520 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6521 compatibility) we end up with the old file dialogs. Define a big
6522 enough struct for the new dialog to trick GetOpenFileName into
6523 giving us the new dialogs on newer versions of Windows. */
6525 OPENFILENAMEW details
;
6526 #if _WIN32_WINNT < 0x500 /* < win2k */
6530 #endif /* < win2k */
6531 } new_file_details_w
;
6533 #ifdef NTGUI_UNICODE
6534 wchar_t filename_buf_w
[32*1024 + 1]; // NT kernel maximum
6535 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6536 const int use_unicode
= 1;
6537 #else /* not NTGUI_UNICODE */
6539 OPENFILENAMEA details
;
6540 #if _WIN32_WINNT < 0x500 /* < win2k */
6544 #endif /* < win2k */
6545 } new_file_details_a
;
6546 wchar_t filename_buf_w
[MAX_PATH
+ 1], dir_w
[MAX_PATH
];
6547 char filename_buf_a
[MAX_PATH
+ 1], dir_a
[MAX_PATH
];
6548 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6549 OPENFILENAMEA
* file_details_a
= &new_file_details_a
.details
;
6550 int use_unicode
= w32_unicode_filenames
;
6554 char fname_ret
[MAX_UTF8_PATH
];
6555 #endif /* NTGUI_UNICODE */
6557 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6558 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6561 struct gcpro gcpro1
, gcpro2
;
6562 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6564 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6565 system file encoding expected by the platform APIs (e.g. Cygwin's
6566 POSIX implementation) may not be the same as the encoding expected
6567 by the Windows "ANSI" APIs! */
6569 CHECK_STRING (prompt
);
6572 dir
= Fexpand_file_name (dir
, Qnil
);
6574 if (STRINGP (filename
))
6575 filename
= Ffile_name_nondirectory (filename
);
6577 filename
= empty_unibyte_string
;
6580 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6581 if (SCHARS (filename
) > 0)
6582 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6586 CHECK_STRING (filename
);
6588 /* The code in file_dialog_callback that attempts to set the text
6589 of the file name edit window when handling the CDN_INITDONE
6590 WM_NOTIFY message does not work. Setting filename to "Current
6591 Directory" in the only_dir_p case here does work however. */
6592 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6593 filename
= build_string ("Current Directory");
6595 /* Convert the values we've computed so far to system form. */
6596 #ifdef NTGUI_UNICODE
6597 to_unicode (prompt
, &prompt
);
6598 to_unicode (dir
, &dir
);
6599 to_unicode (filename
, &filename
);
6600 if (SBYTES (filename
) + 1 > sizeof (filename_buf_w
))
6601 report_file_error ("filename too long", default_filename
);
6603 memcpy (filename_buf_w
, SDATA (filename
), SBYTES (filename
) + 1);
6604 #else /* !NTGUI_UNICODE */
6605 prompt
= ENCODE_FILE (prompt
);
6606 dir
= ENCODE_FILE (dir
);
6607 filename
= ENCODE_FILE (filename
);
6609 /* We modify these in-place, so make copies for safety. */
6610 dir
= Fcopy_sequence (dir
);
6611 unixtodos_filename (SDATA (dir
));
6612 filename
= Fcopy_sequence (filename
);
6613 unixtodos_filename (SDATA (filename
));
6614 if (SBYTES (filename
) >= MAX_UTF8_PATH
)
6615 report_file_error ("filename too long", default_filename
);
6616 if (w32_unicode_filenames
)
6618 filename_to_utf16 (SSDATA (dir
), dir_w
);
6619 if (filename_to_utf16 (SSDATA (filename
), filename_buf_w
) != 0)
6621 /* filename_to_utf16 sets errno to ENOENT when the file
6622 name is too long or cannot be converted to UTF-16. */
6623 if (errno
== ENOENT
&& filename_buf_w
[MAX_PATH
- 1] != 0)
6624 report_file_error ("filename too long", default_filename
);
6626 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6627 SSDATA (prompt
), -1, NULL
, 0);
6630 prompt_w
= alloca (len
* sizeof (wchar_t));
6631 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6632 SSDATA (prompt
), -1, prompt_w
, len
);
6636 filename_to_ansi (SSDATA (dir
), dir_a
);
6637 if (filename_to_ansi (SSDATA (filename
), filename_buf_a
) != '\0')
6639 /* filename_to_ansi sets errno to ENOENT when the file
6640 name is too long or cannot be converted to UTF-16. */
6641 if (errno
== ENOENT
&& filename_buf_a
[MAX_PATH
- 1] != 0)
6642 report_file_error ("filename too long", default_filename
);
6644 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6645 SSDATA (prompt
), -1, NULL
, 0);
6648 prompt_w
= alloca (len
* sizeof (wchar_t));
6649 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6650 SSDATA (prompt
), -1, prompt_w
, len
);
6651 len
= pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, NULL
, 0, NULL
, NULL
);
6654 prompt_a
= alloca (len
);
6655 pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, prompt_a
, len
, NULL
, NULL
);
6657 #endif /* NTGUI_UNICODE */
6659 /* Fill in the structure for the call to GetOpenFileName below.
6660 For NTGUI_UNICODE builds (which run only on NT), we just use
6661 the actual size of the structure. For non-NTGUI_UNICODE
6662 builds, we tell the OS we're using an old version of the
6663 structure if the OS isn't new enough to support the newer
6667 memset (&new_file_details_w
, 0, sizeof (new_file_details_w
));
6668 if (w32_major_version
> 4 && w32_major_version
< 95)
6669 file_details_w
->lStructSize
= sizeof (new_file_details_w
);
6671 file_details_w
->lStructSize
= sizeof (*file_details_w
);
6672 /* Set up the inout parameter for the selected file name. */
6673 file_details_w
->lpstrFile
= filename_buf_w
;
6674 file_details_w
->nMaxFile
=
6675 sizeof (filename_buf_w
) / sizeof (*filename_buf_w
);
6676 file_details_w
->hwndOwner
= FRAME_W32_WINDOW (f
);
6677 /* Undocumented Bug in Common File Dialog:
6678 If a filter is not specified, shell links are not resolved. */
6679 file_details_w
->lpstrFilter
= filter_w
;
6680 #ifdef NTGUI_UNICODE
6681 file_details_w
->lpstrInitialDir
= (wchar_t*) SDATA (dir
);
6682 file_details_w
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6684 file_details_w
->lpstrInitialDir
= dir_w
;
6685 file_details_w
->lpstrTitle
= prompt_w
;
6687 file_details_w
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6688 file_details_w
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6689 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6690 if (!NILP (mustmatch
))
6692 /* Require that the path to the parent directory exists. */
6693 file_details_w
->Flags
|= OFN_PATHMUSTEXIST
;
6694 /* If we are looking for a file, require that it exists. */
6695 if (NILP (only_dir_p
))
6696 file_details_w
->Flags
|= OFN_FILEMUSTEXIST
;
6699 #ifndef NTGUI_UNICODE
6702 memset (&new_file_details_a
, 0, sizeof (new_file_details_a
));
6703 if (w32_major_version
> 4 && w32_major_version
< 95)
6704 file_details_a
->lStructSize
= sizeof (new_file_details_a
);
6706 file_details_a
->lStructSize
= sizeof (*file_details_a
);
6707 file_details_a
->lpstrFile
= filename_buf_a
;
6708 file_details_a
->nMaxFile
=
6709 sizeof (filename_buf_a
) / sizeof (*filename_buf_a
);
6710 file_details_a
->hwndOwner
= FRAME_W32_WINDOW (f
);
6711 file_details_a
->lpstrFilter
= filter_a
;
6712 file_details_a
->lpstrInitialDir
= dir_a
;
6713 file_details_a
->lpstrTitle
= prompt_a
;
6714 file_details_a
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6715 file_details_a
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6716 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6717 if (!NILP (mustmatch
))
6719 /* Require that the path to the parent directory exists. */
6720 file_details_a
->Flags
|= OFN_PATHMUSTEXIST
;
6721 /* If we are looking for a file, require that it exists. */
6722 if (NILP (only_dir_p
))
6723 file_details_a
->Flags
|= OFN_FILEMUSTEXIST
;
6726 #endif /* !NTGUI_UNICODE */
6729 int count
= SPECPDL_INDEX ();
6730 /* Prevent redisplay. */
6731 specbind (Qinhibit_redisplay
, Qt
);
6735 file_details_w
->lpfnHook
= file_dialog_callback
;
6737 file_opened
= GetOpenFileNameW (file_details_w
);
6739 #ifndef NTGUI_UNICODE
6742 file_details_a
->lpfnHook
= file_dialog_callback
;
6744 file_opened
= GetOpenFileNameA (file_details_a
);
6746 #endif /* !NTGUI_UNICODE */
6748 unbind_to (count
, Qnil
);
6753 /* Get an Emacs string from the value Windows gave us. */
6754 #ifdef NTGUI_UNICODE
6755 filename
= from_unicode_buffer (filename_buf_w
);
6756 #else /* !NTGUI_UNICODE */
6758 filename_from_utf16 (filename_buf_w
, fname_ret
);
6760 filename_from_ansi (filename_buf_a
, fname_ret
);
6761 dostounix_filename (fname_ret
);
6762 filename
= DECODE_FILE (build_unibyte_string (fname_ret
));
6763 #endif /* NTGUI_UNICODE */
6766 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
6769 /* Strip the dummy filename off the end of the string if we
6770 added it to select a directory. */
6771 if ((use_unicode
&& file_details_w
->nFilterIndex
== 2)
6772 #ifndef NTGUI_UNICODE
6773 || (!use_unicode
&& file_details_a
->nFilterIndex
== 2)
6776 filename
= Ffile_name_directory (filename
);
6778 /* User canceled the dialog without making a selection. */
6779 else if (!CommDlgExtendedError ())
6781 /* An error occurred, fallback on reading from the mini-buffer. */
6783 filename
= Fcompleting_read (
6785 intern ("read-file-name-internal"),
6796 /* Make "Cancel" equivalent to C-g. */
6797 if (NILP (filename
))
6798 Fsignal (Qquit
, Qnil
);
6800 RETURN_UNGCPRO (filename
);
6805 /* Moving files to the system recycle bin.
6806 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6807 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6808 Ssystem_move_file_to_trash
, 1, 1, 0,
6809 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6810 (Lisp_Object filename
)
6812 Lisp_Object handler
;
6813 Lisp_Object encoded_file
;
6814 Lisp_Object operation
;
6816 operation
= Qdelete_file
;
6817 if (!NILP (Ffile_directory_p (filename
))
6818 && NILP (Ffile_symlink_p (filename
)))
6820 operation
= intern ("delete-directory");
6821 filename
= Fdirectory_file_name (filename
);
6824 /* Must have fully qualified file names for moving files to Recycle
6826 filename
= Fexpand_file_name (filename
, Qnil
);
6828 handler
= Ffind_file_name_handler (filename
, operation
);
6829 if (!NILP (handler
))
6830 return call2 (handler
, operation
, filename
);
6836 encoded_file
= ENCODE_FILE (filename
);
6838 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6840 /* The Unicode version of SHFileOperation is not supported on
6842 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
6844 SHFILEOPSTRUCTW file_op_w
;
6845 /* We need one more element beyond MAX_PATH because this is
6846 a list of file names, with the last element double-null
6848 wchar_t tmp_path_w
[MAX_PATH
+ 1];
6850 memset (tmp_path_w
, 0, sizeof (tmp_path_w
));
6851 filename_to_utf16 (path
, tmp_path_w
);
6853 /* On Windows, write permission is required to delete/move files. */
6854 _wchmod (tmp_path_w
, 0666);
6856 memset (&file_op_w
, 0, sizeof (file_op_w
));
6857 file_op_w
.hwnd
= HWND_DESKTOP
;
6858 file_op_w
.wFunc
= FO_DELETE
;
6859 file_op_w
.pFrom
= tmp_path_w
;
6860 file_op_w
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6861 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6862 file_op_w
.fAnyOperationsAborted
= FALSE
;
6864 result
= SHFileOperationW (&file_op_w
);
6868 SHFILEOPSTRUCTA file_op_a
;
6869 char tmp_path_a
[MAX_PATH
+ 1];
6871 memset (tmp_path_a
, 0, sizeof (tmp_path_a
));
6872 filename_to_ansi (path
, tmp_path_a
);
6874 /* If a file cannot be represented in ANSI codepage, don't
6875 let them inadvertently delete other files because some
6876 characters are interpreted as a wildcards. */
6877 if (_mbspbrk (tmp_path_a
, "?*"))
6878 result
= ERROR_FILE_NOT_FOUND
;
6881 _chmod (tmp_path_a
, 0666);
6883 memset (&file_op_a
, 0, sizeof (file_op_a
));
6884 file_op_a
.hwnd
= HWND_DESKTOP
;
6885 file_op_a
.wFunc
= FO_DELETE
;
6886 file_op_a
.pFrom
= tmp_path_a
;
6887 file_op_a
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6888 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6889 file_op_a
.fAnyOperationsAborted
= FALSE
;
6891 result
= SHFileOperationA (&file_op_a
);
6895 report_file_error ("Removing old name", list1 (filename
));
6900 #endif /* WINDOWSNT */
6903 /***********************************************************************
6904 w32 specialized functions
6905 ***********************************************************************/
6907 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6908 Sw32_send_sys_command
, 1, 2, 0,
6909 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6910 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6911 to minimize), #xf120 to restore frame to original size, and #xf100
6912 to activate the menubar for keyboard access. #xf140 activates the
6913 screen saver if defined.
6915 If optional parameter FRAME is not specified, use selected frame. */)
6916 (Lisp_Object command
, Lisp_Object frame
)
6918 struct frame
*f
= decode_window_system_frame (frame
);
6920 CHECK_NUMBER (command
);
6922 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6927 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6928 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6929 This is a wrapper around the ShellExecute system function, which
6930 invokes the application registered to handle OPERATION for DOCUMENT.
6932 OPERATION is either nil or a string that names a supported operation.
6933 What operations can be used depends on the particular DOCUMENT and its
6934 handler application, but typically it is one of the following common
6937 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6938 executable program (application). If it is an application,
6939 that application is launched in the current buffer's default
6940 directory. Otherwise, the application associated with
6941 DOCUMENT is launched in the buffer's default directory.
6942 \"opennew\" - like \"open\", but instruct the application to open
6943 DOCUMENT in a new window.
6944 \"openas\" - open the \"Open With\" dialog for DOCUMENT.
6945 \"print\" - print DOCUMENT, which must be a file.
6946 \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
6947 The printer should be provided in PARAMETERS, see below.
6948 \"explore\" - start the Windows Explorer on DOCUMENT.
6949 \"edit\" - launch an editor and open DOCUMENT for editing; which
6950 editor is launched depends on the association for the
6952 \"find\" - initiate search starting from DOCUMENT, which must specify
6954 \"delete\" - move DOCUMENT, a file or a directory, to Recycle Bin.
6955 \"copy\" - copy DOCUMENT, which must be a file or a directory, into
6957 \"cut\" - move DOCUMENT, a file or a directory, into the clipboard.
6958 \"paste\" - paste the file whose name is in the clipboard into DOCUMENT,
6959 which must be a directory.
6961 - create a shortcut in DOCUMENT (which must be a directory)
6962 the file or directory whose name is in the clipboard.
6963 \"runas\" - run DOCUMENT, which must be an excutable file, with
6964 elevated privileges (a.k.a. \"as Administrator\").
6966 - open the property sheet dialog for DOCUMENT.
6967 nil - invoke the default OPERATION, or \"open\" if default is
6968 not defined or unavailable.
6970 DOCUMENT is typically the name of a document file or a URL, but can
6971 also be an executable program to run, or a directory to open in the
6972 Windows Explorer. If it is a file or a directory, it must be a local
6973 one; this function does not support remote file names.
6975 If DOCUMENT is an executable program, the optional third arg PARAMETERS
6976 can be a string containing command line parameters, separated by blanks,
6977 that will be passed to the program. Some values of OPERATION also require
6978 parameters (e.g., \"printto\" requires the printer address). Otherwise,
6979 PARAMETERS should be nil or unspecified. Note that double quote characters
6980 in PARAMETERS must each be enclosed in 2 additional quotes, as in \"\"\".
6982 Optional fourth argument SHOW-FLAG can be used to control how the
6983 application will be displayed when it is invoked. If SHOW-FLAG is nil
6984 or unspecified, the application is displayed as if SHOW-FLAG of 10 was
6985 specified, otherwise it is an integer between 0 and 11 representing
6989 1 - start as normal-size window
6990 3 - start in a maximized window
6991 6 - start in a minimized window
6992 10 - start as the application itself specifies; this is the default. */)
6993 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6996 Lisp_Object current_dir
= BVAR (current_buffer
, directory
);;
6997 wchar_t *doc_w
= NULL
, *params_w
= NULL
, *ops_w
= NULL
;
7001 int use_unicode
= w32_unicode_filenames
;
7002 char *doc_a
= NULL
, *params_a
= NULL
, *ops_a
= NULL
;
7003 Lisp_Object absdoc
, handler
;
7005 struct gcpro gcpro1
;
7008 CHECK_STRING (document
);
7011 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
7012 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
7014 /* Encode filename, current directory and parameters. */
7015 current_dir
= GUI_ENCODE_FILE (current_dir
);
7016 document
= GUI_ENCODE_FILE (document
);
7017 doc_w
= GUI_SDATA (document
);
7018 if (STRINGP (parameters
))
7020 parameters
= GUI_ENCODE_SYSTEM (parameters
);
7021 params_w
= GUI_SDATA (parameters
);
7023 if (STRINGP (operation
))
7025 operation
= GUI_ENCODE_SYSTEM (operation
);
7026 ops_w
= GUI_SDATA (operation
);
7028 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
7029 GUI_SDATA (current_dir
),
7030 (INTEGERP (show_flag
)
7031 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
7038 case SE_ERR_ACCESSDENIED
:
7039 errstr
= w32_strerror (ERROR_ACCESS_DENIED
);
7041 case SE_ERR_ASSOCINCOMPLETE
:
7042 case SE_ERR_NOASSOC
:
7043 errstr
= w32_strerror (ERROR_NO_ASSOCIATION
);
7045 case SE_ERR_DDEBUSY
:
7046 case SE_ERR_DDEFAIL
:
7047 errstr
= w32_strerror (ERROR_DDE_FAIL
);
7049 case SE_ERR_DDETIMEOUT
:
7050 errstr
= w32_strerror (ERROR_TIMEOUT
);
7052 case SE_ERR_DLLNOTFOUND
:
7053 errstr
= w32_strerror (ERROR_DLL_NOT_FOUND
);
7056 errstr
= w32_strerror (ERROR_FILE_NOT_FOUND
);
7059 errstr
= w32_strerror (ERROR_NOT_ENOUGH_MEMORY
);
7062 errstr
= w32_strerror (ERROR_PATH_NOT_FOUND
);
7065 errstr
= w32_strerror (ERROR_SHARING_VIOLATION
);
7068 errstr
= w32_strerror (0);
7074 const char file_url_str
[] = "file:///";
7075 const int file_url_len
= sizeof (file_url_str
) - 1;
7076 if (strncmp (SSDATA (document
), file_url_str
, file_url_len
) == 0)
7078 /* Passing "file:///" URLs to ShellExecute causes shlwapi.dll to
7079 start a thread in some rare system configurations, for
7080 unknown reasons. That thread is started in the context of
7081 the Emacs process, but out of control of our code, and seems
7082 to never exit afterwards. Each such thread reserves 8MB of
7083 stack space (because that's the value recorded in the Emacs
7084 executable at link time: Emacs needs a large stack). So a
7085 large enough number of invocations of w32-shell-execute can
7086 potentially cause the Emacs process to run out of available
7087 address space, which is nasty. To work around this, we
7088 convert such URLs to local file names, which seems to prevent
7089 those threads from starting. See bug #20220. */
7090 char *p
= SSDATA (document
) + file_url_len
;
7092 if (c_isalpha (*p
) && p
[1] == ':' && IS_DIRECTORY_SEP (p
[2]))
7093 document
= Fsubstring_no_properties (document
,
7094 make_number (file_url_len
), Qnil
);
7096 /* We have a situation here. If DOCUMENT is a relative file name,
7097 but its name includes leading directories, i.e. it lives not in
7098 CURRENT_DIR, but in its subdirectory, then ShellExecute below
7099 will fail to find it. So we need to make the file name is
7100 absolute. But DOCUMENT does not have to be a file, it can be a
7101 URL, for example. So we make it absolute only if it is an
7102 existing file; if it is a file that does not exist, tough. */
7104 absdoc
= Fexpand_file_name (document
, Qnil
);
7105 /* Don't call file handlers for file-exists-p, since they might
7106 attempt to access the file, which could fail or produce undesired
7107 consequences, see bug#16558 for an example. */
7108 handler
= Ffind_file_name_handler (absdoc
, Qfile_exists_p
);
7111 Lisp_Object absdoc_encoded
= ENCODE_FILE (absdoc
);
7113 if (faccessat (AT_FDCWD
, SSDATA (absdoc_encoded
), F_OK
, AT_EACCESS
) == 0)
7115 /* ShellExecute fails if DOCUMENT is a UNC with forward
7116 slashes (expand-file-name above converts all backslashes
7117 to forward slashes). Now that we know DOCUMENT is a
7118 file, we can mirror all forward slashes into backslashes. */
7119 unixtodos_filename (SSDATA (absdoc_encoded
));
7120 document
= absdoc_encoded
;
7123 document
= ENCODE_FILE (document
);
7126 document
= ENCODE_FILE (document
);
7129 current_dir
= ENCODE_FILE (current_dir
);
7132 wchar_t document_w
[MAX_PATH
], current_dir_w
[MAX_PATH
];
7133 SHELLEXECUTEINFOW shexinfo_w
;
7135 /* Encode filename, current directory and parameters, and
7136 convert operation to UTF-16. */
7137 filename_to_utf16 (SSDATA (current_dir
), current_dir_w
);
7138 filename_to_utf16 (SSDATA (document
), document_w
);
7140 if (STRINGP (parameters
))
7144 parameters
= ENCODE_SYSTEM (parameters
);
7145 len
= pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7146 SSDATA (parameters
), -1, NULL
, 0);
7149 params_w
= alloca (len
* sizeof (wchar_t));
7150 pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7151 SSDATA (parameters
), -1, params_w
, len
);
7153 if (STRINGP (operation
))
7155 /* Assume OPERATION is pure ASCII. */
7156 const char *s
= SSDATA (operation
);
7158 int len
= SBYTES (operation
) + 1;
7162 d
= ops_w
= alloca (len
* sizeof (wchar_t));
7163 while (d
< ops_w
+ len
- 1)
7168 /* Using ShellExecuteEx and setting the SEE_MASK_INVOKEIDLIST
7169 flag succeeds with more OPERATIONs (a.k.a. "verbs"), as it is
7170 able to invoke verbs from shortcut menu extensions, not just
7171 static verbs listed in the Registry. */
7172 memset (&shexinfo_w
, 0, sizeof (shexinfo_w
));
7173 shexinfo_w
.cbSize
= sizeof (shexinfo_w
);
7175 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7176 shexinfo_w
.hwnd
= NULL
;
7177 shexinfo_w
.lpVerb
= ops_w
;
7178 shexinfo_w
.lpFile
= doc_w
;
7179 shexinfo_w
.lpParameters
= params_w
;
7180 shexinfo_w
.lpDirectory
= current_dir_w
;
7182 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7183 success
= ShellExecuteExW (&shexinfo_w
);
7187 char document_a
[MAX_PATH
], current_dir_a
[MAX_PATH
];
7188 SHELLEXECUTEINFOA shexinfo_a
;
7190 filename_to_ansi (SSDATA (current_dir
), current_dir_a
);
7191 filename_to_ansi (SSDATA (document
), document_a
);
7193 if (STRINGP (parameters
))
7195 parameters
= ENCODE_SYSTEM (parameters
);
7196 params_a
= SSDATA (parameters
);
7198 if (STRINGP (operation
))
7200 /* Assume OPERATION is pure ASCII. */
7201 ops_a
= SSDATA (operation
);
7203 memset (&shexinfo_a
, 0, sizeof (shexinfo_a
));
7204 shexinfo_a
.cbSize
= sizeof (shexinfo_a
);
7206 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7207 shexinfo_a
.hwnd
= NULL
;
7208 shexinfo_a
.lpVerb
= ops_a
;
7209 shexinfo_a
.lpFile
= doc_a
;
7210 shexinfo_a
.lpParameters
= params_a
;
7211 shexinfo_a
.lpDirectory
= current_dir_a
;
7213 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7214 success
= ShellExecuteExA (&shexinfo_a
);
7220 errstr
= w32_strerror (0);
7222 #endif /* !CYGWIN */
7224 /* The error string might be encoded in the locale's encoding. */
7225 if (!NILP (Vlocale_coding_system
))
7227 Lisp_Object decoded
=
7228 code_convert_string_norecord (build_unibyte_string (errstr
),
7229 Vlocale_coding_system
, 0);
7230 errstr
= SSDATA (decoded
);
7232 error ("ShellExecute failed: %s", errstr
);
7235 /* Lookup virtual keycode from string representing the name of a
7236 non-ascii keystroke into the corresponding virtual key, using
7237 lispy_function_keys. */
7239 lookup_vk_code (char *key
)
7243 for (i
= 0; i
< 256; i
++)
7244 if (lispy_function_keys
[i
]
7245 && strcmp (lispy_function_keys
[i
], key
) == 0)
7251 /* Convert a one-element vector style key sequence to a hot key
7254 w32_parse_hot_key (Lisp_Object key
)
7256 /* Copied from Fdefine_key and store_in_keymap. */
7257 register Lisp_Object c
;
7261 struct gcpro gcpro1
;
7265 if (ASIZE (key
) != 1)
7272 if (CONSP (c
) && lucid_event_type_list_p (c
))
7273 c
= Fevent_convert_list (c
);
7277 if (! INTEGERP (c
) && ! SYMBOLP (c
))
7278 error ("Key definition is invalid");
7280 /* Work out the base key and the modifiers. */
7283 c
= parse_modifiers (c
);
7284 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
7288 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
7290 else if (INTEGERP (c
))
7292 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
7293 /* Many ascii characters are their own virtual key code. */
7294 vk_code
= XINT (c
) & CHARACTERBITS
;
7297 if (vk_code
< 0 || vk_code
> 255)
7300 if ((lisp_modifiers
& meta_modifier
) != 0
7301 && !NILP (Vw32_alt_is_meta
))
7302 lisp_modifiers
|= alt_modifier
;
7304 /* Supply defs missing from mingw32. */
7306 #define MOD_ALT 0x0001
7307 #define MOD_CONTROL 0x0002
7308 #define MOD_SHIFT 0x0004
7309 #define MOD_WIN 0x0008
7312 /* Convert lisp modifiers to Windows hot-key form. */
7313 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
7314 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
7315 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
7316 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
7318 return HOTKEY (vk_code
, w32_modifiers
);
7321 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
7322 Sw32_register_hot_key
, 1, 1, 0,
7323 doc
: /* Register KEY as a hot-key combination.
7324 Certain key combinations like Alt-Tab are reserved for system use on
7325 Windows, and therefore are normally intercepted by the system. However,
7326 most of these key combinations can be received by registering them as
7327 hot-keys, overriding their special meaning.
7329 KEY must be a one element key definition in vector form that would be
7330 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
7331 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
7332 is always interpreted as the Windows modifier keys.
7334 The return value is the hotkey-id if registered, otherwise nil. */)
7337 key
= w32_parse_hot_key (key
);
7339 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
7341 /* Reuse an empty slot if possible. */
7342 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
7344 /* Safe to add new key to list, even if we have focus. */
7346 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
7348 XSETCAR (item
, key
);
7350 /* Notify input thread about new hot-key definition, so that it
7351 takes effect without needing to switch focus. */
7352 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
7353 (WPARAM
) XINT (key
), 0);
7359 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
7360 Sw32_unregister_hot_key
, 1, 1, 0,
7361 doc
: /* Unregister KEY as a hot-key combination. */)
7366 if (!INTEGERP (key
))
7367 key
= w32_parse_hot_key (key
);
7369 item
= Fmemq (key
, w32_grabbed_keys
);
7375 eassert (CONSP (item
));
7376 /* Pass the tail of the list as a pointer to a Lisp_Cons cell,
7377 so that it works in a --with-wide-int build as well. */
7378 lparam
= (LPARAM
) XUNTAG (item
, Lisp_Cons
);
7380 /* Notify input thread about hot-key definition being removed, so
7381 that it takes effect without needing focus switch. */
7382 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
7383 (WPARAM
) XINT (XCAR (item
)), lparam
))
7386 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7393 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
7394 Sw32_registered_hot_keys
, 0, 0, 0,
7395 doc
: /* Return list of registered hot-key IDs. */)
7398 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
7401 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
7402 Sw32_reconstruct_hot_key
, 1, 1, 0,
7403 doc
: /* Convert hot-key ID to a lisp key combination.
7404 usage: (w32-reconstruct-hot-key ID) */)
7405 (Lisp_Object hotkeyid
)
7407 int vk_code
, w32_modifiers
;
7410 CHECK_NUMBER (hotkeyid
);
7412 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
7413 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
7415 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
7416 key
= intern (lispy_function_keys
[vk_code
]);
7418 key
= make_number (vk_code
);
7420 key
= Fcons (key
, Qnil
);
7421 if (w32_modifiers
& MOD_SHIFT
)
7422 key
= Fcons (Qshift
, key
);
7423 if (w32_modifiers
& MOD_CONTROL
)
7424 key
= Fcons (Qctrl
, key
);
7425 if (w32_modifiers
& MOD_ALT
)
7426 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
7427 if (w32_modifiers
& MOD_WIN
)
7428 key
= Fcons (Qhyper
, key
);
7433 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
7434 Sw32_toggle_lock_key
, 1, 2, 0,
7435 doc
: /* Toggle the state of the lock key KEY.
7436 KEY can be `capslock', `kp-numlock', or `scroll'.
7437 If the optional parameter NEW-STATE is a number, then the state of KEY
7438 is set to off if the low bit of NEW-STATE is zero, otherwise on.
7439 If NEW-STATE is omitted or nil, the function toggles the state,
7441 Value is the new state of the key, or nil if the function failed
7442 to change the state. */)
7443 (Lisp_Object key
, Lisp_Object new_state
)
7448 if (EQ (key
, intern ("capslock")))
7449 vk_code
= VK_CAPITAL
;
7450 else if (EQ (key
, intern ("kp-numlock")))
7451 vk_code
= VK_NUMLOCK
;
7452 else if (EQ (key
, intern ("scroll")))
7453 vk_code
= VK_SCROLL
;
7457 if (!dwWindowsThreadId
)
7458 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
7460 if (NILP (new_state
))
7463 lparam
= (XUINT (new_state
)) & 1;
7464 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
7465 (WPARAM
) vk_code
, lparam
))
7468 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7469 return make_number (msg
.wParam
);
7474 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
7476 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
7478 This is a direct interface to the Windows API FindWindow function. */)
7479 (Lisp_Object
class, Lisp_Object name
)
7484 CHECK_STRING (class);
7486 CHECK_STRING (name
);
7488 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
7489 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
7495 DEFUN ("w32-frame-menu-bar-size", Fw32_frame_menu_bar_size
, Sw32_frame_menu_bar_size
, 0, 1, 0,
7496 doc
: /* Return sizes of menu bar on frame FRAME.
7497 The return value is a list of four elements: The current width and
7498 height of FRAME's menu bar in pixels, the height of one menu bar line in
7499 a wrapped menu bar in pixels, and the height of a single line menu bar
7502 If FRAME is omitted or nil, the selected frame is used. */)
7505 struct frame
*f
= decode_any_frame (frame
);
7506 MENUBARINFO menu_bar
;
7507 int width
, height
, single_height
, wrapped_height
;
7511 single_height
= GetSystemMetrics (SM_CYMENU
);
7512 wrapped_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7513 menu_bar
.cbSize
= sizeof (menu_bar
);
7514 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7515 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7516 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7517 width
= menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
;
7518 height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7522 return list4 (make_number (width
), make_number (height
),
7523 make_number (wrapped_height
), make_number (single_height
));
7526 DEFUN ("w32-frame-rect", Fw32_frame_rect
, Sw32_frame_rect
, 0, 2, 0,
7527 doc
: /* Return boundary rectangle of FRAME in screen coordinates.
7528 FRAME must be a live frame and defaults to the selected one.
7530 The boundary rectangle is a list of four elements, specifying the left,
7531 top, right and bottom screen coordinates of FRAME including menu and
7532 title bar and decorations. Optional argument CLIENT non-nil means to
7533 return the boundaries of the client rectangle which excludes menu and
7534 title bar and decorations. */)
7535 (Lisp_Object frame
, Lisp_Object client
)
7537 struct frame
*f
= decode_live_frame (frame
);
7543 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
7545 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
7549 return list4 (make_number (rect
.left
), make_number (rect
.top
),
7550 make_number (rect
.right
), make_number (rect
.bottom
));
7553 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
7554 doc
: /* Return geometric attributes of frame FRAME.
7555 FRAME must be a live frame and defaults to the selected one.
7557 The return value is an association list containing the following
7558 elements (all size values are in pixels).
7560 - `frame-outer-size' is a cons of the outer width and height of FRAME.
7561 The outer size includes the title bar and the external borders as well
7562 as any menu and/or tool bar of frame.
7564 - `border' is a cons of the horizontal and vertical width of FRAME's
7567 - `title-bar-height' is the height of the title bar of FRAME.
7569 - `menu-bar-external' if t means the menu bar is by default external
7570 (not included in the inner size of FRAME).
7572 - `menu-bar-size' is a cons of the width and height of the menu bar of
7575 - `tool-bar-external' if t means the tool bar is by default external
7576 (not included in the inner size of FRAME).
7578 - `tool-bar-side' tells tells on which side the tool bar on FRAME is by
7579 default and can be one of `left', `top', `right' or `bottom'.
7581 - `tool-bar-size' is a cons of the width and height of the tool bar of
7584 - `frame-inner-size' is a cons of the inner width and height of FRAME.
7585 This excludes FRAME's title bar and external border as well as any
7586 external menu and/or tool bar. */)
7589 struct frame
*f
= decode_live_frame (frame
);
7590 Lisp_Object geometry
= Qnil
;
7591 RECT frame_outer_edges
, frame_inner_edges
;
7592 MENUBARINFO menu_bar
;
7593 int border_width
, border_height
, title_height
;
7594 int single_bar_height
, wrapped_bar_height
, menu_bar_height
;
7595 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
7599 /* Outer frame rectangle, including outer borders and title bar. */
7600 GetWindowRect (FRAME_W32_WINDOW (f
), &frame_outer_edges
);
7601 /* Inner frame rectangle, excluding borders and title bar. */
7602 GetClientRect (FRAME_W32_WINDOW (f
), &frame_inner_edges
);
7604 border_width
= GetSystemMetrics (SM_CXFRAME
);
7605 border_height
= GetSystemMetrics (SM_CYFRAME
);
7607 title_height
= GetSystemMetrics (SM_CYCAPTION
);
7609 menu_bar
.cbSize
= sizeof (menu_bar
);
7610 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7611 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7612 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7613 single_bar_height
= GetSystemMetrics (SM_CYMENU
);
7614 wrapped_bar_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7617 menu_bar_height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7618 /* Fix menu bar height reported by GetMenuBarInfo. */
7619 if (menu_bar_height
> single_bar_height
)
7620 /* A wrapped menu bar. */
7621 menu_bar_height
+= single_bar_height
- wrapped_bar_height
;
7622 else if (menu_bar_height
> 0)
7623 /* A single line menu bar. */
7624 menu_bar_height
= single_bar_height
;
7627 listn (CONSTYPE_HEAP
, 10,
7628 Fcons (Qframe_position
,
7629 Fcons (make_number (frame_outer_edges
.left
),
7630 make_number (frame_outer_edges
.top
))),
7631 Fcons (Qframe_outer_size
,
7633 (frame_outer_edges
.right
- frame_outer_edges
.left
),
7635 (frame_outer_edges
.bottom
- frame_outer_edges
.top
))),
7636 Fcons (Qexternal_border_size
,
7637 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7638 ? Fcons (make_number (0), make_number (0))
7639 : Fcons (make_number (border_width
),
7640 make_number (border_height
)))),
7641 Fcons (Qtitle_height
,
7642 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7644 : make_number (title_height
))),
7645 Fcons (Qmenu_bar_external
, Qt
),
7646 Fcons (Qmenu_bar_size
,
7648 (menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
),
7649 make_number (menu_bar_height
))),
7650 Fcons (Qtool_bar_external
, Qnil
),
7651 Fcons (Qtool_bar_position
, Qtop
),
7652 Fcons (Qtool_bar_size
,
7653 Fcons (make_number (FRAME_TOOL_BAR_LINES (f
)
7654 ? (FRAME_PIXEL_WIDTH (f
)
7655 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f
))
7657 make_number (FRAME_TOOL_BAR_HEIGHT (f
)))),
7658 Fcons (Qframe_inner_size
,
7660 (frame_inner_edges
.right
- frame_inner_edges
.left
),
7662 (frame_inner_edges
.bottom
- frame_inner_edges
.top
))));
7665 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
7666 doc
: /* Get power status information from Windows system.
7668 The following %-sequences are provided:
7669 %L AC line status (verbose)
7670 %B Battery status (verbose)
7671 %b Battery status, empty means high, `-' means low,
7672 `!' means critical, and `+' means charging
7673 %p Battery load percentage
7674 %s Remaining time (to charge or discharge) in seconds
7675 %m Remaining time (to charge or discharge) in minutes
7676 %h Remaining time (to charge or discharge) in hours
7677 %t Remaining time (to charge or discharge) in the form `h:min' */)
7680 Lisp_Object status
= Qnil
;
7682 SYSTEM_POWER_STATUS system_status
;
7683 if (GetSystemPowerStatus (&system_status
))
7685 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
7686 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
7688 long seconds_left
= (long) system_status
.BatteryLifeTime
;
7690 if (system_status
.ACLineStatus
== 0)
7691 line_status
= build_string ("off-line");
7692 else if (system_status
.ACLineStatus
== 1)
7693 line_status
= build_string ("on-line");
7695 line_status
= build_string ("N/A");
7697 if (system_status
.BatteryFlag
& 128)
7699 battery_status
= build_string ("N/A");
7700 battery_status_symbol
= empty_unibyte_string
;
7702 else if (system_status
.BatteryFlag
& 8)
7704 battery_status
= build_string ("charging");
7705 battery_status_symbol
= build_string ("+");
7706 if (system_status
.BatteryFullLifeTime
!= -1L)
7707 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
7709 else if (system_status
.BatteryFlag
& 4)
7711 battery_status
= build_string ("critical");
7712 battery_status_symbol
= build_string ("!");
7714 else if (system_status
.BatteryFlag
& 2)
7716 battery_status
= build_string ("low");
7717 battery_status_symbol
= build_string ("-");
7719 else if (system_status
.BatteryFlag
& 1)
7721 battery_status
= build_string ("high");
7722 battery_status_symbol
= empty_unibyte_string
;
7726 battery_status
= build_string ("medium");
7727 battery_status_symbol
= empty_unibyte_string
;
7730 if (system_status
.BatteryLifePercent
> 100)
7731 load_percentage
= build_string ("N/A");
7735 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
7736 load_percentage
= build_string (buffer
);
7739 if (seconds_left
< 0)
7740 seconds
= minutes
= hours
= remain
= build_string ("N/A");
7746 snprintf (buffer
, 16, "%ld", seconds_left
);
7747 seconds
= build_string (buffer
);
7749 m
= seconds_left
/ 60;
7750 snprintf (buffer
, 16, "%ld", m
);
7751 minutes
= build_string (buffer
);
7753 h
= seconds_left
/ 3600.0;
7754 snprintf (buffer
, 16, "%3.1f", h
);
7755 hours
= build_string (buffer
);
7757 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
7758 remain
= build_string (buffer
);
7761 status
= listn (CONSTYPE_HEAP
, 8,
7762 Fcons (make_number ('L'), line_status
),
7763 Fcons (make_number ('B'), battery_status
),
7764 Fcons (make_number ('b'), battery_status_symbol
),
7765 Fcons (make_number ('p'), load_percentage
),
7766 Fcons (make_number ('s'), seconds
),
7767 Fcons (make_number ('m'), minutes
),
7768 Fcons (make_number ('h'), hours
),
7769 Fcons (make_number ('t'), remain
));
7776 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
7777 doc
: /* Return storage information about the file system FILENAME is on.
7778 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
7779 storage of the file system, FREE is the free storage, and AVAIL is the
7780 storage available to a non-superuser. All 3 numbers are in bytes.
7781 If the underlying system call fails, value is nil. */)
7782 (Lisp_Object filename
)
7784 Lisp_Object encoded
, value
;
7786 CHECK_STRING (filename
);
7787 filename
= Fexpand_file_name (filename
, Qnil
);
7788 encoded
= ENCODE_FILE (filename
);
7792 /* Determining the required information on Windows turns out, sadly,
7793 to be more involved than one would hope. The original Windows API
7794 call for this will return bogus information on some systems, but we
7795 must dynamically probe for the replacement api, since that was
7796 added rather late on. */
7798 HMODULE hKernel
= GetModuleHandle ("kernel32");
7799 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExW
)
7800 (wchar_t *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7801 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExW");
7802 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExA
)
7803 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7804 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExA");
7805 bool have_pfn_GetDiskFreeSpaceEx
=
7806 ((w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExW
)
7807 || (!w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExA
));
7809 /* On Windows, we may need to specify the root directory of the
7810 volume holding FILENAME. */
7811 char rootname
[MAX_UTF8_PATH
];
7812 wchar_t rootname_w
[MAX_PATH
];
7813 char rootname_a
[MAX_PATH
];
7814 char *name
= SDATA (encoded
);
7817 /* find the root name of the volume if given */
7818 if (isalpha (name
[0]) && name
[1] == ':')
7820 rootname
[0] = name
[0];
7821 rootname
[1] = name
[1];
7825 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
7827 char *str
= rootname
;
7831 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
7841 if (w32_unicode_filenames
)
7842 filename_to_utf16 (rootname
, rootname_w
);
7844 filename_to_ansi (rootname
, rootname_a
);
7846 if (have_pfn_GetDiskFreeSpaceEx
)
7848 /* Unsigned large integers cannot be cast to double, so
7849 use signed ones instead. */
7850 LARGE_INTEGER availbytes
;
7851 LARGE_INTEGER freebytes
;
7852 LARGE_INTEGER totalbytes
;
7854 if (w32_unicode_filenames
)
7855 result
= pfn_GetDiskFreeSpaceExW (rootname_w
,
7856 (ULARGE_INTEGER
*)&availbytes
,
7857 (ULARGE_INTEGER
*)&totalbytes
,
7858 (ULARGE_INTEGER
*)&freebytes
);
7860 result
= pfn_GetDiskFreeSpaceExA (rootname_a
,
7861 (ULARGE_INTEGER
*)&availbytes
,
7862 (ULARGE_INTEGER
*)&totalbytes
,
7863 (ULARGE_INTEGER
*)&freebytes
);
7865 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
7866 make_float ((double) freebytes
.QuadPart
),
7867 make_float ((double) availbytes
.QuadPart
));
7871 DWORD sectors_per_cluster
;
7872 DWORD bytes_per_sector
;
7873 DWORD free_clusters
;
7874 DWORD total_clusters
;
7876 if (w32_unicode_filenames
)
7877 result
= GetDiskFreeSpaceW (rootname_w
,
7878 §ors_per_cluster
,
7883 result
= GetDiskFreeSpaceA (rootname_a
,
7884 §ors_per_cluster
,
7889 value
= list3 (make_float ((double) total_clusters
7890 * sectors_per_cluster
* bytes_per_sector
),
7891 make_float ((double) free_clusters
7892 * sectors_per_cluster
* bytes_per_sector
),
7893 make_float ((double) free_clusters
7894 * sectors_per_cluster
* bytes_per_sector
));
7900 #endif /* WINDOWSNT */
7904 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
7905 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
7908 static char pname_buf
[256];
7911 PRINTER_INFO_2W
*ppi2w
= NULL
;
7912 PRINTER_INFO_2A
*ppi2a
= NULL
;
7913 DWORD dwNeeded
= 0, dwReturned
= 0;
7914 char server_name
[MAX_UTF8_PATH
], share_name
[MAX_UTF8_PATH
];
7915 char port_name
[MAX_UTF8_PATH
];
7917 /* Retrieve the default string from Win.ini (the registry).
7918 * String will be in form "printername,drivername,portname".
7919 * This is the most portable way to get the default printer. */
7920 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
7922 /* printername precedes first "," character */
7923 strtok (pname_buf
, ",");
7924 /* We want to know more than the printer name */
7925 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
7927 /* GetPrinterW is not supported by unicows.dll. */
7928 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7929 GetPrinterW (hPrn
, 2, NULL
, 0, &dwNeeded
);
7931 GetPrinterA (hPrn
, 2, NULL
, 0, &dwNeeded
);
7934 ClosePrinter (hPrn
);
7937 /* Call GetPrinter again with big enough memory block. */
7938 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7940 /* Allocate memory for the PRINTER_INFO_2 struct. */
7941 ppi2w
= xmalloc (dwNeeded
);
7942 err
= GetPrinterW (hPrn
, 2, (LPBYTE
)ppi2w
, dwNeeded
, &dwReturned
);
7943 ClosePrinter (hPrn
);
7950 if ((ppi2w
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7951 && ppi2w
->pServerName
)
7953 filename_from_utf16 (ppi2w
->pServerName
, server_name
);
7954 filename_from_utf16 (ppi2w
->pShareName
, share_name
);
7958 server_name
[0] = '\0';
7959 filename_from_utf16 (ppi2w
->pPortName
, port_name
);
7964 ppi2a
= xmalloc (dwNeeded
);
7965 err
= GetPrinterA (hPrn
, 2, (LPBYTE
)ppi2a
, dwNeeded
, &dwReturned
);
7966 ClosePrinter (hPrn
);
7973 if ((ppi2a
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7974 && ppi2a
->pServerName
)
7976 filename_from_ansi (ppi2a
->pServerName
, server_name
);
7977 filename_from_ansi (ppi2a
->pShareName
, share_name
);
7981 server_name
[0] = '\0';
7982 filename_from_ansi (ppi2a
->pPortName
, port_name
);
7988 /* a remote printer */
7989 if (server_name
[0] == '\\')
7990 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", server_name
,
7993 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", server_name
,
7995 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7999 /* a local printer */
8000 strncpy (pname_buf
, port_name
, sizeof (pname_buf
));
8001 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
8002 /* `pPortName' can include several ports, delimited by ','.
8003 * we only use the first one. */
8004 strtok (pname_buf
, ",");
8007 return DECODE_FILE (build_unibyte_string (pname_buf
));
8009 #endif /* WINDOWSNT */
8012 /* Equivalent of strerror for W32 error codes. */
8014 w32_strerror (int error_no
)
8016 static char buf
[500];
8020 error_no
= GetLastError ();
8022 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
8023 FORMAT_MESSAGE_IGNORE_INSERTS
,
8026 0, /* choose most suitable language */
8027 buf
, sizeof (buf
), NULL
);
8029 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
8030 buf
[ret
- 1] == '\r' ))
8034 sprintf (buf
, "w32 error %u", error_no
);
8039 /* For convenience when debugging. (You cannot call GetLastError
8040 directly from GDB: it will crash, because it uses the __stdcall
8041 calling convention, not the _cdecl convention assumed by GDB.) */
8043 w32_last_error (void)
8045 return GetLastError ();
8048 /* Cache information describing the NT system for later use. */
8050 cache_system_info (void)
8063 /* Cache the module handle of Emacs itself. */
8064 hinst
= GetModuleHandle (NULL
);
8066 /* Cache the version of the operating system. */
8067 version
.data
= GetVersion ();
8068 w32_major_version
= version
.info
.major
;
8069 w32_minor_version
= version
.info
.minor
;
8071 if (version
.info
.platform
& 0x8000)
8076 /* Cache page size, allocation unit, processor type, etc. */
8077 GetSystemInfo (&sysinfo_cache
);
8078 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
8080 /* Cache os info. */
8081 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
8082 GetVersionEx (&osinfo_cache
);
8084 w32_build_number
= osinfo_cache
.dwBuildNumber
;
8085 if (os_subtype
== OS_9X
)
8086 w32_build_number
&= 0xffff;
8088 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
8093 _DebPrint (const char *fmt
, ...)
8098 va_start (args
, fmt
);
8099 vsprintf (buf
, fmt
, args
);
8102 fprintf (stderr
, "%s", buf
);
8104 OutputDebugString (buf
);
8109 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
8111 int cur_state
= (GetKeyState (vk_code
) & 1);
8113 if (NILP (new_state
)
8114 || (NUMBERP (new_state
)
8115 && ((XUINT (new_state
)) & 1) != cur_state
))
8118 faked_key
= vk_code
;
8119 #endif /* WINDOWSNT */
8121 keybd_event ((BYTE
) vk_code
,
8122 (BYTE
) MapVirtualKey (vk_code
, 0),
8123 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8124 keybd_event ((BYTE
) vk_code
,
8125 (BYTE
) MapVirtualKey (vk_code
, 0),
8126 KEYEVENTF_EXTENDEDKEY
| 0, 0);
8127 keybd_event ((BYTE
) vk_code
,
8128 (BYTE
) MapVirtualKey (vk_code
, 0),
8129 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8130 cur_state
= !cur_state
;
8136 /* Translate console modifiers to emacs modifiers.
8137 German keyboard support (Kai Morgan Zeise 2/18/95). */
8139 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
8143 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
8144 pressed, first remove those modifiers. */
8145 if (!NILP (Vw32_recognize_altgr
)
8146 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8147 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8148 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
8150 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
8151 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
8153 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8155 retval
|= ctrl_modifier
;
8156 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8157 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8158 retval
|= meta_modifier
;
8161 if (mods
& LEFT_WIN_PRESSED
)
8162 retval
|= w32_key_to_modifier (VK_LWIN
);
8163 if (mods
& RIGHT_WIN_PRESSED
)
8164 retval
|= w32_key_to_modifier (VK_RWIN
);
8165 if (mods
& APPS_PRESSED
)
8166 retval
|= w32_key_to_modifier (VK_APPS
);
8167 if (mods
& SCROLLLOCK_ON
)
8168 retval
|= w32_key_to_modifier (VK_SCROLL
);
8170 /* Just in case someone wanted the original behavior, make it
8171 optional by setting w32-capslock-is-shiftlock to t. */
8172 if (NILP (Vw32_capslock_is_shiftlock
)
8173 /* Keys that should _not_ be affected by CapsLock. */
8174 && ( (key
== VK_BACK
)
8176 || (key
== VK_CLEAR
)
8177 || (key
== VK_RETURN
)
8178 || (key
== VK_ESCAPE
)
8179 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
8180 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
8181 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
8184 /* Only consider shift state. */
8185 if ((mods
& SHIFT_PRESSED
) != 0)
8186 retval
|= shift_modifier
;
8190 /* Ignore CapsLock state if not enabled. */
8191 if (NILP (Vw32_enable_caps_lock
))
8192 mods
&= ~CAPSLOCK_ON
;
8193 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
8194 retval
|= shift_modifier
;
8200 /* The return code indicates key code size. cpID is the codepage to
8201 use for translation to Unicode; -1 means use the current console
8204 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
8206 unsigned int key_code
= event
->wVirtualKeyCode
;
8207 unsigned int mods
= event
->dwControlKeyState
;
8209 static BYTE ansi_code
[4];
8210 static int isdead
= 0;
8214 event
->uChar
.AsciiChar
= ansi_code
[2];
8218 if (event
->uChar
.AsciiChar
!= 0)
8221 memset (keystate
, 0, sizeof (keystate
));
8222 keystate
[key_code
] = 0x80;
8223 if (mods
& SHIFT_PRESSED
)
8224 keystate
[VK_SHIFT
] = 0x80;
8225 if (mods
& CAPSLOCK_ON
)
8226 keystate
[VK_CAPITAL
] = 1;
8227 /* If we recognize right-alt and left-ctrl as AltGr, set the key
8228 states accordingly before invoking ToAscii. */
8229 if (!NILP (Vw32_recognize_altgr
)
8230 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
8232 keystate
[VK_CONTROL
] = 0x80;
8233 keystate
[VK_LCONTROL
] = 0x80;
8234 keystate
[VK_MENU
] = 0x80;
8235 keystate
[VK_RMENU
] = 0x80;
8239 /* Because of an OS bug, ToAscii corrupts the stack when called to
8240 convert a dead key in console mode on NT4. Unfortunately, trying
8241 to check for dead keys using MapVirtualKey doesn't work either -
8242 these functions apparently use internal information about keyboard
8243 layout which doesn't get properly updated in console programs when
8244 changing layout (though apparently it gets partly updated,
8245 otherwise ToAscii wouldn't crash). */
8246 if (is_dead_key (event
->wVirtualKeyCode
))
8250 /* On NT, call ToUnicode instead and then convert to the current
8251 console input codepage. */
8252 if (os_subtype
== OS_NT
)
8256 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8257 keystate
, buf
, 128, 0);
8260 /* When we are called from the GUI message processing code,
8261 we are passed the current keyboard codepage, a positive
8262 number, to use below. */
8264 cpId
= GetConsoleCP ();
8266 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
8267 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
8268 ansi_code
, 4, NULL
, NULL
);
8275 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8276 keystate
, (LPWORD
) ansi_code
, 0);
8281 event
->uChar
.AsciiChar
= ansi_code
[0];
8287 w32_sys_ring_bell (struct frame
*f
)
8289 if (sound_type
== 0xFFFFFFFF)
8293 else if (sound_type
== MB_EMACS_SILENT
)
8298 MessageBeep (sound_type
);
8301 DEFUN ("w32--menu-bar-in-use", Fw32__menu_bar_in_use
, Sw32__menu_bar_in_use
,
8303 doc
: /* Return non-nil when a menu-bar menu is being used.
8304 Internal use only. */)
8307 return menubar_in_use
? Qt
: Qnil
;
8311 /***********************************************************************
8313 ***********************************************************************/
8315 /* Keep this list in the same order as frame_parms in frame.c.
8316 Use 0 for unsupported frame parameters. */
8318 frame_parm_handler w32_frame_parm_handlers
[] =
8322 x_set_background_color
,
8328 x_set_foreground_color
,
8331 x_set_internal_border_width
,
8332 x_set_right_divider_width
,
8333 x_set_bottom_divider_width
,
8334 x_set_menu_bar_lines
,
8336 x_explicitly_set_name
,
8337 x_set_scroll_bar_width
,
8338 x_set_scroll_bar_height
,
8341 x_set_vertical_scroll_bars
,
8342 x_set_horizontal_scroll_bars
,
8344 x_set_tool_bar_lines
,
8345 0, /* x_set_scroll_bar_foreground, */
8346 0, /* x_set_scroll_bar_background, */
8351 0, /* x_set_wait_for_wm, */
8355 0, /* x_set_sticky */
8356 0, /* x_set_tool_bar_position */
8360 syms_of_w32fns (void)
8362 globals_of_w32fns ();
8363 track_mouse_window
= NULL
;
8365 w32_visible_system_caret_hwnd
= NULL
;
8367 DEFSYM (Qundefined_color
, "undefined-color");
8368 DEFSYM (Qcancel_timer
, "cancel-timer");
8369 DEFSYM (Qhyper
, "hyper");
8370 DEFSYM (Qsuper
, "super");
8371 DEFSYM (Qmeta
, "meta");
8372 DEFSYM (Qalt
, "alt");
8373 DEFSYM (Qctrl
, "ctrl");
8374 DEFSYM (Qcontrol
, "control");
8375 DEFSYM (Qshift
, "shift");
8376 DEFSYM (Qfont_param
, "font-parameter");
8377 DEFSYM (Qgeometry
, "geometry");
8378 DEFSYM (Qworkarea
, "workarea");
8379 DEFSYM (Qmm_size
, "mm-size");
8380 DEFSYM (Qframes
, "frames");
8381 DEFSYM (Qtip_frame
, "tip-frame");
8382 DEFSYM (Qunicode_sip
, "unicode-sip");
8384 /* Symbols used elsewhere, but only in MS-Windows-specific code. */
8385 DEFSYM (Qgnutls_dll
, "gnutls");
8386 DEFSYM (Qlibxml2_dll
, "libxml2");
8387 DEFSYM (Qserif
, "serif");
8388 DEFSYM (Qzlib_dll
, "zlib");
8390 Fput (Qundefined_color
, Qerror_conditions
,
8391 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
8392 Fput (Qundefined_color
, Qerror_message
,
8393 build_pure_c_string ("Undefined color"));
8395 staticpro (&w32_grabbed_keys
);
8396 w32_grabbed_keys
= Qnil
;
8398 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
8399 doc
: /* An array of color name mappings for Windows. */);
8400 Vw32_color_map
= Qnil
;
8402 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
8403 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8404 When non-nil, for example, Alt pressed and released and then space will
8405 open the System menu. When nil, Emacs processes the Alt key events, and
8406 then silently swallows them. */);
8407 Vw32_pass_alt_to_system
= Qnil
;
8409 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
8410 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8411 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8412 Vw32_alt_is_meta
= Qt
;
8414 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
8415 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8418 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8419 Vw32_pass_lwindow_to_system
,
8420 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8422 When non-nil, the Start menu is opened by tapping the key.
8423 If you set this to nil, the left \"Windows\" key is processed by Emacs
8424 according to the value of `w32-lwindow-modifier', which see.
8426 Note that some combinations of the left \"Windows\" key with other keys are
8427 caught by Windows at low level, and so binding them in Emacs will have no
8428 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8429 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8430 the doc string of `w32-phantom-key-code'. */);
8431 Vw32_pass_lwindow_to_system
= Qt
;
8433 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8434 Vw32_pass_rwindow_to_system
,
8435 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8437 When non-nil, the Start menu is opened by tapping the key.
8438 If you set this to nil, the right \"Windows\" key is processed by Emacs
8439 according to the value of `w32-rwindow-modifier', which see.
8441 Note that some combinations of the right \"Windows\" key with other keys are
8442 caught by Windows at low level, and so binding them in Emacs will have no
8443 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8444 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8445 the doc string of `w32-phantom-key-code'. */);
8446 Vw32_pass_rwindow_to_system
= Qt
;
8448 DEFVAR_LISP ("w32-phantom-key-code",
8449 Vw32_phantom_key_code
,
8450 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8451 Value is a number between 0 and 255.
8453 Phantom key presses are generated in order to stop the system from
8454 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8455 `w32-pass-rwindow-to-system' is nil. */);
8456 /* Although 255 is technically not a valid key code, it works and
8457 means that this hack won't interfere with any real key code. */
8458 XSETINT (Vw32_phantom_key_code
, 255);
8460 DEFVAR_LISP ("w32-enable-num-lock",
8461 Vw32_enable_num_lock
,
8462 doc
: /* If non-nil, the Num Lock key acts normally.
8463 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8464 Vw32_enable_num_lock
= Qt
;
8466 DEFVAR_LISP ("w32-enable-caps-lock",
8467 Vw32_enable_caps_lock
,
8468 doc
: /* If non-nil, the Caps Lock key acts normally.
8469 Set to nil to handle Caps Lock as the `capslock' key. */);
8470 Vw32_enable_caps_lock
= Qt
;
8472 DEFVAR_LISP ("w32-scroll-lock-modifier",
8473 Vw32_scroll_lock_modifier
,
8474 doc
: /* Modifier to use for the Scroll Lock ON state.
8475 The value can be hyper, super, meta, alt, control or shift for the
8476 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8477 Any other value will cause the Scroll Lock key to be ignored. */);
8478 Vw32_scroll_lock_modifier
= Qnil
;
8480 DEFVAR_LISP ("w32-lwindow-modifier",
8481 Vw32_lwindow_modifier
,
8482 doc
: /* Modifier to use for the left \"Windows\" key.
8483 The value can be hyper, super, meta, alt, control or shift for the
8484 respective modifier, or nil to appear as the `lwindow' key.
8485 Any other value will cause the key to be ignored. */);
8486 Vw32_lwindow_modifier
= Qnil
;
8488 DEFVAR_LISP ("w32-rwindow-modifier",
8489 Vw32_rwindow_modifier
,
8490 doc
: /* Modifier to use for the right \"Windows\" key.
8491 The value can be hyper, super, meta, alt, control or shift for the
8492 respective modifier, or nil to appear as the `rwindow' key.
8493 Any other value will cause the key to be ignored. */);
8494 Vw32_rwindow_modifier
= Qnil
;
8496 DEFVAR_LISP ("w32-apps-modifier",
8498 doc
: /* Modifier to use for the \"Apps\" key.
8499 The value can be hyper, super, meta, alt, control or shift for the
8500 respective modifier, or nil to appear as the `apps' key.
8501 Any other value will cause the key to be ignored. */);
8502 Vw32_apps_modifier
= Qnil
;
8504 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
8505 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8506 w32_enable_synthesized_fonts
= 0;
8508 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
8509 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8510 Vw32_enable_palette
= Qt
;
8512 DEFVAR_INT ("w32-mouse-button-tolerance",
8513 w32_mouse_button_tolerance
,
8514 doc
: /* Analogue of double click interval for faking middle mouse events.
8515 The value is the minimum time in milliseconds that must elapse between
8516 left and right button down events before they are considered distinct events.
8517 If both mouse buttons are depressed within this interval, a middle mouse
8518 button down event is generated instead. */);
8519 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8521 DEFVAR_INT ("w32-mouse-move-interval",
8522 w32_mouse_move_interval
,
8523 doc
: /* Minimum interval between mouse move events.
8524 The value is the minimum time in milliseconds that must elapse between
8525 successive mouse move (or scroll bar drag) events before they are
8526 reported as lisp events. */);
8527 w32_mouse_move_interval
= 0;
8529 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8530 w32_pass_extra_mouse_buttons_to_system
,
8531 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8532 Recent versions of Windows support mice with up to five buttons.
8533 Since most applications don't support these extra buttons, most mouse
8534 drivers will allow you to map them to functions at the system level.
8535 If this variable is non-nil, Emacs will pass them on, allowing the
8536 system to handle them. */);
8537 w32_pass_extra_mouse_buttons_to_system
= 0;
8539 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
8540 w32_pass_multimedia_buttons_to_system
,
8541 doc
: /* If non-nil, media buttons are passed to Windows.
8542 Some modern keyboards contain buttons for controlling media players, web
8543 browsers and other applications. Generally these buttons are handled on a
8544 system wide basis, but by setting this to nil they are made available
8545 to Emacs for binding. Depending on your keyboard, additional keys that
8546 may be available are:
8548 browser-back, browser-forward, browser-refresh, browser-stop,
8549 browser-search, browser-favorites, browser-home,
8550 mail, mail-reply, mail-forward, mail-send,
8552 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
8553 spell-check, correction-list, toggle-dictate-command,
8554 media-next, media-previous, media-stop, media-play-pause, media-select,
8555 media-play, media-pause, media-record, media-fast-forward, media-rewind,
8556 media-channel-up, media-channel-down,
8557 volume-mute, volume-up, volume-down,
8558 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
8559 bass-down, bass-boost, bass-up, treble-down, treble-up */);
8560 w32_pass_multimedia_buttons_to_system
= 1;
8562 #if 0 /* TODO: Mouse cursor customization. */
8563 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
8564 doc
: /* The shape of the pointer when over text.
8565 Changing the value does not affect existing frames
8566 unless you set the mouse color. */);
8567 Vx_pointer_shape
= Qnil
;
8569 Vx_nontext_pointer_shape
= Qnil
;
8571 Vx_mode_pointer_shape
= Qnil
;
8573 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
8574 doc
: /* The shape of the pointer when Emacs is busy.
8575 This variable takes effect when you create a new frame
8576 or when you set the mouse color. */);
8577 Vx_hourglass_pointer_shape
= Qnil
;
8579 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8580 Vx_sensitive_text_pointer_shape
,
8581 doc
: /* The shape of the pointer when over mouse-sensitive text.
8582 This variable takes effect when you create a new frame
8583 or when you set the mouse color. */);
8584 Vx_sensitive_text_pointer_shape
= Qnil
;
8586 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8587 Vx_window_horizontal_drag_shape
,
8588 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8589 This variable takes effect when you create a new frame
8590 or when you set the mouse color. */);
8591 Vx_window_horizontal_drag_shape
= Qnil
;
8593 DEFVAR_LISP ("x-window-vertical-drag-cursor",
8594 Vx_window_vertical_drag_shape
,
8595 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
8596 This variable takes effect when you create a new frame
8597 or when you set the mouse color. */);
8598 Vx_window_vertical_drag_shape
= Qnil
;
8601 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
8602 doc
: /* A string indicating the foreground color of the cursor box. */);
8603 Vx_cursor_fore_pixel
= Qnil
;
8605 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
8606 doc
: /* Maximum size for tooltips.
8607 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8608 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8610 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
8611 doc
: /* Non-nil if no window manager is in use.
8612 Emacs doesn't try to figure this out; this is always nil
8613 unless you set it to something else. */);
8614 /* We don't have any way to find this out, so set it to nil
8615 and maybe the user would like to set it to t. */
8616 Vx_no_window_manager
= Qnil
;
8618 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8619 Vx_pixel_size_width_font_regexp
,
8620 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8622 Since Emacs gets width of a font matching with this regexp from
8623 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8624 such a font. This is especially effective for such large fonts as
8625 Chinese, Japanese, and Korean. */);
8626 Vx_pixel_size_width_font_regexp
= Qnil
;
8628 DEFVAR_LISP ("w32-bdf-filename-alist",
8629 Vw32_bdf_filename_alist
,
8630 doc
: /* List of bdf fonts and their corresponding filenames. */);
8631 Vw32_bdf_filename_alist
= Qnil
;
8633 DEFVAR_BOOL ("w32-strict-fontnames",
8634 w32_strict_fontnames
,
8635 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8636 Default is nil, which allows old fontnames that are not XLFD compliant,
8637 and allows third-party CJK display to work by specifying false charset
8638 fields to trick Emacs into translating to Big5, SJIS etc.
8639 Setting this to t will prevent wrong fonts being selected when
8640 fontsets are automatically created. */);
8641 w32_strict_fontnames
= 0;
8643 DEFVAR_BOOL ("w32-strict-painting",
8644 w32_strict_painting
,
8645 doc
: /* Non-nil means use strict rules for repainting frames.
8646 Set this to nil to get the old behavior for repainting; this should
8647 only be necessary if the default setting causes problems. */);
8648 w32_strict_painting
= 1;
8650 #if 0 /* TODO: Port to W32 */
8651 defsubr (&Sx_change_window_property
);
8652 defsubr (&Sx_delete_window_property
);
8653 defsubr (&Sx_window_property
);
8655 defsubr (&Sxw_display_color_p
);
8656 defsubr (&Sx_display_grayscale_p
);
8657 defsubr (&Sxw_color_defined_p
);
8658 defsubr (&Sxw_color_values
);
8659 defsubr (&Sx_server_max_request_size
);
8660 defsubr (&Sx_server_vendor
);
8661 defsubr (&Sx_server_version
);
8662 defsubr (&Sx_display_pixel_width
);
8663 defsubr (&Sx_display_pixel_height
);
8664 defsubr (&Sx_display_mm_width
);
8665 defsubr (&Sx_display_mm_height
);
8666 defsubr (&Sx_display_screens
);
8667 defsubr (&Sx_display_planes
);
8668 defsubr (&Sx_display_color_cells
);
8669 defsubr (&Sx_display_visual_class
);
8670 defsubr (&Sx_display_backing_store
);
8671 defsubr (&Sx_display_save_under
);
8672 defsubr (&Sx_create_frame
);
8673 defsubr (&Sx_open_connection
);
8674 defsubr (&Sx_close_connection
);
8675 defsubr (&Sx_display_list
);
8676 defsubr (&Sx_frame_geometry
);
8677 defsubr (&Sx_synchronize
);
8679 /* W32 specific functions */
8681 defsubr (&Sw32_define_rgb_color
);
8682 defsubr (&Sw32_default_color_map
);
8683 defsubr (&Sw32_display_monitor_attributes_list
);
8684 defsubr (&Sw32_send_sys_command
);
8685 defsubr (&Sw32_shell_execute
);
8686 defsubr (&Sw32_register_hot_key
);
8687 defsubr (&Sw32_unregister_hot_key
);
8688 defsubr (&Sw32_registered_hot_keys
);
8689 defsubr (&Sw32_reconstruct_hot_key
);
8690 defsubr (&Sw32_toggle_lock_key
);
8691 defsubr (&Sw32_window_exists_p
);
8692 defsubr (&Sw32_frame_rect
);
8693 defsubr (&Sw32_frame_menu_bar_size
);
8694 defsubr (&Sw32_battery_status
);
8695 defsubr (&Sw32__menu_bar_in_use
);
8698 defsubr (&Sfile_system_info
);
8699 defsubr (&Sdefault_printer_name
);
8702 defsubr (&Sset_message_beep
);
8703 defsubr (&Sx_show_tip
);
8704 defsubr (&Sx_hide_tip
);
8706 staticpro (&tip_timer
);
8708 staticpro (&tip_frame
);
8710 last_show_tip_args
= Qnil
;
8711 staticpro (&last_show_tip_args
);
8713 defsubr (&Sx_file_dialog
);
8715 defsubr (&Ssystem_move_file_to_trash
);
8721 /* Crashing and reporting backtrace. */
8724 static LONG CALLBACK
my_exception_handler (EXCEPTION_POINTERS
*);
8725 static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_handler
;
8727 static DWORD except_code
;
8728 static PVOID except_addr
;
8731 /* This handler records the exception code and the address where it
8732 was triggered so that this info could be included in the backtrace.
8733 Without that, the backtrace in some cases has no information
8734 whatsoever about the offending code, and looks as if the top-level
8735 exception handler in the MinGW startup code di the one that
8737 static LONG CALLBACK
8738 my_exception_handler (EXCEPTION_POINTERS
* exception_data
)
8740 except_code
= exception_data
->ExceptionRecord
->ExceptionCode
;
8741 except_addr
= exception_data
->ExceptionRecord
->ExceptionAddress
;
8743 if (prev_exception_handler
)
8744 return prev_exception_handler (exception_data
);
8745 return EXCEPTION_EXECUTE_HANDLER
;
8749 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
8752 #define BACKTRACE_LIMIT_MAX 62
8755 w32_backtrace (void **buffer
, int limit
)
8757 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
8758 HMODULE hm_kernel32
= NULL
;
8760 if (!s_pfn_CaptureStackBackTrace
)
8762 hm_kernel32
= LoadLibrary ("Kernel32.dll");
8763 s_pfn_CaptureStackBackTrace
=
8764 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
8765 "RtlCaptureStackBackTrace");
8767 if (s_pfn_CaptureStackBackTrace
)
8768 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
8777 button
= MessageBox (NULL
,
8778 "A fatal error has occurred!\n\n"
8779 "Would you like to attach a debugger?\n\n"
8781 "YES -- to debug Emacs, or\n"
8782 "NO -- to abort Emacs and produce a backtrace\n"
8783 " (emacs_backtrace.txt in current directory)."
8785 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
8786 "\"continue\" inside GDB before clicking YES.)"
8788 , "Emacs Abort Dialog",
8789 MB_ICONEXCLAMATION
| MB_TASKMODAL
8790 | MB_SETFOREGROUND
| MB_YESNO
);
8795 exit (2); /* tell the compiler we will never return */
8799 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
8800 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
8804 int errfile_fd
= -1;
8806 char buf
[sizeof ("\r\nException at this address:\r\n\r\n")
8807 /* The type below should really be 'void *', but
8808 INT_BUFSIZE_BOUND cannot handle that without
8809 triggering compiler warnings (under certain
8810 pedantic warning switches), it wants an
8812 + 2 * INT_BUFSIZE_BOUND (intptr_t)];
8816 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
8819 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
8820 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
8823 /* We use %p, not 0x%p, as %p produces a leading "0x" on XP,
8824 but not on Windows 7. addr2line doesn't mind a missing
8825 "0x", but will be confused by an extra one. */
8827 sprintf (buf
, "\r\nException 0x%lx at this address:\r\n%p\r\n",
8828 except_code
, except_addr
);
8832 write (stderr_fd
, buf
, strlen (buf
));
8833 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
8838 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
8839 if (errfile_fd
>= 0)
8841 lseek (errfile_fd
, 0L, SEEK_END
);
8843 write (errfile_fd
, buf
, strlen (buf
));
8844 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
8847 for (j
= 0; j
< i
; j
++)
8849 /* stack[] gives the return addresses, whereas we want
8850 the address of the call, so decrease each address
8851 by approximate size of 1 CALL instruction. */
8852 sprintf (buf
, "%p\r\n", (char *)stack
[j
] - sizeof(void *));
8854 write (stderr_fd
, buf
, strlen (buf
));
8855 if (errfile_fd
>= 0)
8856 write (errfile_fd
, buf
, strlen (buf
));
8858 if (i
== BACKTRACE_LIMIT_MAX
)
8861 write (stderr_fd
, "...\r\n", 5);
8862 if (errfile_fd
>= 0)
8863 write (errfile_fd
, "...\r\n", 5);
8865 if (errfile_fd
>= 0)
8876 /* Initialization. */
8879 globals_of_w32fns is used to initialize those global variables that
8880 must always be initialized on startup even when the global variable
8881 initialized is non zero (see the function main in emacs.c).
8882 globals_of_w32fns is called from syms_of_w32fns when the global
8883 variable initialized is 0 and directly from main when initialized
8887 globals_of_w32fns (void)
8889 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8891 TrackMouseEvent not available in all versions of Windows, so must load
8892 it dynamically. Do it once, here, instead of every time it is used.
8894 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8895 GetProcAddress (user32_lib
, "TrackMouseEvent");
8897 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
8898 GetProcAddress (user32_lib
, "MonitorFromPoint");
8899 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
8900 GetProcAddress (user32_lib
, "GetMonitorInfoA");
8901 monitor_from_window_fn
= (MonitorFromWindow_Proc
)
8902 GetProcAddress (user32_lib
, "MonitorFromWindow");
8903 enum_display_monitors_fn
= (EnumDisplayMonitors_Proc
)
8904 GetProcAddress (user32_lib
, "EnumDisplayMonitors");
8907 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
8908 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
8909 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
8910 get_ime_context_fn
= (ImmGetContext_Proc
)
8911 GetProcAddress (imm32_lib
, "ImmGetContext");
8912 release_ime_context_fn
= (ImmReleaseContext_Proc
)
8913 GetProcAddress (imm32_lib
, "ImmReleaseContext");
8914 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
8915 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
8921 prev_exception_handler
= SetUnhandledExceptionFilter (my_exception_handler
);
8924 DEFVAR_INT ("w32-ansi-code-page",
8926 doc
: /* The ANSI code page used by the system. */);
8927 w32_ansi_code_page
= GetACP ();
8929 if (os_subtype
== OS_NT
)
8930 w32_unicode_gui
= 1;
8932 w32_unicode_gui
= 0;
8934 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
8935 InitCommonControls ();
8937 syms_of_w32uniscribe ();
8940 #ifdef NTGUI_UNICODE
8943 ntgui_encode_system (Lisp_Object str
)
8945 Lisp_Object encoded
;
8946 to_unicode (str
, &encoded
);
8950 #endif /* NTGUI_UNICODE */