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 */
36 #include "character.h"
38 #include "intervals.h"
39 #include "dispextern.h"
41 #include "blockinput.h"
48 #include "termhooks.h"
50 #include "w32common.h"
55 #endif /* WINDOWSNT */
63 #include "bitmaps/gray.xbm"
78 #ifndef FOF_NO_CONNECTED_ELEMENTS
79 #define FOF_NO_CONNECTED_ELEMENTS 0x2000
82 void syms_of_w32fns (void);
83 void globals_of_w32fns (void);
85 extern void free_frame_menubar (struct frame
*);
86 extern int w32_console_toggle_lock_key (int, Lisp_Object
);
87 extern void w32_menu_display_help (HWND
, HMENU
, UINT
, UINT
);
88 extern void w32_free_menu_strings (HWND
);
89 extern const char *map_w32_filename (const char *, const char **);
90 extern char * w32_strerror (int error_no
);
93 #define IDC_HAND MAKEINTRESOURCE(32649)
96 /* Prefix for system colors. */
97 #define SYSTEM_COLOR_PREFIX "System"
98 #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1)
100 /* State variables for emulating a three button mouse. */
105 static int button_state
= 0;
106 static W32Msg saved_mouse_button_msg
;
107 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
108 static W32Msg saved_mouse_move_msg
;
109 static unsigned mouse_move_timer
= 0;
111 /* Window that is tracking the mouse. */
112 static HWND track_mouse_window
;
114 /* Multi-monitor API definitions that are not pulled from the headers
115 since we are compiling for NT 4. */
116 #ifndef MONITOR_DEFAULT_TO_NEAREST
117 #define MONITOR_DEFAULT_TO_NEAREST 2
119 #ifndef MONITORINFOF_PRIMARY
120 #define MONITORINFOF_PRIMARY 1
122 #ifndef SM_XVIRTUALSCREEN
123 #define SM_XVIRTUALSCREEN 76
125 #ifndef SM_YVIRTUALSCREEN
126 #define SM_YVIRTUALSCREEN 77
128 /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't.
129 To avoid a compile error on one or the other, redefine with a new name. */
138 #ifndef CCHDEVICENAME
139 #define CCHDEVICENAME 32
141 struct MONITOR_INFO_EX
147 char szDevice
[CCHDEVICENAME
];
150 /* Reportedly, MSVC does not have this in its headers. */
151 #if defined (_MSC_VER) && _WIN32_WINNT < 0x0500
152 DECLARE_HANDLE(HMONITOR
);
155 typedef BOOL (WINAPI
* TrackMouseEvent_Proc
)
156 (IN OUT LPTRACKMOUSEEVENT lpEventTrack
);
157 typedef LONG (WINAPI
* ImmGetCompositionString_Proc
)
158 (IN HIMC context
, IN DWORD index
, OUT LPVOID buffer
, IN DWORD bufLen
);
159 typedef HIMC (WINAPI
* ImmGetContext_Proc
) (IN HWND window
);
160 typedef HWND (WINAPI
* ImmReleaseContext_Proc
) (IN HWND wnd
, IN HIMC context
);
161 typedef HWND (WINAPI
* ImmSetCompositionWindow_Proc
) (IN HIMC context
,
162 IN COMPOSITIONFORM
*form
);
163 typedef HMONITOR (WINAPI
* MonitorFromPoint_Proc
) (IN POINT pt
, IN DWORD flags
);
164 typedef BOOL (WINAPI
* GetMonitorInfo_Proc
)
165 (IN HMONITOR monitor
, OUT
struct MONITOR_INFO
* info
);
166 typedef HMONITOR (WINAPI
* MonitorFromWindow_Proc
)
167 (IN HWND hwnd
, IN DWORD dwFlags
);
168 typedef BOOL
CALLBACK (* MonitorEnum_Proc
)
169 (IN HMONITOR monitor
, IN HDC hdc
, IN RECT
*rcMonitor
, IN LPARAM dwData
);
170 typedef BOOL (WINAPI
* EnumDisplayMonitors_Proc
)
171 (IN HDC hdc
, IN RECT
*rcClip
, IN MonitorEnum_Proc fnEnum
, IN LPARAM dwData
);
173 TrackMouseEvent_Proc track_mouse_event_fn
= NULL
;
174 ImmGetCompositionString_Proc get_composition_string_fn
= NULL
;
175 ImmGetContext_Proc get_ime_context_fn
= NULL
;
176 ImmReleaseContext_Proc release_ime_context_fn
= NULL
;
177 ImmSetCompositionWindow_Proc set_ime_composition_window_fn
= NULL
;
178 MonitorFromPoint_Proc monitor_from_point_fn
= NULL
;
179 GetMonitorInfo_Proc get_monitor_info_fn
= NULL
;
180 MonitorFromWindow_Proc monitor_from_window_fn
= NULL
;
181 EnumDisplayMonitors_Proc enum_display_monitors_fn
= NULL
;
184 #define unicode_append_menu AppendMenuW
185 #else /* !NTGUI_UNICODE */
186 extern AppendMenuW_Proc unicode_append_menu
;
187 #endif /* NTGUI_UNICODE */
189 /* Flag to selectively ignore WM_IME_CHAR messages. */
190 static int ignore_ime_char
= 0;
192 /* W95 mousewheel handler */
193 unsigned int msh_mousewheel
= 0;
196 #define MOUSE_BUTTON_ID 1
197 #define MOUSE_MOVE_ID 2
198 #define MENU_FREE_ID 3
199 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
201 #define MENU_FREE_DELAY 1000
202 static unsigned menu_free_timer
= 0;
205 static int image_cache_refcount
, dpyinfo_refcount
;
208 static HWND w32_visible_system_caret_hwnd
;
210 static int w32_unicode_gui
;
213 extern HMENU current_popup_menu
;
214 int menubar_in_use
= 0;
216 /* From w32uniscribe.c */
217 extern void syms_of_w32uniscribe (void);
218 extern int uniscribe_available
;
221 /* From w32inevt.c */
222 extern int faked_key
;
223 #endif /* WINDOWSNT */
225 /* This gives us the page size and the size of the allocation unit on NT. */
226 SYSTEM_INFO sysinfo_cache
;
228 /* This gives us version, build, and platform identification. */
229 OSVERSIONINFO osinfo_cache
;
231 DWORD_PTR syspage_mask
= 0;
233 /* The major and minor versions of NT. */
234 int w32_major_version
;
235 int w32_minor_version
;
236 int w32_build_number
;
238 /* Distinguish between Windows NT and Windows 95. */
242 HINSTANCE hinst
= NULL
;
245 static unsigned int sound_type
= 0xFFFFFFFF;
246 #define MB_EMACS_SILENT (0xFFFFFFFF - 1)
248 /* Let the user specify a display with a frame.
249 nil stands for the selected frame--or, if that is not a w32 frame,
250 the first display on the list. */
252 struct w32_display_info
*
253 check_x_display_info (Lisp_Object object
)
257 struct frame
*sf
= XFRAME (selected_frame
);
259 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
260 return FRAME_DISPLAY_INFO (sf
);
262 return &one_w32_display_info
;
264 else if (TERMINALP (object
))
266 struct terminal
*t
= decode_live_terminal (object
);
268 if (t
->type
!= output_w32
)
269 error ("Terminal %d is not a W32 display", t
->id
);
271 return t
->display_info
.w32
;
273 else if (STRINGP (object
))
274 return x_display_info_for_name (object
);
279 CHECK_LIVE_FRAME (object
);
281 if (! FRAME_W32_P (f
))
282 error ("Non-W32 frame used");
283 return FRAME_DISPLAY_INFO (f
);
287 /* Return the Emacs frame-object corresponding to an w32 window.
288 It could be the frame's main window or an icon window. */
291 x_window_to_frame (struct w32_display_info
*dpyinfo
, HWND wdesc
)
293 Lisp_Object tail
, frame
;
296 FOR_EACH_FRAME (tail
, frame
)
299 if (!FRAME_W32_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
302 if (FRAME_W32_WINDOW (f
) == wdesc
)
309 static Lisp_Object
unwind_create_frame (Lisp_Object
);
310 static void unwind_create_tip_frame (Lisp_Object
);
311 static void my_create_window (struct frame
*);
312 static void my_create_tip_window (struct frame
*);
314 /* TODO: Native Input Method support; see x_create_im. */
315 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
316 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
317 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
318 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
319 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
320 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
321 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
322 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
323 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
324 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
325 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
326 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
327 void x_set_internal_border_width (struct frame
*f
, Lisp_Object
, Lisp_Object
);
330 /* Store the screen positions of frame F into XPTR and YPTR.
331 These are the positions of the containing window manager window,
332 not Emacs's own window. */
335 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
340 /* Get the bounds of the WM window. */
341 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
346 /* Convert (0, 0) in the client area to screen co-ordinates. */
347 ClientToScreen (FRAME_W32_WINDOW (f
), &pt
);
353 /* Returns the window rectangle appropriate for the given fullscreen mode.
354 The normal rect parameter was the window's rectangle prior to entering
355 fullscreen mode. If multiple monitor support is available, the nearest
356 monitor to the window is chosen. */
359 w32_fullscreen_rect (HWND hwnd
, int fsmode
, RECT normal
, RECT
*rect
)
361 struct MONITOR_INFO mi
= { sizeof(mi
) };
362 if (monitor_from_window_fn
&& get_monitor_info_fn
)
365 monitor_from_window_fn (hwnd
, MONITOR_DEFAULT_TO_NEAREST
);
366 get_monitor_info_fn (monitor
, &mi
);
370 mi
.rcMonitor
.left
= 0;
371 mi
.rcMonitor
.top
= 0;
372 mi
.rcMonitor
.right
= GetSystemMetrics (SM_CXSCREEN
);
373 mi
.rcMonitor
.bottom
= GetSystemMetrics (SM_CYSCREEN
);
376 mi
.rcWork
.right
= GetSystemMetrics (SM_CXMAXIMIZED
);
377 mi
.rcWork
.bottom
= GetSystemMetrics (SM_CYMAXIMIZED
);
382 case FULLSCREEN_BOTH
:
383 rect
->left
= mi
.rcMonitor
.left
;
384 rect
->top
= mi
.rcMonitor
.top
;
385 rect
->right
= mi
.rcMonitor
.right
;
386 rect
->bottom
= mi
.rcMonitor
.bottom
;
388 case FULLSCREEN_WIDTH
:
389 rect
->left
= mi
.rcWork
.left
;
390 rect
->top
= normal
.top
;
391 rect
->right
= mi
.rcWork
.right
;
392 rect
->bottom
= normal
.bottom
;
394 case FULLSCREEN_HEIGHT
:
395 rect
->left
= normal
.left
;
396 rect
->top
= mi
.rcWork
.top
;
397 rect
->right
= normal
.right
;
398 rect
->bottom
= mi
.rcWork
.bottom
;
408 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
409 Sw32_define_rgb_color
, 4, 4, 0,
410 doc
: /* Convert RGB numbers to a Windows color reference and associate with NAME.
411 This adds or updates a named color to `w32-color-map', making it
412 available for use. The original entry's RGB ref is returned, or nil
413 if the entry is new. */)
414 (Lisp_Object red
, Lisp_Object green
, Lisp_Object blue
, Lisp_Object name
)
417 Lisp_Object oldrgb
= Qnil
;
421 CHECK_NUMBER (green
);
425 XSETINT (rgb
, RGB (XUINT (red
), XUINT (green
), XUINT (blue
)));
429 /* replace existing entry in w32-color-map or add new entry. */
430 entry
= Fassoc (name
, Vw32_color_map
);
433 entry
= Fcons (name
, rgb
);
434 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
438 oldrgb
= Fcdr (entry
);
439 Fsetcdr (entry
, rgb
);
447 /* The default colors for the w32 color map */
448 typedef struct colormap_t
454 colormap_t w32_color_map
[] =
456 {"snow" , PALETTERGB (255,250,250)},
457 {"ghost white" , PALETTERGB (248,248,255)},
458 {"GhostWhite" , PALETTERGB (248,248,255)},
459 {"white smoke" , PALETTERGB (245,245,245)},
460 {"WhiteSmoke" , PALETTERGB (245,245,245)},
461 {"gainsboro" , PALETTERGB (220,220,220)},
462 {"floral white" , PALETTERGB (255,250,240)},
463 {"FloralWhite" , PALETTERGB (255,250,240)},
464 {"old lace" , PALETTERGB (253,245,230)},
465 {"OldLace" , PALETTERGB (253,245,230)},
466 {"linen" , PALETTERGB (250,240,230)},
467 {"antique white" , PALETTERGB (250,235,215)},
468 {"AntiqueWhite" , PALETTERGB (250,235,215)},
469 {"papaya whip" , PALETTERGB (255,239,213)},
470 {"PapayaWhip" , PALETTERGB (255,239,213)},
471 {"blanched almond" , PALETTERGB (255,235,205)},
472 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
473 {"bisque" , PALETTERGB (255,228,196)},
474 {"peach puff" , PALETTERGB (255,218,185)},
475 {"PeachPuff" , PALETTERGB (255,218,185)},
476 {"navajo white" , PALETTERGB (255,222,173)},
477 {"NavajoWhite" , PALETTERGB (255,222,173)},
478 {"moccasin" , PALETTERGB (255,228,181)},
479 {"cornsilk" , PALETTERGB (255,248,220)},
480 {"ivory" , PALETTERGB (255,255,240)},
481 {"lemon chiffon" , PALETTERGB (255,250,205)},
482 {"LemonChiffon" , PALETTERGB (255,250,205)},
483 {"seashell" , PALETTERGB (255,245,238)},
484 {"honeydew" , PALETTERGB (240,255,240)},
485 {"mint cream" , PALETTERGB (245,255,250)},
486 {"MintCream" , PALETTERGB (245,255,250)},
487 {"azure" , PALETTERGB (240,255,255)},
488 {"alice blue" , PALETTERGB (240,248,255)},
489 {"AliceBlue" , PALETTERGB (240,248,255)},
490 {"lavender" , PALETTERGB (230,230,250)},
491 {"lavender blush" , PALETTERGB (255,240,245)},
492 {"LavenderBlush" , PALETTERGB (255,240,245)},
493 {"misty rose" , PALETTERGB (255,228,225)},
494 {"MistyRose" , PALETTERGB (255,228,225)},
495 {"white" , PALETTERGB (255,255,255)},
496 {"black" , PALETTERGB ( 0, 0, 0)},
497 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
498 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
499 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
500 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
501 {"dim gray" , PALETTERGB (105,105,105)},
502 {"DimGray" , PALETTERGB (105,105,105)},
503 {"dim grey" , PALETTERGB (105,105,105)},
504 {"DimGrey" , PALETTERGB (105,105,105)},
505 {"slate gray" , PALETTERGB (112,128,144)},
506 {"SlateGray" , PALETTERGB (112,128,144)},
507 {"slate grey" , PALETTERGB (112,128,144)},
508 {"SlateGrey" , PALETTERGB (112,128,144)},
509 {"light slate gray" , PALETTERGB (119,136,153)},
510 {"LightSlateGray" , PALETTERGB (119,136,153)},
511 {"light slate grey" , PALETTERGB (119,136,153)},
512 {"LightSlateGrey" , PALETTERGB (119,136,153)},
513 {"gray" , PALETTERGB (190,190,190)},
514 {"grey" , PALETTERGB (190,190,190)},
515 {"light grey" , PALETTERGB (211,211,211)},
516 {"LightGrey" , PALETTERGB (211,211,211)},
517 {"light gray" , PALETTERGB (211,211,211)},
518 {"LightGray" , PALETTERGB (211,211,211)},
519 {"midnight blue" , PALETTERGB ( 25, 25,112)},
520 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
521 {"navy" , PALETTERGB ( 0, 0,128)},
522 {"navy blue" , PALETTERGB ( 0, 0,128)},
523 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
524 {"cornflower blue" , PALETTERGB (100,149,237)},
525 {"CornflowerBlue" , PALETTERGB (100,149,237)},
526 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
527 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
528 {"slate blue" , PALETTERGB (106, 90,205)},
529 {"SlateBlue" , PALETTERGB (106, 90,205)},
530 {"medium slate blue" , PALETTERGB (123,104,238)},
531 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
532 {"light slate blue" , PALETTERGB (132,112,255)},
533 {"LightSlateBlue" , PALETTERGB (132,112,255)},
534 {"medium blue" , PALETTERGB ( 0, 0,205)},
535 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
536 {"royal blue" , PALETTERGB ( 65,105,225)},
537 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
538 {"blue" , PALETTERGB ( 0, 0,255)},
539 {"dodger blue" , PALETTERGB ( 30,144,255)},
540 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
541 {"deep sky blue" , PALETTERGB ( 0,191,255)},
542 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
543 {"sky blue" , PALETTERGB (135,206,235)},
544 {"SkyBlue" , PALETTERGB (135,206,235)},
545 {"light sky blue" , PALETTERGB (135,206,250)},
546 {"LightSkyBlue" , PALETTERGB (135,206,250)},
547 {"steel blue" , PALETTERGB ( 70,130,180)},
548 {"SteelBlue" , PALETTERGB ( 70,130,180)},
549 {"light steel blue" , PALETTERGB (176,196,222)},
550 {"LightSteelBlue" , PALETTERGB (176,196,222)},
551 {"light blue" , PALETTERGB (173,216,230)},
552 {"LightBlue" , PALETTERGB (173,216,230)},
553 {"powder blue" , PALETTERGB (176,224,230)},
554 {"PowderBlue" , PALETTERGB (176,224,230)},
555 {"pale turquoise" , PALETTERGB (175,238,238)},
556 {"PaleTurquoise" , PALETTERGB (175,238,238)},
557 {"dark turquoise" , PALETTERGB ( 0,206,209)},
558 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
559 {"medium turquoise" , PALETTERGB ( 72,209,204)},
560 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
561 {"turquoise" , PALETTERGB ( 64,224,208)},
562 {"cyan" , PALETTERGB ( 0,255,255)},
563 {"light cyan" , PALETTERGB (224,255,255)},
564 {"LightCyan" , PALETTERGB (224,255,255)},
565 {"cadet blue" , PALETTERGB ( 95,158,160)},
566 {"CadetBlue" , PALETTERGB ( 95,158,160)},
567 {"medium aquamarine" , PALETTERGB (102,205,170)},
568 {"MediumAquamarine" , PALETTERGB (102,205,170)},
569 {"aquamarine" , PALETTERGB (127,255,212)},
570 {"dark green" , PALETTERGB ( 0,100, 0)},
571 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
572 {"dark olive green" , PALETTERGB ( 85,107, 47)},
573 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
574 {"dark sea green" , PALETTERGB (143,188,143)},
575 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
576 {"sea green" , PALETTERGB ( 46,139, 87)},
577 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
578 {"medium sea green" , PALETTERGB ( 60,179,113)},
579 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
580 {"light sea green" , PALETTERGB ( 32,178,170)},
581 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
582 {"pale green" , PALETTERGB (152,251,152)},
583 {"PaleGreen" , PALETTERGB (152,251,152)},
584 {"spring green" , PALETTERGB ( 0,255,127)},
585 {"SpringGreen" , PALETTERGB ( 0,255,127)},
586 {"lawn green" , PALETTERGB (124,252, 0)},
587 {"LawnGreen" , PALETTERGB (124,252, 0)},
588 {"green" , PALETTERGB ( 0,255, 0)},
589 {"chartreuse" , PALETTERGB (127,255, 0)},
590 {"medium spring green" , PALETTERGB ( 0,250,154)},
591 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
592 {"green yellow" , PALETTERGB (173,255, 47)},
593 {"GreenYellow" , PALETTERGB (173,255, 47)},
594 {"lime green" , PALETTERGB ( 50,205, 50)},
595 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
596 {"yellow green" , PALETTERGB (154,205, 50)},
597 {"YellowGreen" , PALETTERGB (154,205, 50)},
598 {"forest green" , PALETTERGB ( 34,139, 34)},
599 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
600 {"olive drab" , PALETTERGB (107,142, 35)},
601 {"OliveDrab" , PALETTERGB (107,142, 35)},
602 {"dark khaki" , PALETTERGB (189,183,107)},
603 {"DarkKhaki" , PALETTERGB (189,183,107)},
604 {"khaki" , PALETTERGB (240,230,140)},
605 {"pale goldenrod" , PALETTERGB (238,232,170)},
606 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
607 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
608 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
609 {"light yellow" , PALETTERGB (255,255,224)},
610 {"LightYellow" , PALETTERGB (255,255,224)},
611 {"yellow" , PALETTERGB (255,255, 0)},
612 {"gold" , PALETTERGB (255,215, 0)},
613 {"light goldenrod" , PALETTERGB (238,221,130)},
614 {"LightGoldenrod" , PALETTERGB (238,221,130)},
615 {"goldenrod" , PALETTERGB (218,165, 32)},
616 {"dark goldenrod" , PALETTERGB (184,134, 11)},
617 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
618 {"rosy brown" , PALETTERGB (188,143,143)},
619 {"RosyBrown" , PALETTERGB (188,143,143)},
620 {"indian red" , PALETTERGB (205, 92, 92)},
621 {"IndianRed" , PALETTERGB (205, 92, 92)},
622 {"saddle brown" , PALETTERGB (139, 69, 19)},
623 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
624 {"sienna" , PALETTERGB (160, 82, 45)},
625 {"peru" , PALETTERGB (205,133, 63)},
626 {"burlywood" , PALETTERGB (222,184,135)},
627 {"beige" , PALETTERGB (245,245,220)},
628 {"wheat" , PALETTERGB (245,222,179)},
629 {"sandy brown" , PALETTERGB (244,164, 96)},
630 {"SandyBrown" , PALETTERGB (244,164, 96)},
631 {"tan" , PALETTERGB (210,180,140)},
632 {"chocolate" , PALETTERGB (210,105, 30)},
633 {"firebrick" , PALETTERGB (178,34, 34)},
634 {"brown" , PALETTERGB (165,42, 42)},
635 {"dark salmon" , PALETTERGB (233,150,122)},
636 {"DarkSalmon" , PALETTERGB (233,150,122)},
637 {"salmon" , PALETTERGB (250,128,114)},
638 {"light salmon" , PALETTERGB (255,160,122)},
639 {"LightSalmon" , PALETTERGB (255,160,122)},
640 {"orange" , PALETTERGB (255,165, 0)},
641 {"dark orange" , PALETTERGB (255,140, 0)},
642 {"DarkOrange" , PALETTERGB (255,140, 0)},
643 {"coral" , PALETTERGB (255,127, 80)},
644 {"light coral" , PALETTERGB (240,128,128)},
645 {"LightCoral" , PALETTERGB (240,128,128)},
646 {"tomato" , PALETTERGB (255, 99, 71)},
647 {"orange red" , PALETTERGB (255, 69, 0)},
648 {"OrangeRed" , PALETTERGB (255, 69, 0)},
649 {"red" , PALETTERGB (255, 0, 0)},
650 {"hot pink" , PALETTERGB (255,105,180)},
651 {"HotPink" , PALETTERGB (255,105,180)},
652 {"deep pink" , PALETTERGB (255, 20,147)},
653 {"DeepPink" , PALETTERGB (255, 20,147)},
654 {"pink" , PALETTERGB (255,192,203)},
655 {"light pink" , PALETTERGB (255,182,193)},
656 {"LightPink" , PALETTERGB (255,182,193)},
657 {"pale violet red" , PALETTERGB (219,112,147)},
658 {"PaleVioletRed" , PALETTERGB (219,112,147)},
659 {"maroon" , PALETTERGB (176, 48, 96)},
660 {"medium violet red" , PALETTERGB (199, 21,133)},
661 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
662 {"violet red" , PALETTERGB (208, 32,144)},
663 {"VioletRed" , PALETTERGB (208, 32,144)},
664 {"magenta" , PALETTERGB (255, 0,255)},
665 {"violet" , PALETTERGB (238,130,238)},
666 {"plum" , PALETTERGB (221,160,221)},
667 {"orchid" , PALETTERGB (218,112,214)},
668 {"medium orchid" , PALETTERGB (186, 85,211)},
669 {"MediumOrchid" , PALETTERGB (186, 85,211)},
670 {"dark orchid" , PALETTERGB (153, 50,204)},
671 {"DarkOrchid" , PALETTERGB (153, 50,204)},
672 {"dark violet" , PALETTERGB (148, 0,211)},
673 {"DarkViolet" , PALETTERGB (148, 0,211)},
674 {"blue violet" , PALETTERGB (138, 43,226)},
675 {"BlueViolet" , PALETTERGB (138, 43,226)},
676 {"purple" , PALETTERGB (160, 32,240)},
677 {"medium purple" , PALETTERGB (147,112,219)},
678 {"MediumPurple" , PALETTERGB (147,112,219)},
679 {"thistle" , PALETTERGB (216,191,216)},
680 {"gray0" , PALETTERGB ( 0, 0, 0)},
681 {"grey0" , PALETTERGB ( 0, 0, 0)},
682 {"dark grey" , PALETTERGB (169,169,169)},
683 {"DarkGrey" , PALETTERGB (169,169,169)},
684 {"dark gray" , PALETTERGB (169,169,169)},
685 {"DarkGray" , PALETTERGB (169,169,169)},
686 {"dark blue" , PALETTERGB ( 0, 0,139)},
687 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
688 {"dark cyan" , PALETTERGB ( 0,139,139)},
689 {"DarkCyan" , PALETTERGB ( 0,139,139)},
690 {"dark magenta" , PALETTERGB (139, 0,139)},
691 {"DarkMagenta" , PALETTERGB (139, 0,139)},
692 {"dark red" , PALETTERGB (139, 0, 0)},
693 {"DarkRed" , PALETTERGB (139, 0, 0)},
694 {"light green" , PALETTERGB (144,238,144)},
695 {"LightGreen" , PALETTERGB (144,238,144)},
699 w32_default_color_map (void)
702 colormap_t
*pc
= w32_color_map
;
709 for (i
= 0; i
< ARRAYELTS (w32_color_map
); pc
++, i
++)
710 cmap
= Fcons (Fcons (build_string (pc
->name
),
711 make_number (pc
->colorref
)),
719 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
720 0, 0, 0, doc
: /* Return the default color map. */)
723 return w32_default_color_map ();
727 w32_color_map_lookup (const char *colorname
)
729 Lisp_Object tail
, ret
= Qnil
;
733 for (tail
= Vw32_color_map
; CONSP (tail
); tail
= XCDR (tail
))
735 register Lisp_Object elt
, tem
;
738 if (!CONSP (elt
)) continue;
742 if (lstrcmpi (SDATA (tem
), colorname
) == 0)
758 add_system_logical_colors_to_map (Lisp_Object
*system_colors
)
762 /* Other registry operations are done with input blocked. */
765 /* Look for "Control Panel/Colors" under User and Machine registry
767 if (RegOpenKeyEx (HKEY_CURRENT_USER
, "Control Panel\\Colors", 0,
768 KEY_READ
, &colors_key
) == ERROR_SUCCESS
769 || RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "Control Panel\\Colors", 0,
770 KEY_READ
, &colors_key
) == ERROR_SUCCESS
)
773 char color_buffer
[64];
774 char full_name_buffer
[MAX_PATH
+ SYSTEM_COLOR_PREFIX_LEN
];
776 DWORD name_size
, color_size
;
777 char *name_buffer
= full_name_buffer
+ SYSTEM_COLOR_PREFIX_LEN
;
779 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
780 color_size
= sizeof (color_buffer
);
782 strcpy (full_name_buffer
, SYSTEM_COLOR_PREFIX
);
784 while (RegEnumValueA (colors_key
, index
, name_buffer
, &name_size
,
785 NULL
, NULL
, color_buffer
, &color_size
)
789 if (sscanf (color_buffer
, " %u %u %u", &r
, &g
, &b
) == 3)
790 *system_colors
= Fcons (Fcons (build_string (full_name_buffer
),
791 make_number (RGB (r
, g
, b
))),
794 name_size
= sizeof (full_name_buffer
) - SYSTEM_COLOR_PREFIX_LEN
;
795 color_size
= sizeof (color_buffer
);
798 RegCloseKey (colors_key
);
806 x_to_w32_color (const char * colorname
)
808 register Lisp_Object ret
= Qnil
;
812 if (colorname
[0] == '#')
814 /* Could be an old-style RGB Device specification. */
815 int size
= strlen (colorname
+ 1);
816 char *color
= alloca (size
+ 1);
818 strcpy (color
, colorname
+ 1);
819 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
827 for (i
= 0; i
< 3; i
++)
833 /* The check for 'x' in the following conditional takes into
834 account the fact that strtol allows a "0x" in front of
835 our numbers, and we don't. */
836 if (!isxdigit (color
[0]) || color
[1] == 'x')
840 value
= strtoul (color
, &end
, 16);
842 if (errno
== ERANGE
|| end
- color
!= size
)
847 value
= value
* 0x10;
858 colorval
|= (value
<< pos
);
863 XSETINT (ret
, colorval
);
870 else if (strnicmp (colorname
, "rgb:", 4) == 0)
878 color
= colorname
+ 4;
879 for (i
= 0; i
< 3; i
++)
884 /* The check for 'x' in the following conditional takes into
885 account the fact that strtol allows a "0x" in front of
886 our numbers, and we don't. */
887 if (!isxdigit (color
[0]) || color
[1] == 'x')
889 value
= strtoul (color
, &end
, 16);
895 value
= value
* 0x10 + value
;
908 if (value
== ULONG_MAX
)
910 colorval
|= (value
<< pos
);
917 XSETINT (ret
, colorval
);
925 else if (strnicmp (colorname
, "rgbi:", 5) == 0)
927 /* This is an RGB Intensity specification. */
934 color
= colorname
+ 5;
935 for (i
= 0; i
< 3; i
++)
941 value
= strtod (color
, &end
);
944 if (value
< 0.0 || value
> 1.0)
946 val
= (UINT
)(0x100 * value
);
947 /* We used 0x100 instead of 0xFF to give a continuous
948 range between 0.0 and 1.0 inclusive. The next statement
949 fixes the 1.0 case. */
952 colorval
|= (val
<< pos
);
959 XSETINT (ret
, colorval
);
967 /* I am not going to attempt to handle any of the CIE color schemes
968 or TekHVC, since I don't know the algorithms for conversion to
971 /* If we fail to lookup the color name in w32_color_map, then check the
972 colorname to see if it can be crudely approximated: If the X color
973 ends in a number (e.g., "darkseagreen2"), strip the number and
974 return the result of looking up the base color name. */
975 ret
= w32_color_map_lookup (colorname
);
978 int len
= strlen (colorname
);
980 if (isdigit (colorname
[len
- 1]))
982 char *ptr
, *approx
= alloca (len
+ 1);
984 strcpy (approx
, colorname
);
985 ptr
= &approx
[len
- 1];
986 while (ptr
> approx
&& isdigit (*ptr
))
989 ret
= w32_color_map_lookup (approx
);
998 w32_regenerate_palette (struct frame
*f
)
1000 struct w32_palette_entry
* list
;
1001 LOGPALETTE
* log_palette
;
1002 HPALETTE new_palette
;
1005 /* don't bother trying to create palette if not supported */
1006 if (! FRAME_DISPLAY_INFO (f
)->has_palette
)
1009 log_palette
= (LOGPALETTE
*)
1010 alloca (sizeof (LOGPALETTE
) +
1011 FRAME_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1012 log_palette
->palVersion
= 0x300;
1013 log_palette
->palNumEntries
= FRAME_DISPLAY_INFO (f
)->num_colors
;
1015 list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1017 i
< FRAME_DISPLAY_INFO (f
)->num_colors
;
1018 i
++, list
= list
->next
)
1019 log_palette
->palPalEntry
[i
] = list
->entry
;
1021 new_palette
= CreatePalette (log_palette
);
1025 if (FRAME_DISPLAY_INFO (f
)->palette
)
1026 DeleteObject (FRAME_DISPLAY_INFO (f
)->palette
);
1027 FRAME_DISPLAY_INFO (f
)->palette
= new_palette
;
1029 /* Realize display palette and garbage all frames. */
1030 release_frame_dc (f
, get_frame_dc (f
));
1035 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1036 #define SET_W32_COLOR(pe, color) \
1039 pe.peRed = GetRValue (color); \
1040 pe.peGreen = GetGValue (color); \
1041 pe.peBlue = GetBValue (color); \
1046 /* Keep these around in case we ever want to track color usage. */
1048 w32_map_color (struct frame
*f
, COLORREF color
)
1050 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1052 if (NILP (Vw32_enable_palette
))
1055 /* check if color is already mapped */
1058 if (W32_COLOR (list
->entry
) == color
)
1066 /* not already mapped, so add to list and recreate Windows palette */
1067 list
= xmalloc (sizeof (struct w32_palette_entry
));
1068 SET_W32_COLOR (list
->entry
, color
);
1070 list
->next
= FRAME_DISPLAY_INFO (f
)->color_list
;
1071 FRAME_DISPLAY_INFO (f
)->color_list
= list
;
1072 FRAME_DISPLAY_INFO (f
)->num_colors
++;
1074 /* set flag that palette must be regenerated */
1075 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1079 w32_unmap_color (struct frame
*f
, COLORREF color
)
1081 struct w32_palette_entry
* list
= FRAME_DISPLAY_INFO (f
)->color_list
;
1082 struct w32_palette_entry
**prev
= &FRAME_DISPLAY_INFO (f
)->color_list
;
1084 if (NILP (Vw32_enable_palette
))
1087 /* check if color is already mapped */
1090 if (W32_COLOR (list
->entry
) == color
)
1092 if (--list
->refcount
== 0)
1096 FRAME_DISPLAY_INFO (f
)->num_colors
--;
1106 /* set flag that palette must be regenerated */
1107 FRAME_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1112 /* Gamma-correct COLOR on frame F. */
1115 gamma_correct (struct frame
*f
, COLORREF
*color
)
1119 *color
= PALETTERGB (
1120 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1121 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1122 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1127 /* Decide if color named COLOR is valid for the display associated with
1128 the selected frame; if so, return the rgb values in COLOR_DEF.
1129 If ALLOC is nonzero, allocate a new colormap cell. */
1132 w32_defined_color (struct frame
*f
, const char *color
, XColor
*color_def
,
1135 register Lisp_Object tem
;
1136 COLORREF w32_color_ref
;
1138 tem
= x_to_w32_color (color
);
1144 /* Apply gamma correction. */
1145 w32_color_ref
= XUINT (tem
);
1146 gamma_correct (f
, &w32_color_ref
);
1147 XSETINT (tem
, w32_color_ref
);
1150 /* Map this color to the palette if it is enabled. */
1151 if (!NILP (Vw32_enable_palette
))
1153 struct w32_palette_entry
* entry
=
1154 one_w32_display_info
.color_list
;
1155 struct w32_palette_entry
** prev
=
1156 &one_w32_display_info
.color_list
;
1158 /* check if color is already mapped */
1161 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1163 prev
= &entry
->next
;
1164 entry
= entry
->next
;
1167 if (entry
== NULL
&& alloc_p
)
1169 /* not already mapped, so add to list */
1170 entry
= xmalloc (sizeof (struct w32_palette_entry
));
1171 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1174 one_w32_display_info
.num_colors
++;
1176 /* set flag that palette must be regenerated */
1177 one_w32_display_info
.regen_palette
= TRUE
;
1180 /* Ensure COLORREF value is snapped to nearest color in (default)
1181 palette by simulating the PALETTERGB macro. This works whether
1182 or not the display device has a palette. */
1183 w32_color_ref
= XUINT (tem
) | 0x2000000;
1185 color_def
->pixel
= w32_color_ref
;
1186 color_def
->red
= GetRValue (w32_color_ref
) * 256;
1187 color_def
->green
= GetGValue (w32_color_ref
) * 256;
1188 color_def
->blue
= GetBValue (w32_color_ref
) * 256;
1198 /* Given a string ARG naming a color, compute a pixel value from it
1199 suitable for screen F.
1200 If F is not a color screen, return DEF (default) regardless of what
1204 x_decode_color (struct frame
*f
, Lisp_Object arg
, int def
)
1210 if (strcmp (SDATA (arg
), "black") == 0)
1211 return BLACK_PIX_DEFAULT (f
);
1212 else if (strcmp (SDATA (arg
), "white") == 0)
1213 return WHITE_PIX_DEFAULT (f
);
1215 if ((FRAME_DISPLAY_INFO (f
)->n_planes
* FRAME_DISPLAY_INFO (f
)->n_cbits
) == 1)
1218 /* w32_defined_color is responsible for coping with failures
1219 by looking for a near-miss. */
1220 if (w32_defined_color (f
, SDATA (arg
), &cdef
, true))
1223 /* defined_color failed; return an ultimate default. */
1229 /* Functions called only from `x_set_frame_param'
1230 to set individual parameters.
1232 If FRAME_W32_WINDOW (f) is 0,
1233 the frame is being created and its window does not exist yet.
1234 In that case, just record the parameter's new value
1235 in the standard place; do not attempt to change the window. */
1238 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1240 struct w32_output
*x
= f
->output_data
.w32
;
1241 PIX_TYPE fg
, old_fg
;
1243 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1244 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1245 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1247 if (FRAME_W32_WINDOW (f
) != 0)
1249 if (x
->cursor_pixel
== old_fg
)
1251 x
->cursor_pixel
= fg
;
1252 x
->cursor_gc
->background
= fg
;
1255 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1256 if (FRAME_VISIBLE_P (f
))
1262 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1264 FRAME_BACKGROUND_PIXEL (f
)
1265 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1267 if (FRAME_W32_WINDOW (f
) != 0)
1269 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1270 FRAME_BACKGROUND_PIXEL (f
));
1272 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1274 if (FRAME_VISIBLE_P (f
))
1280 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1282 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1286 if (!EQ (Qnil
, arg
))
1287 f
->output_data
.w32
->mouse_pixel
1288 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1289 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1291 /* Don't let pointers be invisible. */
1292 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1293 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1294 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1296 #if 0 /* TODO : Mouse cursor customization. */
1299 /* It's not okay to crash if the user selects a screwy cursor. */
1300 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1302 if (!EQ (Qnil
, Vx_pointer_shape
))
1304 CHECK_NUMBER (Vx_pointer_shape
);
1305 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1308 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1309 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1311 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1313 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1314 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1315 XINT (Vx_nontext_pointer_shape
));
1318 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1319 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1321 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
1323 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1324 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1325 XINT (Vx_hourglass_pointer_shape
));
1328 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1329 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1331 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1332 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1334 CHECK_NUMBER (Vx_mode_pointer_shape
);
1335 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1336 XINT (Vx_mode_pointer_shape
));
1339 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1340 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
1342 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1344 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1346 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1347 XINT (Vx_sensitive_text_pointer_shape
));
1350 hand_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
1352 if (!NILP (Vx_window_horizontal_drag_shape
))
1354 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1355 horizontal_drag_cursor
1356 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1357 XINT (Vx_window_horizontal_drag_shape
));
1360 horizontal_drag_cursor
1361 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_h_double_arrow
);
1363 if (!NILP (Vx_window_vertical_drag_shape
))
1365 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
1366 vertical_drag_cursor
1367 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1368 XINT (Vx_window_vertical_drag_shape
));
1371 vertical_drag_cursor
1372 = XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_sb_v_double_arrow
);
1374 /* Check and report errors with the above calls. */
1375 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
1376 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
1379 XColor fore_color
, back_color
;
1381 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
1382 back_color
.pixel
= mask_color
;
1383 XQueryColor (FRAME_W32_DISPLAY (f
),
1384 DefaultColormap (FRAME_W32_DISPLAY (f
),
1385 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1387 XQueryColor (FRAME_W32_DISPLAY (f
),
1388 DefaultColormap (FRAME_W32_DISPLAY (f
),
1389 DefaultScreen (FRAME_W32_DISPLAY (f
))),
1391 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
1392 &fore_color
, &back_color
);
1393 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
1394 &fore_color
, &back_color
);
1395 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
1396 &fore_color
, &back_color
);
1397 XRecolorCursor (FRAME_W32_DISPLAY (f
), hand_cursor
,
1398 &fore_color
, &back_color
);
1399 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
1400 &fore_color
, &back_color
);
1403 if (FRAME_W32_WINDOW (f
) != 0)
1404 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
1406 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
1407 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
1408 f
->output_data
.w32
->text_cursor
= cursor
;
1410 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
1411 && f
->output_data
.w32
->nontext_cursor
!= 0)
1412 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
1413 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
1415 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
1416 && f
->output_data
.w32
->hourglass_cursor
!= 0)
1417 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
1418 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
1420 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
1421 && f
->output_data
.w32
->modeline_cursor
!= 0)
1422 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
1423 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
1425 if (hand_cursor
!= f
->output_data
.w32
->hand_cursor
1426 && f
->output_data
.w32
->hand_cursor
!= 0)
1427 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hand_cursor
);
1428 f
->output_data
.w32
->hand_cursor
= hand_cursor
;
1430 XFlush (FRAME_W32_DISPLAY (f
));
1433 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1438 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1440 unsigned long fore_pixel
, pixel
;
1442 if (!NILP (Vx_cursor_fore_pixel
))
1443 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1444 WHITE_PIX_DEFAULT (f
));
1446 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1448 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1450 /* Make sure that the cursor color differs from the background color. */
1451 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1453 pixel
= f
->output_data
.w32
->mouse_pixel
;
1454 if (pixel
== fore_pixel
)
1455 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1458 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
1459 f
->output_data
.w32
->cursor_pixel
= pixel
;
1461 if (FRAME_W32_WINDOW (f
) != 0)
1464 /* Update frame's cursor_gc. */
1465 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
1466 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
1470 if (FRAME_VISIBLE_P (f
))
1472 x_update_cursor (f
, 0);
1473 x_update_cursor (f
, 1);
1477 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1480 /* Set the border-color of frame F to pixel value PIX.
1481 Note that this does not fully take effect if done before
1485 x_set_border_pixel (struct frame
*f
, int pix
)
1488 f
->output_data
.w32
->border_pixel
= pix
;
1490 if (FRAME_W32_WINDOW (f
) != 0 && f
->border_width
> 0)
1492 if (FRAME_VISIBLE_P (f
))
1497 /* Set the border-color of frame F to value described by ARG.
1498 ARG can be a string naming a color.
1499 The border-color is used for the border that is drawn by the server.
1500 Note that this does not fully take effect if done before
1501 F has a window; it must be redone when the window is created. */
1504 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1509 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1510 x_set_border_pixel (f
, pix
);
1511 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1516 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1518 set_frame_cursor_types (f
, arg
);
1522 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1526 if (NILP (arg
) && NILP (oldval
))
1529 if (STRINGP (arg
) && STRINGP (oldval
)
1530 && EQ (Fstring_equal (oldval
, arg
), Qt
))
1533 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
1538 result
= x_bitmap_icon (f
, arg
);
1542 error ("No icon window available");
1549 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1553 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1556 else if (!NILP (arg
) || NILP (oldval
))
1559 fset_icon_name (f
, arg
);
1562 if (f
->output_data
.w32
->icon_bitmap
!= 0)
1567 result
= x_text_icon (f
,
1568 SSDATA ((!NILP (f
->icon_name
)
1577 error ("No icon window available");
1580 /* If the window was unmapped (and its icon was mapped),
1581 the new icon is not mapped, so map the window in its stead. */
1582 if (FRAME_VISIBLE_P (f
))
1584 #ifdef USE_X_TOOLKIT
1585 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
1587 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
1590 XFlush (FRAME_W32_DISPLAY (f
));
1596 x_clear_under_internal_border (struct frame
*f
)
1598 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1600 /* Clear border if it's larger than before. */
1603 HDC hdc
= get_frame_dc (f
);
1604 int width
= FRAME_PIXEL_WIDTH (f
);
1605 int height
= FRAME_PIXEL_HEIGHT (f
);
1608 w32_clear_area (f
, hdc
, 0, FRAME_TOP_MARGIN_HEIGHT (f
), width
, border
);
1609 w32_clear_area (f
, hdc
, 0, 0, border
, height
);
1610 w32_clear_area (f
, hdc
, width
- border
, 0, border
, height
);
1611 w32_clear_area (f
, hdc
, 0, height
- border
, width
, border
);
1612 release_frame_dc (f
, hdc
);
1619 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1623 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1624 border
= max (XINT (arg
), 0);
1626 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1628 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1630 if (FRAME_X_WINDOW (f
) != 0)
1632 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1634 if (FRAME_VISIBLE_P (f
))
1635 x_clear_under_internal_border (f
);
1642 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1646 /* Right now, menu bars don't work properly in minibuf-only frames;
1647 most of the commands try to apply themselves to the minibuffer
1648 frame itself, and get an error because you can't switch buffers
1649 in or split the minibuffer window. */
1650 if (FRAME_MINIBUF_ONLY_P (f
))
1653 if (INTEGERP (value
))
1654 nlines
= XINT (value
);
1658 FRAME_MENU_BAR_LINES (f
) = 0;
1659 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1662 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1663 windows_or_buffers_changed
= 23;
1667 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1668 free_frame_menubar (f
);
1669 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1671 /* Adjust the frame size so that the client (text) dimensions
1672 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1673 set correctly. Note that we resize twice: The first time upon
1674 a request from the window manager who wants to keep the height
1675 of the outer rectangle (including decorations) unchanged, and a
1676 second time because we want to keep the height of the inner
1677 rectangle (without the decorations unchanged). */
1678 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1680 /* Not sure whether this is needed. */
1681 x_clear_under_internal_border (f
);
1686 /* Set the number of lines used for the tool bar of frame F to VALUE.
1687 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL is
1688 the old number of tool bar lines (and is unused). This function may
1689 change the height of all windows on frame F to match the new tool bar
1690 height. By design, the frame's height doesn't change (but maybe it
1691 should if we don't get enough space otherwise). */
1694 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1698 /* Treat tool bars like menu bars. */
1699 if (FRAME_MINIBUF_ONLY_P (f
))
1702 /* Use VALUE only if an integer >= 0. */
1703 if (INTEGERP (value
) && XINT (value
) >= 0)
1704 nlines
= XFASTINT (value
);
1708 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1712 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1714 x_change_tool_bar_height (struct frame
*f
, int height
)
1717 int unit
= FRAME_LINE_HEIGHT (f
);
1718 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1719 int lines
= (height
+ unit
- 1) / unit
;
1720 int old_text_height
= FRAME_TEXT_HEIGHT (f
);
1721 Lisp_Object fullscreen
;
1723 /* Make sure we redisplay all windows in this frame. */
1724 windows_or_buffers_changed
= 23;
1726 /* Recalculate tool bar and frame text sizes. */
1727 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1728 FRAME_TOOL_BAR_LINES (f
) = lines
;
1729 /* Store `tool-bar-lines' and `height' frame parameters. */
1730 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1731 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1733 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1736 clear_current_matrices (f
);
1739 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1740 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1742 /* Recalculate toolbar height. */
1743 f
->n_tool_bar_rows
= 0;
1745 adjust_frame_size (f
, -1, -1,
1746 ((!f
->tool_bar_redisplayed_once
1747 && (NILP (fullscreen
=
1748 get_frame_param (f
, Qfullscreen
))
1749 || EQ (fullscreen
, Qfullwidth
))) ? 1
1750 : (old_height
== 0 || height
== 0) ? 2
1752 false, Qtool_bar_lines
);
1754 /* adjust_frame_size might not have done anything, garbage frame
1756 adjust_frame_glyphs (f
);
1757 SET_FRAME_GARBAGED (f
);
1758 if (FRAME_X_WINDOW (f
))
1759 x_clear_under_internal_border (f
);
1763 w32_set_title_bar_text (struct frame
*f
, Lisp_Object name
)
1765 if (FRAME_W32_WINDOW (f
))
1769 GUI_FN (SetWindowText
) (FRAME_W32_WINDOW (f
),
1770 GUI_SDATA (GUI_ENCODE_SYSTEM (name
)));
1772 /* The frame's title many times shows the name of the file
1773 visited in the selected window's buffer, so it makes sense to
1774 support non-ASCII characters outside of the current system
1775 codepage in the title. */
1776 if (w32_unicode_filenames
)
1778 Lisp_Object encoded_title
= ENCODE_UTF_8 (name
);
1780 int tlen
= pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
),
1785 /* Windows truncates the title text beyond what fits on
1786 a single line, so we can limit the length to some
1787 reasonably large value, and use alloca. */
1790 title_w
= alloca ((tlen
+ 1) * sizeof (wchar_t));
1791 pMultiByteToWideChar (CP_UTF8
, 0, SSDATA (encoded_title
), -1,
1793 title_w
[tlen
] = L
'\0';
1794 SetWindowTextW (FRAME_W32_WINDOW (f
), title_w
);
1796 else /* Conversion to UTF-16 failed, so we punt. */
1797 SetWindowTextA (FRAME_W32_WINDOW (f
),
1798 SSDATA (ENCODE_SYSTEM (name
)));
1801 SetWindowTextA (FRAME_W32_WINDOW (f
), SSDATA (ENCODE_SYSTEM (name
)));
1807 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1810 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1811 name; if NAME is a string, set F's name to NAME and set
1812 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1814 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1815 suggesting a new name, which lisp code should override; if
1816 F->explicit_name is set, ignore the new name; otherwise, set it. */
1819 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1821 /* Make sure that requests from lisp code override requests from
1822 Emacs redisplay code. */
1825 /* If we're switching from explicit to implicit, we had better
1826 update the mode lines and thereby update the title. */
1827 if (f
->explicit_name
&& NILP (name
))
1828 update_mode_lines
= 25;
1830 f
->explicit_name
= ! NILP (name
);
1832 else if (f
->explicit_name
)
1835 /* If NAME is nil, set the name to the w32_id_name. */
1838 /* Check for no change needed in this very common case
1839 before we do any consing. */
1840 if (!strcmp (FRAME_DISPLAY_INFO (f
)->w32_id_name
,
1843 name
= build_string (FRAME_DISPLAY_INFO (f
)->w32_id_name
);
1846 CHECK_STRING (name
);
1848 /* Don't change the name if it's already NAME. */
1849 if (! NILP (Fstring_equal (name
, f
->name
)))
1852 fset_name (f
, name
);
1854 /* For setting the frame title, the title parameter should override
1855 the name parameter. */
1856 if (! NILP (f
->title
))
1859 w32_set_title_bar_text (f
, name
);
1862 /* This function should be called when the user's lisp code has
1863 specified a name for the frame; the name will override any set by the
1866 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1868 x_set_name (f
, arg
, true);
1871 /* This function should be called by Emacs redisplay code to set the
1872 name; names set this way will never override names set by the user's
1875 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1877 x_set_name (f
, arg
, false);
1880 /* Change the title of frame F to NAME.
1881 If NAME is nil, use the frame name as the title. */
1884 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1886 /* Don't change the title if it's already NAME. */
1887 if (EQ (name
, f
->title
))
1890 update_mode_lines
= 26;
1892 fset_title (f
, name
);
1897 w32_set_title_bar_text (f
, name
);
1901 x_set_scroll_bar_default_width (struct frame
*f
)
1903 int unit
= FRAME_COLUMN_WIDTH (f
);
1905 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
1906 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
1907 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
1912 x_set_scroll_bar_default_height (struct frame
*f
)
1914 int unit
= FRAME_LINE_HEIGHT (f
);
1916 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
1917 FRAME_CONFIG_SCROLL_BAR_LINES (f
)
1918 = (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) + unit
- 1) / unit
;
1921 /* Subroutines for creating a frame. */
1924 w32_load_cursor (LPCTSTR name
)
1926 /* Try first to load cursor from application resource. */
1927 Cursor cursor
= LoadImage ((HINSTANCE
) GetModuleHandle (NULL
),
1928 name
, IMAGE_CURSOR
, 0, 0,
1929 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1932 /* Then try to load a shared predefined cursor. */
1933 cursor
= LoadImage (NULL
, name
, IMAGE_CURSOR
, 0, 0,
1934 LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
| LR_SHARED
);
1939 static LRESULT CALLBACK
w32_wnd_proc (HWND
, UINT
, WPARAM
, LPARAM
);
1941 #define INIT_WINDOW_CLASS(WC) \
1942 (WC).style = CS_HREDRAW | CS_VREDRAW; \
1943 (WC).lpfnWndProc = (WNDPROC) w32_wnd_proc; \
1944 (WC).cbClsExtra = 0; \
1945 (WC).cbWndExtra = WND_EXTRA_BYTES; \
1946 (WC).hInstance = hinst; \
1947 (WC).hIcon = LoadIcon (hinst, EMACS_CLASS); \
1948 (WC).hCursor = w32_load_cursor (IDC_ARROW); \
1949 (WC).hbrBackground = NULL; \
1950 (WC).lpszMenuName = NULL; \
1953 w32_init_class (HINSTANCE hinst
)
1955 if (w32_unicode_gui
)
1958 INIT_WINDOW_CLASS(uwc
);
1959 uwc
.lpszClassName
= L
"Emacs";
1961 return RegisterClassW (&uwc
);
1966 INIT_WINDOW_CLASS(wc
);
1967 wc
.lpszClassName
= EMACS_CLASS
;
1969 return RegisterClassA (&wc
);
1974 w32_createvscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1976 return CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
1977 /* Position and size of scroll bar. */
1978 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
1979 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
1983 w32_createhscrollbar (struct frame
*f
, struct scroll_bar
* bar
)
1985 return CreateWindow ("SCROLLBAR", "", SBS_HORZ
| WS_CHILD
| WS_VISIBLE
,
1986 /* Position and size of scroll bar. */
1987 bar
->left
, bar
->top
, bar
->width
, bar
->height
,
1988 FRAME_W32_WINDOW (f
), NULL
, hinst
, NULL
);
1992 w32_createwindow (struct frame
*f
, int *coords
)
1999 rect
.left
= rect
.top
= 0;
2000 rect
.right
= FRAME_PIXEL_WIDTH (f
);
2001 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
2003 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
2004 FRAME_EXTERNAL_MENU_BAR (f
));
2006 /* Do first time app init */
2008 w32_init_class (hinst
);
2010 if (f
->size_hint_flags
& USPosition
|| f
->size_hint_flags
& PPosition
)
2021 FRAME_W32_WINDOW (f
) = hwnd
2022 = CreateWindow (EMACS_CLASS
,
2024 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
2026 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2034 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
2035 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
2036 SetWindowLong (hwnd
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
2037 SetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_WIDTH (f
));
2038 SetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
, FRAME_SCROLL_BAR_AREA_HEIGHT (f
));
2039 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
2041 /* Enable drag-n-drop. */
2042 DragAcceptFiles (hwnd
, TRUE
);
2044 /* Do this to discard the default setting specified by our parent. */
2045 ShowWindow (hwnd
, SW_HIDE
);
2047 /* Update frame positions. */
2048 GetWindowRect (hwnd
, &rect
);
2049 f
->left_pos
= rect
.left
;
2050 f
->top_pos
= rect
.top
;
2055 my_post_msg (W32Msg
* wmsg
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2057 wmsg
->msg
.hwnd
= hwnd
;
2058 wmsg
->msg
.message
= msg
;
2059 wmsg
->msg
.wParam
= wParam
;
2060 wmsg
->msg
.lParam
= lParam
;
2061 wmsg
->msg
.time
= GetMessageTime ();
2066 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
2067 between left and right keys as advertised. We test for this
2068 support dynamically, and set a flag when the support is absent. If
2069 absent, we keep track of the left and right control and alt keys
2070 ourselves. This is particularly necessary on keyboards that rely
2071 upon the AltGr key, which is represented as having the left control
2072 and right alt keys pressed. For these keyboards, we need to know
2073 when the left alt key has been pressed in addition to the AltGr key
2074 so that we can properly support M-AltGr-key sequences (such as M-@
2075 on Swedish keyboards). */
2077 #define EMACS_LCONTROL 0
2078 #define EMACS_RCONTROL 1
2079 #define EMACS_LMENU 2
2080 #define EMACS_RMENU 3
2082 static int modifiers
[4];
2083 static int modifiers_recorded
;
2084 static int modifier_key_support_tested
;
2087 test_modifier_support (unsigned int wparam
)
2091 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
2093 if (wparam
== VK_CONTROL
)
2103 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
2104 modifiers_recorded
= 1;
2106 modifiers_recorded
= 0;
2107 modifier_key_support_tested
= 1;
2111 record_keydown (unsigned int wparam
, unsigned int lparam
)
2115 if (!modifier_key_support_tested
)
2116 test_modifier_support (wparam
);
2118 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2121 if (wparam
== VK_CONTROL
)
2122 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2124 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2130 record_keyup (unsigned int wparam
, unsigned int lparam
)
2134 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
2137 if (wparam
== VK_CONTROL
)
2138 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
2140 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
2145 /* Emacs can lose focus while a modifier key has been pressed. When
2146 it regains focus, be conservative and clear all modifiers since
2147 we cannot reconstruct the left and right modifier state. */
2149 reset_modifiers (void)
2153 if (GetFocus () == NULL
)
2154 /* Emacs doesn't have keyboard focus. Do nothing. */
2157 ctrl
= GetAsyncKeyState (VK_CONTROL
);
2158 alt
= GetAsyncKeyState (VK_MENU
);
2160 if (!(ctrl
& 0x08000))
2161 /* Clear any recorded control modifier state. */
2162 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2164 if (!(alt
& 0x08000))
2165 /* Clear any recorded alt modifier state. */
2166 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2168 /* Update the state of all modifier keys, because modifiers used in
2169 hot-key combinations can get stuck on if Emacs loses focus as a
2170 result of a hot-key being pressed. */
2174 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
2176 memset (keystate
, 0, sizeof (keystate
));
2177 GetKeyboardState (keystate
);
2178 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
2179 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
2180 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
2181 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
2182 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
2183 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
2184 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
2185 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
2186 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
2187 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
2188 SetKeyboardState (keystate
);
2192 /* Synchronize modifier state with what is reported with the current
2193 keystroke. Even if we cannot distinguish between left and right
2194 modifier keys, we know that, if no modifiers are set, then neither
2195 the left or right modifier should be set. */
2197 sync_modifiers (void)
2199 if (!modifiers_recorded
)
2202 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
2203 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
2205 if (!(GetKeyState (VK_MENU
) & 0x8000))
2206 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
2210 modifier_set (int vkey
)
2212 /* Warning: The fact that VK_NUMLOCK is not treated as the other 2
2213 toggle keys is not an omission! If you want to add it, you will
2214 have to make changes in the default sub-case of the WM_KEYDOWN
2215 switch, because if the NUMLOCK modifier is set, the code there
2216 will directly convert any key that looks like an ASCII letter,
2217 and also downcase those that look like upper-case ASCII. */
2218 if (vkey
== VK_CAPITAL
)
2220 if (NILP (Vw32_enable_caps_lock
))
2223 return (GetKeyState (vkey
) & 0x1);
2225 if (vkey
== VK_SCROLL
)
2227 if (NILP (Vw32_scroll_lock_modifier
)
2228 /* w32-scroll-lock-modifier can be any non-nil value that is
2229 not one of the modifiers, in which case it shall be ignored. */
2230 || !( EQ (Vw32_scroll_lock_modifier
, Qhyper
)
2231 || EQ (Vw32_scroll_lock_modifier
, Qsuper
)
2232 || EQ (Vw32_scroll_lock_modifier
, Qmeta
)
2233 || EQ (Vw32_scroll_lock_modifier
, Qalt
)
2234 || EQ (Vw32_scroll_lock_modifier
, Qcontrol
)
2235 || EQ (Vw32_scroll_lock_modifier
, Qshift
)))
2238 return (GetKeyState (vkey
) & 0x1);
2241 if (!modifiers_recorded
)
2242 return (GetKeyState (vkey
) & 0x8000);
2247 return modifiers
[EMACS_LCONTROL
];
2249 return modifiers
[EMACS_RCONTROL
];
2251 return modifiers
[EMACS_LMENU
];
2253 return modifiers
[EMACS_RMENU
];
2255 return (GetKeyState (vkey
) & 0x8000);
2258 /* Convert between the modifier bits W32 uses and the modifier bits
2262 w32_key_to_modifier (int key
)
2264 Lisp_Object key_mapping
;
2269 key_mapping
= Vw32_lwindow_modifier
;
2272 key_mapping
= Vw32_rwindow_modifier
;
2275 key_mapping
= Vw32_apps_modifier
;
2278 key_mapping
= Vw32_scroll_lock_modifier
;
2284 /* NB. This code runs in the input thread, asynchronously to the lisp
2285 thread, so we must be careful to ensure access to lisp data is
2286 thread-safe. The following code is safe because the modifier
2287 variable values are updated atomically from lisp and symbols are
2288 not relocated by GC. Also, we don't have to worry about seeing GC
2290 if (EQ (key_mapping
, Qhyper
))
2291 return hyper_modifier
;
2292 if (EQ (key_mapping
, Qsuper
))
2293 return super_modifier
;
2294 if (EQ (key_mapping
, Qmeta
))
2295 return meta_modifier
;
2296 if (EQ (key_mapping
, Qalt
))
2297 return alt_modifier
;
2298 if (EQ (key_mapping
, Qctrl
))
2299 return ctrl_modifier
;
2300 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
2301 return ctrl_modifier
;
2302 if (EQ (key_mapping
, Qshift
))
2303 return shift_modifier
;
2305 /* Don't generate any modifier if not explicitly requested. */
2310 w32_get_modifiers (void)
2312 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
2313 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
2314 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
2315 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
2316 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
2317 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
2318 (modifier_set (VK_MENU
) ?
2319 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
2322 /* We map the VK_* modifiers into console modifier constants
2323 so that we can use the same routines to handle both console
2324 and window input. */
2327 construct_console_modifiers (void)
2332 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
2333 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
2334 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
2335 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
2336 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
2337 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
2338 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
2339 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
2340 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
2341 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
2342 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
2348 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
2352 /* Convert to emacs modifiers. */
2353 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
2359 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
2361 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
2364 if (virt_key
== VK_RETURN
)
2365 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
2367 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
2368 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
2370 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
2371 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
2373 if (virt_key
== VK_CLEAR
)
2374 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
2379 /* List of special key combinations which w32 would normally capture,
2380 but Emacs should grab instead. Not directly visible to lisp, to
2381 simplify synchronization. Each item is an integer encoding a virtual
2382 key code and modifier combination to capture. */
2383 static Lisp_Object w32_grabbed_keys
;
2385 #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
2386 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
2387 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
2388 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
2390 #define RAW_HOTKEY_ID(k) ((k) & 0xbfff)
2391 #define RAW_HOTKEY_VK_CODE(k) ((k) & 255)
2392 #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8)
2394 /* Register hot-keys for reserved key combinations when Emacs has
2395 keyboard focus, since this is the only way Emacs can receive key
2396 combinations like Alt-Tab which are used by the system. */
2399 register_hot_keys (HWND hwnd
)
2401 Lisp_Object keylist
;
2403 /* Use CONSP, since we are called asynchronously. */
2404 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2406 Lisp_Object key
= XCAR (keylist
);
2408 /* Deleted entries get set to nil. */
2409 if (!INTEGERP (key
))
2412 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
2413 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
2418 unregister_hot_keys (HWND hwnd
)
2420 Lisp_Object keylist
;
2422 for (keylist
= w32_grabbed_keys
; CONSP (keylist
); keylist
= XCDR (keylist
))
2424 Lisp_Object key
= XCAR (keylist
);
2426 if (!INTEGERP (key
))
2429 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
2435 w32_name_of_message (UINT msg
)
2438 static char buf
[64];
2439 static const struct {
2443 #define M(msg) { msg, # msg }
2451 M (WM_EMACS_CREATEWINDOW
),
2453 M (WM_EMACS_CREATEVSCROLLBAR
),
2454 M (WM_EMACS_CREATEHSCROLLBAR
),
2455 M (WM_EMACS_SHOWWINDOW
),
2456 M (WM_EMACS_SETWINDOWPOS
),
2457 M (WM_EMACS_DESTROYWINDOW
),
2458 M (WM_EMACS_TRACKPOPUPMENU
),
2459 M (WM_EMACS_SETFOCUS
),
2460 M (WM_EMACS_SETFOREGROUND
),
2461 M (WM_EMACS_SETLOCALE
),
2462 M (WM_EMACS_SETKEYBOARDLAYOUT
),
2463 M (WM_EMACS_REGISTER_HOT_KEY
),
2464 M (WM_EMACS_UNREGISTER_HOT_KEY
),
2465 M (WM_EMACS_TOGGLE_LOCK_KEY
),
2466 M (WM_EMACS_TRACK_CARET
),
2467 M (WM_EMACS_DESTROY_CARET
),
2468 M (WM_EMACS_SHOW_CARET
),
2469 M (WM_EMACS_HIDE_CARET
),
2470 M (WM_EMACS_SETCURSOR
),
2471 M (WM_EMACS_SHOWCURSOR
),
2478 for (i
= 0; msgnames
[i
].name
; ++i
)
2479 if (msgnames
[i
].msg
== msg
)
2480 return msgnames
[i
].name
;
2482 sprintf (buf
, "message 0x%04x", (unsigned)msg
);
2485 #endif /* EMACSDEBUG */
2487 /* Here's an overview of how Emacs input works in GUI sessions on
2488 MS-Windows. (For description of non-GUI input, see the commentary
2489 before w32_console_read_socket in w32inevt.c.)
2491 System messages are read and processed by w32_msg_pump below. This
2492 function runs in a separate thread. It handles a small number of
2493 custom WM_EMACS_* messages (posted by the main thread, look for
2494 PostMessage calls), and dispatches the rest to w32_wnd_proc, which
2495 is the main window procedure for the entire Emacs application.
2497 w32_wnd_proc also runs in the same separate input thread. It
2498 handles some messages, mostly those that need GDI calls, by itself.
2499 For the others, it calls my_post_msg, which inserts the messages
2500 into the input queue serviced by w32_read_socket.
2502 w32_read_socket runs in the main (a.k.a. "Lisp") thread, and is
2503 called synchronously from keyboard.c when it is known or suspected
2504 that some input is available. w32_read_socket either handles
2505 messages immediately, or converts them into Emacs input events and
2506 stuffs them into kbd_buffer, where kbd_buffer_get_event can get at
2507 them and process them when read_char and its callers require
2510 Under Cygwin with the W32 toolkit, the use of /dev/windows with
2511 select(2) takes the place of w32_read_socket.
2515 /* Main message dispatch loop. */
2518 w32_msg_pump (deferred_msg
* msg_buf
)
2524 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
2526 while ((w32_unicode_gui
? GetMessageW
: GetMessageA
) (&msg
, NULL
, 0, 0))
2529 /* DebPrint (("w32_msg_pump: %s time:%u\n", */
2530 /* w32_name_of_message (msg.message), msg.time)); */
2532 if (msg
.hwnd
== NULL
)
2534 switch (msg
.message
)
2537 /* Produced by complete_deferred_msg; just ignore. */
2539 case WM_EMACS_CREATEWINDOW
:
2540 /* Initialize COM for this window. Even though we don't use it,
2541 some third party shell extensions can cause it to be used in
2542 system dialogs, which causes a crash if it is not initialized.
2543 This is a known bug in Windows, which was fixed long ago, but
2544 the patch for XP is not publicly available until XP SP3,
2545 and older versions will never be patched. */
2546 CoInitialize (NULL
);
2547 w32_createwindow ((struct frame
*) msg
.wParam
,
2548 (int *) msg
.lParam
);
2549 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2552 case WM_EMACS_SETLOCALE
:
2553 SetThreadLocale (msg
.wParam
);
2554 /* Reply is not expected. */
2556 case WM_EMACS_SETKEYBOARDLAYOUT
:
2557 result
= (WPARAM
) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
2558 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2562 case WM_EMACS_REGISTER_HOT_KEY
:
2563 focus_window
= GetFocus ();
2564 if (focus_window
!= NULL
)
2565 RegisterHotKey (focus_window
,
2566 RAW_HOTKEY_ID (msg
.wParam
),
2567 RAW_HOTKEY_MODIFIERS (msg
.wParam
),
2568 RAW_HOTKEY_VK_CODE (msg
.wParam
));
2569 /* Reply is not expected. */
2571 case WM_EMACS_UNREGISTER_HOT_KEY
:
2572 focus_window
= GetFocus ();
2573 if (focus_window
!= NULL
)
2574 UnregisterHotKey (focus_window
, RAW_HOTKEY_ID (msg
.wParam
));
2575 /* Mark item as erased. NB: this code must be
2576 thread-safe. The next line is okay because the cons
2577 cell is never made into garbage and is not relocated by
2579 XSETCAR (make_lisp_ptr ((void *)msg
.lParam
, Lisp_Cons
), Qnil
);
2580 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2583 case WM_EMACS_TOGGLE_LOCK_KEY
:
2585 int vk_code
= (int) msg
.wParam
;
2586 int cur_state
= (GetKeyState (vk_code
) & 1);
2587 int new_state
= msg
.lParam
;
2590 || ((new_state
& 1) != cur_state
))
2592 one_w32_display_info
.faked_key
= vk_code
;
2594 keybd_event ((BYTE
) vk_code
,
2595 (BYTE
) MapVirtualKey (vk_code
, 0),
2596 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2597 keybd_event ((BYTE
) vk_code
,
2598 (BYTE
) MapVirtualKey (vk_code
, 0),
2599 KEYEVENTF_EXTENDEDKEY
| 0, 0);
2600 keybd_event ((BYTE
) vk_code
,
2601 (BYTE
) MapVirtualKey (vk_code
, 0),
2602 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
2603 cur_state
= !cur_state
;
2605 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
2611 /* Broadcast messages make it here, so you need to be looking
2612 for something in particular for this to be useful. */
2614 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
2620 if (w32_unicode_gui
)
2621 DispatchMessageW (&msg
);
2623 DispatchMessageA (&msg
);
2626 /* Exit nested loop when our deferred message has completed. */
2627 if (msg_buf
->completed
)
2632 deferred_msg
* deferred_msg_head
;
2634 static deferred_msg
*
2635 find_deferred_msg (HWND hwnd
, UINT msg
)
2637 deferred_msg
* item
;
2639 /* Don't actually need synchronization for read access, since
2640 modification of single pointer is always atomic. */
2641 /* enter_crit (); */
2643 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2644 if (item
->w32msg
.msg
.hwnd
== hwnd
2645 && item
->w32msg
.msg
.message
== msg
)
2648 /* leave_crit (); */
2654 send_deferred_msg (deferred_msg
* msg_buf
,
2660 /* Only input thread can send deferred messages. */
2661 if (GetCurrentThreadId () != dwWindowsThreadId
)
2664 /* It is an error to send a message that is already deferred. */
2665 if (find_deferred_msg (hwnd
, msg
) != NULL
)
2668 /* Enforced synchronization is not needed because this is the only
2669 function that alters deferred_msg_head, and the following critical
2670 section is guaranteed to only be serially reentered (since only the
2671 input thread can call us). */
2673 /* enter_crit (); */
2675 msg_buf
->completed
= 0;
2676 msg_buf
->next
= deferred_msg_head
;
2677 deferred_msg_head
= msg_buf
;
2678 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
2680 /* leave_crit (); */
2682 /* Start a new nested message loop to process other messages until
2683 this one is completed. */
2684 w32_msg_pump (msg_buf
);
2686 deferred_msg_head
= msg_buf
->next
;
2688 return msg_buf
->result
;
2692 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
2694 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
2696 if (msg_buf
== NULL
)
2697 /* Message may have been canceled, so don't abort. */
2700 msg_buf
->result
= result
;
2701 msg_buf
->completed
= 1;
2703 /* Ensure input thread is woken so it notices the completion. */
2704 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2708 cancel_all_deferred_msgs (void)
2710 deferred_msg
* item
;
2712 /* Don't actually need synchronization for read access, since
2713 modification of single pointer is always atomic. */
2714 /* enter_crit (); */
2716 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
2719 item
->completed
= 1;
2722 /* leave_crit (); */
2724 /* Ensure input thread is woken so it notices the completion. */
2725 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
2729 w32_msg_worker (void *arg
)
2732 deferred_msg dummy_buf
;
2734 /* Ensure our message queue is created */
2736 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
2738 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
2741 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
2742 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
2743 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
2745 /* This is the initial message loop which should only exit when the
2746 application quits. */
2747 w32_msg_pump (&dummy_buf
);
2753 signal_user_input (void)
2755 /* Interrupt any lisp that wants to be interrupted by input. */
2756 if (!NILP (Vthrow_on_input
))
2758 Vquit_flag
= Vthrow_on_input
;
2759 /* Doing a QUIT from this thread is a bad idea, since this
2760 unwinds the stack of the Lisp thread, and the Windows runtime
2761 rightfully barfs. Disabled. */
2763 /* If we're inside a function that wants immediate quits,
2765 if (immediate_quit
&& NILP (Vinhibit_quit
))
2776 post_character_message (HWND hwnd
, UINT msg
,
2777 WPARAM wParam
, LPARAM lParam
,
2782 wmsg
.dwModifiers
= modifiers
;
2784 /* Detect quit_char and set quit-flag directly. Note that we
2785 still need to post a message to ensure the main thread will be
2786 woken up if blocked in sys_select, but we do NOT want to post
2787 the quit_char message itself (because it will usually be as if
2788 the user had typed quit_char twice). Instead, we post a dummy
2789 message that has no particular effect. */
2792 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
2793 c
= make_ctrl_char (c
) & 0377;
2795 || (wmsg
.dwModifiers
== 0
2796 && w32_quit_key
&& wParam
== w32_quit_key
))
2800 /* The choice of message is somewhat arbitrary, as long as
2801 the main thread handler just ignores it. */
2804 /* Interrupt any blocking system calls. */
2807 /* As a safety precaution, forcibly complete any deferred
2808 messages. This is a kludge, but I don't see any particularly
2809 clean way to handle the situation where a deferred message is
2810 "dropped" in the lisp thread, and will thus never be
2811 completed, eg. by the user trying to activate the menubar
2812 when the lisp thread is busy, and then typing C-g when the
2813 menubar doesn't open promptly (with the result that the
2814 menubar never responds at all because the deferred
2815 WM_INITMENU message is never completed). Another problem
2816 situation is when the lisp thread calls SendMessage (to send
2817 a window manager command) when a message has been deferred;
2818 the lisp thread gets blocked indefinitely waiting for the
2819 deferred message to be completed, which itself is waiting for
2820 the lisp thread to respond.
2822 Note that we don't want to block the input thread waiting for
2823 a response from the lisp thread (although that would at least
2824 solve the deadlock problem above), because we want to be able
2825 to receive C-g to interrupt the lisp thread. */
2826 cancel_all_deferred_msgs ();
2829 signal_user_input ();
2832 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2835 /* Main window procedure */
2837 static LRESULT CALLBACK
2838 w32_wnd_proc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2841 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
2843 int windows_translate
;
2846 /* Note that it is okay to call x_window_to_frame, even though we are
2847 not running in the main lisp thread, because frame deletion
2848 requires the lisp thread to synchronize with this thread. Thus, if
2849 a frame struct is returned, it can be used without concern that the
2850 lisp thread might make it disappear while we are using it.
2852 NB. Walking the frame list in this thread is safe (as long as
2853 writes of Lisp_Object slots are atomic, which they are on Windows).
2854 Although delete-frame can destructively modify the frame list while
2855 we are walking it, a garbage collection cannot occur until after
2856 delete-frame has synchronized with this thread.
2858 It is also safe to use functions that make GDI calls, such as
2859 w32_clear_rect, because these functions must obtain a DC handle
2860 from the frame struct using get_frame_dc which is thread-aware. */
2865 f
= x_window_to_frame (dpyinfo
, hwnd
);
2868 HDC hdc
= get_frame_dc (f
);
2869 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
2870 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
2871 release_frame_dc (f
, hdc
);
2873 #if defined (W32_DEBUG_DISPLAY)
2874 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
2876 wmsg
.rect
.left
, wmsg
.rect
.top
,
2877 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2878 #endif /* W32_DEBUG_DISPLAY */
2881 case WM_PALETTECHANGED
:
2882 /* ignore our own changes */
2883 if ((HWND
)wParam
!= hwnd
)
2885 f
= x_window_to_frame (dpyinfo
, hwnd
);
2887 /* get_frame_dc will realize our palette and force all
2888 frames to be redrawn if needed. */
2889 release_frame_dc (f
, get_frame_dc (f
));
2894 PAINTSTRUCT paintStruct
;
2896 memset (&update_rect
, 0, sizeof (update_rect
));
2898 f
= x_window_to_frame (dpyinfo
, hwnd
);
2901 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
2905 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
2906 fails. Apparently this can happen under some
2908 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
2911 BeginPaint (hwnd
, &paintStruct
);
2913 /* The rectangles returned by GetUpdateRect and BeginPaint
2914 do not always match. Play it safe by assuming both areas
2916 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
2918 #if defined (W32_DEBUG_DISPLAY)
2919 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
2921 wmsg
.rect
.left
, wmsg
.rect
.top
,
2922 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
2923 DebPrint ((" [update region is %d,%d-%d,%d]\n",
2924 update_rect
.left
, update_rect
.top
,
2925 update_rect
.right
, update_rect
.bottom
));
2927 EndPaint (hwnd
, &paintStruct
);
2930 /* Change the message type to prevent Windows from
2931 combining WM_PAINT messages in the Lisp thread's queue,
2932 since Windows assumes that each message queue is
2933 dedicated to one frame and does not bother checking
2934 that hwnd matches before combining them. */
2935 my_post_msg (&wmsg
, hwnd
, WM_EMACS_PAINT
, wParam
, lParam
);
2940 /* If GetUpdateRect returns 0 (meaning there is no update
2941 region), assume the whole window needs to be repainted. */
2942 GetClientRect (hwnd
, &wmsg
.rect
);
2943 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2947 case WM_INPUTLANGCHANGE
:
2948 /* Inform lisp thread of keyboard layout changes. */
2949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
2951 /* Clear dead keys in the keyboard state; for simplicity only
2952 preserve modifier key states. */
2957 GetKeyboardState (keystate
);
2958 for (i
= 0; i
< 256; i
++)
2975 SetKeyboardState (keystate
);
2980 /* Synchronize hot keys with normal input. */
2981 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
2986 record_keyup (wParam
, lParam
);
2991 /* Ignore keystrokes we fake ourself; see below. */
2992 if (dpyinfo
->faked_key
== wParam
)
2994 dpyinfo
->faked_key
= 0;
2995 /* Make sure TranslateMessage sees them though (as long as
2996 they don't produce WM_CHAR messages). This ensures that
2997 indicator lights are toggled promptly on Windows 9x, for
2999 if (wParam
< 256 && lispy_function_keys
[wParam
])
3001 windows_translate
= 1;
3007 /* Synchronize modifiers with current keystroke. */
3009 record_keydown (wParam
, lParam
);
3010 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
3012 windows_translate
= 0;
3017 if (NILP (Vw32_pass_lwindow_to_system
))
3019 /* Prevent system from acting on keyup (which opens the
3020 Start menu if no other key was pressed) by simulating a
3021 press of Space which we will ignore. */
3022 if (GetAsyncKeyState (wParam
) & 1)
3024 if (NUMBERP (Vw32_phantom_key_code
))
3025 key
= XUINT (Vw32_phantom_key_code
) & 255;
3028 dpyinfo
->faked_key
= key
;
3029 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3032 if (!NILP (Vw32_lwindow_modifier
))
3036 if (NILP (Vw32_pass_rwindow_to_system
))
3038 if (GetAsyncKeyState (wParam
) & 1)
3040 if (NUMBERP (Vw32_phantom_key_code
))
3041 key
= XUINT (Vw32_phantom_key_code
) & 255;
3044 dpyinfo
->faked_key
= key
;
3045 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
3048 if (!NILP (Vw32_rwindow_modifier
))
3052 if (!NILP (Vw32_apps_modifier
))
3056 if (NILP (Vw32_pass_alt_to_system
))
3057 /* Prevent DefWindowProc from activating the menu bar if an
3058 Alt key is pressed and released by itself. */
3060 windows_translate
= 1;
3063 /* Decide whether to treat as modifier or function key. */
3064 if (NILP (Vw32_enable_caps_lock
))
3065 goto disable_lock_key
;
3066 windows_translate
= 1;
3069 /* Decide whether to treat as modifier or function key. */
3070 if (NILP (Vw32_enable_num_lock
))
3071 goto disable_lock_key
;
3072 windows_translate
= 1;
3075 /* Decide whether to treat as modifier or function key. */
3076 if (NILP (Vw32_scroll_lock_modifier
))
3077 goto disable_lock_key
;
3078 windows_translate
= 1;
3081 /* Ensure the appropriate lock key state (and indicator light)
3082 remains in the same state. We do this by faking another
3083 press of the relevant key. Apparently, this really is the
3084 only way to toggle the state of the indicator lights. */
3085 dpyinfo
->faked_key
= wParam
;
3086 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3087 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3088 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3089 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3090 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
3091 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3092 /* Ensure indicator lights are updated promptly on Windows 9x
3093 (TranslateMessage apparently does this), after forwarding
3095 post_character_message (hwnd
, msg
, wParam
, lParam
,
3096 w32_get_key_modifiers (wParam
, lParam
));
3097 windows_translate
= 1;
3101 case VK_PROCESSKEY
: /* Generated by IME. */
3102 windows_translate
= 1;
3105 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
3106 which is confusing for purposes of key binding; convert
3107 VK_CANCEL events into VK_PAUSE events. */
3111 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
3112 for purposes of key binding; convert these back into
3113 VK_NUMLOCK events, at least when we want to see NumLock key
3114 presses. (Note that there is never any possibility that
3115 VK_PAUSE with Ctrl really is C-Pause as per above.) */
3116 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
3117 wParam
= VK_NUMLOCK
;
3120 /* If not defined as a function key, change it to a WM_CHAR message. */
3121 if (wParam
> 255 || !lispy_function_keys
[wParam
])
3123 DWORD modifiers
= construct_console_modifiers ();
3125 if (!NILP (Vw32_recognize_altgr
)
3126 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
3128 /* Always let TranslateMessage handle AltGr key chords;
3129 for some reason, ToAscii doesn't always process AltGr
3130 chords correctly. */
3131 windows_translate
= 1;
3133 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
3135 /* Handle key chords including any modifiers other
3136 than shift directly, in order to preserve as much
3137 modifier information as possible. */
3138 if ('A' <= wParam
&& wParam
<= 'Z')
3140 /* Don't translate modified alphabetic keystrokes,
3141 so the user doesn't need to constantly switch
3142 layout to type control or meta keystrokes when
3143 the normal layout translates alphabetic
3144 characters to non-ascii characters. */
3145 if (!modifier_set (VK_SHIFT
))
3146 wParam
+= ('a' - 'A');
3151 /* Try to handle other keystrokes by determining the
3152 base character (ie. translating the base key plus
3155 KEY_EVENT_RECORD key
;
3157 key
.bKeyDown
= TRUE
;
3158 key
.wRepeatCount
= 1;
3159 key
.wVirtualKeyCode
= wParam
;
3160 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
3161 key
.uChar
.AsciiChar
= 0;
3162 key
.dwControlKeyState
= modifiers
;
3164 add
= w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3165 /* 0 means an unrecognized keycode, negative means
3166 dead key. Ignore both. */
3169 /* Forward asciified character sequence. */
3170 post_character_message
3172 (unsigned char) key
.uChar
.AsciiChar
, lParam
,
3173 w32_get_key_modifiers (wParam
, lParam
));
3174 w32_kbd_patch_key (&key
, w32_keyboard_codepage
);
3181 /* Let TranslateMessage handle everything else. */
3182 windows_translate
= 1;
3188 if (windows_translate
)
3190 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
3191 windows_msg
.time
= GetMessageTime ();
3192 TranslateMessage (&windows_msg
);
3204 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3205 signal_user_input ();
3206 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, wParam
, lParam
);
3210 post_character_message (hwnd
, msg
, wParam
, lParam
,
3211 w32_get_key_modifiers (wParam
, lParam
));
3215 /* WM_UNICHAR looks promising from the docs, but the exact
3216 circumstances in which TranslateMessage sends it is one of those
3217 Microsoft secret API things that EU and US courts are supposed
3218 to have put a stop to already. Spy++ shows it being sent to Notepad
3219 and other MS apps, but never to Emacs.
3221 Some third party IMEs send it in accordance with the official
3222 documentation though, so handle it here.
3224 UNICODE_NOCHAR is used to test for support for this message.
3225 TRUE indicates that the message is supported. */
3226 if (wParam
== UNICODE_NOCHAR
)
3231 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3232 signal_user_input ();
3233 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3238 /* If we can't get the IME result as Unicode, use default processing,
3239 which will at least allow characters decodable in the system locale
3241 if (!get_composition_string_fn
)
3244 else if (!ignore_ime_char
)
3249 HIMC context
= get_ime_context_fn (hwnd
);
3250 wmsg
.dwModifiers
= w32_get_key_modifiers (wParam
, lParam
);
3251 /* Get buffer size. */
3252 size
= get_composition_string_fn (context
, GCS_RESULTSTR
, NULL
, 0);
3253 buffer
= alloca (size
);
3254 size
= get_composition_string_fn (context
, GCS_RESULTSTR
,
3256 release_ime_context_fn (hwnd
, context
);
3258 signal_user_input ();
3259 for (i
= 0; i
< size
/ sizeof (wchar_t); i
++)
3261 my_post_msg (&wmsg
, hwnd
, WM_UNICHAR
, (WPARAM
) buffer
[i
],
3264 /* Ignore the messages for the rest of the
3265 characters in the string that was output above. */
3266 ignore_ime_char
= (size
/ sizeof (wchar_t)) - 1;
3273 case WM_IME_STARTCOMPOSITION
:
3274 if (!set_ime_composition_window_fn
)
3278 COMPOSITIONFORM form
;
3282 /* Implementation note: The code below does something that
3283 one shouldn't do: it accesses the window object from a
3284 separate thread, while the main (a.k.a. "Lisp") thread
3285 runs and can legitimately delete and even GC it. That is
3286 why we are extra careful not to futz with a window that
3287 is different from the one recorded when the system caret
3288 coordinates were last modified. That is also why we are
3289 careful not to move the IME window if the window
3290 described by W was deleted, as indicated by its buffer
3291 field being reset to nil. */
3292 f
= x_window_to_frame (dpyinfo
, hwnd
);
3293 if (!(f
&& FRAME_LIVE_P (f
)))
3295 w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
3296 /* Punt if someone changed the frame's selected window
3298 if (w
!= w32_system_caret_window
)
3301 form
.dwStyle
= CFS_RECT
;
3302 form
.ptCurrentPos
.x
= w32_system_caret_x
;
3303 form
.ptCurrentPos
.y
= w32_system_caret_y
;
3305 form
.rcArea
.left
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, 0);
3306 form
.rcArea
.top
= (WINDOW_TOP_EDGE_Y (w
)
3307 + w32_system_caret_hdr_height
);
3308 form
.rcArea
.right
= (WINDOW_BOX_RIGHT_EDGE_X (w
)
3309 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
3310 - WINDOW_RIGHT_FRINGE_WIDTH (w
));
3311 form
.rcArea
.bottom
= (WINDOW_BOTTOM_EDGE_Y (w
)
3312 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
3313 - w32_system_caret_mode_height
);
3315 /* Punt if the window was deleted behind our back. */
3316 if (!BUFFERP (w
->contents
))
3319 context
= get_ime_context_fn (hwnd
);
3324 set_ime_composition_window_fn (context
, &form
);
3325 release_ime_context_fn (hwnd
, context
);
3327 /* Pass WM_IME_STARTCOMPOSITION to DefWindowProc, so that the
3328 composition window will actually be displayed. */
3331 case WM_IME_ENDCOMPOSITION
:
3332 ignore_ime_char
= 0;
3335 /* Simulate middle mouse button events when left and right buttons
3336 are used together, but only if user has two button mouse. */
3337 case WM_LBUTTONDOWN
:
3338 case WM_RBUTTONDOWN
:
3339 if (w32_num_mouse_buttons
> 2)
3340 goto handle_plain_button
;
3343 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
3344 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
3346 if (button_state
& this)
3349 if (button_state
== 0)
3352 button_state
|= this;
3354 if (button_state
& other
)
3356 if (mouse_button_timer
)
3358 KillTimer (hwnd
, mouse_button_timer
);
3359 mouse_button_timer
= 0;
3361 /* Generate middle mouse event instead. */
3362 msg
= WM_MBUTTONDOWN
;
3363 button_state
|= MMOUSE
;
3365 else if (button_state
& MMOUSE
)
3367 /* Ignore button event if we've already generated a
3368 middle mouse down event. This happens if the
3369 user releases and press one of the two buttons
3370 after we've faked a middle mouse event. */
3375 /* Flush out saved message. */
3376 post_msg (&saved_mouse_button_msg
);
3378 wmsg
.dwModifiers
= w32_get_modifiers ();
3379 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3380 signal_user_input ();
3382 /* Clear message buffer. */
3383 saved_mouse_button_msg
.msg
.hwnd
= 0;
3387 /* Hold onto message for now. */
3388 mouse_button_timer
=
3389 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
3390 w32_mouse_button_tolerance
, NULL
);
3391 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
3392 saved_mouse_button_msg
.msg
.message
= msg
;
3393 saved_mouse_button_msg
.msg
.wParam
= wParam
;
3394 saved_mouse_button_msg
.msg
.lParam
= lParam
;
3395 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
3396 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
3403 if (w32_num_mouse_buttons
> 2)
3404 goto handle_plain_button
;
3407 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
3408 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
3410 if ((button_state
& this) == 0)
3413 button_state
&= ~this;
3415 if (button_state
& MMOUSE
)
3417 /* Only generate event when second button is released. */
3418 if ((button_state
& other
) == 0)
3421 button_state
&= ~MMOUSE
;
3423 if (button_state
) emacs_abort ();
3430 /* Flush out saved message if necessary. */
3431 if (saved_mouse_button_msg
.msg
.hwnd
)
3433 post_msg (&saved_mouse_button_msg
);
3436 wmsg
.dwModifiers
= w32_get_modifiers ();
3437 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3438 signal_user_input ();
3440 /* Always clear message buffer and cancel timer. */
3441 saved_mouse_button_msg
.msg
.hwnd
= 0;
3442 KillTimer (hwnd
, mouse_button_timer
);
3443 mouse_button_timer
= 0;
3445 if (button_state
== 0)
3450 case WM_XBUTTONDOWN
:
3452 if (w32_pass_extra_mouse_buttons_to_system
)
3454 /* else fall through and process them. */
3455 case WM_MBUTTONDOWN
:
3457 handle_plain_button
:
3462 /* Ignore middle and extra buttons as long as the menu is active. */
3463 f
= x_window_to_frame (dpyinfo
, hwnd
);
3464 if (f
&& f
->output_data
.w32
->menubar_active
)
3467 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
3469 if (up
) ReleaseCapture ();
3470 else SetCapture (hwnd
);
3471 button
= (button
== 0) ? LMOUSE
:
3472 ((button
== 1) ? MMOUSE
: RMOUSE
);
3474 button_state
&= ~button
;
3476 button_state
|= button
;
3480 wmsg
.dwModifiers
= w32_get_modifiers ();
3481 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3482 signal_user_input ();
3484 /* Need to return true for XBUTTON messages, false for others,
3485 to indicate that we processed the message. */
3486 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
3489 /* Ignore mouse movements as long as the menu is active. These
3490 movements are processed by the window manager anyway, and
3491 it's wrong to handle them as if they happened on the
3492 underlying frame. */
3493 f
= x_window_to_frame (dpyinfo
, hwnd
);
3494 if (f
&& f
->output_data
.w32
->menubar_active
)
3497 /* If the mouse has just moved into the frame, start tracking
3498 it, so we will be notified when it leaves the frame. Mouse
3499 tracking only works under W98 and NT4 and later. On earlier
3500 versions, there is no way of telling when the mouse leaves the
3501 frame, so we just have to put up with help-echo and mouse
3502 highlighting remaining while the frame is not active. */
3503 if (track_mouse_event_fn
&& !track_mouse_window
3504 /* If the menu bar is active, turning on tracking of mouse
3505 movement events might send these events to the tooltip
3506 frame, if the user happens to move the mouse pointer over
3507 the tooltip. But since we don't process events for
3508 tooltip frames, this causes Windows to present a
3509 hourglass cursor, which is ugly and unexpected. So don't
3510 enable tracking mouse events in this case; they will be
3511 restarted when the menu pops down. (Confusingly, the
3512 menubar_active member of f->output_data.w32, tested
3513 above, is only set when a menu was popped up _not_ from
3514 the frame's menu bar, but via x-popup-menu.) */
3517 TRACKMOUSEEVENT tme
;
3518 tme
.cbSize
= sizeof (tme
);
3519 tme
.dwFlags
= TME_LEAVE
;
3520 tme
.hwndTrack
= hwnd
;
3521 tme
.dwHoverTime
= HOVER_DEFAULT
;
3523 track_mouse_event_fn (&tme
);
3524 track_mouse_window
= hwnd
;
3528 if (w32_mouse_move_interval
<= 0
3529 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
3531 wmsg
.dwModifiers
= w32_get_modifiers ();
3532 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3536 /* Hang onto mouse move and scroll messages for a bit, to avoid
3537 sending such events to Emacs faster than it can process them.
3538 If we get more events before the timer from the first message
3539 expires, we just replace the first message. */
3541 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
3543 SetTimer (hwnd
, MOUSE_MOVE_ID
,
3544 w32_mouse_move_interval
, NULL
);
3546 /* Hold onto message for now. */
3547 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
3548 saved_mouse_move_msg
.msg
.message
= msg
;
3549 saved_mouse_move_msg
.msg
.wParam
= wParam
;
3550 saved_mouse_move_msg
.msg
.lParam
= lParam
;
3551 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
3552 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
3558 wmsg
.dwModifiers
= w32_get_modifiers ();
3559 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3560 signal_user_input ();
3564 if (w32_pass_multimedia_buttons_to_system
)
3566 /* Otherwise, pass to lisp, the same way we do with mousehwheel. */
3567 case WM_MOUSEHWHEEL
:
3568 wmsg
.dwModifiers
= w32_get_modifiers ();
3569 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3570 signal_user_input ();
3571 /* Non-zero must be returned when WM_MOUSEHWHEEL messages are
3572 handled, to prevent the system trying to handle it by faking
3573 scroll bar events. */
3577 /* Flush out saved messages if necessary. */
3578 if (wParam
== mouse_button_timer
)
3580 if (saved_mouse_button_msg
.msg
.hwnd
)
3582 post_msg (&saved_mouse_button_msg
);
3583 signal_user_input ();
3584 saved_mouse_button_msg
.msg
.hwnd
= 0;
3586 KillTimer (hwnd
, mouse_button_timer
);
3587 mouse_button_timer
= 0;
3589 else if (wParam
== mouse_move_timer
)
3591 if (saved_mouse_move_msg
.msg
.hwnd
)
3593 post_msg (&saved_mouse_move_msg
);
3594 saved_mouse_move_msg
.msg
.hwnd
= 0;
3596 KillTimer (hwnd
, mouse_move_timer
);
3597 mouse_move_timer
= 0;
3599 else if (wParam
== menu_free_timer
)
3601 KillTimer (hwnd
, menu_free_timer
);
3602 menu_free_timer
= 0;
3603 f
= x_window_to_frame (dpyinfo
, hwnd
);
3604 /* If a popup menu is active, don't wipe its strings. */
3606 && current_popup_menu
== NULL
)
3608 /* Free memory used by owner-drawn and help-echo strings. */
3609 w32_free_menu_strings (hwnd
);
3611 f
->output_data
.w32
->menubar_active
= 0;
3618 /* Windows doesn't send us focus messages when putting up and
3619 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
3620 The only indication we get that something happened is receiving
3621 this message afterwards. So this is a good time to reset our
3622 keyboard modifiers' state. */
3629 /* We must ensure menu bar is fully constructed and up to date
3630 before allowing user interaction with it. To achieve this
3631 we send this message to the lisp thread and wait for a
3632 reply (whose value is not actually needed) to indicate that
3633 the menu bar is now ready for use, so we can now return.
3635 To remain responsive in the meantime, we enter a nested message
3636 loop that can process all other messages.
3638 However, we skip all this if the message results from calling
3639 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
3640 thread a message because it is blocked on us at this point. We
3641 set menubar_active before calling TrackPopupMenu to indicate
3642 this (there is no possibility of confusion with real menubar
3645 f
= x_window_to_frame (dpyinfo
, hwnd
);
3647 && (f
->output_data
.w32
->menubar_active
3648 /* We can receive this message even in the absence of a
3649 menubar (ie. when the system menu is activated) - in this
3650 case we do NOT want to forward the message, otherwise it
3651 will cause the menubar to suddenly appear when the user
3652 had requested it to be turned off! */
3653 || f
->output_data
.w32
->menubar_widget
== NULL
))
3657 deferred_msg msg_buf
;
3659 /* Detect if message has already been deferred; in this case
3660 we cannot return any sensible value to ignore this. */
3661 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3666 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
3669 case WM_EXITMENULOOP
:
3670 f
= x_window_to_frame (dpyinfo
, hwnd
);
3672 /* If a menu is still active, check again after a short delay,
3673 since Windows often (always?) sends the WM_EXITMENULOOP
3674 before the corresponding WM_COMMAND message.
3675 Don't do this if a popup menu is active, since it is only
3676 menubar menus that require cleaning up in this way.
3678 if (f
&& menubar_in_use
&& current_popup_menu
== NULL
)
3679 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
3681 /* If hourglass cursor should be displayed, display it now. */
3682 if (f
&& f
->output_data
.w32
->hourglass_p
)
3683 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3688 /* Direct handling of help_echo in menus. Should be safe now
3689 that we generate the help_echo by placing a help event in the
3692 HMENU menu
= (HMENU
) lParam
;
3693 UINT menu_item
= (UINT
) LOWORD (wParam
);
3694 UINT flags
= (UINT
) HIWORD (wParam
);
3696 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
3700 case WM_MEASUREITEM
:
3701 f
= x_window_to_frame (dpyinfo
, hwnd
);
3704 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
3706 if (pMis
->CtlType
== ODT_MENU
)
3708 /* Work out dimensions for popup menu titles. */
3709 char * title
= (char *) pMis
->itemData
;
3710 HDC hdc
= GetDC (hwnd
);
3711 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3712 LOGFONT menu_logfont
;
3716 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3717 menu_logfont
.lfWeight
= FW_BOLD
;
3718 menu_font
= CreateFontIndirect (&menu_logfont
);
3719 old_font
= SelectObject (hdc
, menu_font
);
3721 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
3724 if (unicode_append_menu
)
3725 GetTextExtentPoint32W (hdc
, (WCHAR
*) title
,
3726 wcslen ((WCHAR
*) title
),
3729 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
3731 pMis
->itemWidth
= size
.cx
;
3732 if (pMis
->itemHeight
< size
.cy
)
3733 pMis
->itemHeight
= size
.cy
;
3736 pMis
->itemWidth
= 0;
3738 SelectObject (hdc
, old_font
);
3739 DeleteObject (menu_font
);
3740 ReleaseDC (hwnd
, hdc
);
3747 f
= x_window_to_frame (dpyinfo
, hwnd
);
3750 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
3752 if (pDis
->CtlType
== ODT_MENU
)
3754 /* Draw popup menu title. */
3755 char * title
= (char *) pDis
->itemData
;
3758 HDC hdc
= pDis
->hDC
;
3759 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
3760 LOGFONT menu_logfont
;
3763 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
3764 menu_logfont
.lfWeight
= FW_BOLD
;
3765 menu_font
= CreateFontIndirect (&menu_logfont
);
3766 old_font
= SelectObject (hdc
, menu_font
);
3768 /* Always draw title as if not selected. */
3769 if (unicode_append_menu
)
3772 + GetSystemMetrics (SM_CXMENUCHECK
),
3774 ETO_OPAQUE
, &pDis
->rcItem
,
3776 wcslen ((WCHAR
*) title
), NULL
);
3780 + GetSystemMetrics (SM_CXMENUCHECK
),
3782 ETO_OPAQUE
, &pDis
->rcItem
,
3783 title
, strlen (title
), NULL
);
3785 SelectObject (hdc
, old_font
);
3786 DeleteObject (menu_font
);
3794 /* Still not right - can't distinguish between clicks in the
3795 client area of the frame from clicks forwarded from the scroll
3796 bars - may have to hook WM_NCHITTEST to remember the mouse
3797 position and then check if it is in the client area ourselves. */
3798 case WM_MOUSEACTIVATE
:
3799 /* Discard the mouse click that activates a frame, allowing the
3800 user to click anywhere without changing point (or worse!).
3801 Don't eat mouse clicks on scrollbars though!! */
3802 if (LOWORD (lParam
) == HTCLIENT
)
3803 return MA_ACTIVATEANDEAT
;
3808 /* No longer tracking mouse. */
3809 track_mouse_window
= NULL
;
3811 case WM_ACTIVATEAPP
:
3813 case WM_WINDOWPOSCHANGED
:
3815 /* Inform lisp thread that a frame might have just been obscured
3816 or exposed, so should recheck visibility of all frames. */
3817 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3821 dpyinfo
->faked_key
= 0;
3823 register_hot_keys (hwnd
);
3826 unregister_hot_keys (hwnd
);
3829 /* Relinquish the system caret. */
3830 if (w32_system_caret_hwnd
)
3832 w32_visible_system_caret_hwnd
= NULL
;
3833 w32_system_caret_hwnd
= NULL
;
3839 f
= x_window_to_frame (dpyinfo
, hwnd
);
3840 if (f
&& HIWORD (wParam
) == 0)
3842 if (menu_free_timer
)
3844 KillTimer (hwnd
, menu_free_timer
);
3845 menu_free_timer
= 0;
3851 wmsg
.dwModifiers
= w32_get_modifiers ();
3852 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3860 wmsg
.dwModifiers
= w32_get_modifiers ();
3861 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3864 case WM_WINDOWPOSCHANGING
:
3865 /* Don't restrict the sizing of any kind of frames. If the window
3866 manager doesn't, there's no reason to do it ourselves. */
3868 if (frame_resize_pixelwise
|| hwnd
== tip_window
)
3873 /* Don't restrict the sizing of fullscreened frames, allowing them to be
3874 flush with the sides of the screen. */
3875 f
= x_window_to_frame (dpyinfo
, hwnd
);
3876 if (f
&& FRAME_PREV_FSMODE (f
) != FULLSCREEN_NONE
)
3881 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
3883 wp
.length
= sizeof (WINDOWPLACEMENT
);
3884 GetWindowPlacement (hwnd
, &wp
);
3886 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
&& wp
.showCmd
!= SW_SHOWMINIMIZED
3887 && (lppos
->flags
& SWP_NOSIZE
) == 0)
3894 DWORD internal_border
;
3895 DWORD vscrollbar_extra
;
3896 DWORD hscrollbar_extra
;
3899 wp
.length
= sizeof (wp
);
3900 GetWindowRect (hwnd
, &wr
);
3904 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
3905 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
3906 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
3907 vscrollbar_extra
= GetWindowLong (hwnd
, WND_VSCROLLBAR_INDEX
);
3908 hscrollbar_extra
= GetWindowLong (hwnd
, WND_HSCROLLBAR_INDEX
);
3912 memset (&rect
, 0, sizeof (rect
));
3913 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
3914 GetMenu (hwnd
) != NULL
);
3916 /* Force width and height of client area to be exact
3917 multiples of the character cell dimensions. */
3918 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
3919 - 2 * internal_border
- vscrollbar_extra
)
3921 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
3922 - 2 * internal_border
- hscrollbar_extra
)
3927 /* For right/bottom sizing we can just fix the sizes.
3928 However for top/left sizing we will need to fix the X
3929 and Y positions as well. */
3931 int cx_mintrack
= GetSystemMetrics (SM_CXMINTRACK
);
3932 int cy_mintrack
= GetSystemMetrics (SM_CYMINTRACK
);
3934 lppos
->cx
= max (lppos
->cx
- wdiff
, cx_mintrack
);
3935 lppos
->cy
= max (lppos
->cy
- hdiff
, cy_mintrack
);
3937 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
3938 && (lppos
->flags
& SWP_NOMOVE
) == 0)
3940 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
3947 lppos
->flags
|= SWP_NOMOVE
;
3959 case WM_GETMINMAXINFO
:
3960 /* Hack to allow resizing the Emacs frame above the screen size.
3961 Note that Windows 9x limits coordinates to 16-bits. */
3962 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
3963 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
3967 if (LOWORD (lParam
) == HTCLIENT
)
3969 f
= x_window_to_frame (dpyinfo
, hwnd
);
3970 if (f
&& f
->output_data
.w32
->hourglass_p
3971 && !menubar_in_use
&& !current_popup_menu
)
3972 SetCursor (f
->output_data
.w32
->hourglass_cursor
);
3974 SetCursor (f
->output_data
.w32
->current_cursor
);
3979 case WM_EMACS_SETCURSOR
:
3981 Cursor cursor
= (Cursor
) wParam
;
3982 f
= x_window_to_frame (dpyinfo
, hwnd
);
3985 f
->output_data
.w32
->current_cursor
= cursor
;
3986 if (!f
->output_data
.w32
->hourglass_p
)
3992 case WM_EMACS_SHOWCURSOR
:
3994 ShowCursor ((BOOL
) wParam
);
3999 case WM_EMACS_CREATEVSCROLLBAR
:
4000 return (LRESULT
) w32_createvscrollbar ((struct frame
*) wParam
,
4001 (struct scroll_bar
*) lParam
);
4003 case WM_EMACS_CREATEHSCROLLBAR
:
4004 return (LRESULT
) w32_createhscrollbar ((struct frame
*) wParam
,
4005 (struct scroll_bar
*) lParam
);
4007 case WM_EMACS_SHOWWINDOW
:
4008 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4010 case WM_EMACS_BRINGTOTOP
:
4011 case WM_EMACS_SETFOREGROUND
:
4013 HWND foreground_window
;
4014 DWORD foreground_thread
, retval
;
4016 /* On NT 5.0, and apparently Windows 98, it is necessary to
4017 attach to the thread that currently has focus in order to
4018 pull the focus away from it. */
4019 foreground_window
= GetForegroundWindow ();
4020 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4021 if (!foreground_window
4022 || foreground_thread
== GetCurrentThreadId ()
4023 || !AttachThreadInput (GetCurrentThreadId (),
4024 foreground_thread
, TRUE
))
4025 foreground_thread
= 0;
4027 retval
= SetForegroundWindow ((HWND
) wParam
);
4028 if (msg
== WM_EMACS_BRINGTOTOP
)
4029 retval
= BringWindowToTop ((HWND
) wParam
);
4031 /* Detach from the previous foreground thread. */
4032 if (foreground_thread
)
4033 AttachThreadInput (GetCurrentThreadId (),
4034 foreground_thread
, FALSE
);
4039 case WM_EMACS_SETWINDOWPOS
:
4041 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4042 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4043 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4046 case WM_EMACS_DESTROYWINDOW
:
4047 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4048 return DestroyWindow ((HWND
) wParam
);
4050 case WM_EMACS_HIDE_CARET
:
4051 return HideCaret (hwnd
);
4053 case WM_EMACS_SHOW_CARET
:
4054 return ShowCaret (hwnd
);
4056 case WM_EMACS_DESTROY_CARET
:
4057 w32_system_caret_hwnd
= NULL
;
4058 w32_visible_system_caret_hwnd
= NULL
;
4059 return DestroyCaret ();
4061 case WM_EMACS_TRACK_CARET
:
4062 /* If there is currently no system caret, create one. */
4063 if (w32_system_caret_hwnd
== NULL
)
4065 /* Use the default caret width, and avoid changing it
4066 unnecessarily, as it confuses screen reader software. */
4067 w32_system_caret_hwnd
= hwnd
;
4068 CreateCaret (hwnd
, NULL
, 0,
4069 w32_system_caret_height
);
4072 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
4074 /* Ensure visible caret gets turned on when requested. */
4075 else if (w32_use_visible_system_caret
4076 && w32_visible_system_caret_hwnd
!= hwnd
)
4078 w32_visible_system_caret_hwnd
= hwnd
;
4079 return ShowCaret (hwnd
);
4081 /* Ensure visible caret gets turned off when requested. */
4082 else if (!w32_use_visible_system_caret
4083 && w32_visible_system_caret_hwnd
)
4085 w32_visible_system_caret_hwnd
= NULL
;
4086 return HideCaret (hwnd
);
4091 case WM_EMACS_TRACKPOPUPMENU
:
4096 pos
= (POINT
*)lParam
;
4097 flags
= TPM_CENTERALIGN
;
4098 if (button_state
& LMOUSE
)
4099 flags
|= TPM_LEFTBUTTON
;
4100 else if (button_state
& RMOUSE
)
4101 flags
|= TPM_RIGHTBUTTON
;
4103 /* Remember we did a SetCapture on the initial mouse down event,
4104 so for safety, we make sure the capture is canceled now. */
4108 /* Use menubar_active to indicate that WM_INITMENU is from
4109 TrackPopupMenu below, and should be ignored. */
4110 f
= x_window_to_frame (dpyinfo
, hwnd
);
4112 f
->output_data
.w32
->menubar_active
= 1;
4114 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4118 /* Eat any mouse messages during popupmenu */
4119 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4121 /* Get the menu selection, if any */
4122 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4124 retval
= LOWORD (amsg
.wParam
);
4138 case WM_EMACS_FILENOTIFY
:
4139 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4143 /* Check for messages registered at runtime. */
4144 if (msg
== msh_mousewheel
)
4146 wmsg
.dwModifiers
= w32_get_modifiers ();
4147 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4148 signal_user_input ();
4153 return (w32_unicode_gui
? DefWindowProcW
: DefWindowProcA
) (hwnd
, msg
, wParam
, lParam
);
4156 /* The most common default return code for handled messages is 0. */
4161 my_create_window (struct frame
* f
)
4164 static int coords
[2];
4165 Lisp_Object left
, top
;
4166 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4168 /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
4169 anything that is not a number and is not Qunbound. */
4170 left
= x_get_arg (dpyinfo
, Qnil
, Qleft
, "left", "Left", RES_TYPE_NUMBER
);
4171 top
= x_get_arg (dpyinfo
, Qnil
, Qtop
, "top", "Top", RES_TYPE_NUMBER
);
4172 if (EQ (left
, Qunbound
))
4173 coords
[0] = CW_USEDEFAULT
;
4175 coords
[0] = XINT (left
);
4176 if (EQ (top
, Qunbound
))
4177 coords
[1] = CW_USEDEFAULT
;
4179 coords
[1] = XINT (top
);
4181 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
,
4182 (WPARAM
)f
, (LPARAM
)coords
))
4184 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4188 /* Create a tooltip window. Unlike my_create_window, we do not do this
4189 indirectly via the Window thread, as we do not need to process Window
4190 messages for the tooltip. Creating tooltips indirectly also creates
4191 deadlocks when tooltips are created for menu items. */
4193 my_create_tip_window (struct frame
*f
)
4197 rect
.left
= rect
.top
= 0;
4198 rect
.right
= FRAME_PIXEL_WIDTH (f
);
4199 rect
.bottom
= FRAME_PIXEL_HEIGHT (f
);
4201 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
4202 FRAME_EXTERNAL_MENU_BAR (f
));
4204 tip_window
= FRAME_W32_WINDOW (f
)
4205 = CreateWindow (EMACS_CLASS
,
4207 f
->output_data
.w32
->dwStyle
,
4210 rect
.right
- rect
.left
,
4211 rect
.bottom
- rect
.top
,
4212 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
4219 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FRAME_COLUMN_WIDTH (f
));
4220 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, FRAME_LINE_HEIGHT (f
));
4221 SetWindowLong (tip_window
, WND_BORDER_INDEX
, FRAME_INTERNAL_BORDER_WIDTH (f
));
4222 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
4224 /* Tip frames have no scrollbars. */
4225 SetWindowLong (tip_window
, WND_VSCROLLBAR_INDEX
, 0);
4226 SetWindowLong (tip_window
, WND_HSCROLLBAR_INDEX
, 0);
4228 /* Do this to discard the default setting specified by our parent. */
4229 ShowWindow (tip_window
, SW_HIDE
);
4234 /* Create and set up the w32 window for frame F. */
4237 w32_window (struct frame
*f
, long window_prompting
, bool minibuffer_only
)
4241 /* Use the resource name as the top-level window name
4242 for looking up resources. Make a non-Lisp copy
4243 for the window manager, so GC relocation won't bother it.
4245 Elsewhere we specify the window name for the window manager. */
4246 f
->namebuf
= xlispstrdup (Vx_resource_name
);
4248 my_create_window (f
);
4250 validate_x_resource_name ();
4252 /* x_set_name normally ignores requests to set the name if the
4253 requested name is the same as the current name. This is the one
4254 place where that assumption isn't correct; f->name is set, but
4255 the server hasn't been told. */
4258 int explicit = f
->explicit_name
;
4260 f
->explicit_name
= 0;
4262 fset_name (f
, Qnil
);
4263 x_set_name (f
, name
, explicit);
4268 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4269 initialize_frame_menubar (f
);
4271 if (FRAME_W32_WINDOW (f
) == 0)
4272 error ("Unable to create window");
4275 /* Handle the icon stuff for this window. Perhaps later we might
4276 want an x_set_icon_position which can be called interactively as
4280 x_icon (struct frame
*f
, Lisp_Object parms
)
4282 Lisp_Object icon_x
, icon_y
;
4283 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4285 /* Set the position of the icon. Note that Windows 95 groups all
4286 icons in the tray. */
4287 icon_x
= x_get_arg (dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4288 icon_y
= x_get_arg (dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4289 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4291 CHECK_NUMBER (icon_x
);
4292 CHECK_NUMBER (icon_y
);
4294 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4295 error ("Both left and top icon corners of icon must be specified");
4300 /* Start up iconic or window? */
4301 x_wm_set_window_state
4302 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4306 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
4316 x_make_gc (struct frame
*f
)
4318 XGCValues gc_values
;
4322 /* Create the GC's of this frame.
4323 Note that many default values are used. */
4326 gc_values
.font
= FRAME_FONT (f
);
4328 /* Cursor has cursor-color background, background-color foreground. */
4329 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4330 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4331 f
->output_data
.w32
->cursor_gc
4332 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4333 (GCFont
| GCForeground
| GCBackground
),
4337 f
->output_data
.w32
->white_relief
.gc
= 0;
4338 f
->output_data
.w32
->black_relief
.gc
= 0;
4344 /* Handler for signals raised during x_create_frame and
4345 x_create_tip_frame. FRAME is the frame which is partially
4349 unwind_create_frame (Lisp_Object frame
)
4351 struct frame
*f
= XFRAME (frame
);
4353 /* If frame is ``official'', nothing to do. */
4354 if (NILP (Fmemq (frame
, Vframe_list
)))
4357 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4359 /* If the frame's image cache refcount is still the same as our
4360 private shadow variable, it means we are unwinding a frame
4361 for which we didn't yet call init_frame_faces, where the
4362 refcount is incremented. Therefore, we increment it here, so
4363 that free_frame_faces, called in x_free_frame_resources
4364 below, will not mistakenly decrement the counter that was not
4365 incremented yet to account for this new frame. */
4366 if (FRAME_IMAGE_CACHE (f
) != NULL
4367 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
4368 FRAME_IMAGE_CACHE (f
)->refcount
++;
4371 x_free_frame_resources (f
);
4375 /* Check that reference counts are indeed correct. */
4376 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4377 eassert ((dpyinfo
->terminal
->image_cache
== NULL
4378 && image_cache_refcount
== 0)
4379 || (dpyinfo
->terminal
->image_cache
!= NULL
4380 && dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
));
4389 do_unwind_create_frame (Lisp_Object frame
)
4391 unwind_create_frame (frame
);
4395 unwind_create_frame_1 (Lisp_Object val
)
4397 inhibit_lisp_code
= val
;
4401 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
4403 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4404 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
4407 if (EQ (font_param
, Qunbound
))
4409 font
= !NILP (font_param
) ? font_param
4410 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4412 if (!STRINGP (font
))
4415 static char *names
[]
4416 = { "Courier New-10",
4417 "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1",
4418 "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1",
4422 for (i
= 0; names
[i
]; i
++)
4424 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
4429 error ("No suitable font was found");
4431 else if (!NILP (font_param
))
4433 /* Remember the explicit font parameter, so we can re-apply it after
4434 we've applied the `default' face settings. */
4435 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
4437 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
4440 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4442 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
4443 Return an Emacs frame object.
4444 PARAMETERS is an alist of frame parameters.
4445 If the parameters specify that the frame should not have a minibuffer,
4446 and do not specify a specific minibuffer window to use,
4447 then `default-minibuffer-frame' must be a frame whose minibuffer can
4448 be shared by the new frame.
4450 This function is an internal primitive--use `make-frame' instead. */)
4451 (Lisp_Object parameters
)
4454 Lisp_Object frame
, tem
;
4456 bool minibuffer_only
= false;
4457 long window_prompting
= 0;
4458 ptrdiff_t count
= SPECPDL_INDEX ();
4459 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4460 Lisp_Object display
;
4461 struct w32_display_info
*dpyinfo
= NULL
;
4465 if (!FRAME_W32_P (SELECTED_FRAME ())
4466 && !FRAME_INITIAL_P (SELECTED_FRAME ()))
4467 error ("Cannot create a GUI frame in a -nw session");
4469 /* Make copy of frame parameters because the original is in pure
4471 parameters
= Fcopy_alist (parameters
);
4473 /* Use this general default value to start with
4474 until we know if this frame has a specified name. */
4475 Vx_resource_name
= Vinvocation_name
;
4477 display
= x_get_arg (dpyinfo
, parameters
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
4478 if (EQ (display
, Qunbound
))
4479 display
= x_get_arg (dpyinfo
, parameters
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4480 if (EQ (display
, Qunbound
))
4482 dpyinfo
= check_x_display_info (display
);
4483 kb
= dpyinfo
->terminal
->kboard
;
4485 if (!dpyinfo
->terminal
->name
)
4486 error ("Terminal is not live, can't create new frames on it");
4488 name
= x_get_arg (dpyinfo
, parameters
, Qname
, "name", "Name", RES_TYPE_STRING
);
4490 && ! EQ (name
, Qunbound
)
4492 error ("Invalid frame name--not a string or nil");
4495 Vx_resource_name
= name
;
4497 /* See if parent window is specified. */
4498 parent
= x_get_arg (dpyinfo
, parameters
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4499 if (EQ (parent
, Qunbound
))
4501 if (! NILP (parent
))
4502 CHECK_NUMBER (parent
);
4504 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4505 /* No need to protect DISPLAY because that's not used after passing
4506 it to make_frame_without_minibuffer. */
4508 GCPRO4 (parameters
, parent
, name
, frame
);
4509 tem
= x_get_arg (dpyinfo
, parameters
, Qminibuffer
, "minibuffer", "Minibuffer",
4511 if (EQ (tem
, Qnone
) || NILP (tem
))
4512 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4513 else if (EQ (tem
, Qonly
))
4515 f
= make_minibuffer_frame ();
4516 minibuffer_only
= true;
4518 else if (WINDOWP (tem
))
4519 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4521 f
= make_frame (true);
4523 XSETFRAME (frame
, f
);
4525 /* By default, make scrollbars the system standard width and height. */
4526 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
4527 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = GetSystemMetrics (SM_CXHSCROLL
);
4529 f
->terminal
= dpyinfo
->terminal
;
4531 f
->output_method
= output_w32
;
4532 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
4533 FRAME_FONTSET (f
) = -1;
4536 (f
, x_get_arg (dpyinfo
, parameters
, Qicon_name
, "iconName", "Title",
4538 if (! STRINGP (f
->icon_name
))
4539 fset_icon_name (f
, Qnil
);
4541 /* FRAME_DISPLAY_INFO (f) = dpyinfo; */
4543 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
4544 record_unwind_protect (do_unwind_create_frame
, frame
);
4547 image_cache_refcount
=
4548 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4549 dpyinfo_refcount
= dpyinfo
->reference_count
;
4550 #endif /* GLYPH_DEBUG */
4552 /* Specify the parent under which to make this window. */
4555 /* Cast to UINT_PTR shuts up compiler warnings about cast to
4556 pointer from integer of different size. */
4557 f
->output_data
.w32
->parent_desc
= (Window
) (UINT_PTR
) XFASTINT (parent
);
4558 f
->output_data
.w32
->explicit_parent
= true;
4562 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4563 f
->output_data
.w32
->explicit_parent
= false;
4566 /* Set the name; the functions to which we pass f expect the name to
4568 if (EQ (name
, Qunbound
) || NILP (name
))
4570 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
4571 f
->explicit_name
= false;
4575 fset_name (f
, name
);
4576 f
->explicit_name
= true;
4577 /* Use the frame's title when getting resources for this frame. */
4578 specbind (Qx_resource_name
, name
);
4581 if (uniscribe_available
)
4582 register_font_driver (&uniscribe_font_driver
, f
);
4583 register_font_driver (&w32font_driver
, f
);
4585 x_default_parameter (f
, parameters
, Qfont_backend
, Qnil
,
4586 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4588 /* Extract the window parameters from the supplied values
4589 that are needed to determine window geometry. */
4590 x_default_font_parameter (f
, parameters
);
4592 x_default_parameter (f
, parameters
, Qborder_width
, make_number (2),
4593 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4595 /* We recognize either internalBorderWidth or internalBorder
4596 (which is what xterm calls it). */
4597 if (NILP (Fassq (Qinternal_border_width
, parameters
)))
4601 value
= x_get_arg (dpyinfo
, parameters
, Qinternal_border_width
,
4602 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
4603 if (! EQ (value
, Qunbound
))
4604 parameters
= Fcons (Fcons (Qinternal_border_width
, value
),
4607 /* Default internalBorderWidth to 0 on Windows to match other programs. */
4608 x_default_parameter (f
, parameters
, Qinternal_border_width
, make_number (0),
4609 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
4610 x_default_parameter (f
, parameters
, Qright_divider_width
, make_number (0),
4611 NULL
, NULL
, RES_TYPE_NUMBER
);
4612 x_default_parameter (f
, parameters
, Qbottom_divider_width
, make_number (0),
4613 NULL
, NULL
, RES_TYPE_NUMBER
);
4614 x_default_parameter (f
, parameters
, Qvertical_scroll_bars
, Qright
,
4615 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4616 x_default_parameter (f
, parameters
, Qhorizontal_scroll_bars
, Qnil
,
4617 "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
4619 /* Also do the stuff which must be set before the window exists. */
4620 x_default_parameter (f
, parameters
, Qforeground_color
, build_string ("black"),
4621 "foreground", "Foreground", RES_TYPE_STRING
);
4622 x_default_parameter (f
, parameters
, Qbackground_color
, build_string ("white"),
4623 "background", "Background", RES_TYPE_STRING
);
4624 x_default_parameter (f
, parameters
, Qmouse_color
, build_string ("black"),
4625 "pointerColor", "Foreground", RES_TYPE_STRING
);
4626 x_default_parameter (f
, parameters
, Qborder_color
, build_string ("black"),
4627 "borderColor", "BorderColor", RES_TYPE_STRING
);
4628 x_default_parameter (f
, parameters
, Qscreen_gamma
, Qnil
,
4629 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4630 x_default_parameter (f
, parameters
, Qline_spacing
, Qnil
,
4631 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4632 x_default_parameter (f
, parameters
, Qleft_fringe
, Qnil
,
4633 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4634 x_default_parameter (f
, parameters
, Qright_fringe
, Qnil
,
4635 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4636 /* Process alpha here (Bug#16619). */
4637 x_default_parameter (f
, parameters
, Qalpha
, Qnil
,
4638 "alpha", "Alpha", RES_TYPE_NUMBER
);
4640 /* Init faces first since we need the frame's column width/line
4641 height in various occasions. */
4642 init_frame_faces (f
);
4644 /* The following call of change_frame_size is needed since otherwise
4645 x_set_tool_bar_lines will already work with the character sizes
4646 installed by init_frame_faces while the frame's pixel size is
4647 still calculated from a character size of 1 and we subsequently
4648 hit the (height >= 0) assertion in window_box_height.
4650 The non-pixelwise code apparently worked around this because it
4651 had one frame line vs one toolbar line which left us with a zero
4652 root window height which was obviously wrong as well ... */
4653 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
4654 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
4657 /* The X resources controlling the menu-bar and tool-bar are
4658 processed specially at startup, and reflected in the mode
4659 variables; ignore them here. */
4660 x_default_parameter (f
, parameters
, Qmenu_bar_lines
,
4661 NILP (Vmenu_bar_mode
)
4662 ? make_number (0) : make_number (1),
4663 NULL
, NULL
, RES_TYPE_NUMBER
);
4664 x_default_parameter (f
, parameters
, Qtool_bar_lines
,
4665 NILP (Vtool_bar_mode
)
4666 ? make_number (0) : make_number (1),
4667 NULL
, NULL
, RES_TYPE_NUMBER
);
4669 x_default_parameter (f
, parameters
, Qbuffer_predicate
, Qnil
,
4670 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
4671 x_default_parameter (f
, parameters
, Qtitle
, Qnil
,
4672 "title", "Title", RES_TYPE_STRING
);
4674 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
4675 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4677 f
->output_data
.w32
->text_cursor
= w32_load_cursor (IDC_IBEAM
);
4678 f
->output_data
.w32
->nontext_cursor
= w32_load_cursor (IDC_ARROW
);
4679 f
->output_data
.w32
->modeline_cursor
= w32_load_cursor (IDC_ARROW
);
4680 f
->output_data
.w32
->hand_cursor
= w32_load_cursor (IDC_HAND
);
4681 f
->output_data
.w32
->hourglass_cursor
= w32_load_cursor (IDC_WAIT
);
4682 f
->output_data
.w32
->horizontal_drag_cursor
= w32_load_cursor (IDC_SIZEWE
);
4683 f
->output_data
.w32
->vertical_drag_cursor
= w32_load_cursor (IDC_SIZENS
);
4685 f
->output_data
.w32
->current_cursor
= f
->output_data
.w32
->nontext_cursor
;
4687 window_prompting
= x_figure_window_size (f
, parameters
, true);
4689 tem
= x_get_arg (dpyinfo
, parameters
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4690 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4692 w32_window (f
, window_prompting
, minibuffer_only
);
4693 x_icon (f
, parameters
);
4697 /* Now consider the frame official. */
4698 f
->terminal
->reference_count
++;
4699 FRAME_DISPLAY_INFO (f
)->reference_count
++;
4700 Vframe_list
= Fcons (frame
, Vframe_list
);
4702 /* We need to do this after creating the window, so that the
4703 icon-creation functions can say whose icon they're describing. */
4704 x_default_parameter (f
, parameters
, Qicon_type
, Qnil
,
4705 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4707 x_default_parameter (f
, parameters
, Qauto_raise
, Qnil
,
4708 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4709 x_default_parameter (f
, parameters
, Qauto_lower
, Qnil
,
4710 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4711 x_default_parameter (f
, parameters
, Qcursor_type
, Qbox
,
4712 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4713 x_default_parameter (f
, parameters
, Qscroll_bar_width
, Qnil
,
4714 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
4715 x_default_parameter (f
, parameters
, Qscroll_bar_height
, Qnil
,
4716 "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER
);
4718 /* Allow x_set_window_size, now. */
4719 f
->can_x_set_window_size
= true;
4721 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
4724 /* Tell the server what size and position, etc, we want, and how
4725 badly we want them. This should be done after we have the menu
4726 bar so that its size can be taken into account. */
4728 x_wm_set_size_hint (f
, window_prompting
, false);
4731 /* Process fullscreen parameter here in the hope that normalizing a
4732 fullheight/fullwidth frame will produce the size set by the last
4733 adjust_frame_size call. */
4734 x_default_parameter (f
, parameters
, Qfullscreen
, Qnil
,
4735 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4737 /* Make the window appear on the frame and enable display, unless
4738 the caller says not to. However, with explicit parent, Emacs
4739 cannot control visibility, so don't try. */
4740 if (! f
->output_data
.w32
->explicit_parent
)
4742 Lisp_Object visibility
;
4744 visibility
= x_get_arg (dpyinfo
, parameters
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
4745 if (EQ (visibility
, Qunbound
))
4748 if (EQ (visibility
, Qicon
))
4749 x_iconify_frame (f
);
4750 else if (! NILP (visibility
))
4751 x_make_frame_visible (f
);
4753 /* Must have been Qnil. */
4757 /* Initialize `default-minibuffer-frame' in case this is the first
4758 frame on this terminal. */
4759 if (FRAME_HAS_MINIBUF_P (f
)
4760 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
4761 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
4762 kset_default_minibuffer_frame (kb
, frame
);
4764 /* All remaining specified parameters, which have not been "used"
4765 by x_get_arg and friends, now go in the misc. alist of the frame. */
4766 for (tem
= parameters
; CONSP (tem
); tem
= XCDR (tem
))
4767 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
4768 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
4772 /* Make sure windows on this frame appear in calls to next-window
4773 and similar functions. */
4774 Vwindow_list
= Qnil
;
4776 return unbind_to (count
, frame
);
4779 /* FRAME is used only to get a handle on the X display. We don't pass the
4780 display info directly because we're called from frame.c, which doesn't
4781 know about that structure. */
4783 x_get_focus_frame (struct frame
*frame
)
4785 struct w32_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4787 if (! dpyinfo
->w32_focus_frame
)
4790 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
4794 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4795 doc
: /* Internal function called by `color-defined-p', which see.
4796 \(Note that the Nextstep version of this function ignores FRAME.) */)
4797 (Lisp_Object color
, Lisp_Object frame
)
4800 struct frame
*f
= decode_window_system_frame (frame
);
4802 CHECK_STRING (color
);
4804 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4810 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4811 doc
: /* Internal function called by `color-values', which see. */)
4812 (Lisp_Object color
, Lisp_Object frame
)
4815 struct frame
*f
= decode_window_system_frame (frame
);
4817 CHECK_STRING (color
);
4819 if (w32_defined_color (f
, SDATA (color
), &foo
, false))
4820 return list3i ((GetRValue (foo
.pixel
) << 8) | GetRValue (foo
.pixel
),
4821 (GetGValue (foo
.pixel
) << 8) | GetGValue (foo
.pixel
),
4822 (GetBValue (foo
.pixel
) << 8) | GetBValue (foo
.pixel
));
4827 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4828 doc
: /* Internal function called by `display-color-p', which see. */)
4829 (Lisp_Object display
)
4831 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4833 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
4839 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
4840 Sx_display_grayscale_p
, 0, 1, 0,
4841 doc
: /* Return t if DISPLAY supports shades of gray.
4842 Note that color displays do support shades of gray.
4843 The optional argument DISPLAY specifies which display to ask about.
4844 DISPLAY should be either a frame or a display name (a string).
4845 If omitted or nil, that stands for the selected frame's display. */)
4846 (Lisp_Object display
)
4848 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4850 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
4856 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
4857 Sx_display_pixel_width
, 0, 1, 0,
4858 doc
: /* Return the width in pixels of DISPLAY.
4859 The optional argument DISPLAY specifies which display to ask about.
4860 DISPLAY should be either a frame or a display name (a string).
4861 If omitted or nil, that stands for the selected frame's display.
4863 On \"multi-monitor\" setups this refers to the pixel width for all
4864 physical monitors associated with DISPLAY. To get information for
4865 each physical monitor, use `display-monitor-attributes-list'. */)
4866 (Lisp_Object display
)
4868 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4870 return make_number (x_display_pixel_width (dpyinfo
));
4873 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4874 Sx_display_pixel_height
, 0, 1, 0,
4875 doc
: /* Return the height in pixels of DISPLAY.
4876 The optional argument DISPLAY specifies which display to ask about.
4877 DISPLAY should be either a frame or a display name (a string).
4878 If omitted or nil, that stands for the selected frame's display.
4880 On \"multi-monitor\" setups this refers to the pixel height for all
4881 physical monitors associated with DISPLAY. To get information for
4882 each physical monitor, use `display-monitor-attributes-list'. */)
4883 (Lisp_Object display
)
4885 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4887 return make_number (x_display_pixel_height (dpyinfo
));
4890 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4892 doc
: /* Return the number of bitplanes of DISPLAY.
4893 The optional argument DISPLAY specifies which display to ask about.
4894 DISPLAY should be either a frame or a display name (a string).
4895 If omitted or nil, that stands for the selected frame's display. */)
4896 (Lisp_Object display
)
4898 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4900 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
4903 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4905 doc
: /* Return the number of color cells of DISPLAY.
4906 The optional argument DISPLAY specifies which display to ask about.
4907 DISPLAY should be either a frame or a display name (a string).
4908 If omitted or nil, that stands for the selected frame's display. */)
4909 (Lisp_Object display
)
4911 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4914 /* Don't use NCOLORS: it returns incorrect results under remote
4915 * desktop. We force 24+ bit depths to 24-bit, both to prevent an
4916 * overflow and because probably is more meaningful on Windows
4919 cap
= 1 << min (dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
4920 return make_number (cap
);
4923 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4924 Sx_server_max_request_size
,
4926 doc
: /* Return the maximum request size of the server of DISPLAY.
4927 The optional argument DISPLAY specifies which display to ask about.
4928 DISPLAY should be either a frame or a display name (a string).
4929 If omitted or nil, that stands for the selected frame's display. */)
4930 (Lisp_Object display
)
4932 return make_number (1);
4935 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4936 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
4938 \(Labeling every distributor as a "vendor" embodies the false assumption
4939 that operating systems cannot be developed and distributed noncommercially.)
4941 For GNU and Unix systems, this queries the X server software; for
4942 MS-Windows, this queries the OS.
4944 The optional argument TERMINAL specifies which display to ask about.
4945 TERMINAL should be a terminal object, a frame or a display name (a string).
4946 If omitted or nil, that stands for the selected frame's display. */)
4947 (Lisp_Object terminal
)
4949 return build_string ("Microsoft Corp.");
4952 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4953 doc
: /* Return the version numbers of the GUI software on TERMINAL.
4954 The value is a list of three integers specifying the version of the GUI
4957 For GNU and Unix system, the first 2 numbers are the version of the X
4958 Protocol used on TERMINAL and the 3rd number is the distributor-specific
4959 release number. For MS-Windows, the 3 numbers report the version and
4960 the build number of the OS.
4962 See also the function `x-server-vendor'.
4964 The optional argument TERMINAL specifies which display to ask about.
4965 TERMINAL should be a terminal object, a frame or a display name (a string).
4966 If omitted or nil, that stands for the selected frame's display. */)
4967 (Lisp_Object terminal
)
4969 return list3i (w32_major_version
, w32_minor_version
, w32_build_number
);
4972 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4973 doc
: /* Return the number of screens on the server of DISPLAY.
4974 The optional argument DISPLAY specifies which display to ask about.
4975 DISPLAY should be either a frame or a display name (a string).
4976 If omitted or nil, that stands for the selected frame's display. */)
4977 (Lisp_Object display
)
4979 return make_number (1);
4982 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
4983 Sx_display_mm_height
, 0, 1, 0,
4984 doc
: /* Return the height in millimeters of DISPLAY.
4985 The optional argument DISPLAY specifies which display to ask about.
4986 DISPLAY should be either a frame or a display name (a string).
4987 If omitted or nil, that stands for the selected frame's display.
4989 On \"multi-monitor\" setups this refers to the height in millimeters for
4990 all physical monitors associated with DISPLAY. To get information
4991 for each physical monitor, use `display-monitor-attributes-list'. */)
4992 (Lisp_Object display
)
4994 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
4996 double mm_per_pixel
;
4999 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5000 / GetDeviceCaps (hdc
, VERTRES
));
5001 ReleaseDC (NULL
, hdc
);
5003 return make_number (x_display_pixel_height (dpyinfo
) * mm_per_pixel
+ 0.5);
5006 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
5007 doc
: /* Return the width in millimeters of DISPLAY.
5008 The optional argument DISPLAY specifies which display to ask about.
5009 DISPLAY should be either a frame or a display name (a string).
5010 If omitted or nil, that stands for the selected frame's display.
5012 On \"multi-monitor\" setups this refers to the width in millimeters for
5013 all physical monitors associated with TERMINAL. To get information
5014 for each physical monitor, use `display-monitor-attributes-list'. */)
5015 (Lisp_Object display
)
5017 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5019 double mm_per_pixel
;
5022 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5023 / GetDeviceCaps (hdc
, HORZRES
));
5024 ReleaseDC (NULL
, hdc
);
5026 return make_number (x_display_pixel_width (dpyinfo
) * mm_per_pixel
+ 0.5);
5029 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
5030 Sx_display_backing_store
, 0, 1, 0,
5031 doc
: /* Return an indication of whether DISPLAY does backing store.
5032 The value may be `always', `when-mapped', or `not-useful'.
5033 The optional argument DISPLAY specifies which display to ask about.
5034 DISPLAY should be either a frame or a display name (a string).
5035 If omitted or nil, that stands for the selected frame's display. */)
5036 (Lisp_Object display
)
5038 return intern ("not-useful");
5041 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
5042 Sx_display_visual_class
, 0, 1, 0,
5043 doc
: /* Return the visual class of DISPLAY.
5044 The value is one of the symbols `static-gray', `gray-scale',
5045 `static-color', `pseudo-color', `true-color', or `direct-color'.
5047 The optional argument DISPLAY specifies which display to ask about.
5048 DISPLAY should be either a frame or a display name (a string).
5049 If omitted or nil, that stands for the selected frame's display. */)
5050 (Lisp_Object display
)
5052 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5053 Lisp_Object result
= Qnil
;
5055 if (dpyinfo
->has_palette
)
5056 result
= intern ("pseudo-color");
5057 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
5058 result
= intern ("static-grey");
5059 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
5060 result
= intern ("static-color");
5061 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
5062 result
= intern ("true-color");
5067 DEFUN ("x-display-save-under", Fx_display_save_under
,
5068 Sx_display_save_under
, 0, 1, 0,
5069 doc
: /* Return t if DISPLAY supports the save-under feature.
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
)
5078 static BOOL CALLBACK ALIGN_STACK
5079 w32_monitor_enum (HMONITOR monitor
, HDC hdc
, RECT
*rcMonitor
, LPARAM dwData
)
5081 Lisp_Object
*monitor_list
= (Lisp_Object
*) dwData
;
5083 *monitor_list
= Fcons (make_save_ptr (monitor
), *monitor_list
);
5089 w32_display_monitor_attributes_list (void)
5091 Lisp_Object attributes_list
= Qnil
, primary_monitor_attributes
= Qnil
;
5092 Lisp_Object monitor_list
= Qnil
, monitor_frames
, rest
, frame
;
5095 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5097 if (!(enum_display_monitors_fn
&& get_monitor_info_fn
5098 && monitor_from_window_fn
))
5101 if (!enum_display_monitors_fn (NULL
, NULL
, w32_monitor_enum
,
5102 (LPARAM
) &monitor_list
)
5103 || NILP (monitor_list
))
5107 for (rest
= monitor_list
; CONSP (rest
); rest
= XCDR (rest
))
5110 monitors
= xmalloc (n_monitors
* sizeof (*monitors
));
5111 for (i
= 0; i
< n_monitors
; i
++)
5113 monitors
[i
] = XSAVE_POINTER (XCAR (monitor_list
), 0);
5114 monitor_list
= XCDR (monitor_list
);
5117 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
5118 FOR_EACH_FRAME (rest
, frame
)
5120 struct frame
*f
= XFRAME (frame
);
5122 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5125 monitor_from_window_fn (FRAME_W32_WINDOW (f
),
5126 MONITOR_DEFAULT_TO_NEAREST
);
5128 for (i
= 0; i
< n_monitors
; i
++)
5129 if (monitors
[i
] == monitor
)
5133 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
5137 GCPRO3 (attributes_list
, primary_monitor_attributes
, monitor_frames
);
5139 for (i
= 0; i
< n_monitors
; i
++)
5141 Lisp_Object geometry
, workarea
, name
, attributes
= Qnil
;
5143 int width_mm
, height_mm
;
5144 struct MONITOR_INFO_EX mi
;
5146 mi
.cbSize
= sizeof (mi
);
5147 if (!get_monitor_info_fn (monitors
[i
], (struct MONITOR_INFO
*) &mi
))
5150 hdc
= CreateDCA ("DISPLAY", mi
.szDevice
, NULL
, NULL
);
5153 width_mm
= GetDeviceCaps (hdc
, HORZSIZE
);
5154 height_mm
= GetDeviceCaps (hdc
, VERTSIZE
);
5157 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
5160 name
= DECODE_SYSTEM (build_unibyte_string (mi
.szDevice
));
5162 attributes
= Fcons (Fcons (Qname
, name
), attributes
);
5164 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5167 workarea
= list4i (mi
.rcWork
.left
, mi
.rcWork
.top
,
5168 mi
.rcWork
.right
- mi
.rcWork
.left
,
5169 mi
.rcWork
.bottom
- mi
.rcWork
.top
);
5170 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5172 geometry
= list4i (mi
.rcMonitor
.left
, mi
.rcMonitor
.top
,
5173 mi
.rcMonitor
.right
- mi
.rcMonitor
.left
,
5174 mi
.rcMonitor
.bottom
- mi
.rcMonitor
.top
);
5175 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5177 if (mi
.dwFlags
& MONITORINFOF_PRIMARY
)
5178 primary_monitor_attributes
= attributes
;
5180 attributes_list
= Fcons (attributes
, attributes_list
);
5183 if (!NILP (primary_monitor_attributes
))
5184 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
5190 return attributes_list
;
5194 w32_display_monitor_attributes_list_fallback (struct w32_display_info
*dpyinfo
)
5196 Lisp_Object geometry
, workarea
, frames
, rest
, frame
, attributes
= Qnil
;
5198 double mm_per_pixel
;
5199 int pixel_width
, pixel_height
, width_mm
, height_mm
;
5202 /* Fallback: treat (possibly) multiple physical monitors as if they
5203 formed a single monitor as a whole. This should provide a
5204 consistent result at least on single monitor environments. */
5205 attributes
= Fcons (Fcons (Qname
, build_string ("combined screen")),
5209 FOR_EACH_FRAME (rest
, frame
)
5211 struct frame
*f
= XFRAME (frame
);
5213 if (FRAME_W32_P (f
) && !EQ (frame
, tip_frame
))
5214 frames
= Fcons (frame
, frames
);
5216 attributes
= Fcons (Fcons (Qframes
, frames
), attributes
);
5218 pixel_width
= x_display_pixel_width (dpyinfo
);
5219 pixel_height
= x_display_pixel_height (dpyinfo
);
5222 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, HORZSIZE
)
5223 / GetDeviceCaps (hdc
, HORZRES
));
5224 width_mm
= pixel_width
* mm_per_pixel
+ 0.5;
5225 mm_per_pixel
= ((double) GetDeviceCaps (hdc
, VERTSIZE
)
5226 / GetDeviceCaps (hdc
, VERTRES
));
5227 height_mm
= pixel_height
* mm_per_pixel
+ 0.5;
5228 ReleaseDC (NULL
, hdc
);
5229 attributes
= Fcons (Fcons (Qmm_size
, list2i (width_mm
, height_mm
)),
5232 /* GetSystemMetrics below may return 0 for Windows 95 or NT 4.0, but
5234 geometry
= list4i (GetSystemMetrics (SM_XVIRTUALSCREEN
),
5235 GetSystemMetrics (SM_YVIRTUALSCREEN
),
5236 pixel_width
, pixel_height
);
5237 if (SystemParametersInfo (SPI_GETWORKAREA
, 0, &workarea_rect
, 0))
5238 workarea
= list4i (workarea_rect
.left
, workarea_rect
.top
,
5239 workarea_rect
.right
- workarea_rect
.left
,
5240 workarea_rect
.bottom
- workarea_rect
.top
);
5242 workarea
= geometry
;
5243 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
5245 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
5247 return list1 (attributes
);
5250 DEFUN ("w32-display-monitor-attributes-list", Fw32_display_monitor_attributes_list
,
5251 Sw32_display_monitor_attributes_list
,
5253 doc
: /* Return a list of physical monitor attributes on the W32 display DISPLAY.
5255 The optional argument DISPLAY specifies which display to ask about.
5256 DISPLAY should be either a frame or a display name (a string).
5257 If omitted or nil, that stands for the selected frame's display.
5259 Internal use only, use `display-monitor-attributes-list' instead. */)
5260 (Lisp_Object display
)
5262 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5263 Lisp_Object attributes_list
;
5266 attributes_list
= w32_display_monitor_attributes_list ();
5267 if (NILP (attributes_list
))
5268 attributes_list
= w32_display_monitor_attributes_list_fallback (dpyinfo
);
5271 return attributes_list
;
5274 DEFUN ("set-message-beep", Fset_message_beep
, Sset_message_beep
, 1, 1, 0,
5275 doc
: /* Set the sound generated when the bell is rung.
5276 SOUND is 'asterisk, 'exclamation, 'hand, 'question, 'ok, or 'silent
5277 to use the corresponding system sound for the bell. The 'silent sound
5278 prevents Emacs from making any sound at all.
5279 SOUND is nil to use the normal beep. */)
5282 CHECK_SYMBOL (sound
);
5285 sound_type
= 0xFFFFFFFF;
5286 else if (EQ (sound
, intern ("asterisk")))
5287 sound_type
= MB_ICONASTERISK
;
5288 else if (EQ (sound
, intern ("exclamation")))
5289 sound_type
= MB_ICONEXCLAMATION
;
5290 else if (EQ (sound
, intern ("hand")))
5291 sound_type
= MB_ICONHAND
;
5292 else if (EQ (sound
, intern ("question")))
5293 sound_type
= MB_ICONQUESTION
;
5294 else if (EQ (sound
, intern ("ok")))
5296 else if (EQ (sound
, intern ("silent")))
5297 sound_type
= MB_EMACS_SILENT
;
5299 sound_type
= 0xFFFFFFFF;
5305 x_screen_planes (register struct frame
*f
)
5307 return FRAME_DISPLAY_INFO (f
)->n_planes
;
5310 /* Return the display structure for the display named NAME.
5311 Open a new connection if necessary. */
5313 struct w32_display_info
*
5314 x_display_info_for_name (Lisp_Object name
)
5316 struct w32_display_info
*dpyinfo
;
5318 CHECK_STRING (name
);
5320 for (dpyinfo
= &one_w32_display_info
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
5321 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
5324 /* Use this general default value to start with. */
5325 Vx_resource_name
= Vinvocation_name
;
5327 validate_x_resource_name ();
5329 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
5330 SSDATA (Vx_resource_name
));
5333 error ("Cannot connect to server %s", SDATA (name
));
5335 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5340 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5341 1, 3, 0, doc
: /* Open a connection to a display server.
5342 DISPLAY is the name of the display to connect to.
5343 Optional second arg XRM-STRING is a string of resources in xrdb format.
5344 If the optional third arg MUST-SUCCEED is non-nil,
5345 terminate Emacs if we can't open the connection.
5346 \(In the Nextstep version, the last two arguments are currently ignored.) */)
5347 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
5349 unsigned char *xrm_option
;
5350 struct w32_display_info
*dpyinfo
;
5352 CHECK_STRING (display
);
5354 /* Signal an error in order to encourage correct use from callers.
5355 * If we ever support multiple window systems in the same Emacs,
5356 * we'll need callers to be precise about what window system they
5359 if (strcmp (SSDATA (display
), "w32") != 0)
5360 error ("The name of the display in this Emacs must be \"w32\"");
5362 /* If initialization has already been done, return now to avoid
5363 overwriting critical parts of one_w32_display_info. */
5364 if (window_system_available (NULL
))
5367 if (! NILP (xrm_string
))
5368 CHECK_STRING (xrm_string
);
5370 /* Allow color mapping to be defined externally; first look in user's
5371 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
5373 Lisp_Object color_file
;
5374 struct gcpro gcpro1
;
5376 color_file
= build_string ("~/rgb.txt");
5378 GCPRO1 (color_file
);
5380 if (NILP (Ffile_readable_p (color_file
)))
5382 Fexpand_file_name (build_string ("rgb.txt"),
5383 Fsymbol_value (intern ("data-directory")));
5385 Vw32_color_map
= Fx_load_color_file (color_file
);
5389 if (NILP (Vw32_color_map
))
5390 Vw32_color_map
= w32_default_color_map ();
5392 /* Merge in system logical colors. */
5393 add_system_logical_colors_to_map (&Vw32_color_map
);
5395 if (! NILP (xrm_string
))
5396 xrm_option
= SDATA (xrm_string
);
5398 xrm_option
= (unsigned char *) 0;
5400 /* Use this general default value to start with. */
5401 /* First remove .exe suffix from invocation-name - it looks ugly. */
5403 char basename
[ MAX_PATH
], *str
;
5405 lispstpcpy (basename
, Vinvocation_name
);
5406 str
= strrchr (basename
, '.');
5408 Vinvocation_name
= build_string (basename
);
5410 Vx_resource_name
= Vinvocation_name
;
5412 validate_x_resource_name ();
5414 /* This is what opens the connection and sets x_current_display.
5415 This also initializes many symbols, such as those used for input. */
5416 dpyinfo
= w32_term_init (display
, xrm_option
,
5417 SSDATA (Vx_resource_name
));
5421 if (!NILP (must_succeed
))
5422 fatal ("Cannot connect to server %s.\n",
5425 error ("Cannot connect to server %s", SDATA (display
));
5428 XSETFASTINT (Vwindow_system_version
, w32_major_version
);
5432 DEFUN ("x-close-connection", Fx_close_connection
,
5433 Sx_close_connection
, 1, 1, 0,
5434 doc
: /* Close the connection to DISPLAY's server.
5435 For DISPLAY, specify either a frame or a display name (a string).
5436 If DISPLAY is nil, that stands for the selected frame's display. */)
5437 (Lisp_Object display
)
5439 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
5441 if (dpyinfo
->reference_count
> 0)
5442 error ("Display still has frames on it");
5445 x_destroy_all_bitmaps (dpyinfo
);
5447 x_delete_display (dpyinfo
);
5453 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5454 doc
: /* Return the list of display names that Emacs has connections to. */)
5457 Lisp_Object result
= Qnil
;
5458 struct w32_display_info
*wdi
;
5460 for (wdi
= x_display_list
; wdi
; wdi
= wdi
->next
)
5461 result
= Fcons (XCAR (wdi
->name_list_element
), result
);
5466 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5467 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5468 This function only has an effect on X Windows. With MS Windows, it is
5469 defined but does nothing.
5471 If ON is nil, allow buffering of requests.
5472 Turning on synchronization prohibits the Xlib routines from buffering
5473 requests and seriously degrades performance, but makes debugging much
5475 The optional second argument TERMINAL specifies which display to act on.
5476 TERMINAL should be a terminal object, a frame or a display name (a string).
5477 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
5478 (Lisp_Object on
, Lisp_Object display
)
5485 /***********************************************************************
5487 ***********************************************************************/
5489 #if 0 /* TODO : port window properties to W32 */
5491 DEFUN ("x-change-window-property", Fx_change_window_property
,
5492 Sx_change_window_property
, 2, 6, 0,
5493 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
5494 PROP must be a string. VALUE may be a string or a list of conses,
5495 numbers and/or strings. If an element in the list is a string, it is
5496 converted to an atom and the value of the Atom is used. If an element
5497 is a cons, it is converted to a 32 bit number where the car is the 16
5498 top bits and the cdr is the lower 16 bits.
5500 FRAME nil or omitted means use the selected frame.
5501 If TYPE is given and non-nil, it is the name of the type of VALUE.
5502 If TYPE is not given or nil, the type is STRING.
5503 FORMAT gives the size in bits of each element if VALUE is a list.
5504 It must be one of 8, 16 or 32.
5505 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
5506 If OUTER-P is non-nil, the property is changed for the outer X window of
5507 FRAME. Default is to change on the edit X window. */)
5508 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
5509 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
5511 struct frame
*f
= decode_window_system_frame (frame
);
5514 CHECK_STRING (prop
);
5515 CHECK_STRING (value
);
5518 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5519 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5520 prop_atom
, XA_STRING
, 8, PropModeReplace
,
5521 SDATA (value
), SCHARS (value
));
5523 /* Make sure the property is set when we return. */
5524 XFlush (FRAME_W32_DISPLAY (f
));
5531 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
5532 Sx_delete_window_property
, 1, 2, 0,
5533 doc
: /* Remove window property PROP from X window of FRAME.
5534 FRAME nil or omitted means use the selected frame. Value is PROP. */)
5535 (Lisp_Object prop
, Lisp_Object frame
)
5537 struct frame
*f
= decode_window_system_frame (frame
);
5540 CHECK_STRING (prop
);
5542 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5543 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
5545 /* Make sure the property is removed when we return. */
5546 XFlush (FRAME_W32_DISPLAY (f
));
5553 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5555 doc
: /* Value is the value of window property PROP on FRAME.
5556 If FRAME is nil or omitted, use the selected frame.
5558 On X Windows, the following optional arguments are also accepted:
5559 If TYPE is nil or omitted, get the property as a string.
5560 Otherwise TYPE is the name of the atom that denotes the type expected.
5561 If SOURCE is non-nil, get the property on that window instead of from
5562 FRAME. The number 0 denotes the root window.
5563 If DELETE-P is non-nil, delete the property after retrieving it.
5564 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5566 On MS Windows, this function accepts but ignores those optional arguments.
5568 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5569 no value of TYPE (always string in the MS Windows case). */)
5570 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5571 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5573 struct frame
*f
= decode_window_system_frame (frame
);
5576 Lisp_Object prop_value
= Qnil
;
5577 char *tmp_data
= NULL
;
5580 unsigned long actual_size
, bytes_remaining
;
5582 CHECK_STRING (prop
);
5584 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), SDATA (prop
), False
);
5585 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5586 prop_atom
, 0, 0, False
, XA_STRING
,
5587 &actual_type
, &actual_format
, &actual_size
,
5588 &bytes_remaining
, (unsigned char **) &tmp_data
);
5591 int size
= bytes_remaining
;
5596 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
5597 prop_atom
, 0, bytes_remaining
,
5599 &actual_type
, &actual_format
,
5600 &actual_size
, &bytes_remaining
,
5601 (unsigned char **) &tmp_data
);
5603 prop_value
= make_string (tmp_data
, size
);
5617 /***********************************************************************
5619 ***********************************************************************/
5621 static Lisp_Object
x_create_tip_frame (struct w32_display_info
*,
5622 Lisp_Object
, Lisp_Object
);
5623 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5624 Lisp_Object
, int, int, int *, int *);
5626 /* The frame of a currently visible tooltip. */
5628 Lisp_Object tip_frame
;
5630 /* If non-nil, a timer started that hides the last tooltip when it
5633 Lisp_Object tip_timer
;
5636 /* If non-nil, a vector of 3 elements containing the last args
5637 with which x-show-tip was called. See there. */
5639 Lisp_Object last_show_tip_args
;
5643 unwind_create_tip_frame (Lisp_Object frame
)
5645 Lisp_Object deleted
;
5647 deleted
= unwind_create_frame (frame
);
5648 if (EQ (deleted
, Qt
))
5656 /* Create a frame for a tooltip on the display described by DPYINFO.
5657 PARMS is a list of frame parameters. TEXT is the string to
5658 display in the tip frame. Value is the frame.
5660 Note that functions called here, esp. x_default_parameter can
5661 signal errors, for instance when a specified color name is
5662 undefined. We have to make sure that we're in a consistent state
5663 when this happens. */
5666 x_create_tip_frame (struct w32_display_info
*dpyinfo
,
5667 Lisp_Object parms
, Lisp_Object text
)
5672 long window_prompting
= 0;
5674 ptrdiff_t count
= SPECPDL_INDEX ();
5675 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5677 bool face_change_before
= face_change
;
5679 struct buffer
*old_buffer
;
5681 /* Use this general default value to start with until we know if
5682 this frame has a specified name. */
5683 Vx_resource_name
= Vinvocation_name
;
5685 kb
= dpyinfo
->terminal
->kboard
;
5687 /* The calls to x_get_arg remove elements from PARMS, so copy it to
5688 avoid destructive changes behind our caller's back. */
5689 parms
= Fcopy_alist (parms
);
5691 /* Get the name of the frame to use for resource lookup. */
5692 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5694 && !EQ (name
, Qunbound
)
5696 error ("Invalid frame name--not a string or nil");
5697 Vx_resource_name
= name
;
5700 GCPRO3 (parms
, name
, frame
);
5701 /* Make a frame without minibuffer nor mode-line. */
5702 f
= make_frame (false);
5703 f
->wants_modeline
= 0;
5704 XSETFRAME (frame
, f
);
5706 AUTO_STRING (tip
, " *tip*");
5707 buffer
= Fget_buffer_create (tip
);
5708 /* Use set_window_buffer instead of Fset_window_buffer (see
5709 discussion of bug#11984, bug#12025, bug#12026). */
5710 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5711 old_buffer
= current_buffer
;
5712 set_buffer_internal_1 (XBUFFER (buffer
));
5713 bset_truncate_lines (current_buffer
, Qnil
);
5714 specbind (Qinhibit_read_only
, Qt
);
5715 specbind (Qinhibit_modification_hooks
, Qt
);
5718 set_buffer_internal_1 (old_buffer
);
5720 record_unwind_protect (unwind_create_tip_frame
, frame
);
5722 /* By setting the output method, we're essentially saying that
5723 the frame is live, as per FRAME_LIVE_P. If we get a signal
5724 from this point on, x_destroy_window might screw up reference
5726 f
->terminal
= dpyinfo
->terminal
;
5727 f
->output_method
= output_w32
;
5728 f
->output_data
.w32
= xzalloc (sizeof (struct w32_output
));
5730 FRAME_FONTSET (f
) = -1;
5731 fset_icon_name (f
, Qnil
);
5734 image_cache_refcount
=
5735 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5736 dpyinfo_refcount
= dpyinfo
->reference_count
;
5737 #endif /* GLYPH_DEBUG */
5738 FRAME_KBOARD (f
) = kb
;
5739 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5740 f
->output_data
.w32
->explicit_parent
= false;
5742 /* Set the name; the functions to which we pass f expect the name to
5744 if (EQ (name
, Qunbound
) || NILP (name
))
5746 fset_name (f
, build_string (dpyinfo
->w32_id_name
));
5747 f
->explicit_name
= false;
5751 fset_name (f
, name
);
5752 f
->explicit_name
= true;
5753 /* use the frame's title when getting resources for this frame. */
5754 specbind (Qx_resource_name
, name
);
5757 if (uniscribe_available
)
5758 register_font_driver (&uniscribe_font_driver
, f
);
5759 register_font_driver (&w32font_driver
, f
);
5761 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5762 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5764 /* Extract the window parameters from the supplied values
5765 that are needed to determine window geometry. */
5766 x_default_font_parameter (f
, parms
);
5768 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5769 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5770 /* This defaults to 2 in order to match xterm. We recognize either
5771 internalBorderWidth or internalBorder (which is what xterm calls
5773 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5777 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5778 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5779 if (! EQ (value
, Qunbound
))
5780 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5783 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5784 "internalBorderWidth", "internalBorderWidth",
5786 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5787 NULL
, NULL
, RES_TYPE_NUMBER
);
5788 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5789 NULL
, NULL
, RES_TYPE_NUMBER
);
5791 /* Also do the stuff which must be set before the window exists. */
5792 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5793 "foreground", "Foreground", RES_TYPE_STRING
);
5794 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5795 "background", "Background", RES_TYPE_STRING
);
5796 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5797 "pointerColor", "Foreground", RES_TYPE_STRING
);
5798 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5799 "cursorColor", "Foreground", RES_TYPE_STRING
);
5800 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5801 "borderColor", "BorderColor", RES_TYPE_STRING
);
5802 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
5803 "alpha", "Alpha", RES_TYPE_NUMBER
);
5805 /* Init faces before x_default_parameter is called for the
5806 scroll-bar-width parameter because otherwise we end up in
5807 init_iterator with a null face cache, which should not happen. */
5808 init_frame_faces (f
);
5810 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
5811 f
->output_data
.w32
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5813 window_prompting
= x_figure_window_size (f
, parms
, false);
5815 /* No fringes on tip frame. */
5817 f
->left_fringe_width
= 0;
5818 f
->right_fringe_width
= 0;
5821 my_create_tip_window (f
);
5826 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5827 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5828 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5829 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5830 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5831 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5833 /* Dimensions, especially FRAME_LINES (f), must be done via
5834 change_frame_size. Change will not be effected unless different
5835 from the current FRAME_LINES (f). */
5836 width
= FRAME_COLS (f
);
5837 height
= FRAME_LINES (f
);
5838 SET_FRAME_COLS (f
, 0);
5839 SET_FRAME_LINES (f
, 0);
5840 adjust_frame_size (f
, width
* FRAME_COLUMN_WIDTH (f
),
5841 height
* FRAME_LINE_HEIGHT (f
), 0, true, Qtip_frame
);
5843 /* Add `tooltip' frame parameter's default value. */
5844 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5845 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
5847 /* Set up faces after all frame parameters are known. This call
5848 also merges in face attributes specified for new frames.
5850 Frame parameters may be changed if .Xdefaults contains
5851 specifications for the default font. For example, if there is an
5852 `Emacs.default.attributeBackground: pink', the `background-color'
5853 attribute of the frame get's set, which let's the internal border
5854 of the tooltip frame appear in pink. Prevent this. */
5856 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5857 Lisp_Object fg
= Fframe_parameter (frame
, Qforeground_color
);
5858 Lisp_Object colors
= Qnil
;
5860 /* Set tip_frame here, so that */
5862 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5864 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5865 colors
= Fcons (Fcons (Qbackground_color
, bg
), colors
);
5866 if (!EQ (fg
, Fframe_parameter (frame
, Qforeground_color
)))
5867 colors
= Fcons (Fcons (Qforeground_color
, fg
), colors
);
5870 Fmodify_frame_parameters (frame
, colors
);
5877 /* Now that the frame is official, it counts as a reference to
5879 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5880 f
->terminal
->reference_count
++;
5882 /* It is now ok to make the frame official even if we get an error
5883 below. And the frame needs to be on Vframe_list or making it
5884 visible won't work. */
5885 Vframe_list
= Fcons (frame
, Vframe_list
);
5886 f
->can_x_set_window_size
= true;
5888 /* Setting attributes of faces of the tooltip frame from resources
5889 and similar will set face_change, which leads to the
5890 clearing of all current matrices. Since this isn't necessary
5891 here, avoid it by resetting face_change to the value it
5892 had before we created the tip frame. */
5893 face_change
= face_change_before
;
5895 /* Discard the unwind_protect. */
5896 return unbind_to (count
, frame
);
5900 /* Compute where to display tip frame F. PARMS is the list of frame
5901 parameters for F. DX and DY are specified offsets from the current
5902 location of the mouse. WIDTH and HEIGHT are the width and height
5903 of the tooltip. Return coordinates relative to the root window of
5904 the display in *ROOT_X, and *ROOT_Y. */
5907 compute_tip_xy (struct frame
*f
,
5908 Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
,
5909 int width
, int height
, int *root_x
, int *root_y
)
5911 Lisp_Object left
, top
;
5912 int min_x
, min_y
, max_x
, max_y
;
5914 /* User-specified position? */
5915 left
= Fcdr (Fassq (Qleft
, parms
));
5916 top
= Fcdr (Fassq (Qtop
, parms
));
5918 /* Move the tooltip window where the mouse pointer is. Resize and
5920 if (!INTEGERP (left
) || !INTEGERP (top
))
5924 /* Default min and max values. */
5927 max_x
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
));
5928 max_y
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
));
5936 /* If multiple monitor support is available, constrain the tip onto
5937 the current monitor. This improves the above by allowing negative
5938 co-ordinates if monitor positions are such that they are valid, and
5939 snaps a tooltip onto a single monitor if we are close to the edge
5940 where it would otherwise flow onto the other monitor (or into
5941 nothingness if there is a gap in the overlap). */
5942 if (monitor_from_point_fn
&& get_monitor_info_fn
)
5944 struct MONITOR_INFO info
;
5946 = monitor_from_point_fn (pt
, MONITOR_DEFAULT_TO_NEAREST
);
5947 info
.cbSize
= sizeof (info
);
5949 if (get_monitor_info_fn (monitor
, &info
))
5951 min_x
= info
.rcWork
.left
;
5952 min_y
= info
.rcWork
.top
;
5953 max_x
= info
.rcWork
.right
;
5954 max_y
= info
.rcWork
.bottom
;
5960 *root_y
= XINT (top
);
5961 else if (*root_y
+ XINT (dy
) <= min_y
)
5962 *root_y
= min_y
; /* Can happen for negative dy */
5963 else if (*root_y
+ XINT (dy
) + height
<= max_y
)
5964 /* It fits below the pointer */
5965 *root_y
+= XINT (dy
);
5966 else if (height
+ XINT (dy
) + min_y
<= *root_y
)
5967 /* It fits above the pointer. */
5968 *root_y
-= height
+ XINT (dy
);
5970 /* Put it on the top. */
5973 if (INTEGERP (left
))
5974 *root_x
= XINT (left
);
5975 else if (*root_x
+ XINT (dx
) <= min_x
)
5976 *root_x
= 0; /* Can happen for negative dx */
5977 else if (*root_x
+ XINT (dx
) + width
<= max_x
)
5978 /* It fits to the right of the pointer. */
5979 *root_x
+= XINT (dx
);
5980 else if (width
+ XINT (dx
) + min_x
<= *root_x
)
5981 /* It fits to the left of the pointer. */
5982 *root_x
-= width
+ XINT (dx
);
5984 /* Put it left justified on the screen -- it ought to fit that way. */
5989 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5990 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
5991 A tooltip window is a small window displaying a string.
5993 This is an internal function; Lisp code should call `tooltip-show'.
5995 FRAME nil or omitted means use the selected frame.
5997 PARMS is an optional list of frame parameters which can be
5998 used to change the tooltip's appearance.
6000 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
6001 means use the default timeout of 5 seconds.
6003 If the list of frame parameters PARMS contains a `left' parameter,
6004 the tooltip is displayed at that x-position. Otherwise it is
6005 displayed at the mouse position, with offset DX added (default is 5 if
6006 DX isn't specified). Likewise for the y-position; if a `top' frame
6007 parameter is specified, it determines the y-position of the tooltip
6008 window, otherwise it is displayed at the mouse position, with offset
6009 DY added (default is -10).
6011 A tooltip's maximum size is specified by `x-max-tooltip-size'.
6012 Text larger than the specified size is clipped. */)
6013 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
6018 struct buffer
*old_buffer
;
6019 struct text_pos pos
;
6020 int i
, width
, height
;
6021 bool seen_reversed_p
;
6022 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6023 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6024 ptrdiff_t count
= SPECPDL_INDEX ();
6026 specbind (Qinhibit_redisplay
, Qt
);
6028 GCPRO4 (string
, parms
, frame
, timeout
);
6030 CHECK_STRING (string
);
6031 f
= decode_window_system_frame (frame
);
6033 timeout
= make_number (5);
6035 CHECK_NATNUM (timeout
);
6038 dx
= make_number (5);
6043 dy
= make_number (-10);
6047 if (NILP (last_show_tip_args
))
6048 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
6050 if (!NILP (tip_frame
))
6052 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
6053 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
6054 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
6056 if (EQ (frame
, last_frame
)
6057 && !NILP (Fequal (last_string
, string
))
6058 && !NILP (Fequal (last_parms
, parms
)))
6060 struct frame
*f
= XFRAME (tip_frame
);
6062 /* Only DX and DY have changed. */
6063 if (!NILP (tip_timer
))
6065 Lisp_Object timer
= tip_timer
;
6067 call1 (Qcancel_timer
, timer
);
6071 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
6072 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
6074 /* Put tooltip in topmost group and in position. */
6075 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6076 root_x
, root_y
, 0, 0,
6077 SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6079 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6080 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6082 SWP_NOMOVE
| SWP_NOSIZE
6083 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6090 /* Hide a previous tip, if any. */
6093 ASET (last_show_tip_args
, 0, string
);
6094 ASET (last_show_tip_args
, 1, frame
);
6095 ASET (last_show_tip_args
, 2, parms
);
6097 /* Add default values to frame parameters. */
6098 if (NILP (Fassq (Qname
, parms
)))
6099 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
6100 if (NILP (Fassq (Qinternal_border_width
, parms
)))
6101 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
6102 if (NILP (Fassq (Qright_divider_width
, parms
)))
6103 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
6104 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
6105 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
6106 if (NILP (Fassq (Qborder_width
, parms
)))
6107 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
6108 if (NILP (Fassq (Qborder_color
, parms
)))
6109 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
6110 if (NILP (Fassq (Qbackground_color
, parms
)))
6111 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
6114 /* Block input until the tip has been fully drawn, to avoid crashes
6115 when drawing tips in menus. */
6118 /* Create a frame for the tooltip, and record it in the global
6119 variable tip_frame. */
6120 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
6123 /* Set up the frame's root window. */
6124 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6130 if (CONSP (Vx_max_tooltip_size
)
6131 && INTEGERP (XCAR (Vx_max_tooltip_size
))
6132 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
6133 && INTEGERP (XCDR (Vx_max_tooltip_size
))
6134 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
6136 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
6137 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
6142 w
->total_lines
= 40;
6145 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
6146 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
6148 FRAME_TOTAL_COLS (f
) = WINDOW_TOTAL_COLS (w
);
6149 adjust_frame_glyphs (f
);
6150 w
->pseudo_window_p
= true;
6152 /* Display the tooltip text in a temporary buffer. */
6153 old_buffer
= current_buffer
;
6154 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
6155 bset_truncate_lines (current_buffer
, Qnil
);
6156 clear_glyph_matrix (w
->desired_matrix
);
6157 clear_glyph_matrix (w
->current_matrix
);
6158 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
6159 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6161 /* Compute width and height of the tooltip. */
6163 seen_reversed_p
= false;
6164 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6166 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6170 /* Stop at the first empty row at the end. */
6171 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6174 /* Let the row go over the full width of the frame. */
6175 row
->full_width_p
= true;
6177 row_width
= row
->pixel_width
;
6178 if (row
->used
[TEXT_AREA
])
6180 if (!row
->reversed_p
)
6182 /* There's a glyph at the end of rows that is used to
6183 place the cursor there. Don't include the width of
6185 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6186 if (NILP (last
->object
))
6187 row_width
-= last
->pixel_width
;
6191 /* There could be a stretch glyph at the beginning of R2L
6192 rows that is produced by extend_face_to_end_of_line.
6193 Don't count that glyph. */
6194 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
6196 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
6198 row_width
-= g
->pixel_width
;
6199 seen_reversed_p
= true;
6204 height
+= row
->height
;
6205 width
= max (width
, row_width
);
6208 /* If we've seen partial-length R2L rows, we need to re-adjust the
6209 tool-tip frame width and redisplay it again, to avoid over-wide
6210 tips due to the stretch glyph that extends R2L lines to full
6211 width of the frame. */
6212 if (seen_reversed_p
)
6214 /* PXW: Why do we do the pixel-to-cols conversion only if
6215 seen_reversed_p holds? Don't we have to set other fields of
6216 the window/frame structure?
6218 w->total_cols and FRAME_TOTAL_COLS want the width in columns,
6220 w
->pixel_width
= width
;
6221 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
6222 w
->total_cols
= width
;
6223 FRAME_TOTAL_COLS (f
) = width
;
6224 SET_FRAME_WIDTH (f
, width
);
6225 adjust_frame_glyphs (f
);
6226 w
->pseudo_window_p
= 1;
6227 clear_glyph_matrix (w
->desired_matrix
);
6228 clear_glyph_matrix (w
->current_matrix
);
6229 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
6231 /* Recompute width and height of the tooltip. */
6232 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
6234 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
6238 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
6240 row
->full_width_p
= true;
6241 row_width
= row
->pixel_width
;
6242 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
6244 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
6245 if (NILP (last
->object
))
6246 row_width
-= last
->pixel_width
;
6249 height
+= row
->height
;
6250 width
= max (width
, row_width
);
6254 /* Add the frame's internal border to the width and height the w32
6255 window should have. */
6256 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6257 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
6259 /* Move the tooltip window where the mouse pointer is. Resize and
6262 PXW: This should use the frame's pixel coordinates. */
6263 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
6266 /* Adjust Window size to take border into account. */
6268 rect
.left
= rect
.top
= 0;
6270 rect
.bottom
= height
;
6271 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
6272 FRAME_EXTERNAL_MENU_BAR (f
));
6274 /* Position and size tooltip, and put it in the topmost group.
6275 The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
6276 peculiarity of w32 display: without it, some fonts cause the
6277 last character of the tip to be truncated or wrapped around to
6279 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
6281 rect
.right
- rect
.left
+ FRAME_COLUMN_WIDTH (f
),
6282 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6284 /* Ensure tooltip is on top of other topmost windows (eg menus). */
6285 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
6287 SWP_NOMOVE
| SWP_NOSIZE
6288 | SWP_NOACTIVATE
| SWP_NOOWNERZORDER
);
6290 /* Let redisplay know that we have made the frame visible already. */
6291 SET_FRAME_VISIBLE (f
, 1);
6293 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
6296 /* Draw into the window. */
6297 w
->must_be_updated_p
= true;
6298 update_single_window (w
);
6302 /* Restore original current buffer. */
6303 set_buffer_internal_1 (old_buffer
);
6304 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6307 /* Let the tip disappear after timeout seconds. */
6308 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
6309 intern ("x-hide-tip"));
6312 return unbind_to (count
, Qnil
);
6316 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
6317 doc
: /* Hide the current tooltip window, if there is any.
6318 Value is t if tooltip was open, nil otherwise. */)
6322 Lisp_Object deleted
, frame
, timer
;
6323 struct gcpro gcpro1
, gcpro2
;
6325 /* Return quickly if nothing to do. */
6326 if (NILP (tip_timer
) && NILP (tip_frame
))
6331 GCPRO2 (frame
, timer
);
6332 tip_frame
= tip_timer
= deleted
= Qnil
;
6334 count
= SPECPDL_INDEX ();
6335 specbind (Qinhibit_redisplay
, Qt
);
6336 specbind (Qinhibit_quit
, Qt
);
6339 call1 (Qcancel_timer
, timer
);
6343 delete_frame (frame
, Qnil
);
6348 return unbind_to (count
, deleted
);
6351 /***********************************************************************
6352 File selection dialog
6353 ***********************************************************************/
6355 #define FILE_NAME_TEXT_FIELD edt1
6356 #define FILE_NAME_COMBO_BOX cmb13
6357 #define FILE_NAME_LIST lst1
6359 /* Callback for altering the behavior of the Open File dialog.
6360 Makes the Filename text field contain "Current Directory" and be
6361 read-only when "Directories" is selected in the filter. This
6362 allows us to work around the fact that the standard Open File
6363 dialog does not support directories. */
6364 static UINT_PTR CALLBACK
6365 file_dialog_callback (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
6367 if (msg
== WM_NOTIFY
)
6369 OFNOTIFYW
* notify_w
= (OFNOTIFYW
*)lParam
;
6370 OFNOTIFYA
* notify_a
= (OFNOTIFYA
*)lParam
;
6371 int dropdown_changed
;
6373 #ifdef NTGUI_UNICODE
6374 const int use_unicode
= 1;
6375 #else /* !NTGUI_UNICODE */
6376 int use_unicode
= w32_unicode_filenames
;
6377 #endif /* NTGUI_UNICODE */
6379 /* Detect when the Filter dropdown is changed. */
6382 notify_w
->hdr
.code
== CDN_TYPECHANGE
6383 || notify_w
->hdr
.code
== CDN_INITDONE
;
6386 notify_a
->hdr
.code
== CDN_TYPECHANGE
6387 || notify_a
->hdr
.code
== CDN_INITDONE
;
6388 if (dropdown_changed
)
6390 HWND dialog
= GetParent (hwnd
);
6391 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
6392 HWND list
= GetDlgItem (dialog
, FILE_NAME_LIST
);
6395 /* At least on Windows 7, the above attempt to get the window handle
6396 to the File Name Text Field fails. The following code does the
6397 job though. Note that this code is based on my examination of the
6398 window hierarchy using Microsoft Spy++. bk */
6399 if (edit_control
== NULL
)
6401 HWND tmp
= GetDlgItem (dialog
, FILE_NAME_COMBO_BOX
);
6404 tmp
= GetWindow (tmp
, GW_CHILD
);
6406 edit_control
= GetWindow (tmp
, GW_CHILD
);
6410 /* Directories is in index 2. */
6413 dir_index
= notify_w
->lpOFN
->nFilterIndex
;
6414 hdr_code
= notify_w
->hdr
.code
;
6418 dir_index
= notify_a
->lpOFN
->nFilterIndex
;
6419 hdr_code
= notify_a
->hdr
.code
;
6424 SendMessageW (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6425 (LPARAM
)L
"Current Directory");
6427 SendMessageA (dialog
, CDM_SETCONTROLTEXT
, FILE_NAME_TEXT_FIELD
,
6428 (LPARAM
)"Current Directory");
6429 EnableWindow (edit_control
, FALSE
);
6430 /* Note that at least on Windows 7, the above call to EnableWindow
6431 disables the window that would ordinarily have focus. If we
6432 do not set focus to some other window here, focus will land in
6433 no man's land and the user will be unable to tab through the
6434 dialog box (pressing tab will only result in a beep).
6435 Avoid that problem by setting focus to the list here. */
6436 if (hdr_code
== CDN_INITDONE
)
6441 /* Don't override default filename on init done. */
6442 if (hdr_code
== CDN_TYPECHANGE
)
6445 SendMessageW (dialog
, CDM_SETCONTROLTEXT
,
6446 FILE_NAME_TEXT_FIELD
, (LPARAM
)L
"");
6448 SendMessageA (dialog
, CDM_SETCONTROLTEXT
,
6449 FILE_NAME_TEXT_FIELD
, (LPARAM
)"");
6451 EnableWindow (edit_control
, TRUE
);
6458 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6459 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6460 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6461 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6462 or directory must exist.
6464 This function is only defined on NS, MS Windows, and X Windows with the
6465 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6466 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6467 On Windows 7 and later, the file selection dialog "remembers" the last
6468 directory where the user selected a file, and will open that directory
6469 instead of DIR on subsequent invocations of this function with the same
6470 value of DIR as in previous invocations; this is standard Windows behavior. */)
6471 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6473 /* Filter index: 1: All Files, 2: Directories only */
6474 static const wchar_t filter_w
[] = L
"All Files (*.*)\0*.*\0Directories\0*|*\0";
6475 static const char filter_a
[] = "All Files (*.*)\0*.*\0Directories\0*|*\0";
6477 Lisp_Object filename
= default_filename
;
6478 struct frame
*f
= SELECTED_FRAME ();
6479 BOOL file_opened
= FALSE
;
6480 Lisp_Object orig_dir
= dir
;
6481 Lisp_Object orig_prompt
= prompt
;
6483 /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4
6484 compatibility) we end up with the old file dialogs. Define a big
6485 enough struct for the new dialog to trick GetOpenFileName into
6486 giving us the new dialogs on newer versions of Windows. */
6488 OPENFILENAMEW details
;
6489 #if _WIN32_WINNT < 0x500 /* < win2k */
6493 #endif /* < win2k */
6494 } new_file_details_w
;
6496 #ifdef NTGUI_UNICODE
6497 wchar_t filename_buf_w
[32*1024 + 1]; // NT kernel maximum
6498 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6499 const int use_unicode
= 1;
6500 #else /* not NTGUI_UNICODE */
6502 OPENFILENAMEA details
;
6503 #if _WIN32_WINNT < 0x500 /* < win2k */
6507 #endif /* < win2k */
6508 } new_file_details_a
;
6509 wchar_t filename_buf_w
[MAX_PATH
+ 1], dir_w
[MAX_PATH
];
6510 char filename_buf_a
[MAX_PATH
+ 1], dir_a
[MAX_PATH
];
6511 OPENFILENAMEW
* file_details_w
= &new_file_details_w
.details
;
6512 OPENFILENAMEA
* file_details_a
= &new_file_details_a
.details
;
6513 int use_unicode
= w32_unicode_filenames
;
6517 char fname_ret
[MAX_UTF8_PATH
];
6518 #endif /* NTGUI_UNICODE */
6520 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
6521 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, filename
);
6524 struct gcpro gcpro1
, gcpro2
;
6525 GCPRO2 (orig_dir
, orig_prompt
); /* There is no GCPRON, N>6. */
6527 /* Note: under NTGUI_UNICODE, we do _NOT_ use ENCODE_FILE: the
6528 system file encoding expected by the platform APIs (e.g. Cygwin's
6529 POSIX implementation) may not be the same as the encoding expected
6530 by the Windows "ANSI" APIs! */
6532 CHECK_STRING (prompt
);
6535 dir
= Fexpand_file_name (dir
, Qnil
);
6537 if (STRINGP (filename
))
6538 filename
= Ffile_name_nondirectory (filename
);
6540 filename
= empty_unibyte_string
;
6543 dir
= Fcygwin_convert_file_name_to_windows (dir
, Qt
);
6544 if (SCHARS (filename
) > 0)
6545 filename
= Fcygwin_convert_file_name_to_windows (filename
, Qnil
);
6549 CHECK_STRING (filename
);
6551 /* The code in file_dialog_callback that attempts to set the text
6552 of the file name edit window when handling the CDN_INITDONE
6553 WM_NOTIFY message does not work. Setting filename to "Current
6554 Directory" in the only_dir_p case here does work however. */
6555 if (SCHARS (filename
) == 0 && ! NILP (only_dir_p
))
6556 filename
= build_string ("Current Directory");
6558 /* Convert the values we've computed so far to system form. */
6559 #ifdef NTGUI_UNICODE
6560 to_unicode (prompt
, &prompt
);
6561 to_unicode (dir
, &dir
);
6562 to_unicode (filename
, &filename
);
6563 if (SBYTES (filename
) + 1 > sizeof (filename_buf_w
))
6564 report_file_error ("filename too long", default_filename
);
6566 memcpy (filename_buf_w
, SDATA (filename
), SBYTES (filename
) + 1);
6567 #else /* !NTGUI_UNICODE */
6568 prompt
= ENCODE_FILE (prompt
);
6569 dir
= ENCODE_FILE (dir
);
6570 filename
= ENCODE_FILE (filename
);
6572 /* We modify these in-place, so make copies for safety. */
6573 dir
= Fcopy_sequence (dir
);
6574 unixtodos_filename (SDATA (dir
));
6575 filename
= Fcopy_sequence (filename
);
6576 unixtodos_filename (SDATA (filename
));
6577 if (SBYTES (filename
) >= MAX_UTF8_PATH
)
6578 report_file_error ("filename too long", default_filename
);
6579 if (w32_unicode_filenames
)
6581 filename_to_utf16 (SSDATA (dir
), dir_w
);
6582 if (filename_to_utf16 (SSDATA (filename
), filename_buf_w
) != 0)
6584 /* filename_to_utf16 sets errno to ENOENT when the file
6585 name is too long or cannot be converted to UTF-16. */
6586 if (errno
== ENOENT
&& filename_buf_w
[MAX_PATH
- 1] != 0)
6587 report_file_error ("filename too long", default_filename
);
6589 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6590 SSDATA (prompt
), -1, NULL
, 0);
6593 prompt_w
= alloca (len
* sizeof (wchar_t));
6594 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6595 SSDATA (prompt
), -1, prompt_w
, len
);
6599 filename_to_ansi (SSDATA (dir
), dir_a
);
6600 if (filename_to_ansi (SSDATA (filename
), filename_buf_a
) != '\0')
6602 /* filename_to_ansi sets errno to ENOENT when the file
6603 name is too long or cannot be converted to UTF-16. */
6604 if (errno
== ENOENT
&& filename_buf_a
[MAX_PATH
- 1] != 0)
6605 report_file_error ("filename too long", default_filename
);
6607 len
= pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6608 SSDATA (prompt
), -1, NULL
, 0);
6611 prompt_w
= alloca (len
* sizeof (wchar_t));
6612 pMultiByteToWideChar (CP_UTF8
, MB_ERR_INVALID_CHARS
,
6613 SSDATA (prompt
), -1, prompt_w
, len
);
6614 len
= pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, NULL
, 0, NULL
, NULL
);
6617 prompt_a
= alloca (len
);
6618 pWideCharToMultiByte (CP_ACP
, 0, prompt_w
, -1, prompt_a
, len
, NULL
, NULL
);
6620 #endif /* NTGUI_UNICODE */
6622 /* Fill in the structure for the call to GetOpenFileName below.
6623 For NTGUI_UNICODE builds (which run only on NT), we just use
6624 the actual size of the structure. For non-NTGUI_UNICODE
6625 builds, we tell the OS we're using an old version of the
6626 structure if the OS isn't new enough to support the newer
6630 memset (&new_file_details_w
, 0, sizeof (new_file_details_w
));
6631 if (w32_major_version
> 4 && w32_major_version
< 95)
6632 file_details_w
->lStructSize
= sizeof (new_file_details_w
);
6634 file_details_w
->lStructSize
= sizeof (*file_details_w
);
6635 /* Set up the inout parameter for the selected file name. */
6636 file_details_w
->lpstrFile
= filename_buf_w
;
6637 file_details_w
->nMaxFile
=
6638 sizeof (filename_buf_w
) / sizeof (*filename_buf_w
);
6639 file_details_w
->hwndOwner
= FRAME_W32_WINDOW (f
);
6640 /* Undocumented Bug in Common File Dialog:
6641 If a filter is not specified, shell links are not resolved. */
6642 file_details_w
->lpstrFilter
= filter_w
;
6643 #ifdef NTGUI_UNICODE
6644 file_details_w
->lpstrInitialDir
= (wchar_t*) SDATA (dir
);
6645 file_details_w
->lpstrTitle
= (guichar_t
*) SDATA (prompt
);
6647 file_details_w
->lpstrInitialDir
= dir_w
;
6648 file_details_w
->lpstrTitle
= prompt_w
;
6650 file_details_w
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6651 file_details_w
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6652 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6653 if (!NILP (mustmatch
))
6655 /* Require that the path to the parent directory exists. */
6656 file_details_w
->Flags
|= OFN_PATHMUSTEXIST
;
6657 /* If we are looking for a file, require that it exists. */
6658 if (NILP (only_dir_p
))
6659 file_details_w
->Flags
|= OFN_FILEMUSTEXIST
;
6662 #ifndef NTGUI_UNICODE
6665 memset (&new_file_details_a
, 0, sizeof (new_file_details_a
));
6666 if (w32_major_version
> 4 && w32_major_version
< 95)
6667 file_details_a
->lStructSize
= sizeof (new_file_details_a
);
6669 file_details_a
->lStructSize
= sizeof (*file_details_a
);
6670 file_details_a
->lpstrFile
= filename_buf_a
;
6671 file_details_a
->nMaxFile
=
6672 sizeof (filename_buf_a
) / sizeof (*filename_buf_a
);
6673 file_details_a
->hwndOwner
= FRAME_W32_WINDOW (f
);
6674 file_details_a
->lpstrFilter
= filter_a
;
6675 file_details_a
->lpstrInitialDir
= dir_a
;
6676 file_details_a
->lpstrTitle
= prompt_a
;
6677 file_details_a
->nFilterIndex
= NILP (only_dir_p
) ? 1 : 2;
6678 file_details_a
->Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
6679 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
6680 if (!NILP (mustmatch
))
6682 /* Require that the path to the parent directory exists. */
6683 file_details_a
->Flags
|= OFN_PATHMUSTEXIST
;
6684 /* If we are looking for a file, require that it exists. */
6685 if (NILP (only_dir_p
))
6686 file_details_a
->Flags
|= OFN_FILEMUSTEXIST
;
6689 #endif /* !NTGUI_UNICODE */
6692 int count
= SPECPDL_INDEX ();
6693 /* Prevent redisplay. */
6694 specbind (Qinhibit_redisplay
, Qt
);
6698 file_details_w
->lpfnHook
= file_dialog_callback
;
6700 file_opened
= GetOpenFileNameW (file_details_w
);
6702 #ifndef NTGUI_UNICODE
6705 file_details_a
->lpfnHook
= file_dialog_callback
;
6707 file_opened
= GetOpenFileNameA (file_details_a
);
6709 #endif /* !NTGUI_UNICODE */
6711 unbind_to (count
, Qnil
);
6716 /* Get an Emacs string from the value Windows gave us. */
6717 #ifdef NTGUI_UNICODE
6718 filename
= from_unicode_buffer (filename_buf_w
);
6719 #else /* !NTGUI_UNICODE */
6721 filename_from_utf16 (filename_buf_w
, fname_ret
);
6723 filename_from_ansi (filename_buf_a
, fname_ret
);
6724 dostounix_filename (fname_ret
);
6725 filename
= DECODE_FILE (build_unibyte_string (fname_ret
));
6726 #endif /* NTGUI_UNICODE */
6729 filename
= Fcygwin_convert_file_name_from_windows (filename
, Qt
);
6732 /* Strip the dummy filename off the end of the string if we
6733 added it to select a directory. */
6734 if ((use_unicode
&& file_details_w
->nFilterIndex
== 2)
6735 #ifndef NTGUI_UNICODE
6736 || (!use_unicode
&& file_details_a
->nFilterIndex
== 2)
6739 filename
= Ffile_name_directory (filename
);
6741 /* User canceled the dialog without making a selection. */
6742 else if (!CommDlgExtendedError ())
6744 /* An error occurred, fallback on reading from the mini-buffer. */
6746 filename
= Fcompleting_read (
6748 intern ("read-file-name-internal"),
6759 /* Make "Cancel" equivalent to C-g. */
6760 if (NILP (filename
))
6761 Fsignal (Qquit
, Qnil
);
6763 RETURN_UNGCPRO (filename
);
6768 /* Moving files to the system recycle bin.
6769 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6770 DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash
,
6771 Ssystem_move_file_to_trash
, 1, 1, 0,
6772 doc
: /* Move file or directory named FILENAME to the recycle bin. */)
6773 (Lisp_Object filename
)
6775 Lisp_Object handler
;
6776 Lisp_Object encoded_file
;
6777 Lisp_Object operation
;
6779 operation
= Qdelete_file
;
6780 if (!NILP (Ffile_directory_p (filename
))
6781 && NILP (Ffile_symlink_p (filename
)))
6783 operation
= intern ("delete-directory");
6784 filename
= Fdirectory_file_name (filename
);
6787 /* Must have fully qualified file names for moving files to Recycle
6789 filename
= Fexpand_file_name (filename
, Qnil
);
6791 handler
= Ffind_file_name_handler (filename
, operation
);
6792 if (!NILP (handler
))
6793 return call2 (handler
, operation
, filename
);
6799 encoded_file
= ENCODE_FILE (filename
);
6801 path
= map_w32_filename (SDATA (encoded_file
), NULL
);
6803 /* The Unicode version of SHFileOperation is not supported on
6805 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
6807 SHFILEOPSTRUCTW file_op_w
;
6808 /* We need one more element beyond MAX_PATH because this is
6809 a list of file names, with the last element double-null
6811 wchar_t tmp_path_w
[MAX_PATH
+ 1];
6813 memset (tmp_path_w
, 0, sizeof (tmp_path_w
));
6814 filename_to_utf16 (path
, tmp_path_w
);
6816 /* On Windows, write permission is required to delete/move files. */
6817 _wchmod (tmp_path_w
, 0666);
6819 memset (&file_op_w
, 0, sizeof (file_op_w
));
6820 file_op_w
.hwnd
= HWND_DESKTOP
;
6821 file_op_w
.wFunc
= FO_DELETE
;
6822 file_op_w
.pFrom
= tmp_path_w
;
6823 file_op_w
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6824 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6825 file_op_w
.fAnyOperationsAborted
= FALSE
;
6827 result
= SHFileOperationW (&file_op_w
);
6831 SHFILEOPSTRUCTA file_op_a
;
6832 char tmp_path_a
[MAX_PATH
+ 1];
6834 memset (tmp_path_a
, 0, sizeof (tmp_path_a
));
6835 filename_to_ansi (path
, tmp_path_a
);
6837 /* If a file cannot be represented in ANSI codepage, don't
6838 let them inadvertently delete other files because some
6839 characters are interpreted as a wildcards. */
6840 if (_mbspbrk (tmp_path_a
, "?*"))
6841 result
= ERROR_FILE_NOT_FOUND
;
6844 _chmod (tmp_path_a
, 0666);
6846 memset (&file_op_a
, 0, sizeof (file_op_a
));
6847 file_op_a
.hwnd
= HWND_DESKTOP
;
6848 file_op_a
.wFunc
= FO_DELETE
;
6849 file_op_a
.pFrom
= tmp_path_a
;
6850 file_op_a
.fFlags
= FOF_SILENT
| FOF_NOCONFIRMATION
| FOF_ALLOWUNDO
6851 | FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
;
6852 file_op_a
.fAnyOperationsAborted
= FALSE
;
6854 result
= SHFileOperationA (&file_op_a
);
6858 report_file_error ("Removing old name", list1 (filename
));
6863 #endif /* WINDOWSNT */
6866 /***********************************************************************
6867 w32 specialized functions
6868 ***********************************************************************/
6870 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
6871 Sw32_send_sys_command
, 1, 2, 0,
6872 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
6873 Some useful values for COMMAND are #xf030 to maximize frame (#xf020
6874 to minimize), #xf120 to restore frame to original size, and #xf100
6875 to activate the menubar for keyboard access. #xf140 activates the
6876 screen saver if defined.
6878 If optional parameter FRAME is not specified, use selected frame. */)
6879 (Lisp_Object command
, Lisp_Object frame
)
6881 struct frame
*f
= decode_window_system_frame (frame
);
6883 CHECK_NUMBER (command
);
6885 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
6890 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
6891 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
6892 This is a wrapper around the ShellExecute system function, which
6893 invokes the application registered to handle OPERATION for DOCUMENT.
6895 OPERATION is either nil or a string that names a supported operation.
6896 What operations can be used depends on the particular DOCUMENT and its
6897 handler application, but typically it is one of the following common
6900 \"open\" - open DOCUMENT, which could be a file, a directory, or an
6901 executable program (application). If it is an application,
6902 that application is launched in the current buffer's default
6903 directory. Otherwise, the application associated with
6904 DOCUMENT is launched in the buffer's default directory.
6905 \"opennew\" - like \"open\", but instruct the application to open
6906 DOCUMENT in a new window.
6907 \"openas\" - open the \"Open With\" dialog for DOCUMENT.
6908 \"print\" - print DOCUMENT, which must be a file.
6909 \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
6910 The printer should be provided in PARAMETERS, see below.
6911 \"explore\" - start the Windows Explorer on DOCUMENT.
6912 \"edit\" - launch an editor and open DOCUMENT for editing; which
6913 editor is launched depends on the association for the
6915 \"find\" - initiate search starting from DOCUMENT, which must specify
6917 \"delete\" - move DOCUMENT, a file or a directory, to Recycle Bin.
6918 \"copy\" - copy DOCUMENT, which must be a file or a directory, into
6920 \"cut\" - move DOCUMENT, a file or a directory, into the clipboard.
6921 \"paste\" - paste the file whose name is in the clipboard into DOCUMENT,
6922 which must be a directory.
6924 - create a shortcut in DOCUMENT (which must be a directory)
6925 the file or directory whose name is in the clipboard.
6926 \"runas\" - run DOCUMENT, which must be an excutable file, with
6927 elevated privileges (a.k.a. \"as Administrator\").
6929 - open the property sheet dialog for DOCUMENT.
6930 nil - invoke the default OPERATION, or \"open\" if default is
6931 not defined or unavailable.
6933 DOCUMENT is typically the name of a document file or a URL, but can
6934 also be an executable program to run, or a directory to open in the
6935 Windows Explorer. If it is a file or a directory, it must be a local
6936 one; this function does not support remote file names.
6938 If DOCUMENT is an executable program, the optional third arg PARAMETERS
6939 can be a string containing command line parameters, separated by blanks,
6940 that will be passed to the program. Some values of OPERATION also require
6941 parameters (e.g., \"printto\" requires the printer address). Otherwise,
6942 PARAMETERS should be nil or unspecified. Note that double quote characters
6943 in PARAMETERS must each be enclosed in 2 additional quotes, as in \"\"\".
6945 Optional fourth argument SHOW-FLAG can be used to control how the
6946 application will be displayed when it is invoked. If SHOW-FLAG is nil
6947 or unspecified, the application is displayed as if SHOW-FLAG of 10 was
6948 specified, otherwise it is an integer between 0 and 11 representing
6952 1 - start as normal-size window
6953 3 - start in a maximized window
6954 6 - start in a minimized window
6955 10 - start as the application itself specifies; this is the default. */)
6956 (Lisp_Object operation
, Lisp_Object document
, Lisp_Object parameters
, Lisp_Object show_flag
)
6959 Lisp_Object current_dir
= BVAR (current_buffer
, directory
);;
6960 wchar_t *doc_w
= NULL
, *params_w
= NULL
, *ops_w
= NULL
;
6964 int use_unicode
= w32_unicode_filenames
;
6965 char *doc_a
= NULL
, *params_a
= NULL
, *ops_a
= NULL
;
6966 Lisp_Object absdoc
, handler
;
6968 struct gcpro gcpro1
;
6971 CHECK_STRING (document
);
6974 current_dir
= Fcygwin_convert_file_name_to_windows (current_dir
, Qt
);
6975 document
= Fcygwin_convert_file_name_to_windows (document
, Qt
);
6977 /* Encode filename, current directory and parameters. */
6978 current_dir
= GUI_ENCODE_FILE (current_dir
);
6979 document
= GUI_ENCODE_FILE (document
);
6980 doc_w
= GUI_SDATA (document
);
6981 if (STRINGP (parameters
))
6983 parameters
= GUI_ENCODE_SYSTEM (parameters
);
6984 params_w
= GUI_SDATA (parameters
);
6986 if (STRINGP (operation
))
6988 operation
= GUI_ENCODE_SYSTEM (operation
);
6989 ops_w
= GUI_SDATA (operation
);
6991 result
= (intptr_t) ShellExecuteW (NULL
, ops_w
, doc_w
, params_w
,
6992 GUI_SDATA (current_dir
),
6993 (INTEGERP (show_flag
)
6994 ? XINT (show_flag
) : SW_SHOWDEFAULT
));
7001 case SE_ERR_ACCESSDENIED
:
7002 errstr
= w32_strerror (ERROR_ACCESS_DENIED
);
7004 case SE_ERR_ASSOCINCOMPLETE
:
7005 case SE_ERR_NOASSOC
:
7006 errstr
= w32_strerror (ERROR_NO_ASSOCIATION
);
7008 case SE_ERR_DDEBUSY
:
7009 case SE_ERR_DDEFAIL
:
7010 errstr
= w32_strerror (ERROR_DDE_FAIL
);
7012 case SE_ERR_DDETIMEOUT
:
7013 errstr
= w32_strerror (ERROR_TIMEOUT
);
7015 case SE_ERR_DLLNOTFOUND
:
7016 errstr
= w32_strerror (ERROR_DLL_NOT_FOUND
);
7019 errstr
= w32_strerror (ERROR_FILE_NOT_FOUND
);
7022 errstr
= w32_strerror (ERROR_NOT_ENOUGH_MEMORY
);
7025 errstr
= w32_strerror (ERROR_PATH_NOT_FOUND
);
7028 errstr
= w32_strerror (ERROR_SHARING_VIOLATION
);
7031 errstr
= w32_strerror (0);
7037 current_dir
= ENCODE_FILE (current_dir
);
7038 /* We have a situation here. If DOCUMENT is a relative file name,
7039 but its name includes leading directories, i.e. it lives not in
7040 CURRENT_DIR, but in its subdirectory, then ShellExecute below
7041 will fail to find it. So we need to make the file name is
7042 absolute. But DOCUMENT does not have to be a file, it can be a
7043 URL, for example. So we make it absolute only if it is an
7044 existing file; if it is a file that does not exist, tough. */
7046 absdoc
= Fexpand_file_name (document
, Qnil
);
7047 /* Don't call file handlers for file-exists-p, since they might
7048 attempt to access the file, which could fail or produce undesired
7049 consequences, see bug#16558 for an example. */
7050 handler
= Ffind_file_name_handler (absdoc
, Qfile_exists_p
);
7053 Lisp_Object absdoc_encoded
= ENCODE_FILE (absdoc
);
7055 if (faccessat (AT_FDCWD
, SSDATA (absdoc_encoded
), F_OK
, AT_EACCESS
) == 0)
7057 /* ShellExecute fails if DOCUMENT is a UNC with forward
7058 slashes (expand-file-name above converts all backslashes
7059 to forward slashes). Now that we know DOCUMENT is a
7060 file, we can mirror all forward slashes into backslashes. */
7061 unixtodos_filename (SSDATA (absdoc_encoded
));
7062 document
= absdoc_encoded
;
7065 document
= ENCODE_FILE (document
);
7068 document
= ENCODE_FILE (document
);
7072 wchar_t document_w
[MAX_PATH
], current_dir_w
[MAX_PATH
];
7073 SHELLEXECUTEINFOW shexinfo_w
;
7075 /* Encode filename, current directory and parameters, and
7076 convert operation to UTF-16. */
7077 filename_to_utf16 (SSDATA (current_dir
), current_dir_w
);
7078 filename_to_utf16 (SSDATA (document
), document_w
);
7080 if (STRINGP (parameters
))
7084 parameters
= ENCODE_SYSTEM (parameters
);
7085 len
= pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7086 SSDATA (parameters
), -1, NULL
, 0);
7089 params_w
= alloca (len
* sizeof (wchar_t));
7090 pMultiByteToWideChar (CP_ACP
, MB_ERR_INVALID_CHARS
,
7091 SSDATA (parameters
), -1, params_w
, len
);
7093 if (STRINGP (operation
))
7095 /* Assume OPERATION is pure ASCII. */
7096 const char *s
= SSDATA (operation
);
7098 int len
= SBYTES (operation
) + 1;
7102 d
= ops_w
= alloca (len
* sizeof (wchar_t));
7103 while (d
< ops_w
+ len
- 1)
7108 /* Using ShellExecuteEx and setting the SEE_MASK_INVOKEIDLIST
7109 flag succeeds with more OPERATIONs (a.k.a. "verbs"), as it is
7110 able to invoke verbs from shortcut menu extensions, not just
7111 static verbs listed in the Registry. */
7112 memset (&shexinfo_w
, 0, sizeof (shexinfo_w
));
7113 shexinfo_w
.cbSize
= sizeof (shexinfo_w
);
7115 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7116 shexinfo_w
.hwnd
= NULL
;
7117 shexinfo_w
.lpVerb
= ops_w
;
7118 shexinfo_w
.lpFile
= doc_w
;
7119 shexinfo_w
.lpParameters
= params_w
;
7120 shexinfo_w
.lpDirectory
= current_dir_w
;
7122 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7123 success
= ShellExecuteExW (&shexinfo_w
);
7127 char document_a
[MAX_PATH
], current_dir_a
[MAX_PATH
];
7128 SHELLEXECUTEINFOA shexinfo_a
;
7130 filename_to_ansi (SSDATA (current_dir
), current_dir_a
);
7131 filename_to_ansi (SSDATA (document
), document_a
);
7133 if (STRINGP (parameters
))
7135 parameters
= ENCODE_SYSTEM (parameters
);
7136 params_a
= SSDATA (parameters
);
7138 if (STRINGP (operation
))
7140 /* Assume OPERATION is pure ASCII. */
7141 ops_a
= SSDATA (operation
);
7143 memset (&shexinfo_a
, 0, sizeof (shexinfo_a
));
7144 shexinfo_a
.cbSize
= sizeof (shexinfo_a
);
7146 SEE_MASK_INVOKEIDLIST
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
;
7147 shexinfo_a
.hwnd
= NULL
;
7148 shexinfo_a
.lpVerb
= ops_a
;
7149 shexinfo_a
.lpFile
= doc_a
;
7150 shexinfo_a
.lpParameters
= params_a
;
7151 shexinfo_a
.lpDirectory
= current_dir_a
;
7153 (INTEGERP (show_flag
) ? XINT (show_flag
) : SW_SHOWDEFAULT
);
7154 success
= ShellExecuteExA (&shexinfo_a
);
7160 errstr
= w32_strerror (0);
7162 #endif /* !CYGWIN */
7164 /* The error string might be encoded in the locale's encoding. */
7165 if (!NILP (Vlocale_coding_system
))
7167 Lisp_Object decoded
=
7168 code_convert_string_norecord (build_unibyte_string (errstr
),
7169 Vlocale_coding_system
, 0);
7170 errstr
= SSDATA (decoded
);
7172 error ("ShellExecute failed: %s", errstr
);
7175 /* Lookup virtual keycode from string representing the name of a
7176 non-ascii keystroke into the corresponding virtual key, using
7177 lispy_function_keys. */
7179 lookup_vk_code (char *key
)
7183 for (i
= 0; i
< 256; i
++)
7184 if (lispy_function_keys
[i
]
7185 && strcmp (lispy_function_keys
[i
], key
) == 0)
7191 /* Convert a one-element vector style key sequence to a hot key
7194 w32_parse_hot_key (Lisp_Object key
)
7196 /* Copied from Fdefine_key and store_in_keymap. */
7197 register Lisp_Object c
;
7201 struct gcpro gcpro1
;
7205 if (ASIZE (key
) != 1)
7212 if (CONSP (c
) && lucid_event_type_list_p (c
))
7213 c
= Fevent_convert_list (c
);
7217 if (! INTEGERP (c
) && ! SYMBOLP (c
))
7218 error ("Key definition is invalid");
7220 /* Work out the base key and the modifiers. */
7223 c
= parse_modifiers (c
);
7224 lisp_modifiers
= XINT (Fcar (Fcdr (c
)));
7228 vk_code
= lookup_vk_code (SDATA (SYMBOL_NAME (c
)));
7230 else if (INTEGERP (c
))
7232 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
7233 /* Many ascii characters are their own virtual key code. */
7234 vk_code
= XINT (c
) & CHARACTERBITS
;
7237 if (vk_code
< 0 || vk_code
> 255)
7240 if ((lisp_modifiers
& meta_modifier
) != 0
7241 && !NILP (Vw32_alt_is_meta
))
7242 lisp_modifiers
|= alt_modifier
;
7244 /* Supply defs missing from mingw32. */
7246 #define MOD_ALT 0x0001
7247 #define MOD_CONTROL 0x0002
7248 #define MOD_SHIFT 0x0004
7249 #define MOD_WIN 0x0008
7252 /* Convert lisp modifiers to Windows hot-key form. */
7253 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
7254 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
7255 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
7256 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
7258 return HOTKEY (vk_code
, w32_modifiers
);
7261 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
7262 Sw32_register_hot_key
, 1, 1, 0,
7263 doc
: /* Register KEY as a hot-key combination.
7264 Certain key combinations like Alt-Tab are reserved for system use on
7265 Windows, and therefore are normally intercepted by the system. However,
7266 most of these key combinations can be received by registering them as
7267 hot-keys, overriding their special meaning.
7269 KEY must be a one element key definition in vector form that would be
7270 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
7271 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
7272 is always interpreted as the Windows modifier keys.
7274 The return value is the hotkey-id if registered, otherwise nil. */)
7277 key
= w32_parse_hot_key (key
);
7279 if (!NILP (key
) && NILP (Fmemq (key
, w32_grabbed_keys
)))
7281 /* Reuse an empty slot if possible. */
7282 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
7284 /* Safe to add new key to list, even if we have focus. */
7286 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
7288 XSETCAR (item
, key
);
7290 /* Notify input thread about new hot-key definition, so that it
7291 takes effect without needing to switch focus. */
7292 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
7293 (WPARAM
) XINT (key
), 0);
7299 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
7300 Sw32_unregister_hot_key
, 1, 1, 0,
7301 doc
: /* Unregister KEY as a hot-key combination. */)
7306 if (!INTEGERP (key
))
7307 key
= w32_parse_hot_key (key
);
7309 item
= Fmemq (key
, w32_grabbed_keys
);
7315 eassert (CONSP (item
));
7316 /* Pass the tail of the list as a pointer to a Lisp_Cons cell,
7317 so that it works in a --with-wide-int build as well. */
7318 lparam
= (LPARAM
) XUNTAG (item
, Lisp_Cons
);
7320 /* Notify input thread about hot-key definition being removed, so
7321 that it takes effect without needing focus switch. */
7322 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
7323 (WPARAM
) XINT (XCAR (item
)), lparam
))
7326 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7333 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
7334 Sw32_registered_hot_keys
, 0, 0, 0,
7335 doc
: /* Return list of registered hot-key IDs. */)
7338 return Fdelq (Qnil
, Fcopy_sequence (w32_grabbed_keys
));
7341 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
7342 Sw32_reconstruct_hot_key
, 1, 1, 0,
7343 doc
: /* Convert hot-key ID to a lisp key combination.
7344 usage: (w32-reconstruct-hot-key ID) */)
7345 (Lisp_Object hotkeyid
)
7347 int vk_code
, w32_modifiers
;
7350 CHECK_NUMBER (hotkeyid
);
7352 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
7353 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
7355 if (vk_code
< 256 && lispy_function_keys
[vk_code
])
7356 key
= intern (lispy_function_keys
[vk_code
]);
7358 key
= make_number (vk_code
);
7360 key
= Fcons (key
, Qnil
);
7361 if (w32_modifiers
& MOD_SHIFT
)
7362 key
= Fcons (Qshift
, key
);
7363 if (w32_modifiers
& MOD_CONTROL
)
7364 key
= Fcons (Qctrl
, key
);
7365 if (w32_modifiers
& MOD_ALT
)
7366 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
7367 if (w32_modifiers
& MOD_WIN
)
7368 key
= Fcons (Qhyper
, key
);
7373 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
7374 Sw32_toggle_lock_key
, 1, 2, 0,
7375 doc
: /* Toggle the state of the lock key KEY.
7376 KEY can be `capslock', `kp-numlock', or `scroll'.
7377 If the optional parameter NEW-STATE is a number, then the state of KEY
7378 is set to off if the low bit of NEW-STATE is zero, otherwise on.
7379 If NEW-STATE is omitted or nil, the function toggles the state,
7381 Value is the new state of the key, or nil if the function failed
7382 to change the state. */)
7383 (Lisp_Object key
, Lisp_Object new_state
)
7388 if (EQ (key
, intern ("capslock")))
7389 vk_code
= VK_CAPITAL
;
7390 else if (EQ (key
, intern ("kp-numlock")))
7391 vk_code
= VK_NUMLOCK
;
7392 else if (EQ (key
, intern ("scroll")))
7393 vk_code
= VK_SCROLL
;
7397 if (!dwWindowsThreadId
)
7398 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
7400 if (NILP (new_state
))
7403 lparam
= (XUINT (new_state
)) & 1;
7404 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
7405 (WPARAM
) vk_code
, lparam
))
7408 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
7409 return make_number (msg
.wParam
);
7414 DEFUN ("w32-window-exists-p", Fw32_window_exists_p
, Sw32_window_exists_p
,
7416 doc
: /* Return non-nil if a window exists with the specified CLASS and NAME.
7418 This is a direct interface to the Windows API FindWindow function. */)
7419 (Lisp_Object
class, Lisp_Object name
)
7424 CHECK_STRING (class);
7426 CHECK_STRING (name
);
7428 hnd
= FindWindow (STRINGP (class) ? ((LPCTSTR
) SDATA (class)) : NULL
,
7429 STRINGP (name
) ? ((LPCTSTR
) SDATA (name
)) : NULL
);
7435 DEFUN ("w32-frame-menu-bar-size", Fw32_frame_menu_bar_size
, Sw32_frame_menu_bar_size
, 0, 1, 0,
7436 doc
: /* Return sizes of menu bar on frame FRAME.
7437 The return value is a list of four elements: The current width and
7438 height of FRAME's menu bar in pixels, the height of one menu bar line in
7439 a wrapped menu bar in pixels, and the height of a single line menu bar
7442 If FRAME is omitted or nil, the selected frame is used. */)
7445 struct frame
*f
= decode_any_frame (frame
);
7446 MENUBARINFO menu_bar
;
7447 int width
, height
, single_height
, wrapped_height
;
7451 single_height
= GetSystemMetrics (SM_CYMENU
);
7452 wrapped_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7453 menu_bar
.cbSize
= sizeof (menu_bar
);
7454 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7455 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7456 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7457 width
= menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
;
7458 height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7462 return list4 (make_number (width
), make_number (height
),
7463 make_number (wrapped_height
), make_number (single_height
));
7466 DEFUN ("w32-frame-rect", Fw32_frame_rect
, Sw32_frame_rect
, 0, 2, 0,
7467 doc
: /* Return boundary rectangle of FRAME in screen coordinates.
7468 FRAME must be a live frame and defaults to the selected one.
7470 The boundary rectangle is a list of four elements, specifying the left,
7471 top, right and bottom screen coordinates of FRAME including menu and
7472 title bar and decorations. Optional argument CLIENT non-nil means to
7473 return the boundaries of the client rectangle which excludes menu and
7474 title bar and decorations. */)
7475 (Lisp_Object frame
, Lisp_Object client
)
7477 struct frame
*f
= decode_live_frame (frame
);
7483 GetClientRect (FRAME_W32_WINDOW (f
), &rect
);
7485 GetWindowRect (FRAME_W32_WINDOW (f
), &rect
);
7489 return list4 (make_number (rect
.left
), make_number (rect
.top
),
7490 make_number (rect
.right
), make_number (rect
.bottom
));
7493 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
7494 doc
: /* Return geometric attributes of frame FRAME.
7495 FRAME must be a live frame and defaults to the selected one.
7497 The return value is an association list containing the following
7498 elements (all size values are in pixels).
7500 - `frame-outer-size' is a cons of the outer width and height of FRAME.
7501 The outer size includes the title bar and the external borders as well
7502 as any menu and/or tool bar of frame.
7504 - `border' is a cons of the horizontal and vertical width of FRAME's
7507 - `title-bar-height' is the height of the title bar of FRAME.
7509 - `menu-bar-external' if `t' means the menu bar is by default external
7510 (not included in the inner size of FRAME).
7512 - `menu-bar-size' is a cons of the width and height of the menu bar of
7515 - `tool-bar-external' if `t' means the tool bar is by default external
7516 (not included in the inner size of FRAME).
7518 - `tool-bar-side' tells tells on which side the tool bar on FRAME is by
7519 default and can be one of `left', `top', `right' or `bottom'.
7521 - `tool-bar-size' is a cons of the width and height of the tool bar of
7524 - `frame-inner-size' is a cons of the inner width and height of FRAME.
7525 This excludes FRAME's title bar and external border as well as any
7526 external menu and/or tool bar. */)
7529 struct frame
*f
= decode_live_frame (frame
);
7530 Lisp_Object geometry
= Qnil
;
7531 RECT frame_outer_edges
, frame_inner_edges
;
7532 MENUBARINFO menu_bar
;
7533 int border_width
, border_height
, title_height
;
7534 int single_bar_height
, wrapped_bar_height
, menu_bar_height
;
7535 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
7539 /* Outer frame rectangle, including outer borders and title bar. */
7540 GetWindowRect (FRAME_W32_WINDOW (f
), &frame_outer_edges
);
7541 /* Inner frame rectangle, excluding borders and title bar. */
7542 GetClientRect (FRAME_W32_WINDOW (f
), &frame_inner_edges
);
7544 border_width
= GetSystemMetrics (SM_CXFRAME
);
7545 border_height
= GetSystemMetrics (SM_CYFRAME
);
7547 title_height
= GetSystemMetrics (SM_CYCAPTION
);
7549 menu_bar
.cbSize
= sizeof (menu_bar
);
7550 menu_bar
.rcBar
.right
= menu_bar
.rcBar
.left
= 0;
7551 menu_bar
.rcBar
.top
= menu_bar
.rcBar
.bottom
= 0;
7552 GetMenuBarInfo (FRAME_W32_WINDOW (f
), 0xFFFFFFFD, 0, &menu_bar
);
7553 single_bar_height
= GetSystemMetrics (SM_CYMENU
);
7554 wrapped_bar_height
= GetSystemMetrics (SM_CYMENUSIZE
);
7557 menu_bar_height
= menu_bar
.rcBar
.bottom
- menu_bar
.rcBar
.top
;
7558 /* Fix menu bar height reported by GetMenuBarInfo. */
7559 if (menu_bar_height
> single_bar_height
)
7560 /* A wrapped menu bar. */
7561 menu_bar_height
+= single_bar_height
- wrapped_bar_height
;
7562 else if (menu_bar_height
> 0)
7563 /* A single line menu bar. */
7564 menu_bar_height
= single_bar_height
;
7567 listn (CONSTYPE_HEAP
, 10,
7568 Fcons (Qframe_position
,
7569 Fcons (make_number (frame_outer_edges
.left
),
7570 make_number (frame_outer_edges
.top
))),
7571 Fcons (Qframe_outer_size
,
7573 (frame_outer_edges
.right
- frame_outer_edges
.left
),
7575 (frame_outer_edges
.bottom
- frame_outer_edges
.top
))),
7576 Fcons (Qexternal_border_size
,
7577 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7578 ? Fcons (make_number (0), make_number (0))
7579 : Fcons (make_number (border_width
),
7580 make_number (border_height
)))),
7581 Fcons (Qtitle_height
,
7582 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
7584 : make_number (title_height
))),
7585 Fcons (Qmenu_bar_external
, Qt
),
7586 Fcons (Qmenu_bar_size
,
7588 (menu_bar
.rcBar
.right
- menu_bar
.rcBar
.left
),
7589 make_number (menu_bar_height
))),
7590 Fcons (Qtool_bar_external
, Qnil
),
7591 Fcons (Qtool_bar_position
, Qtop
),
7592 Fcons (Qtool_bar_size
,
7593 Fcons (make_number (FRAME_TOOL_BAR_LINES (f
)
7594 ? (FRAME_PIXEL_WIDTH (f
)
7595 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f
))
7597 make_number (FRAME_TOOL_BAR_HEIGHT (f
)))),
7598 Fcons (Qframe_inner_size
,
7600 (frame_inner_edges
.right
- frame_inner_edges
.left
),
7602 (frame_inner_edges
.bottom
- frame_inner_edges
.top
))));
7605 DEFUN ("w32-battery-status", Fw32_battery_status
, Sw32_battery_status
, 0, 0, 0,
7606 doc
: /* Get power status information from Windows system.
7608 The following %-sequences are provided:
7609 %L AC line status (verbose)
7610 %B Battery status (verbose)
7611 %b Battery status, empty means high, `-' means low,
7612 `!' means critical, and `+' means charging
7613 %p Battery load percentage
7614 %s Remaining time (to charge or discharge) in seconds
7615 %m Remaining time (to charge or discharge) in minutes
7616 %h Remaining time (to charge or discharge) in hours
7617 %t Remaining time (to charge or discharge) in the form `h:min' */)
7620 Lisp_Object status
= Qnil
;
7622 SYSTEM_POWER_STATUS system_status
;
7623 if (GetSystemPowerStatus (&system_status
))
7625 Lisp_Object line_status
, battery_status
, battery_status_symbol
;
7626 Lisp_Object load_percentage
, seconds
, minutes
, hours
, remain
;
7628 long seconds_left
= (long) system_status
.BatteryLifeTime
;
7630 if (system_status
.ACLineStatus
== 0)
7631 line_status
= build_string ("off-line");
7632 else if (system_status
.ACLineStatus
== 1)
7633 line_status
= build_string ("on-line");
7635 line_status
= build_string ("N/A");
7637 if (system_status
.BatteryFlag
& 128)
7639 battery_status
= build_string ("N/A");
7640 battery_status_symbol
= empty_unibyte_string
;
7642 else if (system_status
.BatteryFlag
& 8)
7644 battery_status
= build_string ("charging");
7645 battery_status_symbol
= build_string ("+");
7646 if (system_status
.BatteryFullLifeTime
!= -1L)
7647 seconds_left
= system_status
.BatteryFullLifeTime
- seconds_left
;
7649 else if (system_status
.BatteryFlag
& 4)
7651 battery_status
= build_string ("critical");
7652 battery_status_symbol
= build_string ("!");
7654 else if (system_status
.BatteryFlag
& 2)
7656 battery_status
= build_string ("low");
7657 battery_status_symbol
= build_string ("-");
7659 else if (system_status
.BatteryFlag
& 1)
7661 battery_status
= build_string ("high");
7662 battery_status_symbol
= empty_unibyte_string
;
7666 battery_status
= build_string ("medium");
7667 battery_status_symbol
= empty_unibyte_string
;
7670 if (system_status
.BatteryLifePercent
> 100)
7671 load_percentage
= build_string ("N/A");
7675 snprintf (buffer
, 16, "%d", system_status
.BatteryLifePercent
);
7676 load_percentage
= build_string (buffer
);
7679 if (seconds_left
< 0)
7680 seconds
= minutes
= hours
= remain
= build_string ("N/A");
7686 snprintf (buffer
, 16, "%ld", seconds_left
);
7687 seconds
= build_string (buffer
);
7689 m
= seconds_left
/ 60;
7690 snprintf (buffer
, 16, "%ld", m
);
7691 minutes
= build_string (buffer
);
7693 h
= seconds_left
/ 3600.0;
7694 snprintf (buffer
, 16, "%3.1f", h
);
7695 hours
= build_string (buffer
);
7697 snprintf (buffer
, 16, "%ld:%02ld", m
/ 60, m
% 60);
7698 remain
= build_string (buffer
);
7701 status
= listn (CONSTYPE_HEAP
, 8,
7702 Fcons (make_number ('L'), line_status
),
7703 Fcons (make_number ('B'), battery_status
),
7704 Fcons (make_number ('b'), battery_status_symbol
),
7705 Fcons (make_number ('p'), load_percentage
),
7706 Fcons (make_number ('s'), seconds
),
7707 Fcons (make_number ('m'), minutes
),
7708 Fcons (make_number ('h'), hours
),
7709 Fcons (make_number ('t'), remain
));
7716 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
7717 doc
: /* Return storage information about the file system FILENAME is on.
7718 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
7719 storage of the file system, FREE is the free storage, and AVAIL is the
7720 storage available to a non-superuser. All 3 numbers are in bytes.
7721 If the underlying system call fails, value is nil. */)
7722 (Lisp_Object filename
)
7724 Lisp_Object encoded
, value
;
7726 CHECK_STRING (filename
);
7727 filename
= Fexpand_file_name (filename
, Qnil
);
7728 encoded
= ENCODE_FILE (filename
);
7732 /* Determining the required information on Windows turns out, sadly,
7733 to be more involved than one would hope. The original Windows API
7734 call for this will return bogus information on some systems, but we
7735 must dynamically probe for the replacement api, since that was
7736 added rather late on. */
7738 HMODULE hKernel
= GetModuleHandle ("kernel32");
7739 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExW
)
7740 (wchar_t *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7741 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExW");
7742 BOOL (WINAPI
*pfn_GetDiskFreeSpaceExA
)
7743 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
7744 = GetProcAddress (hKernel
, "GetDiskFreeSpaceExA");
7745 bool have_pfn_GetDiskFreeSpaceEx
=
7746 ((w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExW
)
7747 || (!w32_unicode_filenames
&& pfn_GetDiskFreeSpaceExA
));
7749 /* On Windows, we may need to specify the root directory of the
7750 volume holding FILENAME. */
7751 char rootname
[MAX_UTF8_PATH
];
7752 wchar_t rootname_w
[MAX_PATH
];
7753 char rootname_a
[MAX_PATH
];
7754 char *name
= SDATA (encoded
);
7757 /* find the root name of the volume if given */
7758 if (isalpha (name
[0]) && name
[1] == ':')
7760 rootname
[0] = name
[0];
7761 rootname
[1] = name
[1];
7765 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
7767 char *str
= rootname
;
7771 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
7781 if (w32_unicode_filenames
)
7782 filename_to_utf16 (rootname
, rootname_w
);
7784 filename_to_ansi (rootname
, rootname_a
);
7786 if (have_pfn_GetDiskFreeSpaceEx
)
7788 /* Unsigned large integers cannot be cast to double, so
7789 use signed ones instead. */
7790 LARGE_INTEGER availbytes
;
7791 LARGE_INTEGER freebytes
;
7792 LARGE_INTEGER totalbytes
;
7794 if (w32_unicode_filenames
)
7795 result
= pfn_GetDiskFreeSpaceExW (rootname_w
,
7796 (ULARGE_INTEGER
*)&availbytes
,
7797 (ULARGE_INTEGER
*)&totalbytes
,
7798 (ULARGE_INTEGER
*)&freebytes
);
7800 result
= pfn_GetDiskFreeSpaceExA (rootname_a
,
7801 (ULARGE_INTEGER
*)&availbytes
,
7802 (ULARGE_INTEGER
*)&totalbytes
,
7803 (ULARGE_INTEGER
*)&freebytes
);
7805 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
7806 make_float ((double) freebytes
.QuadPart
),
7807 make_float ((double) availbytes
.QuadPart
));
7811 DWORD sectors_per_cluster
;
7812 DWORD bytes_per_sector
;
7813 DWORD free_clusters
;
7814 DWORD total_clusters
;
7816 if (w32_unicode_filenames
)
7817 result
= GetDiskFreeSpaceW (rootname_w
,
7818 §ors_per_cluster
,
7823 result
= GetDiskFreeSpaceA (rootname_a
,
7824 §ors_per_cluster
,
7829 value
= list3 (make_float ((double) total_clusters
7830 * sectors_per_cluster
* bytes_per_sector
),
7831 make_float ((double) free_clusters
7832 * sectors_per_cluster
* bytes_per_sector
),
7833 make_float ((double) free_clusters
7834 * sectors_per_cluster
* bytes_per_sector
));
7840 #endif /* WINDOWSNT */
7844 DEFUN ("default-printer-name", Fdefault_printer_name
, Sdefault_printer_name
,
7845 0, 0, 0, doc
: /* Return the name of Windows default printer device. */)
7848 static char pname_buf
[256];
7851 PRINTER_INFO_2W
*ppi2w
= NULL
;
7852 PRINTER_INFO_2A
*ppi2a
= NULL
;
7853 DWORD dwNeeded
= 0, dwReturned
= 0;
7854 char server_name
[MAX_UTF8_PATH
], share_name
[MAX_UTF8_PATH
];
7855 char port_name
[MAX_UTF8_PATH
];
7857 /* Retrieve the default string from Win.ini (the registry).
7858 * String will be in form "printername,drivername,portname".
7859 * This is the most portable way to get the default printer. */
7860 if (GetProfileString ("windows", "device", ",,", pname_buf
, sizeof (pname_buf
)) <= 0)
7862 /* printername precedes first "," character */
7863 strtok (pname_buf
, ",");
7864 /* We want to know more than the printer name */
7865 if (!OpenPrinter (pname_buf
, &hPrn
, NULL
))
7867 /* GetPrinterW is not supported by unicows.dll. */
7868 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7869 GetPrinterW (hPrn
, 2, NULL
, 0, &dwNeeded
);
7871 GetPrinterA (hPrn
, 2, NULL
, 0, &dwNeeded
);
7874 ClosePrinter (hPrn
);
7877 /* Call GetPrinter again with big enough memory block. */
7878 if (w32_unicode_filenames
&& os_subtype
!= OS_9X
)
7880 /* Allocate memory for the PRINTER_INFO_2 struct. */
7881 ppi2w
= xmalloc (dwNeeded
);
7882 err
= GetPrinterW (hPrn
, 2, (LPBYTE
)ppi2w
, dwNeeded
, &dwReturned
);
7883 ClosePrinter (hPrn
);
7890 if ((ppi2w
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7891 && ppi2w
->pServerName
)
7893 filename_from_utf16 (ppi2w
->pServerName
, server_name
);
7894 filename_from_utf16 (ppi2w
->pShareName
, share_name
);
7898 server_name
[0] = '\0';
7899 filename_from_utf16 (ppi2w
->pPortName
, port_name
);
7904 ppi2a
= xmalloc (dwNeeded
);
7905 err
= GetPrinterA (hPrn
, 2, (LPBYTE
)ppi2a
, dwNeeded
, &dwReturned
);
7906 ClosePrinter (hPrn
);
7913 if ((ppi2a
->Attributes
& PRINTER_ATTRIBUTE_SHARED
)
7914 && ppi2a
->pServerName
)
7916 filename_from_ansi (ppi2a
->pServerName
, server_name
);
7917 filename_from_ansi (ppi2a
->pShareName
, share_name
);
7921 server_name
[0] = '\0';
7922 filename_from_ansi (ppi2a
->pPortName
, port_name
);
7928 /* a remote printer */
7929 if (server_name
[0] == '\\')
7930 snprintf (pname_buf
, sizeof (pname_buf
), "%s\\%s", server_name
,
7933 snprintf (pname_buf
, sizeof (pname_buf
), "\\\\%s\\%s", server_name
,
7935 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7939 /* a local printer */
7940 strncpy (pname_buf
, port_name
, sizeof (pname_buf
));
7941 pname_buf
[sizeof (pname_buf
) - 1] = '\0';
7942 /* `pPortName' can include several ports, delimited by ','.
7943 * we only use the first one. */
7944 strtok (pname_buf
, ",");
7947 return DECODE_FILE (build_unibyte_string (pname_buf
));
7949 #endif /* WINDOWSNT */
7952 /* Equivalent of strerror for W32 error codes. */
7954 w32_strerror (int error_no
)
7956 static char buf
[500];
7960 error_no
= GetLastError ();
7962 ret
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
7963 FORMAT_MESSAGE_IGNORE_INSERTS
,
7966 0, /* choose most suitable language */
7967 buf
, sizeof (buf
), NULL
);
7969 while (ret
> 0 && (buf
[ret
- 1] == '\n' ||
7970 buf
[ret
- 1] == '\r' ))
7974 sprintf (buf
, "w32 error %u", error_no
);
7979 /* For convenience when debugging. (You cannot call GetLastError
7980 directly from GDB: it will crash, because it uses the __stdcall
7981 calling convention, not the _cdecl convention assumed by GDB.) */
7983 w32_last_error (void)
7985 return GetLastError ();
7988 /* Cache information describing the NT system for later use. */
7990 cache_system_info (void)
8003 /* Cache the module handle of Emacs itself. */
8004 hinst
= GetModuleHandle (NULL
);
8006 /* Cache the version of the operating system. */
8007 version
.data
= GetVersion ();
8008 w32_major_version
= version
.info
.major
;
8009 w32_minor_version
= version
.info
.minor
;
8011 if (version
.info
.platform
& 0x8000)
8016 /* Cache page size, allocation unit, processor type, etc. */
8017 GetSystemInfo (&sysinfo_cache
);
8018 syspage_mask
= (DWORD_PTR
)sysinfo_cache
.dwPageSize
- 1;
8020 /* Cache os info. */
8021 osinfo_cache
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
8022 GetVersionEx (&osinfo_cache
);
8024 w32_build_number
= osinfo_cache
.dwBuildNumber
;
8025 if (os_subtype
== OS_9X
)
8026 w32_build_number
&= 0xffff;
8028 w32_num_mouse_buttons
= GetSystemMetrics (SM_CMOUSEBUTTONS
);
8033 _DebPrint (const char *fmt
, ...)
8038 va_start (args
, fmt
);
8039 vsprintf (buf
, fmt
, args
);
8042 fprintf (stderr
, "%s", buf
);
8044 OutputDebugString (buf
);
8049 w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
)
8051 int cur_state
= (GetKeyState (vk_code
) & 1);
8053 if (NILP (new_state
)
8054 || (NUMBERP (new_state
)
8055 && ((XUINT (new_state
)) & 1) != cur_state
))
8058 faked_key
= vk_code
;
8059 #endif /* WINDOWSNT */
8061 keybd_event ((BYTE
) vk_code
,
8062 (BYTE
) MapVirtualKey (vk_code
, 0),
8063 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8064 keybd_event ((BYTE
) vk_code
,
8065 (BYTE
) MapVirtualKey (vk_code
, 0),
8066 KEYEVENTF_EXTENDEDKEY
| 0, 0);
8067 keybd_event ((BYTE
) vk_code
,
8068 (BYTE
) MapVirtualKey (vk_code
, 0),
8069 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
8070 cur_state
= !cur_state
;
8076 /* Translate console modifiers to emacs modifiers.
8077 German keyboard support (Kai Morgan Zeise 2/18/95). */
8079 w32_kbd_mods_to_emacs (DWORD mods
, WORD key
)
8083 /* If we recognize right-alt and left-ctrl as AltGr, and it has been
8084 pressed, first remove those modifiers. */
8085 if (!NILP (Vw32_recognize_altgr
)
8086 && (mods
& (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8087 == (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
))
8088 mods
&= ~ (RIGHT_ALT_PRESSED
| LEFT_CTRL_PRESSED
);
8090 if (mods
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
))
8091 retval
= ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
);
8093 if (mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8095 retval
|= ctrl_modifier
;
8096 if ((mods
& (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8097 == (RIGHT_CTRL_PRESSED
| LEFT_CTRL_PRESSED
))
8098 retval
|= meta_modifier
;
8101 if (mods
& LEFT_WIN_PRESSED
)
8102 retval
|= w32_key_to_modifier (VK_LWIN
);
8103 if (mods
& RIGHT_WIN_PRESSED
)
8104 retval
|= w32_key_to_modifier (VK_RWIN
);
8105 if (mods
& APPS_PRESSED
)
8106 retval
|= w32_key_to_modifier (VK_APPS
);
8107 if (mods
& SCROLLLOCK_ON
)
8108 retval
|= w32_key_to_modifier (VK_SCROLL
);
8110 /* Just in case someone wanted the original behavior, make it
8111 optional by setting w32-capslock-is-shiftlock to t. */
8112 if (NILP (Vw32_capslock_is_shiftlock
)
8113 /* Keys that should _not_ be affected by CapsLock. */
8114 && ( (key
== VK_BACK
)
8116 || (key
== VK_CLEAR
)
8117 || (key
== VK_RETURN
)
8118 || (key
== VK_ESCAPE
)
8119 || ((key
>= VK_SPACE
) && (key
<= VK_HELP
))
8120 || ((key
>= VK_NUMPAD0
) && (key
<= VK_F24
))
8121 || ((key
>= VK_NUMPAD_CLEAR
) && (key
<= VK_NUMPAD_DELETE
))
8124 /* Only consider shift state. */
8125 if ((mods
& SHIFT_PRESSED
) != 0)
8126 retval
|= shift_modifier
;
8130 /* Ignore CapsLock state if not enabled. */
8131 if (NILP (Vw32_enable_caps_lock
))
8132 mods
&= ~CAPSLOCK_ON
;
8133 if ((mods
& (SHIFT_PRESSED
| CAPSLOCK_ON
)) != 0)
8134 retval
|= shift_modifier
;
8140 /* The return code indicates key code size. cpID is the codepage to
8141 use for translation to Unicode; -1 means use the current console
8144 w32_kbd_patch_key (KEY_EVENT_RECORD
*event
, int cpId
)
8146 unsigned int key_code
= event
->wVirtualKeyCode
;
8147 unsigned int mods
= event
->dwControlKeyState
;
8149 static BYTE ansi_code
[4];
8150 static int isdead
= 0;
8154 event
->uChar
.AsciiChar
= ansi_code
[2];
8158 if (event
->uChar
.AsciiChar
!= 0)
8161 memset (keystate
, 0, sizeof (keystate
));
8162 keystate
[key_code
] = 0x80;
8163 if (mods
& SHIFT_PRESSED
)
8164 keystate
[VK_SHIFT
] = 0x80;
8165 if (mods
& CAPSLOCK_ON
)
8166 keystate
[VK_CAPITAL
] = 1;
8167 /* If we recognize right-alt and left-ctrl as AltGr, set the key
8168 states accordingly before invoking ToAscii. */
8169 if (!NILP (Vw32_recognize_altgr
)
8170 && (mods
& LEFT_CTRL_PRESSED
) && (mods
& RIGHT_ALT_PRESSED
))
8172 keystate
[VK_CONTROL
] = 0x80;
8173 keystate
[VK_LCONTROL
] = 0x80;
8174 keystate
[VK_MENU
] = 0x80;
8175 keystate
[VK_RMENU
] = 0x80;
8179 /* Because of an OS bug, ToAscii corrupts the stack when called to
8180 convert a dead key in console mode on NT4. Unfortunately, trying
8181 to check for dead keys using MapVirtualKey doesn't work either -
8182 these functions apparently use internal information about keyboard
8183 layout which doesn't get properly updated in console programs when
8184 changing layout (though apparently it gets partly updated,
8185 otherwise ToAscii wouldn't crash). */
8186 if (is_dead_key (event
->wVirtualKeyCode
))
8190 /* On NT, call ToUnicode instead and then convert to the current
8191 console input codepage. */
8192 if (os_subtype
== OS_NT
)
8196 isdead
= ToUnicode (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8197 keystate
, buf
, 128, 0);
8200 /* When we are called from the GUI message processing code,
8201 we are passed the current keyboard codepage, a positive
8202 number, to use below. */
8204 cpId
= GetConsoleCP ();
8206 event
->uChar
.UnicodeChar
= buf
[isdead
- 1];
8207 isdead
= WideCharToMultiByte (cpId
, 0, buf
, isdead
,
8208 ansi_code
, 4, NULL
, NULL
);
8215 isdead
= ToAscii (event
->wVirtualKeyCode
, event
->wVirtualScanCode
,
8216 keystate
, (LPWORD
) ansi_code
, 0);
8221 event
->uChar
.AsciiChar
= ansi_code
[0];
8227 w32_sys_ring_bell (struct frame
*f
)
8229 if (sound_type
== 0xFFFFFFFF)
8233 else if (sound_type
== MB_EMACS_SILENT
)
8238 MessageBeep (sound_type
);
8242 /***********************************************************************
8244 ***********************************************************************/
8246 /* Keep this list in the same order as frame_parms in frame.c.
8247 Use 0 for unsupported frame parameters. */
8249 frame_parm_handler w32_frame_parm_handlers
[] =
8253 x_set_background_color
,
8259 x_set_foreground_color
,
8262 x_set_internal_border_width
,
8263 x_set_right_divider_width
,
8264 x_set_bottom_divider_width
,
8265 x_set_menu_bar_lines
,
8267 x_explicitly_set_name
,
8268 x_set_scroll_bar_width
,
8269 x_set_scroll_bar_height
,
8272 x_set_vertical_scroll_bars
,
8273 x_set_horizontal_scroll_bars
,
8275 x_set_tool_bar_lines
,
8276 0, /* x_set_scroll_bar_foreground, */
8277 0, /* x_set_scroll_bar_background, */
8282 0, /* x_set_wait_for_wm, */
8286 0, /* x_set_sticky */
8287 0, /* x_set_tool_bar_position */
8291 syms_of_w32fns (void)
8293 globals_of_w32fns ();
8294 track_mouse_window
= NULL
;
8296 w32_visible_system_caret_hwnd
= NULL
;
8298 DEFSYM (Qundefined_color
, "undefined-color");
8299 DEFSYM (Qcancel_timer
, "cancel-timer");
8300 DEFSYM (Qhyper
, "hyper");
8301 DEFSYM (Qsuper
, "super");
8302 DEFSYM (Qmeta
, "meta");
8303 DEFSYM (Qalt
, "alt");
8304 DEFSYM (Qctrl
, "ctrl");
8305 DEFSYM (Qcontrol
, "control");
8306 DEFSYM (Qshift
, "shift");
8307 DEFSYM (Qfont_param
, "font-parameter");
8308 DEFSYM (Qgeometry
, "geometry");
8309 DEFSYM (Qworkarea
, "workarea");
8310 DEFSYM (Qmm_size
, "mm-size");
8311 DEFSYM (Qframes
, "frames");
8313 Fput (Qundefined_color
, Qerror_conditions
,
8314 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
8315 Fput (Qundefined_color
, Qerror_message
,
8316 build_pure_c_string ("Undefined color"));
8318 staticpro (&w32_grabbed_keys
);
8319 w32_grabbed_keys
= Qnil
;
8321 DEFVAR_LISP ("w32-color-map", Vw32_color_map
,
8322 doc
: /* An array of color name mappings for Windows. */);
8323 Vw32_color_map
= Qnil
;
8325 DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system
,
8326 doc
: /* Non-nil if Alt key presses are passed on to Windows.
8327 When non-nil, for example, Alt pressed and released and then space will
8328 open the System menu. When nil, Emacs processes the Alt key events, and
8329 then silently swallows them. */);
8330 Vw32_pass_alt_to_system
= Qnil
;
8332 DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta
,
8333 doc
: /* Non-nil if the Alt key is to be considered the same as the META key.
8334 When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */);
8335 Vw32_alt_is_meta
= Qt
;
8337 DEFVAR_INT ("w32-quit-key", w32_quit_key
,
8338 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
8341 DEFVAR_LISP ("w32-pass-lwindow-to-system",
8342 Vw32_pass_lwindow_to_system
,
8343 doc
: /* If non-nil, the left \"Windows\" key is passed on to Windows.
8345 When non-nil, the Start menu is opened by tapping the key.
8346 If you set this to nil, the left \"Windows\" key is processed by Emacs
8347 according to the value of `w32-lwindow-modifier', which see.
8349 Note that some combinations of the left \"Windows\" key with other keys are
8350 caught by Windows at low level, and so binding them in Emacs will have no
8351 effect. For example, <lwindow>-r always pops up the Windows Run dialog,
8352 <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8353 the doc string of `w32-phantom-key-code'. */);
8354 Vw32_pass_lwindow_to_system
= Qt
;
8356 DEFVAR_LISP ("w32-pass-rwindow-to-system",
8357 Vw32_pass_rwindow_to_system
,
8358 doc
: /* If non-nil, the right \"Windows\" key is passed on to Windows.
8360 When non-nil, the Start menu is opened by tapping the key.
8361 If you set this to nil, the right \"Windows\" key is processed by Emacs
8362 according to the value of `w32-rwindow-modifier', which see.
8364 Note that some combinations of the right \"Windows\" key with other keys are
8365 caught by Windows at low level, and so binding them in Emacs will have no
8366 effect. For example, <rwindow>-r always pops up the Windows Run dialog,
8367 <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
8368 the doc string of `w32-phantom-key-code'. */);
8369 Vw32_pass_rwindow_to_system
= Qt
;
8371 DEFVAR_LISP ("w32-phantom-key-code",
8372 Vw32_phantom_key_code
,
8373 doc
: /* Virtual key code used to generate \"phantom\" key presses.
8374 Value is a number between 0 and 255.
8376 Phantom key presses are generated in order to stop the system from
8377 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
8378 `w32-pass-rwindow-to-system' is nil. */);
8379 /* Although 255 is technically not a valid key code, it works and
8380 means that this hack won't interfere with any real key code. */
8381 XSETINT (Vw32_phantom_key_code
, 255);
8383 DEFVAR_LISP ("w32-enable-num-lock",
8384 Vw32_enable_num_lock
,
8385 doc
: /* If non-nil, the Num Lock key acts normally.
8386 Set to nil to handle Num Lock as the `kp-numlock' key. */);
8387 Vw32_enable_num_lock
= Qt
;
8389 DEFVAR_LISP ("w32-enable-caps-lock",
8390 Vw32_enable_caps_lock
,
8391 doc
: /* If non-nil, the Caps Lock key acts normally.
8392 Set to nil to handle Caps Lock as the `capslock' key. */);
8393 Vw32_enable_caps_lock
= Qt
;
8395 DEFVAR_LISP ("w32-scroll-lock-modifier",
8396 Vw32_scroll_lock_modifier
,
8397 doc
: /* Modifier to use for the Scroll Lock ON state.
8398 The value can be hyper, super, meta, alt, control or shift for the
8399 respective modifier, or nil to handle Scroll Lock as the `scroll' key.
8400 Any other value will cause the Scroll Lock key to be ignored. */);
8401 Vw32_scroll_lock_modifier
= Qnil
;
8403 DEFVAR_LISP ("w32-lwindow-modifier",
8404 Vw32_lwindow_modifier
,
8405 doc
: /* Modifier to use for the left \"Windows\" key.
8406 The value can be hyper, super, meta, alt, control or shift for the
8407 respective modifier, or nil to appear as the `lwindow' key.
8408 Any other value will cause the key to be ignored. */);
8409 Vw32_lwindow_modifier
= Qnil
;
8411 DEFVAR_LISP ("w32-rwindow-modifier",
8412 Vw32_rwindow_modifier
,
8413 doc
: /* Modifier to use for the right \"Windows\" key.
8414 The value can be hyper, super, meta, alt, control or shift for the
8415 respective modifier, or nil to appear as the `rwindow' key.
8416 Any other value will cause the key to be ignored. */);
8417 Vw32_rwindow_modifier
= Qnil
;
8419 DEFVAR_LISP ("w32-apps-modifier",
8421 doc
: /* Modifier to use for the \"Apps\" key.
8422 The value can be hyper, super, meta, alt, control or shift for the
8423 respective modifier, or nil to appear as the `apps' key.
8424 Any other value will cause the key to be ignored. */);
8425 Vw32_apps_modifier
= Qnil
;
8427 DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts
,
8428 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
8429 w32_enable_synthesized_fonts
= 0;
8431 DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette
,
8432 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
8433 Vw32_enable_palette
= Qt
;
8435 DEFVAR_INT ("w32-mouse-button-tolerance",
8436 w32_mouse_button_tolerance
,
8437 doc
: /* Analogue of double click interval for faking middle mouse events.
8438 The value is the minimum time in milliseconds that must elapse between
8439 left and right button down events before they are considered distinct events.
8440 If both mouse buttons are depressed within this interval, a middle mouse
8441 button down event is generated instead. */);
8442 w32_mouse_button_tolerance
= GetDoubleClickTime () / 2;
8444 DEFVAR_INT ("w32-mouse-move-interval",
8445 w32_mouse_move_interval
,
8446 doc
: /* Minimum interval between mouse move events.
8447 The value is the minimum time in milliseconds that must elapse between
8448 successive mouse move (or scroll bar drag) events before they are
8449 reported as lisp events. */);
8450 w32_mouse_move_interval
= 0;
8452 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
8453 w32_pass_extra_mouse_buttons_to_system
,
8454 doc
: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows.
8455 Recent versions of Windows support mice with up to five buttons.
8456 Since most applications don't support these extra buttons, most mouse
8457 drivers will allow you to map them to functions at the system level.
8458 If this variable is non-nil, Emacs will pass them on, allowing the
8459 system to handle them. */);
8460 w32_pass_extra_mouse_buttons_to_system
= 0;
8462 DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system",
8463 w32_pass_multimedia_buttons_to_system
,
8464 doc
: /* If non-nil, media buttons are passed to Windows.
8465 Some modern keyboards contain buttons for controlling media players, web
8466 browsers and other applications. Generally these buttons are handled on a
8467 system wide basis, but by setting this to nil they are made available
8468 to Emacs for binding. Depending on your keyboard, additional keys that
8469 may be available are:
8471 browser-back, browser-forward, browser-refresh, browser-stop,
8472 browser-search, browser-favorites, browser-home,
8473 mail, mail-reply, mail-forward, mail-send,
8475 help, find, new, open, close, save, print, undo, redo, copy, cut, paste,
8476 spell-check, correction-list, toggle-dictate-command,
8477 media-next, media-previous, media-stop, media-play-pause, media-select,
8478 media-play, media-pause, media-record, media-fast-forward, media-rewind,
8479 media-channel-up, media-channel-down,
8480 volume-mute, volume-up, volume-down,
8481 mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle,
8482 bass-down, bass-boost, bass-up, treble-down, treble-up */);
8483 w32_pass_multimedia_buttons_to_system
= 1;
8485 #if 0 /* TODO: Mouse cursor customization. */
8486 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
8487 doc
: /* The shape of the pointer when over text.
8488 Changing the value does not affect existing frames
8489 unless you set the mouse color. */);
8490 Vx_pointer_shape
= Qnil
;
8492 Vx_nontext_pointer_shape
= Qnil
;
8494 Vx_mode_pointer_shape
= Qnil
;
8496 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
8497 doc
: /* The shape of the pointer when Emacs is busy.
8498 This variable takes effect when you create a new frame
8499 or when you set the mouse color. */);
8500 Vx_hourglass_pointer_shape
= Qnil
;
8502 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
8503 Vx_sensitive_text_pointer_shape
,
8504 doc
: /* The shape of the pointer when over mouse-sensitive text.
8505 This variable takes effect when you create a new frame
8506 or when you set the mouse color. */);
8507 Vx_sensitive_text_pointer_shape
= Qnil
;
8509 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
8510 Vx_window_horizontal_drag_shape
,
8511 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
8512 This variable takes effect when you create a new frame
8513 or when you set the mouse color. */);
8514 Vx_window_horizontal_drag_shape
= Qnil
;
8516 DEFVAR_LISP ("x-window-vertical-drag-cursor",
8517 Vx_window_vertical_drag_shape
,
8518 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
8519 This variable takes effect when you create a new frame
8520 or when you set the mouse color. */);
8521 Vx_window_vertical_drag_shape
= Qnil
;
8524 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
8525 doc
: /* A string indicating the foreground color of the cursor box. */);
8526 Vx_cursor_fore_pixel
= Qnil
;
8528 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
8529 doc
: /* Maximum size for tooltips.
8530 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
8531 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
8533 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
8534 doc
: /* Non-nil if no window manager is in use.
8535 Emacs doesn't try to figure this out; this is always nil
8536 unless you set it to something else. */);
8537 /* We don't have any way to find this out, so set it to nil
8538 and maybe the user would like to set it to t. */
8539 Vx_no_window_manager
= Qnil
;
8541 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
8542 Vx_pixel_size_width_font_regexp
,
8543 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
8545 Since Emacs gets width of a font matching with this regexp from
8546 PIXEL_SIZE field of the name, font finding mechanism gets faster for
8547 such a font. This is especially effective for such large fonts as
8548 Chinese, Japanese, and Korean. */);
8549 Vx_pixel_size_width_font_regexp
= Qnil
;
8551 DEFVAR_LISP ("w32-bdf-filename-alist",
8552 Vw32_bdf_filename_alist
,
8553 doc
: /* List of bdf fonts and their corresponding filenames. */);
8554 Vw32_bdf_filename_alist
= Qnil
;
8556 DEFVAR_BOOL ("w32-strict-fontnames",
8557 w32_strict_fontnames
,
8558 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
8559 Default is nil, which allows old fontnames that are not XLFD compliant,
8560 and allows third-party CJK display to work by specifying false charset
8561 fields to trick Emacs into translating to Big5, SJIS etc.
8562 Setting this to t will prevent wrong fonts being selected when
8563 fontsets are automatically created. */);
8564 w32_strict_fontnames
= 0;
8566 DEFVAR_BOOL ("w32-strict-painting",
8567 w32_strict_painting
,
8568 doc
: /* Non-nil means use strict rules for repainting frames.
8569 Set this to nil to get the old behavior for repainting; this should
8570 only be necessary if the default setting causes problems. */);
8571 w32_strict_painting
= 1;
8573 #if 0 /* TODO: Port to W32 */
8574 defsubr (&Sx_change_window_property
);
8575 defsubr (&Sx_delete_window_property
);
8576 defsubr (&Sx_window_property
);
8578 defsubr (&Sxw_display_color_p
);
8579 defsubr (&Sx_display_grayscale_p
);
8580 defsubr (&Sxw_color_defined_p
);
8581 defsubr (&Sxw_color_values
);
8582 defsubr (&Sx_server_max_request_size
);
8583 defsubr (&Sx_server_vendor
);
8584 defsubr (&Sx_server_version
);
8585 defsubr (&Sx_display_pixel_width
);
8586 defsubr (&Sx_display_pixel_height
);
8587 defsubr (&Sx_display_mm_width
);
8588 defsubr (&Sx_display_mm_height
);
8589 defsubr (&Sx_display_screens
);
8590 defsubr (&Sx_display_planes
);
8591 defsubr (&Sx_display_color_cells
);
8592 defsubr (&Sx_display_visual_class
);
8593 defsubr (&Sx_display_backing_store
);
8594 defsubr (&Sx_display_save_under
);
8595 defsubr (&Sx_create_frame
);
8596 defsubr (&Sx_open_connection
);
8597 defsubr (&Sx_close_connection
);
8598 defsubr (&Sx_display_list
);
8599 defsubr (&Sx_frame_geometry
);
8600 defsubr (&Sx_synchronize
);
8602 /* W32 specific functions */
8604 defsubr (&Sw32_define_rgb_color
);
8605 defsubr (&Sw32_default_color_map
);
8606 defsubr (&Sw32_display_monitor_attributes_list
);
8607 defsubr (&Sw32_send_sys_command
);
8608 defsubr (&Sw32_shell_execute
);
8609 defsubr (&Sw32_register_hot_key
);
8610 defsubr (&Sw32_unregister_hot_key
);
8611 defsubr (&Sw32_registered_hot_keys
);
8612 defsubr (&Sw32_reconstruct_hot_key
);
8613 defsubr (&Sw32_toggle_lock_key
);
8614 defsubr (&Sw32_window_exists_p
);
8615 defsubr (&Sw32_frame_rect
);
8616 defsubr (&Sw32_frame_menu_bar_size
);
8617 defsubr (&Sw32_battery_status
);
8620 defsubr (&Sfile_system_info
);
8621 defsubr (&Sdefault_printer_name
);
8624 defsubr (&Sset_message_beep
);
8625 defsubr (&Sx_show_tip
);
8626 defsubr (&Sx_hide_tip
);
8628 staticpro (&tip_timer
);
8630 staticpro (&tip_frame
);
8632 last_show_tip_args
= Qnil
;
8633 staticpro (&last_show_tip_args
);
8635 defsubr (&Sx_file_dialog
);
8637 defsubr (&Ssystem_move_file_to_trash
);
8643 /* Crashing and reporting backtrace. */
8646 static LONG CALLBACK
my_exception_handler (EXCEPTION_POINTERS
*);
8647 static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_handler
;
8649 static DWORD except_code
;
8650 static PVOID except_addr
;
8653 /* This handler records the exception code and the address where it
8654 was triggered so that this info could be included in the backtrace.
8655 Without that, the backtrace in some cases has no information
8656 whatsoever about the offending code, and looks as if the top-level
8657 exception handler in the MinGW startup code di the one that
8659 static LONG CALLBACK
8660 my_exception_handler (EXCEPTION_POINTERS
* exception_data
)
8662 except_code
= exception_data
->ExceptionRecord
->ExceptionCode
;
8663 except_addr
= exception_data
->ExceptionRecord
->ExceptionAddress
;
8665 if (prev_exception_handler
)
8666 return prev_exception_handler (exception_data
);
8667 return EXCEPTION_EXECUTE_HANDLER
;
8671 typedef USHORT (WINAPI
* CaptureStackBackTrace_proc
) (ULONG
, ULONG
, PVOID
*,
8674 #define BACKTRACE_LIMIT_MAX 62
8677 w32_backtrace (void **buffer
, int limit
)
8679 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace
= NULL
;
8680 HMODULE hm_kernel32
= NULL
;
8682 if (!s_pfn_CaptureStackBackTrace
)
8684 hm_kernel32
= LoadLibrary ("Kernel32.dll");
8685 s_pfn_CaptureStackBackTrace
=
8686 (CaptureStackBackTrace_proc
) GetProcAddress (hm_kernel32
,
8687 "RtlCaptureStackBackTrace");
8689 if (s_pfn_CaptureStackBackTrace
)
8690 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX
, limit
),
8699 button
= MessageBox (NULL
,
8700 "A fatal error has occurred!\n\n"
8701 "Would you like to attach a debugger?\n\n"
8703 "YES -- to debug Emacs, or\n"
8704 "NO -- to abort Emacs and produce a backtrace\n"
8705 " (emacs_backtrace.txt in current directory)."
8707 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
8708 "\"continue\" inside GDB before clicking YES.)"
8710 , "Emacs Abort Dialog",
8711 MB_ICONEXCLAMATION
| MB_TASKMODAL
8712 | MB_SETFOREGROUND
| MB_YESNO
);
8717 exit (2); /* tell the compiler we will never return */
8721 void *stack
[BACKTRACE_LIMIT_MAX
+ 1];
8722 int i
= w32_backtrace (stack
, BACKTRACE_LIMIT_MAX
+ 1);
8726 int errfile_fd
= -1;
8728 char buf
[sizeof ("\r\nException at this address:\r\n\r\n")
8729 /* The type below should really be 'void *', but
8730 INT_BUFSIZE_BOUND cannot handle that without
8731 triggering compiler warnings (under certain
8732 pedantic warning switches), it wants an
8734 + 2 * INT_BUFSIZE_BOUND (intptr_t)];
8738 HANDLE errout
= GetStdHandle (STD_ERROR_HANDLE
);
8741 if (errout
&& errout
!= INVALID_HANDLE_VALUE
)
8742 stderr_fd
= _open_osfhandle ((intptr_t)errout
, O_APPEND
| O_BINARY
);
8745 /* We use %p, not 0x%p, as %p produces a leading "0x" on XP,
8746 but not on Windows 7. addr2line doesn't mind a missing
8747 "0x", but will be confused by an extra one. */
8749 sprintf (buf
, "\r\nException 0x%lx at this address:\r\n%p\r\n",
8750 except_code
, except_addr
);
8754 write (stderr_fd
, buf
, strlen (buf
));
8755 write (stderr_fd
, "\r\nBacktrace:\r\n", 14);
8760 errfile_fd
= _open ("emacs_backtrace.txt", O_RDWR
| O_CREAT
| O_BINARY
, S_IREAD
| S_IWRITE
);
8761 if (errfile_fd
>= 0)
8763 lseek (errfile_fd
, 0L, SEEK_END
);
8765 write (errfile_fd
, buf
, strlen (buf
));
8766 write (errfile_fd
, "\r\nBacktrace:\r\n", 14);
8769 for (j
= 0; j
< i
; j
++)
8771 /* stack[] gives the return addresses, whereas we want
8772 the address of the call, so decrease each address
8773 by approximate size of 1 CALL instruction. */
8774 sprintf (buf
, "%p\r\n", (char *)stack
[j
] - sizeof(void *));
8776 write (stderr_fd
, buf
, strlen (buf
));
8777 if (errfile_fd
>= 0)
8778 write (errfile_fd
, buf
, strlen (buf
));
8780 if (i
== BACKTRACE_LIMIT_MAX
)
8783 write (stderr_fd
, "...\r\n", 5);
8784 if (errfile_fd
>= 0)
8785 write (errfile_fd
, "...\r\n", 5);
8787 if (errfile_fd
>= 0)
8798 /* Initialization. */
8801 globals_of_w32fns is used to initialize those global variables that
8802 must always be initialized on startup even when the global variable
8803 initialized is non zero (see the function main in emacs.c).
8804 globals_of_w32fns is called from syms_of_w32fns when the global
8805 variable initialized is 0 and directly from main when initialized
8809 globals_of_w32fns (void)
8811 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
8813 TrackMouseEvent not available in all versions of Windows, so must load
8814 it dynamically. Do it once, here, instead of every time it is used.
8816 track_mouse_event_fn
= (TrackMouseEvent_Proc
)
8817 GetProcAddress (user32_lib
, "TrackMouseEvent");
8819 monitor_from_point_fn
= (MonitorFromPoint_Proc
)
8820 GetProcAddress (user32_lib
, "MonitorFromPoint");
8821 get_monitor_info_fn
= (GetMonitorInfo_Proc
)
8822 GetProcAddress (user32_lib
, "GetMonitorInfoA");
8823 monitor_from_window_fn
= (MonitorFromWindow_Proc
)
8824 GetProcAddress (user32_lib
, "MonitorFromWindow");
8825 enum_display_monitors_fn
= (EnumDisplayMonitors_Proc
)
8826 GetProcAddress (user32_lib
, "EnumDisplayMonitors");
8829 HMODULE imm32_lib
= GetModuleHandle ("imm32.dll");
8830 get_composition_string_fn
= (ImmGetCompositionString_Proc
)
8831 GetProcAddress (imm32_lib
, "ImmGetCompositionStringW");
8832 get_ime_context_fn
= (ImmGetContext_Proc
)
8833 GetProcAddress (imm32_lib
, "ImmGetContext");
8834 release_ime_context_fn
= (ImmReleaseContext_Proc
)
8835 GetProcAddress (imm32_lib
, "ImmReleaseContext");
8836 set_ime_composition_window_fn
= (ImmSetCompositionWindow_Proc
)
8837 GetProcAddress (imm32_lib
, "ImmSetCompositionWindow");
8843 prev_exception_handler
= SetUnhandledExceptionFilter (my_exception_handler
);
8846 DEFVAR_INT ("w32-ansi-code-page",
8848 doc
: /* The ANSI code page used by the system. */);
8849 w32_ansi_code_page
= GetACP ();
8851 if (os_subtype
== OS_NT
)
8852 w32_unicode_gui
= 1;
8854 w32_unicode_gui
= 0;
8856 /* MessageBox does not work without this when linked to comctl32.dll 6.0. */
8857 InitCommonControls ();
8859 syms_of_w32uniscribe ();
8862 #ifdef NTGUI_UNICODE
8865 ntgui_encode_system (Lisp_Object str
)
8867 Lisp_Object encoded
;
8868 to_unicode (str
, &encoded
);
8872 #endif /* NTGUI_UNICODE */